Skip to content

Commit 861c09d

Browse files
committed
refactor(pathfinding) simplify function to improve readability Pathfinder::examineCellsCallback
1 parent 204ede8 commit 861c09d

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
@@ -5702,14 +5702,7 @@ struct ExamineCellsStruct
57025702
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
57035703
return 1;
57045704
}
5705-
Bool onList = false;
5706-
if (to->hasInfo()) {
5707-
if (to->getOpen() || to->getClosed())
5708-
{
5709-
// already on one of the lists
5710-
onList = true;
5711-
}
5712-
}
5705+
57135706
if (to->getPinched()) {
57145707
return 1; // abort.
57155708
}
@@ -5731,9 +5724,15 @@ struct ExamineCellsStruct
57315724
if (!d->thePathfinder->checkForMovement(d->obj, info) || info.enemyFixed) {
57325725
return 1; //abort.
57335726
}
5727+
5728+
if (info.allyFixedCount) {
5729+
return 1; //abort.
5730+
}
5731+
57345732
if (info.enemyFixed) {
57355733
return 1; //abort.
57365734
}
5735+
57375736
ICoord2D newCellCoord;
57385737
newCellCoord.x = to_x;
57395738
newCellCoord.y = to_y;
@@ -5742,11 +5741,6 @@ struct ExamineCellsStruct
57425741
if (to->getType() == PathfindCell::CELL_CLIFF ) {
57435742
return 1;
57445743
}
5745-
if (info.allyFixedCount) {
5746-
return 1;
5747-
} else if (info.enemyFixed) {
5748-
return 1;
5749-
}
57505744

57515745
if (!to->allocateInfo(newCellCoord)) {
57525746
// Out of cells for pathing...
@@ -5755,15 +5749,17 @@ struct ExamineCellsStruct
57555749
to->setBlockedByAlly(false);
57565750
Int costRemaining = 0;
57575751
costRemaining = to->costToGoal( d->goalCell );
5752+
57585753
// check if this neighbor cell is already on the open (waiting to be tried)
57595754
// or closed (already tried) lists
5760-
if (onList)
5755+
if ( to->hasInfo() && (to->getOpen() || to->getClosed()) )
57615756
{
57625757
// already on one of the lists - if existing costSoFar is less,
57635758
// the new cell is on a longer path, so skip it
57645759
if (to->getCostSoFar() <= newCostSoFar)
57655760
return 0; // keep going.
57665761
}
5762+
57675763
to->setCostSoFar(newCostSoFar);
57685764
// keep track of path we're building - point back to cell we moved here from
57695765
to->setParentCell(from) ;

0 commit comments

Comments
 (0)