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): another airfield when every airfield's parking stays full
Olcay Seygan9b49557e11a4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1ff33d8fe..d4125c08c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -362,7 +362,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 kind gets another building once every one it has has been busy without a break for two minutes on Easy, 75 seconds on Medium and 45 on Hard, and a new one has to stay busy for that long too before the next. 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. 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.- 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 473cb1b22..f77c6df0d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -387,15 +387,37 @@ 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, shallowest is the shortest queue among the finished ones, and backedUpFor is how many frames- * every one of them has been busy.+ * way, full says every finished one is full now (aiQueueKindFull, aiAirfieldsFull), and backedUpFor+ * is how many frames they have all been full (aiBacklogClock).*- * Another goes up only when every finished factory has been busy for backlogFrames (the rung's+ * 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. Busy, not backed up: the scripts train only into an idle factory- * and the surplus fills a queue one deep, so a unit waiting behind the one being built almost never- * happened, and the computer stood one barracks, one war factory and one airfield all match. */-Bool aiWantsAnotherFactory( Int finished, Int constructing, Int shallowest, UnsignedInt backedUpFor, UnsignedInt backlogFrames );+ * building this would ask for. */+Bool aiWantsAnotherFactory( Int finished, Int constructing, Bool full, UnsignedInt backedUpFor, UnsignedInt backlogFrames );++/** 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+ * fills a queue one deep, so a unit waiting behind the one being built almost never happened, and+ * the computer stood one barracks and one war factory all match. */+inline Bool aiQueueKindFull( Int finished, Int shallowest ) { return finished > 0 && shallowest >= 1; }++/** An airfield is full when its parking is: every finished one (parkingFull of finished) refuses an+ * aircraft to its queue, and the computer has wanted one lately (wanted, a buy refused for parking).+ * Its queue says nothing, since a full airfield takes nothing into it. */+inline Bool aiAirfieldsFull( Int finished, Int parkingFull, Bool wanted ) { return finished > 0 && parkingFull >= finished && wanted; }++/** 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;+}/** 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. */diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex 99e7c78ec..f4dee9c3a 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 busy with none going up, 0 for not+ 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_parkingBlockedFrame; ///< the last frame a buy of an aircraft was refused because the airfield's parking was full, 0 for neverBool 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 b7ea85914..b7b98756a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1318,15 +1318,16 @@ 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 busy 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 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)* 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 */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, 120.0f, 360.0f, 1500.0f, 80.0f, 0.00f, 0.0f, 2.0f, 3 },+ /* 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 }};@@ -1455,14 +1456,14 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractio}//--------------------------------------------------------------------------------------------------Bool aiWantsAnotherFactory( Int finished, Int constructing, Int shallowest, UnsignedInt backedUpFor, UnsignedInt backlogFrames )+Bool aiWantsAnotherFactory( Int finished, Int constructing, Bool full, UnsignedInt backedUpFor, UnsignedInt backlogFrames ){if( constructing > 0 )return FALSE; // one is already going upif( finished <= 0 )return TRUE; // the last one is gone, so put one back- if( shallowest < 1 )- return FALSE; // one of them is idle: that one is the spare+ if( !full )+ return FALSE; // one of them has room: that one is the sparereturn backedUpFor >= backlogFrames;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex c08b061cc..b5b8d9871 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -398,6 +398,7 @@ m_role(AIROLE_AGGRESSIVE)m_startFortune = 0;for( Int k = 0; k < 3; ++k )m_factoryBackedUpSince[ k ] = 0;+ m_parkingBlockedFrame = 0;m_persona = AIPERSONA_NORMAL;m_personaFromRandom = FALSE;m_rushSent = FALSE;@@ -6399,6 +6400,7 @@ struct FactoryLoadInt finished;Int constructing;Int shallowest;+ Int parkingFull; ///< finished ones with no parking place left, which refuse an aircraft to their queue};/** The production kinds the computer buys extra copies of, in m_factoryBackedUpSince's order. */@@ -6479,15 +6481,37 @@ static void countFactoryLoad( Object *obj, void *userData )if( load->finished == 0 || queued < load->shallowest )load->shallowest = queued;++load->finished;+ // the same question ProductionUpdate::canQueueCreateUnit asks before an aircraft goes in the queue;+ // the answer depends only on whether the thing asked about is made at a helipad, and the airfield+ // itself is not+ for( BehaviorModule **m = obj->getBehaviorModules(); *m; ++m )+ {+ ParkingPlaceBehaviorInterface *pp = (*m)->getParkingPlaceBehaviorInterface();+ if( pp && !pp->hasAvailableSpaceFor( obj->getTemplate() ) )+ {+ ++load->parkingFull;+ break;+ }+ }}static FactoryLoad readFactoryLoad( Player *player, KindOfType kind ){- FactoryLoad load = { kind, 0, 0, 0 };+ FactoryLoad load = { kind, 0, 0, 0, 0 };player->iterateObjects( countFactoryLoad, &load );return load;}+/** Whether every finished factory of the kind is full now: a barracks or war factory by its queue, an+ * airfield by its parking while a buy was refused for it within AI_PARKING_WANT_FRAMES. */+static Bool factoryKindFull( const FactoryLoad &load, UnsignedInt parkingBlockedFrame )+{+ if( load.kind != KINDOF_FS_AIRFIELD )+ return aiQueueKindFull( load.finished, load.shallowest );+ const Bool wanted = parkingBlockedFrame != 0 && TheGameLogic->getFrame() - parkingBlockedFrame <= AI_PARKING_WANT_FRAMES;+ return aiAirfieldsFull( load.finished, load.parkingFull, wanted );+}+/** Factories of this kind the build list has yet to put up, which go up before any extra one; with* askedOnly, only the ones the AI asked for itself (a priority entry). */static Int plannedOfKind( Player *player, KindOfType kind, Bool askedOnly = FALSE )@@ -7537,6 +7561,13 @@ void AIPlayer::purchased( Int key, Int cost, AIPurchaseKind kind, const AsciiStrBool AIPlayer::buyUnit( ProductionUpdateInterface *pu, const ThingTemplate *unit, AIPurchaseKind kind ){+ // an airfield with every parking place taken refuses the aircraft (queueCreateUnit fails on it), so+ // nothing is saved for one, and the refusal is what says the computer wants another airfield+ if( pu->canQueueCreateUnit( unit ) == CANMAKE_PARKING_PLACES_FULL )+ {+ m_parkingBlockedFrame = TheGameLogic->getFrame();+ return FALSE;+ }const Int cost = unit->calcCostToBuild( m_player );// a personality's taste moves an army unit up or down the queue: the scripts' teams of a kind it// does not like wait while its favoured units are saved for@@ -7668,7 +7699,7 @@ Bool AIPlayer::holdsExtraFactory( const ThingTemplate *tmpl )if( 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, load.shallowest,+ 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 ) );}@@ -8636,16 +8667,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 busy, read on every pass so a factory that- // went idle in between starts the clock again, and one going up starts it again once it stands, so- // the new one has to prove itself busy too (queueExtraFactory)+ // 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)for( Int k = 0; k < PRODUCTION_KINDS; ++k ){const FactoryLoad load = readFactoryLoad( m_player, PRODUCTION_KIND[ k ] );- if( load.finished == 0 || load.constructing > 0 || load.shallowest < 1 )- m_factoryBackedUpSince[ k ] = 0;- else if( m_factoryBackedUpSince[ k ] == 0 )- m_factoryBackedUpSince[ k ] = now;+ m_factoryBackedUpSince[ k ] = aiBacklogClock( m_factoryBackedUpSince[ k ],+ factoryKindFull( load, m_parkingBlockedFrame ), load.constructing, now );}// the income, off what the score screen counts as earned: gathered, hacked, captured and given@@ -16538,7 +16567,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 27; // 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+ 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 parkingXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -16990,6 +17019,10 @@ void AIPlayer::xfer( Xfer *xfer )xfer->xferUnsignedInt( &m_answeredFrame );}+ // the last aircraft refused for parking, which keeps the airfield backlog clock running+ if( version >= 28 )+ xfer->xferUnsignedInt( &m_parkingBlockedFrame );+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex cb342c903..39b9deb31 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12622,8 +12622,8 @@ TEST(ground_flood_goes_round_the_wall_nearest_first)}/** Another factory only when every one standing has stayed busy for the rung's backlog, with no cap on- how many, and another tech building until three are standing. */-TEST(extra_factory_follows_the_queue_and_tech_stops_at_three)+ how many. */+TEST(extra_factory_follows_the_queue){TAiData data;for( Int s = 0; s < AISKILL_COUNT; ++s )@@ -12636,34 +12636,84 @@ TEST(extra_factory_follows_the_queue_and_tech_stops_at_three)const UnsignedInt BACKLOG = (UnsignedInt)REAL_TO_INT( data.m_skill[ AISKILL_BRUTAL ].m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND );// nothing left standing: put one back- CHECK( aiWantsAnotherFactory( 0, 0, 0, 0, BACKLOG ) );+ CHECK( aiWantsAnotherFactory( 0, 0, FALSE, 0, BACKLOG ) );// one already going up is the building this would ask for- CHECK( !aiWantsAnotherFactory( 0, 1, 0, 0, BACKLOG ) );- CHECK( !aiWantsAnotherFactory( 2, 1, 4, BACKLOG, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 0, 1, FALSE, 0, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 2, 1, TRUE, BACKLOG, BACKLOG ) );- // one with an empty queue is the spare- CHECK( !aiWantsAnotherFactory( 2, 0, 0, BACKLOG, BACKLOG ) );+ // 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 up+ CHECK( !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, 5, 0, BACKLOG ) );- CHECK( !aiWantsAnotherFactory( 1, 0, 1, BACKLOG - 1, BACKLOG ) );-- // busy the whole time, only the unit it builds in the queue, is enough: the scripts never queue- // behind it, and a second factory never went up- CHECK( aiWantsAnotherFactory( 1, 0, 1, BACKLOG, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 1, 0, 2, BACKLOG, BACKLOG ) );+ 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, 1, BACKLOG, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 9, 0, 1, BACKLOG + 600, BACKLOG ) );+ CHECK( aiWantsAnotherFactory( 2, 0, TRUE, BACKLOG, BACKLOG ) );+ CHECK( aiWantsAnotherFactory( 9, 0, TRUE, BACKLOG + 600, BACKLOG ) );// a lower rung waits longer for the same backlogconst UnsignedInt EASY = (UnsignedInt)REAL_TO_INT( data.m_skill[ AISKILL_EASY ].m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND );- CHECK( !aiWantsAnotherFactory( 2, 0, 1, BACKLOG, EASY ) );- CHECK( aiWantsAnotherFactory( 2, 0, 1, EASY, EASY ) );+ 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 ) );+}++/** 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. */+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++ // full takes every airfield's parking and an aircraft refused for it+ CHECK( aiAirfieldsFull( 2, 2, TRUE ) );+ CHECK( !aiAirfieldsFull( 2, 1, TRUE ) ); // one still has a place+ CHECK( !aiAirfieldsFull( 2, 2, FALSE ) ); // parked full, but nothing waits for a place+ CHECK( !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+}++TEST(another_tech_building_until_three_stand)+{CHECK( aiWantsAnotherTechBuilding( 0, 0 ) );CHECK( aiWantsAnotherTechBuilding( AI_TECH_BUILDING_COPIES - 1, 0 ) );CHECK( !aiWantsAnotherTechBuilding( 2, 1 ) );