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(gameengine): AI helicopters leave when a superweapon goes up
Olcay Seyganb6d794ae0f8c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a9f5c7449..c6dde8dcb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -677,6 +677,7 @@ found and fixed, EA's own, not port damage.**- 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.- A tunnel or a barracks put up quietly at the edge of a computer's base used to stand there until it fired on something. Nothing had hit the computer yet, so as far as it knew nothing was wrong: on Easy your tunnel outlasted a five minute test and a Patriot battery lived 300 seconds. It now goes after any enemy building or ground unit it has seen inside its base, workers too, and a building raised in the fog counts from the moment it is spotted. With no shot fired, Easy has that tunnel dead in about 100 seconds and the Patriot battery in 70. Hard clears the tunnel in about 120, where it took 160 to 270, and Medium kills a barracks in 40, where it took 100 to 140.- Hard checks for this every 2 seconds, Medium every 6, Easy every 16, and each sends the nearest idle units it has at home. If those are too few, Easy trains up to what the intruder is worth, Medium half as much again and Hard twice. A computer that cannot see the building does nothing, so a tunnel it never looked at can still stand.+- A computer's helicopters used to hover under your superweapon until it landed. Six Comanches parked in the blast all died to a nuke on Easy and Hard, and Medium kept two. They now leave when they hear the launch warning you hear yourself, spreading out as they go: Hard in a third of a second, Medium in a second and a half, Easy in over three. Hard keeps all six against a nuke, a Scud Storm and a Particle Cannon, Medium loses at most one, Easy loses one to the beam. Easy's Helixes are slower and come out of a nuke alive with next to no health left. The warning never says where the strike is going, so the helicopters fly off from any launch, and those far from it lose a few seconds of the fight.- 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 quitdiff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex cdda8fa30..9e1a3d80d 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -445,6 +445,10 @@ Data/Scenarios/standinfake.txtData/Scenarios/stashbeside.txtData/Scenarios/statues.txtData/Scenarios/stealthintruder.txt+Data/Scenarios/strikeair_nuke.txt+Data/Scenarios/strikeair_nukehelix.txt+Data/Scenarios/strikeair_particle.txt+Data/Scenarios/strikeair_scud.txtData/Scenarios/sun_cloak.txtData/Scenarios/sun_trees.txtData/Scenarios/swhole.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/strikeair_nuke.txt b/GeneralsMD/Code/Data/Scenarios/strikeair_nuke.txtnew file mode 100644index 000000000..35990ec91--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/strikeair_nuke.txt@@ -0,0 +1,24 @@+# A nuclear missile aimed at six Comanches hovering in a computer player's base: who is left when it lands.+# The power verb fires with no countdown, and the launch reaches every seat the way it always has, as a notice with no place on it.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover 1 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 12000 -scenario strikeair_nuke++30 spawn 1 ChinaPowerPlant 2 start1:-280:-300 120+30 spawn 1 ChinaNuclearMissileLauncher 1 start1:-280:-120+3000 spawn 0 AmericaVehicleComanche 6 start0:240:120 40+3000 tally 0 AmericaVehicleComanche+3010 power 1 ChinaNuclearMissileLauncher start0:240:120+3010 tally 0 AmericaVehicleComanche+3090 tally 0 AmericaVehicleComanche+3180 tally 0 AmericaVehicleComanche+3270 tally 0 AmericaVehicleComanche+3360 tally 0 AmericaVehicleComanche+3450 tally 0 AmericaVehicleComanche+3540 tally 0 AmericaVehicleComanche+3630 tally 0 AmericaVehicleComanche+3720 tally 0 AmericaVehicleComanche+3900 tally 0 AmericaVehicleComanche+4200 tally 0 AmericaVehicleComanche+4800 tally 0 AmericaVehicleComanchediff --git a/GeneralsMD/Code/Data/Scenarios/strikeair_nukehelix.txt b/GeneralsMD/Code/Data/Scenarios/strikeair_nukehelix.txtnew file mode 100644index 000000000..9075f9c96--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/strikeair_nukehelix.txt@@ -0,0 +1,23 @@+# The same missile at four Helixes, the slowest helicopter there is.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover 1 -aidiff hard+# -side 0 FactionChina -side 1 FactionChina -seed 1 -maxframes 12000 -scenario strikeair_nukehelix++30 spawn 1 ChinaPowerPlant 2 start1:-280:-300 120+30 spawn 1 ChinaNuclearMissileLauncher 1 start1:-280:-120+3000 spawn 0 ChinaVehicleHelix 4 start0:240:120 40+3000 tally 0 ChinaVehicleHelix+3010 power 1 ChinaNuclearMissileLauncher start0:240:120+3010 tally 0 ChinaVehicleHelix+3090 tally 0 ChinaVehicleHelix+3180 tally 0 ChinaVehicleHelix+3270 tally 0 ChinaVehicleHelix+3360 tally 0 ChinaVehicleHelix+3450 tally 0 ChinaVehicleHelix+3540 tally 0 ChinaVehicleHelix+3630 tally 0 ChinaVehicleHelix+3720 tally 0 ChinaVehicleHelix+3900 tally 0 ChinaVehicleHelix+4200 tally 0 ChinaVehicleHelix+4800 tally 0 ChinaVehicleHelixdiff --git a/GeneralsMD/Code/Data/Scenarios/strikeair_particle.txt b/GeneralsMD/Code/Data/Scenarios/strikeair_particle.txtnew file mode 100644index 000000000..4ff3eab30--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/strikeair_particle.txt@@ -0,0 +1,23 @@+# A Particle Cannon aimed at six Comanches hovering in a computer player's base.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover 1 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionAmerica -seed 1 -maxframes 12000 -scenario strikeair_particle++30 spawn 1 AmericaPowerPlant 2 start1:-280:-300 120+30 spawn 1 AmericaParticleCannonUplink 1 start1:-280:-120+3000 spawn 0 AmericaVehicleComanche 6 start0:240:120 40+3000 tally 0 AmericaVehicleComanche+3010 power 1 AmericaParticleCannonUplink start0:240:120+3010 tally 0 AmericaVehicleComanche+3090 tally 0 AmericaVehicleComanche+3180 tally 0 AmericaVehicleComanche+3270 tally 0 AmericaVehicleComanche+3360 tally 0 AmericaVehicleComanche+3450 tally 0 AmericaVehicleComanche+3540 tally 0 AmericaVehicleComanche+3630 tally 0 AmericaVehicleComanche+3720 tally 0 AmericaVehicleComanche+3900 tally 0 AmericaVehicleComanche+4200 tally 0 AmericaVehicleComanche+4800 tally 0 AmericaVehicleComanchediff --git a/GeneralsMD/Code/Data/Scenarios/strikeair_scud.txt b/GeneralsMD/Code/Data/Scenarios/strikeair_scud.txtnew file mode 100644index 000000000..51066f98a--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/strikeair_scud.txt@@ -0,0 +1,22 @@+# A Scud Storm aimed at six Comanches hovering in a computer player's base.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover 1 -aidiff hard+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 12000 -scenario strikeair_scud++30 spawn 1 GLAScudStorm 1 start1:-280:-120+3000 spawn 0 AmericaVehicleComanche 6 start0:240:120 40+3000 tally 0 AmericaVehicleComanche+3010 power 1 GLAScudStorm start0:240:120+3010 tally 0 AmericaVehicleComanche+3090 tally 0 AmericaVehicleComanche+3180 tally 0 AmericaVehicleComanche+3270 tally 0 AmericaVehicleComanche+3360 tally 0 AmericaVehicleComanche+3450 tally 0 AmericaVehicleComanche+3540 tally 0 AmericaVehicleComanche+3630 tally 0 AmericaVehicleComanche+3720 tally 0 AmericaVehicleComanche+3900 tally 0 AmericaVehicleComanche+4200 tally 0 AmericaVehicleComanche+4800 tally 0 AmericaVehicleComanchediff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 362c7da1d..13b519500 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -273,6 +273,7 @@ enumAIKNOB_ANSWER_ARMY = 2,AIKNOB_MASS_UNIT = 4,AIKNOB_BASE_WATCH = 8,+ AIKNOB_STRIKE_DODGE = 16,};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex e8f506ae0..dde09e97b 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -613,6 +613,7 @@ public:/// Get the enemy an ai player is currently focused on. NOTE - Can be NULL.Player *getCurrentEnemy( void );void noteTeamRequest( Int kind, Int from, Int enemy, const Coord3D *pos ); ///< an ally's request, for this player's AI if it has one (aiPostTeamRequest)+ void noteStrikeLaunched( const Player *launcher ); ///< the word of a superweapon launch every seat hears, for this player's AI if it has one/// Is this player a skirmish ai player?Bool isSkirmishAIPlayer( void );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 1887a03dc..fcd03b3c3 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -292,6 +292,9 @@ struct AIDifficultyProfile// Enemies in the base that have not hit anything yet (AIPlayer::baseSquatter)Real m_baseWatchSeconds; ///< how often it looks for them, and so how late it answers; 0 = only once something has been hitReal m_baseWatchOdds; ///< what it trains and sends at them, in times their price++ // A superweapon going up, the word every seat hears (AIPlayer::dodgeStrike)+ Real m_strikeDodgeSeconds; ///< how long after that word its helicopters leave where they stand; 0 = they stay};//-------------------------------------------------------------------------------------------------@@ -432,6 +435,12 @@ Bool aiFireAnswerOver( Bool retreatHasIt, Bool steppedAway, UnsignedInt framesOn* 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 );+/** Where a helicopter at (x, y) goes when it hears a launch: reach away from the middle of the group it hangs+ * with (clumpX, clumpY), or off on its own line, picked by tie, when it is that middle. Back the other way when+ * the map ends first (bounds: low x, low y, high x, high y). Nobody knows where the shot is going, so reach is+ * twice the blast: from anywhere inside it, a straight flight that long ends outside whatever the heading. */+void aiStrikeDodgeSpot( Real x, Real y, Real clumpX, Real clumpY, Real reach, const Real *bounds, Int tie, Real *outX, Real *outY );+/** 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 adiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex ae279b748..8062f9450 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -274,6 +274,7 @@ public:AIPersonality getAIPersonality(void) const {return m_persona;}Bool superweaponIsPlan(void) const; ///< a Tech AI, or a GLA Air AI whose SCUD Storm stands in for the air force: its first superweapon is rushedvoid noteTeamRequest(AITeamRequestKind kind, Int from, Int enemy, const Coord3D *pos); ///< an ally asks (aiPostTeamRequest)+ void noteStrikeLaunched(const Player *launcher); ///< a superweapon went up, the word every seat hears: who fired, not where (dodgeStrike)/// HEADLESS PERSONA: one line of what this seat's personality did over the match, for ai-batchvoid logPersonaSummary(void);@@ -780,6 +781,8 @@ protected:Object *baseSquatter(Int *count, std::vector<AIVisibleEnemy> *army) const; ///< the known enemy nearest the base center inside the base, hit or not, a building and a worker includedvoid defendHome(void); ///< a base under attack trains fighters from its bank and sends its idle units invoid sendAtSquatter(Object *squatter, Real worth, const std::vector<Object *> &owned); ///< the nearest idle fighters at home, up to worth in combat power+ void dodgeStrike(void); ///< the rung's beat after the word of an enemy launch, the helicopters leave where they stand+ UnsignedInt m_strikeNoticeFrame; ///< when the word of an enemy launch came, 0 when it has been acted onReal waitingPower(Team *team, AIGroup *group) const; ///< what a team has for a wave, less the members out on orders; they join the group if one is given/** How hard this AI leans on its current enemy: its chance against him, looked at again on thediff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex e1476a66c..aca4ff421 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1339,7 +1339,7 @@ Int parseNoTactics(char *args[], int num)return 2;}-/** -aiknobsoff even|odd|all engagegate,answerarmy,massunit,basewatch: those slots keep their rung with these knobs+/** -aiknobsoff even|odd|all engagegate,answerarmy,massunit,basewatch,strikedodge: those slots keep their rung with these knobs* of its profile off, so a batch can play Hard against Hard without them, or a scenario against the AI* as it was. A measuring aid like -notactics: read only in a single-player skirmish, never in a* network game, and a replay made with it is played back with it given again. */@@ -1356,6 +1356,7 @@ Int parseAIKnobsOff(char *args[], int num)if (strstr(names.str(), "answerarmy")) mask |= AIKNOB_ANSWER_ARMY;if (strstr(names.str(), "massunit")) mask |= AIKNOB_MASS_UNIT;if (strstr(names.str(), "basewatch")) mask |= AIKNOB_BASE_WATCH;+ if (strstr(names.str(), "strikedodge")) mask |= AIKNOB_STRIKE_DODGE;TheWritableGlobalData->m_aiKnobsOffMask = mask;}return 3;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 1cf14198d..8bcde2a4b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -1338,6 +1338,12 @@ void Player::noteTeamRequest( Int kind, Int from, Int enemy, const Coord3D *posm_ai->noteTeamRequest( (AITeamRequestKind)kind, from, enemy, pos );}+void Player::noteStrikeLaunched( const Player *launcher )+{+ if( m_ai )+ m_ai->noteStrikeLaunched( launcher );+}+//-------------------------------------------------------------------------------------------------// PlayerObjectFindInfo is used to find a player's object. For example, we iterate through// to find a player's command center, or a specific building capable of firing the specifieddiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex e9ce3a35b..b6d0cc145 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1382,12 +1382,12 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* 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 watch watchOdds */+ * 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 watch watchOdds dodge */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, 4.0f, 3.00f, 0.0f, 0.60f, 10.0f, 16.0f, 1.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, 6.0f, 1.5f },- /* 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, 2.0f, 2.0f }+ /* 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, 16.0f, 1.0f, 3.25f },+ /* 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, 6.0f, 1.5f, 1.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, 1.0f, 0.33f, 300.0f, 1.00f, 40.0f, 2.0f, 2.0f, 0.33f }};//-------------------------------------------------------------------------------------------------@@ -1543,6 +1543,28 @@ Bool aiHolderLetGo( Bool retreatSeesIt, UnsignedInt heldFrames, Bool moving, Unsreturn !retreatSeesIt && !moving && heldFrames > holdFrames;}+//-------------------------------------------------------------------------------------------------+void aiStrikeDodgeSpot( Real x, Real y, Real clumpX, Real clumpY, Real reach, const Real *bounds, Int tie, Real *outX, Real *outY )+{+ Real dx = x - clumpX;+ Real dy = y - clumpY;+ Real length = (Real)sqrt( dx * dx + dy * dy );+ if( length < 1.0f )+ {+ dx = (tie & 1) ? 1.0f : -1.0f;+ dy = (tie & 2) ? 1.0f : -1.0f;+ length = (Real)sqrt( 2.0f );+ }+ dx *= reach / length;+ dy *= reach / length;+ if( x + dx < bounds[ 0 ] || x + dx > bounds[ 2 ] )+ dx = -dx;+ if( y + dy < bounds[ 1 ] || y + dy > bounds[ 3 ] )+ dy = -dy;+ *outX = x + dx;+ *outY = y + dy;+}+//-------------------------------------------------------------------------------------------------Bool aiFireMayLeave( Bool unitAtHome, Bool gunAtHome, Bool rungRetreats, Bool gunKnown, Real gunDistance, Real retreatRadius ){@@ -2465,6 +2487,7 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "FireMemorySeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireMemorySeconds ) },{ "BaseWatchSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_baseWatchSeconds ) },{ "BaseWatchOdds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_baseWatchOdds ) },+ { "StrikeDodgeSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeDodgeSeconds ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 5304ab068..56061636f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -439,6 +439,7 @@ m_role(AIROLE_AGGRESSIVE)m_heldSuffix[ held ] = 0;}m_heldSince = 0;+ m_strikeNoticeFrame = 0;m_pressure = AIPRESSURE_NORMAL;m_knownEnemyPower = 0.0f;m_pressureEnemy = -1;@@ -5719,6 +5720,7 @@ void AIPlayer::update( void )AI_PHASE( AIP_WAVE, answerArmy() ); // Train the answer to the part of it nothing answers.AI_PHASE( AIP_WAVE, doMass() ); // Build the fist, and send it when it is one.AI_PHASE( AIP_WAVE, doWaves() ); // Send the parked attack teams out together.+ AI_PHASE( AIP_TACTICS, dodgeStrike() ); // A superweapon went up: the helicopters do not wait to see where.AI_PHASE( AIP_TACTICS, doTactics() ); // Fight each unit from where it is strongest.AI_PHASE( AIP_TACTICS, holdAtDefences() ); // Wait at the edge of the guns, and shell what can be outranged.AI_PHASE( AIP_TACTICS, doTransports() ); // Put the helicopters' riders down at the fight.@@ -15448,6 +15450,91 @@ void AIPlayer::doTactics( void )}}+//----------------------------------------------------------------------------------------------------------+/** Twice the widest superweapon blast, 210 for the Neutron Missile and 200 for a Scud Storm's. */+static const Real STRIKE_DODGE_REACH = 450.0f;++void AIPlayer::noteStrikeLaunched( const Player *launcher )+{+ if( m_strikeNoticeFrame == 0 && runsOwnAI() && getSkillProfile()->m_strikeDodgeSeconds > 0.0f &&+ m_player->getRelationship( launcher->getDefaultTeam() ) == ENEMIES )+ m_strikeNoticeFrame = TheGameLogic->getFrame();+}++struct StrikeDodgers+{+ const AIPlayer *owner;+ ObjectID ferry;+ std::vector<Object *> ships;+};++static void collectStrikeDodgers( Object *obj, void *userData )+{+ StrikeDodgers *found = (StrikeDodgers *)userData;+ if( !found->owner->isGunshipAircraft( obj ) || found->owner->isTransportChinook( obj ) || obj->isContained() || obj->getID() == found->ferry )+ return;+ found->ships.push_back( obj );+}++/** Six Comanches hovering in a base died to a nuclear missile with five seconds of warning, four of them on Medium+ * and all six on the other rungs, and to a Scud Storm with ten. Every seat hears a launch announced. The aim is never said, its marker shows+ * only to the player firing, so the helicopters leave wherever they are, spread out from each other, and take+ * the retreat's own row: nothing calls a holder up, the hold's clock brings it back to the ground it left. One+ * launch anywhere costs each a few seconds of hovering somewhere else. Nothing here runs without a launch.+ * ponytail: ground units stay, too slow to clear a blast, and a jet flies its own loop; a visible missile's+ * heading would say more, at the cost of a walk over the projectiles every launch */+void AIPlayer::dodgeStrike( void )+{+ if( m_strikeNoticeFrame == 0 || TheGameLogic->getFrame() - m_strikeNoticeFrame < (UnsignedInt)rungFrames( getSkillProfile()->m_strikeDodgeSeconds ) )+ return;+ m_strikeNoticeFrame = 0;++ StrikeDodgers found;+ found.owner = this;+ found.ferry = m_ferryID;+ m_player->iterateObjects( collectStrikeDodgers, &found );+ if( found.ships.empty() )+ return;++ Region3D map;+ TheTerrainLogic->getExtent( &map );+ const Real bounds[ 4 ] = { map.lo.x, map.lo.y, map.hi.x, map.hi.y };+ const UnsignedInt now = TheGameLogic->getFrame();+ std::vector<Coord3D> spots( found.ships.size() );+ for( size_t s = 0; s < found.ships.size(); ++s )+ {+ const Coord3D *pos = found.ships[ s ]->getPosition();+ Real sumX = 0.0f, sumY = 0.0f;+ Int group = 0;+ for( size_t o = 0; o < found.ships.size(); ++o )+ {+ const Coord3D *other = found.ships[ o ]->getPosition();+ if( sqr( other->x - pos->x ) + sqr( other->y - pos->y ) > sqr( STRIKE_DODGE_REACH ) )+ continue;+ sumX += other->x;+ sumY += other->y;+ ++group;+ }+ aiStrikeDodgeSpot( pos->x, pos->y, sumX / group, sumY / group, STRIKE_DODGE_REACH, bounds, (Int)found.ships[ s ]->getID(), &spots[ s ].x, &spots[ s ].y );+ spots[ s ].z = TheTerrainLogic->getGroundHeight( spots[ s ].x, spots[ s ].y );+ }+ for( size_t s = 0; s < found.ships.size(); ++s )+ {+ Object *ship = found.ships[ s ];+ const Coord3D origin = *ship->getPosition();+ leaveTacticsAlone( ship->getID() );+ TacticalStep *step = findTacticalStep( ship->getID() );+ if( !step->fallingBack )+ step->fallbackFrame = now;+ step->fallingBack = TRUE;+ step->fallbackFrom = origin;+ step->answerFrame = 0;+ step->rejoin = FALSE;+ stepCalmly( ship, step, &spots[ s ] );+ }+ DEBUG_LOG(("AI STRIKE frame %d player %d flies %d helicopters off on the word of a launch\n", now, m_player->getPlayerIndex(), (Int)found.ships.size()));+}+//----------------------------------------------------------------------------------------------------------/** How often the loaded helicopters are looked at, and how far back from the fight they may land. */static const Int TRANSPORT_CHECK_RATE = LOGICFRAMES_PER_SECOND / 2;@@ -17557,6 +17644,7 @@ const AIDifficultyProfile *AIPlayer::getSkillProfile( void ) constif( mask & AIKNOB_ANSWER_ARMY ) m_measuredProfile.m_answerArmy = FALSE;if( mask & AIKNOB_MASS_UNIT ) m_measuredProfile.m_massUnit = FALSE;if( mask & AIKNOB_BASE_WATCH ) m_measuredProfile.m_baseWatchSeconds = 0.0f;+ if( mask & AIKNOB_STRIKE_DODGE ) m_measuredProfile.m_strikeDodgeSeconds = 0.0f;}if( m_persona == AIPERSONA_NORMAL )return &m_measuredProfile;@@ -18410,7 +18498,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 33; // 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 fire 33: the influence map being stamped+ XferVersion currentVersion = 34; // 34: the word of a launch not yet acted on 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 fire 33: the influence map being stampedXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -18948,6 +19036,9 @@ void AIPlayer::xfer( Xfer *xfer )if( version >= 33 )m_influenceNext.xfer( xfer );+ if( version >= 34 )+ xfer->xferUnsignedInt( &m_strikeNoticeFrame );+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cppindex 1b5b406f7..e4a1291ad 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp@@ -572,6 +572,16 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )getSpecialPowerModuleData()->m_specialPowerTemplate->getName(),getObject()->getID());+ // every seat hears a launch, below, and a computer player gets the same word: who fired, never where+ const SpecialPowerType launchType = getSpecialPowerModuleData()->m_specialPowerTemplate->getSpecialPowerType();+ if( launchType == SPECIAL_PARTICLE_UPLINK_CANNON || launchType == SUPW_SPECIAL_PARTICLE_UPLINK_CANNON || launchType == LAZR_SPECIAL_PARTICLE_UPLINK_CANNON ||+ launchType == SPECIAL_NEUTRON_MISSILE || launchType == NUKE_SPECIAL_NEUTRON_MISSILE || launchType == SUPW_SPECIAL_NEUTRON_MISSILE ||+ launchType == SPECIAL_SCUD_STORM )+ {+ for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )+ ThePlayerList->getNthPlayer( i )->noteStrikeLaunched( getObject()->getControllingPlayer() );+ }+// the observer's director camera goes to see it, a power aimed at a unit or at nothing included// (location NULL); this only tells the clientTheObserverCamera.noteSpecialPower( getObject()->getControllingPlayer(), getObject()->getPosition(), location,diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 2a018b07b..b0f9d1c57 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13467,6 +13467,9 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)CHECK( upper.m_baseWatchSeconds < lower.m_baseWatchSeconds );CHECK( upper.m_baseWatchOdds > lower.m_baseWatchOdds );+ // the word of a launch: its helicopters leave sooner+ CHECK( upper.m_strikeDodgeSeconds < lower.m_strikeDodgeSeconds );+// capabilities only ever switch on as you climb, never off againCHECK( upper.m_massBeforeAttacking >= lower.m_massBeforeAttacking );CHECK( upper.m_retreatIndividualUnits >= lower.m_retreatIndividualUnits );@@ -14075,6 +14078,26 @@ TEST(a_unit_pulled_out_hurt_is_not_sent_back_to_the_gun)/** AI.cpp: who ends a hold. The retreat ends those it looks at. A hunter on the default team stood calm forforty seconds, out of every call-up, with nothing to send it on, and a rung with no retreat turned its unitback halfway to the quiet ground. */+TEST(a_helicopter_hearing_a_launch_clears_any_blast_it_stands_in)+{+ const Real bounds[ 4 ] = { 0.0f, 0.0f, 5000.0f, 5000.0f };+ const Real reach = 450.0f;+ Real x, y;+ // away from the middle of its group+ aiStrikeDodgeSpot( 1000.0f, 1000.0f, 900.0f, 1000.0f, reach, bounds, 0, &x, &y );+ CHECK_EQ( 1450.0f, x );+ CHECK_EQ( 1000.0f, y );+ // alone: a line of its own, by the tie, and the full distance+ aiStrikeDodgeSpot( 1000.0f, 1000.0f, 1000.0f, 1000.0f, reach, bounds, 3, &x, &y );+ CHECK( x > 1000.0f && y > 1000.0f );+ CHECK( fabs( sqrt( (x - 1000.0f) * (x - 1000.0f) + (y - 1000.0f) * (y - 1000.0f) ) - reach ) < 0.01f );+ aiStrikeDodgeSpot( 1000.0f, 1000.0f, 1000.0f, 1000.0f, reach, bounds, 0, &x, &y );+ CHECK( x < 1000.0f && y < 1000.0f );+ // the map's edge turns it back+ aiStrikeDodgeSpot( 100.0f, 1000.0f, 200.0f, 1000.0f, reach, bounds, 0, &x, &y );+ CHECK_EQ( 550.0f, x );+}+TEST(a_holder_nothing_sends_on_goes_free_once_it_has_stopped){const UnsignedInt hold = 600;