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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): ai ambulance calls only wounded out of the fight
Olcay Seygan8b268f2ca3df
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f5b7b9234..7ba0bbee3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -204,6 +204,7 @@ 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.- 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, three 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/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex c08bb1e34..7e99962c6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -9234,8 +9234,27 @@ void AIPlayer::sendWave( AIGroup *wave, const AsciiString &approach, Int pathSufAsciiString pathLabel;pathLabel.format( "%s%d", approach.str(), pathSuffix );Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( ¢er, pathLabel );- DEBUG_LOG(("AI WAVE frame %d player %d sends %d teams, %d units, %.0f power, after %d s, down %s\n", TheGameLogic->getFrame(),- m_player->getPlayerIndex(), teams, wave->getCount(), power, heldFrames / LOGICFRAMES_PER_SECOND, pathLabel.str()));+ // the ranked units pullOutRanked has out of their teams, mending or on the way, against the whole army+ Int rankedOut = 0;+ Real rankedOutPower = 0.0f;+ Real armyPower = 0.0f;+ std::vector<Object *> owned;+ m_player->iterateObjects( collectOwned, &owned );+ for( size_t o = 0; o < owned.size(); ++o )+ {+ const Object *obj = owned[ o ];+ if( obj->isEffectivelyDead() || obj->isKindOf( KINDOF_STRUCTURE ) || obj->getAI() == NULL )+ continue;+ const Real unitPower = aiCombatPower( obj );+ armyPower += unitPower;+ if( obj->getVeterancyLevel() > LEVEL_REGULAR && !obj->getAI()->isRecruitable() && obj->getTeam() == m_player->getDefaultTeam() )+ {+ ++rankedOut;+ rankedOutPower += unitPower;+ }+ }+ DEBUG_LOG(("AI WAVE frame %d player %d sends %d teams, %d units, %.0f power, after %d s, down %s; %d ranked out mending, %.0f of %.0f army power\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), teams, wave->getCount(), power, heldFrames / LOGICFRAMES_PER_SECOND, pathLabel.str(), rankedOut, rankedOutPower, armyPower));if( way == NULL )return;std::vector<Object *> units;@@ -10799,7 +10818,7 @@ void AIPlayer::doHelixes( void )* through the support-unit queue. An Ambulance waits* AMBULANCE_BEHIND back from the middle of whoever is out, toward home and clear of every known gun,* or at home with nobody out. The cash hoard does not hold it back, since a USA at war banks under- * the hoard all match. Our infantry within AMBULANCE_CALL_REACH of it and under half health+ * the hoard all match. Our infantry within AMBULANCE_CALL_REACH of it, under half health and not hit lately,* walk over and climb in, and each is let out once it is whole. It drives to the nearest hazard* on our side of the map that no known gun covers; one beside it it notices by itself* (CleanupHazardUpdate::startAutoCleanup).@@ -10821,7 +10840,8 @@ static const Int AMBULANCE_CHECK_RATE = LOGICFRAMES_PER_SECOND;static const Int AMBULANCE_FIRST_ARMY = 8;static const Int AMBULANCE_SECOND_ARMY = 20;static const Real AMBULANCE_PATIENT_HEALTH = 0.5f;-static const Real AMBULANCE_CALL_REACH = 450.0f;+static const Real AMBULANCE_CALL_REACH = 900.0f;+static const UnsignedInt AMBULANCE_PATIENT_QUIET = 2 * LOGICFRAMES_PER_SECOND;static const Real AMBULANCE_BEHIND = 300.0f;static const Real AMBULANCE_HAZARD_REACH = 1500.0f;/** The cleanup ability's MaxMoveDistanceFromLocation in retail AmericaVehicle.ini. */@@ -10864,10 +10884,15 @@ Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReac/** What becomes of each one called is in the AI PATIENT lines. In one Hard and one Medium match (ambC,* 2026-10-11) 10 of 15 died on the way, every one within three seconds of the call, so in the fight* that hurt it; every one that lived to climb in was let out whole. Leaving out whoever was hit in the- * last four seconds called nobody at all in the same two matches. */-Bool AIAmbulance_callsPatient( Real healthFraction, Real distance )+ * last four seconds called nobody at all in the same two matches.+ *+ * So one still being shot is not called, and one left alone for AMBULANCE_PATIENT_QUIET is, from twice+ * the old 450. In six Hard USA mirrors on Twilight Flame (2026-10-11) every hurt soldier within 450 had+ * been hit in the last two seconds; the quiet ones, out of the fight, stood 450 to 1,500 away for ten+ * seconds and more, which is the walk back toward an Ambulance waiting behind the army. */+Bool AIAmbulance_callsPatient( Real healthFraction, Real distance, UnsignedInt sinceHit ){- return healthFraction < AMBULANCE_PATIENT_HEALTH && distance <= AMBULANCE_CALL_REACH;+ return healthFraction < AMBULANCE_PATIENT_HEALTH && distance <= AMBULANCE_CALL_REACH && sinceHit >= AMBULANCE_PATIENT_QUIET;}/** A vehicle with a hold that cleans hazards: the Ambulance, and each general's copy of it. */@@ -11127,8 +11152,9 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )continue;const BodyModuleInterface *body = obj->getBodyModule();const Real distance = (Real)sqrt( sqr( obj->getPosition()->x - pos->x ) + sqr( obj->getPosition()->y - pos->y ) );- if( state == AI_ENTER || state == AI_DOCK || state >= 1000 || !hold->isValidContainerFor( obj, TRUE ) ||- !AIAmbulance_callsPatient( body->getHealth() / body->getMaxHealth(), distance ) )+ if( state == AI_ENTER || state == AI_DOCK || state >= 1000 || !hold->isValidContainerFor( obj, TRUE ) )+ continue;+ if( !AIAmbulance_callsPatient( body->getHealth() / body->getMaxHealth(), distance, now - body->getLastDamageTimestamp() ) )continue;leaveTacticsAlone( obj->getID() );// out of its team until it is let out, or the team's next script order walks it off (see releaseMended)diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 2630495db..9499ca19d 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -11236,7 +11236,7 @@ TEST(the_ai_pulls_ranked_units_out_sooner_the_higher_the_rank)/** AIPlayer.cpp: the computer buys its first Ambulance once it has an army and a second once the armyis big, and calls in the badly hurt from near it only. */extern Int AIAmbulance_wanted( Int army, Int skill );-extern Bool AIAmbulance_callsPatient( Real healthFraction, Real distance );+extern Bool AIAmbulance_callsPatient( Real healthFraction, Real distance, UnsignedInt sinceHit );extern Bool AIAmbulance_mayBuyMore( Int bought, Int skill );TEST(the_ai_buys_ambulances_by_army_and_calls_in_the_hurt_nearby)@@ -11257,12 +11257,14 @@ TEST(the_ai_buys_ambulances_by_army_and_calls_in_the_hurt_nearby)CHECK( !AIAmbulance_mayBuyMore( 3, AISKILL_MEDIUM ) );CHECK( !AIAmbulance_mayBuyMore( 0, AISKILL_EASY ) );- CHECK( AIAmbulance_callsPatient( 0.3f, 100.0f ) );- CHECK( AIAmbulance_callsPatient( 0.49f, 450.0f ) );+ CHECK( AIAmbulance_callsPatient( 0.3f, 100.0f, 60 ) );+ CHECK( AIAmbulance_callsPatient( 0.49f, 900.0f, 60 ) );// half health or more stays in the fight- CHECK( !AIAmbulance_callsPatient( 0.5f, 100.0f ) );+ CHECK( !AIAmbulance_callsPatient( 0.5f, 100.0f, 60 ) );// too far off to walk over- CHECK( !AIAmbulance_callsPatient( 0.1f, 451.0f ) );+ CHECK( !AIAmbulance_callsPatient( 0.1f, 901.0f, 60 ) );+ // still being shot: it would die on the way+ CHECK( !AIAmbulance_callsPatient( 0.3f, 100.0f, 59 ) );}/** AIPlayer.cpp: an Ambulance pulls back when shot at or inside a known gun's reach, and a lost one is