Skip to content

Commit 26be73e

Browse files
committed
refactor(pathfinder): Simplify and improve readability of Pathfinder::moveAllies
1 parent 10189db commit 26be73e

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

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

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9985,46 +9985,49 @@ if (g_UT_startTiming) return false;
99859985
for (i=curCell.x-radius; i<curCell.x+numCellsAbove; i++) {
99869986
for (j=curCell.y-radius; j<curCell.y+numCellsAbove; j++) {
99879987
PathfindCell *cell = getCell(node->getLayer(), i, j);
9988-
if (cell) {
9989-
if (cell->getPosUnit()==INVALID_ID) {
9988+
if (!cell) {
9989+
continue; // Cell is not on the pathfinding grid
9990+
}
9991+
if (cell->getPosUnit()==INVALID_ID) {
9992+
continue;
9993+
}
9994+
if (cell->getPosUnit()==obj->getID()) {
9995+
continue; // It's us.
9996+
}
9997+
if (cell->getPosUnit()==ignoreId) {
9998+
continue; // It's the one we are ignoring.
9999+
}
10000+
Object *otherObj = TheGameLogic->findObjectByID(cell->getPosUnit());
10001+
if (obj->getRelationship(otherObj)!=ALLIES) {
10002+
continue; // Only move allies.
10003+
}
10004+
if (!otherObj) {
10005+
continue;
10006+
}
10007+
if (obj->isKindOf(KINDOF_INFANTRY) && otherObj->isKindOf(KINDOF_INFANTRY)) {
10008+
continue; // infantry can walk through other infantry, so just let them.
10009+
}
10010+
if (obj->isKindOf(KINDOF_INFANTRY) && !otherObj->isKindOf(KINDOF_INFANTRY)) {
10011+
// If this is a general clear operation, don't let infantry push vehicles.
10012+
if (!path->getBlockedByAlly()) {
999010013
continue;
999110014
}
9992-
if (cell->getPosUnit()==obj->getID()) {
9993-
continue; // It's us.
9994-
}
9995-
if (cell->getPosUnit()==ignoreId) {
9996-
continue; // It's the one we are ignoring.
9997-
}
9998-
Object *otherObj = TheGameLogic->findObjectByID(cell->getPosUnit());
9999-
if (obj->getRelationship(otherObj)!=ALLIES) {
10000-
continue; // Only move allies.
10001-
}
10002-
if (otherObj==NULL) continue;
10003-
if (obj->isKindOf(KINDOF_INFANTRY) && otherObj->isKindOf(KINDOF_INFANTRY)) {
10004-
continue; // infantry can walk through other infantry, so just let them.
10005-
}
10006-
if (obj->isKindOf(KINDOF_INFANTRY) && !otherObj->isKindOf(KINDOF_INFANTRY)) {
10007-
// If this is a general clear operation, don't let infantry push vehicles.
10008-
if (!path->getBlockedByAlly()) continue;
10009-
}
10010-
if( otherObj && otherObj->getAI() && !otherObj->getAI()->isMoving() )
10011-
{
10012-
if( otherObj->getAI()->isAttacking() )
10013-
{
10014-
continue; // Don't move units that are attacking. [8/14/2003]
10015-
}
10016-
10017-
//Kris: Patch 1.01 November 3, 2003
10018-
//Black Lotus exploit fix -- moving while hacking.
10019-
if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() )
10020-
{
10021-
continue; // Packing or unpacking objects for example
10022-
}
10015+
}
10016+
if (!otherObj->getAI() || otherObj->getAI()->isMoving()) {
10017+
continue;
10018+
}
1002310019

10024-
//DEBUG_LOG(("Moving ally"));
10025-
otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
10026-
}
10020+
if (otherObj->getAI()->isAttacking()) {
10021+
continue; // Don't move units that are attacking. [8/14/2003]
10022+
}
10023+
//Kris: Patch 1.01 November 3, 2003
10024+
//Black Lotus exploit fix -- moving while hacking.
10025+
if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() ) {
10026+
continue; // Packing or unpacking objects for example
1002710027
}
10028+
10029+
//DEBUG_LOG(("Moving ally"));
10030+
otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
1002810031
}
1002910032
}
1003010033
}

0 commit comments

Comments
 (0)