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): angry mob holds formation instead of killing stragglers

Olcay Seygan500c1f543e9b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f70ad7d1..ce9aab238 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1112,6 +1112,12 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
brutal battles on Twilight Flame, units spent 8% less time wedged and 4% less time blocked, with 14%
more new routes actually planned. One of those twenty went the other way: a unit sat stuck for most
of the match, and why is not known yet.
+- An Angry Mob arrives with everyone it set off with. The mob is ten people following one invisible
+ leader, and every one of them used to walk at the exact spot that leader was headed for, so they
+ all arrived on the same square and spent the trip shoving each other off it. Anyone who fell too
+ far behind died on the spot, which is why a mob that walked around a building turned up four men
+ short. Each member now has its own place in the crowd and holds it, whoever gets ahead eases off
+ rather than arriving alone, whoever falls behind runs, and nobody dies for being last.
## Long orders stopped hitching
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MobMemberSlavedUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MobMemberSlavedUpdate.h
index 5a7b6291b..c4c5cc147 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MobMemberSlavedUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MobMemberSlavedUpdate.h
@@ -109,8 +109,6 @@ public:
virtual void onObjectCreated();
virtual Bool isSelfTasking() const { return m_isSelfTasking; };
- void doCatchUpLogic( Coord3D *pinnedPosition );
-
void setMobState( MobStates state ) { m_mobState = state; };
MobStates getMobState( void ) { return m_mobState; };
@@ -118,6 +116,7 @@ public:
virtual UpdateSleepTime update(); ///< Deciding whether or not to make new guys
private:
+ void computeSlotPosition( Object *master, Coord3D *position ); ///< My own standing place inside the mob
void startSlavedEffects( const Object *slaver ); ///< We have been marked as Slaved, so we can't be selected or move too far or other stuff
void stopSlavedEffects(); ///< We are no longer slaved.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp
index 07e8c8090..04f7d5d02 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp
@@ -37,6 +37,7 @@
#include "Common/Xfer.h"
#include "GameClient/Drawable.h"
#include "GameClient/ParticleSys.h"
+#include "GameLogic/AI.h"
#include "GameLogic/AIPathfind.h"
#include "GameLogic/Damage.h"
#include "GameLogic/GameLogic.h"
@@ -62,10 +63,31 @@
#endif
-#define STRAY_MULTIPLIER 2.0f // Multiplier from stating diestance from tunnel, to max distance from
+/* Where a member stands inside the mob. The slot comes from the member's own object id, which is
+ handed out in creation order and is the same number on every machine, so ten members spawned in
+ a row take ten different slots and keep them for as long as they live. The slots sit on a
+ sunflower spiral - turn by the golden angle, step out by the square root of the slot number -
+ which spreads any number of them evenly over a disc without any ring bookkeeping. Before this,
+ every member pathed to the one point the nexus was headed for, arrived on top of its
+ neighbours, and spent the rest of the trip being shoved around by the pathfinder. */
+const Int MOB_FORMATION_SLOT_COUNT = 12;
+const Real MOB_FORMATION_GOLDEN_ANGLE = 2.39996f;
+const Real MOB_FORMATION_SPACING_IN_RADII = 2.2f; // just over two bodies apart, so neighbours do not shove
-const Real CLOSE_ENOUGH = 15; // Our moveTo commands and pathfinding can't handle people in the way, so quit trying to hump someone on your spot
-const Real CLOSE_ENOUGH_SQR = (CLOSE_ENOUGH * CLOSE_ENOUGH);
+// Close enough to my slot to stop steering towards it and start looking for someone to hit.
+const Real MOB_FORMATION_ARRIVED_DISTANCE = PATHFIND_CELL_SIZE_F * 1.2f;
+
+// How far my slot has to have moved before it is worth spending another path on it.
+const Real MOB_FORMATION_REPATH_DISTANCE = PATHFIND_CELL_SIZE_F * 5.0f;
+
+// How far ahead of the nexus I may get before I ease off and let it catch up.
+const Real MOB_FORMATION_LEAD_ALLOWANCE = 25.0f;
+
+// Beyond this multiple of the catch-up radius I have lost the mob and stop being subtle about it.
+const Real MOB_CATCH_UP_CRISIS_MULTIPLIER = 3.0f;
+
+// The fraction of CatchUpCrisisBailTime after which I give up on my slot and walk at the nexus.
+const UnsignedInt MOB_CATCH_UP_CRISIS_DIVISOR = 3;
/* How often a mob member reconsiders where it is standing. EA already ran the expensive half of
update() once every sixteen frames; what it did not do was sleep, so the module was still
@@ -228,98 +250,60 @@ UpdateSleepTime MobMemberSlavedUpdate::update( void )
Real myPathDistToGoal = myAI->getLocomotorDistanceToGoal();
- Real catchUpRadiusSquared = ThePartitionManager->getDistanceSquared( me, master, FROM_CENTER_3D );
- // I'm too far from the nexus... I need to catch up now!
- if( catchUpRadiusSquared > sqr( data->m_mustCatchUpRadius ) )
- {
+ Coord3D slotPosition;
+ computeSlotPosition( master, &slotPosition );
- if ( masterAI->isMoving() )// master is on the move
- {
- if ( masterPathDistToGoal > myPathDistToGoal ) // I'm getting ahead of master, need to slow down
- myAI->chooseLocomotorSet(LOCOMOTORSET_WANDER);
- else
- myAI->chooseLocomotorSet(LOCOMOTORSET_PANIC); // I'm lagging, so I need to snap to it!
+ Coord3D slotDelta = slotPosition;
+ slotDelta.sub( me->getPosition() );
+ const Real distanceToSlot = slotDelta.length();
- Coord3D nuPos = *masterAI->getGoalPosition();
+ const Real distanceToMaster = sqrtf( ThePartitionManager->getDistanceSquared( me, master, FROM_CENTER_3D ) );
- if ( nuPos.length() < 1.0f ) //if a nasty error has sent me to map origin
- {
- myAI->aiMoveToPosition( master->getPosition(), CMD_FROM_AI ); // NASTY BEEHIVE EFFECT
- }
- else
- {
- Coord3D goalDelta = *myAI->getGoalPosition();
- goalDelta.sub( &nuPos );
-
- if ( goalDelta.length() > 5.0f * PATHFIND_CELL_SIZE_F )// only if I am not headed there already
- {
- myAI->aiMoveToPosition( &nuPos, CMD_FROM_AI ); // Whither thou goest... THis causes the mob to reconverge
- }
- }
-
- // on the fly, instead of doubling back to reconverge
- }
- else // master is still, so let's re group in a hurry
- {
- myAI->chooseLocomotorSet(LOCOMOTORSET_PANIC);
- myAI->aiMoveToPosition( master->getPosition(), CMD_FROM_AI );
-
- }
+ /* One body, one speed. A member further from the nexus than it is allowed to be runs; a member
+ that is closer to the shared destination than the nexus is eases off rather than arriving
+ alone and standing there. EA rolled a die here instead, which is why a third of the mob was
+ always ambling while the rest of it ran. */
+ if ( distanceToMaster > data->m_mustCatchUpRadius )
+ myAI->chooseLocomotorSet( LOCOMOTORSET_PANIC );
+ else if ( masterAI->isMoving() && myPathDistToGoal + MOB_FORMATION_LEAD_ALLOWANCE < masterPathDistToGoal )
+ myAI->chooseLocomotorSet( LOCOMOTORSET_WANDER );
+ else
+ myAI->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
+ // Holding my slot never overrides an attack I am already making, unless I have lost the mob doing it.
+ const Bool mustHoldFormation = ( ! myAI->isAttacking() ) || ( distanceToMaster > data->m_mustCatchUpRadius );
+ if ( mustHoldFormation && distanceToSlot > MOB_FORMATION_ARRIVED_DISTANCE )
+ {
+ Coord3D goalDelta = *myAI->getGoalPosition();
+ goalDelta.sub( &slotPosition );
- if (catchUpRadiusSquared > sqr( data->m_mustCatchUpRadius * 3))// I am critically far, now!
+ if ( goalDelta.length() > MOB_FORMATION_REPATH_DISTANCE )// only if I am not headed there already
{
- ++ m_catchUpCrisisTimer; // I'm way too far from the nexus this frame
-
- if ( m_catchUpCrisisTimer > data->m_catchUpCrisisBailTime)
- {
- me->kill();
- return UPDATE_SLEEP_FOREVER;
-
- // Here is the rethink:
- // If the nexus has outrun me to the target by so much, //
- // lets make the nexus come to me, and try to return to where I find it
-// Coord3D masterPosition = *master->getPosition();
-// master->setPosition( me->getPosition() );
-// if ( ! masterAI->isMoving() )
-// {
-// masterAI->aiMoveToPosition( &masterPosition, CMD_FROM_AI );
-// }
-// m_catchUpCrisisTimer = 0;
- }
- else if ( m_catchUpCrisisTimer > data->m_catchUpCrisisBailTime/3 )
- {
- myAI->aiMoveToPosition( master->getPosition(), CMD_FROM_AI ); // NASTY BEEHIVE EFFECT
- }
+ myAI->aiMoveToPosition( &slotPosition, CMD_FROM_AI );
}
-
-
}
- else if ( myAI->isMoving() ) // we're all on a trip, together
- {
- m_catchUpCrisisTimer = 0; // I'm not too far from the nexus this frame
+ if ( distanceToMaster > data->m_mustCatchUpRadius * MOB_CATCH_UP_CRISIS_MULTIPLIER )// I am critically far, now!
+ {
+ ++ m_catchUpCrisisTimer; // I'm way too far from the nexus this frame
- Int seed = GameLogicRandomValue( 0, 10 );
- if ( seed == 1 )
- myAI->chooseLocomotorSet(LOCOMOTORSET_WANDER);
- else if ( seed == 2 )
- myAI->chooseLocomotorSet(LOCOMOTORSET_PANIC);
- else if ( seed == 3 )
- myAI->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
- // else if ( seed >= 5 ) // go towards mommy's goal
- // {
- // Coord3D destination = *me->getPosition();
- // TheAI->pathfinder()->adjustToPossibleDestination(me, myAI->getLocomotorSet(), &destination);
- // myAI->aiMoveToPosition( &destination, CMD_FROM_AI ); // reconverge
- // }
-
+ /* EA killed the member on this timer. That is the straggler dying for the crime of having
+ had a building in the way, and it is why a mob that walked past a wall arrived four men
+ short. It gives up on its slot and walks straight at the nexus instead, which is what
+ CatchUpCrisisBailTime says it does in the first place. */
+ if ( m_catchUpCrisisTimer > data->m_catchUpCrisisBailTime / MOB_CATCH_UP_CRISIS_DIVISOR )
+ {
+ myAI->aiMoveToPosition( master->getPosition(), CMD_FROM_AI );
+ }
}
- else // give me something to do while I'm standing here...
+ else
{
m_catchUpCrisisTimer = 0; // I'm not too far from the nexus this frame
+ }
+ if ( ! myAI->isMoving() ) // give me something to do while I'm standing here...
+ {
SpawnBehaviorInterface *spawnerBehavior = master->getSpawnBehaviorInterface();
if ( spawnerBehavior ) // if I have a mommy
@@ -372,28 +356,32 @@ UpdateSleepTime MobMemberSlavedUpdate::update( void )
//-------------------------------------------------------------------------------------------------
-// We are too far from nexus, so we need to catch-up
+// Where I stand in the mob: my own place around wherever the mob as a whole is going.
//-------------------------------------------------------------------------------------------------
-void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos )
+void MobMemberSlavedUpdate::computeSlotPosition( Object *master, Coord3D *position )
{
- Coord3D nuPos;
- const MobMemberSlavedUpdateModuleData* data = getMobMemberSlavedUpdateModuleData();
- // recalc where we want to be if we wander around
- Real randomDirection = GameLogicRandomValue( 0, 2*PI );
- Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius );
- nuPos.set(pos);
- nuPos.x += randomRadius * Cos( randomDirection );
- nuPos.y += randomRadius * Sin( randomDirection );
- nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y );
+ Object *me = getObject();
+ AIUpdateInterface *myAI = me->getAIUpdateInterface();
+ AIUpdateInterface *masterAI = master->getAIUpdateInterface();
- AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
- if( ai )
+ *position = masterAI->isMoving() ? *masterAI->getGoalPosition() : *master->getPosition();
+
+ if ( position->length() < 1.0f ) // a nasty error has sent the nexus to map origin
{
- ai->aiMoveToPosition( &nuPos, CMD_FROM_AI );
+ *position = *master->getPosition();
}
- setMobState(MOB_STATE_CATCHING_UP);
+ const Int slot = ((Int)me->getID()) % MOB_FORMATION_SLOT_COUNT;
+ const Real spacing = me->getGeometryInfo().getBoundingCircleRadius() * MOB_FORMATION_SPACING_IN_RADII;
+ const Real angle = slot * MOB_FORMATION_GOLDEN_ANGLE;
+ const Real radius = spacing * sqrtf( slot + 0.5f );
+
+ position->x += radius * Cos( angle );
+ position->y += radius * Sin( angle );
+ position->z = TheTerrainLogic->getGroundHeight( position->x, position->y );
+ // A slot that lands in a cliff or a building is a member walking into a wall until the mob dies.
+ TheAI->pathfinder()->adjustToPossibleDestination( me, myAI->getLocomotorSet(), position );
}