|
| 1 | +#include "OpenSHC/AI/AICState.hpp" |
| 2 | +#include "OpenSHC/AI/AITypeA.hpp" |
| 3 | +#include "OpenSHC/Game/Resources/ResourceType.hpp" |
| 4 | +#include "OpenSHC/Globals/DAT_AICState.hpp" |
| 5 | +#include "OpenSHC/Globals/DAT_GameState.hpp" |
| 6 | + |
| 7 | +namespace OpenSHC { |
| 8 | +namespace AI { |
| 9 | + |
| 10 | + using OpenSHC::AI::AITypeA; |
| 11 | + using OpenSHC::Game::Resources::ResourceType; |
| 12 | + |
| 13 | + // FUNCTION: STRONGHOLDCRUSADER 0x004CB060 |
| 14 | + void AICState::setFoodBuyPlan(int playerID) |
| 15 | + { |
| 16 | + |
| 17 | + int const aiType = DAT_GameState::ptr->playerDataArray[playerID].aiType; |
| 18 | + |
| 19 | + // Early return if not an AI player (human player has aiType == 0) |
| 20 | + if (aiType == AITypeA::AITA_NULL) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + // Get AI configuration index (convert 1-based to 0-based index) |
| 25 | + int const aiConfigIndex = aiType - 1; |
| 26 | + |
| 27 | + // Check each food type and queue purchase if current stock is below minimum |
| 28 | + |
| 29 | + // Apples: special handling with >= 0 check (allows -1 to disable) |
| 30 | + int const minimumApples = this->DAT_AICArray[aiConfigIndex].minimumApples; |
| 31 | + int* currentResources = DAT_GameState::ptr->playerDataArray[playerID].currentResources; |
| 32 | + if (minimumApples >= 0 && currentResources[ResourceType::RT_APPLE] < minimumApples) { |
| 33 | + DAT_GameState::ptr->playerDataArray[playerID].resourcesToAcquireArray[ResourceType::RT_APPLE] |
| 34 | + = this->DAT_AICArray[aiConfigIndex].tradeAmountFood; |
| 35 | + } |
| 36 | + |
| 37 | + // Cheese: standard check with > 0 |
| 38 | + int const minimumCheese = this->DAT_AICArray[aiConfigIndex].minimumCheese; |
| 39 | + if (minimumCheese > 0 && currentResources[ResourceType::RT_CHEESE] < minimumCheese) { |
| 40 | + DAT_GameState::ptr->playerDataArray[playerID].resourcesToAcquireArray[ResourceType::RT_CHEESE] |
| 41 | + = this->DAT_AICArray[aiConfigIndex].tradeAmountFood; |
| 42 | + } |
| 43 | + |
| 44 | + // Bread: standard check with > 0 |
| 45 | + int const minimumBread = this->DAT_AICArray[aiConfigIndex].minimumBread; |
| 46 | + if (minimumBread > 0 && currentResources[ResourceType::RT_BREAD] < minimumBread) { |
| 47 | + DAT_GameState::ptr->playerDataArray[playerID].resourcesToAcquireArray[ResourceType::RT_BREAD] |
| 48 | + = this->DAT_AICArray[aiConfigIndex].tradeAmountFood; |
| 49 | + } |
| 50 | + |
| 51 | + // Wheat: standard check with > 0 |
| 52 | + int const minimumWheat = this->DAT_AICArray[aiConfigIndex].minimumWheat; |
| 53 | + if (minimumWheat > 0 && currentResources[ResourceType::RT_WHEAT] < minimumWheat) { |
| 54 | + DAT_GameState::ptr->playerDataArray[playerID].resourcesToAcquireArray[ResourceType::RT_WHEAT] |
| 55 | + = this->DAT_AICArray[aiConfigIndex].tradeAmountFood; |
| 56 | + } |
| 57 | + |
| 58 | + // Hops: standard check with > 0 |
| 59 | + int const minimumHop = this->DAT_AICArray[aiConfigIndex].minimumHop; |
| 60 | + if (minimumHop > 0 && currentResources[ResourceType::RT_HOPS] < minimumHop) { |
| 61 | + DAT_GameState::ptr->playerDataArray[playerID].resourcesToAcquireArray[ResourceType::RT_HOPS] |
| 62 | + = this->DAT_AICArray[aiConfigIndex].tradeAmountFood; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | +} |
0 commit comments