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): keep a guarding deployed unit set up between kills

Olcay Seygan8f20bd92d62f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1238a3480..56995d96c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1104,6 +1104,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
## Twenty-two-year-old bugs, found by testing
+- A Nuke Cannon on guard stays deployed between targets. After every kill it packed up to drive back to the spot it was already standing on, then set up again, so a guarding cannon spent most of a fight folding and unfolding: four Technicals driven into its range one after another cost it four pack-ups and four set-ups, and now cost it none. It still packs up for a move order or a target out of reach. The Sentry Drone guards the same way. Replays recorded before this change play out differently.
- Pressing Continue after a campaign mission goes straight to the next one. The main menu used to wake up behind the score screen on the way out, show its buttons and start loading its own background battle, so the menu sat on screen over the next mission's load.
- The main menu no longer opens with a man screaming. The battle behind it is staged the way EA laid it out: Jarmen Kell sits on the cliff over the GLA infantry as scenery, and the extra reach high ground gives in a match let his rifle hit them from nearly twice its range a quarter of a second after the menu came up. High ground adds nothing behind the menu now, so the first soldier falls about six seconds in, under the battleship's shells, as he always did. Soldiers' death cries on the battlefield also sit back at their own volume; the boost that lifts your units' replies over the guns had been catching them too.
- A civilian car no longer drives into your base in the first minute of every game. A map's civilians are owned by a computer player like any other, and the scouting pass looks for anything of that player's that can drive - so it was picking a parked car out of the scenery and sending it to a start position. A side with no faction and no build list has nothing to learn from the map and does not scout.
diff --git a/GeneralsMD/Code/Data/Scenarios/deployguard.txt b/GeneralsMD/Code/Data/Scenarios/deployguard.txt
new file mode 100644
index 000000000..2fa328dae
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/deployguard.txt
@@ -0,0 +1,24 @@
+# Does a guarding Nuke Cannon stay deployed between kills?
+#
+# One Nuke Cannon put on guard where it stands, and a GLA Technical driven into its range every
+# twenty seconds. Each kill used to send the guard back to its post through a path request, which
+# DeployStyleAIUpdate read as a move and packed the cannon up for, so it unpacked again for every
+# target. Fixed, the log has one deploy and no undeploy after the guard order.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 1 2 small -autoskirmish 2 -takeover
+# -side 0 FactionChina -side 1 FactionGLA -seed 1 -maxframes 5400
+# -scenario deployguard -logPrefix deployguard_
+#
+# See mobstress.txt for the line grammar.
+
+30 spawn 0 ChinaVehicleNukeLauncher 1 700 500
+60 shiftguard 0 ChinaVehicleNukeLauncher 700 500 400
+
+600 spawn 1 GLAVehicleTechnical 1 1000 500
+1200 spawn 1 GLAVehicleTechnical 1 1000 540
+1800 spawn 1 GLAVehicleTechnical 1 1000 460
+2400 spawn 1 GLAVehicleTechnical 1 1000 500
+
+2690 tally 1 GLAVehicleTechnical*
+2690 tally 0 ChinaVehicleNukeLauncher
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
index 97c83e48c..b51dcafdd 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIGuard.h
@@ -227,6 +227,7 @@ public:
AIGuardReturnState( StateMachine *machine ) : AIInternalMoveToState( machine, "AIGuardReturn" )
{
m_nextReturnScanTime = 0;
+ m_stayedAtPost = FALSE;
}
virtual Bool isAttack() const { return FALSE; }
virtual StateReturnType onEnter( void );
@@ -239,6 +240,7 @@ protected:
virtual void loadPostProcess();
private:
UnsignedInt m_nextReturnScanTime;
+ Bool m_stayedAtPost; ///< onEnter skipped the move, so there is no move for onExit to end
};
EMPTY_DTOR(AIGuardReturnState)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
index bc705f53d..bef5b1d05 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuard.cpp
@@ -678,6 +678,19 @@ StateReturnType AIGuardReturnState::onEnter( void )
{
TheAI->pathfinder()->adjustDestination(getMachineOwner(), ai->getLocomotorSet(), &m_goalPosition);
}
+
+ // A deployed unit (Nuke Cannon, Sentry Drone) that is still standing at its post has nothing
+ // to return to. Asking for a path anyway made DeployStyleAIUpdate pack it up after every kill,
+ // drive nowhere, then unpack again on guard idle.
+ const Coord3D *pos = getMachineOwner()->getPosition();
+ Real dx = m_goalPosition.x - pos->x;
+ Real dy = m_goalPosition.y - pos->y;
+ m_stayedAtPost = getMachineOwner()->testStatus(OBJECT_STATUS_DEPLOYED) && dx*dx + dy*dy <= 4*PATHFIND_CELL_SIZE_F*PATHFIND_CELL_SIZE_F;
+ if (m_stayedAtPost)
+ {
+ return STATE_SUCCESS;
+ }
+
setAdjustsDestination(true);
return AIInternalMoveToState::onEnter();
}
@@ -700,6 +713,8 @@ StateReturnType AIGuardReturnState::update( void )
//--------------------------------------------------------------------------------------
void AIGuardReturnState::onExit( StateExitType status )
{
+ if (m_stayedAtPost)
+ return;
AIInternalMoveToState::onExit( status );
}