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): let head-on columns pass through each other
Olcay Seyganc503b9a1e927
diff --git a/GeneralsMD/Code/Data/Scenarios/mass420x2.txt b/GeneralsMD/Code/Data/Scenarios/mass420x2.txtindex a73380b11..fdb3d70a1 100644--- a/GeneralsMD/Code/Data/Scenarios/mass420x2.txt+++ b/GeneralsMD/Code/Data/Scenarios/mass420x2.txt@@ -6,13 +6,21 @@## -peacetime keeps them from fighting, so what is measured is 840 units crossing, not a battle.#+# Seat 1's blocks are offset towards the middle of the map. They used to be offset away from it,+# which on seed 3 put the tank block's centre at (490,30), on the edge of the map: the half of it+# that did not fit was piled onto the half that did, and 210 Crusaders sent from there alone+# stopped 856 times where the same 210 from seat 0's start stopped 72.+#+# 2026-09-19, seed 3, spawns fixed: before head-on pass-through the Crusaders stopped 5095 times+# and arrived on average 5021 frames after the order; after it, 619 and 2736.+## 2026-09-19: all 840 left and arrived, the orders cost 5.1 and 5.2 ms, logic frame p99 9.25 ms and# never over 33.3 ms.30 spawn 0 AmericaTankCrusader 210 start0:0:400 4030 spawn 0 AmericaInfantryRanger 210 start0:400:0 20-30 spawn 1 ChinaTankBattleMaster 210 start1:0:-400 40-30 spawn 1 ChinaInfantryRedguard 210 start1:-400:0 20+30 spawn 1 ChinaTankBattleMaster 210 start1:0:400 40+30 spawn 1 ChinaInfantryRedguard 210 start1:400:0 2090 playermove 0 * start190 playermove 1 * start090 arrive 0 AmericaTankCrusader start1 900diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex 8f0716e67..bc372de04 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -862,6 +862,8 @@ private:until this was pulled out of the crowd model it was only ever asked about units that happenedto have been handed a lane by a group order. */Int m_noProgress; ///< consecutive frames wanting to move, not moving, not turning either.+ Int m_headOnFrames; ///< consecutive frames held up by somebody driving straight at us.+ Bool m_headOnSeen; ///< a collision this frame was with somebody driving straight at us.Coord3D m_lastProgressPos; ///< where we were last frame, which is how the above is counted.Real m_lastProgressAngle; ///< and which way we were pointing, because coming about is progress too./* Dithering: driving a long way and getting nowhere, which the frame by frame test above cannotdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex 1839fd2da..2e38d29ec 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -4546,7 +4546,10 @@ StateReturnType AIFollowWaypointPathState::onEnter()m_currentWaypoint = ((AIStateMachine *)getMachine())->getGoalWaypoint();AIUpdateInterface *ai = getMachineOwner()->getAI();- if (m_currentWaypoint == NULL && !m_moveAsGroup) return STATE_FAILURE;+ // EA let a group move through with no waypoint and read its location on the next line: a unit+ // joining an AI team copied a teammate's path state but not its waypoint (joinTeam, from+ // AIPlayer::checkReadyTeams), and took the game down here+ if (m_currentWaypoint == NULL) return STATE_FAILURE;getMachine()->setGoalPosition(m_currentWaypoint->getLocation());diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 78069678f..577974dd9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -326,6 +326,8 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleDatam_crowdAim = 0.0f;m_crowdAimValid = FALSE;m_noProgress = 0;+ m_headOnFrames = 0;+ m_headOnSeen = FALSE;m_lastProgressPos.zero();m_lastProgressAngle = 0.0f;m_ditherFrom.zero();@@ -1462,6 +1464,9 @@ Real AIUpdateInterface::calculateMaxBlockedSpeed(Object *other) const//-------------------------------------------------------------------------------------------------+static const Real HEAD_ON_DOT = -0.5f; ///< facing more than 120 degrees apart is driving at each other+static const Int HEAD_ON_PASS_FRAMES = 8; ///< held up head-on this long: pass through+Bool AIUpdateInterface::blockedBy(Object *other)/* Returns TRUE if we are blocked from moving by the other object.*/{@@ -1542,6 +1547,18 @@ Bool AIUpdateInterface::blockedBy(Object *other)if (getNumFramesBlocked()>LOGICFRAMES_PER_SECOND) {if (dotProduct<=0.0f) return FALSE; // we are not moving in the same direction.}+ /* The rule above is EA's way out of a head-on meeting and it never fires: doLocomotor puts+ m_blockedFrames back to 1 on every frame the locomotor reports itself unblocked, which a tank+ that has finished turning to face its blocker does, so two groups driving into each other+ stood nose to nose until the rescue ladder or a step aside broke them up. Traced on 20 BattleMasters meeting 20 Crusaders in the open, the front+ pair sat at a speed of 0 for over 200 frames while everybody behind queued on them. This one+ counts on its own clock and lets the pair through each other after a quarter of a second. */+ if (otherMoving && dotProduct <= HEAD_ON_DOT)+ {+ m_headOnSeen = TRUE;+ if (m_headOnFrames > HEAD_ON_PASS_FRAMES)+ return FALSE;+ }Real collisionAngle = ThePartitionManager->getRelativeAngle2D( obj, &otherPos );Real otherAngle = ThePartitionManager->getRelativeAngle2D( other, &pos );@@ -1687,6 +1704,17 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other}Real maxSpeed = calculateMaxBlockedSpeed(other);+ // -tracemove <id>: who is in the way, which way he faces against us, and where he sits off our nose,+ // so a jam can be walked back to the pair at its front one unit at a time+ if (TheGlobalData->m_traceMoveID > 0 && getObject()->getID() == (ObjectID)TheGlobalData->m_traceMoveID)+ {+ const Coord3D *od = other->getUnitDirectionVector2D();+ const Coord3D *md = getObject()->getUnitDirectionVector2D();+ DEBUG_LOG(("MOVEBLOCK %d by %d %s at %.0f,%.0f facing %.2f moving %d waiting %d allowed %.3f bearing %.1f\n", TheGameLogic->getFrame(),+ other->getID(), other->getTemplate()->getName().str(), other->getPosition()->x, other->getPosition()->y,+ md->x * od->x + md->y * od->y, otherMoving, aiOther->isWaitingForPath(), maxSpeed,+ ThePartitionManager->getRelativeAngle2D( getObject(), other->getPosition() ) * 180.0f / PI));+ }if (maxSpeed < m_curMaxBlockedSpeed){m_curMaxBlockedSpeed = maxSpeed;@@ -3655,6 +3683,12 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )chooseGoodLocomotorFromCurrentSet();+ if (m_headOnSeen)+ ++m_headOnFrames;+ else+ m_headOnFrames = 0;+ m_headOnSeen = FALSE;+if (m_isBlocked){++m_blockedFrames;@@ -4187,6 +4221,10 @@ void AIUpdateInterface::joinTeam( void )} else {getStateMachine()->setGoalPosition(ai->getGoalPosition());}+ // a team on a waypoint path is followed along the same path; without it the copied state has no+ // waypoint to start from+ if (ai->getStateMachine()->getGoalWaypoint())+ getStateMachine()->setGoalWaypoint(ai->getStateMachine()->getGoalWaypoint());StateID state = ai->getCurrentStateID();setLastCommandSource( CMD_FROM_AI );// Match the state.