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): the AI answers enemies in its base before they fire
Olcay Seygan9b8bf37f0365
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b16d6592b..df26d5a3c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -673,6 +673,8 @@ found and fixed, EA's own, not port damage.**- 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.+- 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.- 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/Data/Scenarios/baseintruder_barracks.txt b/GeneralsMD/Code/Data/Scenarios/baseintruder_barracks.txtnew file mode 100644index 000000000..f6d37028a--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/baseintruder_barracks.txt@@ -0,0 +1,40 @@+# A barracks with no gun put down in a computer player's base three minutes in: a building nothing has to answer until it trains.+#+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover 1 -aidiff hard+# -side 0 FactionGLA -side 1 FactionAmerica -seed 1 -maxframes 30000 -scenario baseintruder_barracks++# a second command center far off, so the match outlasts the seat's start falling+30 spawn 1 AmericaCommandCenter 1 4361 3126+5400 spawn 1 AmericaBarracks 1 start0:0:520+5400 tally 1 AmericaBarracks+5700 tally 1 AmericaBarracks+6000 tally 1 AmericaBarracks+6300 tally 1 AmericaBarracks+6600 tally 1 AmericaBarracks+6900 tally 1 AmericaBarracks+7200 tally 1 AmericaBarracks+7500 tally 1 AmericaBarracks+7800 tally 1 AmericaBarracks+8100 tally 1 AmericaBarracks+8400 tally 1 AmericaBarracks+8700 tally 1 AmericaBarracks+9000 tally 1 AmericaBarracks+9300 tally 1 AmericaBarracks+9600 tally 1 AmericaBarracks+9900 tally 1 AmericaBarracks+10200 tally 1 AmericaBarracks+10500 tally 1 AmericaBarracks+10800 tally 1 AmericaBarracks+11100 tally 1 AmericaBarracks+11400 tally 1 AmericaBarracks+11700 tally 1 AmericaBarracks+12000 tally 1 AmericaBarracks+12300 tally 1 AmericaBarracks+12600 tally 1 AmericaBarracks+12900 tally 1 AmericaBarracks+13200 tally 1 AmericaBarracks+13500 tally 1 AmericaBarracks+13800 tally 1 AmericaBarracks+14100 tally 1 AmericaBarracks+14400 tally 1 AmericaBarracksdiff --git a/GeneralsMD/Code/Data/Scenarios/baseintruder_patriot.txt b/GeneralsMD/Code/Data/Scenarios/baseintruder_patriot.txtnew file mode 100644index 000000000..5dd42c9a1--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/baseintruder_patriot.txt@@ -0,0 +1,41 @@+# A Patriot put down in a computer player's base three minutes in, with power behind it at the enemy's start.+#+# 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 FactionAmerica -seed 1 -maxframes 30000 -scenario baseintruder_patriot++30 spawn 1 AmericaPowerPlant 2 start1:-250:-100 120+# a second command center far off, so the match outlasts the seat's start falling+30 spawn 1 AmericaCommandCenter 1 4361 3126+5400 spawn 1 AmericaPatriotBattery 1 start0:0:520+5400 tally 1 AmericaPatriotBattery+5700 tally 1 AmericaPatriotBattery+6000 tally 1 AmericaPatriotBattery+6300 tally 1 AmericaPatriotBattery+6600 tally 1 AmericaPatriotBattery+6900 tally 1 AmericaPatriotBattery+7200 tally 1 AmericaPatriotBattery+7500 tally 1 AmericaPatriotBattery+7800 tally 1 AmericaPatriotBattery+8100 tally 1 AmericaPatriotBattery+8400 tally 1 AmericaPatriotBattery+8700 tally 1 AmericaPatriotBattery+9000 tally 1 AmericaPatriotBattery+9300 tally 1 AmericaPatriotBattery+9600 tally 1 AmericaPatriotBattery+9900 tally 1 AmericaPatriotBattery+10200 tally 1 AmericaPatriotBattery+10500 tally 1 AmericaPatriotBattery+10800 tally 1 AmericaPatriotBattery+11100 tally 1 AmericaPatriotBattery+11400 tally 1 AmericaPatriotBattery+11700 tally 1 AmericaPatriotBattery+12000 tally 1 AmericaPatriotBattery+12300 tally 1 AmericaPatriotBattery+12600 tally 1 AmericaPatriotBattery+12900 tally 1 AmericaPatriotBattery+13200 tally 1 AmericaPatriotBattery+13500 tally 1 AmericaPatriotBattery+13800 tally 1 AmericaPatriotBattery+14100 tally 1 AmericaPatriotBattery+14400 tally 1 AmericaPatriotBatterydiff --git a/GeneralsMD/Code/Data/Scenarios/baseintruder_tunnel.txt b/GeneralsMD/Code/Data/Scenarios/baseintruder_tunnel.txtnew file mode 100644index 000000000..fa2dc2bd1--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/baseintruder_tunnel.txt@@ -0,0 +1,42 @@+# An enemy Tunnel Network comes up in a computer player's base three minutes in: how long it stands.+# Seat 1 has no AI, so nothing else of the enemy's is near; the seat 0 rung plays the whole game.+# Ground 537,3708 on Twilight Flame takes a building on every rung and seed (LBC check in the spawn).+#+# 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 30000 -scenario baseintruder_tunnel++# a second command center far off, so the match outlasts the seat's start falling+30 spawn 1 GLACommandCenter 1 4361 3126+5400 spawn 1 GLATunnelNetwork 1 start0:0:520+5400 tally 1 GLATunnelNetwork+5700 tally 1 GLATunnelNetwork+6000 tally 1 GLATunnelNetwork+6300 tally 1 GLATunnelNetwork+6600 tally 1 GLATunnelNetwork+6900 tally 1 GLATunnelNetwork+7200 tally 1 GLATunnelNetwork+7500 tally 1 GLATunnelNetwork+7800 tally 1 GLATunnelNetwork+8100 tally 1 GLATunnelNetwork+8400 tally 1 GLATunnelNetwork+8700 tally 1 GLATunnelNetwork+9000 tally 1 GLATunnelNetwork+9300 tally 1 GLATunnelNetwork+9600 tally 1 GLATunnelNetwork+9900 tally 1 GLATunnelNetwork+10200 tally 1 GLATunnelNetwork+10500 tally 1 GLATunnelNetwork+10800 tally 1 GLATunnelNetwork+11100 tally 1 GLATunnelNetwork+11400 tally 1 GLATunnelNetwork+11700 tally 1 GLATunnelNetwork+12000 tally 1 GLATunnelNetwork+12300 tally 1 GLATunnelNetwork+12600 tally 1 GLATunnelNetwork+12900 tally 1 GLATunnelNetwork+13200 tally 1 GLATunnelNetwork+13500 tally 1 GLATunnelNetwork+13800 tally 1 GLATunnelNetwork+14100 tally 1 GLATunnelNetwork+14400 tally 1 GLATunnelNetworkdiff --git a/GeneralsMD/Code/Data/Scenarios/baseintruder_worker.txt b/GeneralsMD/Code/Data/Scenarios/baseintruder_worker.txtnew file mode 100644index 000000000..3f6c2c47b--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/baseintruder_worker.txt@@ -0,0 +1,40 @@+# A worker walks into a computer player's base three minutes in, the first step of a tunnel or a Patriot: how long it lives.+#+# 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 30000 -scenario baseintruder_worker++# a second command center far off, so the match outlasts the seat's start falling+30 spawn 1 GLACommandCenter 1 4361 3126+5400 spawn 1 GLAInfantryWorker 1 start0:0:520+5400 tally 1 GLAInfantryWorker+5700 tally 1 GLAInfantryWorker+6000 tally 1 GLAInfantryWorker+6300 tally 1 GLAInfantryWorker+6600 tally 1 GLAInfantryWorker+6900 tally 1 GLAInfantryWorker+7200 tally 1 GLAInfantryWorker+7500 tally 1 GLAInfantryWorker+7800 tally 1 GLAInfantryWorker+8100 tally 1 GLAInfantryWorker+8400 tally 1 GLAInfantryWorker+8700 tally 1 GLAInfantryWorker+9000 tally 1 GLAInfantryWorker+9300 tally 1 GLAInfantryWorker+9600 tally 1 GLAInfantryWorker+9900 tally 1 GLAInfantryWorker+10200 tally 1 GLAInfantryWorker+10500 tally 1 GLAInfantryWorker+10800 tally 1 GLAInfantryWorker+11100 tally 1 GLAInfantryWorker+11400 tally 1 GLAInfantryWorker+11700 tally 1 GLAInfantryWorker+12000 tally 1 GLAInfantryWorker+12300 tally 1 GLAInfantryWorker+12600 tally 1 GLAInfantryWorker+12900 tally 1 GLAInfantryWorker+13200 tally 1 GLAInfantryWorker+13500 tally 1 GLAInfantryWorker+13800 tally 1 GLAInfantryWorker+14100 tally 1 GLAInfantryWorker+14400 tally 1 GLAInfantryWorkerdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 1f632695d..362c7da1d 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -272,6 +272,7 @@ enumAIKNOB_ENGAGE_GATE = 1,AIKNOB_ANSWER_ARMY = 2,AIKNOB_MASS_UNIT = 4,+ AIKNOB_BASE_WATCH = 8,};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 6c220faf7..1887a03dc 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -288,6 +288,10 @@ struct AIDifficultyProfileReal m_fireWordRadius; ///< how far from a unit hit the rest of the group goes with it; 0 = each answers its own hit aloneReal m_fireChargeOdds; ///< ours near the unit have to be worth this many times what covers the gun before they go for itReal m_fireMemorySeconds; ///< how long a gun that hit it stays on its map after it has lost sight of it++ // 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 hit+ Real m_baseWatchOdds; ///< what it trains and sends at them, in times their price};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex e0af31f96..ae279b748 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -777,7 +777,9 @@ protected:Bool isAtHome(const Coord3D *pos) const; ///< within two base radii of the base centerBool isBaseUnderAttack(void) const; ///< hit lately, with a known enemy that can shoot standing at homeObject *homeIntruder(Int *count, std::vector<AIVisibleEnemy> *army) const; ///< the enemy nearest the base center while the base is under attack+ 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 in+ void sendAtSquatter(Object *squatter, Real worth, const std::vector<Object *> &owned); ///< the nearest idle fighters at home, up to worth in combat powerReal 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 cbe398276..e1476a66c 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: those slots keep their rung with these knobs+/** -aiknobsoff even|odd|all engagegate,answerarmy,massunit,basewatch: 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. */@@ -1355,6 +1355,7 @@ Int parseAIKnobsOff(char *args[], int num)if (strstr(names.str(), "engagegate")) mask |= AIKNOB_ENGAGE_GATE;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;TheWritableGlobalData->m_aiKnobsOffMask = mask;}return 3;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 1c011d9b6..e9ce3a35b 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 */+ * 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 */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 },- /* 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 }+ /* 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 }};//-------------------------------------------------------------------------------------------------@@ -2463,6 +2463,8 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "FireWordRadius", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireWordRadius ) },{ "FireChargeOdds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireChargeOdds ) },{ "FireMemorySeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_fireMemorySeconds ) },+ { "BaseWatchSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_baseWatchSeconds ) },+ { "BaseWatchOdds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_baseWatchOdds ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 1a8544a7d..5304ab068 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -8732,6 +8732,45 @@ Object *AIPlayer::homeIntruder( Int *count, std::vector<AIVisibleEnemy> *army )return nearest;}+/** A Tunnel Network put up behind the barracks shoots at nothing until something walks past, and a worker+ * with a Patriot on his mind never shoots at all. homeIntruder wants a hit and a gun, so on Easy such a+ * tunnel stood for the rest of the match and on Hard for up to four minutes. This asks for neither: anything+ * that walks or stands, known to this AI, inside the base itself. It stays out of isBaseUnderAttack: that has+ * some 25 readers and one Patriot would stop the economy and the waves for as long as it stood. Not an+ * aircraft, which is gone before an answer arrives and is homeIntruder's when it fires. */+Object *AIPlayer::baseSquatter( Int *count, std::vector<AIVisibleEnemy> *army ) const+{+ *count = 0;+ if( !m_baseCenterSet )+ return NULL;+ PartitionFilterAlive filterAlive;+ PartitionFilterOnMap filterOnMap;+ PartitionFilter *filters[] = { &filterAlive, &filterOnMap, NULL };+ // the base radius runs through the outer buildings: a tunnel just behind them is still in the base+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( &m_baseCenter, 1.5f * m_baseRadius, FROM_CENTER_2D, filters );+ MemoryPoolObjectHolder hold( iter );+ Object *nearest = NULL;+ Real nearestSqr = 0.0f;+ for( Object *obj = iter->first(); obj; obj = iter->next() )+ {+ if( !(obj->isKindOf( KINDOF_STRUCTURE ) || obj->isKindOf( KINDOF_INFANTRY ) || obj->isKindOf( KINDOF_VEHICLE )) ||+ obj->isKindOf( KINDOF_AIRCRAFT ) || obj->isKindOf( KINDOF_MINE ) || obj->isKindOf( KINDOF_DEMOTRAP ) || obj->isKindOf( KINDOF_DRONE ) )+ continue;+ if( m_player->getRelationship( obj->getTeam() ) != ENEMIES || !observerKnowsAbout( obj, m_player->getPlayerIndex() ) )+ continue;+ ++*count;+ addToVisibleArmy( army, obj->getTemplate(), obj->getControllingPlayer(),+ INT_TO_REAL( obj->getTemplate()->calcCostToBuild( obj->getControllingPlayer() ) ) );+ const Real distSqr = sqr( obj->getPosition()->x - m_baseCenter.x ) + sqr( obj->getPosition()->y - m_baseCenter.y );+ if( nearest == NULL || distSqr < nearestSqr )+ {+ nearest = obj;+ nearestSqr = distSqr;+ }+ }+ return nearest;+}+/** Everything that can build a unit, finished and standing. */static void collectFactories( Object *obj, void *userData ){@@ -8814,6 +8853,63 @@ static void creditAnswer( const ThingTemplate *tmpl, const Player *owner, const(*answered)[ best ] += cost;}+/** A unit that could go at a squatter, and how far it has to go. */+struct SquatterHunter+{+ Object *unit;+ Real distSqr;+};++static Bool nearerHunter( const SquatterHunter &a, const SquatterHunter &b )+{+ return a.distSqr != b.distSqr ? a.distSqr < b.distSqr : a.unit->getID() < b.unit->getID();+}++/** The nearest idle fighters at home, up to worth counted in aiCombatPower with those already on it, by a+ * direct order: an attack move walks past a building that shoots at nothing. A worker draws one rifle+ * and not the whole wave parked at home. */+void AIPlayer::sendAtSquatter( Object *squatter, Real worth, const std::vector<Object *> &owned )+{+ std::vector<SquatterHunter> hunters;+ for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )+ {+ Object *obj = *o;+ if( obj->isEffectivelyDead() || obj->isContained() || obj->getAI() == NULL || obj->isKindOf( KINDOF_IMMOBILE ) ||+ !isAtHome( obj->getPosition() ) || !leavesToFinish( obj ) )+ continue;+ if( obj->getAI()->getGoalObject() == squatter || obj->getAI()->getCurrentVictim() == squatter )+ {+ worth -= aiCombatPower( obj );+ continue;+ }+ const StateID state = obj->getAI()->getCurrentStateID();+ if( state != AI_IDLE && state != AI_GUARD && state != AI_GUARD_RETALIATE && state != AI_MOVE_AND_TIGHTEN )+ continue;+ if( obj->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET, squatter, CMD_FROM_AI ) < ATTACKRESULT_POSSIBLE_AFTER_MOVING )+ continue;+ SquatterHunter hunter;+ hunter.unit = obj;+ hunter.distSqr = sqr( obj->getPosition()->x - squatter->getPosition()->x ) + sqr( obj->getPosition()->y - squatter->getPosition()->y );+ hunters.push_back( hunter );+ }+ std::sort( hunters.begin(), hunters.end(), nearerHunter );+ // an attack order on a building out in the fog ends at once, for a computer player: walk there first+ const Bool inView = ThePartitionManager->getShroudStatusForPlayer( m_player->getPlayerIndex(), squatter->getPosition() ) == CELLSHROUD_CLEAR;+ Int sent = 0;+ for( size_t h = 0; h < hunters.size() && worth > 0.0f; ++h )+ {+ if( inView )+ hunters[ h ].unit->getAI()->aiAttackObject( squatter, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ else+ hunters[ h ].unit->getAI()->aiAttackMoveToPosition( squatter->getPosition(), NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ worth -= aiCombatPower( hunters[ h ].unit );+ ++sent;+ }+ if( sent > 0 )+ DEBUG_LOG(("AI SQUATTER frame %d player %d sends %d idle units at '%s' at (%.0f,%.0f), base radius %.0f\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), sent, squatter->getTemplate()->getName().str(), squatter->getPosition()->x, squatter->getPosition()->y, m_baseRadius));+}+//----------------------------------------------------------------------------------------------------------/** A base under attack spends its bank on the fight. A Hard USA rushed a minute in had two fighting* units and 8,000 in the bank, because the opening goes on buildings first and the team plan trains@@ -8832,9 +8928,18 @@ void AIPlayer::defendHome( void )Int intruders = 0;std::vector<AIVisibleEnemy> army;Object *intruder = homeIntruder( &intruders, &army );- if( intruder == NULL )- return;- if( m_persona != AIPERSONA_NORMAL )+ // nobody has been hit: still look round the base on the rung's clock, this being a turn of doWaves' tick+ const Bool squatter = intruder == NULL;+ if( squatter )+ {+ const Real watch = getSkillProfile()->m_baseWatchSeconds;+ if( watch <= 0.0f || (TheGameLogic->getFrame() + computeUpdatePhase( m_player->getPlayerIndex(), WAVE_CHECK_RATE )) % rungFrames( watch ) >= WAVE_CHECK_RATE )+ return;+ intruder = baseSquatter( &intruders, &army );+ if( intruder == NULL )+ return;+ }+ if( m_persona != AIPERSONA_NORMAL && !squatter )personaChat( "Hit" );// Two deep. The queue this builds reads to doEconomy as a barracks that cannot keep up, and a rushed@@ -8871,8 +8976,13 @@ void AIPlayer::defendHome( void )for( size_t k = 1; k < army.size(); ++k )if( army[ k ].m_weight - answered[ k ] > army[ kind ].m_weight - answered[ kind ] )kind = k;- const ThingTemplate *unit = bestDefender( *f, m_player, army[ kind ] );- if( unit == NULL || !buyUnit( pu, unit, AIBUY_EMERGENCY ) )+ // a squatter gets what it is worth and no more: the bank is for the match, which is still on+ if( squatter && answered[ kind ] >= army[ kind ].m_weight * getSkillProfile()->m_baseWatchOdds )+ break;+ Real score = 0.0f;+ const ThingTemplate *unit = bestDefender( *f, m_player, army[ kind ], FALSE, &score );+ // and never an Ambulance bought because nothing here hurts it+ if( unit == NULL || (squatter && score <= 0.0f) || !buyUnit( pu, unit, AIBUY_EMERGENCY ) )break;answered[ kind ] += INT_TO_REAL( unit->calcCostToBuild( m_player ) );DEBUG_LOG(("AI DEFEND frame %d player %d trains '%s' at '%s' against %d intruders, %d in the bank\n",@@ -8886,7 +8996,7 @@ void AIPlayer::defendHome( void )// it over the minute its base was being hitObject *dozer = NULL;m_player->iterateObjects( findAnyDozer, &dozer );- if( dozer && m_player->getCanBuildBase() )+ if( dozer && m_player->getCanBuildBase() && !squatter ){const ThingTemplate *defense = nextBaseDefense( dozer );Bool going = FALSE;@@ -8929,7 +9039,8 @@ void AIPlayer::defendHome( void )// much again, and four Crusaders are not. The advantage is the square law's, so its root scales powerif( getSkillProfile()->m_engageGate )homePower *= (Real)sqrt( armyAdvantage( home, army ) );- if( homePower < 0.5f * intruderWorth )+ // one that cannot shoot is worth going at with anything+ if( homePower < 0.5f * intruderWorth && !(squatter && !intruder->isAbleToAttack()) )return;// A gun standing still outside the base itself is not coming in: on a small map the enemy's own towers// and an expansion's Patriots sit within two base radii, and idle units sent at them one or two at a@@ -8967,6 +9078,12 @@ void AIPlayer::defendHome( void )if( covered && homePower < OUTSIDE_BASE_ODDS[ m_skillLevel ] * (intruderWorth + cover) )return;+ if( squatter )+ {+ sendAtSquatter( intruder, intruderWorth * getSkillProfile()->m_baseWatchOdds, owned );+ return;+ }+Int sent = 0;for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o ){@@ -17439,6 +17556,7 @@ const AIDifficultyProfile *AIPlayer::getSkillProfile( void ) constif( mask & AIKNOB_ENGAGE_GATE ) m_measuredProfile.m_engageGate = FALSE;if( 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( m_persona == AIPERSONA_NORMAL )return &m_measuredProfile;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 1858de719..36b2ec914 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -13448,6 +13448,10 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)CHECK( upper.m_fireChargeOdds > lower.m_fireChargeOdds );CHECK( upper.m_fireMemorySeconds > lower.m_fireMemorySeconds );+ // an enemy in the base that has not fired: looks sooner and sends more+ CHECK( upper.m_baseWatchSeconds < lower.m_baseWatchSeconds );+ CHECK( upper.m_baseWatchOdds > lower.m_baseWatchOdds );+// capabilities only ever switch on as you climb, never off againCHECK( upper.m_massBeforeAttacking >= lower.m_massBeforeAttacking );CHECK( upper.m_retreatIndividualUnits >= lower.m_retreatIndividualUnits );