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 troop crawler squads fighting and moving

Olcay Seygana1a3b4d3b5e9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 302362948..cf0ac9cf5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,7 +37,9 @@ found and fixed — EA's own, not port damage.**
- A unit turns onto whatever is actually shooting it, then resumes the advance.
- Ctrl on the attack-move click no longer shells the ground instead.
- Troop Crawlers wait for their squad to climb back in, up to ten seconds.
+- One man who cannot get back aboard no longer parks the Crawler for the rest of the attack move.
- Their squad stays out until the area is clear, instead of piling back in after every kill.
+- "Clear" now means as far as the men can shoot, so they finish the enemies in front of them.
- Every man aboard gets out to fight; nobody sits out the battle waiting to be patched up.
- A Crawler that has lost its whole squad carries on with your order instead of idling.
- Attack-move state is saved now, instead of coming back as random memory.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h
index 126c48142..27592b5b6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h
@@ -105,6 +105,7 @@ public:
void reset();
Bool isAssaultAreaClear() const; //Nothing hostile left near the transport?
void retrieveMembers();
+ void releaseStragglers();
void giveFinalOrders();
protected:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp
index dc8da86fe..043be49ad 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp
@@ -81,6 +81,16 @@ Bool AssaultTransport_waitingForBoarding( Bool membersOutside, UnsignedInt frame
return membersOutside && framesRemaining > 0;
}
+//-------------------------------------------------------------------------------------------------
+/** Did the boarding wait just run out on somebody who is still outside?
+ * Asked before the countdown ticks, so 1 is the last frame of the wait. The wait used to be
+ * re-armed the moment it hit zero - a man who could not path back in kept the transport standing
+ * there for good, ignoring the attack move. */
+Bool AssaultTransport_boardingWaitJustExpired( Bool membersOutside, UnsignedInt framesRemaining )
+{
+ return membersOutside && framesRemaining == 1;
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
@@ -379,6 +389,12 @@ UpdateSleepTime AssaultTransportAIUpdate::update( void )
{
aiIdle( CMD_FROM_AI );
}
+ if( AssaultTransport_boardingWaitJustExpired( membersOutside, m_framesRemaining ) )
+ {
+ //He is never getting back in. Hand him the order himself instead of arming the
+ //wait again next frame, which held the transport still for good.
+ releaseStragglers();
+ }
m_framesRemaining--;
}
else
@@ -449,6 +465,16 @@ UpdateSleepTime AssaultTransportAIUpdate::update( void )
return UPDATE_SLEEP_NONE;
}
+//-------------------------------------------------------------------------------------------------
+/** How far around a unit do we look for someone still worth fighting?
+ * At least as far as that unit can shoot. The INI's ClearRangeRequiredToContinueAttackMove is
+ * shorter than an infantry rifle, so the men used to kill the one enemy they were deployed for
+ * and climb straight back in with the next one standing in plain sight and well in range. */
+Real AssaultTransport_clearScanRange( Real iniRange, Real weaponRange )
+{
+ return weaponRange > iniRange ? weaponRange : iniRange;
+}
+
//-------------------------------------------------------------------------------------------------
/** Anything alive and hostile to the transport within range of this object? */
static Bool areaClearAround( const Object *around, const Object *transport, Real range )
@@ -458,7 +484,7 @@ static Bool areaClearAround( const Object *around, const Object *transport, Real
PartitionFilterSameMapStatus filterMapStatus( transport );
PartitionFilter *filters[] = { &filterRelationship, &filterAlive, &filterMapStatus, NULL };
- return ThePartitionManager->getClosestObject( around, range, FROM_CENTER_2D, filters ) == NULL;
+ return ThePartitionManager->getClosestObject( around, AssaultTransport_clearScanRange( range, around->getLargestWeaponRange() ), FROM_CENTER_2D, filters ) == NULL;
}
//-------------------------------------------------------------------------------------------------
@@ -511,6 +537,23 @@ void AssaultTransportAIUpdate::retrieveMembers()
}
}
+//-------------------------------------------------------------------------------------------------
+/** The boarding wait ran out with men still on the ground. Give them the transport's own order so
+ * they walk it themselves; a player-sourced order also drops them from the member list on the next
+ * update, which is what lets the transport get on with the attack move. */
+void AssaultTransportAIUpdate::releaseStragglers()
+{
+ for( int i = 0; i < m_currentMembers; i++ )
+ {
+ Object *member = TheGameLogic->findObjectByID( m_memberIDs[ i ] );
+ AIUpdateInterface *ai = member ? member->getAI() : NULL;
+ if( member && ai && !member->isContained() )
+ {
+ ai->aiAttackMoveToPosition( &m_attackMoveGoalPos, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
+ }
+ }
+}
+
//-------------------------------------------------------------------------------------------------
void AssaultTransportAIUpdate::giveFinalOrders()
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 81b9a6ab2..c66cef1d3 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -831,6 +831,44 @@ TEST(troop_crawler_waits_for_boarding_but_not_forever)
CHECK( !AssaultTransport_waitingForBoarding( false, 300 ) );
}
+/* AssaultTransportAIUpdate.cpp: the ten second wait was re-armed the frame it hit zero, so one man
+ who could not path back aboard parked the crawler on the spot and it never resumed the attack
+ move. The last frame of the wait now cuts the stragglers loose instead. */
+extern Bool AssaultTransport_boardingWaitJustExpired( Bool membersOutside, UnsignedInt framesRemaining );
+
+TEST(troop_crawler_gives_up_on_a_man_who_cannot_board)
+{
+ /* last frame of the wait, somebody still on the ground: let him go and drive on. */
+ CHECK( AssaultTransport_boardingWaitJustExpired( true, 1 ) );
+
+ /* still time on the clock: keep waiting. */
+ CHECK( !AssaultTransport_boardingWaitJustExpired( true, 2 ) );
+ CHECK( !AssaultTransport_boardingWaitJustExpired( true, 300 ) );
+
+ /* no wait running - never let go of a squad we are not waiting on. */
+ CHECK( !AssaultTransport_boardingWaitJustExpired( true, 0 ) );
+
+ /* everybody is aboard: nobody to release. */
+ CHECK( !AssaultTransport_boardingWaitJustExpired( false, 1 ) );
+}
+
+/* AssaultTransportAIUpdate.cpp: the "is the fight over?" scan used the raw INI range (50), which is
+ shorter than the rifles the men are carrying - they killed the one enemy they were deployed for
+ and boarded again with the next one standing in range, unshot. */
+extern Real AssaultTransport_clearScanRange( Real iniRange, Real weaponRange );
+
+TEST(troop_crawler_scans_at_least_as_far_as_its_troops_shoot)
+{
+ /* a rifle outranges the INI knob: look as far as the man can shoot. */
+ CHECK_NEAR( AssaultTransport_clearScanRange( 50.0f, 150.0f ), 150.0f, 0.001f );
+
+ /* the knob is the wider of the two (a modded value): honour it. */
+ CHECK_NEAR( AssaultTransport_clearScanRange( 200.0f, 150.0f ), 200.0f, 0.001f );
+
+ /* no weapon at all - getLargestWeaponRange returns -1; never scan a negative radius. */
+ CHECK_NEAR( AssaultTransport_clearScanRange( 50.0f, -1.0f ), 50.0f, 0.001f );
+}
+
/* AIStates.cpp: an attack move leashes a human player's ground unit so a target
that backs away cannot walk it off the order. Aircraft must be exempt: they
acquire out to weapon range, which is far beyond the leash, so they broke it on