Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): skirmish AI players earn double by playing
Olcay Seygan14564d5a42f3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 779f07371..dc0b8d7f1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,13 @@ found and fixed, EA's own, not port damage.**---+## Computer players earn double++- A computer player in a skirmish or a network match now earns double, on every difficulty. A truckload worth 75 banks 150, and the 1000 for capturing an oil derrick is 2000. It counts everything the computer makes by playing: supply docks, oil derricks and other tech buildings, black markets, drop zones, hackers, bounties, crates, salvage and stolen cash. On one generated map, two Easy computers earned 25,800 and 28,200 in six minutes and forty seconds and now earn 51,600 and 56,400. Two Hard ones on the same seed went from 22,800 and 24,825 to 74,800 and 81,090, because Hard spends the extra money on more income: one of them built four supply centers and two drop zones where it used to build two and one.+- Money it gets back stays what it was. Selling a building or cancelling a queue returns the same sum as yours does, or a computer could queue and cancel its way to a fortune, and cash from a map's script or from an ally is not doubled either. The money figure floating over a computer's truck or building shows what it really banked.+- Your own income does not change, and your cut of a computer ally's income under Share Income is the plain cut. Campaign missions and Generals' Challenge opponents earn what they always did.+- Replays recorded before this change play out differently.+## Missions keep the time their script wrote- EA's cinematics slow the game on purpose, so the radio lines fit and the camera lands where the next shot starts. This build had stopped honouring that on 18 October. Every mission's cutscenes now run at the pace their script asks for. China's parade had 16 seconds of radio talking over itself, and has 11 now: what is left is EA's own script, which starts the tank crews' lines two thirds of a second apart.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex dde09e97b..668646748 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -181,6 +181,13 @@ Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, IBool IncomeSharingSplits( Int incomeSharing, Bool fromTechBuilding );UnsignedInt IncomeAllyShare( UnsignedInt amount, Int sharers );+// A skirmish computer player earns double what it earns by playing, on every rung. What one payment+// comes to in a recipient's bank: doubled only when a computer earned it and a computer banks it, so+// a human ally's cut of a computer's income stays plain and a human's income never pays double.+// Refunds, script grants and transfers between allies do not come through here: doubling a refund+// is a queue and cancel money loop.+UnsignedInt EarnedAmount( UnsignedInt amount, Bool earnerIsSkirmishAI, Bool recipientIsSkirmishAI );+// Pro Rules, PRO-RULES.md: what every skirmish and network match refuses whoever plays it.// GameLogic::isProRules() says whether a match is under them; these say what they cover, by name// or by type, so a test can ask them without a match.@@ -397,8 +404,10 @@ public:/// return the Player's Money sub-objectinline Money *getMoney() { return &m_money; }inline const Money *getMoney() const { return &m_money; }- /// steady income - a supply run, a hacker's payout, a derrick's - banked and scored, and split with the allies when the lobby's income sharing covers it- void earnIncome( UnsignedInt amount, Bool fromTechBuilding );+ /// steady income - a supply run, a hacker's payout, a derrick's - banked and scored, and split with the allies when the lobby's income sharing covers it. Returns what the payment came to, all banks together+ UnsignedInt earnIncome( UnsignedInt amount, Bool fromTechBuilding );+ /// money made by playing that nobody shares - a capture bonus, a crate, a bounty, stolen cash - banked and scored. Returns what it came to+ UnsignedInt earnMoney( UnsignedInt amount );UnsignedInt getSupplyBoxValue();///< Many things can affect the alue of a crate, but at heart it is a GlobalData ratio.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex fcd03b3c3..23798046a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -144,9 +144,10 @@ public:/** Three rungs of how well the AI plays. Deliberately NOT GameDifficulty, which carries the same* three values for a different reason: that enum answers "which scripts run" and is baked into* every shipped map and .scb, into the campaign's stat bonus tables and into network messages.- * This one answers "how well does it play", and every rung of it plays by the player's rules - no- * income, build-rate, vision or stat handicap at any level, in either direction. Keeping it a- * separate enum is what lets a rung be tuned in AI.ini without touching what a map's scripts do.+ * This one answers "how well does it play". No rung has a build-rate, vision or stat handicap, in+ * either direction, and no rung's income differs from another's: every skirmish AI earns double by+ * playing (Player::earnMoney), whatever its rung. Keeping it a separate enum is what lets a rung be+ * tuned in AI.ini without touching what a map's scripts do.* See AI-ROADMAP.md sections D6, D7 and D10.*///-------------------------------------------------------------------------------------------------@@ -215,9 +216,10 @@ AIPersonality aiPersonalityFromName( const char *name );/** One rung of the ladder. Every new AI behaviour adds a field here rather than a* switch(difficulty) somewhere, so the whole ladder can be read, tuned and measured in one place.*- * Nothing in here may exceed the AI's honest baseline - the top rung IS the baseline and the- * lower rungs are handicaps on its *decisions*. If a field ever appears that multiplies income,- * build rate, vision or unit stats, the design has drifted. */+ * Nothing in here may exceed the AI's baseline - the top rung IS the baseline and the lower rungs+ * are handicaps on its *decisions*. The double earnings (Player::earnMoney) are outside this table+ * and the same on every rung. If a field ever appears that multiplies income, build rate, vision+ * or unit stats per rung, the design has drifted. *///-------------------------------------------------------------------------------------------------struct AIDifficultyProfile{diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 8bcde2a4b..58d4bd66f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -2777,8 +2777,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim, Real raif( bounty ){- getMoney()->deposit( bounty );- m_scoreKeeper.addMoneyEarned( bounty );+ bounty = earnMoney( bounty );// Display cash income floating over the recipient - but not to an enemy of a killer it cannot see,// or the number gives the stealthed unit away. Client display only, the deposit above is logic.@@ -3592,9 +3591,23 @@ UnsignedInt IncomeAllyShare( UnsignedInt amount, Int sharers )return sharers > 1 ? amount / sharers : 0;}+UnsignedInt EarnedAmount( UnsignedInt amount, Bool earnerIsSkirmishAI, Bool recipientIsSkirmishAI )+{+ return earnerIsSkirmishAI && recipientIsSkirmishAI ? amount * 2 : amount;+}++UnsignedInt Player::earnMoney( UnsignedInt amount )+{+ const Bool skirmishAI = isSkirmishAIPlayer();+ const UnsignedInt earned = EarnedAmount( amount, skirmishAI, skirmishAI );+ m_money.deposit( earned );+ m_scoreKeeper.addMoneyEarned( earned );+ return earned;+}+/* An ally is a playable side still in the match that both ends call allied. The walk is in playerlist order, which every machine holds alike, so the split is the same in a network game. */-void Player::earnIncome( UnsignedInt amount, Bool fromTechBuilding )+UnsignedInt Player::earnIncome( UnsignedInt amount, Bool fromTechBuilding ){Player *allies[ MAX_PLAYER_COUNT ];Int allyCount = 0;@@ -3611,15 +3624,17 @@ void Player::earnIncome( UnsignedInt amount, Bool fromTechBuilding )}const UnsignedInt allyShare = IncomeAllyShare( amount, allyCount + 1 );+ const Bool skirmishAI = isSkirmishAIPlayer();+ UnsignedInt paid = 0;for ( Int i = 0; i < allyCount; ++i ){- allies[ i ]->getMoney()->deposit( allyShare );- allies[ i ]->getScoreKeeper()->addMoneyEarned( allyShare );+ const UnsignedInt cut = EarnedAmount( allyShare, skirmishAI, allies[ i ]->isSkirmishAIPlayer() );+ allies[ i ]->getMoney()->deposit( cut );+ allies[ i ]->getScoreKeeper()->addMoneyEarned( cut );+ paid += cut;}- const UnsignedInt ownShare = amount - allyShare * allyCount;- m_money.deposit( ownShare );- m_scoreKeeper.addMoneyEarned( ownShare );+ return paid + earnMoney( amount - allyShare * allyCount );}// one object: itself if it is a unit, and whatever units it has queued, however many each entry makesdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/MoneyCrateCollide.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/MoneyCrateCollide.cppindex 65d11f332..56098a90b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/MoneyCrateCollide.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/MoneyCrateCollide.cpp@@ -58,8 +58,7 @@ Bool MoneyCrateCollide::executeCrateBehavior( Object *other )money += getUpgradedSupplyBoost(other);- other->getControllingPlayer()->getMoney()->deposit( money );- other->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( money );+ other->getControllingPlayer()->earnMoney( money );//Play a crate pickup sound.AudioEventRTS soundToPlay = TheAudio->getMiscAudio()->m_crateMoney;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyCenterCrateCollide.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyCenterCrateCollide.cppindex 460fe97aa..24e4e952e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyCenterCrateCollide.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyCenterCrateCollide.cpp@@ -143,10 +143,7 @@ Bool SabotageSupplyCenterCrateCollide::executeCrateBehavior( Object *other ){//Steal the cashtargetMoney->withdraw( cash );- objectMoney->deposit( cash );- Player* controller = obj->getControllingPlayer();- if (controller)- controller->getScoreKeeper()->addMoneyEarned( cash );+ const UnsignedInt earned = obj->getControllingPlayer()->earnMoney( cash );//Play the "cash stolen" EVA event if the local player is the victim!if( other && other->isLocallyControlled() )@@ -156,7 +153,7 @@ Bool SabotageSupplyCenterCrateCollide::executeCrateBehavior( Object *other )//Display cash income floating over the about to be deleted saboteur.UnicodeString moneyString;- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), cash );+ moneyString.format( TheGameText->fetch( "GUI:AddCash" ), earned );Coord3D pos;pos.set( obj->getPosition() );pos.z += 20.0f; //add a little z to make it show up above the unit.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyDropzoneCrateCollide.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyDropzoneCrateCollide.cppindex 71f955f49..5aaf6403c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyDropzoneCrateCollide.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SabotageSupplyDropzoneCrateCollide.cpp@@ -153,10 +153,7 @@ Bool SabotageSupplyDropzoneCrateCollide::executeCrateBehavior( Object *other ){//Steal the cashtargetMoney->withdraw( cash );- objectMoney->deposit( cash );- Player* controller = obj->getControllingPlayer();- if (controller)- controller->getScoreKeeper()->addMoneyEarned( cash );+ const UnsignedInt earned = obj->getControllingPlayer()->earnMoney( cash );//Play the "cash stolen" EVA event if the local player is the victim!if( other && other->isLocallyControlled() )@@ -166,7 +163,7 @@ Bool SabotageSupplyDropzoneCrateCollide::executeCrateBehavior( Object *other )//Display cash income floating over the about to be deleted saboteur.UnicodeString moneyString;- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), cash );+ moneyString.format( TheGameText->fetch( "GUI:AddCash" ), earned );Coord3D pos;pos.set( obj->getPosition() );pos.z += 20.0f; //add a little z to make it show up above the unit.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SalvageCrateCollide.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SalvageCrateCollide.cppindex 1316d043a..e3377a6c3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SalvageCrateCollide.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/SalvageCrateCollide.cpp@@ -251,8 +251,7 @@ void SalvageCrateCollide::doMoney( Object *other )if( money > 0 ){- other->getControllingPlayer()->getMoney()->deposit( money );- other->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( money );+ money = other->getControllingPlayer()->earnMoney( money );//Display cash income floating over the crate. Position is me, everything else is them.UnicodeString moneyString;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/CashHackSpecialPower.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/CashHackSpecialPower.cppindex ce82d70da..486021c36 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/CashHackSpecialPower.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/CashHackSpecialPower.cpp@@ -155,12 +155,11 @@ void CashHackSpecialPower::doSpecialPowerAtObject( Object *victim, UnsignedInt c{//Steal the cashtargetMoney->withdraw( cash );- selfMoney->deposit( cash );- self->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( cash );+ const UnsignedInt earned = self->getControllingPlayer()->earnMoney( cash );//Display cash income floating over the blacklotusUnicodeString moneyString;- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), cash );+ moneyString.format( TheGameText->fetch( "GUI:AddCash" ), earned );Coord3D pos;pos.zero();pos.add( self->getPosition() );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cppindex 744004aa9..e64d4965b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp@@ -558,7 +558,7 @@ StateReturnType HackInternetState::update()amount = 1;break;}- owner->getControllingPlayer()->earnIncome( amount, FALSE );+ amount = owner->getControllingPlayer()->earnIncome( amount, FALSE );//Grant the unit some experience for a successful hack.xp->addExperiencePoints( ai->getXpPerCashUpdate() );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cppindex da6d70439..fd34776ef 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp@@ -126,14 +126,13 @@ void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )if(!player || !m_awardInitialCaptureBonus || getAutoDepositUpdateModuleData()->m_initialCaptureBonus <= 0)return;- player->getMoney()->deposit( getAutoDepositUpdateModuleData()->m_initialCaptureBonus );- player->getScoreKeeper()->addMoneyEarned( getAutoDepositUpdateModuleData()->m_initialCaptureBonus );+ const UnsignedInt earned = player->earnMoney( getAutoDepositUpdateModuleData()->m_initialCaptureBonus );//Display cash income floating over the blacklotusif(getAutoDepositUpdateModuleData()->m_initialCaptureBonus > 0){UnicodeString moneyString;- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), getAutoDepositUpdateModuleData()->m_initialCaptureBonus );+ moneyString.format( TheGameText->fetch( "GUI:AddCash" ), earned );Coord3D pos;pos.set( getObject()->getPosition() );pos.z += 10.0f; //add a little z to make it show up above the unit.@@ -173,7 +172,7 @@ UpdateSleepTime AutoDepositUpdate::update( void ){// scores what is actually deposited: this used to score m_depositAmount only, so the// upgraded supply boost never reached the end-game income total.- getObject()->getControllingPlayer()->earnIncome( moneyAmount, getObject()->isKindOf( KINDOF_TECH_BUILDING ) );+ moneyAmount = getObject()->getControllingPlayer()->earnIncome( moneyAmount, getObject()->isKindOf( KINDOF_TECH_BUILDING ) );}// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cppindex 63f2e6c94..2303f4c19 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp@@ -120,7 +120,7 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )if( value > 0){- ownerPlayer->earnIncome( value, FALSE );+ value = ownerPlayer->earnIncome( value, FALSE );if( data->m_grantTemporaryStealthFrames > 0 )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cppindex 59fe5da69..72a8868b6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpecialAbilityUpdate.cpp@@ -1564,10 +1564,7 @@ void SpecialAbilityUpdate::triggerAbilityEffect(){//Steal the cashtargetMoney->withdraw( cash );- objectMoney->deposit( cash );- Player* controller = object->getControllingPlayer();- if (controller)- controller->getScoreKeeper()->addMoneyEarned( cash );+ const UnsignedInt earned = object->getControllingPlayer()->earnMoney( cash );//Play the "cash stolen" EVA event if the local player is the victim!if( target && target->isLocallyControlled() )@@ -1577,7 +1574,7 @@ void SpecialAbilityUpdate::triggerAbilityEffect()//Display cash income floating over the blacklotusUnicodeString moneyString;- moneyString.format( TheGameText->fetch( "GUI:AddCash" ), cash );+ moneyString.format( TheGameText->fetch( "GUI:AddCash" ), earned );Coord3D pos;pos.set( object->getPosition() );pos.z += 20.0f; //add a little z to make it show up above the unit.diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 189299ac7..4e72c9331 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -2316,6 +2316,19 @@ TEST(income_sharing_splits_evenly_and_keeps_the_remainder)CHECK_EQ( IncomeAllyShare( 200, 1 ), 0u );}+/* Player.cpp: a skirmish computer earns double, and the doubling stays between computers. */+TEST(skirmish_ai_earnings_double_only_between_computers)+{+ /* its own supply run, or its cut going to a computer ally */+ CHECK_EQ( EarnedAmount( 200, TRUE, TRUE ), 400u );+ /* a human ally's cut of a computer's income */+ CHECK_EQ( EarnedAmount( 200, TRUE, FALSE ), 200u );+ /* a computer ally's cut of a human's income */+ CHECK_EQ( EarnedAmount( 200, FALSE, TRUE ), 200u );+ /* a human's own */+ CHECK_EQ( EarnedAmount( 200, FALSE, FALSE ), 200u );+}+/* ExperienceTracker.cpp: a kill's experience split by the damage each attacker dealt. */TEST(kill_xp_splits_by_damage_and_the_killing_blow_keeps_the_remainder){