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
fix(gameengine): give up building sites dozers cannot reach, stage idle ones
Olcay Seygane67adc47426a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d4125c08c..a0054554c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -356,6 +356,9 @@ found and fixed — EA's own, not port damage.**- It keeps its money-makers and its superweapons at home. A Hard computer with a full base looked for room further and further out until the map ended, and a black market or a Scud Storm could go up alone on ground nobody held. Those buildings, and the tech building a superweapon waits on, now go inside the base or at its edge, and when there is no room they are not built: the money goes into another factory. Expansions are held to the same standard: a supply centre only goes to a pile on its own side of the map and within reach of home, never to one with an enemy standing at it, and the next expansion waits until the last one has a gun or a guard beside it. Replays recorded before this change play out differently.- A guarded supply pile no longer stops its expansion. One enemy tank parked beside the nearest pile held a Hard computer's expansion for ten minutes while a free pile sat one valley over; it takes the nearest safe pile now, and the unsafe one only when nothing else is left.- It captures the derricks behind its own base first. Each capture used to send the engineer on to the derrick nearest where he stood, so the round walked out into the middle of the map and the ones at home waited for minutes.+- A building it cannot finish no longer holds its money and its spot all match. The computer could put a supply center down at a far pile in enemy ground, lose every dozer it sent there on the way, and leave the empty scaffold standing: the money stayed spent, and no later expansion or gun went to that pile because the scaffold was already there. Now it cancels the building and takes its money back, as you would, once two dozers have died on the way with nothing built (three on Easy), or once a site away from its base has gone three minutes without any progress (four on Medium, five on Easy). It leaves that spot and its pile alone for three minutes on Hard, four on Medium and five on Easy before it tries there again.+- Idle dozers walk ahead. When the computer knows the next building it wants and is only waiting for the money, a dozer with nothing to do walks over to the spot, so the building starts when the money comes instead of after the walk. It never takes one off a job, off repairs or off a supply run. Medium and Hard do this; Easy waits as before.+- Replays recorded before these two changes play out differently.## The computer spends its moneydiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex f77c6df0d..25fbbad85 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -268,6 +268,12 @@ struct AIDifficultyProfileReal m_strikeEconomyWeight; ///< what a factory, power plant, superweapon, supply centre, black market, hacker or strategy centre is worth to a strike on top of its price, in prices; 0 = price aloneReal m_strikeThreatWeight; ///< what an armed unit or gun is worth to a strike on top of its price, in combat power; 0 = price alone, and his army is a candidate only when none of his buildings isInt m_superweaponDefenses; ///< finished base defences each superweapon asks for (Player::canBuildMoreOfType); 0 = none++ // Building sites: when a placed building is given up, and whether idle dozers walk ahead to the next one+ Real m_siteStallSeconds; ///< a site away from home that has not moved forward this long is cancelled and refunded (aiWatchSite)+ Int m_siteBuildersLost; ///< ... and any site whose builders died this many times with nothing built in between+ Real m_siteRetrySeconds; ///< how long a cancelled site's spot is left alone before it is placed again+ Bool m_stageDozers; ///< an idle dozer walks to the site the base builder waits on money for};//-------------------------------------------------------------------------------------------------@@ -419,6 +425,44 @@ inline UnsignedInt aiBacklogClock( UnsignedInt since, Bool full, Int constructinreturn since == 0 ? now : since;}+/** One unfinished building the computer placed, as its base builder last saw it. */+struct AISiteWatch+{+ ObjectID m_site;+ Real m_percent; ///< construction percent when it last moved forward+ UnsignedInt m_progressFrame; ///< the frame it was first seen or last moved forward+ ObjectID m_lostBuilder; ///< the last dead builder counted, so one death counts once+ Int m_buildersLost; ///< builders that died since it last moved forward+};++enum AISiteVerdict+{+ AISITE_KEEP = 0,+ AISITE_STALLED, ///< nothing built on it for the rung's m_siteStallSeconds+ AISITE_BUILDERS_LOST ///< m_siteBuildersLost builders died on the way with nothing built between+};++/** One look at a site: progress resets the clock and the death count, a builder that is gone and not+ * yet counted adds one. stallFrames 0 never stalls (a site at home, which a busy dozer explains). */+AISiteVerdict aiWatchSite( AISiteWatch *watch, Real percent, ObjectID builder, Bool builderAlive,+ UnsignedInt now, UnsignedInt stallFrames, Int maxLost );++/** A spot a cancelled site stood on, left alone until a frame. */+struct AICooledSpot+{+ Coord3D m_pos;+ UnsignedInt m_until;+};++/** How near a cancelled site a dock counts as the one it was for, and a new site as the same spot.+ * The site's is about one building across, so a base site given up under attack does not shut the+ * base around it. */+static const Real AI_COOLED_DOCK_RADIUS = 200.0f;+static const Real AI_COOLED_SITE_RADIUS = 60.0f;++/** True while pos is within radius of a spot whose wait has not run out. */+Bool aiSpotCooling( const std::vector<AICooledSpot> &spots, const Coord3D *pos, Real radius, UnsignedInt now );+/** How many copies of the faction tech building (strategy center, propaganda center, palace) to* keep up so one of them blowing up does not take the tree with it. */static const Int AI_TECH_BUILDING_COPIES = 3;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex f4dee9c3a..dd8405236 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -382,6 +382,11 @@ protected:Int m_startFortune; ///< what the match started with over the default starting cash, 0 at the defaultUnsignedInt m_factoryBackedUpSince[ 3 ]; ///< per war factory, barracks, airfield: the frame every finished one was first seen full (busy, or an airfield's parking) with none going up, 0 for notUnsignedInt m_parkingBlockedFrame; ///< the last frame a buy of an aircraft was refused because the airfield's parking was full, 0 for never+ std::vector<AISiteWatch> m_siteWatches; ///< the unfinished buildings this AI placed, in the order first seen+ std::vector<AICooledSpot> m_cooledSpots; ///< spots of sites it gave up on, left alone for a while+ Bool watchSite(BuildListInfo *info, Object *bldg); ///< cancel and refund a site it cannot finish; TRUE when it did+ Bool spotCooling(const Coord3D *pos); ///< a site was given up near here lately+ void stageDozer(Object *dozer, const Coord3D *site); ///< an idle dozer walks ahead to a site waiting on moneyBool purchaseAllowed(Int key, Int cost, AIPurchaseKind kind, Bool startable, const AsciiString &what, Int scoreOffset = 0);void purchased(Int key, Int cost, AIPurchaseKind kind, const AsciiString &what);Bool buyUnit(ProductionUpdateInterface *pu, const ThingTemplate *unit, AIPurchaseKind kind); ///< queueCreateUnit through the queuediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex b7b98756a..d5bd30804 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1324,12 +1324,19 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* and a bank rule, and a gate that waited for a unit queued behind the one being built, which the* scripts never queue: the computer stood one barracks, one war factory and one airfield all match.*- * 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 and stage, 2026-10-21: a building placed out at a dock in enemy ground stood+ * unbuilt all match, its money spent, every dozer sent to it killed on the way, and its spot taken from+ * every later expansion. A site away from home that has not moved forward for stall seconds, or any+ * site whose builders died lost times with nothing built in between, is cancelled for its money back,+ * and its spot (and the dock it was for) left alone for retry seconds. stage sends an idle dozer+ * ahead to the site the base builder is waiting on money for. Easy gives up latest and does not stage.+ *+ * 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 */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 },- /* 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 },- /* 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 }+ /* 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 },+ /* 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 },+ /* 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 }};//-------------------------------------------------------------------------------------------------@@ -1467,6 +1474,43 @@ Bool aiWantsAnotherFactory( Int finished, Int constructing, Bool full, UnsignedIreturn backedUpFor >= backlogFrames;}+//-------------------------------------------------------------------------------------------------+AISiteVerdict aiWatchSite( AISiteWatch *watch, Real percent, ObjectID builder, Bool builderAlive,+ UnsignedInt now, UnsignedInt stallFrames, Int maxLost )+{+ if( percent > watch->m_percent )+ {+ watch->m_percent = percent;+ watch->m_progressFrame = now;+ watch->m_buildersLost = 0;+ }+ if( !builderAlive && builder != INVALID_ID && builder != watch->m_lostBuilder )+ {+ watch->m_lostBuilder = builder;+ ++watch->m_buildersLost;+ }+ if( maxLost > 0 && watch->m_buildersLost >= maxLost )+ return AISITE_BUILDERS_LOST;+ if( stallFrames > 0 && now - watch->m_progressFrame >= stallFrames )+ return AISITE_STALLED;+ return AISITE_KEEP;+}++//-------------------------------------------------------------------------------------------------+Bool aiSpotCooling( const std::vector<AICooledSpot> &spots, const Coord3D *pos, Real radius, UnsignedInt now )+{+ for( size_t i = 0; i < spots.size(); ++i )+ {+ if( spots[ i ].m_until <= now )+ continue;+ const Real dx = spots[ i ].m_pos.x - pos->x;+ const Real dy = spots[ i ].m_pos.y - pos->y;+ if( dx * dx + dy * dy <= radius * radius )+ return TRUE;+ }+ return FALSE;+}+//-------------------------------------------------------------------------------------------------Bool aiWantsAnotherTechBuilding( Int standing, Int onTheWay ){@@ -2227,6 +2271,10 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "StrikeEconomyWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeEconomyWeight ) },{ "StrikeThreatWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_strikeThreatWeight ) },{ "SuperweaponDefenses", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_superweaponDefenses ) },+ { "SiteStallSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siteStallSeconds ) },+ { "SiteBuildersLost", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_siteBuildersLost ) },+ { "SiteRetrySeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siteRetrySeconds ) },+ { "StageDozers", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_stageDozers ) },{ NULL, NULL, NULL, 0 }};diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex b5b8d9871..0ecea23d7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -1236,10 +1236,138 @@ static void giveUpOnSpot( BuildListInfo *info )info->setObjectTimestamp( TheGameLogic->getFrame() + 1 );}+// ------------------------------------------------------------------------------------------------+/** A site this AI placed and cannot finish is cancelled for its money back, the way a player cancels+ * one, and its spot left alone for the rung's m_siteRetrySeconds. A supply centre put down at a far+ * dock in enemy ground stood unbuilt all match: every dozer sent to it was killed on the way, the+ * money was gone, and the scaffold kept the dock (and every gun the scripts asked for beside it)+ * from going anywhere else. A priority entry is blanked, as giveUpOnSpot does, for whoever asked to+ * ask again; a map plan entry waits out the retry and gets its rebuild back. */+// ------------------------------------------------------------------------------------------------+Bool AIPlayer::watchSite( BuildListInfo *info, Object *bldg )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ AISiteWatch *watch = NULL;+ for( size_t i = 0; i < m_siteWatches.size(); )+ {+ const Object *site = TheGameLogic->findObjectByID( m_siteWatches[ i ].m_site );+ if( site == NULL || !site->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) )+ {+ m_siteWatches.erase( m_siteWatches.begin() + i ); // finished, or gone+ continue;+ }+ if( site == bldg )+ watch = &m_siteWatches[ i ];+ ++i;+ }+ if( watch == NULL )+ {+ AISiteWatch fresh;+ fresh.m_site = bldg->getID();+ fresh.m_percent = bldg->getConstructionPercent();+ fresh.m_progressFrame = now;+ fresh.m_lostBuilder = INVALID_ID;+ fresh.m_buildersLost = 0;+ m_siteWatches.push_back( fresh );+ watch = &m_siteWatches.back();+ }++ const AIDifficultyProfile *profile = getSkillProfile();+ const ObjectID builderID = bldg->getBuilderID();+ const Object *builder = TheGameLogic->findObjectByID( builderID );+ // at home a site that does not move is waiting for a busy dozer, not for one that cannot get there+ const UnsignedInt stallFrames = isAtHome( bldg->getPosition() ) ? 0 :+ (UnsignedInt)REAL_TO_INT( profile->m_siteStallSeconds * LOGICFRAMES_PER_SECOND );+ const AISiteVerdict verdict = aiWatchSite( watch, bldg->getConstructionPercent(), builderID,+ builder != NULL && !builder->isEffectivelyDead(), now, stallFrames, profile->m_siteBuildersLost );+ if( verdict == AISITE_KEEP )+ return FALSE;++ const UnsignedInt retryFrames = (UnsignedInt)REAL_TO_INT( profile->m_siteRetrySeconds * LOGICFRAMES_PER_SECOND );+ const Int refund = bldg->testStatus( OBJECT_STATUS_RECONSTRUCTING ) ? 0 : bldg->getTemplate()->calcCostToBuild( m_player );+ m_player->getMoney()->deposit( refund, FALSE );+ DEBUG_LOG(("AI SITE frame %d player %d gives up '%s' at (%.0f,%.0f), %s, %.0f%% built, %d refunded, spot free at frame %d\n",+ now, m_player->getPlayerIndex(), bldg->getTemplate()->getName().str(), bldg->getPosition()->x, bldg->getPosition()->y,+ verdict == AISITE_STALLED ? "no progress" : "builders lost", bldg->getConstructionPercent(), refund, now + retryFrames));++ for( size_t i = 0; i < m_cooledSpots.size(); )+ {+ if( m_cooledSpots[ i ].m_until <= now )+ m_cooledSpots.erase( m_cooledSpots.begin() + i );+ else+ ++i;+ }+ AICooledSpot spot;+ spot.m_pos = *bldg->getPosition();+ spot.m_until = now + retryFrames;+ m_cooledSpots.push_back( spot );++ // the dock it was for stops being the one the scripts' guns and factories go beside+ const Object *warehouse = TheGameLogic->findObjectByID( m_curWarehouseID );+ if( warehouse && aiSpotCooling( m_cooledSpots, warehouse->getPosition(), AI_COOLED_DOCK_RADIUS, now ) )+ m_curWarehouseID = INVALID_ID;++ info->setObjectID( INVALID_ID );+ info->setUnderConstruction( false );+ if( info->isPriorityBuild() )+ {+ info->setTemplateName( AsciiString::TheEmptyString );+ }+ else+ {+ info->incrementNumRebuilds();+ info->setObjectTimestamp( now + retryFrames );+ }+ bldg->kill(); // its dozer drops the job, as when a player cancels+ return TRUE;+}++// ------------------------------------------------------------------------------------------------+Bool AIPlayer::spotCooling( const Coord3D *pos )+{+ return aiSpotCooling( m_cooledSpots, pos, AI_COOLED_SITE_RADIUS, TheGameLogic->getFrame() );+}++// ------------------------------------------------------------------------------------------------+/** The base builder has its next site and is waiting for the money. An idle dozer walks there now+ * rather than from wherever it stopped once the money comes, so the building starts on arrival.+ * Only one standing idle: never one on a job, the repair dozer, or a worker hauling supplies. */+// ------------------------------------------------------------------------------------------------+void AIPlayer::stageDozer( Object *dozer, const Coord3D *site )+{+ if( !isSkirmishAI() || !getSkillProfile()->m_stageDozers || dozer->getID() == m_repairDozer )+ return;+ AIUpdateInterface *ai = dozer->getAI();+ if( ai->getDozerAIInterface()->isAnyTaskPending() || !ai->isIdle() )+ return;+ SupplyTruckAIInterface *supplyTruckAI = ai->getSupplyTruckAIInterface();+ if( supplyTruckAI && (supplyTruckAI->isCurrentlyFerryingSupplies() || supplyTruckAI->isForcedIntoWantingState()) )+ return;+ const Real STANDOFF = 4 * PATHFIND_CELL_SIZE_F; // beside the footprint, not on it+ const Real dx = dozer->getPosition()->x - site->x;+ const Real dy = dozer->getPosition()->y - site->y;+ const Real distSqr = dx*dx + dy*dy;+ if( distSqr <= sqr( 3 * STANDOFF ) || !reachableFromBase( site ) )+ return;+ const Real dist = sqrt( distSqr );+ Coord3D to = *site;+ to.x += dx / dist * STANDOFF;+ to.y += dy / dist * STANDOFF;+ to.z = TheTerrainLogic->getGroundHeight( to.x, to.y );+ ai->aiMoveToPosition( &to, CMD_FROM_AI );+ DEBUG_LOG(("AI STAGE frame %d player %d dozer %d walks %.0f ahead to (%.0f,%.0f)\n",+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), dozer->getID(), dist, site->x, site->y));+}+// ------------------------------------------------------------------------------------------------// ------------------------------------------------------------------------------------------------Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildListInfo *info){+ // A site given up here lately is left alone until its wait runs out.+ if (isSkirmishAI() && spotCooling(info->getLocation())) {+ giveUpOnSpot(info);+ return NULL;+ }// Find a dozer.Object *dozer = findDozer(info->getLocation());if (dozer==NULL && isSkirmishAI() && getSkillProfile()->m_economyBuildings && isPowerThin() &&@@ -1256,10 +1384,9 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi// Check available funds, and with a Hard AI whether the money is saved for something better.Money *money = m_player->getMoney();const Int cost = bldgPlan->calcCostToBuild(m_player);- if (!purchaseAllowed(bldgPlan->getTemplateID(), cost, purchaseKindOf(bldgPlan), TRUE, bldgPlan->getName(), personaBuildingScore(bldgPlan))) {- return NULL;- }- if ((Int)money->countMoney()<cost) {+ if (!purchaseAllowed(bldgPlan->getTemplateID(), cost, purchaseKindOf(bldgPlan), TRUE, bldgPlan->getName(), personaBuildingScore(bldgPlan)) ||+ (Int)money->countMoney()<cost) {+ stageDozer(dozer, info->getLocation()); // the site is known, only the money is not there yetreturn NULL;}@@ -4195,6 +4322,10 @@ Object *AIPlayer::findSupplyCenter(Int minimumCash, Bool holdableOnly)if (otherSideStructureNear(m_player, obj)) {continue;}+ // a site given up at this dock lately (watchSite): not straight back into the same trap+ if (aiSpotCooling(m_cooledSpots, obj->getPosition(), AI_COOLED_DOCK_RADIUS, TheGameLogic->getFrame())) {+ continue;+ }Real dx, dy;dx = obj->getPosition()->x - m_baseCenter.x;@@ -16567,7 +16698,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 28; // 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+ XferVersion currentVersion = 29; // 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 spotsXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -17023,6 +17154,30 @@ void AIPlayer::xfer( Xfer *xfer )if( version >= 28 )xfer->xferUnsignedInt( &m_parkingBlockedFrame );+ // the unfinished sites it is watching, and the spots of the ones it gave up on+ if( version >= 29 )+ {+ UnsignedShort count = (UnsignedShort)m_siteWatches.size();+ xfer->xferUnsignedShort( &count );+ m_siteWatches.resize( count );+ for( UnsignedShort i = 0; i < count; ++i )+ {+ xfer->xferObjectID( &m_siteWatches[ i ].m_site );+ xfer->xferReal( &m_siteWatches[ i ].m_percent );+ xfer->xferUnsignedInt( &m_siteWatches[ i ].m_progressFrame );+ xfer->xferObjectID( &m_siteWatches[ i ].m_lostBuilder );+ xfer->xferInt( &m_siteWatches[ i ].m_buildersLost );+ }+ count = (UnsignedShort)m_cooledSpots.size();+ xfer->xferUnsignedShort( &count );+ m_cooledSpots.resize( count );+ for( UnsignedShort i = 0; i < count; ++i )+ {+ xfer->xferCoord3D( &m_cooledSpots[ i ].m_pos );+ xfer->xferUnsignedInt( &m_cooledSpots[ i ].m_until );+ }+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cppindex 679587b07..deb33e5e8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp@@ -190,9 +190,13 @@ void AISkirmishPlayer::processBaseBuilding( void )} else {if (bldg->getControllingPlayer() == m_player) {// Check for built or dozer missing.- if( bldg->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )+ if( bldg->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) ){- if (bldg->isKindOf(KINDOF_FS_POWER) && !bldg->isKindOf(KINDOF_CASH_GENERATOR))+ // a site its dozers cannot reach, or die on the way to, is cancelled for the money+ if (watchSite(info, bldg)) {+ continue;+ }+ if (bldg->isKindOf(KINDOF_FS_POWER) && !bldg->isKindOf(KINDOF_CASH_GENERATOR)){powerUnderConstruction = true;}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 39b9deb31..033816a4c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12712,6 +12712,70 @@ TEST(extra_airfield_follows_the_parking)CHECK( aiWantsAnotherFactory( 3, 0, aiAirfieldsFull( 3, 3, TRUE ), BACKLOG, BACKLOG ) ); // no cap}+/** A site that cannot be finished is given up: builders dying on the way with nothing built between,+ or a site away from home standing still for the rung's stall. Its spot then waits out the retry. */+TEST(stuck_building_site_is_given_up)+{+ TAiData data;+ for( Int s = 0; s < AISKILL_COUNT; ++s )+ {+ CHECK( data.m_skill[ s ].m_siteStallSeconds > 0.0f );+ CHECK( data.m_skill[ s ].m_siteBuildersLost > 0 );+ CHECK( data.m_skill[ s ].m_siteRetrySeconds > 0.0f );+ if( s > 0 ) // a higher rung gives up no later+ {+ CHECK( data.m_skill[ s ].m_siteStallSeconds <= data.m_skill[ s - 1 ].m_siteStallSeconds );+ CHECK( data.m_skill[ s ].m_siteBuildersLost <= data.m_skill[ s - 1 ].m_siteBuildersLost );+ }+ }+ const AIDifficultyProfile &hard = data.m_skill[ AISKILL_BRUTAL ];+ const UnsignedInt STALL = (UnsignedInt)REAL_TO_INT( hard.m_siteStallSeconds * LOGICFRAMES_PER_SECOND );+ const Int LOST = hard.m_siteBuildersLost;+ const ObjectID A = (ObjectID)10, B = (ObjectID)11, C = (ObjectID)12;++ AISiteWatch w = { (ObjectID)1, 0.0f, 100, INVALID_ID, 0 };+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 0.0f, A, TRUE, 100 + STALL - 1, STALL, LOST ) );+ CHECK_EQ( (Int)AISITE_STALLED, (Int)aiWatchSite( &w, 0.0f, A, TRUE, 100 + STALL, STALL, LOST ) );+ // at home the stall is off: a busy dozer, not a trap+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 0.0f, A, TRUE, 100 + 10 * STALL, 0, LOST ) );++ // progress resets the clock+ w = AISiteWatch{ (ObjectID)1, 0.0f, 100, INVALID_ID, 0 };+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 5.0f, A, TRUE, 100 + STALL, STALL, LOST ) );+ CHECK_EQ( 100 + STALL, w.m_progressFrame );++ // one death counts once, however many passes see it+ w = AISiteWatch{ (ObjectID)1, 0.0f, 100, INVALID_ID, 0 };+ for( Int pass = 0; pass < 5; ++pass )+ aiWatchSite( &w, 0.0f, A, FALSE, 101 + pass, STALL, LOST );+ CHECK_EQ( 1, w.m_buildersLost );+ // a second builder lost with nothing built gives it up+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 0.0f, B, TRUE, 200, STALL, LOST ) );+ CHECK_EQ( (Int)AISITE_BUILDERS_LOST, (Int)aiWatchSite( &w, 0.0f, B, FALSE, 210, STALL, 2 ) );++ // a builder that got some of it up before dying is not a trap: the count starts over+ w = AISiteWatch{ (ObjectID)1, 0.0f, 100, INVALID_ID, 0 };+ aiWatchSite( &w, 0.0f, A, FALSE, 110, STALL, 2 );+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 30.0f, B, TRUE, 120, STALL, 2 ) );+ CHECK_EQ( 0, w.m_buildersLost );+ CHECK_EQ( (Int)AISITE_KEEP, (Int)aiWatchSite( &w, 30.0f, B, FALSE, 130, STALL, 2 ) );+ CHECK_EQ( (Int)AISITE_BUILDERS_LOST, (Int)aiWatchSite( &w, 30.0f, C, FALSE, 140, STALL, 2 ) );++ // the spot: cooling until its frame, only near it+ std::vector<AICooledSpot> spots;+ AICooledSpot spot;+ spot.m_pos.set( 1000.0f, 1000.0f, 0.0f );+ spot.m_until = 500;+ spots.push_back( spot );+ Coord3D inside, outside; // near and far are macros on Windows+ inside.set( 1000.0f + AI_COOLED_SITE_RADIUS - 1.0f, 1000.0f, 0.0f );+ outside.set( 1000.0f + AI_COOLED_DOCK_RADIUS + 1.0f, 1000.0f, 0.0f );+ CHECK( aiSpotCooling( spots, &inside, AI_COOLED_SITE_RADIUS, 499 ) );+ CHECK( !aiSpotCooling( spots, &inside, AI_COOLED_SITE_RADIUS, 500 ) );+ CHECK( !aiSpotCooling( spots, &outside, AI_COOLED_DOCK_RADIUS, 0 ) );+ CHECK( aiSpotCooling( spots, &outside, AI_COOLED_DOCK_RADIUS + 2.0f, 0 ) );+}+TEST(another_tech_building_until_three_stand){CHECK( aiWantsAnotherTechBuilding( 0, 0 ) );