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.

feat(gameengine): leave sneak attack tunnels out of the superweapon cap

Olcay Seygan67431b13217d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01515d668..e74c5e875 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -933,7 +933,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 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.
+- 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 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 d0ca4d611..dcee48b7c 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -159,6 +159,9 @@ Bool UnitCapRefuses( Int unitsTowardCap, Int unitsItAdds, UnsignedInt unitCap );
// on top of the lobby's rule and never loosens it.
enum { DEFENSES_PER_SUPERWEAPON = 4 };
Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons );
+// Only a defence somebody paid for counts. The Sneak Attack tunnel, its Start and every general's
+// copy are the only FS_BASE_DEFENSE templates with no BuildCost: a power drops them for free.
+Bool DefenseCountsForSuperweapons( Int buildCost );
// 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 );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 64d6f32f9..933628ff0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -3291,6 +3291,11 @@ Bool SuperweaponDefenseCapRefuses( Int finishedDefenses, Int superweapons )
return superweapons >= finishedDefenses / DEFENSES_PER_SUPERWEAPON;
}
+Bool DefenseCountsForSuperweapons( Int buildCost )
+{
+ return buildCost > 0;
+}
+
Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, Int superweaponRestriction )
{
return !( ProRulesExemptSuperweapon( buildingName )
@@ -3313,7 +3318,8 @@ static void countSuperweaponDefenses( Object *obj, void *userData )
SuperweaponDefenseCount *count = (SuperweaponDefenseCount *)userData;
if ( obj->isKindOf( KINDOF_FS_SUPERWEAPON ) )
count->superweapons++;
- else if ( obj->isKindOf( KINDOF_FS_BASE_DEFENSE ) && !obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
+ else if ( obj->isKindOf( KINDOF_FS_BASE_DEFENSE ) && !obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION )
+ && DefenseCountsForSuperweapons( obj->getTemplate()->friend_getBuildCost() ) )
count->defenses++;
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 648457c47..a265d12ef 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -14470,6 +14470,10 @@ TEST(four_finished_defenses_pay_for_each_superweapon)
// losing defences never pulls a standing superweapon down, it only stops the next one
CHECK( SuperweaponDefenseCapRefuses( 4, 2 ) );
+ // a Sneak Attack tunnel costs nothing and buys nothing; a Tunnel Network at 800 does
+ CHECK( !DefenseCountsForSuperweapons( 0 ) );
+ CHECK( DefenseCountsForSuperweapons( 800 ) );
+
// 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 ) );