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 ai ambulance patients and cleanups on their order

Olcay Seygan4d1f08bbe2d4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1f666b60..879fab0e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -204,7 +204,8 @@ found and fixed — EA's own, not port damage.**
- The USA computer fields Ambulances. It never built one before. On Medium and Hard it buys one once eight fighting units stand and a second at twenty, and keeps them a little behind the middle of its army, short of every gun of yours it knows about. A soldier of its own under half health who stands near one walks over and climbs in, and gets out again once he is whole. Toxins, anthrax and radiation on its own side of the map get driven to and washed off. Over six Hard matches against GLA on Twilight Flame it ordered 26 Ambulances, called 10 wounded men in and sent them on 19 cleanups of its own ground. They also die a lot: 24 of the 25 that rolled out were lost, and those six matches went no better for the USA than the same six without them (no win either way, 57 kills a match where it had 66). Replays recorded before this change play out differently.
- Its Ambulances keep their heads down. A truck with no gun and 240 health used to park a short way behind the army and keep washing the toxins of the fight it stood in. Now one that takes a hit, or finds itself inside the reach of a gun it knows about, drops whatever it was doing, the cleanup too, and backs off towards home to the first ground none of those guns covers. Under half health it drives to the War Factory to be repaired, and the soldiers inside go on healing on the way. It waits twice as far behind the army as before and only cleans a spill well clear of any known gun. A lost Ambulance is replaced after a minute and a half, not the moment the bank allows. Each soldier inside gets out as soon as he is whole rather than waiting for the slowest one, and a soldier walking to the Ambulance leaves his squad until he is out, so the squad's next order no longer marches him away from the door. Over twenty matches with Hard computers on Winter Wolf, 13 of 23 Ambulances were lost where 23 of 26 had been. The share of wounded men who come back out did not move, 18 of the 94 called in against 22 of 108, and why the rest never get out is not known yet. Replays recorded before this change play out differently.
- The USA computer stops flooding the field with Ambulances. Each lost one used to be bought again every minute and a half, and two USA computers put eight on the road in one sixteen-minute match. Hard now buys six in a whole match at most and Medium three, and Medium keeps only one at a time and waits three minutes to replace it. An Ambulance under fire backs out of reach before it heads for the War Factory to be repaired: sent straight there, it took the shortest road, often through the guns that had hurt it, and 20 of 31 lost Ambulances died on that drive. It no longer drives ahead of the army to wash a toxin pool, which is where three of the four lost in one Hard match died. The wounded men who never came back out are accounted for too. Of 23 called in over six test matches, 17 died within three seconds of the call, still in the fight that hurt them, and the other six all reached an Ambulance and walked out whole. Replays recorded before this change play out differently.
-- The USA computer stops calling its wounded out of a firefight. A soldier still being shot at stays put, and one who has had two seconds' peace walks over from up to twice as far as before, since the hurt men who live through a fight end up well behind the Ambulance's old reach. In six Hard and six Medium matches between two USA computers on Twilight Flame, 14 were called in and none died within three seconds of the call, where 17 of 23 had; six were healed and walked out whole, three died on the walk four to nine seconds later, and four gave up the walk for a reason not yet known. Replays recorded before this change play out differently.
+- The USA computer stops calling its wounded out of a firefight. A soldier still being shot at stays put, and one who has had two seconds' peace walks over from up to twice as far as before, since the hurt men who live through a fight end up well behind the Ambulance's old reach. In six Hard and six Medium matches between two USA computers on Twilight Flame, 14 were called in and none died within three seconds of the call, where 17 of 23 had; six were healed and walked out whole, three died on the walk four to nine seconds later, and four gave up the walk. Two of those four were the computer's own doing: ten seconds into the walk its fight logic saw a hurt soldier and pulled him back towards home, or sent him back to his squad, or its retreat order took him home with the squad he had left. A soldier walking to an Ambulance now gets no other order until he is inside. The same six matches now lose two on the walk where they lost four; those two stood still at the door of an Ambulance they could not reach and gave up, which is still open. Replays recorded before this change play out differently.
+- The computer's Ambulance only cleans the spills it is sent to. Parked behind the army, it used to notice a toxin pool by itself up to 300 ahead and drive into the fight to wash it, past the line the computer keeps it behind. Over twelve Hard against Medium matches between the USA and GLA on Twilight Flame, 7 of 25 lost Ambulances had died within half a minute of a cleanup they started on their own, 650 to 1,350 from home. With the same matches played again, none started one by itself, and 21 were lost. Replays recorded before this change play out differently.
- It comes at you from two sides. An attack big enough to be two sends a third of its strength down the second-quietest road, so you cannot meet the whole thing in one place.
- It holds ground between attacks. Hard gathers its next wave a third of the way along the road to you, not in front of its own base, as long as nothing it has seen can shoot at that spot; otherwise it gathers at home.
- It builds its economy before it comes for you. No attack leaves a computer base in the opening minutes: six on Easy, five on Medium, four on Hard, and on Medium and Hard not before its first supply drop zone or black market stands, when it can build one. Medium and Easy now put that drop zone or black market up in the opening too, where only Hard did before. And it stops sending you two tanks at a time. A group too small to matter waits at home until enough has gathered to be an attack, about two tanks' worth on Easy, two and a half on Medium and five on Hard, even when the computer thinks it is winning. In one Hard against Hard match on Twilight Flame, the USA side's first attack left at six minutes instead of three and a quarter, after its drop zone, and the two sides sent 24 attacks instead of 47, 12 of them one to four units where 43 had been. Medium sent 9 instead of 19. Replays recorded before this change play out differently.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index fe1a3747c..651e86466 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -629,6 +629,9 @@ public:
/// One of this player's units died; the AI keeps count of the ones that died alone.
void onUnitLost(const Object *obj);
+ /// TRUE for an Ambulance the AI drives behind its army; it cleans only the hazards the AI sends it to.
+ Bool isAIDutyAmbulance(const Object *obj) const;
+
/// Get the center of the ai's base.
virtual Bool getAiBaseCenter(Coord3D *pos);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index 2da9e98ee..5da8d2489 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -474,6 +474,7 @@ public:
Bool isDutyChinook( const Object *obj ) const; ///< either of those, which the gatherer counts leave out
Bool isDutyHelix( const Object *obj ) const; ///< a Helix this AI bought to heal or to raid, which nothing else gives orders
Bool isDutyAmbulance( const Object *obj ) const; ///< an Ambulance this AI bought to follow the army, which nothing else gives orders
+ Bool isWalkingToAmbulance( const Object *obj ) const; ///< a patient on its way into a duty Ambulance, which nothing else gives orders either
protected:
/**
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 4ad2e5b05..1cd46dfc8 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -1673,6 +1673,12 @@ void Player::onUnitLost(const Object *obj)
m_ai->onUnitLost(obj);
}
+//-------------------------------------------------------------------------------------------------
+Bool Player::isAIDutyAmbulance(const Object *obj) const
+{
+ return m_ai ? m_ai->isDutyAmbulance(obj) : FALSE;
+}
+
//-------------------------------------------------------------------------------------------------
/** Do any bridges need repair, and if so repair them. */
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 7e99962c6..961ac8fc8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -10915,6 +10915,12 @@ Bool AIPlayer::isDutyAmbulance( const Object *obj ) const
return FALSE;
}
+Bool AIPlayer::isWalkingToAmbulance( const Object *obj ) const
+{
+ AIUpdateInterface *ai = const_cast<Object *>( obj )->getAI(); // getGoalObject is not const
+ return ai && ai->getCurrentStateID() == AI_ENTER && ai->getGoalObject() && isDutyAmbulance( ai->getGoalObject() );
+}
+
/** For the log only: what became of each patient an Ambulance called in. It climbs in, then is let out
* or dies inside; or it dies on the way; or something else gives it an order first and it walks off. */
void AIPlayer::followPatients( void )
@@ -10958,6 +10964,15 @@ void AIPlayer::followPatients( void )
DEBUG_LOG(("AI PATIENT frame %d player %d %d %s after %d s at %.0f%% health, %.0f from the ambulance; called at %.0f%% health from %.0f\n", now,
m_player->getPlayerIndex(), patient.id, outcome, (now - patient.frame) / LOGICFRAMES_PER_SECOND, health * 100.0f, away,
patient.health * 100.0f, patient.distance));
+ if( obj && !obj->isEffectivelyDead() && !patient.inside )
+ {
+ const Object *goal = obj->getAI()->getGoalObject();
+ DEBUG_LOG(("AI PATIENT frame %d player %d %d walk-off state %d source %d goal %d team '%s' recruitable %d hit %d s ago; ambulance state %d moving %d\n", now,
+ m_player->getPlayerIndex(), patient.id, (Int)obj->getAI()->getCurrentStateID(), (Int)obj->getAI()->getLastCommandSource(),
+ goal ? (Int)goal->getID() : 0, obj->getTeam() ? obj->getTeam()->getName().str() : "", (Int)obj->getAI()->isRecruitable(),
+ (now - obj->getBodyModule()->getLastDamageTimestamp()) / LOGICFRAMES_PER_SECOND,
+ ambulanceUp ? (Int)ambulance->getAI()->getCurrentStateID() : -1, ambulanceUp ? (Int)ambulance->getAI()->isMoving() : -1));
+ }
m_calledPatients.erase( m_calledPatients.begin() + p );
}
}
@@ -11556,6 +11571,10 @@ void AIPlayer::doRetreats( void )
// round at the mouth
if( obj->getAI()->hasTunnelTrip() )
continue;
+ // nor one walking to an Ambulance that called it in: sent home instead, it left the Ambulance
+ // hurt (the other 2 of the 4 walk-offs in six Hard USA mirrors)
+ if( isWalkingToAmbulance( obj ) )
+ continue;
// one that is kiting the fight is winning its own share of it however the totals read: a
// Rocket Buggy turned for home in front of four tanks it outran and outranged died turning
const TacticalStep *kiting = findTacticalStep( obj->getID() );
@@ -11794,8 +11813,10 @@ Bool AIPlayer::doFallback( Team *team )
// its safe spot when the hold ran out kept that walk, unmarked, and the same pass pulled it out
// again for another full hold. One with no gun has no fight to go back to: a Dozer pulled out of
// a fight was walked back into it.
+ // One walking to an Ambulance that called it in carries on too: walked home instead, it had left
+ // the Ambulance's enter order still hurt.
const Bool givesUp = what == AIFALLBACK_GO_HOME && !fightOver;
- if( (!givesUp && obj->getAI()->isMoving()) || (what == AIFALLBACK_RESUME && aiCombatPower( obj ) <= 0.0f) )
+ if( isWalkingToAmbulance( obj ) || (!givesUp && obj->getAI()->isMoving()) || (what == AIFALLBACK_RESUME && aiCombatPower( obj ) <= 0.0f) )
restoreMood( obj, step );
else if( what == AIFALLBACK_RESUME )
{
@@ -12333,7 +12354,10 @@ void AIPlayer::tacticsFor( Object *obj )
const TeamTemplateInfo *info = team->getPrototype()->getTemplateInfo();
if( info && (info->m_isBaseDefense || info->m_isPerimeterDefense) )
return;
- if( obj->getID() == m_capturerID || obj->getID() == m_hijackerID || isDutyHelix( obj ) || isDutyAmbulance( obj ) )
+ // nor a patient on its way into an Ambulance: past leaveTacticsAlone's ten seconds the pull-out and the
+ // rejoin walked 2 of 4 such patients off in six Hard USA mirrors on Twilight Flame (2026-10-11)
+ if( obj->getID() == m_capturerID || obj->getID() == m_hijackerID || isDutyHelix( obj ) || isDutyAmbulance( obj ) ||
+ isWalkingToAmbulance( obj ) )
return;
for( Int i = 0; i < MAX_AI_SCOUTS; ++i )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
index dcaba0ef1..a5b955f29 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
@@ -390,6 +390,11 @@ void CleanupHazardUpdate::startAutoCleanup()
const Bool guarding = ai->getCurrentStateID() == AI_GUARD;
if( !guarding && !ai->isIdle() )
return;
+ // the AI's own Ambulance cleans what the AI sends it to, which keeps it behind the army and clear of
+ // the guns it knows: by itself it drove up to 300 ahead of where it waited, and 7 of 25 lost in twelve
+ // Hard against Medium matches on Twilight Flame (2026-10-11) died within 30 s of a cleanup it started
+ if( obj->getControllingPlayer() && obj->getControllingPlayer()->isAIDutyAmbulance( obj ) )
+ return;
PartitionFilterAcceptByKindOf kindFilter(MAKE_KINDOF_MASK(KINDOF_CLEANUP_HAZARD), KINDOFMASK_NONE);
PartitionFilterSameMapStatus filterMapStatus(obj);