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
feat(ai): shot units answer the gun or leave its reach, on every rung
Olcay Seygana487220a96a6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5b86cc60c..3a75d3fdc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -604,6 +604,14 @@ found and fixed, EA's own, not port damage.**- Hard stops feeding you units. Before a group leaves, or a lone reinforcement sets off to join one out on the map, it weighs what it is sending against everything of yours it has seen in the last three minutes, unit type against unit type, and holds back what would only die. A reinforcement waits at home for the next wave instead of crossing the map alone. When you mass one unit it trains the answer between attacks too, Comanches and Helixes included, and stops buying what your biggest group beats. Against waves of Overlords rolling at its base, the share of its groups sent into a fight their units lose fell from 48% to 40%, and units dying alone from 17% to 14% of its losses. Against itself it changed nothing measurable: in 48 matches where only one side had it, that side won 5 and the other 4. Replays recorded before this change play out differently.- It stops feeding its idle units to your towers. On a small map your base, or a Patriot at your expansion, stands close enough to its own to count as an attack on it, and it answered by sending whatever stood idle at home at the tower, one or two at a time: one Hard GLA walked eight Quad Cannons and Scorpions into the same Fire Base and Patriot, one after the other. A tower that stays outside its base is now gone after only with a force that outweighs it, double on Hard, half again on Medium, level on Easy, and anything that drives in is still met wherever it stands. In 32 Hard against Medium matches, USA and GLA in both seats, what both sides lost to defences fell from 171,800 to 91,700, everything they lost fell from 1,114,000 to 965,000, and Hard still won 14. Replays recorded before this change play out differently.- It stops walking its army into towers and garrisons it has already seen. On Medium and Hard, a group that knows a defence stands in its way waits outside its reach until it is strong enough to take it, and shells it from outside with its longer-range units. It also buys units that beat what it has seen standing there. Before, wave after wave went into the same Gatling cannons. Hard Air Force General against China lost a third fewer units to defences: 1,447 down to 909 over 16 matches. Replays recorded before this change play out differently.++## The computer answers when it is shot++- Computer units used to stand and take it. A group idling in reach of your Tomahawks never looked up, and a tank shooting a power plant went on shooting it with a Gattling Cannon firing into its side. Nothing in the opponent asked who was hitting it. Six Battlemasters shelled by two Tomahawks from past their sight lost three tanks and left both guns standing. On Hard they now have both guns dead nine seconds after the first hit, for one tank; on Medium eleven seconds, for two; on Easy twenty-six seconds, still for three.+- A unit that is hit shoots the gun if it can reach it. If not, and what stands near it is worth more than what covers the gun, they drive over and kill it, whether the computer can see that gun or only its shells. Otherwise it walks to the nearest ground it knows nothing can shoot, holds there and does not walk straight back. Two Battlemasters under four Fire Bases died inside 11 seconds. On Medium and Hard both are now out from under them in five and still alive two minutes later; on Easy one gets out, with 25 health.+- Six Battlemasters taking down power plants beside a Gattling Cannon lost two tanks on every difficulty. Medium now loses none, Easy and Hard one, and all three kill the cannon, which Hard used to leave standing.+- Hard looks every third of a second and a tank that is hit takes everything within 300 with it. Medium looks once a second and takes everything within 150. Easy looks every three seconds and answers alone, so it is often too late: past two Tomahawks on the road it answered once in a minute and lost two tanks, the same two as before. Replays recorded before this change play out differently.+## The computer knows when to quit- Its teams fought to the last man. The word "retreat" appeared nowhere in the opponent's code - the single most visible thing that made it look stupid.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 19ba42562..45c05f86c 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -460,6 +460,11 @@ Data/Scenarios/tunnelshortcut.txtData/Scenarios/tunnelsplit.txtData/Scenarios/tunnelunderfire.txtData/Scenarios/tunnelwalk.txt+Data/Scenarios/underfire_building.txt+Data/Scenarios/underfire_cankill.txt+Data/Scenarios/underfire_outgunned.txt+Data/Scenarios/underfire_parked.txt+Data/Scenarios/underfire_road.txtData/Scenarios/v240_heli.txtData/Scenarios/v240_hook.txtData/Scenarios/v240_md.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/underfire_building.txt b/GeneralsMD/Code/Data/Scenarios/underfire_building.txtnew file mode 100644index 000000000..375d8c34d--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/underfire_building.txt@@ -0,0 +1,44 @@+# Under a tower while it shoots buildings: six Battlemasters of a computer player are sent at four Power Plants+# in turn, with a Gattling Cannon behind them and in reach of where the tanks stop to shoot. They should turn+# on the gun and then go on with the buildings, and not stand on the buildings with the tower on them. The Red+# Guards are for the AI's scout order, which would otherwise walk one of the tanks off.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover 0 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 3600+# -scenario underfire_building -logPrefix uf_++30 spawn 1 ChinaTankBattleMaster 6 start1:0:650 40+31 spawn 0 AmericaPowerPlant 4 start1:-60:900 120+30 spawn 0 ChinaGattlingCannon 1 start1:170:830+35 spawn 1 ChinaInfantryRedguard 4 start1:0:250 20+40 attack 1 ChinaTankBattleMaster 0 AmericaPowerPlant+280 attack 1 ChinaTankBattleMaster 0 AmericaPowerPlant+520 attack 1 ChinaTankBattleMaster 0 AmericaPowerPlant+760 attack 1 ChinaTankBattleMaster 0 AmericaPowerPlant+40 tally 1 ChinaTankBattleMaster+100 tally 1 ChinaTankBattleMaster+160 tally 1 ChinaTankBattleMaster+220 tally 1 ChinaTankBattleMaster+280 tally 1 ChinaTankBattleMaster+340 tally 1 ChinaTankBattleMaster+400 tally 1 ChinaTankBattleMaster+460 tally 1 ChinaTankBattleMaster+520 tally 1 ChinaTankBattleMaster+580 tally 1 ChinaTankBattleMaster+640 tally 1 ChinaTankBattleMaster+700 tally 1 ChinaTankBattleMaster+800 tally 1 ChinaTankBattleMaster+900 tally 1 ChinaTankBattleMaster+1000 tally 1 ChinaTankBattleMaster+1200 tally 1 ChinaTankBattleMaster+1400 tally 1 ChinaTankBattleMaster+1790 tally 1 ChinaTankBattleMaster+340 tally 0 ChinaGattlingCannon+640 tally 0 ChinaGattlingCannon+1000 tally 0 ChinaGattlingCannon+1790 tally 0 ChinaGattlingCannon+340 tally 0 AmericaPowerPlant+640 tally 0 AmericaPowerPlant+1000 tally 0 AmericaPowerPlant+1790 tally 0 AmericaPowerPlantdiff --git a/GeneralsMD/Code/Data/Scenarios/underfire_cankill.txt b/GeneralsMD/Code/Data/Scenarios/underfire_cankill.txtnew file mode 100644index 000000000..809541493--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/underfire_cankill.txt@@ -0,0 +1,66 @@+# Under fire, and able to kill the gun: six Battlemasters of a computer player stand idle 300 from two+# Tomahawks, who outrange them and fire from past their sight. The Red Guards are for the AI's scout+# order, which takes the newest of the default team and would otherwise walk the target off.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover 0 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 2400+# -scenario underfire_cankill -logPrefix underfire_cankill_++30 spawn 1 ChinaTankBattleMaster 6 start1:0:650 40+31 spawn 0 AmericaVehicleTomahawk 2 start1:0:950 40+35 spawn 1 ChinaInfantryRedguard 4 start1:0:250 20+40 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+190 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+340 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+490 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+640 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+790 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+40 tally 1 ChinaTankBattleMaster+70 tally 1 ChinaTankBattleMaster+100 tally 1 ChinaTankBattleMaster+130 tally 1 ChinaTankBattleMaster+160 tally 1 ChinaTankBattleMaster+190 tally 1 ChinaTankBattleMaster+220 tally 1 ChinaTankBattleMaster+250 tally 1 ChinaTankBattleMaster+280 tally 1 ChinaTankBattleMaster+310 tally 1 ChinaTankBattleMaster+340 tally 1 ChinaTankBattleMaster+370 tally 1 ChinaTankBattleMaster+400 tally 1 ChinaTankBattleMaster+430 tally 1 ChinaTankBattleMaster+460 tally 1 ChinaTankBattleMaster+490 tally 1 ChinaTankBattleMaster+520 tally 1 ChinaTankBattleMaster+550 tally 1 ChinaTankBattleMaster+580 tally 1 ChinaTankBattleMaster+610 tally 1 ChinaTankBattleMaster+640 tally 1 ChinaTankBattleMaster+670 tally 1 ChinaTankBattleMaster+700 tally 1 ChinaTankBattleMaster+730 tally 1 ChinaTankBattleMaster+760 tally 1 ChinaTankBattleMaster+790 tally 1 ChinaTankBattleMaster+820 tally 1 ChinaTankBattleMaster+850 tally 1 ChinaTankBattleMaster+880 tally 1 ChinaTankBattleMaster+910 tally 1 ChinaTankBattleMaster+940 tally 1 ChinaTankBattleMaster+970 tally 1 ChinaTankBattleMaster+1000 tally 1 ChinaTankBattleMaster+1100 tally 1 ChinaTankBattleMaster+1190 tally 1 ChinaTankBattleMaster+250 tally 0 AmericaVehicleTomahawk+310 tally 0 AmericaVehicleTomahawk+340 tally 0 AmericaVehicleTomahawk+370 tally 0 AmericaVehicleTomahawk+400 tally 0 AmericaVehicleTomahawk+430 tally 0 AmericaVehicleTomahawk+460 tally 0 AmericaVehicleTomahawk+490 tally 0 AmericaVehicleTomahawk+520 tally 0 AmericaVehicleTomahawk+580 tally 0 AmericaVehicleTomahawk+640 tally 0 AmericaVehicleTomahawk+940 tally 0 AmericaVehicleTomahawk+1190 tally 0 AmericaVehicleTomahawkdiff --git a/GeneralsMD/Code/Data/Scenarios/underfire_outgunned.txt b/GeneralsMD/Code/Data/Scenarios/underfire_outgunned.txtnew file mode 100644index 000000000..65c8b9c37--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/underfire_outgunned.txt@@ -0,0 +1,54 @@+# Under fire, and not able to kill the gun: two Battlemasters of a computer player stand idle in reach of four+# Fire Bases that outrange them. They should leave the ground the Fire Bases cover and stay off it for the+# rest of the two minutes, whatever the hold and the idle hunt do next. The first Red Guard stands by the+# guns, so the AI can see what it is up against from the start. The others are for the AI's scout order, which+# takes the newest of the default team and would otherwise walk one of the tanks off.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover 0 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 7200+# -scenario underfire_outgunned -logPrefix uf_++30 spawn 1 ChinaTankBattleMaster 2 start1:0:650 40+31 spawn 0 AmericaFireBase 4 start1:-120:950 90+32 spawn 1 ChinaInfantryRedguard 1 start1:-80:1040+35 spawn 1 ChinaInfantryRedguard 4 start1:0:250 20+40 tally 1 ChinaTankBattleMaster+70 tally 1 ChinaTankBattleMaster+100 tally 1 ChinaTankBattleMaster+130 tally 1 ChinaTankBattleMaster+160 tally 1 ChinaTankBattleMaster+190 tally 1 ChinaTankBattleMaster+220 tally 1 ChinaTankBattleMaster+250 tally 1 ChinaTankBattleMaster+280 tally 1 ChinaTankBattleMaster+310 tally 1 ChinaTankBattleMaster+340 tally 1 ChinaTankBattleMaster+370 tally 1 ChinaTankBattleMaster+400 tally 1 ChinaTankBattleMaster+430 tally 1 ChinaTankBattleMaster+460 tally 1 ChinaTankBattleMaster+490 tally 1 ChinaTankBattleMaster+520 tally 1 ChinaTankBattleMaster+550 tally 1 ChinaTankBattleMaster+580 tally 1 ChinaTankBattleMaster+610 tally 1 ChinaTankBattleMaster+640 tally 1 ChinaTankBattleMaster+700 tally 1 ChinaTankBattleMaster+800 tally 1 ChinaTankBattleMaster+900 tally 1 ChinaTankBattleMaster+1000 tally 1 ChinaTankBattleMaster+1200 tally 1 ChinaTankBattleMaster+1400 tally 1 ChinaTankBattleMaster+1600 tally 1 ChinaTankBattleMaster+1800 tally 1 ChinaTankBattleMaster+2000 tally 1 ChinaTankBattleMaster+2200 tally 1 ChinaTankBattleMaster+2400 tally 1 ChinaTankBattleMaster+2600 tally 1 ChinaTankBattleMaster+2800 tally 1 ChinaTankBattleMaster+3000 tally 1 ChinaTankBattleMaster+3200 tally 1 ChinaTankBattleMaster+3400 tally 1 ChinaTankBattleMaster+3590 tally 1 ChinaTankBattleMaster+3590 tally 0 AmericaFireBasediff --git a/GeneralsMD/Code/Data/Scenarios/underfire_parked.txt b/GeneralsMD/Code/Data/Scenarios/underfire_parked.txtnew file mode 100644index 000000000..fb0d2c508--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/underfire_parked.txt@@ -0,0 +1,42 @@+# Under fire where the wave gathers: a computer player's scripts take the tanks into a team and park it on+# Alpine Assault's middle road, at (1433,889), and Fire Bases go up in reach of it once it is there. Each tank+# they hit should leave their ground, or go for them when the odds allow it. AI FIRE lines say which it did.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover 0 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 7200+# -scenario underfire_parked -logPrefix uf_++30 spawn 1 ChinaTankBattleMaster 4 start1:0:650 40+35 spawn 1 ChinaInfantryRedguard 4 start1:0:250 20+1200 spawn 0 AmericaFireBase 6 1640 889 90+1200 tally 1 ChinaTankBattleMaster+1300 tally 1 ChinaTankBattleMaster+1400 tally 1 ChinaTankBattleMaster+1500 tally 1 ChinaTankBattleMaster+1600 tally 1 ChinaTankBattleMaster+1700 tally 1 ChinaTankBattleMaster+1800 tally 1 ChinaTankBattleMaster+1900 tally 1 ChinaTankBattleMaster+2000 tally 1 ChinaTankBattleMaster+2200 tally 1 ChinaTankBattleMaster+2400 tally 1 ChinaTankBattleMaster+2600 tally 1 ChinaTankBattleMaster+2800 tally 1 ChinaTankBattleMaster+3000 tally 1 ChinaTankBattleMaster+3200 tally 1 ChinaTankBattleMaster+3400 tally 1 ChinaTankBattleMaster+3590 tally 1 ChinaTankBattleMaster+3800 tally 1 ChinaTankBattleMaster+4000 tally 1 ChinaTankBattleMaster+4200 tally 1 ChinaTankBattleMaster+4400 tally 1 ChinaTankBattleMaster+4600 tally 1 ChinaTankBattleMaster+4800 tally 1 ChinaTankBattleMaster+5000 tally 1 ChinaTankBattleMaster+5200 tally 1 ChinaTankBattleMaster+5400 tally 1 ChinaTankBattleMaster+5600 tally 1 ChinaTankBattleMaster+5800 tally 1 ChinaTankBattleMaster+5990 tally 1 ChinaTankBattleMaster+5990 tally 0 AmericaFireBasediff --git a/GeneralsMD/Code/Data/Scenarios/underfire_road.txt b/GeneralsMD/Code/Data/Scenarios/underfire_road.txtnew file mode 100644index 000000000..623e42e31--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/underfire_road.txt@@ -0,0 +1,42 @@+# Under fire on the road: six Battlemasters of a computer player attack-move north past two Tomahawks that stand+# off to the side, past their sight, and shell them all the way. They should stop for the guns rather than+# drive on under them. The Red Guards are for the AI's scout order, which would otherwise walk one of the tanks+# off.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover 0 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 3600+# -scenario underfire_road -logPrefix uf_++30 spawn 1 ChinaTankBattleMaster 6 start1:0:400 40+31 spawn 0 AmericaVehicleTomahawk 2 start1:340:900 40+35 spawn 1 ChinaInfantryRedguard 4 start1:0:250 20+40 attackmove 1 ChinaTankBattleMaster start1:0:1700+40 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+190 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+340 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+490 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+640 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+790 attack 0 AmericaVehicleTomahawk 1 ChinaTankBattleMaster+40 tally 1 ChinaTankBattleMaster+100 tally 1 ChinaTankBattleMaster+160 tally 1 ChinaTankBattleMaster+220 tally 1 ChinaTankBattleMaster+280 tally 1 ChinaTankBattleMaster+340 tally 1 ChinaTankBattleMaster+400 tally 1 ChinaTankBattleMaster+460 tally 1 ChinaTankBattleMaster+520 tally 1 ChinaTankBattleMaster+580 tally 1 ChinaTankBattleMaster+640 tally 1 ChinaTankBattleMaster+700 tally 1 ChinaTankBattleMaster+800 tally 1 ChinaTankBattleMaster+900 tally 1 ChinaTankBattleMaster+1000 tally 1 ChinaTankBattleMaster+1200 tally 1 ChinaTankBattleMaster+1400 tally 1 ChinaTankBattleMaster+1790 tally 1 ChinaTankBattleMaster+340 tally 0 AmericaVehicleTomahawk+640 tally 0 AmericaVehicleTomahawk+1000 tally 0 AmericaVehicleTomahawk+1790 tally 0 AmericaVehicleTomahawkdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex ab9298749..db0c981c3 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -42,6 +42,7 @@#include "Common/STLTypedefs.h"class AIGroup;+class AIInfluenceMap;class AttackPriorityInfo;class BuildListInfo;class CommandButton;@@ -280,6 +281,13 @@ struct AIDifficultyProfile// Artillery that fires past its own sightInt m_artillerySpotters; ///< the side's spotters (AISideInfo m_spotter) added to a team that brings such a gun and no spotterReal m_artilleryShare; ///< the share of a side's attack teams with no such gun that are given one of its own (AISideInfo m_artillery)++ // Coming under fire (AIPlayer::answerFire): what it does about a gun that is hitting it+ Real m_influenceSeconds; ///< how old its map of what can shoot where may be when it is read+ Real m_fireLookSeconds; ///< how often it looks at who is being hit, and so how late it answers+ Real m_fireWordRadius; ///< how far from a unit hit the rest of the group goes with it; 0 = each answers its own hit alone+ Real m_fireChargeOdds; ///< ours near the unit have to be worth this many times what covers the gun before they go for it+ Real m_fireMemorySeconds; ///< how long a gun that hit it stays on its map after it has lost sight of it};//-------------------------------------------------------------------------------------------------@@ -378,10 +386,60 @@ Real aiArmyAdvantage( const Real *myValue, Int myKinds, const Real *theirValue,Real aiRetreatRatio( Real myHealth, Real myPower, Real enemyHealth, Real enemyPower );/** Where a force losing a fight stops: the first spot on its line home, or 45 or 90 degrees off it, that- * none of the fight's guns reach (x, y, reach triples), plus one step, on the map (bounds: low x, low y,- * high x, high y). FALSE and home when there is none short of it. */+ * none of the fight's guns reach (x, y, reach triples) and that map, when given, has no enemy gun on,+ * plus one step, on the ground (bounds: low x, low y, high x, high y). FALSE and home when there is none+ * short of it. */Bool aiRetreatFallbackPoint( Real fromX, Real fromY, Real homeX, Real homeY, Real step,- const Real *guns, Int gunCount, const Real *bounds, Real *outX, Real *outY );+ const Real *guns, Int gunCount, const Real *bounds, Real *outX, Real *outY,+ const AIInfluenceMap *map = NULL );++/** What a unit that has just been hit does about the gun that hit it. */+enum AIFireAnswer+{+ AIFIRE_CARRY_ON, ///< it is already in a gunfight, or may not leave this one+ AIFIRE_SHOOT_BACK, ///< the gun is in its reach: that is what it shoots now+ AIFIRE_GO_KILL, ///< out of reach, and ours near it are enough: they go and get it+ AIFIRE_LEAVE ///< out of reach, and ours are not enough: off the ground it covers+};++/** The rule. A unit already shooting the gun or some other gun stays on it, and the retreat judges that+ * fight. One with the gun in reach turns on it. Out of reach it goes when it can get at the gun and ours+ * are not outgunned at the gun's own spot, and otherwise leaves if it may. One that may not leave stays on+ * the order it has, or with none, idle under the shells, goes for the gun at any odds and leaves if it cannot+ * get at it. ours and cover are in aiCombatPower's currency; odds is the rung's. */+AIFireAnswer aiAnswerFire( Bool onTheGun, Bool fightingAGun, Bool canShootNow, Bool canGetAtIt, Real ours, Real cover, Real odds, Bool mayLeave, Bool idle );++/** The odds a unit reads a gun at. One already sent at it breaks off only well past the odds that sent it, so+ * a reading either side of them does not turn it round halfway. */+Real aiFireOddsNow( Real odds, Bool sentAtIt, Real margin );++/** A unit that leaves a gun it was sent at has tried it. Going back on the next good reading walked it to and+ * fro for as long as the fight read between the odds that send and the odds that hold, so its hold ends at+ * home. */+Bool aiFireMayGoBack( Bool sentAtIt );++/** A unit stops counting as sent at a gun once the retreat has it, or a step of its own took it away (a hurt+ * unit pulled out, a kite), or the errand has run past the longest it can take. Left on it, the hurt unit was+ * walked back to the gun from its safe spot. */+Bool aiFireAnswerOver( Bool retreatHasIt, Bool steppedAway, UnsignedInt framesOnIt, UnsignedInt maxFrames );++/** A unit holding after it left a fight goes free. The retreat ends the hold of those it looks at, and only+ * one it has lost track of runs to staleFrames. Nothing ends the others (a rung with no retreat, the default+ * team): they hold holdFrames and go free once they have stopped walking, for the call-ups to have them. */+Bool aiHolderLetGo( Bool retreatSeesIt, UnsignedInt heldFrames, Bool moving, UnsignedInt holdFrames, UnsignedInt staleFrames );++/** Whether a unit may answer a gun by leaving. A fight at home is fought, home being where a retreat goes,+ * and a gun out past home that is shelling it is nothing the retreat will take up, so that one it may.+ * Away from home, a gun the retreat can see, known and within its radius, is the retreat's to judge on a+ * rung that retreats: units leaving on one hit where the fight as a whole holds were the passivity 4264d652+ * cost matches to take out. */+Bool aiFireMayLeave( Bool unitAtHome, Bool gunAtHome, Bool rungRetreats, Bool gunKnown, Real gunDistance, Real retreatRadius );++/** ours would lose to cover: there is something there, and ours are worth less than odds times it. */+Bool aiOutgunned( Real ours, Real cover, Real odds );++/** A body's last hit stamp is within window frames of now. The stamp starts out as 0xffffffff. */+Bool aiRecentlyHit( UnsignedInt hitFrame, UnsignedInt now, UnsignedInt window );/** A unit at (x, y) walking along (dirX, dirY), a unit vector, is about to walk into a gun at (gunX, gunY):* it is outside the gun's reach, heading towards it, and the next lookahead of its walk comes within edgediff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIInfluenceMap.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIInfluenceMap.hindex 81fc508b5..6013007e9 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIInfluenceMap.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIInfluenceMap.h@@ -34,7 +34,7 @@ class Xfer;* data almost never sets, so every one of its cells reads zero. This one stamps each armed thing's* combat power onto every cell its guns reach, the reach stretched by the high ground the way* Weapon_elevatedRange stretches it, so "how much can hit me here" is one lookup. The friendly- * layer is the same stamp for this player's own units and its allies'.+ * layer is the same stamp for this player's own units and its allies', drawn for Hard's tactics alone.** Everything here is plain arithmetic on logic state in the order the caller hands it over, so two* machines that stamp the same objects in the same order hold the same map. */diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex a7a257dd5..9407e6b06 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -830,12 +830,50 @@ protected:/** What this player knows can shoot at each patch of the map, and what it has there itself. */AIInfluenceMap m_influence;void rebuildInfluence(void);+ void ensureInfluence(void); ///< the map, no older than this rung reads it; below Hard this is what draws it+ Bool hasTacticalMap(void) const; ///< Hard's map, for the reads the rungs below it do not make+ Bool quietGround(const Coord3D *from, const Real *gun, Coord3D *spot); ///< where to go from here to be off the map's guns and clear of this one (x, y, reach, or NULL); FALSE when no way gets out++ /** A gun that has hit this player from past where its fights look or from the fog. It goes on the map as+ * if seen, where it stood at the last hit, and counts in the fights around that hit, for the rung's+ * m_fireMemorySeconds. The shell's arc is on the screen, so this tells the AI what it tells a player. */+ struct FireReport+ {+ ObjectID shooter;+ Coord3D at; ///< where the gun stood+ Coord3D hitAt; ///< where what it hit stood+ Real reach;+ Real power;+ UnsignedInt frame; ///< the last hit+ };+ std::vector<FireReport> m_fireReports;+ Object *reportedShooter(const FireReport &report) const; ///< NULL when it is dead, forgotten or no enemy now+ void noteFire(const Object *shooter, const Object *gun, const Coord3D *hitAt);++ /** A unit hit answers the gun that hit it, once in each of the rung's looks: AIPlayer::answerFire. What it+ * takes to get a gun is read once a look, by the first unit that has to ask, and holds for the rest. */+ struct GunReading+ {+ ObjectID gun;+ Real ours; ///< what is near the unit that read it and can hurt this gun+ Real cover; ///< what the map has covering the gun's own spot+ Real edge; ///< a fixed gun: the fight at the edge of its reach+ UnsignedInt frame;+ };+ std::vector<GunReading> m_gunReadings;+ void answerFire(void);+ AIFireAnswer answerHit(Object *obj, Object *shooter, Object *gun); ///< decided and ordered+ const GunReading &readGun(const Object *obj, const Object *gun);+ void fightersNear(const Coord3D *at, Real radius, std::vector<Object *> *fighters); ///< our own who take orders here, in ObjectID order+ void finishAnswers(void); ///< those done with a gun go back to what they were doing+ Bool isAnsweringFire(ObjectID unit);/** Hard's fighting units, one at a time: step back from what they outrange, climb onto ground* that lengthens their guns, and take a hurt unit out of ground it cannot win on. */virtual void doTactics(void);void doTransports(void); ///< helicopters put riders who cannot shoot out down at the fightBool measuringWithoutTactics(void) const; ///< -notactics has this slot fight the old way+ Bool fightsOnItsOwn(Object *obj); ///< armed, on the ground, and with no job of its own or base to guard: the tactics' and the answers' to ordervoid tacticsFor(Object *obj);struct TacticalStep{@@ -852,16 +890,17 @@ protected:Bool fallingBack; ///< pulled out of a lost fight to a safe spot, and goes back once it is safeCoord3D fallbackFrom; ///< the fight it was pulled out ofUnsignedInt fallbackFrame; ///< when it was pulled out+ UnsignedInt answerFrame; ///< when it was sent at a gun that hit it, 0 while it is not; target and origin are what it goes back to};std::vector<TacticalStep> m_tactics;TacticalStep *findTacticalStep(ObjectID unit);TacticalStep *tacticalStepFor(ObjectID unit); ///< ... making the row if there is nonevoid leaveTacticsAlone(ObjectID unit);- Bool isFallingBack(ObjectID unit); ///< holding at a safe spot after a lost fight, for doRetreats to send back+ Bool isFallingBack(ObjectID unit) const; ///< holding at a safe spot after a lost fight, for doRetreats to send backvoid measureFight(const Coord3D *centre, Bool countHolders, Real *myHealth, Real *myPower,Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns, Real *advantage = NULL, Real *defencePower = NULL);Real fightRatio(const Coord3D *centre, Bool countHolders, Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns,- Real *defencePower = NULL); ///< the exchange around centre, by the units in it when the rung weighs them; defencePower is the part of the enemy's that is buildings outside our base+ Real *defencePower = NULL); ///< the exchange around centre, by the units in it when the rung weighs them; defencePower is the part of the enemy's that stands outside our base and is a building or a gun known by its shellsBool doFallback(Team *team); ///< TRUE when it sent the team's holders back or home on this passvoid pullOutRanked(Team *team, Bool inFight, Real ratio); ///< veterans and up leave earlier than the team, to a repair or heal padvoid releaseMended(void); ///< pulled-out veterans and let-out patients standing idle again become recruitablediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 37d2060c2..bd3312c4e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1274,7 +1274,7 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* opened a gap the two lower rungs could not cross. Easy looks every 75 seconds and re-decides* every 7, and its trucks follow the piles; it still never retreats, never counters and never* hurries a spend. Medium looks every 45 and re-decides every 3, counters at half weight, and- * starts spending past 6000 instead of 10000. Massing, team retreat, the influence map, defended+ * starts spending past 6000 instead of 10000. Massing, team retreat, the attack lanes, defended* expansions, extra buildings and tactical fighting stay on Hard, and the two measured columns* above were left where the matches put them.*@@ -1369,12 +1369,25 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* Easy's few, half of Medium's and a quarter of Hard's. A side that names no Artillery or Spotter* draws nothing and plays as before.*- * scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU bankS floor payoff upgr nonc share backlog push minPow siege beam strikeE strikeT swDef stall lost retry stage spot arty */+ * inflS to fireMem, 2026-10-30. The owner: "bu ai lar artik su influence map i falan biraz ciddiye+ * alsinlar, hedef aliniyorlar hala devam ediyorlar ayni yerde." Units shelled from past their sight+ * stood and took it on every rung, so every rung now reads the map and answers a hit (AIPlayer::+ * answerFire). inflS is how old the map may be when read: Hard draws it on the clock every second as+ * before, and the rungs below draw it only when something asks, every two and every four seconds at+ * the most, so a quiet match costs them nothing. fireLook is how often a rung looks at who is being hit:+ * Easy every three seconds. A roll for the share of hits it noticed came out: hits come seconds apart, so+ * a miss threw away what may be the only look a tank gets, and every draw redrew the match. word is how far the rest of the group goes with a unit hit: Easy's answer alone, one at a time, which is the+ * sloppy part, and Hard's whole group at once. odds is what ours have to be worth against what covers+ * the gun before they go for it, with Hard the least willing to walk into a loss and Easy the most, as+ * with the odds at a known defence's edge. fireMem is how long a gun it has lost sight of stays on its+ * map, and with it the ground it covers.+ *+ * scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU bankS floor payoff upgr nonc share backlog push minPow siege beam strikeE strikeT swDef stall lost retry stage spot arty inflS fireLook word odds fireMem */static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] ={- /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 90.0f, 360.0f, 1500.0f, 80.0f, 0.00f, 0.0f, 2.0f, 3, 300.0f, 3, 300.0f, FALSE, 1, 1.00f },- /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.25f, 75.0f, 300.0f, 2000.0f, 120.0f, 1.00f, 2.0f, 1.0f, 6, 240.0f, 2, 240.0f, TRUE, 1, 0.50f },- /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 45.0f, 240.0f, 4500.0f, 160.0f, 0.25f, 3.0f, 0.0f, DEFENSES_PER_SUPERWEAPON, 180.0f, 2, 180.0f, TRUE, 2, 0.25f }+ /* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE, 120.0f, 6000, 4.0f, 720.0f, 0.05f, 0.05f, 90.0f, 360.0f, 1500.0f, 80.0f, 0.00f, 0.0f, 2.0f, 3, 300.0f, 3, 300.0f, FALSE, 1, 1.00f, 4.0f, 3.00f, 0.0f, 0.60f, 10.0f },+ /* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE, 60.0f, 5000, 2.5f, 420.0f, 0.05f, 0.25f, 75.0f, 300.0f, 2000.0f, 120.0f, 1.00f, 2.0f, 1.0f, 6, 240.0f, 2, 240.0f, TRUE, 1, 0.50f, 2.0f, 1.00f, 150.0f, 0.80f, 20.0f },+ /* Hard */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE, 30.0f, 4000, 1.5f, 180.0f, 0.05f, 1.00f, 45.0f, 240.0f, 4500.0f, 160.0f, 0.25f, 3.0f, 0.0f, DEFENSES_PER_SUPERWEAPON, 180.0f, 2, 180.0f, TRUE, 2, 0.25f, 1.0f, 0.33f, 300.0f, 1.00f, 40.0f }};//-------------------------------------------------------------------------------------------------@@ -1403,7 +1416,7 @@ Real aiRetreatRatio( Real myHealth, Real myPower, Real enemyHealth, Real enemyPoreturn (ratio > NOT_A_FIGHT) ? NOT_A_FIGHT : ratio;}-static Bool gunsReach( Real x, Real y, const Real *guns, Int gunCount )+static Bool gunsReach( Real x, Real y, const Real *guns, Int gunCount, const AIInfluenceMap *map ){for( Int g = 0; g < gunCount; ++g ){@@ -1412,7 +1425,7 @@ static Bool gunsReach( Real x, Real y, const Real *guns, Int gunCount )if( gx * gx + gy * gy <= guns[ 3 * g + 2 ] * guns[ 3 * g + 2 ] )return TRUE;}- return FALSE;+ return map != NULL && map->enemyAt( x, y ) > 0.0f;}//-------------------------------------------------------------------------------------------------@@ -1420,7 +1433,7 @@ static Bool gunsReach( Real x, Real y, const Real *guns, Int gunCount )* spot no gun reaches with one more step of clear ground past it, that next step included; -1 when it* is not out by maxWalk, or walks off the map (bounds: low x, low y, high x, high y) first. */static Real walkOutOfReach( Real fromX, Real fromY, Real dirX, Real dirY, Real maxWalk, Real step,- const Real *guns, Int gunCount, const Real *bounds )+ const Real *guns, Int gunCount, const Real *bounds, const AIInfluenceMap *map ){for( Real along = step; along + step < maxWalk; along += step ){@@ -1428,8 +1441,8 @@ static Real walkOutOfReach( Real fromX, Real fromY, Real dirX, Real dirY, Real mconst Real nextY = fromY + dirY * (along + step);if( nextX < bounds[ 0 ] || nextY < bounds[ 1 ] || nextX > bounds[ 2 ] || nextY > bounds[ 3 ] )return -1.0f;- if( !gunsReach( fromX + dirX * along, fromY + dirY * along, guns, gunCount ) &&- !gunsReach( fromX + dirX * (along + step), fromY + dirY * (along + step), guns, gunCount ) )+ if( !gunsReach( fromX + dirX * along, fromY + dirY * along, guns, gunCount, map ) &&+ !gunsReach( fromX + dirX * (along + step), fromY + dirY * (along + step), guns, gunCount, map ) )return along + step;}return -1.0f;@@ -1445,10 +1458,12 @@ static Real walkOutOfReach( Real fromX, Real fromY, Real dirX, Real dirY, Real m* Gatling Cannons by Tournament Desert's middle docks among them, and one in seven units a Hard China* pulled out of a fight there died to a building within fifteen seconds of the order. A way that walks* off the map (bounds) is no way out; ground the pathfinder cannot stand on is its to move to the- * nearest that it can, as with any move. */+ * nearest that it can, as with any move. With a map, every enemy gun on it counts as well as the ones in+ * guns[]: those are the guns of the fight, and a spot clear of them stood under the next gun over. *///-------------------------------------------------------------------------------------------------Bool aiRetreatFallbackPoint( Real fromX, Real fromY, Real homeX, Real homeY, Real step,- const Real *guns, Int gunCount, const Real *bounds, Real *outX, Real *outY )+ const Real *guns, Int gunCount, const Real *bounds, Real *outX, Real *outY,+ const AIInfluenceMap *map ){*outX = homeX;*outY = homeY;@@ -1472,7 +1487,7 @@ Bool aiRetreatFallbackPoint( Real fromX, Real fromY, Real homeX, Real homeY, ReaReal bestWalk = 0.0f;for( Int w = 0; w < 5; ++w ){- const Real walk = walkOutOfReach( fromX, fromY, ways[ w ][ 0 ], ways[ w ][ 1 ], homeDist, step, guns, gunCount, bounds );+ const Real walk = walkOutOfReach( fromX, fromY, ways[ w ][ 0 ], ways[ w ][ 1 ], homeDist, step, guns, gunCount, bounds, map );if( walk >= 0.0f && (best < 0 || walk + step < bestWalk) ){best = w;@@ -1486,6 +1501,68 @@ Bool aiRetreatFallbackPoint( Real fromX, Real fromY, Real homeX, Real homeY, Reareturn TRUE;}+//-------------------------------------------------------------------------------------------------+AIFireAnswer aiAnswerFire( Bool onTheGun, Bool fightingAGun, Bool canShootNow, Bool canGetAtIt, Real ours, Real cover, Real odds, Bool mayLeave, Bool idle )+{+ if( onTheGun || fightingAGun )+ return AIFIRE_CARRY_ON;+ if( canShootNow )+ return AIFIRE_SHOOT_BACK;+ if( canGetAtIt && !aiOutgunned( ours, cover, odds ) )+ return AIFIRE_GO_KILL;+ if( mayLeave )+ return AIFIRE_LEAVE;+ if( !idle )+ return AIFIRE_CARRY_ON;+ return canGetAtIt ? AIFIRE_GO_KILL : AIFIRE_LEAVE;+}++//-------------------------------------------------------------------------------------------------+Real aiFireOddsNow( Real odds, Bool sentAtIt, Real margin )+{+ return sentAtIt ? odds / margin : odds;+}++//-------------------------------------------------------------------------------------------------+Bool aiFireMayGoBack( Bool sentAtIt )+{+ return !sentAtIt;+}++//-------------------------------------------------------------------------------------------------+Bool aiFireAnswerOver( Bool retreatHasIt, Bool steppedAway, UnsignedInt framesOnIt, UnsignedInt maxFrames )+{+ return retreatHasIt || steppedAway || framesOnIt >= maxFrames;+}++//-------------------------------------------------------------------------------------------------+Bool aiHolderLetGo( Bool retreatSeesIt, UnsignedInt heldFrames, Bool moving, UnsignedInt holdFrames, UnsignedInt staleFrames )+{+ if( heldFrames > staleFrames )+ return TRUE;+ return !retreatSeesIt && !moving && heldFrames > holdFrames;+}++//-------------------------------------------------------------------------------------------------+Bool aiFireMayLeave( Bool unitAtHome, Bool gunAtHome, Bool rungRetreats, Bool gunKnown, Real gunDistance, Real retreatRadius )+{+ if( unitAtHome )+ return !gunAtHome;+ return !(rungRetreats && gunKnown && gunDistance <= retreatRadius);+}++//-------------------------------------------------------------------------------------------------+Bool aiOutgunned( Real ours, Real cover, Real odds )+{+ return cover > 0.0f && ours < odds * cover;+}++//-------------------------------------------------------------------------------------------------+Bool aiRecentlyHit( UnsignedInt hitFrame, UnsignedInt now, UnsignedInt window )+{+ return hitFrame <= now && now - hitFrame <= window;+}+//-------------------------------------------------------------------------------------------------Bool aiWalkEntersReach( Real x, Real y, Real dirX, Real dirY, Real gunX, Real gunY, Real reach, Real edge, Real lookahead ){@@ -2375,6 +2452,11 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "StageDozers", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_stageDozers ) },{ "ArtillerySpotters", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_artillerySpotters ) },{ "ArtilleryShare", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_artilleryShare ) },+ { "InfluenceSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_influenceSeconds ) },+ { "FireLookSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireLookSeconds ) },+ { "FireWordRadius", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireWordRadius ) },+ { "FireChargeOdds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireChargeOdds ) },+ { "FireMemorySeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireMemorySeconds ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 05b749685..400a321a5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -6038,6 +6038,21 @@ static const Real INFLUENCE_CELL_SIZE = 60.0f;/** A unit that kited this recently is left in its fight by the retreat. */static const UnsignedInt KITE_KEEPS_FIGHT_FRAMES = 5 * LOGICFRAMES_PER_SECOND;+/** One of the rung's times in logic frames, never less than one. */+static Int rungFrames( Real seconds )+{+ return max<Int>( 1, REAL_TO_INT_FLOOR( seconds * LOGICFRAMES_PER_SECOND + 0.5f ) );+}++/** What stands on the map for a shooter: itself, or what it rides in (a garrison's building, an Overlord+ * under its bunker). */+static Object *gunCarrier( Object *shooter )+{+ while( shooter->getContainedBy() )+ shooter = shooter->getContainedBy();+ return shooter;+}+/** Clear ground all the way on the straight line between two points: no cliff, water or wall cell in* between. A spot on top of a ledge is a short step on the map and a long drive round by the ramp,* and a tactical step is only worth it when it is the short one. */@@ -8356,7 +8371,7 @@ Real AIPlayer::knownFirepowerAlongPath( Waypoint *way ){firepower += knownFirepowerNear( way->getLocation() );Waypoint *next = (way->getNumLinks() > 0) ? way->getLink( 0 ) : NULL;- if( next && m_influence.isBuilt() )+ if( next && hasTacticalMap() ){// the whole leg, not only its ends: a gun that covers the middle of a long leg between two// waypoints out of its reach is still on the road@@ -8393,9 +8408,9 @@ struct KnownDefence//----------------------------------------------------------------------------------------------------------/** Every enemy building this player knows of that shoots the ground, its garrison's guns included, in the* order of the object list. What a spot on the map scores is the guns among them that reach it. A- * list and not a layer of the influence map: that map is drawn for Hard alone, its enemy layer mixes the- * armies in, and every layer of it goes into a save; a match has a few dozen of these at most. Not a- * superweapon, whose gun reaches the whole map. */+ * list and not a layer of the influence map: that map is drawn on demand below Hard, its enemy layer+ * mixes the armies in, and every layer of it goes into a save; a match has a few dozen of these at most.+ * Not a superweapon, whose gun reaches the whole map. *///----------------------------------------------------------------------------------------------------------static void collectKnownDefences( const Player *player, std::vector<KnownDefence> *defences ){@@ -8448,7 +8463,7 @@ Real AIPlayer::knownFirepowerNear( const Coord3D *pos )// the influence map answers the question the radius only approximated: not what stands near the// road, but what can shoot onto it, the high ground's reach included. The radius count below also// took in this player's own units, which the affiliation filter lets through whatever it is asked.- if( m_influence.isBuilt() )+ if( hasTacticalMap() )return m_influence.enemyAt( pos->x, pos->y );PartitionFilterPlayerAffiliation enemies( m_player, ALLOW_ENEMIES, true );@@ -10026,7 +10041,7 @@ Real AIPlayer::waitingPower( Team *team, AIGroup *group ) constfor( DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance() ){Object *obj = iter.cur();- if( obj->isEffectivelyDead() || obj->getAI() == NULL || isOutOnOrders( obj ) )+ if( obj->isEffectivelyDead() || obj->getAI() == NULL || isOutOnOrders( obj ) || isFallingBack( obj->getID() ) )continue;power += aiCombatPower( obj );if( group == NULL )@@ -10213,6 +10228,14 @@ Bool AIPlayer::holdTeamForWave( Team *team, const AsciiString &approach, Int patstaging = hold;}}+ // the map chooses the ground: never a spot a gun it knows of already covers+ ensureInfluence();+ if( m_influence.enemyAt( staging.x, staging.y ) > 0.0f )+ {+ const Coord3D wanted = staging;+ if( !quietGround( &wanted, NULL, &staging ) )+ staging = wanted;+ }AIGroup *group = TheAI->createGroup();waitingPower( team, group );if( group->isEmpty() )@@ -10869,7 +10892,7 @@ Bool AIPlayer::loadGunships( void )// Only a wave's own man rides as cargo: one trained for a firing seat and sent to an unbunkered// Helix instead is a gunner lost, and the bunkered one he was bought for flew off emptyconst Bool fires = gunship->getContain()->isPassengerAllowedToFire( rider->getID() );- if( !fires && (!helicopter || !m_influence.isBuilt() || strcmp( r->from, "wave" ) != 0) )+ if( !fires && (!helicopter || !hasTacticalMap() || strcmp( r->from, "wave" ) != 0) )continue; // nothing would put cargo down without the tactics: gunship seats only// a seat he can shoot from before a nearer one he cannot, and a gunship's before a Humvee's: the// riders trained for a Combat Chinook walked into the Humvees parked nearer, and a Medium Air@@ -11894,10 +11917,10 @@ static const Real CHINOOK_CRUISE_SPEED = 150.0f;static const UnsignedInt SHUTTLE_TURNAROUND_FRAMES = 40 * LOGICFRAMES_PER_SECOND;/** A straight flight from a point to (x, y) crosses no cell the influence map says the enemy's known- * guns reach. Without the map (below Hard) nothing is known, and every flight is quiet. */+ * guns reach. Below Hard every flight is quiet: their map is drawn when a unit comes under fire. */Bool AIPlayer::flightIsQuiet( const Coord3D *from, Real x, Real y ) const{- if( !m_influence.isBuilt() )+ if( !hasTacticalMap() )return TRUE;const Real dx = x - from->x;const Real dy = y - from->y;@@ -11948,7 +11971,7 @@ void AIPlayer::computeShuttleFront( Waypoint *way, AIGroup *wave ){const Real x = road[ p - 1 ].x + legX * along / leg;const Real y = road[ p - 1 ].y + legY * along / leg;- hot = walked + along > length * SHUTTLE_DROP_SHARE || (m_influence.isBuilt() && m_influence.enemyAt( x, y ) > 0.0f);+ hot = walked + along > length * SHUTTLE_DROP_SHARE || (hasTacticalMap() && m_influence.enemyAt( x, y ) > 0.0f);if( !hot && flightIsQuiet( &m_baseCenter, x, y ) ){drop.x = x;@@ -14026,9 +14049,10 @@ void AIPlayer::doRetreats( void )Region3D map;TheTerrainLogic->getExtent( &map );const Real bounds[ 4 ] = { map.lo.x, map.lo.y, map.hi.x, map.hi.y };+ ensureInfluence();const Bool shortOfHome = !measuringWithoutTactics() &&aiRetreatFallbackPoint( centre.x, centre.y, m_baseCenter.x, m_baseCenter.y, INFLUENCE_CELL_SIZE,- enemyGuns.empty() ? NULL : &enemyGuns[ 0 ], (Int)enemyGuns.size() / 3, bounds, &fallback.x, &fallback.y );+ enemyGuns.empty() ? NULL : &enemyGuns[ 0 ], (Int)enemyGuns.size() / 3, bounds, &fallback.x, &fallback.y, &m_influence );if( shortOfHome )fallback.z = TheTerrainLogic->getGroundHeight( fallback.x, fallback.y );const Real homeX = m_baseCenter.x - centre.x;@@ -14102,10 +14126,12 @@ void AIPlayer::doRetreats( void )}/** A unit pulled out of a lost fight to a safe spot, and not yet sent back or home. */-Bool AIPlayer::isFallingBack( ObjectID unit )+Bool AIPlayer::isFallingBack( ObjectID unit ) const{- const TacticalStep *step = findTacticalStep( unit );- return step != NULL && step->fallingBack;+ for( size_t i = 0; i < m_tactics.size(); ++i )+ if( m_tactics[ i ].unit == unit )+ return m_tactics[ i ].fallingBack;+ return FALSE;}//----------------------------------------------------------------------------------------------------------@@ -14250,6 +14276,43 @@ void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myH}}+ /* A gun that has hit ours around here and that the walk above missed: one in the fog, or one past its+ radius. The siege guns start at 300, so a Tomahawk shelling a team from further off read enemy power+ 0, "not in a fight", with the team standing in its shells. Around here is where the gun stands or+ where it hit, so holders weigh a gun they walked away from as well as the ground they left. */+ const Int me = m_player->getPlayerIndex();+ for( size_t r = 0; r < m_fireReports.size(); ++r )+ {+ const FireReport &report = m_fireReports[ r ];+ if( sqr( report.hitAt.x - centre->x ) + sqr( report.hitAt.y - centre->y ) > sqr( RETREAT_ENGAGEMENT_RADIUS ) &&+ sqr( report.at.x - centre->x ) + sqr( report.at.y - centre->y ) > sqr( RETREAT_ENGAGEMENT_RADIUS ) )+ continue;+ Object *shooter = reportedShooter( report );+ if( shooter == NULL )+ continue;+ const Object *gun = gunCarrier( shooter );+ // one in view is where it is: the walk above met it, or it has driven off and no longer covers this+ if( observerKnowsAbout( gun, me ) )+ {+ const Real gunDistanceSqr = sqr( gun->getPosition()->x - centre->x ) + sqr( gun->getPosition()->y - centre->y );+ if( gunDistanceSqr <= sqr( RETREAT_ENGAGEMENT_RADIUS ) || gunDistanceSqr > sqr( report.reach + DEFENCE_FIGHT_SLACK ) )+ continue;+ }+ *enemyPower += report.power;+ *enemyHealth += gun->getBodyModule()->getHealth();+ addToArmy( theirKinds, gun );+ if( enemyGuns )+ {+ enemyGuns->push_back( report.at.x );+ enemyGuns->push_back( report.at.y );+ enemyGuns->push_back( report.reach );+ }+ // a building, as above: mortars in the fog behind a rush are no reason to leave the base to it+ if( defencePower && (gun->isKindOf( KINDOF_STRUCTURE ) || gun->isKindOf( KINDOF_IMMOBILE )) &&+ sqr( report.at.x - m_baseCenter.x ) + sqr( report.at.y - m_baseCenter.y ) > sqr( m_baseRadius ) )+ *defencePower += report.power;+ }+for( size_t i = 0; countHolders && i < m_tactics.size(); ++i ){if( !heldFrom( m_tactics[ i ].fallingBack, &m_tactics[ i ].fallbackFrom, centre ) )@@ -14295,6 +14358,8 @@ static const Real FALLBACK_RESUME_RATIO = 1.0f;static const UnsignedInt FALLBACK_STALE_FRAMES = FALLBACK_MAX_HOLD_FRAMES + 10 * LOGICFRAMES_PER_SECOND;/** How long the holders wait for every one of them to stop before the fight they left gets a say. */static const UnsignedInt FALLBACK_ARRIVE_MAX_FRAMES = 10 * LOGICFRAMES_PER_SECOND;+/** How long one that left a gun's ground holds when no retreat is looking at it. */+static const UnsignedInt FIRE_HOLD_FRAMES = 10 * LOGICFRAMES_PER_SECOND;//----------------------------------------------------------------------------------------------------------/** The members of this team holding at a safe spot after a lost fight. Once they have stopped, they go@@ -14377,6 +14442,12 @@ Bool AIPlayer::doFallback( Team *team )else if( what == AIFALLBACK_RESUME ){restoreMood( obj, step );+ // and committed, like one sent at a gun that hit it: back on the ground it left, the next hit does+ // not walk it off again on a reading the retreat would not act on+ step->origin = from;+ step->target = INVALID_ID;+ step->answerFrame = now;+ step->rejoin = FALSE;obj->getAI()->aiAttackMoveToPosition( &from, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );}else@@ -14390,10 +14461,8 @@ Bool AIPlayer::doFallback( Team *team )}//-----------------------------------------------------------------------------------------------------------/** How often the influence map is redrawn, and how often each fighting unit is looked at. Both are on- * the frame and the player's slot, so there is no timer to save and every machine does it on the- * same frame. */-static const Int INFLUENCE_REBUILD_RATE = LOGICFRAMES_PER_SECOND;+/** How often each fighting unit is looked at. This and the map's rung clock are on the frame and the+ * player's slot, so there is no timer to save and every machine does it on the same frame. */static const Int TACTICS_RATE = LOGICFRAMES_PER_SECOND / 3;/** Kiting. A unit steps back from something it outranges once that thing is inside its own reach@@ -14485,7 +14554,8 @@ void AIPlayer::keepSiegeBehind( void ){Object *gun = *o;if( gun->isEffectivelyDead() || gun->isContained() || gun->getAI() == NULL || gun->getGroup() == NULL ||- !isSiegeGun( gun ) || gun->getAI()->isAttacking() || isAtHome( gun->getPosition() ) || isFallingBack( gun->getID() ) )+ !isSiegeGun( gun ) || gun->getAI()->isAttacking() || isAtHome( gun->getPosition() ) || isFallingBack( gun->getID() ) ||+ isAnsweringFire( gun->getID() ) )continue;const Object *front = NULL;Real frontSqr = 0.0f;@@ -14863,13 +14933,15 @@ void AIPlayer::rebuildInfluence( void )m_influence.clear();const Int me = m_player->getPlayerIndex();+ // the friendly layer is for the tactics alone, so the rungs below Hard do not pay for it+ const Bool friends = getSkillProfile()->m_tacticalMicro;for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() ){if( obj->isEffectivelyDead() || obj->isKindOf( KINDOF_PROJECTILE ) )continue;const Bool mine = obj->getControllingPlayer() == m_player;const Relationship relation = m_player->getRelationship( obj->getTeam() );- if( !mine && relation != ENEMIES && relation != ALLIES )+ if( (mine || relation == ALLIES) ? !friends : relation != ENEMIES )continue;const Real power = aiCombatPower( obj );if( power <= 0.0f )@@ -14883,9 +14955,66 @@ void AIPlayer::rebuildInfluence( void )else if( observerKnowsAbout( obj, me ) )m_influence.stampEnemy( pos->x, pos->y, firingHeight( obj ), range, power );}+ // and the guns it knows of only by their shells, where they stood at the last one+ for( size_t r = 0; r < m_fireReports.size(); ++r )+ {+ const FireReport &report = m_fireReports[ r ];+ Object *shooter = reportedShooter( report );+ if( shooter && !observerKnowsAbout( gunCarrier( shooter ), me ) )+ m_influence.stampEnemy( report.at.x, report.at.y, report.at.z, report.reach, report.power );+ }m_influence.markBuilt( TheGameLogic->getFrame() );}+/** Hard draws its map on the clock (doTactics), and everything below Hard draws it here, when it has+ * something to read it for and it is older than the rung's m_influenceSeconds: rebuildInfluence is already+ * a fifth of Hard's AI update, and a quiet match has nothing to read it for. -notactics stays off the map+ * altogether, and every read of one never drawn is nothing there. */+void AIPlayer::ensureInfluence( void )+{+ if( measuringWithoutTactics() )+ return;+ // ponytail: below Hard one whole walk of the objects on one frame, every two or four seconds at most while+ // something asks; Hard's costs 2.38 ms on a late frame. Stamp it over frames as Hard's when that lands+ const AIDifficultyProfile *profile = getSkillProfile();+ if( m_influence.isBuilt() && (profile->m_tacticalMicro ||+ TheGameLogic->getFrame() - m_influence.getBuiltFrame() < (UnsignedInt)rungFrames( profile->m_influenceSeconds )) )+ return;+ rebuildInfluence();+}++/** Every rung reads the map for where to stand now, and drawn is not enough to say the rest may: the lanes,+ * the drops and the shuttles' flights are Hard's, and were switched on by the map being there at all. */+Bool AIPlayer::hasTacticalMap( void ) const+{+ return getSkillProfile()->m_tacticalMicro && m_influence.isBuilt();+}++/** The first ground towards home that the map has no gun on and this gun, when given (x, y, reach), does not+ * reach, by aiRetreatFallbackPoint. From home, where the road home goes nowhere, the way out is straight+ * away from the gun. FALSE, with home or that far from the gun in spot, when nothing nearer is quiet, which+ * is no reason for a group busy with something else to walk home on one hit. */+Bool AIPlayer::quietGround( const Coord3D *from, const Real *gun, Coord3D *spot )+{+ ensureInfluence();+ Region3D map;+ TheTerrainLogic->getExtent( &map );+ const Real bounds[ 4 ] = { map.lo.x, map.lo.y, map.hi.x, map.hi.y };+ Coord3D toward = m_baseCenter;+ if( gun && isAtHome( from ) )+ {+ const Real away = (Real)sqrt( sqr( from->x - gun[ 0 ] ) + sqr( from->y - gun[ 1 ] ) );+ if( away > 1.0f )+ {+ toward.x = from->x + (from->x - gun[ 0 ]) / away * 2.0f * gun[ 2 ];+ toward.y = from->y + (from->y - gun[ 1 ]) / away * 2.0f * gun[ 2 ];+ }+ }+ const Bool found = aiRetreatFallbackPoint( from->x, from->y, toward.x, toward.y, INFLUENCE_CELL_SIZE, gun, gun ? 1 : 0, bounds, &spot->x, &spot->y, &m_influence );+ spot->z = TheTerrainLogic->getGroundHeight( spot->x, spot->y );+ return found;+}+//----------------------------------------------------------------------------------------------------------AIPlayer::TacticalStep *AIPlayer::findTacticalStep( ObjectID unit ){@@ -14916,6 +15045,7 @@ AIPlayer::TacticalStep *AIPlayer::tacticalStepFor( ObjectID unit )step.fallingBack = FALSE;step.fallbackFrom.zero();step.fallbackFrame = 0;+ step.answerFrame = 0;m_tactics.push_back( step );return &m_tactics.back();}@@ -15047,8 +15177,14 @@ void AIPlayer::doTactics( void )const Int me = m_player->getPlayerIndex();const Bool tactics = getSkillProfile()->m_tacticalMicro;- if( tactics && (!m_influence.isBuilt() || (now + computeUpdatePhase( me, INFLUENCE_REBUILD_RATE )) % INFLUENCE_REBUILD_RATE == 0) )- rebuildInfluence();+ if( tactics )+ {+ const Int rebuildRate = rungFrames( getSkillProfile()->m_influenceSeconds );+ if( !m_influence.isBuilt() || (now + computeUpdatePhase( me, rebuildRate )) % rebuildRate == 0 )+ rebuildInfluence();+ }++ answerFire();if( (now + computeUpdatePhase( me, TACTICS_RATE )) % TACTICS_RATE != 0 )return;@@ -15072,8 +15208,12 @@ void AIPlayer::doTactics( void )// after a retreat is doFallback's until it sends it back or home, and doFallback does that by the// longest hold; one still holding well past it has left for a team doFallback never looks at (a// base defence), and gets its mood back here rather than stand calm and uncalled for good.+ // A rung that does not retreat and the default team have no doFallback to send on one that left a gun's+ // ground: let go, it is idle and the hunt and the next call-up have it.const Bool done = (unit == NULL || unit->isEffectivelyDead()) ? TRUE :- row.fallingBack ? now - row.fallbackFrame > FALLBACK_STALE_FRAMES :+ row.fallingBack ? aiHolderLetGo( getSkillProfile()->m_retreatTtkRatio > 0.0f && unit->getTeam() != m_player->getDefaultTeam(),+ now - row.fallbackFrame, unit->getAI() && unit->getAI()->isMoving(), FIRE_HOLD_FRAMES, FALLBACK_STALE_FRAMES ) :+ row.answerFrame != 0 ? FALSE : // finishAnswers ends thesetactics ? now - row.lastSeenFrame > TACTICAL_ROW_EXPIRY_FRAMES :now >= row.leaveAloneUntil && (unit->getAI() == NULL || !unit->getAI()->isMoving() || now >= row.leaveAloneUntil + WALK_HOME_MAX_FRAMES);if( done )@@ -15140,7 +15280,7 @@ void AIPlayer::doTransports( void )}// the dropped riders above include the transport Chinooks' cargo on every rung; the helicopters'// own drops below are Hard's, with its tactics running: nothing else loads the wave's infantry- if( !m_influence.isBuilt() )+ if( !hasTacticalMap() )return;LoadedTransports found;@@ -15249,38 +15389,49 @@ void AIPlayer::spotterStandOff( Object *obj, TacticalStep *step )}//-----------------------------------------------------------------------------------------------------------void AIPlayer::tacticsFor( Object *obj )+/** Who takes the orders the tactics and the answers to fire give, and who is left to what it is doing. */+//----------------------------------------------------------------------------------------------------------+Bool AIPlayer::fightsOnItsOwn( Object *obj ){// armed, not "able to attack" this frame: that reads false while a clip reloads, which is exactly// when a Rocket Buggy has to step away, and it took every buggy out of here the moment it had firedif( obj->isEffectivelyDead() || obj->isContained() || groundAttackRange( obj ) <= 0.0f )- return;+ return FALSE;if( obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_IMMOBILE ) || obj->isKindOf( KINDOF_AIRCRAFT ) ||obj->isKindOf( KINDOF_DOZER ) || obj->isKindOf( KINDOF_HARVESTER ) || obj->isKindOf( KINDOF_PROJECTILE ) )- return;+ return FALSE;AIUpdateInterface *ai = obj->getAI();if( ai == NULL || ai->hasTunnelTrip() || ai->getCurLocomotor() == NULL )- return; // a gun that cannot move (a Helix's gattling mount) has no step to take+ return FALSE; // a gun that cannot move (a Helix's gattling mount) has no step to take// base defence stays where it was put, and the scouts, the capturer and the hijacker have their jobsTeam *team = obj->getTeam();if( team == NULL || obj->isKindOf( KINDOF_MONEY_HACKER ) )- return;+ return FALSE;const TeamTemplateInfo *info = team->getPrototype()->getTemplateInfo();if( info && (info->m_isBaseDefense || info->m_isPerimeterDefense) )- return;+ return FALSE;// 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)// nor one pulled out to be mended: waiting its turn at an Arms Dealer's dock it stood still, and the// rejoin walked it back to the fight still hurtif( obj->getID() == m_capturerID || obj->getID() == m_hijackerID || isDutyHelix( obj ) || isDutyAmbulance( obj ) ||isWalkingToAmbulance( obj ) || isOutToMend( obj ) )- return;+ return FALSE;for( Int i = 0; i < MAX_AI_SCOUTS; ++i ){if( obj->getID() == m_scoutID[ i ] )- return;+ return FALSE;}+ return TRUE;+}+//----------------------------------------------------------------------------------------------------------+void AIPlayer::tacticsFor( Object *obj )+{+ if( !fightsOnItsOwn( obj ) )+ return;+ AIUpdateInterface *ai = obj->getAI();+ Team *team = obj->getTeam();const Coord3D *pos = obj->getPosition();const UnsignedInt now = TheGameLogic->getFrame();const Real threatHere = m_influence.enemyAt( pos->x, pos->y );@@ -15565,6 +15716,386 @@ void AIPlayer::tacticsFor( Object *obj )}}+//----------------------------------------------------------------------------------------------------------+/** How long a unit sent at a gun takes another hit on the odds that keep it going, which are lower than the+ * odds that sent it. Reading each hit afresh had it turn round halfway across, every time what covered the+ * gun changed by one tank. */+static const UnsignedInt FIRE_COMMIT_FRAMES = 20 * LOGICFRAMES_PER_SECOND;+/** The longest a unit counts as being on that errand: it has gone off on some other order by then. */+static const UnsignedInt FIRE_ANSWER_MAX_FRAMES = 60 * LOGICFRAMES_PER_SECOND;+/** How far under a rung's odds one on its way to a gun has to read before it breaks off (aiFireOddsNow). */+static const Real FIRE_RETURN_MARGIN = 1.25f;++/** Whether this shoots at things on the ground: a unit's own gun, or what a building has on it and in it. */+static Bool shootsGround( const Object *obj )+{+ Real reach = 0.0f;+ if( obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_IMMOBILE ) )+ return fixedGunPower( obj, &reach ) > 0.0f;+ return groundAttackRange( obj ) > 0.0f;+}++/** The enemy gun that hit this within the last window frames, or NULL. Not an aircraft: nothing out-walks+ * one, and what can shoot it picks it up by itself. Not a superweapon, whose reach is the whole map, nor a+ * mine. A long gun hitting from past sight stands at its launcher's place in the damage record, and+ * getClearableLastAttacker would clear it for the unit's own retaliation. */+static Object *lastShooter( const Object *obj, const Player *player, UnsignedInt now, UnsignedInt window )+{+ const BodyModuleInterface *body = obj->getBodyModule();+ if( body == NULL || !aiRecentlyHit( body->getLastDamageTimestamp(), now, window ) )+ return NULL;+ Object *shooter = TheGameLogic->findObjectByID( body->getLastDamageInfo()->in.m_sourceID );+ if( shooter == NULL || shooter->isEffectivelyDead() || shooter->isKindOf( KINDOF_PROJECTILE ) || gunCarrier( shooter )->isKindOf( KINDOF_AIRCRAFT ) ||+ shooter->isKindOf( KINDOF_FS_SUPERWEAPON ) || shooter->isKindOf( KINDOF_MINE ) || player->getRelationship( shooter->getTeam() ) != ENEMIES )+ return NULL;+ return groundAttackRange( shooter ) > 0.0f ? shooter : NULL;+}++Object *AIPlayer::reportedShooter( const FireReport &report ) const+{+ if( TheGameLogic->getFrame() - report.frame > (UnsignedInt)rungFrames( getSkillProfile()->m_fireMemorySeconds ) )+ return NULL;+ Object *shooter = TheGameLogic->findObjectByID( report.shooter );+ return shooter && !shooter->isEffectivelyDead() && m_player->getRelationship( shooter->getTeam() ) == ENEMIES ? shooter : NULL;+}++/** A gun measureFight meets by itself, known and near what it hit, needs no report. */+void AIPlayer::noteFire( const Object *shooter, const Object *gun, const Coord3D *hitAt )+{+ const Coord3D *at = gun->getPosition();+ const Bool known = observerKnowsAbout( gun, m_player->getPlayerIndex() );+ if( known && sqr( at->x - hitAt->x ) + sqr( at->y - hitAt->y ) <= sqr( RETREAT_ENGAGEMENT_RADIUS ) )+ return;+ for( size_t r = 0; r < m_fireReports.size(); ++r )+ {+ if( m_fireReports[ r ].shooter == shooter->getID() )+ {+ m_fireReports[ r ].at = *at;+ m_fireReports[ r ].hitAt = *hitAt;+ m_fireReports[ r ].frame = TheGameLogic->getFrame();+ return;+ }+ }+ FireReport report;+ report.shooter = shooter->getID();+ report.at = *at;+ report.hitAt = *hitAt;+ report.reach = groundAttackRange( shooter );+ report.power = aiCombatPower( shooter );+ report.frame = TheGameLogic->getFrame();+ m_fireReports.push_back( report );+ // on the map from now, not from the next time it is drawn+ if( !known )+ m_influence.stampEnemy( at->x, at->y, at->z, report.reach, report.power );+}++Bool AIPlayer::isAnsweringFire( ObjectID unit )+{+ const TacticalStep *step = findTacticalStep( unit );+ return step != NULL && step->answerFrame != 0;+}++/** Those that went for a gun and now stand idle, the gun dead or gone: back to the building they had been+ * shooting, or the ground they left. */+void AIPlayer::finishAnswers( void )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ for( size_t i = 0; i < m_tactics.size(); ++i )+ {+ TacticalStep &row = m_tactics[ i ];+ if( row.answerFrame == 0 )+ continue;+ Object *unit = TheGameLogic->findObjectByID( row.unit );+ // idle at a safe spot is not done with the fight+ if( unit == NULL || unit->isEffectivelyDead() || unit->getAI() == NULL ||+ aiFireAnswerOver( row.fallbackFrame != 0, row.rejoin, now - row.answerFrame, FIRE_ANSWER_MAX_FRAMES ) )+ {+ row.answerFrame = 0;+ continue;+ }+ row.lastSeenFrame = now;+ if( !unit->getAI()->isIdle() )+ continue;+ row.answerFrame = 0;+ Object *target = TheGameLogic->findObjectByID( row.target );+ if( target && !target->isEffectivelyDead() && observerKnowsAbout( target, m_player->getPlayerIndex() ) &&+ unit->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, target, CMD_FROM_AI ) != ATTACKRESULT_NOT_POSSIBLE )+ {+ unit->getAI()->aiAttackObject( target, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ continue;+ }+ // ponytail: a wave goes back to where it was hit and the idle team call-up sends it on, not its old road;+ // keep the order it was on in the row if the walk back shows+ if( sqr( row.origin.x - unit->getPosition()->x ) + sqr( row.origin.y - unit->getPosition()->y ) > sqr( INFLUENCE_CELL_SIZE ) )+ unit->getAI()->aiAttackMoveToPosition( &row.origin, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ }+}++static Bool lowerObjectID( const Object *a, const Object *b )+{+ return a->getID() < b->getID();+}++/** In ObjectID order: the partition's own order differs after a load, and orders and sums here decide things. */+void AIPlayer::fightersNear( const Coord3D *at, Real radius, std::vector<Object *> *fighters )+{+ PartitionFilterAlive filterAlive;+ PartitionFilterOnMap filterOnMap;+ PartitionFilter *filters[] = { &filterAlive, &filterOnMap, 0 };+ MemoryPoolObjectHolder hold;+ SimpleObjectIterator *nearby = ThePartitionManager->iterateObjectsInRange( at, radius, FROM_CENTER_2D, filters );+ hold.hold( nearby );+ for( Object *e = nearby->first(); e; e = nearby->next() )+ if( e->getControllingPlayer() == m_player && fightsOnItsOwn( e ) )+ fighters->push_back( e );+ std::sort( fighters->begin(), fighters->end(), lowerObjectID );+}++/** The gun's reading, once a look: what it would take to get it, by the map. */+const AIPlayer::GunReading &AIPlayer::readGun( const Object *obj, const Object *gun )+{+ for( size_t i = 0; i < m_gunReadings.size(); ++i )+ if( m_gunReadings[ i ].gun == gun->getID() )+ return m_gunReadings[ i ];++ ensureInfluence();+ const Coord3D *at = gun->getPosition();+ const Bool fixed = gun->isKindOf( KINDOF_STRUCTURE ) || gun->isKindOf( KINDOF_IMMOBILE );+ Real reach = 0.0f;+ GunReading reading;+ reading.gun = gun->getID();+ reading.frame = TheGameLogic->getFrame();+ // the map is up to the rung's clock old, and the gun itself is always there+ reading.cover = max<Real>( m_influence.enemyAt( at->x, at->y ), fixed ? fixedGunPower( gun, &reach ) : aiCombatPower( gun ) );+ reading.ours = 0.0f;+ std::vector<AIVisibleEnemy> mine, theirs;+ std::vector<Object *> fighters;+ fightersNear( obj->getPosition(), RETREAT_ENGAGEMENT_RADIUS, &fighters );+ for( size_t f = 0; f < fighters.size(); ++f )+ {+ if( templateFramesToKill( fighters[ f ]->getTemplate(), gun->getTemplate() ) < 0.0f )+ continue;+ reading.ours += aiCombatPower( fighters[ f ] );+ addToArmy( &mine, fighters[ f ] );+ }+ // by unit against unit as well as price, where the rung weighs fights that way: Red Guards are worth an+ // Inferno Cannon by the money, and burn+ if( getSkillProfile()->m_engageGate )+ {+ addToArmy( &theirs, gun );+ reading.ours *= (Real)sqrt( armyAdvantage( mine, theirs ) );+ }+ // a building's own cell is no place to walk to, its reach is what counts; and the owner's rule for a defence+ // holds whatever fired first, nobody walks into one short of the rung's odds at its edge (holdAtDefences).+ // Being shelled by it sent a parked team of four up to five Fire Bases, the first of them all it knew of+ reading.edge = fixed ? edgeRatio( gun, reach, obj->getPosition() ) : 0.0f;+ m_gunReadings.push_back( reading );+ return m_gunReadings.back();+}++/** One unit hit, one answer, by aiAnswerFire, and the order that goes with it. */+AIFireAnswer AIPlayer::answerHit( Object *obj, Object *shooter, Object *gun )+{+ AIUpdateInterface *ai = obj->getAI();+ const UnsignedInt now = TheGameLogic->getFrame();+ const StateID state = ai->getCurrentStateID();+ if( state == AI_DOCK || state == AI_ENTER || state >= 1000 )+ return AIFIRE_CARRY_ON;+ const TacticalStep *row = findTacticalStep( obj->getID() );+ Bool committed = FALSE;+ if( row )+ {+ // a kite or a climb under way+ if( row->resumeFrame != 0 )+ return AIFIRE_CARRY_ON;+ committed = row->answerFrame != 0 && now - row->answerFrame < FIRE_COMMIT_FRAMES;+ // on its way out, by this or by the retreat+ if( row->fallbackFrame == now || (ai->isMoving() && (row->fallingBack || now < row->leaveAloneUntil ||+ (row->fallbackFrame != 0 && now - row->fallbackFrame < RETREAT_HOME_WALK_FRAMES))) )+ return AIFIRE_CARRY_ON;+ }+ const Coord3D *pos = obj->getPosition();+ const Coord3D *at = gun->getPosition();+ const Object *victim = ai->getCurrentVictim();+ const Bool onTheGun = victim == gun || victim == shooter;+ const Bool fightingAGun = !onTheGun && victim && shootsGround( victim );+ const Bool canShootNow = !onTheGun && !fightingAGun && obj->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, gun, CMD_FROM_AI ) == ATTACKRESULT_POSSIBLE;+ const Bool fixed = gun->isKindOf( KINDOF_STRUCTURE ) || gun->isKindOf( KINDOF_IMMOBILE );+ const Bool holding = row && row->fallingBack;+ Real ours = 0.0f;+ Real cover = 0.0f;+ Bool canGetAtIt = FALSE;+ if( !onTheGun && !fightingAGun && !canShootNow )+ {+ const GunReading &reading = readGun( obj, gun );+ ours = reading.ours;+ cover = reading.cover;+ // a holder goes back when the hold says; a spotter's carbine is for show, the guns it spots for are what+ // answers this; and a gun nobody can see cannot be shot however close they walk+ canGetAtIt = !holding && !obj->getTemplate()->hasSpotterSight() && templateFramesToKill( obj->getTemplate(), gun->getTemplate() ) >= 0.0f &&+ (!gun->testStatus( OBJECT_STATUS_STEALTHED ) || gun->testStatus( OBJECT_STATUS_DETECTED )) &&+ (fixed ? reading.edge >= aiFireOddsNow( EDGE_ODDS[ m_skillLevel ], committed, FIRE_RETURN_MARGIN ) :+ TheAI->pathfinder()->clientSafeQuickDoesPathExist( ai->getLocomotorSet(), pos, at ));+ }+ const AIDifficultyProfile *profile = getSkillProfile();+ const Real distance = (Real)sqrt( sqr( at->x - pos->x ) + sqr( at->y - pos->y ) );+ const Bool mayLeave = aiFireMayLeave( isAtHome( pos ), isAtHome( at ), profile->m_retreatTtkRatio > 0.0f,+ observerKnowsAbout( gun, m_player->getPlayerIndex() ), distance, RETREAT_ENGAGEMENT_RADIUS );+ // the guns round the first one show up one hit at a time+ const AIFireAnswer answer = aiAnswerFire( onTheGun, fightingAGun, canShootNow, canGetAtIt, ours, cover,+ aiFireOddsNow( profile->m_fireChargeOdds, committed, FIRE_RETURN_MARGIN ), mayLeave, ai->isIdle() );+ if( answer == AIFIRE_CARRY_ON || (committed && answer != AIFIRE_LEAVE) )+ return AIFIRE_CARRY_ON;++ if( answer == AIFIRE_LEAVE )+ {+ const Real gunTriple[ 3 ] = { at->x, at->y, groundAttackRange( shooter ) };+ Coord3D spot;+ // with nothing quiet near, one with an order stays on it and one standing idle under the shells still goes+ if( (!quietGround( pos, gunTriple, &spot ) && !ai->isIdle()) || sqr( spot.x - pos->x ) + sqr( spot.y - pos->y ) < sqr( INFLUENCE_CELL_SIZE ) )+ return AIFIRE_CARRY_ON; // nowhere better+ DEBUG_LOG(("AI FIRE frame %d player %d '%s' %d hit by '%s' %.0f away leaves (%.0f,%.0f) for (%.0f,%.0f), %.0f against %.0f\n", now, m_player->getPlayerIndex(),+ obj->getTemplate()->getName().str(), obj->getID(), shooter->getTemplate()->getName().str(), distance, pos->x, pos->y, spot.x, spot.y, ours, cover));+ leaveTacticsAlone( obj->getID() );+ TacticalStep *step = findTacticalStep( obj->getID() );+ if( !step->fallingBack )+ step->fallbackFrame = now; // the hold's clock, which moving on does not start again+ step->fallingBack = TRUE;+ // going back to it means going for the gun, not onto its ground; home for one that has tried that+ step->fallbackFrom = aiFireMayGoBack( committed ) ? *at : m_baseCenter;+ step->answerFrame = 0;+ step->rejoin = FALSE;+ stepCalmly( obj, step, &spot );+ return answer;+ }++ DEBUG_LOG(("AI FIRE frame %d player %d '%s' %d hit by '%s' %.0f away %s from (%.0f,%.0f), %.0f against %.0f\n", now, m_player->getPlayerIndex(),+ obj->getTemplate()->getName().str(), obj->getID(), shooter->getTemplate()->getName().str(), distance,+ answer == AIFIRE_SHOOT_BACK ? "shoots back" : "goes for it", pos->x, pos->y, ours, cover));+ // shot from where it holds, on the hold's clock: taken off the hold, the next pass pulled it out again+ if( holding )+ {+ ai->aiAttackObject( gun, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ return answer;+ }+ TacticalStep *step = tacticalStepFor( obj->getID() );+ if( step->answerFrame == 0 )+ {+ step->target = victim ? victim->getID() : INVALID_ID;+ step->origin = *pos;+ }+ step->answerFrame = now;+ step->lastSeenFrame = now;+ step->rejoin = FALSE;+ step->fallingBack = FALSE;+ step->fallbackFrame = 0;+ restoreMood( obj, step );+ // a building it can aim at is aimed at, or it takes up the building it was shooting again on the way. A+ // gun out on the map is walked at, and whatever is in reach on the way is shot+ if( answer == AIFIRE_SHOOT_BACK || (fixed && obj->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, gun, CMD_FROM_AI ) != ATTACKRESULT_NOT_POSSIBLE) )+ ai->aiAttackObject( gun, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ else+ ai->aiAttackMoveToPosition( at, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ return answer;+}++/** Those of the player's objects whose turn in the look falls on this frame. */+struct FireLookTurn+{+ UnsignedInt look;+ UnsignedInt frameOfLook;+ std::vector<Object *> units;+};++static void collectFireLookTurn( Object *obj, void *userData )+{+ FireLookTurn *turn = (FireLookTurn *)userData;+ if( (UnsignedInt)obj->getID() % turn->look == turn->frameOfLook )+ turn->units.push_back( obj );+}++//----------------------------------------------------------------------------------------------------------+/** The owner: "bu ai lar artik su influence map i falan biraz ciddiye alsinlar, hedef aliniyorlar hala+ * devam ediyorlar ayni yerde." A unit idle or parked under a long gun only acquires what it can see, a+ * wave on its road only what its mood looks for, and one shooting a building stays on the building with+ * a tower on it, and none of the rest of the AI asked who was hitting them. So once in each of the rung's+ * looks each unit hit lately answers the gun that hit it: shoots it if it can; goes for it with whatever is+ * near it if the map says ours can take what covers its spot; and otherwise leaves that ground for ground+ * the map has quiet, and holds there. The rest of the AI is told as well: the gun goes on the map and into+ * the fights around it even from the fog (noteFire).+ *+ * A unit is looked at on the frame its ID comes up, so a look costs one share of the owner's objects a frame+ * and a stamp read for each. What surrounds a gun is read once a look, and that first read is the one that+ * tells the units round it; the map is drawn only if something needs it. */+//----------------------------------------------------------------------------------------------------------+void AIPlayer::answerFire( void )+{+ const AIDifficultyProfile *profile = getSkillProfile();+ const UnsignedInt now = TheGameLogic->getFrame();+ const Int look = rungFrames( profile->m_fireLookSeconds );+ if( !m_baseCenterSet )+ return;++ for( size_t i = 0; i < m_gunReadings.size(); )+ {+ if( now - m_gunReadings[ i ].frame < (UnsignedInt)look )+ {+ ++i;+ continue;+ }+ m_gunReadings[ i ] = m_gunReadings.back();+ m_gunReadings.pop_back();+ }+ if( (now + computeUpdatePhase( m_player->getPlayerIndex(), look )) % look == 0 )+ {+ for( size_t r = 0; r < m_fireReports.size(); )+ {+ if( reportedShooter( m_fireReports[ r ] ) )+ {+ ++r;+ continue;+ }+ m_fireReports[ r ] = m_fireReports.back();+ m_fireReports.pop_back();+ }+ finishAnswers();+ }++ FireLookTurn turn;+ turn.look = (UnsignedInt)look;+ turn.frameOfLook = now % turn.look;+ m_player->iterateObjects( collectFireLookTurn, &turn );+ std::sort( turn.units.begin(), turn.units.end(), lowerObjectID );+ for( size_t o = 0; o < turn.units.size(); ++o )+ {+ Object *obj = turn.units[ o ];+ if( obj->isEffectivelyDead() )+ continue;+ Object *shooter = lastShooter( obj, m_player, now, (UnsignedInt)look );+ if( shooter == NULL )+ continue;+ Object *gun = gunCarrier( shooter );+ noteFire( shooter, gun, obj->getPosition() ); // a building's or a worker's hit tells it where the gun is too+ if( !fightsOnItsOwn( obj ) )+ continue;+ const size_t known = m_gunReadings.size();+ const Object *victim = obj->getAI()->getCurrentVictim();+ const Bool onTheGun = victim == gun || victim == shooter;+ answerHit( obj, shooter, gun );+ // one already shooting the gun has no need of a reading, and went alone for want of one+ if( onTheGun )+ readGun( obj, gun );+ // the first unit to read this gun tells those around it, and what it read holds for them+ if( m_gunReadings.size() == known || profile->m_fireWordRadius <= 0.0f )+ continue;+ std::vector<Object *> fighters;+ fightersNear( obj->getPosition(), profile->m_fireWordRadius, &fighters );+ for( size_t f = 0; f < fighters.size(); ++f )+ if( fighters[ f ] != obj )+ answerHit( fighters[ f ], shooter, gun );+ }+}+//----------------------------------------------------------------------------------------------------------/** The cheapest thing this player could build that can walk somewhere and is not needed elsewhere.* Faction-agnostic on purpose - it lands on the Ranger, the Red Guard, the Rebel and the@@ -17677,7 +18208,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 31; // 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 bought 24: the starting fortune 25: the factory backlog clocks 26: the personality 27: the team request inbox 28: the last aircraft refused for parking 29: the watched sites and the cooled spots 30: the factory backlog as a window of passes 31: the factories that let a unit out since the last pass+ XferVersion currentVersion = 32; // 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 bought 24: the starting fortune 25: the factory backlog clocks 26: the personality 27: the team request inbox 28: the last aircraft refused for parking 29: the watched sites and the cooled spots 30: the factory backlog as a window of passes 31: the factories that let a unit out since the last pass 32: the guns known by their shells, the answers to fireXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -17894,8 +18425,8 @@ void AIPlayer::xfer( Xfer *xfer )}// the units part way through a tactical step, above all the mood each was calmed from: a game saved// in the middle of a kite would otherwise load a unit that stays calm for the rest of the match. And- // the influence map as it stands, since the next rebuild can be most of a second off and the lanes,- // the retreat and the steps all read it before then.+ // the influence map as it stands, since the next rebuild can be seconds off below Hard and everything+ // that picks where to stand reads it before then.if( version >= 9 ){m_influence.xfer( xfer );@@ -17929,6 +18460,10 @@ void AIPlayer::xfer( Xfer *xfer )step.fallbackFrom.zero();step.fallbackFrame = 0;}+ if( version >= 32 )+ xfer->xferUnsignedInt( &step.answerFrame );+ else+ step.answerFrame = 0;}}// the capturer's helicopter, and the riders a helicopter is putting down at a fight@@ -18177,6 +18712,36 @@ void AIPlayer::xfer( Xfer *xfer )xfer->xferObjectID( &m_producedSincePass[ i ] );}+ // the guns it knows of by their shells, so a loaded game keeps off the same ground+ if( version >= 32 )+ {+ UnsignedShort reports = (UnsignedShort)m_fireReports.size();+ xfer->xferUnsignedShort( &reports );+ m_fireReports.resize( reports );+ for( UnsignedShort i = 0; i < reports; ++i )+ {+ FireReport &report = m_fireReports[ i ];+ xfer->xferObjectID( &report.shooter );+ xfer->xferCoord3D( &report.at );+ xfer->xferCoord3D( &report.hitAt );+ xfer->xferReal( &report.reach );+ xfer->xferReal( &report.power );+ xfer->xferUnsignedInt( &report.frame );+ }+ UnsignedShort gunReadings = (UnsignedShort)m_gunReadings.size();+ xfer->xferUnsignedShort( &gunReadings );+ m_gunReadings.resize( gunReadings );+ for( UnsignedShort i = 0; i < gunReadings; ++i )+ {+ GunReading &reading = m_gunReadings[ i ];+ xfer->xferObjectID( &reading.gun );+ xfer->xferReal( &reading.ours );+ xfer->xferReal( &reading.cover );+ xfer->xferReal( &reading.edge );+ xfer->xferUnsignedInt( &reading.frame );+ }+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cppindex 8187b9069..6e8c80a18 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp@@ -601,7 +601,9 @@ Int AISkirmishPlayer::getMyEnemyPlayerIndex(void) {* are. Fog-masked, so it is somewhere this AI has actually seen; FALSE means it has not looked* yet and the caller keeps the old aim point.*- * Off on every rung, deliberately - see the note on useInfluenceMapForAttackLane in AI.cpp.+ * Hard's alone, and only where the map has no approach path to take: with one the attack goes down+ * the road chooseApproachLabel picks instead, since aiming at the money walked past the army. See the+ * note on useInfluenceMapForAttackLane in AI.cpp. This is the engine's cash layer, not AIInfluenceMap.*///----------------------------------------------------------------------------------------------------------Bool AISkirmishPlayer::influenceMapAttackGoal( Coord3D *goal )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 762a1b097..5b020e8d7 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13394,6 +13394,14 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)CHECK( upper.m_counterCompositionWeight >= lower.m_counterCompositionWeight );CHECK( upper.m_retreatTtkRatio >= lower.m_retreatTtkRatio );+ // under fire: redraws the map and looks sooner, tells more of the group, wants better odds before+ // going for a gun, and remembers a gun in the fog for longer+ CHECK( upper.m_influenceSeconds < lower.m_influenceSeconds );+ CHECK( upper.m_fireLookSeconds < lower.m_fireLookSeconds );+ CHECK( upper.m_fireWordRadius > lower.m_fireWordRadius );+ CHECK( upper.m_fireChargeOdds > lower.m_fireChargeOdds );+ CHECK( upper.m_fireMemorySeconds > lower.m_fireMemorySeconds );+// capabilities only ever switch on as you climb, never off againCHECK( upper.m_massBeforeAttacking >= lower.m_massBeforeAttacking );CHECK( upper.m_retreatIndividualUnits >= lower.m_retreatIndividualUnits );@@ -13912,6 +13920,169 @@ TEST(a_losing_team_falls_back_out_of_reach_not_home)}+/** AI.cpp: the safe spot is picked from the whole map and not only the guns of the fight it left. A gun the+ fight's list does not have, down the road home, moves the stop off the road as a gun in the list does. */+TEST(a_losing_team_keeps_off_every_gun_on_the_map)+{+ Real x = 0.0f, y = 0.0f;+ const Real bounds[] = { -1000.0f, -1000.0f, 3000.0f, 1000.0f };+ AIInfluenceMap influence;+ influence.reset( -1000.0f, -1000.0f, 4000.0f, 2000.0f, 60.0f );++ // nothing on it: one step and the next, along the road+ CHECK( aiRetreatFallbackPoint( 0.0f, 0.0f, 2000.0f, 0.0f, 60.0f, NULL, 0, bounds, &x, &y, &influence ) );+ CHECK_NEAR( 120.0f, x, 0.01f );+ CHECK_NEAR( 0.0f, y, 0.01f );++ // a gun at 300 east reaching 200 covers the road from about 100 to 500; 45 degrees off it is clear at+ // 120, and the list of the fight's guns is empty. The same call without the map walks straight in+ influence.stampEnemy( 300.0f, 0.0f, 0.0f, 200.0f, 900.0f );+ CHECK( aiRetreatFallbackPoint( 0.0f, 0.0f, 2000.0f, 0.0f, 60.0f, NULL, 0, bounds, &x, &y, &influence ) );+ CHECK_NEAR( 84.853f, x, 0.01f );+ CHECK_NEAR( 84.853f, y, 0.01f );+ CHECK( aiRetreatFallbackPoint( 0.0f, 0.0f, 2000.0f, 0.0f, 60.0f, NULL, 0, bounds, &x, &y ) );+ CHECK_NEAR( 120.0f, x, 0.01f );++ // the map all covered: home, and FALSE says so+ influence.stampEnemy( 0.0f, 0.0f, 0.0f, 5000.0f, 900.0f );+ CHECK( !aiRetreatFallbackPoint( 0.0f, 0.0f, 2000.0f, 0.0f, 60.0f, NULL, 0, bounds, &x, &y, &influence ) );+ CHECK_NEAR( 2000.0f, x, 0.01f );+}+++/** AI.cpp: what a unit hit does about the gun, the owner's rule: answer it if it can, leave if not, and no+ running from what ours can kill. */+TEST(a_unit_hit_answers_the_gun_or_leaves_its_ground)+{+ // already shooting the gun, or some other gun: stays on it, whatever the odds+ CHECK_EQ( (Int)AIFIRE_CARRY_ON, (Int)aiAnswerFire( TRUE, FALSE, TRUE, TRUE, 0.0f, 9000.0f, 1.0f, TRUE, FALSE ) );+ CHECK_EQ( (Int)AIFIRE_CARRY_ON, (Int)aiAnswerFire( FALSE, TRUE, TRUE, TRUE, 0.0f, 9000.0f, 1.0f, TRUE, FALSE ) );+ // shooting a building under a tower it can reach, or standing idle in a gun's reach: shoots back,+ // at any odds, since walking off takes longer than the shot+ CHECK_EQ( (Int)AIFIRE_SHOOT_BACK, (Int)aiAnswerFire( FALSE, FALSE, TRUE, TRUE, 100.0f, 9000.0f, 1.0f, TRUE, TRUE ) );+ // out of reach, with enough near it: goes, and a group that can kill the gun does not run from it+ CHECK_EQ( (Int)AIFIRE_GO_KILL, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 4800.0f, 2400.0f, 1.0f, TRUE, FALSE ) );+ // a gun with nothing else on its ground and the map not yet drawn over it: goes+ CHECK_EQ( (Int)AIFIRE_GO_KILL, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 100.0f, 0.0f, 1.0f, TRUE, FALSE ) );+ // out of reach and outgunned at the gun's spot, or no way to get at it: leaves+ CHECK_EQ( (Int)AIFIRE_LEAVE, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 1600.0f, 4800.0f, 1.0f, TRUE, FALSE ) );+ CHECK_EQ( (Int)AIFIRE_LEAVE, (Int)aiAnswerFire( FALSE, FALSE, FALSE, FALSE, 9000.0f, 900.0f, 1.0f, TRUE, FALSE ) );+ // ... unless it may not. With an order it stays on that order rather than walking+ CHECK_EQ( (Int)AIFIRE_CARRY_ON, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 1600.0f, 4800.0f, 1.0f, FALSE, FALSE ) );+ // and with none no rule leaves it standing under the shells: at the gun, or off its ground if it cannot get there+ CHECK_EQ( (Int)AIFIRE_GO_KILL, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 1600.0f, 4800.0f, 1.0f, FALSE, TRUE ) );+ CHECK_EQ( (Int)AIFIRE_LEAVE, (Int)aiAnswerFire( FALSE, FALSE, FALSE, FALSE, 1600.0f, 4800.0f, 1.0f, FALSE, TRUE ) );+ // the rungs' odds: Easy's go at what Hard's leave+ CHECK_EQ( (Int)AIFIRE_GO_KILL, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 3000.0f, 4800.0f, 0.6f, TRUE, FALSE ) );+ CHECK_EQ( (Int)AIFIRE_LEAVE, (Int)aiAnswerFire( FALSE, FALSE, FALSE, TRUE, 3000.0f, 4800.0f, 1.0f, TRUE, FALSE ) );+}+++/** AI.cpp: the owner's "no dance between two spots". Sent back from a hold at a fight reading 1.1, between the+ retreat's even and Hard's 1.25 at a defence's edge, a team went in, took a hit, read 1.25 afresh, left, held+ and went in again, and going back restarted the hold's clock, so its cap never came. */+TEST(a_unit_sent_at_a_gun_does_not_walk_to_and_fro)+{+ const Real margin = 1.25f;+ const Real reading = 1.1f;+ // what the hold's own rule sends back+ CHECK_EQ( (Int)AIFALLBACK_RESUME, (Int)aiRetreatHoldDecision( TRUE, 300, reading, 1.0f, 300, 1800 ) );+ // is not turned round by the reading either side of the odds+ CHECK( reading < aiFireOddsNow( 1.25f, FALSE, margin ) );+ CHECK( reading >= aiFireOddsNow( 1.25f, TRUE, margin ) );+ // and one that does break off has had its try: its hold ends at home, not at the gun+ CHECK( aiFireMayGoBack( FALSE ) );+ CHECK( !aiFireMayGoBack( TRUE ) );+}+++/** AI.cpp: a unit a step took away from a gun is done with that gun. Pulled out hurt with the errand still+ open, it stood at its safe spot, read as idle, and was walked back to what had hurt it. */+TEST(a_unit_pulled_out_hurt_is_not_sent_back_to_the_gun)+{+ CHECK( !aiFireAnswerOver( FALSE, FALSE, 600, 3600 ) );+ CHECK( aiFireAnswerOver( FALSE, TRUE, 600, 3600 ) ); // a step took it, by its rejoin+ CHECK( aiFireAnswerOver( TRUE, FALSE, 600, 3600 ) ); // the retreat took it+ CHECK( aiFireAnswerOver( FALSE, FALSE, 3600, 3600 ) ); // gone off on something else by now+}+++/** AI.cpp: who ends a hold. The retreat ends those it looks at. A hunter on the default team stood calm for+ forty seconds, out of every call-up, with nothing to send it on, and a rung with no retreat turned its unit+ back halfway to the quiet ground. */+TEST(a_holder_nothing_sends_on_goes_free_once_it_has_stopped)+{+ const UnsignedInt hold = 600;+ const UnsignedInt stale = 2400;+ // the retreat's: only when it has lost track of it+ CHECK( !aiHolderLetGo( TRUE, 2400, FALSE, hold, stale ) );+ CHECK( aiHolderLetGo( TRUE, 2401, FALSE, hold, stale ) );+ // nobody's: after the hold, and not while it is still walking there+ CHECK( !aiHolderLetGo( FALSE, 600, FALSE, hold, stale ) );+ CHECK( aiHolderLetGo( FALSE, 601, FALSE, hold, stale ) );+ CHECK( !aiHolderLetGo( FALSE, 601, TRUE, hold, stale ) );+ CHECK( aiHolderLetGo( FALSE, 2401, TRUE, hold, stale ) );+}+++/** AI.cpp: the two ways a unit is kept from walking off. A fight at home is fought, and a gun the retreat+ can see is the retreat's to judge, so a hit does not undo the fights it would hold. A gun it cannot see,+ the long one past its radius or one in the fog, is this rule's; so is any gun on a rung with no retreat. */+TEST(a_unit_hit_leaves_only_where_nothing_else_judges_the_fight)+{+ // home against a gun at home; at home under a long gun out past it is another matter, seen or not, since+ // the retreat breaks off no fight at home and they stood there until they died+ CHECK( !aiFireMayLeave( TRUE, TRUE, TRUE, FALSE, 500.0f, 300.0f ) );+ CHECK( !aiFireMayLeave( TRUE, TRUE, TRUE, TRUE, 200.0f, 300.0f ) );+ CHECK( aiFireMayLeave( TRUE, FALSE, TRUE, FALSE, 500.0f, 300.0f ) );+ CHECK( aiFireMayLeave( TRUE, FALSE, TRUE, TRUE, 200.0f, 300.0f ) );+ // known and within the retreat's look: not on a rung that retreats, yes on Easy+ CHECK( !aiFireMayLeave( FALSE, FALSE, TRUE, TRUE, 200.0f, 300.0f ) );+ CHECK( aiFireMayLeave( FALSE, FALSE, FALSE, TRUE, 200.0f, 300.0f ) );+ // past its look, or in the fog+ CHECK( aiFireMayLeave( FALSE, FALSE, TRUE, TRUE, 301.0f, 300.0f ) );+ CHECK( aiFireMayLeave( FALSE, FALSE, TRUE, FALSE, 200.0f, 300.0f ) );+}+++/** AI.cpp: the two small readings the answers rest on. */+TEST(outgunned_and_recently_hit_read_as_they_say)+{+ CHECK( aiOutgunned( 100.0f, 200.0f, 1.0f ) );+ CHECK( !aiOutgunned( 200.0f, 200.0f, 1.0f ) );+ CHECK( !aiOutgunned( 0.0f, 0.0f, 1.0f ) ); // nothing there: nothing to lose to+ CHECK( !aiOutgunned( 150.0f, 200.0f, 0.6f ) );++ CHECK( aiRecentlyHit( 100, 110, 20 ) );+ CHECK( aiRecentlyHit( 100, 120, 20 ) );+ CHECK( !aiRecentlyHit( 100, 121, 20 ) );+ // the stamp a body starts with is in the future, and an unsigned subtraction read it as just hit+ CHECK( !aiRecentlyHit( 0xffffffffu, 110, 20 ) );+}+++/** Every rung answers, and the ladder test holds the order. Hard's map stays on its one-second clock and its+ look on the twenty-frame tactics clock, so nothing here costs Hard a new rate. */+TEST(every_rung_answers_fire)+{+ TAiData data;+ for( Int i = 0; i < AISKILL_COUNT; ++i )+ {+ const AIDifficultyProfile &rung = data.m_skill[ i ];+ CHECK( rung.m_influenceSeconds > 0.0f );+ CHECK( rung.m_fireLookSeconds > 0.0f );+ CHECK( rung.m_fireWordRadius >= 0.0f );+ CHECK( rung.m_fireChargeOdds > 0.0f );+ CHECK( rung.m_fireMemorySeconds > 0.0f );+ }+ const AIDifficultyProfile &hard = data.m_skill[ AISKILL_BRUTAL ];+ CHECK_EQ( 1.0f, hard.m_influenceSeconds );+ CHECK_EQ( 20, (Int)(hard.m_fireLookSeconds * LOGICFRAMES_PER_SECOND + 0.5f) );+ // Easy answers each hit alone+ CHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_fireWordRadius );+}++/** AI.cpp: a unit walking at a known defence is caught while the next stretch of its walk only reachesthe slack round the gun, before it is in reach (AIPlayer::holdAtDefences). */TEST(a_walk_into_a_known_defence_is_seen_before_it_is_in_reach)