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): bridge approach, passing preference and infantry in the crowd model

Olcay Seygan94c14da68363
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67c9da9f2..145651d55 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -485,6 +485,14 @@ found and fixed — EA's own, not port damage.**
was given, so an open field is crossed as a wide front and a bridge squeezes the same units back
into a line without anybody deciding to queue. The width closes back onto the middle over the last
few squares, so everyone still parks where you sent them.
+- A group spreads into as many lanes as the road in front of it will take, and that number is now
+ measured rather than assumed. It used to come from the widest reading the game can give, whatever
+ the ground was: a dozen tanks on a two-lane road were handed a dozen lanes, every one of them
+ wider than the road, and each was then cut back to the nearest verge - which is a column pressed
+ into two files against the edges with nothing down the middle. The road is measured on both sides
+ at the group's own feet when the order is given, so a wide field is crossed abreast, a lane road
+ puts as many units side by side as it actually holds and the rest follow, and a route running
+ along a wall lays its lanes out in the room that exists instead of into the wall.
- The position a unit takes across that width is the one it already had. A group you dragged a box
round is spread out before it starts moving, and whoever was on the left of it stays on the left
the whole way there. The spread is proportional, so a selection two hundred feet across arrives as
@@ -617,8 +625,9 @@ found and fixed — EA's own, not port damage.**
- Moving over for someone and joining a road are the same manoeuvre from two sides, and the crowd now does both. A unit coming in at an angle used to be invisible until it was in front of you, at which point everybody braked; the units already on the road now see it crossing their line up to a second and a half ahead and shift a lane over instead, which is what turns a queue into a zipper. The test is a real closest approach rather than a cone, and the courtesy is only extended to traffic that would have made you brake anyway - anything looser and a column spends the whole march shuffling sideways for vehicles driving vaguely alongside it.
- Three ways of building that were measured and thrown away, one of them expensive. Slowing down by how far away the traffic in front is, rather than by whether it is being caught, costs 3518 unit-frames of standing still a battle against 1236. Slowing down behind a unit that is not moving at all costs 16593, and it is the worst kind of bug: braking short of a parked ally means the collision never happens, so nothing counts the unit as blocked and none of the machinery that would have sent it round fires. It dies politely, three feet behind a tank that is never going to move. And standing the rules down for short trips, on the theory that a four-square shuffle inside a fight is not a march, is three times worse than leaving them on: short trips are exactly where units are packed tightest.
- Light vehicles could not hold a straight line: the head of a scout shook the whole way down a road an Overlord drove dead straight. The point a unit steers at sat two cells and a body ahead, taken from whichever sample of the route it happened to be beside, and both halves of that were wrong for a fast chassis. Samples are a cell apart, so the point jumped ten feet forward each time the unit crossed one and the heading jumped with it; it is taken between samples now, off the unit's own unrounded distance along the route, and slides forward a foot at a time. The other half is that thirty feet of warning is forty frames of road for an Overlord and ten for a scout, so the light stuff was steering at something under its nose where a foot of error is a full lock. Two ways of fixing that second half were tried and both cost more than they were worth. Moving the point further out for fast vehicles cured the shake and left four times as many units stuck: a point fifty feet up the road is measured against the ground fifty feet up the road, and nobody asks about the narrow bit in between. Slowing the wheel for them instead - turning towards the new heading at a rate cut by how much road the chassis eats in half a second - was better mannered and still cost nearly four times the stuck units. Lag on the wheel and a point too far ahead fail the same way: both answer where the unit was a moment ago. The sliding point cures the shake on its own, so that is all that is in.
-- 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 forty 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.
-- Infantry can walk through infantry again. Two soldiers crossing have never blocked each other in this game - only two going the same way do - and the crowd rules had quietly taken that back: a squad crossing another squad read as a wall, and every man in it braked, gave way and shuffled sideways for a crowd he was supposed to walk straight into. The crowd now uses the game's own rule for that, so a column following a column is still traffic and two squads crossing pass through one another.
+- 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.
- 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/Include/GameLogic/CrowdModel.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h
index b6d941ff1..732944a90 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/CrowdModel.h
@@ -58,8 +58,11 @@ enum
/// a lane taken to get round somebody is held this long, so it cannot flap side to side
CROWD_HOLD_FRAMES = 45,
- /// how many samples either side of a bridge lose their band as well, so the approach funnels in
- CROWD_BRIDGE_SEAL = 4,
+ /* How many samples either side of a bridge lose their band as well, so the approach funnels in.
+ Six cells and not four: a unit that is still a lane wide of the centre when the band shuts is
+ a unit arriving at the abutment sideways, and the sideways step is rate-limited to a quarter
+ of its speed. The funnel has to be longer than the time that step takes. */
+ CROWD_BRIDGE_SEAL = 6,
/// how far ahead of itself a unit steers, in cells, before its own body length is added
CROWD_LOOKAHEAD_CELLS = 2
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index f6d4f0848..e8c48d6ea 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -1587,6 +1587,43 @@ static Bool laneSeedIsLeftOf( const LaneSeed& a, const LaneSeed& b )
return a.obj->getID() < b.obj->getID();
}
+/** How many lanes the road under a group actually carries, and where the middle of them sits.
+
+ The count used to come from a fixed reference width - the widest answer the probe can give,
+ regardless of the ground - and it was wrong in both directions. On a lane road it handed a
+ dozen tanks a dozen lanes, every one of them wider than the road, and the band then cut every
+ one of them back to the same two edges: a group pressed into two files against the verges with
+ nothing down the middle. On open country it stopped at whatever the reference happened to be
+ while the field went on. Two probes at the group's own feet, one each side, cost sixteen cell
+ lookups apiece and are taken once per order.
+
+ `bias` comes back as the offset of the middle of the drivable span from the centre line, which
+ is what keeps a route running along a wall from spreading into the wall: the room is measured
+ separately on the two sides and the lanes are laid out in the room that exists. */
+static Int crowdRoadLanes( Object *probe, const Coord3D& center, const Coord2D& dir, Real spacing,
+ Real *bias )
+{
+ Coord3D from = center;
+ from.z = TheTerrainLogic->getGroundHeight( from.x, from.y );
+
+ Coord2D left, right;
+ left.x = -dir.y; left.y = dir.x;
+ right.x = dir.y; right.y = -dir.x;
+
+ Pathfinder *pf = TheAI->pathfinder();
+ const LocomotorSet& locoSet = probe->getAIUpdateInterface()->getLocomotorSet();
+ const PathfindLayerEnum layer = probe->getLayer();
+ const Real leftRoom = pf->laneExtent( probe, locoSet, layer, &from, &left );
+ const Real rightRoom = pf->laneExtent( probe, locoSet, layer, &from, &right );
+
+ *bias = (leftRoom - rightRoom) * 0.5f;
+
+ // centres, so a span exactly one spacing wide is two lanes and a span of nothing is still one
+ Int lanes = (Int)((leftRoom + rightRoom) / spacing) + 1;
+ if (lanes < 1) lanes = 1;
+ return lanes;
+}
+
/** Hand every member of a group the distance it should sit off the centre of the road, for the
crowd model only.
@@ -1607,6 +1644,7 @@ static void crowdSeedLanes( std::list<Object *>& members, const Coord3D& center,
std::vector<LaneSeed> across;
Real spacing = 0.0f;
+ Object *widest = NULL;
for (std::list<Object *>::iterator it = members.begin(); it != members.end(); ++it)
{
Object *o = *it;
@@ -1621,7 +1659,10 @@ static void crowdSeedLanes( std::list<Object *>& members, const Coord3D& center,
const Real body = 2.0f * o->getGeometryInfo().getBoundingCircleRadius();
if (body > spacing)
+ {
spacing = body;
+ widest = o; // the road is measured for the biggest body in the group, not an average one
+ }
}
spacing *= 1.15f;
@@ -1632,19 +1673,20 @@ static void crowdSeedLanes( std::list<Object *>& members, const Coord3D& center,
std::sort( across.begin(), across.end(), laneSeedIsLeftOf );
- Int lanes = (Int)(2.0f * Pathfinder_laneReference() / spacing);
- if (lanes < 1) lanes = 1;
- if (lanes > count) lanes = count;
+ Real bias = 0.0f;
+ Int lanes = crowdRoadLanes( widest, center, dir, spacing, &bias );
+ if (lanes > count) lanes = count; // never more lanes than bodies to put in them
for (Int i = 0; i < count; i++)
{
const Int lane = (i * lanes) / count;
- const Real offset = ((Real)lane - (Real)(lanes - 1) * 0.5f) * spacing;
+ const Real offset = bias + ((Real)lane - (Real)(lanes - 1) * 0.5f) * spacing;
across[i].obj->getAIUpdateInterface()->setPendingCrowdLat( offset );
}
if (TheGlobalData->m_showLanes)
- DEBUG_LOG(("SHOWLANES crowdSeedLanes: members=%d lanes=%d spacing=%.1f\n", count, lanes, spacing));
+ DEBUG_LOG(("SHOWLANES crowdSeedLanes: members=%d lanes=%d spacing=%.1f bias=%.1f\n",
+ count, lanes, spacing, bias));
}
/**
@@ -1855,6 +1897,7 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com
std::vector<LaneSeed> across;
Real spacing = 0.0f;
+ Object *widest = NULL;
for (Object *o = iter->first(); o; o = iter->next())
{
if (o->getAIUpdateInterface() == NULL)
@@ -1868,7 +1911,10 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com
Real body = 2.0f * o->getGeometryInfo().getBoundingCircleRadius();
if (body > spacing)
+ {
spacing = body;
+ widest = o;
+ }
}
// a little air between bodies, or the lanes are exactly touching and the collision push
@@ -1880,8 +1926,20 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com
{
std::sort( across.begin(), across.end(), laneSeedIsLeftOf );
- Int lanes = (Int)(2.0f * Pathfinder_laneReference() / spacing);
- if (lanes < 1) lanes = 1;
+ /* Under -crowd the lane count is the road's, measured here; the old model keeps the fixed
+ reference it was written against, because its own offsets are scaled again downstream by
+ the room found at the unit's feet and measuring the same width twice would square it. */
+ Real bias = 0.0f;
+ Int lanes;
+ if (TheGlobalData->m_crowdModel)
+ {
+ lanes = crowdRoadLanes( widest, groupCenter, groupDir, spacing, &bias );
+ }
+ else
+ {
+ lanes = (Int)(2.0f * Pathfinder_laneReference() / spacing);
+ if (lanes < 1) lanes = 1;
+ }
if (lanes > count) lanes = count;
for (Int i = 0; i < count; i++)
@@ -1889,7 +1947,7 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com
// blocks, not round-robin: whoever was left of somebody stays left of them, and a
// group with more members than lanes puts the extra ones behind rather than beside
Int lane = (i * lanes) / count;
- Real offset = ((Real)lane - (Real)(lanes - 1) * 0.5f) * spacing;
+ Real offset = bias + ((Real)lane - (Real)(lanes - 1) * 0.5f) * spacing;
Real u = Pathfinder_groupLane( offset );
across[i].obj->getAIUpdateInterface()->setPendingLane( u );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 74e866a44..3b4fe697c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -1546,9 +1546,11 @@ Bool AIUpdateInterface::needToRotate(void)
static const Real CROWD_AIR = 4.0f; ///< air a body wants round it, on top of both radii
static const Real CROWD_SEP_STEP = 1.5f; ///< most one frame of separation may move a lane
static const Real CROWD_PASS_CLEAR = 6.0f; ///< room a passing lane leaves beside the blocker
+static const Real CROWD_PASS_TIGHT = 1.5f; ///< and the room it settles for rather than queue
+static const Int CROWD_PASS_RETRY = 10; ///< queued this long: ask to pass again, hold or no hold
static const Real CROWD_TAPER_DIST = PATHFIND_CELL_SIZE_F * 8.0f; ///< the band closes over the last of the route
static const Int CROWD_BRAKE_FRAMES = 8; ///< frames of closing time a brake is allowed to read
-static const Int CROWD_FAN_FRAMES = 30; ///< held up this long before spreading out
+static const Int CROWD_FAN_FRAMES = 12; ///< held up this long before spreading out
static const Real CROWD_FAN_RATE = 0.8f; ///< and then sideways at this much a frame
static const Real CROWD_SEP_FILTER = 0.13f; ///< how much of a frame's sideways push is believed (~4/sec)
static const Real CROWD_AIM_CRUISE = 0.23f; ///< how fast the aim follows the route while driving (~7/sec)
@@ -2407,10 +2409,18 @@ Bool AIUpdateInterface::crowdOutranksMe( Object *other ) const
//-------------------------------------------------------------------------------------------------
/** Somewhere a wedged unit can back out to, or FALSE if it is walled in on every side.
Sideways first and backwards second: the ground ahead is what it is already failing to drive
- through, and a unit that has been stationary for two seconds is in a hole its own route made. */
+ through, and a unit that has been stationary for two seconds is in a hole its own route made.
+
+ `backFirst` reverses that order, and the caller sets it wherever the road has no width - a
+ bridge and the ground either side of it. The riverbank next to an abutment is perfectly valid
+ ground to stand on, so the sideways probe finds it, and a unit that backs out onto it has left
+ the only queue that leads onto the bridge and has to fight its way back into the funnel. That
+ is the jam at the mouth of a bridge, and it is this function causing it. Taking the sideways
+ candidates away entirely rather than demoting them was measured and is worse: a unit that
+ cannot back up either has nowhere left to go and stays wedged for the rest of the battle. */
//-------------------------------------------------------------------------------------------------
static Bool crowdFindEscape( Object *self, const LocomotorSet& locoSet, const Coord2D& tan,
- Int firstSide, Coord3D *out )
+ Int firstSide, Bool backFirst, Coord3D *out )
{
const Coord3D *pos = self->getPosition();
const Real myR = self->getGeometryInfo().getBoundingCircleRadius();
@@ -2420,9 +2430,11 @@ static Bool crowdFindEscape( Object *self, const LocomotorSet& locoSet, const Co
const PathfindLayerEnum layer = self->getLayer();
const Real sx = -tan.y, sy = tan.x; // left of the route
- for (Int t = 0; t < 4; t++)
+ for (Int k = 0; k < 4; k++)
{
- // out and back to the roomier side, out and back the other way, straight out, straight back
+ // out and back to the roomier side, out and back the other way, straight out, straight back;
+ // on a bridge the last of those is tried first and the sideways three only if it fails
+ const Int t = backFirst ? ((k == 0) ? 3 : k - 1) : k;
const Real side = (t == 1) ? -(Real)firstSide : (Real)firstSide;
const Real lat = (t < 3) ? across : 0.0f;
const Real back = (t < 2) ? behind : ((t == 2) ? 0.0f : across);
@@ -2456,6 +2468,21 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
if (!m_hasPendingCrowdLat && !m_crowdLatValid)
return;
+ /* Foot soldiers get no band and no traffic rules, on either side of the question. Infantry walks
+ through infantry - the bodies interpenetrate, retail lets them, and a squad sent across a map
+ is meant to arrive as a squad on one line rather than as a rank spread over sixty feet of
+ road. Every rule below is written for bodies that cannot share ground: give way, queue,
+ brake, fan out. Applied to a platoon they are a machine for pulling it apart, which is what a
+ group of riflemen ordered across open ground was visibly doing. A vehicle does not get the
+ rules for them either (the scan below skips them): it drives over them, and braking for a man
+ it is about to walk through is a stop for nothing.
+
+ What a foot soldier keeps is the wedge rescue. Returning out of this function for infantry
+ was measured and it is not free: it takes the rescue away with everything else, and stuck
+ units went from 1.3 a match to 16.0. So the ladder below still runs for him and only the
+ lane is held at nothing. */
+ const Bool foot = self->isKindOf( KINDOF_INFANTRY );
+
/* The band is measured once per route. m_crowdSample = -1 is the latch for a route too short
to have one, without which a unit driving the last two cells of its path re-probes two
hundred cells every frame for the rest of its life. */
@@ -2555,7 +2582,8 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
else if (m_crowdStuck > CROWD_STUCK_GIVEUP && now >= m_crowdEscapeCool)
{
const Int firstSide = (here.left >= here.right) ? 1 : -1;
- if (crowdFindEscape( self, m_locomotorSet, here.tan, firstSide, &m_crowdEscape ))
+ const Bool sealed = (here.left <= 0.01f && here.right <= 0.01f); // a bridge, or its approach
+ if (crowdFindEscape( self, m_locomotorSet, here.tan, firstSide, sealed, &m_crowdEscape ))
{
m_crowdEscapeUntil = now + CROWD_ESCAPE_FRAMES;
m_crowdStuck = 0;
@@ -2573,7 +2601,9 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
PartitionFilterAlive fAlive;
PartitionFilterSameMapStatus fMap( self );
PartitionFilter *filters[] = { &fRel, &fAlive, &fMap, NULL };
- SimpleObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( self, scanRange, FROM_CENTER_2D, filters );
+ // a foot soldier reads nobody: he has no lane to hold and nothing on the road is his traffic
+ SimpleObjectIterator *iter = foot ? NULL
+ : ThePartitionManager->iterateObjectsInRange( self, scanRange, FROM_CENTER_2D, filters );
MemoryPoolObjectHolder hold( iter );
Real sep = 0.0f; // how far sideways the crowd is pushing us
@@ -2597,7 +2627,7 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
if (myPhys != NULL)
myVel = *myPhys->getVelocity();
- for (Object *o = iter->first(); o; o = iter->next())
+ for (Object *o = (iter != NULL) ? iter->first() : NULL; o; o = iter->next())
{
if (o == self)
continue;
@@ -2605,19 +2635,9 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
if (ai == NULL || !ai->isDoingGroundMovement())
continue;
- /* Infantry walks through infantry, and the band is not allowed to take that back. Retail's
- own rule is in blockedBy: two foot soldiers block each other only while they are going the
- same way, and two squads crossing pass straight through one another. Left in the scan
- below, a crossing squad reads as a wall of blockers - every man of it brakes, gives way and
- shuffles sideways for a crowd he is supposed to walk into. Same dot product as blockedBy's
- so the two agree; a column following a column is still traffic and still gets the rules. */
- if (self->isKindOf( KINDOF_INFANTRY ) && o->isKindOf( KINDOF_INFANTRY ))
- {
- const Coord3D *myDir = self->getUnitDirectionVector2D();
- const Coord3D *hisDir = o->getUnitDirectionVector2D();
- if (myDir->x * hisDir->x + myDir->y * hisDir->y <= 0.25f)
- continue;
- }
+ // infantry is nobody's traffic: see the gate at the top of this function
+ if (o->isKindOf( KINDOF_INFANTRY ))
+ continue;
const Coord3D *hp = o->getPosition();
const Real dx = hp->x - myPos->x;
@@ -2731,7 +2751,9 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
}
//--- the rules, in order -----------------------------------------------------------------------
- Real lat = m_crowdLat;
+ // nothing was scanned for a foot soldier, so every rule below stands down on its own; the lane is
+ // the one thing that has to be said out loud, and it is the middle of the road
+ Real lat = foot ? 0.0f : m_crowdLat;
Real cap = speed;
Bool queued = FALSE;
Bool merged = FALSE;
@@ -2769,7 +2791,6 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
{
const Real hisR = blocker->getGeometryInfo().getBoundingCircleRadius();
const Real hisLat = m_corridor->latOf( i, *blocker->getPosition() );
- const Real shift = myR + hisR + CROWD_PASS_CLEAR;
/* Pass on the outside of a bend. The inside is where the road runs out, and a unit that
dives up the inside of a turn to get past somebody arrives at the apex with a wall on
@@ -2777,18 +2798,36 @@ void AIUpdateInterface::crowdSteer( Coord3D& goalPos, Real& speed )
const Real curv = m_corridor->curvature( i );
Int first = (fabs( curv ) > 0.08f) ? ((curv > 0.0f) ? -1 : 1) : m_crowdSide;
+ /* Go round rather than sit behind, and mean it. Two gates used to send a unit to the back
+ of a queue that a foot of road either side would have let it out of.
+
+ The first was the lane hold. It is there so a lane cannot flap, and a unit that gave way
+ to somebody a second ago is exactly the unit now stuck behind the next one along - the
+ hold was answering "do not change your mind" to a question nobody asked twice. Once a
+ unit has been queueing for a third of a second, the hold does not get a vote.
+
+ The second was the clearance. Six units of air beside the blocker is what a comfortable
+ 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. */
Bool took = FALSE;
- if (now >= m_crowdHoldFrame)
+ const Bool retry = m_crowdQueued > CROWD_PASS_RETRY;
+ if (now >= m_crowdHoldFrame || retry)
{
- for (Int t = 0; t < 2 && !took; t++)
+ for (Int c = 0; c < 2 && !took; c++)
{
- const Real want = hisLat + (Real)((t == 0) ? first : -first) * shift;
- if (fabs( m_corridor->clampLat( i, want ) - want ) < 0.5f)
+ const Real shift = myR + hisR + ((c == 0) ? CROWD_PASS_CLEAR : CROWD_PASS_TIGHT);
+ for (Int t = 0; t < 2 && !took; t++)
{
- lat = want;
- m_crowdSide = (want >= hisLat) ? 1 : -1;
- m_crowdHoldFrame = now + CROWD_HOLD_FRAMES;
- took = TRUE;
+ 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;
+ }
}
}
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index e7682e58c..6ede518da 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -8711,7 +8711,7 @@ TEST(crowd_corridor_has_no_band_on_a_bridge_or_at_its_approaches)
riverbank. A lane held across either one drives the unit off the side, and a lane held on the
approach arrives beside the abutment instead of at the entrance - which is a unit that never
gets onto the bridge and a queue behind it that never gets anywhere. The band closes over the
- deck and for four samples each side of it. */
+ deck and for CROWD_BRIDGE_SEAL samples each side of it. */
Coord3D pts[ 20 ];
PathfindLayerEnum layers[ 20 ];
for (Int k = 0; k < 20; k++)
@@ -8736,8 +8736,11 @@ TEST(crowd_corridor_has_no_band_on_a_bridge_or_at_its_approaches)
corr.sealBridges();
- // the deck itself, and the four samples each side of it
- for (Int k = 6; k <= 16; k++)
+ const Int sealLo = 10 - (Int)CROWD_BRIDGE_SEAL;
+ const Int sealHi = 12 + (Int)CROWD_BRIDGE_SEAL;
+
+ // the deck itself, and the sealed samples each side of it
+ for (Int k = sealLo; k <= sealHi; k++)
{
CHECK_NEAR( corr.at( k ).left, 0.0f, 0.001f );
CHECK_NEAR( corr.at( k ).right, 0.0f, 0.001f );
@@ -8746,9 +8749,9 @@ TEST(crowd_corridor_has_no_band_on_a_bridge_or_at_its_approaches)
}
// and the road on either side of that stretch keeps its band
- CHECK_NEAR( corr.at( 5 ).left, 15.0f, 0.001f );
- CHECK_NEAR( corr.at( 17 ).right, 15.0f, 0.001f );
- CHECK_NEAR( corr.clampLat( 5, 12.0f ), 12.0f, 0.001f );
+ CHECK_NEAR( corr.at( sealLo - 1 ).left, 15.0f, 0.001f );
+ CHECK_NEAR( corr.at( sealHi + 1 ).right, 15.0f, 0.001f );
+ CHECK_NEAR( corr.clampLat( sealLo - 1, 12.0f ), 12.0f, 0.001f );
// a route with no bridge on it is untouched
CrowdCorridor plain;