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): cap ai ambulances by difficulty, back off before repair
Olcay Seyganfb53cfc4be50
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3afd3c3a7..f62fd7731 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -202,6 +202,7 @@ found and fixed — EA's own, not port damage.**- Its Helixes have jobs. Every Helix the computer owned bought its upgrades in button order, so each one carried a battle bunker whatever it was up against, with napalm on top. A Helix in one of its attack or guard groups now looks at what it knows of your army first and takes the gattling cannon when most of your strength is on foot, the bunker when most of it is in vehicles, and the soldiers trained to sit in that bunker are Tank Hunters rather than Red Guards. Against GLA over four Hard matches that came out 15 bunkers to 6 cannons, each decided on the split at that moment. China on Medium and Hard also buys two Helixes as healers, a third once its army passes thirty units, each under a Propaganda Tower. They hang behind the attack over whichever of its units is most hurt, carry nobody, and pull away when they are hit or when anti-air they know of comes near; over twelve Hard matches they spent 93% of their time out of the base further from the nearest enemy gun than it could shoot. They used to bunch up over the same tank, which got nothing out of it: a unit inside two towers heals no faster than inside one. Each healer now keeps its spot at least a tower's reach, 150, from the others', going to the most hurt unit nobody else's tower already covers, or stepping sideways behind the attack until it is clear of theirs. Two more Helixes take the napalm bomb, or the Nuke General's nuclear one, and raid your base, a factory first and otherwise whatever pays for it or powers it. A raid comes in from the side your known anti-air does not cover, looks for a new way in when a gun turns up ahead, and turns for home when it is hit below half health. Over the same twelve matches 126 raids went out, 23 dropped their bomb, five buildings fell after a drop, and 31 raiders were shot down on a raid. A raider also stops bombing once its run is over. A Helix told to bomb a spot drops another bomb under itself every ten seconds until it gets a different order, and the computer's own orders never counted as one, so a raider that had bombed your base went on dropping napalm all the way home, over your soldiers on the way, and then on its own base for the rest of the match. Over eight Hard matches against America, 104 of 121 bombs fell nowhere near the building they were meant for. On the same matches now, each of the 14 bombs dropped lands on its building, and a raid that turns back before its drop no longer flies out again to finish it once it is home. The Infantry General's Helix has no tower, so it only raids. Replays recorded before this change play out differently.- 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.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex 31c7fc8dd..2dd3cb07c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -561,10 +561,26 @@ protected:{ObjectID id; ///< INVALID_ID for a free slotCoord3D spot; ///< where it was last sent+ Coord3D seen; ///< for the log only, not saved: where it stood on the last pass+ Real seenHealth; ///< for the log only, not saved: its health share on the last pass+ Real seenReach; ///< for the log only, not saved: how deep inside a known gun's reach it stood, negative when clear};enum { MAX_DUTY_AMBULANCES = 2 };DutyAmbulance m_ambulance[ MAX_DUTY_AMBULANCES ];UnsignedInt m_ambulanceLost; ///< the frame the last duty Ambulance was lost, 0 for never+ Int m_ambulancesBought; ///< duty Ambulances that came out this match+ /// for the log only, not saved: each patient an Ambulance called in, until it is let out, dies or walks off+ struct CalledPatient+ {+ ObjectID id;+ ObjectID ambulance;+ UnsignedInt frame;+ Real health;+ Real distance;+ Bool inside;+ };+ std::vector<CalledPatient> m_calledPatients;+ void followPatients(void);Int m_healerSeconds; ///< for the log only, not saved: healer seconds counted, and those clear of the nearest gun's reachInt m_healerClearSeconds;Int m_captureTimer; ///< frames until the next look for something to capturediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 84042a60e..8e597f3a2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -378,8 +378,12 @@ m_role(AIROLE_AGGRESSIVE){m_ambulance[ slot ].id = INVALID_ID;m_ambulance[ slot ].spot.zero();+ m_ambulance[ slot ].seen.zero();+ m_ambulance[ slot ].seenHealth = 1.0f;+ m_ambulance[ slot ].seenReach = 0.0f;}m_ambulanceLost = 0;+ m_ambulancesBought = 0;m_incomeMark = 0;m_incomeMarkFrame = 0;m_bankMark = 0;@@ -1816,8 +1820,12 @@ void AIPlayer::onUnitProduced( Object *factory, Object *unit )if (m_ambulance[slot].id == INVALID_ID) {m_ambulance[slot].id = unit->getID();m_ambulance[slot].spot = *unit->getPosition();- DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d comes out\n", TheGameLogic->getFrame(),- m_player->getPlayerIndex(), unit->getTemplate()->getName().str(), unit->getID()));+ m_ambulance[slot].seen = *unit->getPosition();+ m_ambulance[slot].seenHealth = 1.0f;+ m_ambulance[slot].seenReach = 0.0f;+ ++m_ambulancesBought;+ DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d comes out, %d bought this match\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), unit->getTemplate()->getName().str(), unit->getID(), m_ambulancesBought));break;}}@@ -10664,17 +10672,29 @@ static const UnsignedInt AMBULANCE_HIT_FRAMES = 4 * LOGICFRAMES_PER_SECOND;static const Real AMBULANCE_PULLBACK = 400.0f;static const Real AMBULANCE_REPAIR_HEALTH = 0.5f;static const UnsignedInt AMBULANCE_REBUY_FRAMES = 90 * LOGICFRAMES_PER_SECOND;+/** Medium keeps one at a time, waits twice as long to replace it and buys half as many in a match.+ * Each lost one was bought again on Hard every 90 seconds: eight came out of two USA seats in one+ * 16-minute match (ambA4_700), and a player counted dozens over a long game. */+static const Int AMBULANCE_MATCH_CAP[ AISKILL_COUNT ] = { 0, 3, 6 };-Int AIAmbulance_wanted( Int army )+Int AIAmbulance_wanted( Int army, Int skill ){- if( army >= AMBULANCE_SECOND_ARMY )+ if( skill == AISKILL_EASY )+ return 0;+ if( army >= AMBULANCE_SECOND_ARMY && skill >= AISKILL_BRUTAL )return 2;return army >= AMBULANCE_FIRST_ARMY ? 1 : 0;}-Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost )+Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost, Int skill )+{+ const UnsignedInt wait = skill >= AISKILL_BRUTAL ? AMBULANCE_REBUY_FRAMES : 2 * AMBULANCE_REBUY_FRAMES;+ return lost != 0 && now - lost < wait;+}++Bool AIAmbulance_mayBuyMore( Int bought, Int skill ){- return lost != 0 && now - lost < AMBULANCE_REBUY_FRAMES;+ return bought < AMBULANCE_MATCH_CAP[ skill ];}Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReach )@@ -10682,6 +10702,10 @@ Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReacreturn inGunReach || (lastHit != 0 && now - lastHit < AMBULANCE_HIT_FRAMES);}+/** 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 ){return healthFraction < AMBULANCE_PATIENT_HEALTH && distance <= AMBULANCE_CALL_REACH;@@ -10707,6 +10731,53 @@ Bool AIPlayer::isDutyAmbulance( const Object *obj ) constreturn FALSE;}+/** 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 )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ for( size_t p = 0; p < m_calledPatients.size(); )+ {+ CalledPatient &patient = m_calledPatients[ p ];+ Object *obj = TheGameLogic->findObjectByID( patient.id );+ const Object *ambulance = TheGameLogic->findObjectByID( patient.ambulance );+ const Bool ambulanceUp = ambulance && !ambulance->isEffectivelyDead();+ const char *outcome = NULL;+ Real health = 0.0f;+ Real away = 0.0f;+ if( obj && !obj->isEffectivelyDead() )+ {+ health = obj->getBodyModule()->getHealth() / obj->getBodyModule()->getMaxHealth();+ if( ambulance )+ away = (Real)sqrt( sqr( obj->getPosition()->x - ambulance->getPosition()->x ) + sqr( obj->getPosition()->y - ambulance->getPosition()->y ) );+ }+ if( obj == NULL || obj->isEffectivelyDead() )+ outcome = patient.inside ? (ambulanceUp ? "dies inside" : "dies with the ambulance") : "dies on the way";+ else if( obj->isContained() )+ {+ if( !patient.inside )+ {+ patient.inside = TRUE;+ DEBUG_LOG(("AI PATIENT frame %d player %d '%s' %d climbs in after %d s at %.0f%% health\n", now, m_player->getPlayerIndex(),+ obj->getTemplate()->getName().str(), patient.id, (now - patient.frame) / LOGICFRAMES_PER_SECOND, health * 100.0f));+ }+ }+ else if( patient.inside )+ outcome = ambulanceUp ? "is let out" : "is let out by the wreck";+ else if( obj->getAI()->getCurrentStateID() != AI_ENTER || obj->getAI()->getGoalObject() != ambulance )+ outcome = ambulanceUp ? "walks off" : "walks off, the ambulance lost";+ if( outcome == NULL )+ {+ ++p;+ continue;+ }+ 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));+ m_calledPatients.erase( m_calledPatients.begin() + p );+ }+}+void AIPlayer::doAmbulances( void ){if( !isSkirmishAI() || !m_baseCenterSet || m_skillLevel == AISKILL_EASY || measuringWithoutTactics() )@@ -10725,16 +10796,21 @@ void AIPlayer::doAmbulances( void )++owned;continue;}- DEBUG_LOG(("AI AMBULANCE frame %d player %d loses %d\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(), duty.id));+ DEBUG_LOG(("AI AMBULANCE frame %d player %d loses %d at (%.0f,%.0f), %.0f from home, last seen at %.0f%% health %s a known gun's reach by %.0f, last sent to (%.0f,%.0f)\n",+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), duty.id, duty.seen.x, duty.seen.y,+ (Real)sqrt( sqr( duty.seen.x - m_baseCenter.x ) + sqr( duty.seen.y - m_baseCenter.y ) ), duty.seenHealth * 100.0f,+ duty.seenReach > 0.0f ? "inside" : "clear of", fabs( duty.seenReach ), duty.spot.x, duty.spot.y));duty.id = INVALID_ID;m_ambulanceLost = TheGameLogic->getFrame();}releaseMended();+ followPatients();- const Int wanted = AIAmbulance_wanted( tallyBase( m_player ).army );+ const Int wanted = AIAmbulance_wanted( tallyBase( m_player ).army, m_skillLevel );// no cash hoard to clear: an Ambulance is 600, and a USA at war banks under the hoard all match long.// queueSupportUnit still waits for twice its price- if( owned < wanted && !AIAmbulance_rebuyWaits( TheGameLogic->getFrame(), m_ambulanceLost ) && !isBaseUnderAttack() && !scoutInQueue() )+ if( owned < wanted && AIAmbulance_mayBuyMore( m_ambulancesBought, m_skillLevel ) &&+ !AIAmbulance_rebuyWaits( TheGameLogic->getFrame(), m_ambulanceLost, m_skillLevel ) && !isBaseUnderAttack() && !scoutInQueue() ){std::vector<Object *> factories;m_player->iterateObjects( collectFactories, &factories );@@ -10788,6 +10864,10 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )ContainModuleInterface *hold = ambulance->getContain();const Coord3D *pos = ambulance->getPosition();const UnsignedInt now = TheGameLogic->getFrame();+ const Real reach = deepestReach( guns, pos->x, pos->y, FALSE );+ duty.seen = *pos;+ duty.seenHealth = ambulance->getBodyModule()->getHealth() / ambulance->getBodyModule()->getMaxHealth();+ duty.seenReach = reach;// each one whole again gets out; one still hurt stays in and goes on healingconst ContainedItemsList *riders = hold->getContainedItemsList();@@ -10802,28 +10882,14 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )rider->getAI()->aiExit( ambulance, CMD_FROM_AI );}- // badly hurt: to be repaired, riders and all, who go on healing insideconst StateID state = ai->getCurrentStateID();const BodyModuleInterface *body = ambulance->getBodyModule();- if( body->getHealth() < AMBULANCE_REPAIR_HEALTH * body->getMaxHealth() )- {- Object *mender = findMender( m_player, ambulance );- if( mender && TheActionManager->canGetRepairedAt( ambulance, mender, CMD_FROM_AI ) )- {- if( state != AI_DOCK && state != AI_ENTER && state < 1000 )- {- DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d goes to be repaired at '%s' %d, %.0f%% health\n", now, m_player->getPlayerIndex(),- ambulance->getTemplate()->getName().str(), duty.id, mender->getTemplate()->getName().str(), mender->getID(),- body->getHealth() * 100.0f / body->getMaxHealth()));- ai->aiGetRepaired( mender, CMD_FROM_SCRIPT ); // not CMD_FROM_AI, which a cleanup under way would keep- duty.spot = *mender->getPosition();- }- return;- }- }- // shot at, or inside a gun's reach: back toward home, out of every known gun's reach, whatever it was doing- if( AIAmbulance_pullsBack( now, body->getLastDamageTimestamp(), deepestReach( guns, pos->x, pos->y, FALSE ) > 0.0f ) )+ // shot at, or inside a gun's reach: back toward home, out of every known gun's reach, whatever it was+ // doing, a trip to be repaired included. Sent to be repaired first, it drove the pathfinder's way to+ // the War Factory, through whatever reached that way: 20 of 31 lost in eight matches (ambA4) died on+ // that trip, most within a few seconds of the order and inside a known gun's reach+ if( AIAmbulance_pullsBack( now, body->getLastDamageTimestamp(), reach > 0.0f ) ){Coord3D back = *pos;const Real dx = m_baseCenter.x - pos->x;@@ -10848,6 +10914,25 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )}return;}++ // badly hurt, and out of reach now: to be repaired, riders and all, who go on healing inside+ if( body->getHealth() < AMBULANCE_REPAIR_HEALTH * body->getMaxHealth() )+ {+ Object *mender = findMender( m_player, ambulance );+ if( mender && TheActionManager->canGetRepairedAt( ambulance, mender, CMD_FROM_AI ) )+ {+ if( state != AI_DOCK && state != AI_ENTER && state < 1000 )+ {+ DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d goes to be repaired at '%s' %d, %.0f%% health\n", now, m_player->getPlayerIndex(),+ ambulance->getTemplate()->getName().str(), duty.id, mender->getTemplate()->getName().str(), mender->getID(),+ body->getHealth() * 100.0f / body->getMaxHealth()));+ ai->aiGetRepaired( mender, CMD_FROM_SCRIPT ); // not CMD_FROM_AI, which a cleanup under way would keep+ duty.spot = *mender->getPosition();+ }+ return;+ }+ }+if( cleaner->isCleaningArea() || state == AI_DOCK )return; // its own module drives it until the ground is clean and brings it back; or it is being repaired@@ -10893,6 +10978,14 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )obj->getAI()->aiEnter( ambulance, CMD_FROM_AI );--room;++called;+ CalledPatient patient;+ patient.id = obj->getID();+ patient.ambulance = duty.id;+ patient.frame = now;+ patient.health = body->getHealth() / body->getMaxHealth();+ patient.distance = distance;+ patient.inside = FALSE;+ m_calledPatients.push_back( patient );DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d calls in '%s' %d at %.0f%% health, %.0f away\n", now, m_player->getPlayerIndex(),ambulance->getTemplate()->getName().str(), duty.id, obj->getTemplate()->getName().str(), obj->getID(),body->getHealth() * 100.0f / body->getMaxHealth(), distance));@@ -10905,7 +10998,14 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )PartitionFilterSameMapStatus filterMapStatus( ambulance );PartitionFilter *filters[] = { &kindFilter, &filterMapStatus, NULL };Object *hazard = ThePartitionManager->getClosestObject( pos, AMBULANCE_HAZARD_REACH, FROM_CENTER_2D, filters );+ // and no farther from home than where it waits behind the army, or at home with nobody out. Three of+ // four lost in one Hard match (ambD) died on or after a cleanup 1,400 out, 2,100 to 2,800 from home+ Real hazardLimit = 0.0f;+ if( out > 0 )+ hazardLimit = (Real)sqrt( sqr( middle.x / out - m_baseCenter.x ) + sqr( middle.y / out - m_baseCenter.y ) ) - AMBULANCE_BEHIND;if( hazard && isOurSideOfMap( hazard->getPosition() ) &&+ (isAtHome( hazard->getPosition() ) ||+ sqr( hazard->getPosition()->x - m_baseCenter.x ) + sqr( hazard->getPosition()->y - m_baseCenter.y ) <= sqr( max( hazardLimit, 0.0f ) )) &&deepestReach( guns, hazard->getPosition()->x, hazard->getPosition()->y, FALSE ) < -HELIX_GUN_MARGIN ){DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d goes to clean '%s' %d at (%.0f,%.0f), %.0f away\n", now, m_player->getPlayerIndex(),@@ -13646,7 +13746,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 22; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger 18: the fist 19: the Ambulances 20: the last Ambulance lost 21: the purchase queue's reservation 22: the measured income+ XferVersion currentVersion = 23; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger 18: the fist 19: the Ambulances 20: the last Ambulance lost 21: the purchase queue's reservation 22: the measured income 23: the Ambulances boughtXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -14047,6 +14147,8 @@ void AIPlayer::xfer( Xfer *xfer )xfer->xferInt( &m_bankMark );xfer->xferReal( &m_incomePerSecond );}+ if( version >= 23 )+ xfer->xferInt( &m_ambulancesBought );// the ladder rung and the role, which are rolled once and must come back the same wayif( version >= 3 )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 789f9d470..f7ce2ef3d 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -11235,17 +11235,27 @@ 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 );+extern Int AIAmbulance_wanted( Int army, Int skill );extern Bool AIAmbulance_callsPatient( Real healthFraction, Real distance );+extern Bool AIAmbulance_mayBuyMore( Int bought, Int skill );TEST(the_ai_buys_ambulances_by_army_and_calls_in_the_hurt_nearby){- CHECK_EQ( 0, AIAmbulance_wanted( 0 ) );- CHECK_EQ( 0, AIAmbulance_wanted( 7 ) );- CHECK_EQ( 1, AIAmbulance_wanted( 8 ) );- CHECK_EQ( 1, AIAmbulance_wanted( 19 ) );- CHECK_EQ( 2, AIAmbulance_wanted( 20 ) );- CHECK_EQ( 2, AIAmbulance_wanted( 200 ) );+ CHECK_EQ( 0, AIAmbulance_wanted( 0, AISKILL_BRUTAL ) );+ CHECK_EQ( 0, AIAmbulance_wanted( 7, AISKILL_BRUTAL ) );+ CHECK_EQ( 1, AIAmbulance_wanted( 8, AISKILL_BRUTAL ) );+ CHECK_EQ( 1, AIAmbulance_wanted( 19, AISKILL_BRUTAL ) );+ CHECK_EQ( 2, AIAmbulance_wanted( 20, AISKILL_BRUTAL ) );+ CHECK_EQ( 2, AIAmbulance_wanted( 200, AISKILL_BRUTAL ) );+ // Medium keeps one, Easy none+ CHECK_EQ( 1, AIAmbulance_wanted( 200, AISKILL_MEDIUM ) );+ CHECK_EQ( 0, AIAmbulance_wanted( 200, AISKILL_EASY ) );+ // and a match buys only so many+ CHECK( AIAmbulance_mayBuyMore( 5, AISKILL_BRUTAL ) );+ CHECK( !AIAmbulance_mayBuyMore( 6, AISKILL_BRUTAL ) );+ CHECK( AIAmbulance_mayBuyMore( 2, AISKILL_MEDIUM ) );+ 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 ) );@@ -11258,7 +11268,7 @@ TEST(the_ai_buys_ambulances_by_army_and_calls_in_the_hurt_nearby)/** AIPlayer.cpp: an Ambulance pulls back when shot at or inside a known gun's reach, and a lost one isreplaced only after a wait. */extern Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReach );-extern Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost );+extern Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost, Int skill );TEST(the_ai_ambulance_pulls_back_when_hit_and_is_not_rebought_at_once){@@ -11268,9 +11278,12 @@ TEST(the_ai_ambulance_pulls_back_when_hit_and_is_not_rebought_at_once)CHECK( !AIAmbulance_pullsBack( 1000, 0, FALSE ) );CHECK( !AIAmbulance_pullsBack( 1000, 500, FALSE ) );- CHECK( !AIAmbulance_rebuyWaits( 1000, 0 ) );- CHECK( AIAmbulance_rebuyWaits( 1000, 900 ) );- CHECK( !AIAmbulance_rebuyWaits( 10000, 900 ) );+ CHECK( !AIAmbulance_rebuyWaits( 1000, 0, AISKILL_BRUTAL ) );+ CHECK( AIAmbulance_rebuyWaits( 1000, 900, AISKILL_BRUTAL ) );+ CHECK( !AIAmbulance_rebuyWaits( 10000, 900, AISKILL_BRUTAL ) );+ // Medium waits twice as long+ CHECK( AIAmbulance_rebuyWaits( 6000, 900, AISKILL_MEDIUM ) );+ CHECK( !AIAmbulance_rebuyWaits( 6500, 900, AISKILL_MEDIUM ) );}