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): stop a guard return from re-entering a dead fight

Olcay Seygancb5472f0c831
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2fdf07f7..5efd83ad4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -199,6 +199,7 @@ found and fixed — EA's own, not port damage.**
- A Chinook unloads its passengers one at a time, not stacked in one frame.
- Campaign reinforcements flown in by Chinook land again. That one-at-a-time unloading sent a mission's scripted Chinooks home with their cargo still aboard, so on the second American mission the dozers announced at the docks never got off, and neither did the next one.
- A guarding unit no longer fights itself between returning to post and shooting back.
+- A unit sent out to answer a shot, whose target then died, is supposed to walk home. When that walk cannot start, because the unit cannot move or the pathfinder has no way back, the failure was taken to mean someone was still in range, and the unit went back into the attack on a target that was already gone. Both ends of that attack find nobody and hand it back to the walk, which fails again, so the loop runs out inside the same step and starts over on the next one. One match wrote 67,416 lines about it, and every line is pushed out to disk as it is written. The failed walk now counts as the walk being over. The unit looks once more, and with nobody there it goes back to what it was doing. A save that caught the chase dropped it on load; it picks the target back up. A soldier whose tunnel is gone did the same thing, and a computer match wrote 80 of those lines. With no tunnel he waits and looks. A replay recorded before this change plays back differently.
- Engineers can clear mines and booby traps they cannot see.
- A helicopter no longer boards a transport from the air.
- A building in the fog takes orders. Send infantry into a fogged garrison, a Ranger at a fogged oil derrick or a hacker at a fogged supply center and they go, where the click used to turn into a plain move to the spot. The cursor and the walk over go by what you last saw there, so if the building was taken, filled or emptied while you were not looking, nothing on your screen says so until your men get close enough to see it, and then they stop. Ground you have never seen stays out of reach.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
index 6d5b08807..f260dcc98 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGuardRetaliate.cpp
@@ -403,7 +403,7 @@ StateReturnType AIGuardRetaliateInnerState::onEnter( void )
Object* nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID()) ;
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AIGuardRetaliateInnerState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AIGuardRetaliateInnerState.\n"));
return STATE_SUCCESS;
}
m_enterState = newInstance(AIEnterState)(getMachine());
@@ -422,7 +422,7 @@ StateReturnType AIGuardRetaliateInnerState::onEnter( void )
Object* nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID()) ;
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AIGuardRetaliateInnerState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AIGuardRetaliateInnerState.\n"));
return STATE_SUCCESS;
}
m_exitConditions.m_center = pos;
@@ -506,7 +506,8 @@ void AIGuardRetaliateOuterState::xfer( Xfer *xfer )
/** Load post process */
// ------------------------------------------------------------------------------------------------
void AIGuardRetaliateOuterState::loadPostProcess( void )
-{ AIGuardRetaliateOuterState
+{
+ // see AIGuardOuterState::loadPostProcess. The stray class name made this a no-op.
onEnter();
} // end loadPostProcess
@@ -524,7 +525,7 @@ StateReturnType AIGuardRetaliateOuterState::onEnter( void )
Object* nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID()) ;
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AIGuardRetaliateOuterState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AIGuardRetaliateOuterState.\n"));
return STATE_SUCCESS;
}
Object *obj = getMachineOwner();
@@ -630,7 +631,14 @@ StateReturnType AIGuardRetaliateReturnState::onEnter( void )
TheAI->pathfinder()->adjustDestination(getMachineOwner(), ai->getLocomotorSet(), &m_goalPosition);
}
setAdjustsDestination(true);
- return AIInternalMoveToState::onEnter();
+ // Failure from the walk means it cannot start: the unit cannot move, or the
+ // pathfinder handed back nothing. That same failure is how a live target found
+ // on the way home enters the attack, so a walk that cannot start used to attack
+ // an id that was already gone, and the machine handed itself straight back here.
+ StateReturnType started = AIInternalMoveToState::onEnter();
+ if (started == STATE_FAILURE)
+ return STATE_SUCCESS;
+ return started;
}
//--------------------------------------------------------------------------------------
@@ -644,8 +652,12 @@ StateReturnType AIGuardRetaliateReturnState::update( void )
return STATE_FAILURE; // early termination because we found a target.
}
- // Just let the return movement finish.
- return AIInternalMoveToState::update();
+ // A walk that cannot be finished is the walk being over. The failure edge above
+ // is the only one that means a target was found.
+ StateReturnType moved = AIInternalMoveToState::update();
+ if (moved == STATE_FAILURE)
+ return STATE_SUCCESS;
+ return moved;
}
//--------------------------------------------------------------------------------------
@@ -814,7 +826,7 @@ StateReturnType AIGuardRetaliateAttackAggressorState::onEnter( void )
if( !nemesis )
{
- DEBUG_LOG(("Unexpected NULL nemesis in AIGuardRetaliateAttackAggressorState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AIGuardRetaliateAttackAggressorState.\n"));
return STATE_SUCCESS;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
index b4d4539c5..df3d2c10c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AITNGuard.cpp
@@ -341,7 +341,7 @@ StateReturnType AITNGuardInnerState::onEnter( void )
Object* nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID()) ;
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AITNGuardInnerState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AITNGuardInnerState.\n"));
return STATE_SUCCESS;
}
m_exitConditions.m_attackGiveUpFrame = TheGameLogic->getFrame() + TheAI->getAiData()->m_guardChaseUnitFrames;
@@ -488,7 +488,7 @@ StateReturnType AITNGuardOuterState::onEnter( void )
Object* nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID()) ;
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AITNGuardOuterState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AITNGuardOuterState.\n"));
return STATE_SUCCESS;
}
@@ -611,12 +611,19 @@ StateReturnType AITNGuardReturnState::onEnter( void )
// Find tunnel network to enter.
// Scan my tunnels.
Object *bestTunnel = findBestTunnel(getMachineOwner()->getControllingPlayer(), getMachineOwner()->getPosition());
- if (bestTunnel==NULL) return STATE_FAILURE;
+ // No tunnel to enter is not a target. Failure here used to enter the attack
+ // on whatever id was left, which was already gone, and the machine handed
+ // itself straight back.
+ if (bestTunnel==NULL) return STATE_SUCCESS;
getMachine()->setGoalObject(bestTunnel);
getMachineOwner()->getAI()->friend_setGoalObject(bestTunnel);
-
- return AIEnterState::onEnter();
+
+ // The walk into the tunnel failing is the same thing: the return is over.
+ StateReturnType entered = AIEnterState::onEnter();
+ if (entered == STATE_FAILURE)
+ return STATE_SUCCESS;
+ return entered;
}
//--------------------------------------------------------------------------------------
@@ -732,7 +739,7 @@ StateReturnType AITNGuardIdleState::update( void )
Object *nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID());
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AITNGuardAttackAggressorState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AITNGuardAttackAggressorState.\n"));
return STATE_SLEEP(0);
}
if (getMachineOwner()->getContainedBy()) {
@@ -821,7 +828,7 @@ StateReturnType AITNGuardAttackAggressorState::onEnter( void )
Object *nemesis = TheGameLogic->findObjectByID(getGuardMachine()->getNemesisID());
if (nemesis == NULL)
{
- DEBUG_LOG(("Unexpected NULL nemesis in AITNGuardAttackAggressorState.\n"));
+ DEBUG_LOG_DEV(("Unexpected NULL nemesis in AITNGuardAttackAggressorState.\n"));
return STATE_SUCCESS;
}