Skip to content

Commit 4b1653f

Browse files
committed
refactor(pathfinding) simplify function to improve readability Pathfinder::examineCellsCallback
1 parent 4c7b28b commit 4b1653f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,14 +5696,7 @@ struct ExamineCellsStruct
56965696
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
56975697
return 1;
56985698
}
5699-
Bool onList = false;
5700-
if (to->hasInfo()) {
5701-
if (to->getOpen() || to->getClosed())
5702-
{
5703-
// already on one of the lists
5704-
onList = true;
5705-
}
5706-
}
5699+
57075700
if (to->getPinched()) {
57085701
return 1; // abort.
57095702
}
@@ -5725,9 +5718,15 @@ struct ExamineCellsStruct
57255718
if (!d->thePathfinder->checkForMovement(d->obj, info) || info.enemyFixed) {
57265719
return 1; //abort.
57275720
}
5721+
5722+
if (info.allyFixedCount) {
5723+
return 1; //abort.
5724+
}
5725+
57285726
if (info.enemyFixed) {
57295727
return 1; //abort.
57305728
}
5729+
57315730
ICoord2D newCellCoord;
57325731
newCellCoord.x = to_x;
57335732
newCellCoord.y = to_y;
@@ -5736,11 +5735,6 @@ struct ExamineCellsStruct
57365735
if (to->getType() == PathfindCell::CELL_CLIFF ) {
57375736
return 1;
57385737
}
5739-
if (info.allyFixedCount) {
5740-
return 1;
5741-
} else if (info.enemyFixed) {
5742-
return 1;
5743-
}
57445738

57455739
if (!to->allocateInfo(newCellCoord)) {
57465740
// Out of cells for pathing...
@@ -5749,15 +5743,17 @@ struct ExamineCellsStruct
57495743
to->setBlockedByAlly(false);
57505744
Int costRemaining = 0;
57515745
costRemaining = to->costToGoal( d->goalCell );
5746+
57525747
// check if this neighbor cell is already on the open (waiting to be tried)
57535748
// or closed (already tried) lists
5754-
if (onList)
5749+
if ( to->hasInfo() && (to->getOpen() || to->getClosed()) )
57555750
{
57565751
// already on one of the lists - if existing costSoFar is less,
57575752
// the new cell is on a longer path, so skip it
57585753
if (to->getCostSoFar() <= newCostSoFar)
57595754
return 0; // keep going.
57605755
}
5756+
57615757
to->setCostSoFar(newCostSoFar);
57625758
// keep track of path we're building - point back to cell we moved here from
57635759
to->setParentCell(from) ;

0 commit comments

Comments
 (0)