Skip to content

Commit c95e79b

Browse files
Maullerxezon
authored andcommitted
refactor(pathfinder): Simplify and improve readability of Pathfinder::examineCellsCallback (#1645)
1 parent 155280b commit c95e79b

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5413,14 +5413,7 @@ struct ExamineCellsStruct
54135413
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
54145414
return 1;
54155415
}
5416-
Bool onList = false;
5417-
if (to->hasInfo()) {
5418-
if (to->getOpen() || to->getClosed())
5419-
{
5420-
// already on one of the lists
5421-
onList = true;
5422-
}
5423-
}
5416+
54245417
if (to->getPinched()) {
54255418
return 1; // abort.
54265419
}
@@ -5439,25 +5432,26 @@ struct ExamineCellsStruct
54395432
info.radius = d->radius;
54405433
info.considerTransient = false;
54415434
info.acceptableSurfaces = d->theLoco->getValidSurfaces();
5442-
if (!d->thePathfinder->checkForMovement(d->obj, info) || info.enemyFixed) {
5435+
if (!d->thePathfinder->checkForMovement(d->obj, info)) {
54435436
return 1; //abort.
54445437
}
5438+
54455439
if (info.enemyFixed) {
54465440
return 1; //abort.
54475441
}
5448-
ICoord2D newCellCoord;
5449-
newCellCoord.x = to_x;
5450-
newCellCoord.y = to_y;
5442+
5443+
if (info.allyFixedCount) {
5444+
return 1; //abort.
5445+
}
54515446

54525447
UnsignedInt newCostSoFar = from->getCostSoFar( ) + 0.5f*COST_ORTHOGONAL;
54535448
if (to->getType() == PathfindCell::CELL_CLIFF ) {
54545449
return 1;
54555450
}
5456-
if (info.allyFixedCount) {
5457-
return 1;
5458-
} else if (info.enemyFixed) {
5459-
return 1;
5460-
}
5451+
5452+
ICoord2D newCellCoord;
5453+
newCellCoord.x = to_x;
5454+
newCellCoord.y = to_y;
54615455

54625456
if (!to->allocateInfo(newCellCoord)) {
54635457
// Out of cells for pathing...
@@ -5466,15 +5460,17 @@ struct ExamineCellsStruct
54665460
to->setBlockedByAlly(false);
54675461
Int costRemaining = 0;
54685462
costRemaining = to->costToGoal( d->goalCell );
5463+
54695464
// check if this neighbor cell is already on the open (waiting to be tried)
54705465
// or closed (already tried) lists
5471-
if (onList)
5466+
if ( to->hasInfo() && (to->getOpen() || to->getClosed()) )
54725467
{
54735468
// already on one of the lists - if existing costSoFar is less,
54745469
// the new cell is on a longer path, so skip it
54755470
if (to->getCostSoFar() <= newCostSoFar)
54765471
return 0; // keep going.
54775472
}
5473+
54785474
to->setCostSoFar(newCostSoFar);
54795475
// keep track of path we're building - point back to cell we moved here from
54805476
to->setParentCell(from) ;

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)