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): pass round the outside of the pack, not into an occupied lane

Olcay Seygan3dd1597973e9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2eaba9e9c..7e7152f3a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -628,6 +628,7 @@ found and fixed — EA's own, not port damage.**
- Vehicles walked off the side of bridges and queued up beside the entrance to them instead of driving on. A unit driving in a crowd holds a line a set distance off the middle of the road, and the road's width is measured by asking the ground either side whether a tank fits on it. On a bridge that question was being asked of the riverbank underneath. So the road read as sixty feet wide over a deck barely wide enough for two tanks, and a line held a body width off centre walked a column into the water - and on the approach, the same line put the leading tank against the abutment rather than the entrance, with everybody behind it stopped on the bank. The width is now measured on the deck the route actually runs over, and both the bridge and sixty feet of road each side of it have no width at all: every unit drives the middle of the road across a bridge, which is what the crossing is for. Coming at the entrance from an angle used to jam anyway, and that was the rescue rule doing it. A unit that has been getting nowhere for two seconds backs out sideways and tries the road again from there, and the riverbank beside an abutment is perfectly good ground to back out onto - so the vehicle left the only queue that leads onto the bridge and then had to fight its way back into it. On a bridge and its approach it now backs straight up instead, and keeps its place.
- Infantry can walk through infantry again, and a squad arrives as a squad. Soldiers have always been able to share ground in this game, and the crowd rules had quietly taken that back: a platoon sent across a field pulled itself into a rank sixty feet wide, every man of it braking, giving way and shuffling sideways for a crowd he was supposed to walk straight into. Foot soldiers are now outside the crowd model on both sides of the question. They keep to one line and follow it, and a tank no longer brakes for a rifleman it is about to drive through.
- A tank that cannot get past goes round on whatever room there is, rather than settling in behind. Two things used to send it to the back of the queue when a foot of road either side would have let it out. It would not change lanes within a second and a half of the last time it changed lanes, which is exactly the vehicle that just gave way to somebody and is now stuck behind the next one along; and it wanted six feet of air beside the vehicle it was passing or it would not go at all. A unit that has been queueing for a third of a second now asks again regardless, and settles for a body and a half of air if that is what the road has. The comfortable pass is still tried on both sides first, so nothing squeezes past where there was room to go round properly. Units also start spreading out at the back of a jam after a third of a second instead of a full second.
+- A tank going round now goes round the outside of the crowd, not into the middle of it. The pass only ever asked whether the road reached the spot beside the vehicle in front; it never asked whether anything was standing there. In a group six abreast every such spot is another tank, so the unit aimed at one, was shoved back out of it, and queued inside its own group - which is what it looked like on screen. It now knows where its neighbours sit across the road, refuses any line one of them is already on, and has the outer edge of the whole pack as a third choice between the comfortable pass and the tight one. With a single vehicle in front the outside of the pack and the tight pass beside it are the same line, so an ordinary overtake is unchanged.
- None of the crowd was being measured, and the numbers written here for it were another rule's. A unit steers as part of a crowd only if it was handed a line across the road, a line is handed out only by the order a player gives to a selection, and a computer opponent never gives that order: it moves its teams one vehicle at a time. So every self-play batch run to argue about the crowd was driving the two rules that live in the collision code and none of the steering. The harness now has a switch that hands every army on the map one group order every twenty seconds, to alternating corners. The match it produces is nonsense and its result says nothing, but it multiplies the time units spend standing still by fourteen, from around 300 unit-frames a match to 4,200, which is the proof it is finally creating the traffic the crowd was written for.
- With the traffic there, the crowd steering does not pay for itself. Thirty-nine battles paired map by map: time spent standing behind another unit 4,444 unit-frames a match with the rules off against 4,787 with them on, 7.7% worse, eleven maps better and twenty worse. The middle map moved by 19 unit-frames either way, so that average is four bad maps carrying thirty-five that barely noticed. What it does fix is the thing it was asked to fix. Units left properly stuck fell from 3.0 a match to 1.4, and the maps that moved are the pathological ones: 62 units wedged for good down to none, 35 down to none, 7 down to none. It creates new ones elsewhere, one map going from 5 to 34. The switch stays off, and what needs explaining now is the four maps, not the average.
- Since the first attempt at the band failed silently and passed every test it had, the band can now be drawn. A switch puts each moving unit's route on the ground in blue, the line it holds as a yellow mark sideways from the unit, and the offset that survived as a green mark from the route out to where the unit is actually aiming. The three failures that look identical from the camera - a line never given out, a line given out and dropped on the way, a line applied but too small to see - are three different pictures under it, and the same run writes them to the log as well.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 3b4fe697c..aa110f749 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -2621,6 +2621,18 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
Real joinerR = 0.0f;
Real joinerWhen = 1.0e9f;
+ /* Where the traffic in front of us sits across the road, which is the question a pass has to ask
+ and used to not. A pass aimed a body and a half clear of the unit directly ahead is aimed at
+ whatever is standing beside that unit, and in a pack six wide every such slot is taken: the
+ unit picks one, gets shoved back out of it by the collision push, and queues in the middle of
+ its own group instead of going round the outside of it. */
+ enum { CROWD_NEAR_MAX = 16 };
+ Real nearLat[CROWD_NEAR_MAX]; // each neighbour's line across the road
+ Real nearR[CROWD_NEAR_MAX];
+ Int nearCount = 0;
+ Real packLo = 0.0f, packHi = 0.0f; // the outside edges of the whole pack ahead
+ Bool packAny = FALSE;
+
PhysicsBehavior *myPhys = self->getPhysics();
Coord3D myVel;
myVel.zero();
@@ -2725,6 +2737,25 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
giveWay = TRUE;
}
+ /* Anything abreast or in front, wherever it sits across the road. This is the set the pass
+ below is aimed clear of, so it is deliberately wider than the "in our way" test under it:
+ the unit two lanes over is not blocking us and is exactly the one we must not aim at. */
+ if (fwd > -myR && fwd < lookAhead + hisR)
+ {
+ const Real hisLatHere = m_corridor->latOf( i, *hp );
+ if (nearCount < CROWD_NEAR_MAX)
+ {
+ nearLat[nearCount] = hisLatHere;
+ nearR[nearCount] = hisR;
+ ++nearCount;
+ }
+ const Real lo = hisLatHere - hisR;
+ const Real hi = hisLatHere + hisR;
+ if (!packAny || lo < packLo) packLo = lo;
+ if (!packAny || hi > packHi) packHi = hi;
+ packAny = TRUE;
+ }
+
// directly ahead, near enough to matter
if (fwd > 0.0f && fwd < lookAhead + hisR && fabs( side ) < myR + hisR + 1.0f)
{
@@ -2810,25 +2841,53 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
pass wants, and a road that has five is not a road you queue on: the tight figure is a
body and a half of air, which is still a pass and is still wider than the collision push
that would otherwise decide it. Full clearance is tried on both sides before the tight
- one is tried on either, so the comfortable pass still wins wherever there is room. */
+ one is tried on either, so the comfortable pass still wins wherever there is room.
+
+ Between those two comes going round the outside of the whole pack, and a candidate is
+ only taken if no neighbour is already sitting on it. Without that test the road is the
+ only thing consulted, so in a group six abreast the clear slot beside the blocker is
+ another tank and the pass is a swap of positions inside the same knot. With one unit in
+ front the outside of the pack and the tight pass beside him are the same line, so nothing
+ changes for the ordinary overtake; it is the pack that goes wide. */
Bool took = FALSE;
const Bool retry = m_crowdQueued > CROWD_PASS_RETRY;
if (now >= m_crowdHoldFrame || retry)
{
- for (Int c = 0; c < 2 && !took; c++)
+ const Real clearShift = myR + hisR + CROWD_PASS_CLEAR;
+ const Real tightShift = myR + hisR + CROWD_PASS_TIGHT;
+ const Real outside = myR + CROWD_PASS_TIGHT;
+
+ Real cands[6];
+ Int nCand = 0;
+ cands[nCand++] = hisLat + (Real)first * clearShift;
+ cands[nCand++] = hisLat - (Real)first * clearShift;
+ if (packAny)
{
- const Real shift = myR + hisR + ((c == 0) ? CROWD_PASS_CLEAR : CROWD_PASS_TIGHT);
- for (Int t = 0; t < 2 && !took; t++)
+ cands[nCand++] = (first > 0) ? (packHi + outside) : (packLo - outside);
+ cands[nCand++] = (first > 0) ? (packLo - outside) : (packHi + outside);
+ }
+ cands[nCand++] = hisLat + (Real)first * tightShift;
+ cands[nCand++] = hisLat - (Real)first * tightShift;
+
+ for (Int c = 0; c < nCand && !took; c++)
+ {
+ const Real want = cands[c];
+ if (fabs( m_corridor->clampLat( i, want ) - want ) >= 0.5f)
+ continue; // the road does not go there
+
+ Bool taken = FALSE;
+ for (Int n = 0; n < nearCount && !taken; n++)
{
- const Real want = hisLat + (Real)((t == 0) ? first : -first) * shift;
- if (fabs( m_corridor->clampLat( i, want ) - want ) < 0.5f)
- {
- lat = want;
- m_crowdSide = (want >= hisLat) ? 1 : -1;
- m_crowdHoldFrame = now + CROWD_HOLD_FRAMES;
- took = TRUE;
- }
+ if ((Real)fabs( nearLat[n] - want ) < myR + nearR[n])
+ taken = TRUE; // somebody is already in it
}
+ if (taken)
+ continue;
+
+ lat = want;
+ m_crowdSide = (want >= hisLat) ? 1 : -1;
+ m_crowdHoldFrame = now + CROWD_HOLD_FRAMES;
+ took = TRUE;
}
}