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): ctrl on an attack move click, and troop crawler re-boarding

Olcay Seyganbce6112de8ec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c38d2dd98..b450eebb4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -93,6 +93,16 @@ What you get now:
whatever it happened to pick — usually the nearest thing — while something else emptied a magazine
into its flank. It now turns onto whatever is actually hurting it, as long as it can reach it, and
goes back to the advance once that is dealt with.
+- **Ctrl on the attack-move click orders the attack-move, not a bombardment of the dirt.** Ctrl is
+ the force-fire key, and while the attack-move cursor was up the click was still being read that
+ way: instead of advancing at a shared pace, the group stood where it was and shelled the ground
+ you clicked. Ctrl now means what the attack-move cursor says it means, and only that.
+- **Troop Crawlers pick their squad back up.** A Troop Crawler on attack-move drops its passengers
+ on whatever it runs into. Once that fight was over the infantry stayed out, jogging along behind
+ the crawler in the open for the rest of the order — arriving at the next fight on foot, scattered,
+ and already in range. Now, when there is nothing left to shoot at, the crawler holds for them to
+ climb back in and then carries on. If someone cannot make it back it waits ten seconds and moves
+ on rather than parking the whole advance.
- **Loading a save does not scramble what your attack-moving units do next.** The count of rounds a
unit had spent on its current fight — which is how the game tells a real firing pass from a failed
approach — was not among the things written into a save file, and on load it came back as whatever
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AssaultTransportAIUpdate.h
index 0499d49aa..ee72c133b 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 isMemberWounded( const Object *member ) const; //Member requires medical attention?
Bool isMemberHealthy( const Object *member ) const; //Member has full health?
+ Bool isAssaultAreaClear() const; //Nothing hostile left near the transport?
void retrieveMembers();
void giveFinalOrders();
Bool isAttackPointless() const;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 099bc31c8..b0a8a8832 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -96,6 +96,24 @@
#define dont_ALLOW_ALT_F4
+//-------------------------------------------------------------------------------------------------
+/**
+ * Is the ctrl key asking for force fire right now?
+ * While the attack move cursor is up, ctrl means "one shared pace" instead (see
+ * issueMoveToLocationCommand), so the targeting code must not read it as force attack - otherwise
+ * ctrl + click on the ground fires at the dirt instead of ordering the attack move.
+ */
+Bool CommandXlat_isForceAttackTargeting( Bool ctrlHeld, Bool attackMoveArmed )
+{
+ return ctrlHeld && !attackMoveArmed;
+}
+
+static Bool isForceAttackTargeting( void )
+{
+ return CommandXlat_isForceAttackTargeting( TheInGameUI->isInForceAttackMode(),
+ TheInGameUI->isInAttackMoveToMode() );
+}
+
#if defined(_DEBUG) || defined(_INTERNAL)
/*non-static*/ Real TheSkateDistOverride = 0.0f;
@@ -887,7 +905,7 @@ GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *
{
msgType = GameMessage::MSG_DO_FORCEMOVETO;
}
- else if( TheInGameUI->isInForceAttackMode() && isForceAttackable )
+ else if( isForceAttackTargeting() && isForceAttackable )
{
msgType = GameMessage::MSG_DO_ATTACK_OBJECT;
}
@@ -1461,7 +1479,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
//a position interaction.
draw = NULL;
obj = NULL;
- } else if (TheInGameUI->isInForceAttackMode() ) {
+ } else if (isForceAttackTargeting() ) {
// setting the drawableInWay to draw will allow us to force attack in the issue move command
// if there is a location to which we should attack.
drawableInWay = draw;
@@ -1714,7 +1732,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
}
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_RESUME_CONSTRUCTION, obj, InGameUI::SELECTION_ANY ) )
{
@@ -1746,7 +1764,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_DOCK_AT,
obj,
InGameUI::SELECTION_ALL ) )
@@ -1784,7 +1802,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
}
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_REPAIR_OBJECT, obj, InGameUI::SELECTION_ANY ) )
{
@@ -1816,7 +1834,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_GET_REPAIRED_AT, obj, InGameUI::SELECTION_ANY ) )
{
@@ -1850,7 +1868,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_GET_HEALED_AT, obj, InGameUI::SELECTION_ANY ) )
{
@@ -1882,7 +1900,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && draw->getObject() && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && draw->getObject() && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_HIJACK_VEHICLE,
draw->getObject(),
InGameUI::SELECTION_ANY ) )
@@ -1907,7 +1925,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_CONVERT_OBJECT_TO_CARBOMB, obj, InGameUI::SELECTION_ANY ) )
{
@@ -1928,7 +1946,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else
}
// ********************************************************************************************
- else if( draw && draw->getObject() && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && draw->getObject() && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_SABOTAGE_BUILDING,
draw->getObject(),
InGameUI::SELECTION_ANY ) )
@@ -1947,7 +1965,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() && canSelectionSalvage(obj) )
+ else if( draw && !isForceAttackTargeting() && canSelectionSalvage(obj) )
{
GameMessage *msg;
@@ -1967,7 +1985,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && !TheInGameUI->isInForceAttackMode() &&
+ else if( draw && !isForceAttackTargeting() &&
TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_ENTER_OBJECT, obj, InGameUI::SELECTION_ANY, true ) )
{
@@ -1988,7 +2006,7 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
} // end else if
// ********************************************************************************************
- else if( draw && (result = TheInGameUI->getCanSelectedObjectsAttack( InGameUI::ACTIONTYPE_ATTACK_OBJECT, obj, InGameUI::SELECTION_ANY, TheInGameUI->isInForceAttackMode() )) == ATTACKRESULT_POSSIBLE )
+ else if( draw && (result = TheInGameUI->getCanSelectedObjectsAttack( InGameUI::ACTIONTYPE_ATTACK_OBJECT, obj, InGameUI::SELECTION_ANY, isForceAttackTargeting() )) == ATTACKRESULT_POSSIBLE )
{
if( type == DO_COMMAND || type == EVALUATE_ONLY )
@@ -3724,7 +3742,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// and what "picked" is we would do a command ... but here we only will generate
// the hint message, *not* the actual command
//
- if (TheInGameUI->isInForceAttackMode()) {
+ if (isForceAttackTargeting()) {
evaluateForceAttack(draw, draw->getPosition(), DO_HINT );
} else {
evaluateContextCommand( draw, draw->getPosition(), DO_HINT );
@@ -3748,7 +3766,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// This message occurs whenever the mouse cursor moves off of a drawable, in which
// case we want to turn off the pick hint.
//
- if (TheInGameUI->isInForceAttackMode()) {
+ if (isForceAttackTargeting()) {
evaluateForceAttack( NULL, &position, DO_HINT );
} else {
evaluateContextCommand( NULL, &position, DO_HINT );
@@ -3835,11 +3853,11 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
|| (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT);
if (isPoint && controllable)
{
- UnsignedInt pickType = getPickTypesForContext( TheInGameUI->isInForceAttackMode() );
+ UnsignedInt pickType = getPickTypesForContext( isForceAttackTargeting() );
Drawable *draw = TheTacticalView->pickDrawable(&msg->getArgument(0)->pixelRegion.lo,
- TheInGameUI->isInForceAttackMode(),
+ isForceAttackTargeting(),
(PickType) pickType);
- if (TheInGameUI->isInForceAttackMode()) {
+ if (isForceAttackTargeting()) {
evaluateForceAttack( draw, &pos, DO_COMMAND );
} else {
evaluateContextCommand( draw, &pos, DO_COMMAND );
@@ -3906,12 +3924,12 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
|| (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT);
if (isPoint && controllable)
{
- UnsignedInt pickType = getPickTypesForContext( TheInGameUI->isInForceAttackMode() );
+ UnsignedInt pickType = getPickTypesForContext( isForceAttackTargeting() );
Drawable *draw = TheTacticalView->pickDrawable(&msg->getArgument(0)->pixelRegion.lo,
- TheInGameUI->isInForceAttackMode(),
+ isForceAttackTargeting(),
(PickType) pickType);
- if (TheInGameUI->isInForceAttackMode()) {
+ if (isForceAttackTargeting()) {
evaluateForceAttack( draw, &pos, DO_COMMAND );
} else {
evaluateContextCommand( draw, &pos, DO_COMMAND );
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 a71d86094..10590c884 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/AssaultTransportAIUpdate.cpp
@@ -49,6 +49,28 @@
//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
#endif
+//How long the transport waits for its troops to board again before it rolls on without them.
+#define FRAMES_TO_WAIT_FOR_BOARDING (10 * LOGICFRAMES_PER_SECOND)
+
+//-------------------------------------------------------------------------------------------------
+/** Should the troops we deployed climb back into the transport?
+ * Only once nobody is still shooting and there is nothing left near us worth shooting at.
+ * Free function with no Object in its signature so a test can pin the rule - the same trick as
+ * AIAttackMove_shouldRetaliate in AIStates.cpp. */
+Bool AssaultTransport_shouldRetrieveMembers( Bool membersOutside, Bool membersFighting, Bool areaClear )
+{
+ return membersOutside && !membersFighting && areaClear;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Does the transport hold still this frame instead of driving on with the attack move?
+ * Only while troops are still outside and the boarding wait has not run out; see
+ * AssaultTransport_shouldRetrieveMembers above. */
+Bool AssaultTransport_waitingForBoarding( Bool membersOutside, UnsignedInt framesRemaining )
+{
+ return membersOutside && framesRemaining > 0;
+}
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
@@ -320,10 +342,63 @@ UpdateSleepTime AssaultTransportAIUpdate::update( void )
}
else
{
- if( m_isAttackMove && getAIStateType() != AI_ATTACK_MOVE_TO )
+ if( m_isAttackMove )
{
- //Continue to move towards the attackmove area.
- aiAttackMoveToPosition( &m_attackMoveGoalPos, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
+ //The target we deployed for is gone. Find out whether the troops we let out still have
+ //something to do.
+ Bool membersOutside = FALSE;
+ Bool membersFighting = FALSE;
+ 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() )
+ {
+ membersOutside = TRUE;
+ if( ai->getCurrentVictim() != NULL )
+ {
+ membersFighting = TRUE;
+ }
+ }
+ }
+
+ //Only worth a partition scan once the troops are out and nobody is engaged.
+ Bool areaClear = FALSE;
+ if( membersOutside && !membersFighting )
+ {
+ areaClear = isAssaultAreaClear();
+ }
+
+ if( AssaultTransport_shouldRetrieveMembers( membersOutside, membersFighting, areaClear ) )
+ {
+ //Nobody left to shoot at, so pick the troops back up instead of walking them along
+ //behind the transport for the rest of the attack move.
+ retrieveMembers();
+ if( !m_framesRemaining )
+ {
+ m_framesRemaining = FRAMES_TO_WAIT_FOR_BOARDING;
+ }
+ }
+
+ if( AssaultTransport_waitingForBoarding( membersOutside, m_framesRemaining ) )
+ {
+ //Hold here while they climb back in - driving off would just make them chase us.
+ //The wait is bounded so a member that cannot make it back never stalls the attack move.
+ if( getAIStateType() == AI_ATTACK_MOVE_TO )
+ {
+ aiIdle( CMD_FROM_AI );
+ }
+ m_framesRemaining--;
+ }
+ else
+ {
+ m_framesRemaining = 0;
+ if( getAIStateType() != AI_ATTACK_MOVE_TO )
+ {
+ //Continue to move towards the attackmove area.
+ aiAttackMoveToPosition( &m_attackMoveGoalPos, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
+ }
+ }
}
else if( m_isAttackObject )
{
@@ -437,6 +512,24 @@ Bool AssaultTransportAIUpdate::isMemberHealthy( const Object *member ) const
return FALSE;
}
+//-------------------------------------------------------------------------------------------------
+/** Is there anything left worth fighting near the transport? ClearRangeRequiredToContinueAttackMove
+ * is the INI knob EA declared for exactly this and never read. */
+Bool AssaultTransportAIUpdate::isAssaultAreaClear() const
+{
+ const AssaultTransportAIUpdateModuleData *data = getAssaultTransportAIUpdateModuleData();
+ const Object *transport = getObject();
+
+ PartitionFilterRelationship filterRelationship( transport, PartitionFilterRelationship::ALLOW_ENEMIES );
+ PartitionFilterAlive filterAlive;
+ PartitionFilterSameMapStatus filterMapStatus( transport );
+ PartitionFilter *filters[] = { &filterRelationship, &filterAlive, &filterMapStatus, NULL };
+
+ Object *enemy = ThePartitionManager->getClosestObject( transport, data->m_clearRangeRequiredToContinueAttackMove,
+ FROM_CENTER_2D, filters );
+ return enemy == NULL;
+}
+
//-------------------------------------------------------------------------------------------------
void AssaultTransportAIUpdate::retrieveMembers()
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 6624a38fc..d4e7836ff 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -711,6 +711,57 @@ TEST(physics_forward_speed_is_the_projection_not_a_per_axis_norm)
CHECK_NEAR( PhysicsBehavior::calcForwardSpeed( climb, up ), 12.0f, 0.01f );
}
+/* CommandXlat.cpp: ctrl is the force fire modifier, but while the attack move cursor is up it
+ means "one shared pace" for the group instead. The click dispatch used to read the raw ctrl
+ state, so A then ctrl+click fired at the ground rather than issuing the attack move. */
+extern Bool CommandXlat_isForceAttackTargeting( Bool ctrlHeld, Bool attackMoveArmed );
+
+TEST(ctrl_is_force_fire_only_while_the_attack_move_cursor_is_down)
+{
+ /* plain ctrl+click: force fire, as in retail. */
+ CHECK( CommandXlat_isForceAttackTargeting( true, false ) );
+
+ /* attack move armed: ctrl is the group speed modifier, so nothing force fires. */
+ CHECK( !CommandXlat_isForceAttackTargeting( true, true ) );
+
+ /* no ctrl at all, either way. */
+ CHECK( !CommandXlat_isForceAttackTargeting( false, false ) );
+ CHECK( !CommandXlat_isForceAttackTargeting( false, true ) );
+}
+
+/* AssaultTransportAIUpdate.cpp: the troop crawler deploys its passengers at a target and used to
+ leave them walking behind it for the rest of the attack move once that target died. */
+extern Bool AssaultTransport_shouldRetrieveMembers( Bool membersOutside, Bool membersFighting, Bool areaClear );
+extern Bool AssaultTransport_waitingForBoarding( Bool membersOutside, UnsignedInt framesRemaining );
+
+TEST(troop_crawler_picks_its_troops_back_up_only_when_the_fight_is_over)
+{
+ /* deployed, nobody shooting, nothing hostile in range: climb back in. */
+ CHECK( AssaultTransport_shouldRetrieveMembers( true, false, true ) );
+
+ /* a member still has a victim - leave them to it. */
+ CHECK( !AssaultTransport_shouldRetrieveMembers( true, true, true ) );
+
+ /* nobody has a target yet, but something hostile is still in range: wait for them to engage. */
+ CHECK( !AssaultTransport_shouldRetrieveMembers( true, false, false ) );
+
+ /* everybody is already aboard: nothing to order. */
+ CHECK( !AssaultTransport_shouldRetrieveMembers( false, false, true ) );
+}
+
+TEST(troop_crawler_waits_for_boarding_but_not_forever)
+{
+ /* troops outside and time on the clock: hold position while they board. */
+ CHECK( AssaultTransport_waitingForBoarding( true, 300 ) );
+ CHECK( AssaultTransport_waitingForBoarding( true, 1 ) );
+
+ /* the wait ran out - roll on rather than stalling on a member that cannot get back. */
+ CHECK( !AssaultTransport_waitingForBoarding( true, 0 ) );
+
+ /* all aboard: continue the attack move immediately. */
+ CHECK( !AssaultTransport_waitingForBoarding( false, 300 ) );
+}
+
/* 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