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(gamelogic): ambulance gives up on spills it cannot reach

Olcay Seygan0f14ea603218
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dd5ba833e..7e48aad46 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -363,7 +363,7 @@ found and fixed — EA's own, not port damage.**
- Campaign reinforcements flown in by Chinook land again. That one-at-a-time unloading sent a mission's scripted Chinooks home with their cargo still aboard, so on the second American mission the dozers announced at the docks never got off, and neither did the next one.
- A guarding unit no longer fights itself between returning to post and shooting back.
- Every unit of yours on guard carries a small steel shield over its head, selected or not, in place of the blocky "G" it used to wear. The shield has smooth edges and a lit and a shaded half, and it shrinks as you zoom out the way the health bars do: at 1080p it was 24 pixels tall over every unit at every zoom, and it is now 18 up close and 11 from the opening camera, about the height of an infantryman's head.
-- An Ambulance cleans up the toxins around it without being told. Its hose reaches 100, and that was all it ever looked at, so one parked a truck's length from a toxin pool sat and watched it. Standing idle or on guard, it now notices a pool, an anthrax cloud or a radiation field up to 300 away, drives over, washes off every one in that circle, and goes back to where it stood; one that was on guard is back on guard. A unit you are moving is never pulled off its order, and any order you give while it is cleaning ends the cleanup. Put down 150 to 250 from two Ambulances, one idle and one guarding, three poison fields were gone inside 16 seconds, both trucks were back on their spots, and a third Ambulance driving past a fourth field went straight on to where it was sent. The Cleanup Area button works better for it too: an Ambulance sent to clean an area used to shoot only at what was already in reach once it got there and stood still in front of the rest, and once the area was clean it never counted as idle again, so it ignored the next spill. An Ambulance guarding a tank goes back to guarding the tank after a cleanup, not the patch of ground it left from, so it follows the tank again: with the tank driven 600 away after the cleanup, the Ambulance reached it 17 seconds later. One that gives up on a spill it cannot drive up to no longer goes back for the same spill every time it stands idle; telling it to clean the area yourself still sends it. Giving up never actually happened, though: it counted only the looks that found it standing still, and it ordered the drive again every time it stopped, so a look nearly always caught it moving. It now gives up after eight looks in a row that find it parked no nearer the spill, and leaves the whole patch round it alone, since a toxin field is many spills and the next one in the same field drew it straight back. One still driving, round a river say, is left to get there. The computer's Ambulances keep to that too, and one the computer pulls off a cleanup under fire leaves that patch alone afterwards instead of being sent straight back to it. Replays recorded before this change play out differently.
+- An Ambulance cleans up the toxins around it without being told. Its hose reaches 100, and that was all it ever looked at, so one parked a truck's length from a toxin pool sat and watched it. Standing idle or on guard, it now notices a pool, an anthrax cloud or a radiation field up to 300 away, drives over, washes off every one in that circle, and goes back to where it stood; one that was on guard is back on guard. A unit you are moving is never pulled off its order, and any order you give while it is cleaning ends the cleanup. Put down 150 to 250 from two Ambulances, one idle and one guarding, three poison fields were gone inside 16 seconds, both trucks were back on their spots, and a third Ambulance driving past a fourth field went straight on to where it was sent. The Cleanup Area button works better for it too: an Ambulance sent to clean an area used to shoot only at what was already in reach once it got there and stood still in front of the rest, and once the area was clean it never counted as idle again, so it ignored the next spill. An Ambulance guarding a tank goes back to guarding the tank after a cleanup, not the patch of ground it left from, so it follows the tank again: with the tank driven 600 away after the cleanup, the Ambulance reached it 17 seconds later. One that gives up on a spill it cannot drive up to no longer goes back for the same spill every time it stands idle; telling it to clean the area yourself still sends it. Giving up never actually happened, though: it counted only the looks that found it standing still, and it ordered the drive again every time it stopped, so a look nearly always caught it moving. It now gives up after eight looks in a row that find it parked no nearer the spill, and leaves the whole patch round it alone, since a toxin field is many spills and the next one in the same field drew it straight back. One still driving, round a river say, is left to get there, but not for ever: 20 seconds on one patch with nothing washed off and no nearer and it gives up too. Sent at two fields on a cliff top, an Ambulance stayed under the cliff for the fields' whole lifetime without once giving up, and never went for a third field put down on open ground 225 away. In the same test now it gives up on the cliff top 22 seconds after it set off, never looks at that patch again, not even at a fresh field put down there, and washes the open-ground field away. The computer's Ambulances keep to that too, and one the computer pulls off a cleanup under fire leaves that patch alone afterwards instead of being sent straight back to it. Replays recorded before this change play out differently.
- Jets on guard attack what is inside the circle you drew. A plane on guard flies to its post and circles it, and since guards stopped shooting at enemies hidden in fog it only went after what that loop brought into its own sight: a Raptor guarding a circle of 700 hung over the post for the whole 80 seconds of the test with a power plant 550 out, and an Aurora circled for ten seconds before it found the same one. Aircraft are back on the original rule and take anything in the circle, fog or not. The Raptor's first missiles now land 11 seconds after the order and the Aurora's bomb after 9, and neither flies over the post first. Ground units still leave alone what they cannot see. A replay recorded before this change plays back differently.
- H now sets a stance for the group. Defensive is how your units have always behaved: they fire on what comes into range and stay put. Aggressive lets them go after anything they can see, the way the computer's own units do, so a group left on aggressive clears the ground around it without being told. The button shows the stance the selection holds.
- A queued attack move finishes its fights before the next order on the list goes out. The first enemy it met used to count as arriving, so a list of attack moves round a town skipped ahead a step at every skirmish and the group was off to the last point while the first was still contested. Replays recorded before this version play back differently.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index ff2152cc2..0d8e81bf3 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -163,6 +163,7 @@ Data/Scenarios/airbelow.txt
Data/Scenarios/airbelowfar.txt
Data/Scenarios/alphaaurora.txt
Data/Scenarios/ambulanceclean.txt
+Data/Scenarios/ambulancegiveup.txt
Data/Scenarios/ambulanceguard.txt
Data/Scenarios/aurorablast.txt
Data/Scenarios/aurorafog.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/ambulancegiveup.txt b/GeneralsMD/Code/Data/Scenarios/ambulancegiveup.txt
new file mode 100644
index 000000000..8e1984fbd
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/ambulancegiveup.txt
@@ -0,0 +1,54 @@
+# Does an Ambulance give up on a toxin field it cannot drive up to, once, and leave that ground alone?
+#
+# Twilight Flame's cliff plateau from 2300,3775 to 2650,4175 (a headless probe grid of Ambulances,
+# 2026-10-14; the thin cliff strip near 850,3850 can be driven round) takes two
+# poison fields 50 apart in its middle, 2450,3975 and 2450,3925. An idle Ambulance on the open ground at
+# 2700,3975, 250 east, notices them by itself (CleanupHazardUpdate::startAutoCleanup, 300 reach),
+# drives to the cliff foot and stalls there out of its hose's 100. After eight scans in a row parked
+# no nearer it should log "CLEANUP ... gave up on a hazard it cannot reach" and drive back to where it
+# started, and never set off for that ground again: not for the two fields, and not for a fresh one
+# put on the same spot at 600. A field at 2700,4200 on open ground at 750 proves it still cleans
+# what it can reach.
+#
+# The five probe spawns at 20 use the Ambulance's own locomotor: each must log "SCENARIO: ... refused
+# at (x,y): cell type ... (CLIFF)", the middle and four points 100 out from it. If any of them is put
+# down, the Ambulance can reach that ground and the run proves nothing; move the fields.
+#
+# What to read (CLEANUP lines count logic frames, 60 a second; this file and the SCENARIO and TALLY
+# lines count 30 a second, so file frame 750 is logic frame 1500):
+# grep "CLEANUP" <prefix>DebugLogFile.txt
+# "goes to clean by itself round (2700,3975)" at 121, then exactly one "gave up on a hazard it
+# cannot reach" at 1463, the eight-scan one (", no progress in time" is the 20 s fallback), and no
+# "scan:" line on the plateau hazards after it. The next "goes to clean by itself" is for the open
+# field (2378 in the 2026-10-14 run), ending in "area clean" at 2805. Each "scan:" line gives
+# distance, reach, how far it drove since the last scan, the stall count, frames since progress
+# and the AI state (1 move, 10 attack, 0 idle).
+# grep "HEADLESS TALLY" <prefix>DebugLogFile.txt
+# 2 alive at 740 and 2 at 1100, all left alone or not yet reached (a field lives 900 file frames:
+# the first two run out at 960); 1 at 1420, after the open-ground one is cleaned: only the 600 one
+# on the plateau, which runs out at 1500.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 3600
+# -scenario ambulancegiveup -logPrefix ambulancegiveup_
+#
+# Run 2026-10-14: give-up at 1463, open field cleaned at 2805. See mobstress.txt for the line grammar.
+
+20 spawn 0 AmericaVehicleMedic 1 2450 3975
+20 spawn 0 AmericaVehicleMedic 1 2450 3875
+20 spawn 0 AmericaVehicleMedic 1 2450 4075
+20 spawn 0 AmericaVehicleMedic 1 2350 3975
+20 spawn 0 AmericaVehicleMedic 1 2550 3975
+
+30 spawn 0 AirF_AmericaVehicleMedic 1 2700 3975
+
+60 spawn 1 PoisonFieldMedium 1 2450 3975
+60 spawn 1 PoisonFieldMedium 1 2450 3925
+
+600 spawn 1 PoisonFieldMedium 1 2450 3975
+740 tally 1 PoisonFieldMedium
+
+750 spawn 1 PoisonFieldMedium 1 2700 4200
+1100 tally 1 PoisonFieldMedium
+1420 tally 1 PoisonFieldMedium
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/CleanupHazardUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/CleanupHazardUpdate.h
index 3eb7e887f..a7704c7ef 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/CleanupHazardUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/CleanupHazardUpdate.h
@@ -108,6 +108,8 @@ protected:
Coord3D m_approachPos; ///< where the hazard it is after stood when the count began; any within GIVEN_UP_RADIUS is the same ground
Coord3D m_lastScanPos; ///< where it stood on the last scan that counted
Real m_closestApproach; ///< the nearest it has come to a hazard on that ground
+ UnsignedInt m_progressFrame; ///< the last frame of progress in the area: started, nearer, a hazard hosed or gone
+ ObjectID m_lastTargetID; ///< the hazard the last scan found
ObjectID m_resumeGuardObject; ///< the object it was guarding when a cleanup took it off guard, or INVALID_ID for a spot
Bool m_hasGivenUp; ///< m_givenUpPos holds ground it gave up on
Coord3D m_givenUpPos; ///< where the last hazard it gave up on as out of reach stood; none near it is gone for again
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index c3e506165..763cb851f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -2873,6 +2873,13 @@ void AIPlayer::onUnitLost( const Object *obj )
team ? team->getName().str() : "", obj->getAI() ? (Int)obj->getAI()->getCurrentStateID() : -1,
obj->getAI() ? (Int)obj->getAI()->getLastCommandSource() : -1,
(Real)sqrt( sqr( obj->getPosition()->x - m_baseCenter.x ) + sqr( obj->getPosition()->y - m_baseCenter.y ) )));
+ // what killed a duty Ambulance, from how far, and whether this AI knew of it
+ if( isSkirmishAI() && isDutyAmbulance( obj ) )
+ DEBUG_LOG(("AI AMBULANCE frame %d player %d %d killed by '%s' %.0f away, %s, %s\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(),
+ obj->getID(), killer ? killer->getTemplate()->getName().str() : "nothing known",
+ killer ? (Real)sqrt( sqr( killer->getPosition()->x - obj->getPosition()->x ) + sqr( killer->getPosition()->y - obj->getPosition()->y ) ) : -1.0f,
+ killer && observerKnowsAbout( killer, m_player->getPlayerIndex() ) ? "known" : "unseen",
+ killer && killer->isKindOf( KINDOF_AIRCRAFT ) ? "aircraft" : killer && killer->isKindOf( KINDOF_STRUCTURE ) ? "building" : "ground"));
if( isSkirmishAI() && obj->isKindOf( KINDOF_STRUCTURE ) && aiCombatPower( obj ) > 0.0f )
DEBUG_LOG(("AI DEFDEAD frame %d player %d '%s' worth %.0f\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(),
obj->getTemplate()->getName().str(), aiCombatPower( obj )));
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
index 8d4db3dbd..bdeaa0753 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp
@@ -69,6 +69,10 @@ static const Real CLEANUP_DRIVEN = 20.0f;
makes the hazards of one field one target for the give-up count. */
static const Real GIVEN_UP_RADIUS = 150.0f;
+/** How long an area cleaner goes with no hazard hosed or gone and no nearer to one before it gives the
+ area up, whatever the scan count says. A field takes seconds to hose down. */
+static const UnsignedInt CLEANUP_STUCK_FRAMES = 20 * LOGICFRAMES_PER_SECOND;
+
/** One scan of an area cleaner out of reach of its hazard: whether it counts toward giving up. It does
when the cleaner stands no CLEANUP_PROGRESS nearer than the nearest it had come and has driven under
CLEANUP_DRIVEN since the last scan. One driving round a river or a cliff gets no nearer for a while
@@ -142,6 +146,8 @@ CleanupHazardUpdate::CleanupHazardUpdate( Thing *thing, const ModuleData* module
m_approachPos.zero();
m_lastScanPos.zero();
m_closestApproach = 0.0f;
+ m_progressFrame = 0;
+ m_lastTargetID = INVALID_ID;
m_resumeGuardObject = INVALID_ID;
m_hasGivenUp = FALSE;
m_givenUpPos.zero();
@@ -242,35 +248,73 @@ UpdateSleepTime CleanupHazardUpdate::update()
// fireWhenReady orders the drive again whenever it stops, so a scan nearly always found it moving
// and the count never got anywhere. Counted for the ground, not the one hazard: the nearest of a
// toxin field changes as it drives, and each change started the count over
+ //
+ // And by time: in the cliff-top run (ambulancegiveup.txt on Twilight Flame) the count never reached
+ // its eight in 6,000 frames, though nothing was ever cleaned, so whatever the scans read, an area
+ // that has seen no progress for CLEANUP_STUCK_FRAMES is given up as well. The clock starts with
+ // the area; progress is a scan that finds it CLEANUP_PROGRESS nearer, the hazard it finds hit since
+ // the last scan, or the one it was after gone (cleaned, or run out). Driving is not: the likeliest
+ // reading of that run is a cleaner shuttling along the cliff foot, over CLEANUP_DRIVEN a scan, which
+ // the count takes for a drive round. Each scan logs what it read, so the next run says which of the
+ // two fired and why.
WeaponBonus bonus;
bonus.clear();
const Real distance = (Real)sqrt( ThePartitionManager->getDistanceSquared( obj, found, FROM_CENTER_2D ) );
- if( m_moveRange > 0.0f && distance > m_weaponTemplate->getAttackRange( bonus ) )
+ const Real reach = m_weaponTemplate->getAttackRange( bonus );
+ if( m_moveRange > 0.0f )
{
const Coord3D *at = found->getPosition();
const Coord3D *here = obj->getPosition();
+ const UnsignedInt now = TheGameLogic->getFrame();
+ const Real driven = (Real)sqrt( sqr( here->x - m_lastScanPos.x ) + sqr( here->y - m_lastScanPos.y ) );
+ if( !m_approaching )
+ m_progressFrame = now; // the clock runs from the start of the area, not of each ground in it
if( !m_approaching || sqr( at->x - m_approachPos.x ) + sqr( at->y - m_approachPos.y ) > sqr( GIVEN_UP_RADIUS ) )
{
+ // fireWhenReady drives only an idle or busy cleaner, and one still on its way to the old ground
+ // (in that run, never there) passed by a field it could reach for 900 frames. Two grounds whose
+ // nearest swaps as it drives are not ordered: only ground nearer by CLEANUP_PROGRESS than the old
+ if( m_approaching && distance > reach && distance <= m_closestApproach - CLEANUP_PROGRESS )
+ {
+ obj->getAI()->aiIdle( CMD_FROM_AI );
+ obj->getAI()->aiMoveToPosition( at, CMD_FROM_AI );
+ }
m_approaching = TRUE;
m_approachPos = *at;
m_closestApproach = distance;
m_approaches = 0;
}
- else if( !CleanupHazard_stalls( distance, (Real)sqrt( sqr( here->x - m_lastScanPos.x ) + sqr( here->y - m_lastScanPos.y ) ), &m_closestApproach ) )
- m_approaches = 0;
- else if( ++m_approaches > MAX_CLEANUP_APPROACHES )
+ else
+ {
+ // progress for the clock: the hazard it was after gone, the one found hit since the last scan
+ // (whichever of two puddles in reach is nearest), or a CLEANUP_PROGRESS nearer. Driving is not:
+ // one shuttling along a cliff foot drives every scan
+ const Bool targetGone = m_lastTargetID != INVALID_ID && TheGameLogic->findObjectByID( m_lastTargetID ) == NULL;
+ const Bool sameHazard = found->getID() == m_lastTargetID;
+ const Bool hosed = found->getBodyModule()->getLastDamageTimestamp() + data->m_scanFrames >= now;
+ // another hazard of the same ground being nearer is no progress: the plateau run swapped from
+ // one field to the other at frame 1219, and the nearer reading started the clock over
+ if( !sameHazard )
+ m_closestApproach = min( m_closestApproach, distance );
+ if( targetGone || hosed || distance <= m_closestApproach - CLEANUP_PROGRESS )
+ m_progressFrame = now;
+ if( distance > reach && CleanupHazard_stalls( distance, driven, &m_closestApproach ) )
+ ++m_approaches;
+ else
+ m_approaches = 0;
+ }
+ DEBUG_LOG(("CLEANUP frame %d '%s' %d scan: hazard %d %.0f away, reach %.0f, drove %.0f, nearest %.0f, %d stalls, %d frames since progress, state %d\n",
+ now, obj->getTemplate()->getName().str(), obj->getID(), found->getID(), distance, reach, driven, m_closestApproach, m_approaches,
+ (Int)(now - m_progressFrame), (Int)obj->getAI()->getCurrentStateID()));
+ m_lastScanPos = *here;
+ m_lastTargetID = found->getID();
+ if( m_approaches >= MAX_CLEANUP_APPROACHES || now - m_progressFrame > CLEANUP_STUCK_FRAMES )
{
m_hasGivenUp = TRUE;
- m_givenUpPos = *at;
- finishArea( "gave up on a hazard it cannot reach", TRUE );
+ m_givenUpPos = m_approachPos;
+ finishArea( m_approaches >= MAX_CLEANUP_APPROACHES ? "gave up on a hazard it cannot reach" : "gave up on a hazard it cannot reach, no progress in time", TRUE );
return UPDATE_SLEEP_NONE;
}
- m_lastScanPos = *here;
- }
- else
- {
- m_approaches = 0;
- m_approaching = FALSE;
}
//1 frame can make a big difference so fire ASAP!
fireWhenReady();
@@ -549,13 +593,14 @@ void CleanupHazardUpdate::crc( Xfer *xfer )
* 1: Initial version
* 2: the guard a cleanup it started by itself gives back, the walk back, the drives toward a hazard
* 3: the object that guard was on, the hazard given up on
- * 4: the ground given up on instead of the one hazard, and the ground it is after with how near it has come */
+ * 4: the ground given up on instead of the one hazard, and the ground it is after with how near it has come
+ * 5: the frame it last made progress in the area, and the hazard it was after at the last scan */
// ------------------------------------------------------------------------------------------------
void CleanupHazardUpdate::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 4;
+ XferVersion currentVersion = 5;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -606,6 +651,13 @@ void CleanupHazardUpdate::xfer( Xfer *xfer )
xfer->xferCoord3D( &m_lastScanPos );
xfer->xferReal( &m_closestApproach );
}
+ if( version >= 5 )
+ {
+ xfer->xferUnsignedInt( &m_progressFrame );
+ xfer->xferObjectID( &m_lastTargetID );
+ }
+ else
+ m_progressFrame = TheGameLogic->getFrame();
} // end xfer