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 infantry walk round vehicles instead of waiting
Olcay Seyganb7514253ed7c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c7c4a61ee..f1336af05 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -296,6 +296,7 @@ found and fixed — EA's own, not port damage.**- The whole unit limit moves on one click. The lobby allows 840 units in a match, and the game could only keep 512 of them waiting for a route at once: sent across the map together, 329 of 841 never took a step, then or ever. All 840 go now, whether one player owns them or two armies of 420 are crossing through each other, and the game never falls behind: the click itself costs 13 milliseconds, and no moment of the march took longer than 33, the time the game has for each step of the battle. With all 840 on screen the picture averages 30 frames a second on the new renderer and 37 on the old one, 2.7 milliseconds quicker than before because a crowd of infantry now redraws its shadows' poses in turns instead of every soldier every frame.- A tank in a column no longer parks behind the one in front while that one drives away. Touching the tank ahead cut its speed a little more every moment and never let it come back, so once the leader had paused, the follower sat at a dead stop until their hulls came apart and then crawled back up to speed. Every pause at the head of a column rippled down it as a line of tanks standing still. The follower now picks its speed up again as soon as the one in front moves off. Across eight maps, stops of a second or more behind the unit ahead fell from 27 to 19 in a 30-unit squad and from 1169 to 781 in a 200-unit army, the longest single stop in that army went from 14.6 seconds to 9, and the last tank of the squad arrives 6.6 seconds sooner. In computer-against-computer matches, the time units spent jammed so hard that the game counted them stuck fell from about 1.3 seconds a match to half a second.- Tanks and infantry sent together no longer trip over each other. A tank that caught up with a soldier of its own side marching the same way told him to step aside, and a soldier who steps aside forgets his route and stands for a full second before he may ask for another. In a mixed squad of 20 Crusaders and 10 Rangers every one of the 28 second-long stops across eight maps was exactly that. The tank now rolls through a soldier walking its way, the way soldiers already walk through each other; one standing still or crossing its path is still asked to move. Stops of a second or more fell from 48 to 12 in that squad and from 977 to 546 in a 200-unit army, and both arrive sooner: the last Crusader 2.5 seconds earlier, the whole army 1.9 seconds earlier on average. In computer-against-computer matches, time spent wedged fell 11%.+- Infantry no longer clogs a road your tanks are driving down. A soldier who walked into the side of a tank stood there until it left, and a tank queueing in a town street does not leave: on Alpine Assault one Ranger waited four and a half seconds against the flank of a Crusader that was itself waiting for the one in front. A soldier who meets a vehicle now walks round it and steps a little away from the hull, and a tank coming at a marching soldier slows to a third of its speed instead of ordering him aside, which used to cost him his route and another second on the spot. With 36 soldiers walking one way down that street and 12 vehicles driving the other, the soldiers' stops of a second or more fell from 35 to 6 over three matches, and on the slowest of them the last Ranger arrives 41 seconds after the order where he used to take 55. The vehicles get through sooner too. A replay recorded before this change plays back differently.- Two columns that meet head-on get past each other. The game has a rule for it, written by the original team: two tanks nose to nose for a second drive through each other. A counter that reset itself every frame meant it never once fired, so the front pair stood there, sometimes for more than seven seconds, and everything behind them queued. It fires now, after a quarter of a second. Twenty tanks meeting twenty in the open used to stop 104 times and bring the last one in after 72 seconds; now they stop once, and the last one arrives after 23. Two armies of 420 crossing the map through each other get there in half the time: the Crusaders' average trip went from 167 seconds to 91, the Battlemasters' from 149 to 75.- A group you send round a corner goes round it side by side. Every tank used to work out its own route, every one of those routes ran over the tip of the corner, and the whole group squeezed onto that one point with the outside tanks cutting across the inside ones to reach it. Now the group takes one route and each vehicle drives its own lane of it: the outside lane swings wide, the inside one stays clear of the wall, and where the street narrows the lanes close up over a few corners rather than zigzagging. A tank whose place is short of the click stops at it, instead of driving its lane to the far end and coming back. Twenty-four tanks sent through the streets of Alpine Assault came to a dead stop 7 times a crossing instead of 10 and spent a third less time pressed against each other, and the column in the Forgotten Forest trailer scene gets its last tank home 20 seconds sooner. Infantry, and any group whose route crosses a bridge, still find their own way. A replay recorded before this change plays back differently.- A group spreads out over a bridge instead of crossing it in single file. Every bridge used to count as one lane wide, so a group closed up into a queue on the bank and went over one tank at a time, even though the Kandahar bridge on Golden Oasis carries three Crusaders abreast. The deck now keeps its real width, and the lanes close up to that width just before the ramp, so the tanks on the flanks come onto the ramp instead of nosing into the end of the railing beside it. Twenty Crusaders over the Kandahar bridge get their last tank across four seconds sooner.diff --git a/GeneralsMD/Code/Data/Scenarios/infconvoy.txt b/GeneralsMD/Code/Data/Scenarios/infconvoy.txtindex 65c5b6233..53dd3d732 100644--- a/GeneralsMD/Code/Data/Scenarios/infconvoy.txt+++ b/GeneralsMD/Code/Data/Scenarios/infconvoy.txt@@ -2,10 +2,11 @@# 760,920 to 1400,1400 while twelve vehicles drive it the other way, one right click for the soldiers and one each# for the tanks and the Humvees.#-# A vehicle lets a moving allied soldier heading within 60 degrees of it through, but one coming-# head-on is told to step aside (AIUpdate::processCollision, aiMoveAwayFromUnit), loses its path and-# stands about a second before it asks again (PATHFINDING-ANALYSIS.md, step-aside yield). This-# puts thirty-six soldiers in front of twelve vehicles on the one street where that can happen.+# Until the change measured at the bottom of this header, a vehicle let a moving allied soldier+# heading within 60 degrees of it through, but one coming head-on was told to step aside+# (AIUpdate::processCollision, aiMoveAwayFromUnit), lost his path and stood about a second before+# he asked again (PATHFINDING-ANALYSIS.md, step-aside yield). This puts thirty-six soldiers in+# front of twelve vehicles on the one street where that can happen.## generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit# -map "Maps\Alpine Assault\Alpine Assault.map" -autoskirmish 2 -takeover@@ -26,6 +27,18 @@# (one Crusader by itself takes 724). -tracemove 238 on seed 1: Ranger 238 stands at 1081,1125# from frame 629 to 764 with Crusader 264 twenty units ahead, its allowed speed 0 on every frame;# the Crusader is itself stopped behind Crusader 263.+#+# 2026-10-04, after a soldier touching a vehicle walks along its side and half a step out from it+# instead of stopping, and a vehicle creeps at a third of its speed behind a marching soldier+# instead of telling him to step aside. Same seeds:+#+# Rangers 3 / 0 / 3 (none held back or blocked) 1122 / 1119 / 1227+# Missile Defenders 0 / 0 / 0 1022 / 1010 / 1020+# Crusaders 0 / 2 / 1 1338 / 1253 / 1390+# Humvees 1 / 0 / 1 997 / 966 / 989+#+# Ranger mean arrival 1256 / 1215 / 1220 before, 1038 / 1031 / 1091 after. The six Ranger stops+# left are counted "with a path and no reason", the longest 73 frames.30 spawn 0 AmericaInfantryRanger 24 760 920 1830 spawn 0 AmericaInfantryMissileDefender 12 760 1000 18diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.hindex af37e03e8..bccaf7f2e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h@@ -921,6 +921,8 @@ private: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.+ Coord2D m_sideStep; ///< a soldier's way out of the vehicles he touched since the last move, summed.+ Bool m_sideStepSeen; ///< and whether he touched any.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/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex f6a788050..c320a677b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -342,6 +342,8 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleDatam_noProgress = 0;m_headOnFrames = 0;m_headOnSeen = FALSE;+ m_sideStep.x = m_sideStep.y = 0.0f;+ m_sideStepSeen = FALSE;m_lastProgressPos.zero();m_lastProgressAngle = 0.0f;m_ditherFrom.zero();@@ -1807,6 +1809,27 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *otherif (!aiOther->isDoingGroundMovement()) return FALSE;if (selfMoving){+ /* A soldier walks round a vehicle rather than waiting at its side. The blocked-speed rule stops+ him dead in front of any tank facing his way or standing still, and a tank queueing in a+ street is both: on Alpine Assault a Ranger stood 135 frames against the flank of a Crusader+ that was itself queued behind another. Here he only notes which way is out, and doLocomotor+ takes the part of his step that points into the hull away and adds a half step out from it.+ Asking blockedBy first made it flicker: turned along the hull, the hull is off his nose and no+ longer blocks him, so he turned back, and stood turning on the spot. */+ if (getObject()->isKindOf(KINDOF_INFANTRY) && other->isKindOf(KINDOF_VEHICLE)+ && getStateMachine()->getCurrentStateID() != AI_PANIC)+ {+ Real ax = getObject()->getPosition()->x - other->getPosition()->x;+ Real ay = getObject()->getPosition()->y - other->getPosition()->y;+ const Real len = sqrtf(ax*ax + ay*ay);+ if (len > 0.01f)+ {+ m_sideStep.x += ax / len;+ m_sideStep.y += ay / len;+ m_sideStepSeen = TRUE;+ return FALSE;+ }+ }Bool blocked = blockedBy(other);if (blocked){@@ -1825,6 +1848,19 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other}Real maxSpeed = calculateMaxBlockedSpeed(other);+ /* A vehicle held up by a soldier on the march creeps at a third of its speed rather than stopping+ or telling him to step aside. He is already walking round the hull (the top of this function),+ and a soldier told to step aside lost his route and stood a second before the repath guard let+ him ask for another: 13 of the 28 Ranger stops in infconvoy.txt. One who has stopped getting+ anywhere is wedged, and is still told. */+ const Bool marchingSoldier = getObject()->isKindOf(KINDOF_VEHICLE) && other->isKindOf(KINDOF_INFANTRY)+ && otherMoving && aiOther->m_noProgress < STUCK_PRESS_FRAMES;+ if (marchingSoldier && getCurLocomotor())+ {+ const Real crawl = getCurLocomotor()->getMaxSpeedForCondition(getObject()->getBodyModule()->getDamageState()) * 0.33f;+ if (maxSpeed < crawl)+ maxSpeed = crawl;+ }// -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 timeif (TheGlobalData->m_traceMoveID > 0 && getObject()->getID() == (ObjectID)TheGlobalData->m_traceMoveID)@@ -1854,6 +1890,8 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other{return FALSE;}+ if (marchingSoldier)+ return FALSE; // he is walking round usaiOther->aiMoveAwayFromUnit(getObject(), CMD_FROM_AI);return FALSE;}@@ -3947,6 +3985,10 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )const Bool traceWasBlocked = m_isBlocked; // -tracemove: the flag is cleared on the next lineconst Coord3D tracePos = *getObject()->getPosition(); // -tracemove: where the last whole frame left itm_isBlocked = FALSE;+ const Bool sideStep = m_sideStepSeen;+ const Coord2D sideAway = m_sideStep;+ m_sideStepSeen = FALSE;+ m_sideStep.x = m_sideStep.y = 0.0f;Bool blocked = m_blockedFrames > 0;Bool requiresConstantCalling = TRUE; // assume the worst.@@ -4127,6 +4169,43 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )crowdSteer(goalPos, speed);}+ // a soldier touching a vehicle (processCollision): walk along its side, never into it+ if (sideStep)+ {+ const Real len = sqrtf(sideAway.x*sideAway.x + sideAway.y*sideAway.y);+ const Coord3D *here = getObject()->getPosition();+ Real gx = goalPos.x - here->x;+ Real gy = goalPos.y - here->y;+ const Real dist = sqrtf(gx*gx + gy*gy);+ if (len > 0.01f && dist > 0.01f)+ {+ const Real nx = sideAway.x / len;+ const Real ny = sideAway.y / len;+ const Real into = gx*nx + gy*ny;+ if (into < 0.0f)+ {+ gx -= into*nx;+ gy -= into*ny;+ Real t = sqrtf(gx*gx + gy*gy);+ if (t < 0.1f*dist)+ {+ // dead against the hull: pick a side by ID, the same one every frame+ const Real side = (getObject()->getID() & 1) ? 1.0f : -1.0f;+ gx = -ny*side;+ gy = nx*side;+ t = 1.0f;+ }+ goalPos.x = here->x + gx*dist/t;+ goalPos.y = here->y + gy*dist/t;+ }+ /* and half a step out from it, so a tank coming past moves him over rather than+ driving through him: with the slide alone a soldier and a tank going the same way+ overlapped 31% more often than before in squad30.txt, with this 22% less */+ goalPos.x += nx*dist*0.5f;+ goalPos.y += ny*dist*0.5f;+ }+ }+m_curLocomotor->locoUpdate_moveTowardsPosition(getObject(), goalPos,onPathDistToGoal+getPathExtraDistance(), speed, &blocked, faceTarget, bendDist, bendCos);