Skip to content

Commit cdb1b68

Browse files
committed
unify(pathfinder): Merge Pathfinder::moveAllies and Pathfinder::findAttackPath from Zero Hour (#)
1 parent 5dd864d commit cdb1b68

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10180,6 +10180,18 @@ if (g_UT_startTiming) return false;
1018010180
continue;
1018110181
}
1018210182

10183+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING)
10184+
if (otherObj->getAI()->isAttacking()) {
10185+
continue; // Don't move units that are attacking. [8/14/2003]
10186+
}
10187+
10188+
//Kris: Patch 1.01 November 3, 2003
10189+
//Black Lotus exploit fix -- moving while hacking.
10190+
if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() ) {
10191+
continue; // Packing or unpacking objects for example
10192+
}
10193+
#endif
10194+
1018310195
//DEBUG_LOG(("Moving ally"));
1018410196
otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
1018510197
}
@@ -10820,6 +10832,68 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1082010832
if (show)
1082110833
debugShowSearch(true);
1082210834

10835+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING)
10836+
// put parent cell onto closed list - its evaluation is finished
10837+
parentCell->putOnClosedList( m_closedList );
10838+
10839+
if (obj->isKindOf(KINDOF_VEHICLE)) {
10840+
// Strip backwards.
10841+
PathfindCell *lastBlocked = nullptr;
10842+
PathfindCell *cur = parentCell;
10843+
Bool useLargeRadius = false;
10844+
Int cellLimit = 12; // Magic number, yes I know - jba. It is about 4 * size of an average vehicle width (3 cells) [8/15/2003]
10845+
while (cur) {
10846+
cellLimit--;
10847+
if (cellLimit<0) {
10848+
break;
10849+
}
10850+
TCheckMovementInfo info;
10851+
info.cell.x = cur->getXIndex();
10852+
info.cell.y = cur->getYIndex();
10853+
info.layer = cur->getLayer();
10854+
if (useLargeRadius) {
10855+
info.centerInCell = centerInCell;
10856+
info.radius = radius;
10857+
} else {
10858+
info.centerInCell = true;
10859+
info.radius = 0;
10860+
}
10861+
info.considerTransient = false;
10862+
info.acceptableSurfaces = locomotorSet.getValidSurfaces();
10863+
PathfindCell *cell = getCell(info.layer,info.cell.x,info.cell.y);
10864+
Bool unitIdle = false;
10865+
if (cell) {
10866+
ObjectID posUnit = cell->getPosUnit();
10867+
Object *unit = TheGameLogic->findObjectByID(posUnit);
10868+
if (unit && unit->getAI() && unit->getAI()->isIdle()) {
10869+
unitIdle = true;
10870+
}
10871+
}
10872+
Bool checkMovement = checkForMovement(obj, info);
10873+
Bool blockedByEnemy = info.enemyFixed;
10874+
Bool blockedByAllies = info.allyFixedCount || info.allyGoal;
10875+
if (unitIdle) {
10876+
// If the unit present is idle, it doesn't block allies. [8/18/2003]
10877+
blockedByAllies = false;
10878+
}
10879+
10880+
10881+
if (!checkMovement || blockedByEnemy || blockedByAllies) {
10882+
lastBlocked = cur;
10883+
useLargeRadius = true;
10884+
} else {
10885+
useLargeRadius = false;
10886+
}
10887+
cur = cur->getParentCell();
10888+
}
10889+
if (lastBlocked) {
10890+
parentCell = lastBlocked;
10891+
if (lastBlocked->getParentCell()) {
10892+
parentCell = lastBlocked->getParentCell();
10893+
}
10894+
}
10895+
}
10896+
#endif
1082310897
// construct and return path
1082410898
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
1082510899
#if RETAIL_COMPATIBLE_PATHFINDING

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10180,6 +10180,7 @@ if (g_UT_startTiming) return false;
1018010180
continue;
1018110181
}
1018210182

10183+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING)
1018310184
if (otherObj->getAI()->isAttacking()) {
1018410185
continue; // Don't move units that are attacking. [8/14/2003]
1018510186
}
@@ -10189,6 +10190,7 @@ if (g_UT_startTiming) return false;
1018910190
if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() ) {
1019010191
continue; // Packing or unpacking objects for example
1019110192
}
10193+
#endif
1019210194

1019310195
//DEBUG_LOG(("Moving ally"));
1019410196
otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
@@ -10830,9 +10832,10 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1083010832
if (show)
1083110833
debugShowSearch(true);
1083210834

10835+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING)
1083310836
// put parent cell onto closed list - its evaluation is finished
1083410837
parentCell->putOnClosedList( m_closedList );
10835-
// construct and return path
10838+
1083610839
if (obj->isKindOf(KINDOF_VEHICLE)) {
1083710840
// Strip backwards.
1083810841
PathfindCell *lastBlocked = nullptr;
@@ -10890,6 +10893,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1089010893
}
1089110894
}
1089210895
}
10896+
#endif
10897+
// construct and return path
1089310898
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
1089410899
#if RETAIL_COMPATIBLE_PATHFINDING
1089510900
if (!s_useFixedPathfinding) {

0 commit comments

Comments
 (0)