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): seed crowd lanes on waypoint-follow waves

Olcay Seygan56f4c8032f4a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e765e4c3..d37830cc0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1196,6 +1196,7 @@ found and fixed — EA's own, not port damage.**
- A network game now runs the shipped rules no matter what was typed to start it. Half a dozen switches exist so that the same build can be run twice and the two compared, and every one of them changes what a unit or the computer opponent decides: the crowd model, the three that put a piece of the movement back the way it shipped in 2003, how often a unit thinks, and the truce clock. Two players deciding differently is a match that comes apart on the first order rather than one that refuses the join, so online they are all off and the host's lobby settings are the only settings. Anyone who turned one on to look at it can still play with anyone who did not. A replay keeps whatever it was recorded with.
- Then the switches themselves went, because a switch that changes what a unit decides is a way to start two copies of the game that play different matches. The crowd steering is no longer something you start the game with: every match drives with it now, the computer's armies included. The three that put a piece of 2003 movement back are gone and the movement they could turn off is always on. The group drill that measured the crowd went too, and so did the setting for how often a unit thinks, which nobody had ever measured.
- A group no longer drops to half speed at every corner of its route. The crowd steering slowed a vehicle to as little as 55% wherever the road turned, on top of the slowing down the tank already does for a turn it cannot take, and a pathfinder route turns all the time: a quarter of the steering on a twenty-tank test sat under it, and a tank with the road to itself averaged 92% of its speed. Without it the same twenty Crusaders cross the same ramp to the enemy base in 71 seconds instead of 86, three seconds quicker than with no crowd steering at all, and the time they spend stuck behind each other fell by a third. The truce clock and the unit limit stay, since both are lobby settings the host picks for everyone.
+- The computer's attack waves now travel as a crowd too. A selection you send, and a computer team told to gather at a point, were already handed a line across the road. The order that actually sends a wave down an approach path was not: every tank on it steered at the middle of the same road, which is the single file the crowd was written to stop. That order now hands out the same lines a move does, aimed at the next point on the path so a group already standing on the first waypoint still has a direction to spread across.
- 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/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index 6ae757408..7f73a3bb3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -57,6 +57,7 @@
#include "GameLogic/Module/StealthUpdate.h"
#include "GameLogic/Module/SpecialPowerUpdateModule.h"
#include "GameLogic/ObjectIter.h"
+#include "GameLogic/TerrainLogic.h"
#ifdef _INTERNAL
// for occasional debugging...
@@ -1641,12 +1642,10 @@ static void crowdClearLanes( std::list<Object *>& members )
/** Hand every member of a group the distance it should sit off the centre of the road, for the
crowd model only.
- The same arithmetic groupMoveToPosition does inline, extracted because the computer's armies
- never go through that function: an AI team moves with groupTightenToPosition
- (AIPlayer.cpp:3505), which handed nobody a lane, and a unit with no lane is a unit crowdSteer
- returns out of on its first line. So every steering rule in the crowd model was reachable by
- the player and by nothing else, and the self-play harness was measuring the collision rules in
- AIUpdate::blockedBy while reporting on the crowd model. */
+ groupMoveToPosition does the same arithmetic inline because it also has to feed the older
+ lane share (setPendingLane). Everything else that marches a group - tighten, attack-move,
+ and the waypoint follow a wave actually leaves on - comes through here. A unit with no lane
+ is a unit crowdSteer returns out of on its first line. */
static void crowdSeedLanes( std::list<Object *>& members, const Coord3D& center, const Coord3D *pos )
{
crowdClearLanes( members ); // whatever this order hands out replaces the last one entirely
@@ -1706,6 +1705,39 @@ static void crowdSeedLanes( std::list<Object *>& members, const Coord3D& center,
count, lanes, spacing, bias));
}
+/** Where a waypoint-follow should spread across. doWaves parks the team, then asks for the closest
+ point on the approach path, which is often under their feet: crowdSeedLanes then sees no
+ direction and hands nobody a lane. The first link is the next point they will actually drive
+ at. */
+static const Coord3D *crowdWaypointAim( const Coord3D& center, const Waypoint *way )
+{
+ if (way == NULL)
+ return NULL;
+ const Coord3D *pos = way->getLocation();
+ Coord2D d;
+ d.x = pos->x - center.x;
+ d.y = pos->y - center.y;
+ if (d.length() > 1.0f)
+ return pos;
+ if (way->getNumLinks() > 0)
+ {
+ const Waypoint *next = way->getLink( 0 );
+ if (next != NULL)
+ return next->getLocation();
+ }
+ return pos;
+}
+
+static void crowdSeedLanesAlongWaypoint( AIGroup *group, std::list<Object *>& members, const Waypoint *way )
+{
+ if (group == NULL || way == NULL)
+ return;
+ Coord2D min, max;
+ Coord3D center;
+ group->getMinMaxAndCenter( &min, &max, &center );
+ crowdSeedLanes( members, center, crowdWaypointAim( center, way ) );
+}
+
/**
* Move to given position(s)
*/
@@ -2293,6 +2325,7 @@ void AIGroup::groupTightenToPosition( const Coord3D *pos, Bool addWaypoint, Comm
*/
void AIGroup::groupFollowWaypointPath( const Waypoint *way, CommandSourceType cmdSource )
{
+ crowdSeedLanesAlongWaypoint( this, m_memberList, way );
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); ++i )
{
@@ -2309,6 +2342,7 @@ void AIGroup::groupFollowWaypointPath( const Waypoint *way, CommandSourceType cm
*/
void AIGroup::groupFollowWaypointPathExact( const Waypoint *way, CommandSourceType cmdSource )
{
+ crowdSeedLanesAlongWaypoint( this, m_memberList, way );
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); ++i )
{
@@ -2358,6 +2392,9 @@ void AIGroup::groupMoveToAndEvacuateAndExit( const Coord3D *pos, CommandSourceTy
*/
void AIGroup::groupFollowWaypointPathAsTeam( const Waypoint *way, CommandSourceType cmdSource )
{
+ /* A wave leaves on this order, not on groupMoveToPosition. Without a lane every member drives
+ the centre of the same road, which is the single file the crowd model was written to stop. */
+ crowdSeedLanesAlongWaypoint( this, m_memberList, way );
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); ++i )
{
@@ -2374,6 +2411,7 @@ void AIGroup::groupFollowWaypointPathAsTeam( const Waypoint *way, CommandSourceT
*/
void AIGroup::groupFollowWaypointPathAsTeamExact( const Waypoint *way, CommandSourceType cmdSource )
{
+ crowdSeedLanesAlongWaypoint( this, m_memberList, way );
std::list<Object *>::iterator i;
for( i = m_memberList.begin(); i != m_memberList.end(); ++i )
{