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): keep every unit of a big selection moving

Olcay Seygan17939e91b420
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1ce7d0b4..9ab7deb6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -159,6 +159,10 @@ found and fixed — EA's own, not port damage.**
- A guarding unit no longer fights itself between returning to post and shooting back.
- Engineers can clear mines and booby traps they cannot see.
- A helicopter no longer boards a transport from the air.
+- Select a big army, right click once, and all of it goes. In a crowd, units step aside to let a neighbour past, and a unit that stepped aside at the moment it was working out its route forgot the order and stood where it was. Out of 120 units sent across a small map, 7 were left behind, and the bigger the selection the more of them stayed. Now 200 out of 200 get there. Clicking on a building did the same thing to the whole group: there was no open ground right under the cursor, so nobody was given a place to stand. The group now stands around the building.
+- 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%.
- A jet shot down in the air flies on before it falls. Its wings stopped working on the frame it was hit, so it dropped almost vertically and hit the ground under the spot it was killed at, which is the one thing a plane doing three hundred knots cannot do. It keeps its lift now and gives it up over the next second or so, carrying forward and nosing over as it goes.
- And the bombers come down at all. A B-52, a Spectre gunship, a cargo plane and an A-10 all left the falling speed out of their data, and nought means the lift exactly cancels gravity: shot down, they flew on at cruising height, burning, and blew up in the air still level. Every one of them now falls at half gravity or better, and the fireball waits for the ground instead of going off on a timer somewhere over the map. Measured on the way in: a B-52 falls for 2.8 seconds and lands, where it used to detonate at a hundred feet. On the way home it still did not: after the drop a bomber flies off the map on a precise course that is allowed three times its normal lift, which held a dead one up with lift to spare. A bomber shot down after its run now comes down like one shot down before it.
diff --git a/GeneralsMD/Code/Data/Scenarios/mass420x2.txt b/GeneralsMD/Code/Data/Scenarios/mass420x2.txt
new file mode 100644
index 000000000..a73380b11
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/mass420x2.txt
@@ -0,0 +1,21 @@
+# The unit limit split between two players, both armies ordered across the map through each other.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 3 2 large -autoskirmish 2 -takeover -seed 3 -maxframes 9000 -peacetime 10
+# -scenario mass420x2 -logPrefix mass420x2_
+#
+# -peacetime keeps them from fighting, so what is measured is 840 units crossing, not a battle.
+#
+# 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 40
+30 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
+90 playermove 0 * start1
+90 playermove 1 * start0
+90 arrive 0 AmericaTankCrusader start1 900
+90 arrive 0 AmericaInfantryRanger start1 900
+90 arrive 1 ChinaTankBattleMaster start0 900
+90 arrive 1 ChinaInfantryRedguard start0 900
diff --git a/GeneralsMD/Code/Data/Scenarios/mass840.txt b/GeneralsMD/Code/Data/Scenarios/mass840.txt
new file mode 100644
index 000000000..8c41aa0ee
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/mass840.txt
@@ -0,0 +1,22 @@
+# The whole unit limit in one order: 840 units, one player, one right click.
+#
+# The lobby's unit limit is 840 for the match. This is all of it under one player and one
+# playermove, which is the most a single order can ever carry.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 3 2 large -autoskirmish 2 -takeover -seed 3 -maxframes 9000 -peacetime 10
+# -scenario mass840 -logPrefix mass840_
+#
+# Grep HEADLESS DEPART (did every unit start), HEADLESS ARRIVE (did every unit get there),
+# SLOW GROUPMOVE (what the order frame cost) and HEADLESS LOGICTIME. Drop -headless -observer and add
+# -win -xres 1280 -yres 720 -camera 1900 2300 for the drawn frame with the whole army on screen.
+#
+# 2026-09-19: 840 of 840 left and arrived, the last to leave after 19.1 s, the order frame 13.1 ms,
+# logic frame p99 8.5 ms and never over 33.3 ms. Before the pathfind queue grew past 512, 329 of them
+# never left.
+
+30 spawn 0 AmericaTankCrusader 420 start0:0:400 40
+30 spawn 0 AmericaInfantryRanger 420 start0:400:0 20
+90 playermove 0 * start1
+90 arrive 0 AmericaTankCrusader start1 900
+90 arrive 0 AmericaInfantryRanger start1 900
diff --git a/GeneralsMD/Code/Data/Scenarios/massmove.txt b/GeneralsMD/Code/Data/Scenarios/massmove.txt
new file mode 100644
index 000000000..9e6d3d441
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/massmove.txt
@@ -0,0 +1,19 @@
+# Mass move probe: does every unit of a big selection obey one right click?
+#
+# Two hundred units, one player-shaped order (playermove takes the same branch of
+# AIGroup::groupMoveToPosition as a right click; move is a script order and does not), and a count of
+# who arrived. Before 2026-09-19 a crowd this size left units standing idle halfway: a unit shoved
+# aside by a neighbour lost the path its order was waiting for and gave the order up.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 3 2 small -autoskirmish 2 -takeover -seed 3 -maxframes 4000
+# -scenario massmove -logPrefix mass_
+#
+# then grep the log for HEADLESS ARRIVE; every unit that did not arrive writes a HEADLESS STRAGGLER
+# line with its position and whether it is idle, moving or still waiting for a path.
+
+30 spawn 0 AmericaTankCrusader 100 start0:0:300 40
+30 spawn 0 AmericaInfantryRanger 100 start0:300:0 20
+90 playermove 0 * 700 600
+90 arrive 0 AmericaTankCrusader 700 600 450
+90 arrive 0 AmericaInfantryRanger 700 600 450
diff --git a/GeneralsMD/Code/Data/Scenarios/squad30.txt b/GeneralsMD/Code/Data/Scenarios/squad30.txt
new file mode 100644
index 000000000..97ddb93f1
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/squad30.txt
@@ -0,0 +1,20 @@
+# Squad stop probe: how often does a unit on the march stand still for a second?
+#
+# A player-sized army (20 Crusaders, 10 Rangers) given one right click to the enemy start. The
+# arrive lines count who got there and, in HEADLESS STALL, every stop of a second or more on the
+# way, split by what the unit was doing when it stopped: held back by the repath guard, queued for
+# a route, blocked by something in front, or none of those.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -randommap 3 2 small -autoskirmish 2 -takeover -seed 1 -maxframes 4000 -peacetime 10
+# -scenario squad30 -logPrefix squad_
+#
+# Seeds 1-5 and 7-9, 2026-09-19: 53 stops (25 held back, 27 blocked) before the bump limit could
+# recover in contact, 48 (28 held back, 19 blocked) after; 12 (2 held back, 9 blocked) once tanks
+# stopped shoving marching infantry aside. Last arrival 2006 -> 1807 -> 1733 frames.
+
+30 spawn 0 AmericaTankCrusader 20 start0:0:300 40
+30 spawn 0 AmericaInfantryRanger 10 start0:300:0 20
+90 playermove 0 * start1
+90 arrive 0 AmericaTankCrusader start1 250
+90 arrive 0 AmericaInfantryRanger start1 250
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
index 13186873e..11279aeda 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
@@ -542,7 +542,10 @@ private:
#define PATHFIND_CELL_SIZE 10
#define PATHFIND_CELL_SIZE_F 10.0f
-enum { PATHFIND_QUEUE_LEN=512};
+// One slot per object that can ask (queueForPath refuses a second), so this has to outnumber
+// everything that paths at once. Retail 512 was under the lobby's 840-unit limit: one order to 841
+// units left 329 of them waiting for a path that was never queued.
+enum { PATHFIND_QUEUE_LEN=2048};
struct TCheckMovementInfo;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
index 477dde2a4..8f0716e67 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
@@ -740,6 +740,9 @@ public:
inline Int getTmpValue(void) {return m_tmpInt;}
inline Bool getRetryPath(void) {return m_retryPath;}
+ inline Bool didPathfindFindNothing(void) const {return m_pathfindFoundNothing;}
+ void queueForPathOrRetry(void); ///< join the pathfind queue, or try again shortly when it is full
+ UnsignedInt getQueueForPathFrame(void) const {return m_queueForPathFrame;} ///< nonzero while a too-quick path request is held back
inline void setAllowedToChase( Bool allow ) { m_allowedToChase = allow; }
inline Bool isAllowedToChase() const { return m_allowedToChase; }
@@ -945,6 +948,7 @@ private:
Bool m_isRecruitable; ///< TRUE if recruitable by the ai.
Bool m_executingWaypointQueue; ///< if true, we are moving thru the waypoints
Bool m_retryPath; ///< If true, we need to try the path a second time. jba.
+ Bool m_pathfindFoundNothing; ///< The last ground search, closest-path fallback included, returned no path.
Bool m_allowedToChase; ///< Allowed to pursue targets.
Bool m_isInUpdate; ///< If true, we are inside our update method.
Bool m_fixLocoInPostProcess;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 3c3d4de64..02fcfe0f6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -65,7 +65,8 @@ enum ScenarioActionType
SCENARIO_ACTION_STOP, ///< stop <slot> <selector>
SCENARIO_ACTION_ARRIVE, ///< arrive <slot> <selector> <position> [radius]
SCENARIO_ACTION_PARTICLES, ///< particles <slot> <systemTemplate> <count> <position> [spacing]; slot is read and ignored
- SCENARIO_ACTION_ENTER ///< enter <slot> <selector> <targetSlot> <targetSelector>
+ SCENARIO_ACTION_ENTER, ///< enter <slot> <selector> <targetSlot> <targetSelector>
+ SCENARIO_ACTION_PLAYERMOVE ///< playermove <slot> <selector> <position>; a right click, not a script order
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 563e3f58b..4e88c00fa 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -7045,7 +7045,10 @@ void Pathfinder::floodGroupGoals(const Coord3D *dest, const std::vector<Object *
}
}
- if (!isStandable && head > 0)
+ /* Until somebody has a cell the flood goes through anything, because a click on a building
+ or into a lake has no standable neighbour and used to hand the whole group nothing: every
+ member was sent at the building itself. Once the first goal is out, a cliff stops it. */
+ if (!isStandable && unplacedCount < memberCount)
continue;
for (Int dy = -1; dy <= 1; dy++)
{
@@ -7316,7 +7319,7 @@ Bool Pathfinder::queueForPath(ObjectID id)
nextSlot = 0;
}
if (nextSlot==m_queuePRHead) {
- DEBUG_CRASH(("Ran out of pathfind queue slots."));
+ DEBUG_LOG(("PATHFIND QUEUE FULL: object %d asks again shortly\n", id));
return false;
}
m_queuedPathfindRequests[m_queuePRTail] = id;
@@ -7575,6 +7578,10 @@ void Pathfinder::processPathfindQueue(void)
the searches themselves 25,202 to 21,995 - a unit whose request waits a frame often no longer
needs the second, third and fourth repath it used to make while jammed. Two is a shade faster
still and the movement gives way: blocked back up to 8,531, units left stuck 12 to 21. */
+ /* Tried against an 841-unit order, 2026-09-19: one extra request a frame for every sixteen
+ waiting answered the backlog sooner and made the army leave later, the last unit 23.2 s after
+ the order against 19.1 s, with one of them never arriving. The back of a packed army waits for
+ the front to clear, not for its path, and more paths at once is more units shoving. */
enum { PATHFIND_REQUESTS_PER_FRAME = 3 };
Int requestsThisFrame = 0;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 30c3e9b92..1839fd2da 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -1641,7 +1641,7 @@ StateReturnType AIInternalMoveToState::onEnter()
}
}
m_tryOneMoreRepath = true; // We may try one more repath after the first one is finished.
- ai->friend_startingMove();
+ ai->friend_startingMove();
// get object physics state
PhysicsBehavior *physics = obj->getPhysics();
@@ -1800,8 +1800,20 @@ StateReturnType AIInternalMoveToState::update()
/// @todo srj -- find a way to sleep for a number of frames here, if possible
return STATE_CONTINUE;
}
- if (thePath==NULL)
+ if (thePath==NULL)
{
+ /* An empty path here is usually not the pathfinder's answer. A unit shoved aside by a
+ neighbour runs AIMoveOutOfTheWayState on top of this order, and that state destroys the
+ path when it ends; if this order was waiting for a repath at that moment, the path it was
+ waiting for is gone and it used to give up and stand. In a big selection units shove each
+ other all the way, and 120 units ordered across a small map left 7 of them idle halfway.
+ So a path that was found and then lost is asked for again, as often as it is lost; only
+ the pathfinder coming back with nothing ends the move. */
+ if (!ai->didPathfindFindNothing())
+ {
+ computePath();
+ return STATE_CONTINUE;
+ }
//Kris: 7/01/03 (Temporary debug hook for units not being able to leave maps)
if( blah )
{
@@ -1890,7 +1902,7 @@ StateReturnType AIInternalMoveToState::update()
if (forceRecompute || !isSamePosition(obj->getPosition(), &m_pathGoalPosition, &m_goalPosition ))
{
// goal moved - repath
- if (!computePath())
+ if (!computePath())
{
//Kris: 7/01/03 (Temporary debug hook for units not being able to leave maps)
if( blah )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 382d76ae2..78069678f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -388,6 +388,7 @@ AIUpdateInterface::AIUpdateInterface( Thing *thing, const ModuleData* moduleData
// state or an attack move turns it on for as long as it lasts.
m_allowedToChase = FALSE;
m_retryPath = FALSE;
+ m_pathfindFoundNothing = FALSE;
m_isInUpdate = FALSE;
m_fixLocoInPostProcess = FALSE;
@@ -507,7 +508,7 @@ void AIUpdateInterface::doPathfind( PathfindServicesInterface *pathfinder )
return;
}
//CRCDEBUG_LOG(("AIUpdateInterface::doPathfind() for object %d\n", getObject()->getID()));
- m_waitingForPath = FALSE;
+ m_waitingForPath = FALSE;
if (m_isSafePath) {
destroyPath();
Coord3D pos1, pos2;
@@ -525,6 +526,7 @@ void AIUpdateInterface::doPathfind( PathfindServicesInterface *pathfinder )
getObject()->getPosition(),
&pos1, &pos2,
getObject()->getVisionRange() + TheAI->getAiData()->m_repulsedDistance);
+ m_pathfindFoundNothing = (m_path == NULL);
return;
}
if (m_isApproachPath & !isDoingGroundMovement()) {
@@ -534,6 +536,7 @@ void AIUpdateInterface::doPathfind( PathfindServicesInterface *pathfinder )
destroyPath();
m_path = pathfinder->findClosestPath(getObject(), m_locomotorSet, getObject()->getPosition(),
&m_requestedDestination, m_isBlockedAndStuck, 0.2f, FALSE );
+ m_pathfindFoundNothing = (m_path == NULL);
if (isDoingGroundMovement() && getPath()) {
TheAI->pathfinder()->updateGoal(getObject(), getPath()->getLastNode()->getPosition(),
getPath()->getLastNode()->getLayer());
@@ -545,7 +548,9 @@ void AIUpdateInterface::doPathfind( PathfindServicesInterface *pathfinder )
if (m_requestedVictimID != INVALID_ID) {
victim = TheGameLogic->findObjectByID(m_requestedVictimID);
}
- if (computeAttackPath(pathfinder, victim, &m_requestedDestination)) {
+ if (computeAttackPath(pathfinder, victim, &m_requestedDestination)) {
+ // in range already comes back with no path, and the approach state still ends on that
+ m_pathfindFoundNothing = (m_path == NULL);
if (getPath()) {
TheAI->pathfinder()->updateGoal(getObject(), getPath()->getLastNode()->getPosition(),
getPath()->getLastNode()->getLayer());
@@ -620,7 +625,7 @@ void AIUpdateInterface::requestPath( Coord3D *destination, Bool isFinalGoal )
}
return;
}
- TheAI->pathfinder()->queueForPath(getObject()->getID());
+ queueForPathOrRetry();
}
@@ -644,7 +649,7 @@ void AIUpdateInterface::requestAttackPath( ObjectID victimID, const Coord3D* vic
setLocomotorGoalNone();
return;
}
- TheAI->pathfinder()->queueForPath(getObject()->getID());
+ queueForPathOrRetry();
}
//-------------------------------------------------------------------------------------------------
@@ -667,7 +672,7 @@ void AIUpdateInterface::requestApproachPath( Coord3D *destination )
setQueueForPathTime(2*LOGICFRAMES_PER_SECOND);
return;
}
- TheAI->pathfinder()->queueForPath(getObject()->getID());
+ queueForPathOrRetry();
}
//-------------------------------------------------------------------------------------------------
@@ -691,7 +696,7 @@ void AIUpdateInterface::requestSafePath( ObjectID repulsor )
setQueueForPathTime(2*LOGICFRAMES_PER_SECOND);
return;
}
- TheAI->pathfinder()->queueForPath(getObject()->getID());
+ queueForPathOrRetry();
}
enum {WAYPOINT_PATH_LIMIT=1024};
@@ -1090,6 +1095,16 @@ void AIUpdateInterface::setQueueForPathTime(Int frames)
m_queueForPathFrame = frames ? (TheGameLogic->getFrame() + frames) : 0;
}
+//-------------------------------------------------------------------------------------------------
+/* A full pathfind queue refuses the request, and every caller used to carry on waiting for a path
+ nobody was going to find: the unit stood there for the rest of the match. Refused, it asks
+ again half a second later through the same timer a too-quick repath uses. */
+void AIUpdateInterface::queueForPathOrRetry()
+{
+ if (!TheAI->pathfinder()->queueForPath(getObject()->getID()))
+ setQueueForPathTime(LOGICFRAMES_PER_SECOND / 2);
+}
+
//-------------------------------------------------------------------------------------------------
void AIUpdateInterface::wakeUpNow()
{
@@ -1225,10 +1240,10 @@ UpdateSleepTime AIUpdateInterface::update( void )
UnsignedInt now = TheGameLogic->getFrame();
if (m_queueForPathFrame != 0)
{
- if (now >= m_queueForPathFrame)
+ if (now >= m_queueForPathFrame)
{
- TheAI->pathfinder()->queueForPath(getObject()->getID());
setQueueForPathTime(0);
+ queueForPathOrRetry();
}
else
{
@@ -1483,6 +1498,19 @@ Bool AIUpdateInterface::blockedBy(Object *other)
Real dy = pos.y-otherPos.y;
Real curDSqr = dx*dx+dy*dy;
+ /* A foot soldier marching our way is not in our way. A vehicle blocked by an ally on foot tells him
+ to step aside, and a soldier who steps aside loses his own route and stands for a second before
+ the repath guard lets him ask for another: in a 30-unit mixed squad every one of the 28 stops of
+ that kind was a Ranger shoved by a Crusader going the same way. The vehicle drives through him
+ instead, the way infantry already walks through infantry. One standing still, or crossing, is
+ still asked to move. */
+ if (!obj->isKindOf(KINDOF_INFANTRY) && other->isKindOf(KINDOF_INFANTRY) && otherMoving) {
+ const Coord3D *ourDir = obj->getUnitDirectionVector2D();
+ const Coord3D *theirDir = other->getUnitDirectionVector2D();
+ if (ourDir->x*theirDir->x + ourDir->y*theirDir->y > 0.5f)
+ return FALSE;
+ }
+
if (obj->isKindOf(KINDOF_INFANTRY) && other->isKindOf(KINDOF_INFANTRY)) {
// Infantry doesn't tend to impede other infantry...
#ifdef INFANTRY_MOVES_THROUGH_INFANTRY
@@ -1752,7 +1780,7 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other
// Just wait.
}
}
- else
+ else
{
// We are rotating, so don't accumulate blocked frames.
m_blockedFrames = 1;
@@ -1966,6 +1994,7 @@ Bool AIUpdateInterface::computePath( PathfindServicesInterface *pathServices, Co
// search fail rather than merely route differently.
if (theNewPath == NULL)
Pathfinder::bumpNoPath();
+ m_pathfindFoundNothing = (theNewPath == NULL);
if (theNewPath) {
// destroy previous path
destroyPath();
@@ -3757,11 +3786,25 @@ UpdateSleepTime AIUpdateInterface::doLocomotor( void )
if (blocked && speed>m_curMaxBlockedSpeed)
{
speed = m_curMaxBlockedSpeed;
+ /* The bump limit used to shrink by 5% every frame of contact and never grow while
+ contact lasted, so once a blocker had stood still for a moment it sat at zero: the
+ tank in front drove off at full speed and the one touching it stayed parked until
+ the bodies came apart, then crept back up from a fifth of its speed. Traced on a
+ Crusader, 17 frames at a limit of 0.000 while the speed it was allowed rose from
+ 0.02 to 0.55. It now recovers towards what the blocker allows, the same way it
+ recovers out of contact, and drives at 95% of it so the gap still opens. */
if (m_bumpSpeedLimit>speed) {
m_bumpSpeedLimit = speed;
+ } else {
+ if (m_bumpSpeedLimit<speed*0.2f) {
+ m_bumpSpeedLimit = speed*0.2f;
+ }
+ m_bumpSpeedLimit *= 1.05f;
+ if (m_bumpSpeedLimit>speed) {
+ m_bumpSpeedLimit = speed;
+ }
}
- m_bumpSpeedLimit *= 0.95f;
- speed = m_bumpSpeedLimit;
+ speed = m_bumpSpeedLimit * 0.95f;
}
else
{
@@ -6818,12 +6861,13 @@ void AIUpdateInterface::crc( Xfer *x )
* 5: the production rally point and its flag
* 6: the out-of-bounds xfer of m_guardTargetType is fixed
* 11: m_isMoving, which the duplicated m_isSafePath used to stand in place of
- * 12: m_allowedToChase */
+ * 12: m_allowedToChase
+ * 13: m_pathfindFoundNothing */
// ------------------------------------------------------------------------------------------------
void AIUpdateInterface::xfer( Xfer *xfer )
{
// version
- const XferVersion currentVersion = 12;
+ const XferVersion currentVersion = 13;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -7112,6 +7156,11 @@ void AIUpdateInterface::xfer( Xfer *xfer )
xfer->xferReal(&m_crowdLaneSpace);
}
+ if (version >= 13)
+ {
+ // lives from one path search to the move state's next look at it, which a save can fall between
+ xfer->xferBool(&m_pathfindFoundNothing);
+ }
} // end xfer
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 708d665d6..8c4cebeb3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -155,6 +155,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_SPAWN;
else if (token == "move")
*action = SCENARIO_ACTION_MOVE;
+ else if (token == "playermove")
+ *action = SCENARIO_ACTION_PLAYERMOVE;
else if (token == "attackmove")
*action = SCENARIO_ACTION_ATTACKMOVE;
else if (token == "attack")
@@ -241,6 +243,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_SPAWN: return SCENARIO_TOKENS_SPAWN;
case SCENARIO_ACTION_PARTICLES: return SCENARIO_TOKENS_SPAWN;
case SCENARIO_ACTION_MOVE: return SCENARIO_TOKENS_MOVE;
+ case SCENARIO_ACTION_PLAYERMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACKMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;
@@ -306,6 +309,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
}
case SCENARIO_ACTION_MOVE:
+ case SCENARIO_ACTION_PLAYERMOVE:
case SCENARIO_ACTION_ATTACKMOVE:
case SCENARIO_ACTION_ARRIVE:
{
@@ -377,8 +381,29 @@ struct ScenarioArrival
UnsignedInt fromFrame;
std::vector<ObjectID> ids;
std::vector<UnsignedInt> arrivedOn;
+ std::vector<Coord3D> startedAt; ///< where each stood when the line fired
+ std::vector<UnsignedInt> departedOn; ///< the frame each first stood SCENARIO_DEPARTED_DISTANCE from there
+ std::vector<Coord3D> lastSeenAt; ///< where each stood on the frame before
+ std::vector<Int> stillFor; ///< frames each has stood still since it last moved
+ // Stops on the way: a unit that has left and not arrived standing still for SCENARIO_STALL_FRAMES,
+ // counted once per stop by what it was doing at that moment.
+ Int stallsIdle; ///< gave the order up
+ Int stallsHeldBack; ///< its path request held back a second for coming too soon after the last
+ Int stallsWaitingForPath; ///< still waiting in the queue for its route
+ Int stallsBlocked; ///< blocked by something in front
+ Int stallsOther; ///< has a route, is not blocked, and is not moving
+ Int longestStall;
+ ObjectID longestStallID;
};
+/// how long a unit on its way has to stand still before it counts as having stopped
+static const Int SCENARIO_STALL_FRAMES = LOGICFRAMES_PER_SECOND;
+/// less than this from one frame to the next is standing still
+static const Real SCENARIO_STILL_DISTANCE = 0.05f;
+
+/// how far a unit has to have gone from where it stood before it counts as having obeyed the order
+static const Real SCENARIO_DEPARTED_DISTANCE = 20.0f;
+
static std::vector<ScenarioArrival> theScenarioArrivals;
static void resetScenario( void )
@@ -682,7 +707,18 @@ static Bool executeArrive( const ScenarioAction &action, Player *player, const C
arrival.ids.push_back( obj->getID() );
arrival.arrivedOn.push_back( SCENARIO_NOT_ARRIVED );
+ arrival.startedAt.push_back( *obj->getPosition() );
+ arrival.departedOn.push_back( SCENARIO_NOT_ARRIVED );
+ arrival.lastSeenAt.push_back( *obj->getPosition() );
+ arrival.stillFor.push_back( 0 );
}
+ arrival.stallsIdle = 0;
+ arrival.stallsHeldBack = 0;
+ arrival.stallsWaitingForPath = 0;
+ arrival.stallsBlocked = 0;
+ arrival.stallsOther = 0;
+ arrival.longestStall = 0;
+ arrival.longestStallID = INVALID_ID;
DEBUG_LOG(("SCENARIO: frame %d arrive slot %d '%s' x%d within %.0f of (%.0f,%.0f)\n",
action.frame, action.slot, action.selector.str(), (Int)arrival.ids.size(),
@@ -710,6 +746,41 @@ static void updateArrivals( UnsignedInt now )
if (obj == NULL || obj->isEffectivelyDead())
continue;
+ if (it->departedOn[ i ] == SCENARIO_NOT_ARRIVED)
+ {
+ const Real mx = obj->getPosition()->x - it->startedAt[ i ].x;
+ const Real my = obj->getPosition()->y - it->startedAt[ i ].y;
+ if (mx * mx + my * my >= SCENARIO_DEPARTED_DISTANCE * SCENARIO_DEPARTED_DISTANCE)
+ it->departedOn[ i ] = now;
+ }
+ else
+ {
+ const Real sx = obj->getPosition()->x - it->lastSeenAt[ i ].x;
+ const Real sy = obj->getPosition()->y - it->lastSeenAt[ i ].y;
+ if (sx * sx + sy * sy >= SCENARIO_STILL_DISTANCE * SCENARIO_STILL_DISTANCE)
+ it->stillFor[ i ] = 0;
+ else if (++it->stillFor[ i ] == SCENARIO_STALL_FRAMES)
+ {
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ if (ai->isIdle())
+ ++it->stallsIdle;
+ else if (ai->isWaitingForPath() && ai->getQueueForPathFrame() != 0)
+ ++it->stallsHeldBack;
+ else if (ai->isWaitingForPath())
+ ++it->stallsWaitingForPath;
+ else if (ai->getNumFramesBlocked() > 0 || ai->isBlockedAndStuck())
+ ++it->stallsBlocked;
+ else
+ ++it->stallsOther;
+ }
+ if (it->stillFor[ i ] > it->longestStall)
+ {
+ it->longestStall = it->stillFor[ i ];
+ it->longestStallID = obj->getID();
+ }
+ }
+ it->lastSeenAt[ i ] = *obj->getPosition();
+
const Real dx = obj->getPosition()->x - it->goal.x;
const Real dy = obj->getPosition()->y - it->goal.y;
if (dx * dx + dy * dy <= radiusSquared)
@@ -727,12 +798,14 @@ void ScenarioDrill_logArrivals( void )
Int lost = 0;
UnsignedInt first = SCENARIO_NOT_ARRIVED;
UnsignedInt last = 0;
+ Real arrivalSum = 0.0f;
for( size_t i = 0; i < it->ids.size(); ++i )
{
const UnsignedInt on = it->arrivedOn[ i ];
if (on != SCENARIO_NOT_ARRIVED)
{
++arrived;
+ arrivalSum += (Real)(on - it->fromFrame);
first = (on < first) ? on : first;
last = (on > last) ? on : last;
continue;
@@ -740,11 +813,42 @@ void ScenarioDrill_logArrivals( void )
Object *obj = TheGameLogic->findObjectByID( it->ids[ i ] );
if (obj == NULL || obj->isEffectivelyDead())
+ {
++lost;
+ continue;
+ }
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ DEBUG_LOG(("HEADLESS STRAGGLER: '%s' id %d at (%.0f,%.0f), state %d idle %d moving %d waiting %d path %d\n",
+ it->selector.str(), obj->getID(), obj->getPosition()->x, obj->getPosition()->y,
+ ai->getCurrentStateID(), ai->isIdle(), ai->isMoving(), ai->isWaitingForPath(), ai->getPath() != NULL));
}
const Int total = (Int)it->ids.size();
const Int stillOut = total - arrived - lost;
+
+ // how long the last of them stood before it obeyed; the order is only as quick as that
+ Int departed = 0;
+ UnsignedInt lastDeparture = 0;
+ for( size_t i = 0; i < it->ids.size(); ++i )
+ {
+ if (it->departedOn[ i ] == SCENARIO_NOT_ARRIVED)
+ continue;
+ ++departed;
+ lastDeparture = (it->departedOn[ i ] > lastDeparture) ? it->departedOn[ i ] : lastDeparture;
+ }
+ DEBUG_LOG(("HEADLESS DEPART: slot %d '%s' from frame %d: %d of %d moved %.0f, the last after %d frames (%.1f s)\n",
+ it->slot, it->selector.str(), it->fromFrame, departed, total, SCENARIO_DEPARTED_DISTANCE,
+ departed ? (Int)(lastDeparture - it->fromFrame) : 0,
+ departed ? (Real)(lastDeparture - it->fromFrame) / (Real)LOGICFRAMES_PER_SECOND : 0.0f));
+
+ DEBUG_LOG(("HEADLESS STALL: slot %d '%s': %d stops of %.0f s or more on the way - %d idle, %d held back, %d waiting for a path, %d blocked, %d with a path and no reason; longest %d frames (%.1f s), unit %d\n",
+ it->slot, it->selector.str(),
+ it->stallsIdle + it->stallsHeldBack + it->stallsWaitingForPath + it->stallsBlocked + it->stallsOther,
+ (Real)SCENARIO_STALL_FRAMES / (Real)LOGICFRAMES_PER_SECOND,
+ it->stallsIdle, it->stallsHeldBack, it->stallsWaitingForPath, it->stallsBlocked, it->stallsOther,
+ it->longestStall, (Real)it->longestStall / (Real)LOGICFRAMES_PER_SECOND,
+ (Int)it->longestStallID));
+
if (arrived == 0)
{
DEBUG_LOG(("HEADLESS ARRIVE: slot %d '%s' from frame %d: none of %d within %.0f of (%.0f,%.0f), %d lost, %d still out\n",
@@ -753,9 +857,9 @@ void ScenarioDrill_logArrivals( void )
continue;
}
- DEBUG_LOG(("HEADLESS ARRIVE: slot %d '%s' from frame %d: %d of %d within %.0f of (%.0f,%.0f), first after %d frames, last after %d frames (%.1f s), %d lost, %d still out\n",
+ DEBUG_LOG(("HEADLESS ARRIVE: slot %d '%s' from frame %d: %d of %d within %.0f of (%.0f,%.0f), first after %d frames, mean %.0f, last after %d frames (%.1f s), %d lost, %d still out\n",
it->slot, it->selector.str(), it->fromFrame, arrived, total, it->radius, it->goal.x, it->goal.y,
- first - it->fromFrame, last - it->fromFrame,
+ first - it->fromFrame, arrivalSum / (Real)arrived, last - it->fromFrame,
(Real)(last - it->fromFrame) / (Real)LOGICFRAMES_PER_SECOND, lost, stillOut));
}
}
@@ -776,16 +880,21 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
switch (action.action)
{
case SCENARIO_ACTION_MOVE:
+ case SCENARIO_ACTION_PLAYERMOVE:
case SCENARIO_ACTION_ATTACKMOVE:
{
+ // A player's move takes a different branch of groupMoveToPosition (every member gathers on
+ // the clicked point), so a script order cannot stand in for a right click.
if (action.action == SCENARIO_ACTION_MOVE)
group->groupMoveToPosition( &dest, FALSE, CMD_FROM_SCRIPT );
+ else if (action.action == SCENARIO_ACTION_PLAYERMOVE)
+ group->groupMoveToPosition( &dest, FALSE, CMD_FROM_PLAYER );
else
group->groupAttackMoveToPosition( &dest, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );
DEBUG_LOG(("SCENARIO: frame %d %s slot %d '%s' x%d to (%.0f,%.0f)\n",
action.frame,
- (action.action == SCENARIO_ACTION_MOVE) ? "move" : "attackmove",
+ (action.action == SCENARIO_ACTION_ATTACKMOVE) ? "attackmove" : "move",
action.slot, action.selector.str(), taken, dest.x, dest.y));
break;
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DVolumetricShadow.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DVolumetricShadow.h
index cc87bb446..2540f06ea 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DVolumetricShadow.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DVolumetricShadow.h
@@ -182,6 +182,7 @@ class W3DVolumetricShadow : public Shadow
Int m_shadowVolumeCount[MAX_SHADOW_CASTER_MESHES]; // how man shadows are valid in m_shadowVolume
Vector3 m_lightPosHistory[ MAX_SHADOW_LIGHTS ][MAX_SHADOW_CASTER_MESHES];
Matrix4x4 m_objectXformHistory[ MAX_SHADOW_LIGHTS ][MAX_SHADOW_CASTER_MESHES];
+ UnsignedInt m_skinRebuiltOnFrame[ MAX_SHADOW_LIGHTS ][MAX_SHADOW_CASTER_MESHES]; ///< render frame a skinned volume was last rebuilt on
// silhouette building space
Short *m_silhouetteIndex[MAX_SHADOW_CASTER_MESHES]; // silhouette vertex index list, edges occur
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 6d0cd8180..12df84a40 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -1906,6 +1906,7 @@ W3DVolumetricShadow::W3DVolumetricShadow( void )
m_shadowVolumeRenderTask[i][j].m_lightIndex = (UnsignedByte)i;
m_objectXformHistory[ i ][j].Make_Identity();
m_lightPosHistory[ i ][j] = Vector3(0,0,0);
+ m_skinRebuiltOnFrame[ i ][j] = 0;
}
} // end for i
@@ -2377,6 +2378,34 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, MeshCl
if (isSkin)
isMeshRotating = true;
+ /* That rebuild is the most expensive thing a shadow does, and an army of infantry asks for it
+ once per soldier per frame: 420 Rangers on screen were a tenth of the frame in shadows alone.
+ So a frame rebuilds at most SKIN_SHADOW_REBUILDS_PER_FRAME skinned volumes, and any past that
+ keep last frame's pose, but never one older than SKIN_SHADOW_MAX_AGE_FRAMES: a stale one is
+ rebuilt whatever the budget says, which bounds how far a shadow's arms can lag its body. The
+ volume still moves with the unit either way; only the pose waits. Drawing only, so the logic
+ never sees it. */
+ if (isSkin && !isLightMoving && m_shadowVolume[ lightIndex ][meshIndex])
+ {
+ enum { SKIN_SHADOW_REBUILDS_PER_FRAME = 64, SKIN_SHADOW_MAX_AGE_FRAMES = 6 };
+ static UnsignedInt s_budgetFrame = 0;
+ static Int s_rebuildsThisFrame = 0;
+ const UnsignedInt frame = WW3D::Get_Frame_Count();
+ if (frame != s_budgetFrame)
+ {
+ s_budgetFrame = frame;
+ s_rebuildsThisFrame = 0;
+ }
+ const Bool isStale = frame - m_skinRebuiltOnFrame[ lightIndex ][meshIndex] >= SKIN_SHADOW_MAX_AGE_FRAMES;
+ if (!isStale && s_rebuildsThisFrame >= SKIN_SHADOW_REBUILDS_PER_FRAME)
+ isMeshRotating = false;
+ else
+ {
+ ++s_rebuildsThisFrame;
+ m_skinRebuiltOnFrame[ lightIndex ][meshIndex] = frame;
+ }
+ }
+
// reconstruct if needed
if (isLightMoving || isMeshRotating)
{