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