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): open the factory gate on a share of busy passes
Olcay Seygana5d7b05f9512
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a0054554c..cec2accc1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -365,7 +365,7 @@ found and fixed — EA's own, not port damage.**- It no longer sits on a pile of cash. Past a level that depends on the difficulty, the more money it has the faster it builds - twice the pile, half the wait, and it stops at four times. It is spending sooner, not building faster: the rate itself is untouched.- A full bank buys a bigger army. Late in a match the computer's plan allows one of each attack group, so once they were all on the map it only replaced its losses and banked the rest: a Hard USA sat on 117,000 on Twilight Flame. Now every 8,000 in the bank on Hard allows one more copy of each attack group, up to four of them.- Hard builds past its plan. A war factory, barracks or airfield gets another copy only once every one of its kind has kept units waiting in its queue for 45 seconds, and a factory that was destroyed is put back. The second barracks used to be an opening buy. The Infantry General's plan holds four, and its scripts asked for the second 38 seconds in, before the first had trained anyone, then sat on an empty bank waiting for the third. Now a second factory waits for the queue on every difficulty, the plan's own copies included, and in a Hard Infantry General match on Twilight Flame the second barracks went up at eleven and a half minutes. Supply drop zones and black markets go up one after another as soon as the bank is past a small cushion, whatever else it is buying; they used to wait until production had nothing to ask for, which on a busy map was never, and over twelve four-player matches the count went from 5 to 95. Internet centers follow that same rule. The spot search used to give up two rings outside the opening base, so a full base simply stopped. It now keeps looking further out until the map ends, for factories and power plants; the income buildings stay at home. Strategy centers, propaganda centers and palaces stop at three, so one of them blowing up leaves the tech tree standing. Extra factories still go beside the newest expansion it holds, nearer the fighting. China trains a hacker from every barracks that has room in its queue, not one barracks at a time: 120 hackers across those matches became 375. A hacker left standing still is put to work. It stops at six, an internet center's four plus a couple, because nothing counted them before: a Hard Tank General trained 67 over twenty thousand frames, about two thirds of everything it spent, and every one of them went through the barracks queue its army was waiting in. A player watching it from the other side of the map said China's tank general builds nothing but infantry, and he was right. Seven now, and the teams at the top of its build list are tanks. The limit grows with the match: one hacker for every four fighting units, never more than its Internet Centers have seats for plus four working outside, and never fewer than four. A computer that has not built an army does not buy an economy instead, and one with a full Internet Center and ninety units behind it keeps eight. Replays recorded before this change play out differently.-- The computer builds more than one barracks, war factory and airfield again, on every difficulty. Since 3.2.0 it stood one of each all match, even where its own plan had two war factories or four barracks: another one waited for units to queue up behind the one being built, and the computer never queues them that way. Now a barracks or war factory gets another once every one it has has been busy without a break for 90 seconds on Easy, 75 on Medium and 45 on Hard, and a new one has to stay busy for that long too before the next. An airfield goes by its parking instead, since a full one takes nothing into its queue: when every airfield has its places taken and a plane is waiting for one for that same time, another goes up, and a plane lost on the way starts the wait again. There is no limit on how many: an army that keeps all its factories busy gets more of them. The old cap of three, five and eight production buildings and the bank rule that added them are gone. Replays recorded before this change play out differently.+- The computer builds more than one barracks, war factory and airfield again, on every difficulty. Since 3.2.0 it stood one of each all match, even where its own plan had two war factories or four barracks: another one waited for units to queue up behind the one being built, and the computer never queues them that way. Every ten seconds it looks at each kind, and once every one it has was busy on four looks in five over the last 90 seconds on Easy, 75 on Medium and 45 on Hard, another goes up; a new one has to fill a whole stretch like that before the next. A factory caught between two units no longer starts the wait again, which is why Easy, whose units come out inside ten seconds, never got a second one. An airfield goes by its parking instead, since a full one takes nothing into its queue: it counts as busy while every airfield has its places taken and a plane is waiting for one. There is no limit on how many: an army that keeps all its factories busy gets more of them. The old cap of three, five and eight production buildings and the bank rule that added them are gone. Replays recorded before this change play out differently.- Hard saves up for what it needs most. It used to buy whatever the bank covered the moment it covered it, so the drop zone it needed waited while tank after tank rolled off the line. Every purchase is ranked now: income and power come first for the opening six minutes, the army after that, and when the top one cannot be paid for yet its price is set aside and anything that ranks lower waits until the bank holds more than that price. The saving never turns into a hoard. It lapses after forty seconds, and once the bank is past Hard's cash cushion nothing waits at all. The first drop zone and the first black market also go up in those opening minutes without waiting for the cushion. Over twenty matches with Hard computers on Winter Wolf, 27 computer players had a drop zone or black market standing where 19 had, the first one came at five and a half minutes instead of seven and a half, and 104 of them went up against 46. Replays recorded before this change play out differently.- The computer researches upgrades on its own, and spends its bank. Upgrades used to come only from a fixed list in its plan, written before anyone knew what it would build. It now looks at the army it actually has and buys the upgrade that army gets the most out of for the price, and an army that beats what it has seen of yours counts for more. Buildings count for little there, so a GLA no longer opens with Fortified Structure. It also keeps a bank of so many seconds of its income and spends anything past that: an upgrade it would otherwise have waited on, extra units from idle factories, and on Hard another war factory or barracks whenever half a minute goes by without the bank coming down. Hard holds half a minute of income, spends what is over it on extra units at up to three times the rate it earns, builds up to eight factories, one every half minute whenever its bank passes twice what it means to keep, and starts upgrading at three minutes. Medium holds a minute, tops its army up at a tenth of Hard's rate, keeps to the factories its plan lays out and starts upgrading at seven. Easy holds two minutes, tops up at a twentieth of Hard's rate, keeps to its plan's factories too and waits twelve minutes and for a much bigger army before it buys an upgrade. Saving up for the most important purchase, which only Hard did, now runs on every difficulty, each below its own bank. Over six matches of Hard against Medium, on a build one small fix short of this one (Medium and Easy now count the factories their plan has yet to build), Hard ended on 1,600 in the bank on average where it had ended on about 12,000, and won all three that finished. Replays recorded before this change play out differently.- Hard picks its road into your base. Of the three approaches it takes the one with the fewest guns it has seen along it, and keeps to the one its plan named until it has scouted something. Aiming at your money instead was tried first and walked it straight past your army.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 25fbbad85..2c9b52798 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -256,7 +256,7 @@ struct AIDifficultyProfileReal m_upgradeStartSeconds; ///< and not before this far into the matchReal m_upgradeNonCombatWeight; ///< what a building or an unarmed unit counts for next to a fighting unit when an upgrade is weighedReal m_surplusShare; ///< of the income over aiSurplusBudget's window, how much a bank over target may train as extra units- Real m_factoryBacklogSeconds; ///< how long every finished factory of a kind has to stay busy before another of that kind goes up (aiWantsAnotherFactory)+ Real m_factoryBacklogSeconds; ///< the window over which every finished factory of a kind has to be full on AI_FACTORY_FULL_PERCENT of the spend passes before another of that kind goes up (aiWantsAnotherFactory)// Pushing: when the army first leaves home, and how small a force may goReal m_firstPushSeconds; ///< no attack before this, nor before the first drop zone or black market stands (AI_PURCHASE_EARLY_FRAMES at most)@@ -393,13 +393,44 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractioBool timeExpired, Bool baseUnderAttack );/** Another factory of this kind. finished are standing and done, constructing are already on the- * way, full says every finished one is full now (aiQueueKindFull, aiAirfieldsFull), and backedUpFor- * is how many frames they have all been full (aiBacklogClock).+ * way, history holds one bit a spend pass, newest lowest, set when every finished one was full on it+ * (aiQueueKindFull, aiAirfieldsFull; aiSampleFactories), count is how many passes it holds, and+ * window is the rung's m_factoryBacklogSeconds in passes (aiBacklogSamples).*- * Another goes up only when every finished factory has been full for backlogFrames (the rung's- * m_factoryBacklogSeconds), and a replacement when none are left. One already on the way is the- * building this would ask for. */-Bool aiWantsAnotherFactory( Int finished, Int constructing, Bool full, UnsignedInt backedUpFor, UnsignedInt backlogFrames );+ * Another goes up once the last window passes are all in and at least AI_FACTORY_FULL_PERCENT of+ * them were full, and a replacement when none are left. One already on the way is the building+ * this would ask for. A share, not an unbroken run: a pass that found a factory between two units+ * reset the clock, and an Easy computer whose units finish inside a pass never got a second one. */+Bool aiWantsAnotherFactory( Int finished, Int constructing, UnsignedInt history, Int count, Int window );++/** The share of a window's passes, in percent, that have to find the kind full. */+static const Int AI_FACTORY_FULL_PERCENT = 80;++/** The most passes a window holds: the bits in the history. */+static const Int AI_FACTORY_HISTORY_PASSES = 32;++/** The rung's backlog in spend passes of passFrames each, rounded up, 1 to AI_FACTORY_HISTORY_PASSES. */+inline Int aiBacklogSamples( Real seconds, Int passFrames )+{+ const Int frames = REAL_TO_INT( seconds * LOGICFRAMES_PER_SECOND );+ const Int passes = ( frames + passFrames - 1 ) / passFrames;+ return passes < 1 ? 1 : passes > AI_FACTORY_HISTORY_PASSES ? AI_FACTORY_HISTORY_PASSES : passes;+}++/** One spend pass of a kind's history: shifts in whether it was full. One of the kind going up+ * empties it, so the window starts again once that one stands and has to prove itself full too. */+inline void aiSampleFactories( UnsignedInt *history, Int *count, Bool full, Int constructing )+{+ if( constructing > 0 )+ {+ *history = 0;+ *count = 0;+ return;+ }+ *history = ( *history << 1 ) | ( full ? 1u : 0u );+ if( *count < AI_FACTORY_HISTORY_PASSES )+ ++*count;+}/** A barracks or war factory is full while it is busy: shallowest is the shortest queue among the* finished ones. Busy, not backed up: the scripts train only into an idle factory and the surplus@@ -415,16 +446,6 @@ inline Bool aiAirfieldsFull( Int finished, Int parkingFull, Bool wanted ) { retu/** How long a buy refused for parking keeps the computer wanting another airfield. */static const UnsignedInt AI_PARKING_WANT_FRAMES = 15 * LOGICFRAMES_PER_SECOND;-/** The backlog clock of one kind, read on every spend pass: the frame it has been full since, 0 for- * not. A pass that finds it not full, or one of the kind going up, starts it again, so a slot that- * frees up and a new factory that has yet to prove itself busy both reset it. */-inline UnsignedInt aiBacklogClock( UnsignedInt since, Bool full, Int constructing, UnsignedInt now )-{- if( !full || constructing > 0 )- return 0;- return since == 0 ? now : since;-}-/** One unfinished building the computer placed, as its base builder last saw it. */struct AISiteWatch{diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex dd8405236..0a80e0263 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -380,7 +380,8 @@ protected:Int m_bankMark; ///< ... and the bank thenReal m_incomePerSecond; ///< smoothed over the windows measured so farInt m_startFortune; ///< what the match started with over the default starting cash, 0 at the default- UnsignedInt 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 not+ UnsignedInt m_factoryFullHistory[ 3 ]; ///< per war factory, barracks, airfield: a bit a spend pass, newest lowest, set when every finished one was full (busy, or an airfield's parking) (aiSampleFactories)+ Int m_factoryFullCount[ 3 ]; ///< ... and how many passes that holds since one of the kind last went upUnsignedInt m_parkingBlockedFrame; ///< the last frame a buy of an aircraft was refused because the airfield's parking was full, 0 for neverstd::vector<AISiteWatch> m_siteWatches; ///< the unfinished buildings this AI placed, in the order first seenstd::vector<AICooledSpot> m_cooledSpots; ///< spots of sites it gave up on, left alone for a whilediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex d5bd30804..b528ed428 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1318,9 +1318,9 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* Easy from 17 of 30 to 27 of 29. Easy's 3 is unmeasured in play: its script clock still holds its* first superweapon past 25 minutes, so none was built either way.*- * backlog, 2026-10-21: the seconds every factory of a kind has to stay full (a barracks or war- * factory busy, an airfield's parking taken while an aircraft waits for a place) before another of- * that kind goes up, with no cap on how many stand. It replaced a cap on production buildings (3, 5, 8)+ * backlog, 2026-10-21: the window over which every factory of a kind has to be full (a barracks or+ * war factory busy, an airfield's parking taken while an aircraft waits for a place) on 80% of the+ * ten-second spend passes before another of that kind goes up, with no cap on how many stand. It replaced a cap on production buildings (3, 5, 8)* 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.*@@ -1463,15 +1463,19 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractio}//--------------------------------------------------------------------------------------------------Bool aiWantsAnotherFactory( Int finished, Int constructing, Bool full, UnsignedInt backedUpFor, UnsignedInt backlogFrames )+Bool aiWantsAnotherFactory( Int finished, Int constructing, UnsignedInt history, Int count, Int window ){if( constructing > 0 )return FALSE; // one is already going upif( finished <= 0 )return TRUE; // the last one is gone, so put one back- if( !full )- return FALSE; // one of them has room: that one is the spare- return backedUpFor >= backlogFrames;+ if( count < window )+ return FALSE; // the window is not in yet+ Int full = 0;+ for( Int i = 0; i < window; ++i )+ if( history & ( 1u << i ) )+ ++full;+ return full * 100 >= window * AI_FACTORY_FULL_PERCENT;}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 0ecea23d7..32e573350 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -397,7 +397,10 @@ m_role(AIROLE_AGGRESSIVE)m_incomePerSecond = 0.0f;m_startFortune = 0;for( Int k = 0; k < 3; ++k )- m_factoryBackedUpSince[ k ] = 0;+ {+ m_factoryFullHistory[ k ] = 0;+ m_factoryFullCount[ k ] = 0;+ }m_parkingBlockedFrame = 0;m_persona = AIPERSONA_NORMAL;m_personaFromRandom = FALSE;@@ -7812,8 +7815,8 @@ Bool AIPlayer::queueExtraFactory( Object *dozer, KindOfType kind )}//-----------------------------------------------------------------------------------------------------------/** Another factory of a kind waits until every finished one has stayed busy for the rung's- * m_factoryBacklogSeconds (aiWantsAnotherFactory; doSpending keeps that clock), and while one is+/** Another factory of a kind waits until every finished one has been full on most of the spend passes+ * of the rung's m_factoryBacklogSeconds (aiWantsAnotherFactory; doSpending samples it), and while one is* going up. The build list's own copies wait the same way: the Infantry General's plan holds four* barracks, and its scripts asked for the second 38 seconds in, before the first had trained anyone,* and the bank went to nothing waiting on the third. */@@ -7829,10 +7832,8 @@ Bool AIPlayer::holdsExtraFactory( const ThingTemplate *tmpl )// AI's plan airfield waited here from 3.3 minutes to 15if( favouredFactoryScore( tmpl ) > 0 )return load.constructing > 0 || load.finished >= PERSONA_FAVOURED_FACTORIES[ m_skillLevel ];- const UnsignedInt since = m_factoryBackedUpSince[ k ];- return !aiWantsAnotherFactory( load.finished, load.constructing, factoryKindFull( load, m_parkingBlockedFrame ),- since == 0 ? 0 : TheGameLogic->getFrame() - since,- (UnsignedInt)REAL_TO_INT( getSkillProfile()->m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND ) );+ return !aiWantsAnotherFactory( load.finished, load.constructing, m_factoryFullHistory[ k ], m_factoryFullCount[ k ],+ aiBacklogSamples( getSkillProfile()->m_factoryBacklogSeconds, ECONOMY_CHECK_RATE ) );}return FALSE;}@@ -8798,14 +8799,14 @@ void AIPlayer::doSpending( void )if( (now + computeUpdatePhase( m_player->getPlayerIndex(), ECONOMY_CHECK_RATE ) + ECONOMY_CHECK_RATE - ECONOMY_SLOT_STEP) % ECONOMY_CHECK_RATE != 0 )return;- // since when every finished factory of each kind has been full, read on every pass so a factory that- // went idle or a parking place that freed up in between starts the clock again, and one going up- // starts it again once it stands, so the new one has to prove itself full too (queueExtraFactory)+ // whether every finished factory of each kind is full on this pass, into a rolling window the gate+ // reads as a share (queueExtraFactory); one going up empties it, so the new one has to prove itself+ // full toofor( Int k = 0; k < PRODUCTION_KINDS; ++k ){const FactoryLoad load = readFactoryLoad( m_player, PRODUCTION_KIND[ k ] );- m_factoryBackedUpSince[ k ] = aiBacklogClock( m_factoryBackedUpSince[ k ],- factoryKindFull( load, m_parkingBlockedFrame ), load.constructing, now );+ aiSampleFactories( &m_factoryFullHistory[ k ], &m_factoryFullCount[ k ],+ factoryKindFull( load, m_parkingBlockedFrame ), load.constructing );}// the income, off what the score screen counts as earned: gathered, hacked, captured and given@@ -16698,7 +16699,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- 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 spots+ XferVersion currentVersion = 30; // 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 passesXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -17103,8 +17104,18 @@ void AIPlayer::xfer( Xfer *xfer )xfer->xferInt( &m_ambulancesBought );if( version >= 24 )xfer->xferInt( &m_startFortune );- if( version >= 25 )- xfer->xferUser( m_factoryBackedUpSince, sizeof( m_factoryBackedUpSince ) );+ // the factory backlog: from 30 the rolling window of full passes, before it a clock of frames that+ // means nothing to the window, read and dropped so the window starts empty+ if( version >= 30 )+ {+ xfer->xferUser( m_factoryFullHistory, sizeof( m_factoryFullHistory ) );+ xfer->xferUser( m_factoryFullCount, sizeof( m_factoryFullCount ) );+ }+ else if( version >= 25 )+ {+ UnsignedInt oldClocks[ 3 ];+ xfer->xferUser( oldClocks, sizeof( oldClocks ) );+ }// the ladder rung and the role, which are rolled once and must come back the same wayif( version >= 3 )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 033816a4c..2916b9b13 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12633,53 +12633,80 @@ TEST(extra_factory_follows_the_queue)if( s > 0 )CHECK( data.m_skill[ s ].m_factoryBacklogSeconds < data.m_skill[ s - 1 ].m_factoryBacklogSeconds );}- const UnsignedInt BACKLOG = (UnsignedInt)REAL_TO_INT( data.m_skill[ AISKILL_BRUTAL ].m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND );+ const Int PASS = 10 * LOGICFRAMES_PER_SECOND; // the spend pass that samples it+ const Int EASY = aiBacklogSamples( data.m_skill[ AISKILL_EASY ].m_factoryBacklogSeconds, PASS );+ const Int HARD = aiBacklogSamples( data.m_skill[ AISKILL_BRUTAL ].m_factoryBacklogSeconds, PASS );+ CHECK_EQ( 9, EASY ); // 90 s+ CHECK_EQ( 8, aiBacklogSamples( data.m_skill[ AISKILL_MEDIUM ].m_factoryBacklogSeconds, PASS ) ); // 75 s, rounded up+ CHECK_EQ( 5, HARD ); // 45 s, rounded up+ CHECK_EQ( 1, aiBacklogSamples( 0.0f, PASS ) );+ CHECK_EQ( AI_FACTORY_HISTORY_PASSES, aiBacklogSamples( 3600.0f, PASS ) );// nothing left standing: put one back- CHECK( aiWantsAnotherFactory( 0, 0, FALSE, 0, BACKLOG ) );+ CHECK( aiWantsAnotherFactory( 0, 0, 0, 0, HARD ) );// one already going up is the building this would ask for- CHECK( !aiWantsAnotherFactory( 0, 1, FALSE, 0, BACKLOG ) );- CHECK( !aiWantsAnotherFactory( 2, 1, TRUE, BACKLOG, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 0, 1, 0, 0, HARD ) );+ CHECK( !aiWantsAnotherFactory( 2, 1, 0x1F, HARD, HARD ) );// a barracks or war factory with an empty queue is the spare; busy, only the unit it builds in the// queue, is full: the scripts never queue behind it, and a second factory never went upCHECK( !aiQueueKindFull( 2, 0 ) );CHECK( aiQueueKindFull( 2, 1 ) );CHECK( !aiQueueKindFull( 0, 3 ) );- CHECK( !aiWantsAnotherFactory( 2, 0, FALSE, BACKLOG, BACKLOG ) );- // a team landing in the queue all at once is a batch, not a factory falling behind: the- // opening's training does not buy a second barracks- CHECK( !aiWantsAnotherFactory( 1, 0, TRUE, 0, BACKLOG ) );- CHECK( !aiWantsAnotherFactory( 1, 0, TRUE, BACKLOG - 1, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 1, 0, TRUE, BACKLOG, BACKLOG ) );-- // a third once both stay busy, and past any plan's count: no cap- CHECK( aiWantsAnotherFactory( 2, 0, TRUE, BACKLOG, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 9, 0, TRUE, BACKLOG + 600, BACKLOG ) );-- // a lower rung waits longer for the same backlog- const UnsignedInt EASY = (UnsignedInt)REAL_TO_INT( data.m_skill[ AISKILL_EASY ].m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND );- CHECK( !aiWantsAnotherFactory( 2, 0, TRUE, BACKLOG, EASY ) );- CHECK( aiWantsAnotherFactory( 2, 0, TRUE, EASY, EASY ) );-- // the clock: full since the first pass that found it so, back to 0 on a pass that does not, and- // held at 0 while one of the kind goes up- CHECK_EQ( 600u, aiBacklogClock( 0, TRUE, 0, 600 ) );- CHECK_EQ( 600u, aiBacklogClock( 600, TRUE, 0, 1200 ) );- CHECK_EQ( 0u, aiBacklogClock( 600, FALSE, 0, 1200 ) );- CHECK_EQ( 0u, aiBacklogClock( 600, TRUE, 1, 1200 ) );+ // the window has to be in: four full passes are not a 45 s window, five are+ UnsignedInt history = 0;+ Int count = 0;+ for( Int i = 0; i < HARD - 1; ++i )+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK( !aiWantsAnotherFactory( 1, 0, history, count, HARD ) );+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK( aiWantsAnotherFactory( 1, 0, history, count, HARD ) );++ // an idle gap, a factory found between two units, used to start the wait again; 4 of 5 is 80% and+ // passes, and on Easy 8 of 9 passes too+ history = 0; count = 0;+ aiSampleFactories( &history, &count, TRUE, 0 );+ aiSampleFactories( &history, &count, FALSE, 0 );+ aiSampleFactories( &history, &count, TRUE, 0 );+ aiSampleFactories( &history, &count, TRUE, 0 );+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK( aiWantsAnotherFactory( 1, 0, history, count, HARD ) );+ CHECK( aiWantsAnotherFactory( 2, 0, 0x1FE, 9, EASY ) ); // 8 of 9, the newest idle+ // under 80% holds: 3 of 5, 7 of 9+ CHECK( !aiWantsAnotherFactory( 1, 0, 0x15, 5, HARD ) );+ CHECK( !aiWantsAnotherFactory( 2, 0, 0x1F6, 9, EASY ) );++ // the window rolls: old full passes drop out of it+ for( Int i = 0; i < 2; ++i )+ aiSampleFactories( &history, &count, FALSE, 0 );+ CHECK( !aiWantsAnotherFactory( 1, 0, history, count, HARD ) ); // 3 of the last 5++ // one going up empties it, and the new one has to fill a whole window again+ aiSampleFactories( &history, &count, TRUE, 1 );+ CHECK_EQ( 0u, history );+ CHECK_EQ( 0, count );+ for( Int i = 0; i < HARD - 1; ++i )+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK( !aiWantsAnotherFactory( 2, 0, history, count, HARD ) );+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK( aiWantsAnotherFactory( 2, 0, history, count, HARD ) ); // a third: no cap+ CHECK( aiWantsAnotherFactory( 9, 0, history, count, HARD ) );++ // the history keeps 32 passes and the count stops there+ for( Int i = 0; i < 40; ++i )+ aiSampleFactories( &history, &count, TRUE, 0 );+ CHECK_EQ( AI_FACTORY_HISTORY_PASSES, count );+ CHECK( aiWantsAnotherFactory( 1, 0, history, count, AI_FACTORY_HISTORY_PASSES ) );}/** An airfield goes by its parking, not its queue: every one with its parking taken while the computer- wants an aircraft, held for the rung's backlog, gives another, and a place that frees up starts the- wait again. */+ wants an aircraft, on 80% of the rung's window, gives another. */TEST(extra_airfield_follows_the_parking){TAiData data;- const UnsignedInt BACKLOG = (UnsignedInt)REAL_TO_INT( data.m_skill[ AISKILL_BRUTAL ].m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND );- const UnsignedInt STEP = 600; // one spend pass+ const Int HARD = aiBacklogSamples( data.m_skill[ AISKILL_BRUTAL ].m_factoryBacklogSeconds, 10 * LOGICFRAMES_PER_SECOND );// full takes every airfield's parking and an aircraft refused for itCHECK( aiAirfieldsFull( 2, 2, TRUE ) );@@ -12687,29 +12714,24 @@ TEST(extra_airfield_follows_the_parking)CHECK( !aiAirfieldsFull( 2, 2, FALSE ) ); // parked full, but nothing waits for a placeCHECK( !aiAirfieldsFull( 0, 0, TRUE ) );- // parking full and an aircraft waiting, held for the window: another airfield- UnsignedInt since = 0;- UnsignedInt now = 0;- while( since == 0 || now - since < BACKLOG )- {- now += STEP;- since = aiBacklogClock( since, aiAirfieldsFull( 1, 1, TRUE ), 0, now );- CHECK( since == STEP ); // the first full pass, kept while it stays full- }- CHECK( !aiWantsAnotherFactory( 1, 0, TRUE, now - STEP - since, BACKLOG ) ); // one pass short- CHECK( aiWantsAnotherFactory( 1, 0, aiAirfieldsFull( 1, 1, TRUE ), now - since, BACKLOG ) );-- // a jet lost frees a place: the clock starts again and the wait is the whole window once more- since = aiBacklogClock( since, aiAirfieldsFull( 1, 0, TRUE ), 0, now );- CHECK_EQ( 0u, since );- CHECK( !aiWantsAnotherFactory( 1, 0, aiAirfieldsFull( 1, 0, TRUE ), 0, BACKLOG ) );- since = aiBacklogClock( since, aiAirfieldsFull( 1, 1, TRUE ), 0, now + STEP );- CHECK( !aiWantsAnotherFactory( 1, 0, TRUE, STEP, BACKLOG ) );-- // the new airfield going up holds the clock, and it has to fill before the next- CHECK_EQ( 0u, aiBacklogClock( since, TRUE, 1, now + 2 * STEP ) );- CHECK( !aiWantsAnotherFactory( 2, 0, aiAirfieldsFull( 2, 1, TRUE ), BACKLOG, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 3, 0, aiAirfieldsFull( 3, 3, TRUE ), BACKLOG, BACKLOG ) ); // no cap+ // parking full and an aircraft waiting over the window: another airfield+ UnsignedInt history = 0;+ Int count = 0;+ for( Int i = 0; i < HARD; ++i )+ aiSampleFactories( &history, &count, aiAirfieldsFull( 1, 1, TRUE ), 0 );+ CHECK( aiWantsAnotherFactory( 1, 0, history, count, HARD ) );++ // jets lost free places for two passes: 3 of 5 holds it+ aiSampleFactories( &history, &count, aiAirfieldsFull( 1, 0, TRUE ), 0 );+ aiSampleFactories( &history, &count, aiAirfieldsFull( 1, 0, TRUE ), 0 );+ CHECK( !aiWantsAnotherFactory( 1, 0, history, count, HARD ) );++ // the new airfield going up starts the window again, and it has to fill before the next+ aiSampleFactories( &history, &count, TRUE, 1 );+ CHECK( !aiWantsAnotherFactory( 2, 0, history, count, HARD ) );+ for( Int i = 0; i < HARD; ++i )+ aiSampleFactories( &history, &count, aiAirfieldsFull( 2, 2, TRUE ), 0 );+ CHECK( aiWantsAnotherFactory( 2, 0, history, count, HARD ) ); // no cap}/** A site that cannot be finished is given up: builders dying on the way with nothing built between,