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(ai): stop sending idle units at towers outside the base

Olcay Seyganf66674eff816
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e48aad46..1f33d72dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -259,6 +259,7 @@ found and fixed — EA's own, not port damage.**
- And when that switch does happen, the old order stops there. It used to finish its own turn afterwards, steering one last time toward the place the unit was going before the order changed, which is a visible flinch at the head of a column.
- It no longer chases what it cannot see. A stealthed Colonel Burton nobody had detected still counted as seen to the computer, so walking him into its base drew the whole guard after him while not one of their guns was allowed to fire at him. A hidden unit is now hidden from the computer the way it is from you, until a detector or a shot of his own gives him away, and a GLA bomb truck dressed as one of the computer's own units fools it as well. In four staged runs a Burton pacing inside a USA base had the guard sent at him about 70 seconds in every time; now nothing goes for him until the base's first Patriot Battery, which can see him, is up.
- Hard stops feeding you units. Before a group leaves, or a lone reinforcement sets off to join one out on the map, it weighs what it is sending against everything of yours it has seen in the last three minutes, unit type against unit type, and holds back what would only die. A reinforcement waits at home for the next wave instead of crossing the map alone. When you mass one unit it trains the answer between attacks too, Comanches and Helixes included, and stops buying what your biggest group beats. Against waves of Overlords rolling at its base, the share of its groups sent into a fight their units lose fell from 48% to 40%, and units dying alone from 17% to 14% of its losses. Against itself it changed nothing measurable: in 48 matches where only one side had it, that side won 5 and the other 4. Replays recorded before this change play out differently.
+- It stops feeding its idle units to your towers. On a small map your base, or a Patriot at your expansion, stands close enough to its own to count as an attack on it, and it answered by sending whatever stood idle at home at the tower, one or two at a time: one Hard GLA walked eight Quad Cannons and Scorpions into the same Fire Base and Patriot, one after the other. A tower that stays outside its base is now gone after only with a force that outweighs it, double on Hard, half again on Medium, level on Easy, and anything that drives in is still met wherever it stands. In 32 Hard against Medium matches, USA and GLA in both seats, what both sides lost to defences fell from 171,800 to 91,700, everything they lost fell from 1,114,000 to 965,000, and Hard still won 14. Replays recorded before this change play out differently.
## The computer knows when to quit
- Its teams fought to the last man. The word "retreat" appeared nowhere in the opponent's code - the single most visible thing that made it look stupid.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 763cb851f..7377e0623 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -7315,6 +7315,16 @@ void AIPlayer::defendHome( void )
homePower *= (Real)sqrt( armyAdvantage( home, army ) );
if( homePower < 0.5f * intruderWorth )
return;
+ // A gun standing still outside the base itself is not coming in: on a small map the enemy's own towers
+ // and an expansion's Patriots sit within two base radii, and idle units sent at them one or two at a
+ // time were the biggest loss to defences in 32 Hard against Medium matches. They go only with odds
+ // that win, Easy the least careful. A unit that can move is still met wherever it stands at home:
+ // gating those too slowed the quick wins on small maps and lost more over the longer matches.
+ static const Real OUTSIDE_BASE_ODDS[ AISKILL_COUNT ] = { 1.0f, 1.5f, 2.0f };
+ if( intruder->isKindOf( KINDOF_IMMOBILE ) &&
+ sqr( intruder->getPosition()->x - m_baseCenter.x ) + sqr( intruder->getPosition()->y - m_baseCenter.y ) > sqr( m_baseRadius ) &&
+ homePower < OUTSIDE_BASE_ODDS[ m_skillLevel ] * intruderWorth )
+ return;
Int sent = 0;
for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )
@@ -7330,8 +7340,8 @@ void AIPlayer::defendHome( void )
++sent;
}
if( sent > 0 )
- DEBUG_LOG(("AI DEFEND frame %d player %d sends %d idle units at the intruder at (%.0f,%.0f)\n", TheGameLogic->getFrame(),
- m_player->getPlayerIndex(), sent, intruder->getPosition()->x, intruder->getPosition()->y));
+ DEBUG_LOG(("AI DEFEND frame %d player %d sends %d idle units at the intruder '%s' at (%.0f,%.0f)\n", TheGameLogic->getFrame(),
+ m_player->getPlayerIndex(), sent, intruder->getTemplate()->getName().str(), intruder->getPosition()->x, intruder->getPosition()->y));
}
/** How often the army is looked at for a part of the enemy's nothing answers, how big a part has to be