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): the AI targets only what it can see

Olcay Seyganeb51ec6cbacd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 450dcc04d..0f3403d34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ found and fixed — EA's own, not port damage.**
- The AI checks ten seconds of supply-line damage, not a third of one.
- One AI decision read leftover memory, so identical matches played out differently.
- Difficulty and AI money change build pace again; every order was pinned at three seconds.
+- The computer no longer shoots at what it cannot see. Its units, and its base defences, used to auto-target through the fog of war - a hard exemption written into the code for computer players only. Stealth works against it now, and so does anything it has not scouted.
## Attack-move actually attacks
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 283d16a6b..a52ca2143 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -4710,12 +4710,18 @@ Object* AIUpdateInterface::getNextMoodTarget( Bool calledByAI, Bool calledDuring
flags |= AI::WITHIN_ATTACK_RANGE;
}
+ //
// Instead of shroud affecting the ability to attack, it affects the ability to target.
// The same checks apply as the old WeaponSet check (now commented out, search for getShroudedStatus)
- if( calledByAI
- && obj->getControllingPlayer()
- && obj->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN
- )
+ //
+ // This used to carry "&& getPlayerType() == PLAYER_HUMAN", which is not a balance knob but a
+ // hard if on who is playing: a computer player's units auto-acquired targets standing in fog it
+ // could not see, and a human player's could not. UNFOGGED is the only thing that engages
+ // PartitionFilterFreeOfFog, and getNextMoodTarget is the shared path - attack states, guard, mob
+ // members and base defence turrets all route through here - so the exemption covered every one
+ // of them. The AI now sees what a player sees, which is also what makes stealth work against it.
+ //
+ if( calledByAI && obj->getControllingPlayer() )
{
flags |= AI::UNFOGGED;
}