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): ai ambulances pull back when hit, free each patient

Olcay Seygand36929fcb0b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18ee04dc5..2f9a90033 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -198,6 +198,7 @@ found and fixed — EA's own, not port damage.**
- Its Chinooks fly the army. A USA attack walked the whole road, at the pace of its slowest tank. Medium and Hard now buy plain Chinooks for nothing but lift, more of them the bigger the attack and the longer the road: they load tanks and soldiers at home, put them down on the attack's road short of anything the computer has seen that can shoot, and go home for the next load while the attack is under way. The drop is one a straight flight from the base reaches over quiet ground, after the first version flew seven loaded Chinooks in one match straight at a drop beyond an enemy base and lost every one. A Chinook hit hard on the way puts its load down where it is. Neither these nor the Air Force General's Combat Chinooks go on the supply runs unless nothing else is left to gather and nothing else can be bought, and the Combat Chinook is no longer ever bought as a gatherer.
- 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.
- 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.h
index cc0554d59..4c7c5bae6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -534,6 +534,7 @@ protected:
};
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_healerSeconds; ///< for the log only, not saved: healer seconds counted, and those clear of the nearest gun's reach
Int m_healerClearSeconds;
Int m_captureTimer; ///< frames until the next look for something to capture
@@ -683,7 +684,7 @@ protected:
Real fightRatio(const Coord3D *centre, Bool countHolders, Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns); ///< the exchange around centre, by the units in it when the rung weighs them
Bool doFallback(Team *team); ///< TRUE when it sent the team's holders back or home on this pass
void pullOutRanked(Team *team, Bool inFight, Real ratio); ///< veterans and up leave earlier than the team, to a repair or heal pad
- void releaseMendedRanked(void); ///< pulled-out ranked units standing idle again become recruitable
+ void releaseMended(void); ///< pulled-out veterans and let-out patients standing idle again become recruitable
void stepCalmly(Object *obj, TacticalStep *step, const Coord3D *spot); ///< a move the unit's mood cannot turn into an attack move
void restoreMood(Object *obj, TacticalStep *step);
Bool pickTacticalSpot(const Object *obj, const Coord3D *from, const Coord3D *awayFrom, Real distance,
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 27c2b8a45..b4650ecc9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -379,6 +379,7 @@ m_role(AIROLE_AGGRESSIVE)
m_ambulance[ slot ].id = INVALID_ID;
m_ambulance[ slot ].spot.zero();
}
+ m_ambulanceLost = 0;
m_healerSeconds = 0;
m_healerClearSeconds = 0;
m_captureTimer = 1;
@@ -10039,21 +10040,37 @@ void AIPlayer::doHelixes( void )
* 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
- * walk over and climb in, and it lets them out once they are whole. It drives to the nearest hazard
+ * 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). Split out with plain values so the rules are testable
- * without a running game. */
+ * (CleanupHazardUpdate::startAutoCleanup).
+ *
+ * It is a 240-health truck with no gun. Hit in the last AMBULANCE_HIT_FRAMES or inside a known gun's
+ * reach, it drops whatever it was doing, the cleanup included, and drives AMBULANCE_PULLBACK toward
+ * home to the first ground no known gun reaches; under AMBULANCE_REPAIR_HEALTH it goes to be repaired.
+ * Before that it parked 150 from the middle of the army and kept cleaning the toxins of the fight it
+ * stood in: 90 of 112 bought in eight 2v2 matches died, each bought again once the bank allowed.
+ * A lost one is now replaced after AMBULANCE_REBUY_FRAMES.
+ *
+ * A patient leaves its team for the default one until it is let out, as a pulled-out veteran does
+ * (pullOutRanked): left in its team, the team's next script order walked it away from the door, and
+ * 23 of 93 called in were ever let out.
+ *
+ * Split out with plain values so the rules are testable without a running game. */
//----------------------------------------------------------------------------------------------------------
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_BEHIND = 150.0f;
+static const Real AMBULANCE_BEHIND = 300.0f;
static const Real AMBULANCE_HAZARD_REACH = 1500.0f;
/** The cleanup ability's MaxMoveDistanceFromLocation in retail AmericaVehicle.ini. */
static const Real AMBULANCE_CLEANUP_RANGE = 300.0f;
static const Real AMBULANCE_REORDER_DISTANCE = 100.0f;
+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;
Int AIAmbulance_wanted( Int army )
{
@@ -10062,6 +10079,16 @@ Int AIAmbulance_wanted( Int army )
return army >= AMBULANCE_FIRST_ARMY ? 1 : 0;
}
+Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost )
+{
+ return lost != 0 && now - lost < AMBULANCE_REBUY_FRAMES;
+}
+
+Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReach )
+{
+ return inGunReach || (lastHit != 0 && now - lastHit < AMBULANCE_HIT_FRAMES);
+}
+
Bool AIAmbulance_callsPatient( Real healthFraction, Real distance )
{
return healthFraction < AMBULANCE_PATIENT_HEALTH && distance <= AMBULANCE_CALL_REACH;
@@ -10107,12 +10134,14 @@ void AIPlayer::doAmbulances( void )
}
DEBUG_LOG(("AI AMBULANCE frame %d player %d loses %d\n", TheGameLogic->getFrame(), m_player->getPlayerIndex(), duty.id));
duty.id = INVALID_ID;
+ m_ambulanceLost = TheGameLogic->getFrame();
}
+ releaseMended();
const Int wanted = AIAmbulance_wanted( tallyBase( m_player ).army );
// 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 && !isBaseUnderAttack() && !scoutInQueue() )
+ if( owned < wanted && !AIAmbulance_rebuyWaits( TheGameLogic->getFrame(), m_ambulanceLost ) && !isBaseUnderAttack() && !scoutInQueue() )
{
std::vector<Object *> factories;
m_player->iterateObjects( collectFactories, &factories );
@@ -10152,6 +10181,8 @@ void AIPlayer::doAmbulances( void )
}
}
+static Object *findMender( Player *player, Object *unit );
+
void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )
{
DutyAmbulance &duty = m_ambulance[ slot ];
@@ -10165,24 +10196,67 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )
const Coord3D *pos = ambulance->getPosition();
const UnsignedInt now = TheGameLogic->getFrame();
- // whole again: out they get
- if( hold->getContainCount() > 0 )
+ // each one whole again gets out; one still hurt stays in and goes on healing
+ const ContainedItemsList *riders = hold->getContainedItemsList();
+ for( ContainedItemsList::const_iterator r = riders->begin(); r != riders->end(); ++r )
+ {
+ Object *rider = *r;
+ if( rider->getBodyModule()->getHealth() < rider->getBodyModule()->getMaxHealth() || rider->getAI() == NULL ||
+ rider->getAI()->getCurrentStateID() == AI_EXIT )
+ continue;
+ DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d lets 1 out whole, '%s' %d, at (%.0f,%.0f)\n", now, m_player->getPlayerIndex(),
+ ambulance->getTemplate()->getName().str(), duty.id, rider->getTemplate()->getName().str(), rider->getID(), pos->x, pos->y));
+ rider->getAI()->aiExit( ambulance, CMD_FROM_AI );
+ }
+
+ // badly hurt: to be repaired, riders and all, who go on healing inside
+ const StateID state = ai->getCurrentStateID();
+ const BodyModuleInterface *body = ambulance->getBodyModule();
+ if( body->getHealth() < AMBULANCE_REPAIR_HEALTH * body->getMaxHealth() )
{
- Bool whole = TRUE;
- const ContainedItemsList *riders = hold->getContainedItemsList();
- for( ContainedItemsList::const_iterator r = riders->begin(); r != riders->end(); ++r )
- if( (*r)->getBodyModule()->getHealth() < (*r)->getBodyModule()->getMaxHealth() )
- whole = FALSE;
- if( whole )
+ Object *mender = findMender( m_player, ambulance );
+ if( mender && TheActionManager->canGetRepairedAt( ambulance, mender, CMD_FROM_AI ) )
{
- DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d lets %d out whole at (%.0f,%.0f)\n", now, m_player->getPlayerIndex(),
- ambulance->getTemplate()->getName().str(), duty.id, (Int)hold->getContainCount(), pos->x, pos->y));
- ai->aiEvacuate( FALSE, 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() )
- return; // its own module drives it until the ground is clean and brings it back
+
+ // 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 ) )
+ {
+ Coord3D back = *pos;
+ const Real dx = m_baseCenter.x - pos->x;
+ const Real dy = m_baseCenter.y - pos->y;
+ const Real length = (Real)sqrt( dx * dx + dy * dy );
+ if( length > AMBULANCE_PULLBACK )
+ {
+ back.x += dx * AMBULANCE_PULLBACK / length;
+ back.y += dy * AMBULANCE_PULLBACK / length;
+ }
+ else
+ back = m_baseCenter;
+ Coord3D spot = rearOf( &back, guns );
+ const Bool goingThere = ai->isMoving() && sqr( spot.x - duty.spot.x ) + sqr( spot.y - duty.spot.y ) <= sqr( AMBULANCE_REORDER_DISTANCE );
+ if( !goingThere )
+ {
+ DEBUG_LOG(("AI AMBULANCE frame %d player %d '%s' %d pulls back to (%.0f,%.0f) at %.0f%% health%s\n", now, m_player->getPlayerIndex(),
+ ambulance->getTemplate()->getName().str(), duty.id, spot.x, spot.y, body->getHealth() * 100.0f / body->getMaxHealth(),
+ cleaner->isCleaningArea() ? ", off its cleanup" : ""));
+ ai->aiMoveToPosition( &spot, CMD_FROM_SCRIPT ); // not CMD_FROM_AI, which a cleanup under way would keep
+ duty.spot = spot;
+ }
+ 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
// the hurt nearby climb in, while there is room, and the middle of whoever is out
BoardingSearch boarding;
@@ -10208,15 +10282,21 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )
middle.y += obj->getPosition()->y;
++out;
}
- if( room <= 0 || !obj->isKindOf( KINDOF_INFANTRY ) )
- continue;
const StateID state = obj->getAI()->getCurrentStateID();
+ if( state == AI_ENTER && obj->getAI()->getGoalObject() == ambulance )
+ --room; // a seat already taken by one on its way
+ // not a burning man running about, which is infantry with no gun and dies in seconds
+ if( room <= 0 || !obj->isKindOf( KINDOF_INFANTRY ) || aiCombatPower( obj ) <= 0.0f )
+ 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 ) )
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)
+ obj->setTeam( m_player->getDefaultTeam() );
+ obj->getAI()->setIsRecruitable( FALSE );
obj->getAI()->aiEnter( ambulance, CMD_FROM_AI );
--room;
++called;
@@ -10227,12 +10307,13 @@ void AIPlayer::steerAmbulance( Int slot, const std::vector<AIKnownGun> &guns )
if( called > 0 || boarding.found )
return; // no new spot while they walk over
- // the nearest hazard, if it is on our side and out of every known gun's reach
+ // the nearest hazard, if it is on our side and clear of every known gun's reach by the healer's margin
PartitionFilterAcceptByKindOf kindFilter( MAKE_KINDOF_MASK( KINDOF_CLEANUP_HAZARD ), KINDOFMASK_NONE );
PartitionFilterSameMapStatus filterMapStatus( ambulance );
PartitionFilter *filters[] = { &kindFilter, &filterMapStatus, NULL };
Object *hazard = ThePartitionManager->getClosestObject( pos, AMBULANCE_HAZARD_REACH, FROM_CENTER_2D, filters );
- if( hazard && isOurSideOfMap( hazard->getPosition() ) && deepestReach( guns, hazard->getPosition()->x, hazard->getPosition()->y, FALSE ) < 0.0f )
+ if( hazard && isOurSideOfMap( hazard->getPosition() ) &&
+ 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(),
ambulance->getTemplate()->getName().str(), duty.id, hazard->getTemplate()->getName().str(), hazard->getID(),
@@ -10443,16 +10524,18 @@ void AIPlayer::pullOutRanked( Team *team, Bool inFight, Real ratio )
}
}
-/** Pulled-out ranked units that stand idle again, mended or home, go back to being recruitable.
- * ponytail: any ranked default-team unit not recruitable counts as one of ours; a script that marks
- * a default-team veteran unrecruitable would see it undone. */
-void AIPlayer::releaseMendedRanked( void )
+/** Pulled-out ranked units and Ambulance patients that stand idle again, mended, home or let out, go back
+ * to being recruitable. A patient still inside stays out of reach.
+ * ponytail: any ranked or infantry default-team unit not recruitable counts as one of ours; a script that
+ * marks such a unit unrecruitable would see it undone. */
+void AIPlayer::releaseMended( void )
{
for( DLINK_ITERATOR<Object> m = m_player->getDefaultTeam()->iterate_TeamMemberList(); !m.done(); m.advance() )
{
Object *obj = m.cur();
AIUpdateInterface *ai = obj->getAI();
- if( ai == NULL || ai->isRecruitable() || obj->getVeterancyLevel() <= LEVEL_REGULAR || obj->isEffectivelyDead() )
+ if( ai == NULL || ai->isRecruitable() || obj->isEffectivelyDead() || obj->isContained() ||
+ (obj->getVeterancyLevel() <= LEVEL_REGULAR && !obj->isKindOf( KINDOF_INFANTRY )) )
continue;
const StateID state = ai->getCurrentStateID();
if( state == AI_DOCK || state == AI_ENTER || state >= 1000 || ai->isMoving() )
@@ -10482,7 +10565,7 @@ void AIPlayer::doRetreats( void )
if( m_retreatTimer < 1 )
m_retreatTimer = 1;
- releaseMendedRanked();
+ releaseMended();
if( !m_baseCenterSet )
return; // nowhere to fall back to
@@ -12970,7 +13053,7 @@ void AIPlayer::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 19; // 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
+ XferVersion currentVersion = 20; // 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
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -13350,6 +13433,8 @@ void AIPlayer::xfer( Xfer *xfer )
xfer->xferCoord3D( &m_ambulance[ slot ].spot );
}
}
+ if( version >= 20 )
+ xfer->xferUnsignedInt( &m_ambulanceLost );
// the ladder rung and the role, which are rolled once and must come back the same way
if( version >= 3 )
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 9bb5373e7..71da909d2 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -11255,6 +11255,24 @@ TEST(the_ai_buys_ambulances_by_army_and_calls_in_the_hurt_nearby)
CHECK( !AIAmbulance_callsPatient( 0.1f, 451.0f ) );
}
+/** AIPlayer.cpp: an Ambulance pulls back when shot at or inside a known gun's reach, and a lost one is
+ replaced only after a wait. */
+extern Bool AIAmbulance_pullsBack( UnsignedInt now, UnsignedInt lastHit, Bool inGunReach );
+extern Bool AIAmbulance_rebuyWaits( UnsignedInt now, UnsignedInt lost );
+
+TEST(the_ai_ambulance_pulls_back_when_hit_and_is_not_rebought_at_once)
+{
+ CHECK( AIAmbulance_pullsBack( 1000, 0, TRUE ) );
+ CHECK( AIAmbulance_pullsBack( 1000, 990, FALSE ) );
+ // never hit, or hit long ago, and clear of every gun: it stays on the job
+ 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 ) );
+}
+
/** AI.cpp: a team that loses a fight stops at the first ground on its way home that none of the
fight's guns reach, a step past it, rather than walking the whole map back to its base. */