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 factory whenever every one of its kind stays busy
Olcay Seygan9481fbb50e7e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 49d00f48d..439ef8157 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -362,6 +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.- 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 f31c93186..473cb1b22 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -256,8 +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- Int m_maxProduction; ///< war factories, barracks and airfields together, beyond which the spend rule adds none- Real m_factoryBankMultiple; ///< past this many times the bank target a factory is added whatever the bank's trend; 0 = only on the trend+ Real m_factoryBacklogSeconds; ///< how long every finished factory of a kind has to stay busy 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)@@ -387,19 +386,16 @@ AIFallbackDecision aiRetreatHoldDecision( Bool arrived, UnsignedInt heldFrames,Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFraction,Bool timeExpired, Bool baseUnderAttack );-/** How long every finished factory of a kind has to keep a unit waiting behind the one it is building- * before the computer buys another. A script's team lands in the queue all at once, so a backlog- * the moment it appears is a batch, not a factory falling behind. */-static const Int AI_FACTORY_BACKLOG_SECONDS = 45;-/** 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 had a unit waiting behind the one it is building.+ * every one of them has been busy.*- * Another goes up only when every finished factory has had a unit waiting for- * AI_FACTORY_BACKLOG_SECONDS, 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, Int shallowest, UnsignedInt backedUpFor );+ * Another goes up only when every finished factory has been busy 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 );/** 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. */@@ -721,12 +717,6 @@ const UnsignedInt AI_INCOME_WINDOW_FRAMES = 30 * LOGICFRAMES_PER_SECOND;/** The bank a computer player keeps: seconds of its income, and never under the floor. */Int aiBankTarget( Real incomePerSecond, Real seconds, Int floor );-/** Another factory, measured rather than guessed: fewer than cap stand, and the bank is over its target- * and no lower than it was an income window ago, so what stands is not spending what comes in, or it is- * past multiple times the target whatever its trend (a busy Hard AI's bank swings, and the trend alone- * almost never fired). multiple 0 leaves only the trend. */-Bool aiWantsMoreProduction( Int bank, Int bankWindowAgo, Int target, Int standing, Int cap, Real multiple );-/** How much a bank over its target may put into extra units on one spend pass: share of the income of* AI_SURPLUS_INCOME_SECONDS, and never what takes the bank under target. At share 1 that is three* passes' income a pass, which drains a pile; a rung with a small share only tops its plan up. */diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex c9b6308af..99e7c78ec 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -364,13 +364,13 @@ protected:/** The spend rule, on every rung with a bank target. Measures the income, and with the bank past* aiBankTarget spends what is over it: upgrades at half the payoff, extra units from idle factories- * within aiSurplusBudget, and another factory when the bank has not come down over an income window- * (aiWantsMoreProduction). Upgrades that pay for the army are bought below the target as well,- * through the purchase queue. */+ * within aiSurplusBudget. Another factory of any kind whose every factory stays busy, whatever the+ * bank. Upgrades that pay for the army are bought below the target as well, through the purchase+ * queue. */void doSpending(void);Int bankTarget(void); ///< what the bank keeps, from the income measured lastvoid buyUpgradesForArmy(Bool overTarget); ///< the player upgrade the standing army gets the most out of- void addProductionForIncome(Int bank, Int bankWindowAgo, Int target); ///< another factory, while what stands does not bring the bank down+ void addProductionForQueues(void); ///< another factory of each kind whose every factory has stayed busyvoid trainSurplus(Int budget); ///< a unit from each idle factory, within budgetvoid trainFavoured(void); ///< a personality's favoured units, below the bank target as wellvoid buyPersonaTransports(void); ///< an Infantry AI's ground transports, a few by rung@@ -380,7 +380,7 @@ 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 with a unit waiting, 0 for not+ UnsignedInt m_factoryBackedUpSince[ 3 ]; ///< per war factory, barracks, airfield: the frame every finished one was first seen busy with none going up, 0 for notBool 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 e29980825..b7ea85914 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1318,12 +1318,17 @@ 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.*- * 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 push minPow siege beam strikeE strikeT swDef */+ * 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)+ * 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, 3, 0.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, 5, 3.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, 8, 2.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, 120.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 }};//-------------------------------------------------------------------------------------------------@@ -1450,15 +1455,15 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractio}//--------------------------------------------------------------------------------------------------Bool aiWantsAnotherFactory( Int finished, Int constructing, Int shallowest, UnsignedInt backedUpFor )+Bool aiWantsAnotherFactory( Int finished, Int constructing, Int shallowest, 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 < 2 )- return FALSE; // one of them has room: nothing is waiting behind what it builds- return backedUpFor >= (UnsignedInt)( AI_FACTORY_BACKLOG_SECONDS * LOGICFRAMES_PER_SECOND );+ if( shallowest < 1 )+ return FALSE; // one of them is idle: that one is the spare+ return backedUpFor >= backlogFrames;}//-------------------------------------------------------------------------------------------------@@ -1932,13 +1937,6 @@ Int aiBankTarget( Real incomePerSecond, Real seconds, Int floor )return byIncome > floor ? byIncome : floor;}-//--------------------------------------------------------------------------------------------------Bool aiWantsMoreProduction( Int bank, Int bankWindowAgo, Int target, Int standing, Int cap, Real multiple )-{- if( standing >= cap || bank <= target )- return FALSE;- return bank >= bankWindowAgo || (multiple > 0.0f && INT_TO_REAL( bank ) > multiple * INT_TO_REAL( target ));-}//-------------------------------------------------------------------------------------------------Int aiSurplusBudget( Int bank, Int target, Real incomePerSecond, Real share )@@ -2220,8 +2218,7 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{ "UpgradeStartSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_upgradeStartSeconds ) },{ "UpgradeNonCombatWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_upgradeNonCombatWeight ) },{ "SurplusShare", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_surplusShare ) },- { "MaxProduction", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_maxProduction ) },- { "FactoryBankMultiple", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_factoryBankMultiple ) },+ { "FactoryBacklogSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_factoryBacklogSeconds ) },{ "FirstPushSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_firstPushSeconds ) },{ "MinAttackPower", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_minAttackPower ) },{ "SiegeTrail", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_siegeTrail ) },diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 571595ad8..c08b061cc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -7025,22 +7025,9 @@ void AIPlayer::doEconomy( void )placeNear( tmpl, &m_baseCenter, 0.5f * m_baseRadius, FALSE );}+ // another factory is doSpending's, on every rungif( m_persona != AIPERSONA_TURTLE )queueBaseDefenses( dozer );-- // ... and what does not pay back for twice it, so the opening build order is not what pays for it- if( m_player->getMoney()->countMoney() <= 2 * profile->m_cashHoardThreshold )- return;-- /* Another factory only once the ones standing fall behind their queues (aiWantsAnotherFactory).- Airfields, and war factories and barracks while the base had no room for an income building,- used to get one a pass whatever their queues, and the opening spent itself on a second barracks- with the first one empty. The kind asked first turns with each pass, so a queue that never- empties does not keep the others waiting. */- const Int first = (Int)( ((TheGameLogic->getFrame() + phase) / ECONOMY_CHECK_RATE) % PRODUCTION_KINDS );- for( Int i = 0; i < PRODUCTION_KINDS; ++i )- if( queueExtraFactory( dozer, PRODUCTION_KIND[ (first + i) % PRODUCTION_KINDS ] ) )- return;}//----------------------------------------------------------------------------------------------------------@@ -7630,8 +7617,9 @@ void AIPlayer::buyMoneyUnits( void )//----------------------------------------------------------------------------------------------------------/** One more factory of this kind, beside a held expansion or around the base. The expansion try is* local: a miss out there must not walk the base's ring cursor past the ground around the command- * center, or the first crowded dock skips the base itself. Nothing while the build list still has one- * of this kind to put up, since that one goes first, and then only when holdsExtraFactory lets it. */+ * center, or the first crowded dock skips the base itself. Nothing while one of this kind is asked for+ * and not yet up, since that one goes first, and then only when holdsExtraFactory lets it. A plan copy+ * the scripts have not asked for does not wait it out: they reach those at eight minutes. *///----------------------------------------------------------------------------------------------------------Bool AIPlayer::queueExtraFactory( Object *dozer, KindOfType kind ){@@ -7650,7 +7638,7 @@ Bool AIPlayer::queueExtraFactory( Object *dozer, KindOfType kind )favoured = load.constructing == 0 && load.finished < PERSONA_FAVOURED_FACTORIES[ m_skillLevel ];}}- if( favoured ? plannedOfKind( m_player, kind, TRUE ) > 0 : plannedOfKind( m_player, kind ) > 0 || holdsExtraFactory( tmpl ) )+ if( plannedOfKind( m_player, kind, TRUE ) > 0 || ( !favoured && holdsExtraFactory( tmpl ) ) )return FALSE;const Object *warehouse = TheGameLogic->findObjectByID( m_curWarehouseID );@@ -7662,8 +7650,8 @@ Bool AIPlayer::queueExtraFactory( Object *dozer, KindOfType kind )}//-----------------------------------------------------------------------------------------------------------/** A second factory of a kind waits until every finished one has kept a unit waiting for- * AI_FACTORY_BACKLOG_SECONDS (aiWantsAnotherFactory; doSpending keeps that clock), and while one is+/** 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* 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. */@@ -7681,7 +7669,8 @@ Bool AIPlayer::holdsExtraFactory( const ThingTemplate *tmpl )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,- since == 0 ? 0 : TheGameLogic->getFrame() - since );+ since == 0 ? 0 : TheGameLogic->getFrame() - since,+ (UnsignedInt)REAL_TO_INT( getSkillProfile()->m_factoryBacklogSeconds * LOGICFRAMES_PER_SECOND ) );}return FALSE;}@@ -8633,8 +8622,8 @@ static const ThingTemplate *surplusUnit( Object *factory, const Player *owner, c/** The bank a computer kept was the part of its income nothing was ever bought with: a Hard AI facing* Medium ended its matches on 12,300 on average, a Medium one on up to 62,000. So every rung* keeps a bank of so many seconds of what it actually earns (m_bankTargetSeconds, aiBankTarget), and- * what is over that goes on upgrades, on extra units within the rung's share (aiSurplusBudget), and- * on another factory once an income window shows the bank is not coming down (aiWantsMoreProduction).+ * what is over that goes on upgrades and on extra units within the rung's share (aiSurplusBudget).+ * Another factory goes up whenever every one of its kind has stayed busy (addProductionForQueues).* The upgrades that pay for the standing army are bought below the target as well, each rung from* its own point in the match, and all of it goes through the purchase queue, which keeps below the* same target. */@@ -8647,12 +8636,13 @@ 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 had a unit waiting behind the one it builds,- // read on every pass so a queue that ran dry in between starts the clock again (queueExtraFactory)+ // 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)for( Int k = 0; k < PRODUCTION_KINDS; ++k ){const FactoryLoad load = readFactoryLoad( m_player, PRODUCTION_KIND[ k ] );- if( load.finished == 0 || load.shallowest < 2 )+ if( load.finished == 0 || load.constructing > 0 || load.shallowest < 1 )m_factoryBackedUpSince[ k ] = 0;else if( m_factoryBackedUpSince[ k ] == 0 )m_factoryBackedUpSince[ k ] = now;@@ -8661,13 +8651,10 @@ void AIPlayer::doSpending( void )// the income, off what the score screen counts as earned: gathered, hacked, captured and givenconst Int bank = (Int)m_player->getMoney()->countMoney();const Int earned = m_player->getScoreKeeper()->getTotalMoneyEarned();- Bool windowEnded = FALSE;- Int bankWindowAgo = bank;if( now - m_incomeMarkFrame >= AI_INCOME_WINDOW_FRAMES ){const Real window = INT_TO_REAL( earned - m_incomeMark ) * LOGICFRAMES_PER_SECOND / INT_TO_REAL( now - m_incomeMarkFrame );- windowEnded = m_incomeMarkFrame != 0; // the first window has no bank before it to compare with- bankWindowAgo = m_bankMark;+ const Int bankWindowAgo = m_bankMark;m_incomePerSecond = m_incomeMarkFrame == 0 ? window : 0.5f * (m_incomePerSecond + window);m_incomeMark = earned;m_incomeMarkFrame = now;@@ -8678,6 +8665,7 @@ void AIPlayer::doSpending( void )if( isBaseUnderAttack() )return; // defendHome's+ addProductionForQueues();if( m_persona != AIPERSONA_NORMAL )trainFavoured();const Int target = bankTarget();@@ -8691,13 +8679,11 @@ void AIPlayer::doSpending( void )// A match that starts on 50,000 handed every AI a bank no income window ever saw coming: the// surplus is a share of what it earns, and in the first minutes it earns nothing, so the fortune// sat there while the build list ticked along. What is over the default starting cash, up to- // what the start gave over it, goes out at the rung's share a pass, and factories go up for it- // without waiting on a window. At the default cash the fortune is 0 and nothing here changes.+ // what the start gave over it, goes out at the rung's share a pass. At the default cash the+ // fortune is 0 and nothing here changes.//const Int keep = max( target, (Int)TheGlobalData->m_defaultStartingCash.countMoney() );const Int fortune = aiFortuneBudget( bank, keep, m_startFortune, getSkillProfile()->m_surplusShare );- if( windowEnded || fortune > 0 )- addProductionForIncome( bank, bankWindowAgo, target ); // between windows bankWindowAgo is the bank itselfconst Int surplus = aiSurplusBudget( (Int)m_player->getMoney()->countMoney(), target, m_incomePerSecond, getSkillProfile()->m_surplusShare );if( fortune > surplus )DEBUG_LOG(("AI ECONOMY frame %d player %d spends its starting fortune, %d of it this pass, %d in the bank, %d kept\n", now,@@ -8843,57 +8829,32 @@ void AIPlayer::buyUpgradesForArmy( Bool overTarget )}//-----------------------------------------------------------------------------------------------------------/** Another tank factory or barracks, whichever the base has fewer of, when an income window ends with- * the bank over its target and no lower than a window before, or past m_factoryBankMultiple times the- * target (aiWantsMoreProduction): what stands is not spending what comes in. One at a time, and no more than the rung's m_maxProduction war- * factories, barracks and airfields together. A guessed spend rate a factory stood here first: a- * Hard AI earning 93 a second wanted the two factories it had. Unbuilt plan entries count as standing,- * or the rule adds the factory the plan is about to put up. A bank alone is no reason: the kind's- * own factories have to be falling behind their queues too (queueExtraFactory), or a match started on- * a big bank opened on a second barracks before the first had trained anyone. */+/** Another war factory, barracks or airfield of each kind whose every factory has stayed busy for the+ * rung's m_factoryBacklogSeconds (queueExtraFactory), on every rung and with no cap on how many stand:+ * a kind that keeps all of its factories busy is short of them. A cap of 3, 5 and 8 production+ * buildings and a bank rule stood here, behind a gate that waited for a unit queued behind the one+ * being built, which the scripts never queue, so the computer stood one of each all match. The+ * money is the purchase queue's, like every other building. *///-----------------------------------------------------------------------------------------------------------void AIPlayer::addProductionForIncome( Int bank, Int bankWindowAgo, Int target )+void AIPlayer::addProductionForQueues( void ){if( !m_player->getCanBuildBase() || !m_baseCenterSet )return;-- Int standing[ PRODUCTION_KINDS ];- Int total = 0;- // ... and the ones the plan has yet to put up count as standing: early on a Medium plan of two war- // factories and a barracks had two up, and the rule added the third the plan was about to build- Int planned = 0;- for( Int k = 0; k < PRODUCTION_KINDS; ++k )- {- const FactoryLoad load = readFactoryLoad( m_player, PRODUCTION_KIND[ k ] );- if( load.constructing > 0 )- return; // one at a time- standing[ k ] = load.finished;- total += load.finished;- planned += plannedOfKind( m_player, PRODUCTION_KIND[ k ] );- }- total += planned;- const Int cap = getSkillProfile()->m_maxProduction;- if( !aiWantsMoreProduction( bank, bankWindowAgo, target, total, cap, getSkillProfile()->m_factoryBankMultiple ) )- return;-Object *dozer = NULL;m_player->iterateObjects( findAnyDozer, &dozer );if( dozer == NULL )return;- const Int first = standing[ 1 ] < standing[ 0 ] ? 1 : 0;- // a personality with a unit taste asks for its favoured kind first, an airfield included- const Int favoured = m_persona != AIPERSONA_NORMAL ? personaFavouredKind( personaTaste() ) : -1;- for( Int k = favoured >= 0 ? -1 : 0; k < 2; ++k )+ for( Int k = 0; k < PRODUCTION_KINDS; ++k ){- const KindOfType kind = PRODUCTION_KIND[ k < 0 ? favoured : k == 0 ? first : 1 - first ];- if( queueExtraFactory( dozer, kind ) )- {- DEBUG_LOG(("AI ECONOMY frame %d player %d puts up another %s, %d of at most %d standing (%d of them planned), %d in the bank (%d a window ago), bank target %d, %.0f a second of income\n",- TheGameLogic->getFrame(), m_player->getPlayerIndex(),- kind == KINDOF_FS_WARFACTORY ? "war factory" : kind == KINDOF_FS_BARRACKS ? "barracks" : "airfield",- total, cap, planned, bank, bankWindowAgo, target, m_incomePerSecond));- return;- }+ // the first of a kind, and one put back, is the plan's when its scripts ask: from here an+ // Easy computer stood its barracks and airfield in the first ten seconds, ahead of its plan+ const FactoryLoad load = readFactoryLoad( m_player, PRODUCTION_KIND[ k ] );+ if( load.finished == 0 || !queueExtraFactory( dozer, PRODUCTION_KIND[ k ] ) )+ continue;+ DEBUG_LOG(("AI ECONOMY frame %d player %d puts up another %s, %d standing, %d in the bank\n",+ TheGameLogic->getFrame(), m_player->getPlayerIndex(),+ k == 0 ? "war factory" : k == 1 ? "barracks" : "airfield", load.finished,+ m_player->getMoney()->countMoney()));}}@@ -15741,8 +15702,6 @@ const AIDifficultyProfile *AIPlayer::getSkillProfile( void ) constp.m_bankTargetFloor = REAL_TO_INT( INT_TO_REAL( p.m_bankTargetFloor ) * w.m_bank );p.m_cashHoardThreshold = REAL_TO_INT( INT_TO_REAL( p.m_cashHoardThreshold ) * w.m_hoard );p.m_surplusShare = min( 1.0f, p.m_surplusShare * w.m_surplus );- // one that spends has the factories to spend at: an Attacker on eight sat on 42,000 at 360 a second- p.m_maxProduction = REAL_TO_INT( INT_TO_REAL( p.m_maxProduction ) * max( 1.0f, 0.75f * w.m_surplus ) );p.m_retreatTtkRatio *= w.m_retreat;p.m_counterCompositionWeight = p.m_counterCompositionWeight * w.m_counter + w.m_counterAdd;p.m_upgradeStartSeconds *= w.m_upgradeStart;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 5c16b7883..cb342c903 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12621,31 +12621,48 @@ TEST(ground_flood_goes_round_the_wall_nearest_first)CHECK_EQ( count, 3 ); // the source and its two side neighbours}-/** Another factory only when every one standing has kept a unit waiting for AI_FACTORY_BACKLOG_SECONDS,- and another tech building until three are standing. */+/** 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){- const UnsignedInt BACKLOG = AI_FACTORY_BACKLOG_SECONDS * LOGICFRAMES_PER_SECOND;+ TAiData data;+ for( Int s = 0; s < AISKILL_COUNT; ++s )+ {+ // every rung waits, Hard the shortest+ CHECK( data.m_skill[ s ].m_factoryBacklogSeconds > 0.0f );+ 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 );// nothing left standing: put one back- CHECK( aiWantsAnotherFactory( 0, 0, 0, 0 ) );+ CHECK( aiWantsAnotherFactory( 0, 0, 0, 0, BACKLOG ) );// one already going up is the building this would ask for- CHECK( !aiWantsAnotherFactory( 0, 1, 0, 0 ) );- CHECK( !aiWantsAnotherFactory( 2, 1, 4, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 0, 1, 0, 0, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 2, 1, 4, BACKLOG, BACKLOG ) );- // one with an empty queue, or only the unit it is building, has room- CHECK( !aiWantsAnotherFactory( 2, 0, 0, BACKLOG ) );- CHECK( !aiWantsAnotherFactory( 1, 0, 1, BACKLOG ) );+ // one with an empty queue is the spare+ CHECK( !aiWantsAnotherFactory( 2, 0, 0, BACKLOG, BACKLOG ) );// a team landing in the queue all at once is a batch, not a factory falling behind: the- // opening's training no longer buys a second barracks- CHECK( !aiWantsAnotherFactory( 1, 0, 5, 0 ) );- CHECK( !aiWantsAnotherFactory( 1, 0, 5, BACKLOG - 1 ) );+ // opening's training does not buy a second barracks+ CHECK( !aiWantsAnotherFactory( 1, 0, 5, 0, BACKLOG ) );+ CHECK( !aiWantsAnotherFactory( 1, 0, 1, BACKLOG - 1, BACKLOG ) );- // every finished one has kept a unit waiting the whole time- CHECK( aiWantsAnotherFactory( 1, 0, 2, BACKLOG ) );- CHECK( aiWantsAnotherFactory( 3, 0, 2, BACKLOG + 600 ) );+ // 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 ) );++ // 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 ) );++ // 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, 1, BACKLOG, EASY ) );+ CHECK( aiWantsAnotherFactory( 2, 0, 1, EASY, EASY ) );CHECK( aiWantsAnotherTechBuilding( 0, 0 ) );CHECK( aiWantsAnotherTechBuilding( AI_TECH_BUILDING_COPIES - 1, 0 ) );@@ -13009,20 +13026,6 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)CHECK_EQ( 6000, aiBankTarget( 200.0f, 30.0f, 4000 ) );CHECK_EQ( 12000, aiBankTarget( 200.0f, 60.0f, 4000 ) );- // another factory only when the bank is over target and has not come down over the window, and the- // rung's cap is not reached: the first cut sized it from income and a Hard AI earning 93 a second- // never added one to the two it had- CHECK( aiWantsMoreProduction( 56700, 56000, 4000, 2, 8, 0.0f ) ); // over target and still rising- CHECK( aiWantsMoreProduction( 9000, 9000, 4000, 2, 8, 0.0f ) ); // over target and flat- CHECK( !aiWantsMoreProduction( 9000, 12000, 4000, 2, 8, 0.0f ) ); // coming down: what stands spends it- CHECK( !aiWantsMoreProduction( 3000, 1000, 4000, 2, 8, 2.0f ) ); // under target- CHECK( !aiWantsMoreProduction( 56700, 56000, 4000, 8, 8, 2.0f ) ); // at the cap- CHECK( !aiWantsMoreProduction( 56700, 56000, 4000, 3, 3, 2.0f ) );- // a busy Hard AI's bank swings, so past twice the target it adds one whatever the trend- CHECK( aiWantsMoreProduction( 52200, 60000, 4000, 4, 8, 2.0f ) );- CHECK( !aiWantsMoreProduction( 8000, 9000, 4000, 4, 8, 2.0f ) ); // at twice, not past it- CHECK( !aiWantsMoreProduction( 52200, 60000, 4000, 4, 8, 0.0f ) ); // a rung without the multiple-// the surplus budget: the rung's share of thirty seconds' income, never past the excessCHECK_EQ( 0, aiSurplusBudget( 3000, 4000, 100.0f, 1.0f ) ); // under target, nothingCHECK_EQ( 3000, aiSurplusBudget( 60000, 4000, 100.0f, 1.0f ) ); // Hard: a window's income a pass@@ -13092,7 +13095,6 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)CHECK( upper.m_upgradePayoff < lower.m_upgradePayoff );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 farthestCHECK( lower.m_firstPushSeconds > 0.0f && upper.m_firstPushSeconds > 0.0f );@@ -13100,13 +13102,8 @@ TEST(the_bank_target_and_the_upgrade_the_army_pays_for)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 builds past its plan with a bank past twice its target, Medium only past a bigger multiple and- // to a lower cap, Easy never; Medium out-armies Easy and Hard out-armies Medium, which an equal share- // and cap for the two lower rungs had undone- CHECK( data.m_skill[ AISKILL_BRUTAL ].m_maxProduction > data.m_skill[ AISKILL_MEDIUM ].m_maxProduction );- CHECK( data.m_skill[ AISKILL_BRUTAL ].m_factoryBankMultiple > 0.0f );- CHECK( data.m_skill[ AISKILL_MEDIUM ].m_factoryBankMultiple > data.m_skill[ AISKILL_BRUTAL ].m_factoryBankMultiple );- CHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_factoryBankMultiple );+ // Medium out-armies Easy and Hard out-armies Medium, which an equal share for the two lower rungs+ // had undoneCHECK( data.m_skill[ AISKILL_BRUTAL ].m_surplusShare >= 4.0f * data.m_skill[ AISKILL_MEDIUM ].m_surplusShare );// Easy fires the retail S curve; Medium drives the Particle Cannon's beam at walking pace, Hard// steers it often enough to count as the double click that drives it fastdiff --git a/ai-batch.ps1 b/ai-batch.ps1index 158cd29e0..b64d46fb5 100644--- a/ai-batch.ps1+++ b/ai-batch.ps1@@ -217,8 +217,18 @@ foreach ($run in $started) {$loss = @{}$engage = @{}$econ = [pscustomobject]@{ Reattach = 0; Waves = 0; Counter = 0 }+ # production buildings each player put up, by kind (an arms dealer is GLA's war factory); a lost+ # one put back counts again, so this is at least the most that ever stood at once+ $factories = @{}foreach ($line in Get-Content $log) {+ if ($line -match "^AI BUILT frame \d+ player (\d+) '.*?(WarFactory|ArmsDealer|Barracks|Airfield)'") {+ $p = [int]$Matches[1]+ if (-not $factories.ContainsKey($p)) { $factories[$p] = @{ WarFactory = 0; Barracks = 0; Airfield = 0 } }+ $kind = if ($Matches[2] -eq "ArmsDealer") { "WarFactory" } else { $Matches[2] }+ $factories[$p][$kind]+++ continue+ }if ($line -match "^AI LOSS frame \d+ player (\d+) .* (straggling|grouped|last), ") {$p = [int]$Matches[1]if (-not $loss.ContainsKey($p)) { $loss[$p] = @{ straggling = 0; grouped = 0; last = 0 } }@@ -303,7 +313,7 @@ foreach ($run in $started) {Write-Host ("{0}, {1}, frame {2}, {3:n0}s" -f $why, $winnerText, $frames, $wall)$rows += [pscustomobject]@{ Seed = $seed; Cells = $cells; Why = $why; Frames = $frames; Wall = $wall; Slots = $slots; Pf = $pf; Perf = $perf; Jobs = $jobs; Ft = $ft; Spikes = $spikes- Value = $value; Loss = $loss; Engage = $engage; Econ = $econ; Winner = $winner }+ Value = $value; Loss = $loss; Engage = $engage; Econ = $econ; Factories = $factories; Winner = $winner }}# ---------------------------------------------------------------------------------------------@@ -342,6 +352,23 @@ $summary = foreach ($p in $slotIds) {}if ($summary) { $summary | Format-Table -AutoSize | Out-String | Write-Host }+# How many of each production building a player put up, the most in any one match of the batch:+# a computer that stands one of each all match is short of factories (AIPlayer::addProductionForQueues).+$factoryIds = $rows | ForEach-Object { if ($_.Factories) { $_.Factories.Keys } } | Sort-Object -Unique+$factoryRows = foreach ($p in $factoryIds) {+ $mine = @($rows | Where-Object { $_.Factories -and $_.Factories.ContainsKey($p) } | ForEach-Object { $_.Factories[$p] })+ [pscustomobject]@{+ Player = $p+ MaxWarFactory = ($mine | ForEach-Object { $_.WarFactory } | Measure-Object -Maximum).Maximum+ MaxBarracks = ($mine | ForEach-Object { $_.Barracks } | Measure-Object -Maximum).Maximum+ MaxAirfield = ($mine | ForEach-Object { $_.Airfield } | Measure-Object -Maximum).Maximum+ }+}+if ($factoryRows) {+ Write-Host "production buildings put up (AI BUILT), most in one match:"+ $factoryRows | Format-Table -AutoSize | Out-String | Write-Host+}+# The exchange each side made, in money: lost over killed below 1 is a side that trades well. Team# deaths by how alone each one died, straggling being the one the AI could have prevented. What it# sent out and why, with the two odds it set off on.