Skip to content

Commit 376eff2

Browse files
committed
refactor(pathfinding) simplify function to improve readability Pathfinder::examineCellsCallback
1 parent f5e005e commit 376eff2

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
@@ -5699,14 +5699,7 @@ struct ExamineCellsStruct
56995699
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
57005700
return 1;
57015701
}
5702-
Bool onList = false;
5703-
if (to->hasInfo()) {
5704-
if (to->getOpen() || to->getClosed())
5705-
{
5706-
// already on one of the lists
5707-
onList = true;
5708-
}
5709-
}
5702+
57105703
if (to->getPinched()) {
57115704
return 1; // abort.
57125705
}
@@ -5725,25 +5718,26 @@ struct ExamineCellsStruct
57255718
info.radius = d->radius;
57265719
info.considerTransient = false;
57275720
info.acceptableSurfaces = d->theLoco->getValidSurfaces();
5728-
if (!d->thePathfinder->checkForMovement(d->obj, info) || info.enemyFixed) {
5721+
if (!d->thePathfinder->checkForMovement(d->obj, info)) {
57295722
return 1; //abort.
57305723
}
5724+
57315725
if (info.enemyFixed) {
57325726
return 1; //abort.
57335727
}
5734-
ICoord2D newCellCoord;
5735-
newCellCoord.x = to_x;
5736-
newCellCoord.y = to_y;
5728+
5729+
if (info.allyFixedCount) {
5730+
return 1; //abort.
5731+
}
57375732

57385733
UnsignedInt newCostSoFar = from->getCostSoFar( ) + 0.5f*COST_ORTHOGONAL;
57395734
if (to->getType() == PathfindCell::CELL_CLIFF ) {
57405735
return 1;
57415736
}
5742-
if (info.allyFixedCount) {
5743-
return 1;
5744-
} else if (info.enemyFixed) {
5745-
return 1;
5746-
}
5737+
5738+
ICoord2D newCellCoord;
5739+
newCellCoord.x = to_x;
5740+
newCellCoord.y = to_y;
57475741

57485742
if (!to->allocateInfo(newCellCoord)) {
57495743
// Out of cells for pathing...
@@ -5752,15 +5746,17 @@ struct ExamineCellsStruct
57525746
to->setBlockedByAlly(false);
57535747
Int costRemaining = 0;
57545748
costRemaining = to->costToGoal( d->goalCell );
5749+
57555750
// check if this neighbor cell is already on the open (waiting to be tried)
57565751
// or closed (already tried) lists
5757-
if (onList)
5752+
if ( to->hasInfo() && (to->getOpen() || to->getClosed()) )
57585753
{
57595754
// already on one of the lists - if existing costSoFar is less,
57605755
// the new cell is on a longer path, so skip it
57615756
if (to->getCostSoFar() <= newCostSoFar)
57625757
return 0; // keep going.
57635758
}
5759+
57645760
to->setCostSoFar(newCostSoFar);
57655761
// keep track of path we're building - point back to cell we moved here from
57665762
to->setParentCell(from) ;

0 commit comments

Comments
 (0)