Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): the AI saves its promotion points for what it came for

Olcay Seyganbcebf3766bbe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b2d88721..18498a257 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,12 @@ found and fixed — EA's own, not port damage.**
- It scouts. There was no such thing as scouting in the computer opponent - it never needed to look, because it could already see everything. One cheap unit now tours the enemy start positions and keeps going round for the rest of the match, replaced out of spare change when it dies. Every difficulty scouts; an opponent that never looks reads as broken, not as easy.
- Nor does it read your base off the map. Where your base is, what it is worth, which supply dock to expand to and where to aim a superweapon all came off a walk of your object list, in the shroud, from the first second of the match. The computer now only counts what it can see, plus the buildings it has already found - buildings do not walk away. Before it has scouted you, all it knows is where you started, which is on the map preview anyway.
+## Generals powers the computer actually meant to buy
+
+- It spent every promotion point the moment it had one, on whatever in its list happened to be cheap enough. The strong three-point ability at the end of the list was never reached, because the points were always already gone.
+- From Medium up it saves. If the next thing in its own list is only out of reach on points, it waits for them instead of buying filler.
+- Which list it draws from now follows its personality, so the powers coming at you tell you which kind of opponent you are facing.
+
## The computer comes in where you are thin
- The game has kept a value-and-danger map of every square of the battlefield, per player, since 2003. It has a query interface and even a debug view. Nothing in the computer opponent had ever read it - its only users were two map-script actions almost nobody used.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 38f3f2a7b..4acd6bd52 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -189,6 +189,7 @@ struct AIDifficultyProfile
Bool m_retreatTeams; ///< ... and break off the whole team when the fight is lost
Bool m_useInfluenceMapForAttackLane;
Bool m_focusFire;
+ Bool m_savesSciencePoints; ///< wait for the next power in the set instead of buying filler
// Economy: decisions only, never multipliers
Bool m_adaptiveHarvesters;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
index a5d0def26..c708c36d8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
@@ -1011,15 +1011,15 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons
*
* Read the columns down, not across: nothing here is money, build speed, vision or unit stats.
*
- * scoutS maxSc react decis cntr mass ttk indiv team infl focus harv expand guard hoard */
+ * scoutS maxSc react decis cntr mass ttk indiv team infl focus save harv expand guard hoard */
static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] =
{
- /* Easy */ { 90.0f, 1, 15.0f, 10.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0 },
- /* Steady */ { 75.0f, 1, 10.0f, 8.0f, 0.00f, FALSE, 0.50f, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0 },
- /* Medium */ { 60.0f, 1, 6.0f, 5.0f, 0.25f, FALSE, 0.60f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, 10000 },
- /* Hard */ { 45.0f, 2, 3.0f, 4.0f, 0.60f, FALSE, 0.70f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, 8000 },
- /* Brutal */ { 30.0f, 2, 1.0f, 2.0f, 0.85f, TRUE, 0.80f, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, 5000 },
- /* Merciless */ { 25.0f, 2, 0.0f, 1.5f, 1.00f, TRUE, 0.85f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000 }
+ /* Easy */ { 90.0f, 1, 15.0f, 10.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0 },
+ /* Steady */ { 75.0f, 1, 10.0f, 8.0f, 0.00f, FALSE, 0.50f, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0 },
+ /* Medium */ { 60.0f, 1, 6.0f, 5.0f, 0.25f, FALSE, 0.60f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 10000 },
+ /* Hard */ { 45.0f, 2, 3.0f, 4.0f, 0.60f, FALSE, 0.70f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 8000 },
+ /* Brutal */ { 30.0f, 2, 1.0f, 2.0f, 0.85f, TRUE, 0.80f, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, 5000 },
+ /* Merciless */ { 25.0f, 2, 0.0f, 1.5f, 1.00f, TRUE, 0.85f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000 }
};
//-------------------------------------------------------------------------------------------------
@@ -1164,6 +1164,7 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*
{ "RetreatTeams", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_retreatTeams ) },
{ "UseInfluenceMapForAttackLane", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_useInfluenceMapForAttackLane ) },
{ "FocusFire", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_focusFire ) },
+ { "SavesSciencePoints", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_savesSciencePoints ) },
{ "AdaptiveHarvesters", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_adaptiveHarvesters ) },
{ "SelfTriggeredExpansion", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_selfTriggeredExpansion ) },
{ "DefendExpansions", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_defendExpansions ) },
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index e3b6d9df8..4d7106ee5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -3462,7 +3462,21 @@ void AIPlayer::doUpgradesAndSkills( void )
}
}
if (isSkirmishAI()) {
- m_skillsetSelector = GameLogicRandomValue(0, limit);
+ //
+ // Split the designers' skill sets between the two roles rather than rolling across all
+ // of them (D8). This makes no claim about which set is which - only that an aggressive
+ // AI and a defensive one draw from different halves, so the powers you see coming tell
+ // you which one you are facing. Still a roll, so repeat matches still differ.
+ //
+ if (limit > 0) {
+ const Int half = limit / 2;
+ if (m_role == AIROLE_AGGRESSIVE)
+ m_skillsetSelector = GameLogicRandomValue(0, half);
+ else
+ m_skillsetSelector = GameLogicRandomValue(half, limit);
+ } else {
+ m_skillsetSelector = 0;
+ }
} else {
m_skillsetSelector = 0; // Non-skirmish default to 0. jba.
}
@@ -3479,9 +3493,25 @@ void AIPlayer::doUpgradesAndSkills( void )
case 3: skillset = &sideInfo->m_skillSet4; break;
case 4: skillset = &sideInfo->m_skillSet5; break;
}
+ const Bool saves = getSkillProfile()->m_savesSciencePoints;
Int i;
for (i=0; i<skillset->m_numSkills; i++) {
ScienceType science = skillset->m_skills[i];
+
+ //
+ // Saving up (B5). EA walked the whole set and bought the first thing it could afford,
+ // so a point went on filler while the ability the set is actually built around sat two
+ // points away for ever. If the next thing in the designer's own order is only out of
+ // reach on points, stop here and keep them; anything else - already owned, or blocked
+ // by a rank we have not reached - is skipped as before.
+ //
+ if (saves && !m_player->hasScience(science)) {
+ const Int cost = TheScienceStore->getSciencePurchaseCost(science);
+ if (cost > m_player->getSciencePurchasePoints()) {
+ break;
+ }
+ }
+
if (m_player->isCapableOfPurchasingScience(science)) {
if (m_player->attemptToPurchaseScience(science)) {
AsciiString msg = TheNameKeyGenerator->keyToName(m_player->getPlayerNameKey());
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index dbf6ca6b1..df6791eaa 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -5818,6 +5818,7 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)
CHECK( upper.m_retreatTeams >= lower.m_retreatTeams );
CHECK( upper.m_useInfluenceMapForAttackLane >= lower.m_useInfluenceMapForAttackLane );
CHECK( upper.m_focusFire >= lower.m_focusFire );
+ CHECK( upper.m_savesSciencePoints >= lower.m_savesSciencePoints );
CHECK( upper.m_adaptiveHarvesters >= lower.m_adaptiveHarvesters );
CHECK( upper.m_selfTriggeredExpansion >= lower.m_selfTriggeredExpansion );
CHECK( upper.m_defendExpansions >= lower.m_defendExpansions );