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): attack move newly built units to the rally point

Olcay Seyganda75220886ef
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
index 43554a79a..703a30031 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
@@ -649,6 +649,9 @@ public:
// this is intended for use ONLY by AIFollowPathState.
inline void friend_setCurrentGoalPathIndex( Int index ) { m_nextGoalPathIndex = index; }
+
+ // this is intended for use ONLY by the production exit modules.
+ void friend_setExitProductionRallyPoint( const Coord3D *pos );
#if defined(_DEBUG) || defined(_INTERNAL)
inline const Coord3D *friend_getRequestedDestination() const { return &m_requestedDestination; }
inline const Coord3D *friend_getRequestedDestination2() const { return &m_requestedDestination2; }
@@ -740,6 +743,8 @@ private:
Int m_nextGoalPathIndex; ///< The simple goal path index we are moving to next.
ObjectID m_moveOutOfWay1;
ObjectID m_moveOutOfWay2;
+ Coord3D m_exitProductionRallyPoint; ///< Rally point to attack-move to once we are clear of the producer that just built us.
+ Bool m_hasExitProductionRallyPoint; ///< True while m_exitProductionRallyPoint is still waiting to be ordered.
// Locomotors -------------------------------------------------------------------------------------------------
enum LocoGoalType // Note - written out in save/load xfer, don't change these numbers. jba.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index c4ef3c0c6..7d7e7c1a1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -250,6 +250,8 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleData
m_nextGoalPathIndex = -1;
m_moveOutOfWay1 = INVALID_ID;
m_moveOutOfWay2 = INVALID_ID;
+ m_exitProductionRallyPoint.zero();
+ m_hasExitProductionRallyPoint = FALSE;
m_locomotorSet.clear();
m_curLocomotor = NULL;
m_curLocomotorSet = LOCOMOTORSET_INVALID;
@@ -1021,6 +1023,18 @@ UpdateSleepTime AIUpdateInterface::update( void )
StateReturnType stRet = getStateMachine()->updateStateMachine();
+ // A unit that was just built walks a short exit path out of its producer and then, if the player
+ // set a rally point, attack moves to it - so it stops and fights whatever it runs into on the way
+ // instead of taking the shots and walking on. This is checked right after the machine ran,
+ // because finishing (or failing) the exit path is what drops us into idle in the first place.
+ if (m_hasExitProductionRallyPoint && getAIStateType() == AI_IDLE)
+ {
+ Coord3D rallyPoint = m_exitProductionRallyPoint;
+ m_hasExitProductionRallyPoint = FALSE;
+ privateAttackMoveToPosition( &rallyPoint, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
+ stRet = STATE_CONTINUE;
+ }
+
if (IS_STATE_SLEEP(stRet))
{
Int frames = GET_STATE_SLEEP_FRAMES(stRet);
@@ -2628,6 +2642,11 @@ void AIUpdateInterface::aiDoCommand(const AICommandParms* parms)
if (!isAllowedToRespondToAiCommands(parms))
return;
+ // Any order at all replaces the trip to the producer's rally point - except the exit path itself,
+ // which is the leg that precedes it.
+ if (parms->m_cmd != AICMD_FOLLOW_EXITPRODUCTION_PATH)
+ m_hasExitProductionRallyPoint = FALSE;
+
#ifdef ALLOW_SURRENDER
// surrendered items have very limited options, and only via AI cmds
if (isSurrendered())
@@ -3376,6 +3395,17 @@ void AIUpdateInterface::privateFollowPathAppend( const Coord3D *pos, CommandSour
}
}
+//----------------------------------------------------------------------------------------
+/**
+ * Remember the rally point of the producer that just built us. The exit path is only the step out
+ * of the door; update() turns this into an attack move once that step is done.
+ */
+void AIUpdateInterface::friend_setExitProductionRallyPoint( const Coord3D *pos )
+{
+ m_exitProductionRallyPoint = *pos;
+ m_hasExitProductionRallyPoint = TRUE;
+}
+
//----------------------------------------------------------------------------------------
/**
* Follow the path defined by the given array of points
@@ -5021,7 +5051,7 @@ void AIUpdateInterface::crc( Xfer *x )
void AIUpdateInterface::xfer( Xfer *xfer )
{
// version
- const XferVersion currentVersion = 4;
+ const XferVersion currentVersion = 5;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -5234,6 +5264,12 @@ void AIUpdateInterface::xfer( Xfer *xfer )
xfer->xferInt(&repulsorCountdown);
}
+ if (version >= 5)
+ {
+ xfer->xferCoord3D(&m_exitProductionRallyPoint);
+ xfer->xferBool(&m_hasExitProductionRallyPoint);
+ }
+
} // end xfer
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/DefaultProductionExitUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/DefaultProductionExitUpdate.cpp
index 6c4c8283e..660857d43 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/DefaultProductionExitUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/DefaultProductionExitUpdate.cpp
@@ -106,15 +106,15 @@ void DefaultProductionExitUpdate::exitObjectViaDoor( Object *newObj, ExitDoorTyp
exitPath.push_back(tmp);
AIUpdateInterface *ai = newObj->getAIUpdateInterface();
- if (m_rallyPointExists)
+ if (m_rallyPointExists && ai && ai->isDoingGroundMovement())
{
tmp = m_rallyPoint;
- if (ai && ai->isDoingGroundMovement())
- {
- if (TheAI->pathfinder()->adjustDestination(newObj, ai->getLocomotorSet(), &tmp))
- exitPath.push_back(tmp);
-
- }
+ //
+ // the rally point is not a leg of the exit path any more - the unit attack moves there
+ // once it is out the door, so it fights what it meets on the way instead of walking past it
+ //
+ if (TheAI->pathfinder()->adjustDestination(newObj, ai->getLocomotorSet(), &tmp))
+ ai->friend_setExitProductionRallyPoint( &tmp );
}
if (ai) {
ai->aiFollowExitProductionPath( &exitPath, creationObject, CMD_FROM_AI );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/QueueProductionExitUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/QueueProductionExitUpdate.cpp
index 28d0cd47e..127a23e95 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/QueueProductionExitUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionExitUpdate/QueueProductionExitUpdate.cpp
@@ -143,12 +143,15 @@ void QueueProductionExitUpdate::exitObjectViaDoor( Object *newObj, ExitDoorType
AIUpdateInterface *ai = newObj->getAIUpdateInterface();
if (m_rallyPointExists)
{
- tmp = m_rallyPoint;
- if (ai && ai->isDoingGroundMovement())
+ if (ai && ai->isDoingGroundMovement())
{
+ tmp = m_rallyPoint;
+ //
+ // the rally point is not a leg of the exit path any more - the unit attack moves there
+ // once it is out the door, so it fights what it meets on the way instead of walking past it
+ //
if (TheAI->pathfinder()->adjustDestination(newObj, ai->getLocomotorSet(), &tmp))
- exitPath.push_back(tmp);
-
+ ai->friend_setExitProductionRallyPoint( &tmp );
}
} else {
// Double the destination to keep redguards from stacking.