Skip to content

Commit 5525b78

Browse files
committed
refactor(pathfinding): simplify and reduce branching in Pathfinder::classifyLayerMapCell
1 parent b1409a7 commit 5525b78

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3567,20 +3567,23 @@ void PathfindLayer::classifyLayerMapCell( Int i, Int j , PathfindCell *cell, Bri
35673567
Coord3D center = topLeftCorner;
35683568
center.x += PATHFIND_CELL_SIZE/2;
35693569
center.y += PATHFIND_CELL_SIZE/2;
3570-
if (cell->getType()!=PathfindCell::CELL_IMPASSABLE) {
3571-
if (!(cell->getConnectLayer()==LAYER_GROUND) ) {
3572-
// Check for bridge clearance. If the ground isn't 1 pathfind cells below, mark impassable.
3573-
Real groundHeight = TheTerrainLogic->getLayerHeight( center.x, center.y, LAYER_GROUND );
3574-
Real bridgeHeight = theBridge->getBridgeHeight( &center, NULL );
3575-
if (groundHeight+LAYER_Z_CLOSE_ENOUGH_F > bridgeHeight) {
3576-
PathfindCell *groundCell = TheAI->pathfinder()->getCell(LAYER_GROUND,i, j);
3577-
if (!(groundCell->getType()==PathfindCell::CELL_OBSTACLE)) {
3578-
groundCell->setType(PathfindCell::CELL_BRIDGE_IMPASSABLE);
3579-
}
3580-
}
3570+
if (cell->getType() == PathfindCell::CELL_IMPASSABLE) {
3571+
return;
3572+
}
3573+
3574+
if (cell->getConnectLayer() == LAYER_GROUND) {
3575+
return;
3576+
}
3577+
3578+
// Check for bridge clearance. If the ground isn't 1 pathfind cells below, mark impassable.
3579+
Real groundHeight = TheTerrainLogic->getLayerHeight( center.x, center.y, LAYER_GROUND );
3580+
Real bridgeHeight = theBridge->getBridgeHeight( &center, NULL );
3581+
if (groundHeight+LAYER_Z_CLOSE_ENOUGH_F > bridgeHeight) {
3582+
PathfindCell *groundCell = TheAI->pathfinder()->getCell(LAYER_GROUND, i, j);
3583+
if (groundCell->getType() != PathfindCell::CELL_OBSTACLE) {
3584+
groundCell->setType(PathfindCell::CELL_BRIDGE_IMPASSABLE);
35813585
}
35823586
}
3583-
return;
35843587
}
35853588

35863589

0 commit comments

Comments
 (0)