Skip to content

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.

fix(gameengine): superweapon towers rule binds computer players only

Olcay Seygan371dfdb2817d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f1404c97..72f583b52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -182,7 +182,7 @@ found and fixed — EA's own, not port damage.**
- USA's Chinooks stop collecting over the command center. When the pile beside a supply centre ran out, its Chinooks flew home and hovered, and the computer went on buying new ones for its other centres while those sat idle. It only looked for an idle gatherer when a pile stood right next to the centre, a fraction of how far a Chinook looks. An idle gatherer is now sent to any of its supply centres with a pile inside that gatherer's own range, and nothing new is bought while one stands idle beside a pile that has no room for it.
- It keeps its lights on, and keeps them out of reach. Its plan carries a fixed number of power plants and nothing ever adds one, so a raid that took two of them left the base underpowered - radar dark, base defences off, superweapon clock stopped - until a rebuild timer came round and put the new plant back on the spot the raid already knew the way to. It now buys a plant when the margin gets thin rather than when the meter reads zero, and puts it on the far side of the base from whoever it is fighting.
- Spare cash also buys a gun on the side the trouble comes from. Production and income go up around the middle of the base, the power goes behind it, and base defences go out in front, so money that keeps arriving thickens the base in the order a base wants to be thick in. Front means towards the nearest enemy, which is not the same as the one it has decided to attack - that one can be across the map, and a wall built facing it has its back to the neighbour. The walls grow with the army. One gun every minute and a half, never more than ten, used to be the rule; now the computer may stand one gun for every four fighting units it has, so a big army comes home to a fortress and a beaten one rebuilds its tanks before its bunkers. Letting it buy guns on every pass instead was tried first: 241 guns over twelve four-player matches, and they ate the army, down to 60 kills a match from 73. Tied to the army, 71 guns, and the army is the biggest of any version tried, 78 kills a match.
-- Hard builds its superweapon as soon as it can pay for one and has the guns to stand it on, and then another. Its scripts held the first one back behind a clock that ran for twelve and a half minutes, seven and a half if you had built your own tech building first, and then allowed exactly one: a player who took on seven Hard computers at once saw a single nuke all match. There is no clock now. The tech building that unlocks it goes up first, and the superweapon follows once the money is in the bank and four of its guns stand finished, the rule every player keeps (see the lobby section). More follow as the base grows, one for every four guns, so a computer holding twenty guns can stand five superweapons. Before that rule it put its first particle cannon up at 4.3 minutes on Twilight Flame and its first nuke at 4.9, without a gun to its name. Over 24 matches between two Hard computers on the same map, the first nuke now goes up at 6.2 minutes as a rule, anywhere from 4.4 to 9.8, and the first Particle Cannon at 7.4. The Scud Storm comes last at 7.6 but never later than 8.7, and every GLA side had one inside ten minutes, where 4 of the 32 China and USA sides were still waiting for theirs. The lobby's superweapon limit and Pro Rules still apply to the computer exactly as they do to you.
+- Hard builds its superweapon as soon as it can pay for one and has the guns to stand it on, and then another. Its scripts held the first one back behind a clock that ran for twelve and a half minutes, seven and a half if you had built your own tech building first, and then allowed exactly one: a player who took on seven Hard computers at once saw a single nuke all match. There is no clock now. The tech building that unlocks it goes up first, and the superweapon follows once the money is in the bank and four of its guns stand finished, a rule only the computer plays by (see the lobby section). More follow as the base grows, one for every four guns, so a computer holding twenty guns can stand five superweapons. Before that rule it put its first particle cannon up at 4.3 minutes on Twilight Flame and its first nuke at 4.9, without a gun to its name. Over 24 matches between two Hard computers on the same map, the first nuke now goes up at 6.2 minutes as a rule, anywhere from 4.4 to 9.8, and the first Particle Cannon at 7.4. The Scud Storm comes last at 7.6 but never later than 8.7, and every GLA side had one inside ten minutes, where 4 of the 32 China and USA sides were still waiting for theirs. The lobby's superweapon limit and Pro Rules still apply to the computer exactly as they do to you.
- Hard trains more builders when it has work for them. It only ever made a new dozer after losing all of them, so it played every match on the two it had, and every building it bought queued behind those two. On Twilight Flame a third of the China Tank computers never got round to a war factory, never sent an attack, and ended up sitting in a ring of bunkers on a pile of cash. Now, with money in the bank and every dozer busy, it trains another, up to four. Over six four-player matches on that map, every computer built its war factories, the attack waves went from 39 to 82, and each one spent half as much again.
- Hard no longer rebuilds its factories inside your base. A busy computer puts its next war factory beside its newest expansion, and it remembered that expansion forever: after you destroyed the supply centre there, even one it had built right next to your base, it kept putting the factory back up on the same spot. It now only builds beside an expansion it still holds, and only one nearer its own base than yours.
- Hard keeps its lights on. It asked for a new power plant before running out, and the request then sat in a queue behind everything else its plan wanted: one China waited 95 seconds for a plant with 26,000 in the bank, every builder busy, and went dark halfway. A plant now jumps that queue once the margin is thin, a busy builder is taken off whatever it is doing to put it up, and while the base is dark the computer buys nothing else. Over eight four-player matches the time its bases spent without power fell by a third, from 42 minutes to 28 across all of them.
@@ -996,7 +996,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Every lobby now has two tabs over the bottom panel, Info and Lobby Settings, and the one you are looking at is lettered green (online, it is the greyed-out one). The host's settings live on the settings page; the map details in skirmish and the chat log in a network game come back the moment you tab away from it.
- The skirmish and LAN rooms are laid out again, on one grid. Each column heading sits over its own column instead of up to 18 pixels to the right of it. The seats and the settings page underneath them start and stop at the same two edges, and Play Game stands under the map and your win record on the right-hand pair. The open tab used to be lettered in a grey that measured about 2 to 1 against the panel and read as a button that was switched off. Play Game waits at the bottom right and the button that leaves the room sits at the bottom left, as far from it as the screen allows. With all eight seats taken, "USA Super Weapon General" still fits in its box. The online room keeps its old layout.
-- A GLA player could stand one superweapon more than his towers paid for. A Scud Storm knocked down leaves a hole, and 20 seconds later a worker climbs out of it and builds the storm again for free. Those 20 seconds the storm was off the books, so a new one went down on the same four towers and then the hole put the old one back: two storms on four Stinger Sites, where every other side stopped at one. The hole now counts as the storm it is about to rebuild, for you and for the computer alike. Replays where a superweapon went down while a storm's hole was waiting play out differently.
+- A GLA computer could stand one superweapon more than its towers paid for. A Scud Storm knocked down leaves a hole, and 20 seconds later a worker climbs out of it and builds the storm again for free. Those 20 seconds the storm was off the books, so a new one went down on the same four towers and then the hole put the old one back: two storms on four Stinger Sites, where every other side stopped at one. The hole now counts as the storm it is about to rebuild. Replays where a computer's superweapon went down while a storm's hole was waiting play out differently.
- Skirmish keeps starting cash and the game speed there. LAN and online keep starting cash next to peace time and the superweapon rule. Before this they were scattered around whatever space each of the three lobby screens happened to have left over.
- Game speed in the skirmish room is a dropdown now: x0.5, x0.75, x1, x1.5 or x2. The old slider read out a frame rate nobody plays by, and its last notch read "--" and started the match at a thousand game frames a second, which no machine can play and every machine tried to. A speed saved by the old slider comes back as the nearest of the five.
- The speed can change during a skirmish or a mission, too, from the console: `speed 150` for half again as fast, `speed` alone to ask, `speed reset` for normal. It used to live on numpad plus and minus, where the reset landed on one and a half times normal speed and the readout gave a number of frames nobody could read as a speed. Those keys are free again. Network games keep the speed the host picked.
@@ -1008,7 +1008,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- No Superweapons can be picked. The dropdown sits low on the settings page, and its last row hung past the bottom edge of the panel: it drew, but a click on it went to nobody and the list stayed on whatever it said before. Any dropdown row past the edge of its panel takes the click now.
- The USA Superweapon General is the exception to both, because the rule that reads as a handicap to everyone else reads as a deletion to him: three superweapons of his own are what he pays for weaker tanks, weaker infantry and a worse air force with. Under Limit he keeps four of each of his. Under No he keeps one. Play him against a lobby that has banned superweapons and you are playing the army you paid for, not an empty base.
- No Superweapons leaves China its upgrades. The Nuclear Missile silo is where China buys Uranium Shells, Nuclear Tanks and Neutron Shells, so banning it took them off every China general. Each player may now put up one silo under No, the Superweapon General too, and its missile never launches. Nothing treats it as a superweapon either: no fire button, no shortcut, no countdown on anybody's screen, no announcer telling the enemy one is up, and the doors stay shut. The Particle Cannon and the Scud Storm are still banned. A replay of a No Superweapons match recorded before this, where a silo went up or a missile flew, will not play back the same.
-- Every superweapon is paid for in base defences now. Four finished defences let you put up one, eight let you put up two, and with fewer than four the buttons stay grey. Your Particle Cannons, silos and Scud Storms all count against one allowance, and a superweapon counts from the moment its foundation goes down, so you cannot start two on the same four towers. A defence counts only once it is finished: a scaffold put down and cancelled unlocks nothing. Tunnel Networks and Propaganda Towers count as defences; the tunnel a Sneak Attack drops for free does not. The one exception is the silo whose missile never launches, under No Superweapons or Pro Rules: it is only there for China's upgrades, so it goes up without a single tower. Lose your towers and the superweapons you have keep standing, but the next one waits. The lobby's limit still holds on top of this, and the computer plays by the same rule. Campaign and Generals Challenge missions are left as they were. Replays recorded before this change play out differently.
+- The computer pays for every superweapon in base defences. Four finished defences let it put up one, eight let it put up two, and with fewer than four it waits. Its Particle Cannons, silos and Scud Storms all count against one allowance, and a superweapon counts from the moment its foundation goes down, so it cannot start two on the same four towers. A defence counts only once it is finished: a scaffold put down and cancelled unlocks nothing. Tunnel Networks and Propaganda Towers count as defences; the tunnel a Sneak Attack drops for free does not. The silo whose missile never launches, under No Superweapons or Pro Rules, is only there for China's upgrades and goes up without a single tower. Lose its towers and the superweapons it has keep standing, but the next one waits. You are not asked for towers at all: for a human player the lobby's limit and Pro Rules are the whole rule, as they were before the towers rule came in, and the buttons never grey out for want of defences. Campaign and Generals Challenge missions are left as they were. A replay from a build that held humans to the towers too plays out differently if a human's superweapon was turned away in it.
- The tick box was one number for everybody, which is why it could only ever say yes or no. A ticked box in a settings file from an older build reads back as No Superweapons.
## Pro Rules, in every network game
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index 34b306c11..af04093c8 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -153,8 +153,9 @@ Int UnitLimitPerPlayer( Int nonObserverPlayers );
// Whether a build that adds unitsItAdds (a transport and its payload) goes past the share. 0 is no cap.
Bool UnitCapRefuses( Int unitsTowardCap, Int unitsItAdds, UnsignedInt unitCap );
-// Superweapons are paid for in base defences: every DEFENSES_PER_SUPERWEAPON finished defences a
-// player stands allow him one superweapon, counted across every type. Whether one more is refused,
+// A computer player's superweapons are paid for in base defences: every DEFENSES_PER_SUPERWEAPON
+// finished defences it stands allow it one superweapon, counted across every type. A human is held
+// only by the lobby's rule and Pro Rules. Whether one more is refused,
// given the finished defences and the superweapons he already has, foundations included. It sits
// on top of the lobby's rule and never loosens it.
enum { DEFENSES_PER_SUPERWEAPON = 4 };
@@ -167,8 +168,10 @@ Bool DefenseCountsForSuperweapons( Int buildCost );
// down on the same allowance in those 20 seconds and the hole would make it two.
Bool RebuildHoleHoldsSuperweapon( Bool rebuildsSuperweapon, Bool rebuildStanding );
// The silo whose missile No Superweapons or Pro Rules silences is a shop for China's upgrades, not a
-// weapon, and is not asked for defences.
-Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, Int superweaponRestriction );
+// weapon, and is not asked for defences. Neither is anything a human builds: computerPlayer is
+// getPlayerType() == PLAYER_COMPUTER, which every machine and the replay hold alike.
+Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, Int superweaponRestriction,
+ Bool computerPlayer );
// The lobby's income sharing, an IncomeSharing from GameInfo.h: whether a payment is split in this
// match, and each ally's cut when it is split evenly between sharers players. The earner keeps what
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 39b321008..9f9f8bdc1 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -3297,9 +3297,10 @@ Bool DefenseCountsForSuperweapons( Int buildCost )
return buildCost > 0;
}
-Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, Int superweaponRestriction )
+Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, Int superweaponRestriction,
+ Bool computerPlayer )
{
- return !( ProRulesExemptSuperweapon( buildingName )
+ return computerPlayer && !( ProRulesExemptSuperweapon( buildingName )
&& SuperweaponMissileSilenced( SPECIAL_NEUTRON_MISSILE, proRules, superweaponRestriction ) );
}
@@ -3448,10 +3449,11 @@ Bool Player::canBuildMoreOfType( const ThingTemplate *whatToBuild, Int unitsPerO
maxSimultaneousOfType = (UnsignedInt)cap;
}
- // the defence allowance holds in skirmish and network matches and their replays; a campaign or
- // Generals Challenge mission was laid out without it and keeps EA's rules
+ // the defence allowance binds computer players in skirmish and network matches and their replays;
+ // humans, and a campaign or Generals Challenge mission, keep EA's rules
if ( whatToBuild->isKindOf( KINDOF_FS_SUPERWEAPON ) && TheGameLogic && !TheGameLogic->isInSinglePlayerGame()
- && SuperweaponNeedsDefenses( whatToBuild->getName(), proRules, (Int)TheGameLogic->getSuperweaponRestriction() ) )
+ && SuperweaponNeedsDefenses( whatToBuild->getName(), proRules, (Int)TheGameLogic->getSuperweaponRestriction(),
+ getPlayerType() == PLAYER_COMPUTER ) )
{
SuperweaponDefenseCount count = { 0, 0 };
iterateObjects( countSuperweaponDefenses, &count );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index d89b4bcba..31a2c90ea 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -4810,7 +4810,7 @@ static const Real POWER_SETBACK = 0.75f;
static const Real DEFENSE_STANDOFF = 1.0f;
/** The base grows with the army: one gun allowed per this many fighting units. Superweapons follow
- * the guns by the rule every player keeps, DEFENSES_PER_SUPERWEAPON in Player.h. */
+ * the guns by the computer players' rule, DEFENSES_PER_SUPERWEAPON in Player.h. */
static const Int ARMY_PER_DEFENSE = 4;
/** Dozers a Hard AI trains on its own when every one it has is on a building. */
@@ -5609,7 +5609,7 @@ void AIPlayer::buildAsap( const ThingTemplate *tmpl )
* whole match. The owner's call: no clock. As soon as a dozer can build a superweapon, the money
* is in the bank and DEFENSES_PER_SUPERWEAPON guns stand, the first one goes up. More follow as the
* base grows, one per that many guns, as the guns grow with the army; unrationed, they took the money
- * the army needed. That ration is every player's rule now (Player::canBuildMoreOfType), and the
+ * the army needed. That ration binds computer players only (Player::canBuildMoreOfType), and the
* lobby's superweapon setting and Pro Rules still bind beside it; canMakeUnit asks all three.
* If the tech building it needs is missing, that goes up first, and copies follow once the first
* superweapon is standing, up to AI_TECH_BUILDING_COPIES, so one of them blowing up leaves the tree
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 30eab28b1..7ab20f8b3 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -15099,12 +15099,34 @@ TEST(four_finished_defenses_pay_for_each_superweapon)
CHECK( !RebuildHoleHoldsSuperweapon( TRUE, TRUE ) );
CHECK( !RebuildHoleHoldsSuperweapon( FALSE, FALSE ) );
- // a silo whose missile is silenced sells China's upgrades and asks for no defences
- CHECK( !SuperweaponNeedsDefenses( AsciiString( "ChinaNuclearMissileLauncher" ), FALSE, SUPERWEAPONS_NONE ) );
- CHECK( !SuperweaponNeedsDefenses( AsciiString( "Tank_ChinaNuclearMissileLauncher" ), TRUE, SUPERWEAPONS_ALLOW ) );
- CHECK( SuperweaponNeedsDefenses( AsciiString( "ChinaNuclearMissileLauncher" ), FALSE, SUPERWEAPONS_LIMIT ) );
- CHECK( SuperweaponNeedsDefenses( AsciiString( "SupW_AmericaParticleCannonUplink" ), FALSE, SUPERWEAPONS_NONE ) );
- CHECK( SuperweaponNeedsDefenses( AsciiString( "GLAScudStorm" ), TRUE, SUPERWEAPONS_ALLOW ) );
+ // a computer's silo whose missile is silenced sells China's upgrades and asks for no defences
+ CHECK( !SuperweaponNeedsDefenses( AsciiString( "ChinaNuclearMissileLauncher" ), FALSE, SUPERWEAPONS_NONE, TRUE ) );
+ CHECK( !SuperweaponNeedsDefenses( AsciiString( "Tank_ChinaNuclearMissileLauncher" ), TRUE, SUPERWEAPONS_ALLOW, TRUE ) );
+ CHECK( SuperweaponNeedsDefenses( AsciiString( "ChinaNuclearMissileLauncher" ), FALSE, SUPERWEAPONS_LIMIT, TRUE ) );
+ CHECK( SuperweaponNeedsDefenses( AsciiString( "SupW_AmericaParticleCannonUplink" ), FALSE, SUPERWEAPONS_NONE, TRUE ) );
+ CHECK( SuperweaponNeedsDefenses( AsciiString( "GLAScudStorm" ), TRUE, SUPERWEAPONS_ALLOW, TRUE ) );
+}
+
+/* The defence allowance is the computer's rule only. A human builds a superweapon against the
+ lobby's limit and Pro Rules alone, so no superweapon of his is ever asked for towers, whatever
+ mode the lobby picked. */
+TEST(superweapon_defense_allowance_binds_computer_players_only)
+{
+ const char *const superweapons[] = { "ChinaNuclearMissileLauncher", "SupW_AmericaParticleCannonUplink",
+ "AmericaParticleCannonUplink", "GLAScudStorm" };
+ const Int restrictions[] = { SUPERWEAPONS_ALLOW, SUPERWEAPONS_LIMIT, SUPERWEAPONS_NONE };
+ for ( Int s = 0; s < ARRAY_SIZE( superweapons ); ++s )
+ for ( Int r = 0; r < ARRAY_SIZE( restrictions ); ++r )
+ for ( Int pro = 0; pro < 2; ++pro )
+ CHECK( !SuperweaponNeedsDefenses( AsciiString( superweapons[ s ] ), (Bool)pro, restrictions[ r ], FALSE ) );
+
+ // the same Scud Storm under the same lobby asks a computer for its towers
+ CHECK( SuperweaponNeedsDefenses( AsciiString( "GLAScudStorm" ), FALSE, SUPERWEAPONS_ALLOW, TRUE ) );
+ CHECK( SuperweaponNeedsDefenses( AsciiString( "AmericaParticleCannonUplink" ), FALSE, SUPERWEAPONS_LIMIT, TRUE ) );
+
+ // and for a computer a storm's waiting hole still spends the four towers it stood on
+ CHECK( SuperweaponDefenseCapRefuses( 4, RebuildHoleHoldsSuperweapon( TRUE, FALSE ) ? 1 : 0 ) );
+ CHECK( !SuperweaponDefenseCapRefuses( 4, RebuildHoleHoldsSuperweapon( FALSE, FALSE ) ? 1 : 0 ) );
}
/* The superweapon rule is a mode, and what a mode leaves you depends on who you are playing. The