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): count a scud storm's rebuild hole against the allowance

Olcay Seygan742252847bb5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c99079e0..be0204ede 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -982,6 +982,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.
- 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.
diff --git a/GeneralsMD/Code/Data/Scenarios/swhole.txt b/GeneralsMD/Code/Data/Scenarios/swhole.txt
new file mode 100644
index 000000000..e8aedd1db
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/swhole.txt
@@ -0,0 +1,42 @@
+# Superweapon allowance and the Scud Storm's rebuild hole.
+#
+# GLA holds four finished Stinger Sites, which pay for one superweapon, and one Scud Storm that
+# spends it. Overlords knock the storm down; it leaves a hole that sends a worker to rebuild it
+# 20 seconds later. Placement clicks for a second storm land inside those 20 seconds. The rule
+# says one superweapon for four defences, so the click must be refused: the hole still holds the
+# storm it is about to put back. Read the GLAScudStorm tallies from frame 360 on: 0 alive until
+# the hole's rebuild starts and 1 after it is the rule kept; 1 alive at 360 and 2 at the end is the
+# hole letting a second storm through.
+#
+# The Overlords are turned on the palace at 226, the frame after the storm falls, or they shoot the
+# hole down as well. It still drops to about 100 of its 500 from the shells already in the air.
+# Before the fix this ran to 2 storms at 900 and 2400 on four towers; after it, 0 at 360 and 1 at
+# the end.
+#
+# generals.exe -headless -quickstart -noshellmap -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionGLA -side 1 FactionChina -seed 7 -maxframes 2400
+# -scenario swhole -logPrefix swhole_
+
+10 spawn 0 GLAStingerSite 4 start0:-350:-150 80
+10 spawn 0 GLAPalace 1 start0:-200:150
+10 spawn 0 GLAScudStorm 1 start0:250:250
+10 spawn 1 ChinaTankOverlord 12 start0:250:450 40
+30 tally 0 GLAStingerSite
+30 tally 0 GLAScudStorm
+40 attack 1 ChinaTankOverlord 0 GLAScudStorm
+200 tally 0 GLAScudStorm
+226 attack 1 ChinaTankOverlord 0 GLAPalace
+240 tally 0 GLAHoleScudStorm
+260 tally 0 GLAHoleScudStorm
+280 tally 0 GLAHoleScudStorm
+300 tally 0 GLAScudStorm
+300 tally 0 GLAHoleScudStorm
+330 construct 0 GLAScudStorm start0:-150:-450
+340 construct 0 GLAScudStorm start0:350:-350
+360 tally 0 GLAScudStorm
+400 move 1 ChinaTankOverlord start1
+900 tally 0 GLAScudStorm
+900 tally 0 GLAHoleScudStorm
+2390 tally 0 GLAScudStorm
+2390 tally 0 GLAHoleScudStorm
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index dcee48b7c..34b306c11 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -162,6 +162,10 @@ 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 );
+// A GLA superweapon knocked down leaves a hole whose worker puts it back 20 seconds later at no
+// cost. Until that rebuild stands the hole counts as the superweapon, or a second one could go
+// 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 );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 933628ff0..39b321008 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -102,6 +102,7 @@
#include "GameLogic/Module/SupplyTruckAIUpdate.h"
#include "GameLogic/Module/BattlePlanUpdate.h"
#include "GameLogic/Module/ProductionUpdate.h"
+#include "GameLogic/Module/RebuildHoleBehavior.h"
#include "GameLogic/Module/TransportContain.h"
#include "GameLogic/VictoryConditions.h"
@@ -3303,7 +3304,8 @@ Bool SuperweaponNeedsDefenses( const AsciiString &buildingName, Bool proRules, I
}
/* A defence counts once it stands finished, so a foundation put down and cancelled never unlocks
- anything. A superweapon counts from its foundation, so two cannot be placed on one allowance. */
+ anything. A superweapon counts from its foundation, so two cannot be placed on one allowance,
+ and a GLA one knocked down still counts while its hole waits to put it back for nothing. */
struct SuperweaponDefenseCount
{
Int defenses;
@@ -3321,6 +3323,23 @@ static void countSuperweaponDefenses( Object *obj, void *userData )
else if ( obj->isKindOf( KINDOF_FS_BASE_DEFENSE ) && !obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION )
&& DefenseCountsForSuperweapons( obj->getTemplate()->friend_getBuildCost() ) )
count->defenses++;
+ else if ( obj->isKindOf( KINDOF_REBUILD_HOLE ) )
+ {
+ RebuildHoleBehaviorInterface *hole = RebuildHoleBehavior::getRebuildHoleBehaviorInterfaceFromObject( obj );
+ if ( hole == NULL )
+ return;
+
+ const ThingTemplate *rebuild = hole->getRebuildTemplate();
+ const Object *standing = TheGameLogic->findObjectByID( hole->getReconstructedBuildingID() );
+ if ( RebuildHoleHoldsSuperweapon( rebuild && rebuild->isKindOf( KINDOF_FS_SUPERWEAPON ),
+ standing && !standing->isEffectivelyDead() ) )
+ count->superweapons++;
+ }
+}
+
+Bool RebuildHoleHoldsSuperweapon( Bool rebuildsSuperweapon, Bool rebuildStanding )
+{
+ return rebuildsSuperweapon && !rebuildStanding;
}
//=============================================================================
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 5bf06a9b0..d737c3ead 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -14723,6 +14723,12 @@ TEST(four_finished_defenses_pay_for_each_superweapon)
CHECK( !DefenseCountsForSuperweapons( 0 ) );
CHECK( DefenseCountsForSuperweapons( 800 ) );
+ // a Scud Storm's hole holds its storm until the rebuild stands, then the rebuild counts itself;
+ // a Stinger Site's hole holds nothing
+ CHECK( RebuildHoleHoldsSuperweapon( TRUE, FALSE ) );
+ 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 ) );