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.

fix(gameengine): keep script-driven ai on retail role draw and focus fire

Olcay Seygan560873332604
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
index ced50dd17..ccace143c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
@@ -1515,9 +1515,14 @@ void Team::setTeamTargetObject(const Object *target)
// Whether a team fires together is a rung of the ladder now, not one of the three script
// tiers: the ladder has six steps and this is one of the capabilities that separates them
// (AI-ROADMAP.md D6). The bottom two rungs still do not do it, which is what the old
- // DIFFICULTY_EASY test said.
+ // DIFFICULTY_EASY test said. A script-driven opponent keeps that test itself, so the ladder's
+ // tuning never reaches a Challenge or mission.
//
- if (!TheAI->getDifficultyProfile(getControllingPlayer()->getAISkillLevel())->m_focusFire) {
+ Player *player = getControllingPlayer();
+ const Bool focusFire = player->isSkirmishAIPlayer()
+ ? TheAI->getDifficultyProfile(player->getAISkillLevel())->m_focusFire
+ : player->getPlayerDifficulty() != DIFFICULTY_EASY;
+ if (!focusFire) {
return;
}
m_commonAttackTarget = target->getID();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index bbdb83946..c08bb1e34 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -430,14 +430,8 @@ m_role(AIROLE_AGGRESSIVE)
m_placementRing = 0;
m_difficulty = TheScriptEngine->getGlobalDifficulty();
m_skillLevel = skillLevelForDifficulty( m_difficulty );
-
- //
- // Role is rolled once and kept for the whole match. Sins is explicit that its AI does not flip
- // personality mid-game, and that consistency is what makes an opponent readable and therefore
- // counterable - an AI that turtles for ten minutes and then rushes is not deep, it is noise.
- // GameLogicRandomValue, so a replay rolls the same one.
- //
- m_role = (GameLogicRandomValue( 0, AIROLE_COUNT - 1 ) == 0) ? AIROLE_AGGRESSIVE : AIROLE_DEFENSIVE;
+ // m_role is rolled in AISkirmishPlayer's constructor: a script-driven opponent must not draw
+ // from the logic random stream where retail did not.
m_teamSeconds = TheAI->getAiData()->m_teamSeconds;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
index 07340e595..6c52a0b31 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
@@ -86,6 +86,16 @@ m_currentEnemy(NULL)
{
m_frameLastBuildingBuilt = TheGameLogic->getFrame();
p->setCanBuildUnits(true); // turn on ai production by default.
+
+ //
+ // Role is rolled once and kept for the whole match. Sins is explicit that its AI does not flip
+ // personality mid-game, and that consistency is what makes an opponent readable and therefore
+ // counterable - an AI that turtles for ten minutes and then rushes is not deep, it is noise.
+ // GameLogicRandomValue, so a replay rolls the same one. Rolled here rather than in AIPlayer's
+ // constructor so a Challenge or mission opponent leaves the logic random stream as retail did;
+ // nothing between the two constructors draws, so a skirmish rolls on the same draw as before.
+ //
+ m_role = (GameLogicRandomValue( 0, AIROLE_COUNT - 1 ) == 0) ? AIROLE_AGGRESSIVE : AIROLE_DEFENSIVE;
}
AISkirmishPlayer::~AISkirmishPlayer()