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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): save m_isMoving, seed m_allowedToChase, kill a NaN brake
Olcay Seygan187f8d09761b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 86f5b7212..c355a89a3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -146,6 +146,8 @@ found and fixed — EA's own, not port damage.**- A unit with nowhere to stand appears where asked, not at a random point.- Loading a save remembers what your guards were guarding.- A turret loaded from a save is still tracking what it was tracking, and a worker loaded mid-job carries on with it, instead of both snapping back to their default state.+- A unit that was driving somewhere when you saved is still driving there when you load. One flag was written to the save twice and another not at all, so every loaded unit came back claiming to stand still, and everything that asks - a bike waiting for its rider, a mob following its leader, an ability that breaks if you move - believed it.+- Your units decide the same way on both machines whether to chase what they spotted on their own. That answer was read from uninitialised memory, so the same order could send one player's tank after a target and leave the other's standing.- A shell already in the air finishes its flight after a load instead of going off in the launcher's face.- An aircraft carrier remembers the order it was given, and each runway its own ramp.- A barracks that has already put its mob on the street does not put a second one out after a load.@@ -839,6 +841,9 @@ found and fixed — EA's own, not port damage.**- Jams in the heavy test fell 14% against the build from before all of this, and in ordinary playthe whole of it costs nothing measurable: same number of routes planned, same time spent planningthem.+- A tracked unit braking while sitting exactly on the spot it was sent to divided nothing by+ nothing. The result stayed in its brakes and was multiplied into the next push it was given, and+ a vehicle handed a number that is not a number goes somewhere no player asked for.## Long orders stopped hitchingdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cppindex e5ddcc5c6..86f2fde31 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp@@ -1228,8 +1228,16 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics,if (getFlag(IS_BRAKING)){- m_brakingFactor = slowDownDist/onPathDistToGoal;- m_brakingFactor *= m_brakingFactor;+ // Standing still on top of the goal is 0/0, which came out NaN and stayed in the member:+ // the clamp below lets a NaN through, and the next frame that wants to slow down multiplies+ // the braking force by it and hands the physics a NaN force. Sitting on the goal is as hard+ // as braking gets, so the ratio's limit is what belongs there.+ if (onPathDistToGoal > 0.0f) {+ m_brakingFactor = slowDownDist/onPathDistToGoal;+ m_brakingFactor *= m_brakingFactor;+ } else {+ m_brakingFactor = MAX_BRAKING_FACTOR;+ }if (m_brakingFactor>MAX_BRAKING_FACTOR) {m_brakingFactor = MAX_BRAKING_FACTOR;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 9e9c5bd09..c9d9ccdef 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -381,6 +381,11 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleDatam_isAiDead = FALSE;m_isRecruitable = TRUE; // Things default to being recruitable.m_executingWaypointQueue = FALSE;+ // Never initialised at all before: a human player's unit read whatever was in the heap to+ // decide whether it chases something it auto-acquired, so the same order gave two answers on+ // two machines. FALSE is the rule the approach state is written around; a deploy-and-attack+ // state or an attack move turns it on for as long as it lasts.+ m_allowedToChase = FALSE;m_retryPath = FALSE;m_isInUpdate = FALSE;m_fixLocoInPostProcess = FALSE;@@ -6846,7 +6851,7 @@ void AIUpdateInterface::crc( Xfer *x )void AIUpdateInterface::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 10;+ const XferVersion currentVersion = 11;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -6963,7 +6968,18 @@ void AIUpdateInterface::xfer( Xfer *xfer )xfer->xferBool(&m_isApproachPath);xfer->xferBool(&m_isSafePath);xfer->xferBool(&m_movementComplete);- xfer->xferBool(&m_isSafePath);+ if (version >= 11)+ {+ xfer->xferBool(&m_isMoving);+ }+ else+ {+ // Version 10 and earlier wrote m_isSafePath a second time in this slot, and m_isMoving+ // was never saved at all, so a loaded unit in an AIInternalMoveToState reported itself+ // as standing still.+ Bool safePathWrittenTwice = m_isSafePath;+ xfer->xferBool(&safePathWrittenTwice);+ }xfer->xferBool(&m_upgradedLocomotors);xfer->xferBool(&m_canPathThroughUnits);xfer->xferBool(&m_randomlyOffsetMoodCheck);