Skip to content

Commit d8fd57d

Browse files
committed
refactor(pathfinding) simplify function to improve readability Pathfinder::examineCellsCallback
1 parent 026d861 commit d8fd57d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,14 +5712,7 @@ struct ExamineCellsStruct
57125712
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
57135713
return 1;
57145714
}
5715-
Bool onList = false;
5716-
if (to->hasInfo()) {
5717-
if (to->getOpen() || to->getClosed())
5718-
{
5719-
// already on one of the lists
5720-
onList = true;
5721-
}
5722-
}
5715+
57235716
if (to->getPinched()) {
57245717
return 1; // abort.
57255718
}
@@ -5738,25 +5731,26 @@ struct ExamineCellsStruct
57385731
info.radius = d->radius;
57395732
info.considerTransient = false;
57405733
info.acceptableSurfaces = d->theLoco->getValidSurfaces();
5741-
if (!d->thePathfinder->checkForMovement(d->obj, info) || info.enemyFixed) {
5734+
if (!d->thePathfinder->checkForMovement(d->obj, info)) {
57425735
return 1; //abort.
57435736
}
5737+
57445738
if (info.enemyFixed) {
57455739
return 1; //abort.
57465740
}
5747-
ICoord2D newCellCoord;
5748-
newCellCoord.x = to_x;
5749-
newCellCoord.y = to_y;
5741+
5742+
if (info.allyFixedCount) {
5743+
return 1; //abort.
5744+
}
57505745

57515746
UnsignedInt newCostSoFar = from->getCostSoFar( ) + 0.5f*COST_ORTHOGONAL;
57525747
if (to->getType() == PathfindCell::CELL_CLIFF ) {
57535748
return 1;
57545749
}
5755-
if (info.allyFixedCount) {
5756-
return 1;
5757-
} else if (info.enemyFixed) {
5758-
return 1;
5759-
}
5750+
5751+
ICoord2D newCellCoord;
5752+
newCellCoord.x = to_x;
5753+
newCellCoord.y = to_y;
57605754

57615755
if (!to->allocateInfo(newCellCoord)) {
57625756
// Out of cells for pathing...
@@ -5765,15 +5759,17 @@ struct ExamineCellsStruct
57655759
to->setBlockedByAlly(false);
57665760
Int costRemaining = 0;
57675761
costRemaining = to->costToGoal( d->goalCell );
5762+
57685763
// check if this neighbor cell is already on the open (waiting to be tried)
57695764
// or closed (already tried) lists
5770-
if (onList)
5765+
if ( to->hasInfo() && (to->getOpen() || to->getClosed()) )
57715766
{
57725767
// already on one of the lists - if existing costSoFar is less,
57735768
// the new cell is on a longer path, so skip it
57745769
if (to->getCostSoFar() <= newCostSoFar)
57755770
return 0; // keep going.
57765771
}
5772+
57775773
to->setCostSoFar(newCostSoFar);
57785774
// keep track of path we're building - point back to cell we moved here from
57795775
to->setParentCell(from) ;

0 commit comments

Comments
 (0)