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 builds its economy first, keeps artillery back
Olcay Seygan25780417b176
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f62fd7731..00b4c66ed 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -205,6 +205,8 @@ found and fixed — EA's own, not port damage.**- The USA computer stops flooding the field with Ambulances. Each lost one used to be bought again every minute and a half, and two USA computers put eight on the road in one sixteen-minute match. Hard now buys six in a whole match at most and Medium three, and Medium keeps only one at a time and waits three minutes to replace it. An Ambulance under fire backs out of reach before it heads for the War Factory to be repaired: sent straight there, it took the shortest road, often through the guns that had hurt it, and 20 of 31 lost Ambulances died on that drive. It no longer drives ahead of the army to wash a toxin pool, which is where three of the four lost in one Hard match died. The wounded men who never came back out are accounted for too. Of 23 called in over six test matches, 17 died within three seconds of the call, still in the fight that hurt them, and the other six all reached an Ambulance and walked out whole. Replays recorded before this change play out differently.- It comes at you from two sides. An attack big enough to be two sends a third of its strength down the second-quietest road, so you cannot meet the whole thing in one place.- It holds ground between attacks. Hard gathers its next wave a third of the way along the road to you, not in front of its own base, as long as nothing it has seen can shoot at that spot; otherwise it gathers at home.+- It builds its economy before it comes for you. No attack leaves a computer base in the opening minutes: six on Easy, five on Medium, four on Hard, and on Medium and Hard not before its first supply drop zone or black market stands, when it can build one. Medium and Easy now put that drop zone or black market up in the opening too, where only Hard did before. And it stops sending you two tanks at a time. A group too small to matter waits at home until enough has gathered to be an attack, about two tanks' worth on Easy, three and a half on Medium and five on Hard, even when the computer thinks it is winning. In one Hard against Hard match on Twilight Flame, the USA side's first attack left at six minutes instead of three and a quarter, after its drop zone, and the two sides sent 24 attacks instead of 47, 12 of them one to four units where 43 had been. Medium sent 9 instead of 19. Replays recorded before this change play out differently.+- Its artillery stays behind its tanks. Tomahawks, SCUD Launchers, Nuke and Inferno Cannons and Rocket Buggies walked in the same crowd as the rest of an attack, and the one that came round the corner first died to the first tank it met before its long gun was any use. Each one now keeps a little behind the attack's leading unit, farther on Hard than on Easy, and still fires at whatever comes into reach on the way. Replays recorded before this change play out differently.## The computer picks its fights- Which enemy it goes after was the nearest one and nothing else, plus a rule with its sign the wrong way round: an opponent who had lost his units or his production had his distance treated as half the map, so the computer ignored the one it was about to beat. That is what dragged matches out.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 906580ba6..54e260009 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -225,6 +225,11 @@ struct AIDifficultyProfileReal m_surplusShare; ///< of the income over aiSurplusBudget's window, how much a bank over target may train as extra unitsInt m_maxProduction; ///< war factories, barracks and airfields together, beyond which the spend rule adds noneReal m_factoryBankMultiple; ///< past this many times the bank target a factory is added whatever the bank's trend; 0 = only on the trend++ // Pushing: when the army first leaves home, and how small a force may go+ Real m_firstPushSeconds; ///< no attack before this, nor before the first drop zone or black market stands (AI_PURCHASE_EARLY_FRAMES at most)+ Real m_minAttackPower; ///< parked teams worth less than this wait for company, up to the wave's longest wait+ Real m_siegeTrail; ///< artillery out with a wave keeps this far behind its front unit; 0 = walks with it};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex 2dd3cb07c..ec3b6e94e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -658,6 +658,10 @@ protected:void updatePressure(void);void sendIdleUnitsHunting(void); ///< attack units idle at the end of their road, and the guards once the enemy is finishedBool holdsTeamsForWaves(void) const; ///< this rung parks attack teams at the current level+ Bool readyToPush(void); ///< the economy is in and the opening is over: attack teams may leave home+ Bool waveGoes(Real power, UnsignedInt heldFrames); ///< what is parked, worth this, leaves now+ void buyEarlyIncome(void); ///< the first drop zone and black market, ahead of the army+ void keepSiegeBehind(void); ///< artillery out with a wave trails its front unitBool leavesToFinish(const Object *obj) const; ///< a fighter the last push takes off guard, as against a worker or a scout/** Every enemy unit this AI has seen and not since lost track of: what it was, whose, and where and* when it was last in sight. An army that walks back into the fog is still an army. A row goes whendiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 0c5a6531b..bc276d76f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1143,9 +1143,9 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* 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 maxF fMult */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, 3, 0.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.10f, 3, 0.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, 8, 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, 3, 0.0f, 360.0f, 1500.0f, 80.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.10f, 3, 0.0f, 300.0f, 3000.0f, 120.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, 8, 2.0f, 240.0f, 4500.0f, 160.0f }};//-------------------------------------------------------------------------------------------------@@ -1789,6 +1789,9 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "SurplusShare", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_surplusShare ) },{ "MaxProduction", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_maxProduction ) },{ "FactoryBankMultiple", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_factoryBankMultiple ) },+ { "FirstPushSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_firstPushSeconds ) },+ { "MinAttackPower", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_minAttackPower ) },+ { "SiegeTrail", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siegeTrail ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 8e597f3a2..b99c43dd2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -5844,6 +5844,78 @@ void AIPlayer::doPower( void )placeNear( tmpl, &m_baseCenter, m_baseRadius, FALSE );}+//----------------------------------------------------------------------------------------------------------+/** The drop zone and the black market: what the opening buys before the army leaves home. */+static const Int EARLY_INCOME_KINDS = 2;+static const KindOfType EARLY_INCOME[ EARLY_INCOME_KINDS ] = { KINDOF_FS_SUPPLY_DROPZONE, KINDOF_FS_BLACK_MARKET };++/** Early in the match the first drop zone and the first black market do not wait for the hoard: they+ * are asked for when none stands, and the purchase queue ranks them over the army and saves for them.+ * Behind the hoard alone a Hard AI went out to fight on two gatherers before it owned either. */+void AIPlayer::buyEarlyIncome( void )+{+ if( !purchaseQueueOn() || TheGameLogic->getFrame() >= AI_PURCHASE_EARLY_FRAMES || !m_player->getCanBuildBase() ||+ !m_baseCenterSet || isBaseUnderAttack() )+ return;+ Object *dozer = NULL;+ m_player->iterateObjects( findAnyDozer, &dozer );+ for( Int i = 0; dozer && i < EARLY_INCOME_KINDS; ++i )+ {+ const ThingTemplate *tmpl = buildableOfKind( dozer, GUI_COMMAND_DOZER_CONSTRUCT, EARLY_INCOME[ i ], TRUE );+ if( tmpl == NULL || priorityBuildPending( m_player, tmpl ) )+ continue;+ TechCount owned;+ owned.kind = EARLY_INCOME[ i ];+ owned.standing = 0;+ owned.onTheWay = 0;+ m_player->iterateObjects( countTechBuildings, &owned );+ if( owned.standing + owned.onTheWay == 0 )+ placeNear( tmpl, &m_baseCenter, 0.5f * m_baseRadius, FALSE );+ }+}++/** Players said the computer attacks too early and too often. A Hard USA on Twilight Flame sent two+ * units at frame 5,873 and its first drop zone stood at 10,438. So no attack team leaves home before+ * m_firstPushSeconds, nor before a drop zone or black market stands when the side has one to build.+ * That wait ends with the opening buyEarlyIncome buys in, whatever stands, so a base that cannot+ * build one still plays. China has neither and waits for the clock alone. */+Bool AIPlayer::readyToPush( void )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ if( now < (UnsignedInt)(getSkillProfile()->m_firstPushSeconds * LOGICFRAMES_PER_SECOND) )+ return FALSE;+ if( now >= AI_PURCHASE_EARLY_FRAMES || !m_player->getCanBuildBase() )+ return TRUE;+ Object *dozer = NULL;+ m_player->iterateObjects( findAnyDozer, &dozer );+ const CommandSet *commandSet = dozer ? TheControlBar->findCommandSet( dozer->getCommandSetString() ) : NULL;+ if( commandSet == NULL )+ return TRUE;+ // one the dozer has the prerequisites for, whatever else stops it this moment: asking for one it+ // could make now, a Hard USA went out at 4.7 minutes, a minute before its drop zone stood. A USA+ // drop zone needs the Strategy Center, which Medium puts up late, and is not waited for before it+ Bool hasButton = FALSE;+ for( Int i = 0; i < EARLY_INCOME_KINDS; ++i )+ {+ for( Int b = 0; b < MAX_COMMANDS_PER_SET; ++b )+ {+ const CommandButton *button = commandSet->getCommandButton( b );+ if( button && button->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT && button->getThingTemplate() &&+ button->getThingTemplate()->isKindOf( EARLY_INCOME[ i ] ) &&+ TheBuildAssistant->canMakeUnit( dozer, button->getThingTemplate() ) != CANMAKE_NO_PREREQ )+ hasButton = TRUE;+ }+ TechCount owned;+ owned.kind = EARLY_INCOME[ i ];+ owned.standing = 0;+ owned.onTheWay = 0;+ m_player->iterateObjects( countTechBuildings, &owned );+ if( owned.standing > 0 )+ return TRUE;+ }+ return !hasButton;+}+//----------------------------------------------------------------------------------------------------------/** A bank of a hundred thousand is an army and an economy that were never bought. The skirmish build* list is a fixed plan - two war factories and a barracks - and the scripts never add to it, so@@ -5859,11 +5931,16 @@ void AIPlayer::doPower( void )void AIPlayer::doEconomy( void ){const AIDifficultyProfile *profile = getSkillProfile();- if( !profile->m_economyBuildings )- return;const Int phase = computeUpdatePhase( m_player->getPlayerIndex(), ECONOMY_CHECK_RATE );if( (TheGameLogic->getFrame() + phase) % ECONOMY_CHECK_RATE != 0 )return;+ // a rung that buys nothing else past its build list still puts its first income up before it pushes+ if( !profile->m_economyBuildings )+ {+ if( m_player->getEnergy()->hasSufficientPower() )+ buyEarlyIncome();+ return;+ }if( m_baseCenterSet ){@@ -5896,29 +5973,7 @@ void AIPlayer::doEconomy( void )doTunnels( dozer );}- // Early in the match the first drop zone and the first black market do not wait for the hoard: they- // are asked for when none stands, and the purchase queue ranks them over the army and saves for them.- // Behind the hoard alone a Hard AI went out to fight on two gatherers before it owned either.- if( purchaseQueueOn() && TheGameLogic->getFrame() < AI_PURCHASE_EARLY_FRAMES && m_player->getCanBuildBase() &&- m_baseCenterSet && !isBaseUnderAttack() )- {- Object *dozer = NULL;- m_player->iterateObjects( findAnyDozer, &dozer );- const KindOfType EARLY_INCOME[ 2 ] = { KINDOF_FS_SUPPLY_DROPZONE, KINDOF_FS_BLACK_MARKET };- for( Int i = 0; dozer && i < 2; ++i )- {- const ThingTemplate *tmpl = buildableOfKind( dozer, GUI_COMMAND_DOZER_CONSTRUCT, EARLY_INCOME[ i ], TRUE );- if( tmpl == NULL || priorityBuildPending( m_player, tmpl ) )- continue;- TechCount owned;- owned.kind = EARLY_INCOME[ i ];- owned.standing = 0;- owned.onTheWay = 0;- m_player->iterateObjects( countTechBuildings, &owned );- if( owned.standing + owned.onTheWay == 0 )- placeNear( tmpl, &m_baseCenter, 0.5f * m_baseRadius, FALSE );- }- }+ buyEarlyIncome();// hackers and the buildings that pay out on a timer earn their price back, so they only wait for// the hoard threshold, and each of them is bought on every pass the bank allows one ...@@ -7945,8 +8000,6 @@ Bool AIPlayer::holdTeamForWave( Team *team, const AsciiString &approach, Int patif( info->m_isBaseDefense || info->m_isPerimeterDefense )return FALSE;const Bool underAttack = isBaseUnderAttack();- if( !underAttack && !holdsTeamsForWaves() )- return refuseHold( team, "press", logRefusal );Int freeSlot = -1;Bool anyParked = FALSE;@@ -7962,10 +8015,15 @@ Bool AIPlayer::holdTeamForWave( Team *team, const AsciiString &approach, Int patreturn TRUE; // already parked; the script asking again changes nothinganyParked = TRUE;}+ // a wave on its own waits for nobody, and a rung that does not mass sends what is worth sending+ if( !underAttack && waveGoes( waitingPower( team, NULL ), 0 ) )+ return refuseHold( team, holdsTeamsForWaves() ? "alone" : "press", logRefusal );if( freeSlot < 0 )+ {+ if( !readyToPush() )+ return TRUE; // the opening keeps it at home, parked or notreturn refuseHold( team, "full", logRefusal ); // the staging point is full, so this one goes as the script said- if( !underAttack && aiReleaseWaveAt( m_pressure, waitingPower( team, NULL ), WAVE_POWER, 0, WAVE_MAX_HOLD_FRAMES ) )- return refuseHold( team, "alone", logRefusal ); // a wave on its own waits for nobody+ }m_heldUsed[ freeSlot ] = TRUE;m_heldTeam[ freeSlot ] = team->getID();@@ -8019,8 +8077,8 @@ Bool AIPlayer::holdTeamForWave( Team *team, const AsciiString &approach, Int pat//----------------------------------------------------------------------------------------------------------/** A skirmish script sends a team hunting, or at an area. Both go from wherever the team stands, on* their own, the moment the script fires: a team just out of the factory walks across the map alone,- * past the wave parked at the staging point. With EngageGate a team still mostly at home parks with- * that wave instead, and goes out with it. */+ * past the wave parked at the staging point. A team still mostly at home parks with that wave+ * instead, and goes out with it, unless it is worth sending on its own (waveGoes). *///----------------------------------------------------------------------------------------------------------Bool AIPlayer::gateTeamAttack( Team *team, const char *cause ){@@ -8038,7 +8096,8 @@ Bool AIPlayer::gateTeamAttack( Team *team, const char *cause )if( isAtHome( (*u)->getPosition() ) )++home;Player *enemy = getAiEnemy();- if( getSkillProfile()->m_engageGate && enemy && m_baseCenterSet && 2 * home >= (Int)units.size() &&+ // every rung: holdTeamForWave lets a team worth sending go, and keeps the rest for the next wave+ if( enemy && m_baseCenterSet && 2 * home >= (Int)units.size() &&holdTeamForWave( team, AsciiString( "Center" ), enemy->getMpStartIndex() + 1, FALSE ) ){DEBUG_LOG(("AI ENGAGE frame %d player %d parks '%s' for the next wave instead of its script's %s\n",@@ -8102,6 +8161,20 @@ Bool AIPlayer::holdsTeamsForWaves( void ) constreturn m_pressure == AIPRESSURE_DEFEND && profile->m_retreatTtkRatio > 0.0f;}+/** Whether parked teams worth power, the oldest parked heldFrames ago, leave now. Not before the+ * opening is over (readyToPush). A trickle under m_minAttackPower waits for company however long it+ * takes and whatever the pressure: in one 18,000-frame Twilight Flame match each, 43 of the 47+ * attacks two Hard AIs made were one to four units, and 14 of Medium's 19. Letting it go after the+ * wave's longest wait still sent two-unit Hard waves. */+Bool AIPlayer::waveGoes( Real power, UnsignedInt heldFrames )+{+ if( !readyToPush() || power < getSkillProfile()->m_minAttackPower )+ return FALSE;+ if( !holdsTeamsForWaves() )+ return power > 0.0f;+ return aiReleaseWaveAt( m_pressure, power, WAVE_POWER, heldFrames, WAVE_MAX_HOLD_FRAMES );+}+/** Who the last push takes out of a team the scripts keep at home. The workers, the hackers, the* scouts and whoever is out capturing keep their jobs, and a jet flies its own sorties. */Bool AIPlayer::leavesToFinish( const Object *obj ) const@@ -8230,6 +8303,7 @@ void AIPlayer::doWaves( void )defendHome();sendIdleAttackTeams();sendIdleUnitsHunting();+ keepSiegeBehind();Real power = 0.0f;Int first = -1;@@ -8264,8 +8338,8 @@ void AIPlayer::doWaves( void )const UnsignedInt heldFrames = TheGameLogic->getFrame() - m_heldSince;// a full staging point goes whatever it adds up to: sixteen GLA teams of one man each are 3,200, and// every team formed behind them would leave alone- // and a rung that does not mass lets go the moment the fight at home is over- if( teams < MAX_HELD_TEAMS && holdsTeamsForWaves() && !aiReleaseWaveAt( m_pressure, power, WAVE_POWER, heldFrames, WAVE_MAX_HOLD_FRAMES ) )+ // and a rung that does not mass lets go the moment what is parked is worth sending+ if( teams < MAX_HELD_TEAMS ? !waveGoes( power, heldFrames ) : !readyToPush() )return;const char *cause = !holdsTeamsForWaves() ? "press" : teams >= MAX_HELD_TEAMS ? "full" : power >= WAVE_POWER ? "wave" : "timeout";@@ -9216,7 +9290,7 @@ Real AIPlayer::addHomeStrays( AIGroup *wave ) const//----------------------------------------------------------------------------------------------------------void AIPlayer::sendIdleUnitsHunting( void ){- if( !isSkirmishAI() || !m_baseCenterSet || m_pressure == AIPRESSURE_DEFEND )+ if( !isSkirmishAI() || !m_baseCenterSet || m_pressure == AIPRESSURE_DEFEND || !readyToPush() )return;const Bool finish = m_pressure == AIPRESSURE_FINISH;const Bool guardsGo = finish &&@@ -11688,6 +11762,83 @@ static Real groundAttackRange( const Object *obj )return best;}+/** A ground vehicle whose gun outreaches the line: the Tomahawk, the Scud Launcher, the Nuke and Inferno+ * Cannons, the Rocket Buggy. Not one that carries anybody: the Battle Bus's dummy gun reaches 320. */+static const Real SIEGE_RANGE = 300.0f;+static Bool isSiegeGun( const Object *obj )+{+ return obj->isKindOf( KINDOF_VEHICLE ) && !obj->isKindOf( KINDOF_AIRCRAFT ) && obj->getContain() == NULL &&+ groundAttackRange( obj ) >= SIEGE_RANGE;+}++/** How far a trailing siege gun may stray from its place before it is sent back to it. */+static const Real SIEGE_SLACK = 60.0f;++/** A wave walks its road at the pace of the slowest and nobody keeps an order in it, so a Tomahawk or+ * a Nuke Cannon can be first round the corner, where it dies to the first tank it meets before its+ * long gun is any use. Each wave tick a siege gun out with a group and not firing is sent to a spot+ * m_siegeTrail behind the group's front unit, the line unit farthest from home, on the side towards+ * home. It attack-moves there, so whatever comes into its reach on the way is shot. When the group+ * has no line unit left it is left alone. The front is not the unit nearest the enemy's start: on+ * Twilight Flame that start was a guess, and a Paladin driving at the real enemy drove away from it.+ * ponytail: home is a straight line from the front, not the road; take the path's previous waypoint+ * if guns end up behind a cliff. */+void AIPlayer::keepSiegeBehind( void )+{+ const Real trail = getSkillProfile()->m_siegeTrail;+ if( !isSkirmishAI() || !m_baseCenterSet || trail <= 0.0f )+ return;+ const Coord3D &base = m_baseCenter;+ std::vector<Object *> owned;+ m_player->iterateObjects( collectObject, &owned );+ Int sent = 0;+ Int ahead = 0;+ for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )+ {+ 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() ) )+ continue;+ const Object *front = NULL;+ Real frontSqr = 0.0f;+ const VecObjectID &ids = gun->getGroup()->getAllIDs();+ for( VecObjectID::const_iterator it = ids.begin(); it != ids.end(); ++it )+ {+ const Object *mate = TheGameLogic->findObjectByID( *it );+ if( mate == NULL || mate == gun || mate->isEffectivelyDead() || mate->isContained() || mate->isKindOf( KINDOF_AIRCRAFT ) ||+ isSiegeGun( mate ) || aiCombatPower( mate ) <= 0.0f )+ continue;+ const Real d = sqr( mate->getPosition()->x - base.x ) + sqr( mate->getPosition()->y - base.y );+ if( front == NULL || d > frontSqr )+ {+ front = mate;+ frontSqr = d;+ }+ }+ if( front == NULL )+ continue;+ Coord2D home;+ home.x = base.x - front->getPosition()->x;+ home.y = base.y - front->getPosition()->y;+ if( home.x == 0.0f && home.y == 0.0f )+ continue;+ home.normalize();+ Coord3D spot = *front->getPosition();+ spot.x += home.x * trail;+ spot.y += home.y * trail;+ spot.z = TheTerrainLogic->getGroundHeight( spot.x, spot.y );+ if( sqr( gun->getPosition()->x - spot.x ) + sqr( gun->getPosition()->y - spot.y ) <= sqr( SIEGE_SLACK ) )+ continue;+ gun->getAI()->aiAttackMoveToPosition( &spot, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ ++sent;+ if( sqr( gun->getPosition()->x - base.x ) + sqr( gun->getPosition()->y - base.y ) > frontSqr )+ ++ahead;+ }+ if( sent > 0 )+ DEBUG_LOG(("AI SIEGE frame %d player %d puts %d siege guns %.0f behind their front, %d of them were ahead of it\n",+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), sent, trail, ahead));+}+/** Where a gun fires from, for the high ground's reach: an aircraft's range is flat* (Weapon_elevatedRange), so it counts as standing on the ground under it. */static Real firingHeight( const Object *obj )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex f7ce2ef3d..da6017460 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -11878,6 +11878,12 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)CHECK( upper.m_upgradeStartSeconds < lower.m_upgradeStartSeconds );CHECK( upper.m_surplusShare > lower.m_surplusShare );CHECK( upper.m_maxProduction >= lower.m_maxProduction );+ // every rung waits out an opening and sends no trickle, Hard the shortest wait and the biggest+ // floor; every rung keeps its artillery behind the line, Hard the farthest+ CHECK( lower.m_firstPushSeconds > 0.0f && upper.m_firstPushSeconds > 0.0f );+ CHECK( upper.m_firstPushSeconds <= lower.m_firstPushSeconds );+ CHECK( upper.m_minAttackPower > lower.m_minAttackPower && lower.m_minAttackPower > 0.0f );+ CHECK( upper.m_siegeTrail > lower.m_siegeTrail && lower.m_siegeTrail > 0.0f );}// Hard alone builds past its plan, and with a bank past twice its target; Medium out-armies Easy and// Hard out-armies Medium, which an equal share and cap for the two lower rungs had undone