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.

feat(gameengine): make way for stuck movers and unstack by footprint

Olcay Seygan173757a7cdd6
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
index 21891dcca..0e0ba0afe 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
@@ -743,6 +743,7 @@ public:
static void classifyMapCell( Int x, Int y, PathfindCell *cell); ///< Classify the given map cell
Int clearCellForDiameter( Bool crusher, Int cellX, Int cellY, PathfindLayerEnum layer, Int pathDiameter ); ///< Return true if given position is a valid movement location
+ void getRadiusAndCenter(const Object *obj, Int &iRadius, Bool &center);
protected:
virtual Path *internalFindPath( Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from, const Coord3D *to); ///< Find a short, valid path between given locations
@@ -761,9 +762,8 @@ protected:
Bool checkForTarget(const Object *obj, Int cellX, Int cellY, const Weapon *weapon,
const Object *victim, const Coord3D *victimPos,
Int iRadius, Bool center,Coord3D *dest) ;
- Bool checkForPossible(Bool isCrusher, Int fromZone, Bool center, const LocomotorSet& locomotorSet,
+ Bool checkForPossible(Bool isCrusher, Int fromZone, Bool center, const LocomotorSet& locomotorSet,
Int cellX, Int cellY, PathfindLayerEnum layer, Coord3D *dest, Bool startingInObstacle) ;
- void getRadiusAndCenter(const Object *obj, Int &iRadius, Bool &center);
void adjustCoordToCell(Int cellX, Int cellY, Bool centerInCell, Coord3D &pos, PathfindLayerEnum layer);
Bool checkDestination(const Object *obj, Int cellX, Int cellY, PathfindLayerEnum layer, Int iRadius, Bool centerInCell);
Bool checkForMovement(const Object *obj, TCheckMovementInfo &info);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index e41f7c1a8..7d1cc6a11 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -1624,7 +1624,7 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com
isFormation = false;
if (!addWaypoint) {
Int dx = (max.x-min.x)/PATHFIND_CELL_SIZE_F;
- Int dy = (max.x-min.x)/PATHFIND_CELL_SIZE_F;
+ Int dy = (max.y-min.y)/PATHFIND_CELL_SIZE_F;
Int cells = (dx*dy);
if (cells<2000) {
groupTightenToPosition(pos, false, cmdSource);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 4fdd40bc6..6caf57974 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -6376,7 +6376,9 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
newCostSoFar += 7*COST_DIAGONAL;
}
} else if (newCell->getPinched()) {
- newCostSoFar += COST_ORTHOGONAL;
+ // Pinched = clear cell hugging an obstacle. Charge by footprint so wide
+ // vehicles prefer open corridors while infantry threads the gap as before.
+ newCostSoFar += COST_ORTHOGONAL*(1+radius);
}
newCell->setBlockedByAlly(false);
if (info.allyFixedCount>0) {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 47c0d72f1..e1f74692f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -1329,10 +1329,10 @@ Bool AIUpdateInterface::blockedBy(Object *other)
AIUpdateInterface* aiOther = other->getAI();
+ if (!aiOther) return FALSE; // Ignore it.
if (!aiOther->isDoingGroundMovement()) {
return FALSE; // Can't be blocked if the other is airborne.
}
- if (!aiOther) return FALSE; // Ignore it.
if (getCurLocomotor() && getCurLocomotor()->isMovingBackwards()) {
return false; // don't collide.
@@ -1525,8 +1525,22 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other
if (!needToRotate())
{
// If we are already pointing in the right direction, we may be stuck.
- if (!otherMoving)
+ if (!otherMoving)
{
+ // Before giving up and repathing, ask an idle allied blocker to step aside
+ // (EA only did this for vehicles blocked by infantry). Same guards as the
+ // 1.01 patch above: never disturb a busy unit or one using an ability.
+ if (getObject()->getRelationship(other)==ALLIES && aiOther->isIdle() &&
+ !other->testStatus(OBJECT_STATUS_IS_USING_ABILITY))
+ {
+ aiOther->aiMoveAwayFromUnit(getObject(), CMD_FROM_AI);
+ if (getNumFramesBlocked() < LOGICFRAMES_PER_SECOND)
+ {
+ // Give it a moment to clear; AIStates' 2 second rule still repaths us
+ // if it never does (immobile, held, or refused).
+ return FALSE;
+ }
+ }
// Intense logging jba
// DEBUG_LOG(("Blocked&Stuck !otherMoving\n"));
m_isBlockedAndStuck = TRUE;
@@ -1576,8 +1590,22 @@ Bool AIUpdateInterface::processCollision(PhysicsBehavior *physics, Object *other
Real dx = getObject()->getPosition()->x - otherPos.x;
Real dy = getObject()->getPosition()->y - otherPos.y;
Real curDSqr = dx*dx+dy*dy;
- if (!otherMoving && curDSqr < PATHFIND_CELL_SIZE_F*PATHFIND_CELL_SIZE_F*0.25f)
- {
+ // Two idle units count as stacked when their centers are within half of their
+ // combined pathfind footprints — the old fixed half-cell test never separated
+ // vehicles wider than a cell that ended up half overlapped. For a pair of
+ // single-cell units this degenerates to exactly the old half-cell threshold,
+ // and it stays below the legal parked separation, so no jitter for units
+ // standing on properly allocated adjacent goal cells.
+ Int sepCells = 1;
+ Bool centerUnused;
+ Int radiusCells;
+ TheAI->pathfinder()->getRadiusAndCenter(getObject(), radiusCells, centerUnused);
+ sepCells += radiusCells;
+ TheAI->pathfinder()->getRadiusAndCenter(other, radiusCells, centerUnused);
+ sepCells += radiusCells;
+ Real minSep = 0.5f*PATHFIND_CELL_SIZE_F*sepCells;
+ if (!otherMoving && curDSqr < minSep*minSep)
+ {
if (this->getCurrentStateID() == AI_BUSY) {
return false;
}