@@ -5362,6 +5362,13 @@ void Pathfinder::checkChangeLayers(PathfindCell *parentCell)
53625362 m_openList = newCell->putOnSortedOpenList ( m_openList );
53635363}
53645364
5365+ bool Pathfinder::checkCellOutsideExtents (ICoord2D& cell) {
5366+ return cell.x < m_logicalExtent.lo .x ||
5367+ cell.x > m_logicalExtent.hi .x ||
5368+ cell.y < m_logicalExtent.lo .y ||
5369+ cell.y > m_logicalExtent.hi .y ;
5370+ }
5371+
53655372
53665373struct ExamineCellsStruct
53675374{
@@ -5529,13 +5536,10 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
55295536 if ((newCell->getLayer ()==LAYER_GROUND) && !m_zoneManager.isPassable (newCellCoord.x , newCellCoord.y )) {
55305537 notZonePassable = true ;
55315538 }
5532- if (isHuman) {
5533- // check if new cell is in logical map. (computer can move off logical map)
5534- if (newCellCoord.x < m_logicalExtent.lo .x ) continue ;
5535- if (newCellCoord.y < m_logicalExtent.lo .y ) continue ;
5536- if (newCellCoord.x > m_logicalExtent.hi .x ) continue ;
5537- if (newCellCoord.y > m_logicalExtent.hi .y ) continue ;
5538- }
5539+
5540+ // check if new cell is in logical map. (computer can move off logical map)
5541+ if (isHuman && checkCellOutsideExtents (newCellCoord))
5542+ continue ;
55395543
55405544 // check if this neighbor cell is already on the open (waiting to be tried)
55415545 // or closed (already tried) lists
@@ -6818,9 +6822,10 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
68186822
68196823 // determine goal cell
68206824 PathfindCell *goalCell = getCell ( destinationLayer, cell.x , cell.y );
6821- if (goalCell == NULL ) {
6825+ if (! goalCell) {
68226826 return NULL ;
68236827 }
6828+
68246829 if (!goalCell->allocateInfo (cell)) {
68256830 return NULL ;
68266831 }
@@ -6829,9 +6834,10 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
68296834 ICoord2D startCellNdx;
68306835 PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination (from);
68316836 PathfindCell *parentCell = getClippedCell ( layer,&clipFrom );
6832- if (parentCell == NULL ) {
6837+ if (! parentCell) {
68336838 return NULL ;
68346839 }
6840+
68356841 if (parentCell!=goalCell) {
68366842 worldToCell (&clipFrom, &startCellNdx);
68376843 if (!parentCell->allocateInfo (startCellNdx)) {
@@ -6872,11 +6878,10 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
68726878 goalBlockNdx.y = -1 ;
68736879 }
68746880
6875- if (parentCell->getLayer ()==LAYER_GROUND) {
6876- // initialize "open" list to contain start cell
6877- m_openList = parentCell;
6878- } else {
6879- m_openList = parentCell;
6881+ // initialize "open" list to contain start cell
6882+ m_openList = parentCell;
6883+
6884+ if (parentCell->getLayer ()!=LAYER_GROUND) {
68806885 PathfindLayerEnum layer = parentCell->getLayer ();
68816886 // We're starting on a bridge, so link to land at the bridge end points.
68826887 ICoord2D ndx;
@@ -7008,12 +7013,16 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
70087013 break ;
70097014 }
70107015 PathfindCell *cell = getCell (LAYER_GROUND, toNdx.x , toNdx.y );
7011- if (cell==NULL ) continue ;
7012- if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ())) {
7016+ if (!cell)
70137017 continue ;
7014- }
7018+
7019+ if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ()))
7020+ continue ;
7021+
70157022 PathfindCell *startCell = getCell (LAYER_GROUND, ndx.x , ndx.y );
7016- if (startCell==NULL ) continue ;
7023+ if (!startCell)
7024+ continue ;
7025+
70177026 if (startCell != parentCell) {
70187027 if (!startCell->allocateInfo (ndx)) {
70197028 // TheSuperHackers @info We need to forcefully cleanup dangling pathfinding cells if this failure condition is hit in retail
@@ -7149,20 +7158,19 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
71497158 ICoord2D delta;
71507159 delta.x = -1 ; // left side moves -1.
71517160 delta.y = 0 ;
7161+
71527162 PathfindCell *cell = getCell (LAYER_GROUND, scanCell.x , scanCell.y );
7153- if (cell==NULL ) continue ;
7154- if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ())) {
7155- if (parentZone == m_zoneManager.getBlockZone (locomotorSurface,
7156- crusher, scanCell.x , scanCell.y , m_map)) {
7163+ if (!cell)
7164+ continue ;
7165+
7166+ if ( cell->hasInfo () && (cell->getClosed () || cell->getOpen ()) ) {
7167+ if (parentZone == m_zoneManager.getBlockZone (locomotorSurface, crusher, scanCell.x , scanCell.y , m_map))
71577168 break ;
7158- }
7159- }
7160- if (isHuman) {
7161- if (scanCell.x < m_logicalExtent.lo .x || scanCell.x > m_logicalExtent.hi .x ||
7162- scanCell.y < m_logicalExtent.lo .y || scanCell.y > m_logicalExtent.hi .y ) {
7163- continue ;
7164- }
71657169 }
7170+
7171+ if (isHuman && checkCellOutsideExtents (scanCell))
7172+ continue ;
7173+
71667174 processHierarchicalCell (scanCell, delta, parentCell,
71677175 goalCell, parentZone, examinedZones, numExZones, crusher, cellCount);
71687176 }
@@ -7182,20 +7190,19 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
71827190 ICoord2D delta;
71837191 delta.x = 1 ; // right side moves +1.
71847192 delta.y = 0 ;
7193+
71857194 PathfindCell *cell = getCell (LAYER_GROUND, scanCell.x , scanCell.y );
7186- if (cell==NULL ) continue ;
7187- if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ())) {
7188- if (parentZone == m_zoneManager.getBlockZone (locomotorSurface,
7189- crusher, scanCell.x , scanCell.y , m_map)) {
7195+ if (!cell)
7196+ continue ;
7197+
7198+ if ( cell->hasInfo () && (cell->getClosed () || cell->getOpen ()) ) {
7199+ if (parentZone == m_zoneManager.getBlockZone (locomotorSurface, crusher, scanCell.x , scanCell.y , m_map))
71907200 break ;
7191- }
7192- }
7193- if (isHuman) {
7194- if (scanCell.x < m_logicalExtent.lo .x || scanCell.x > m_logicalExtent.hi .x ||
7195- scanCell.y < m_logicalExtent.lo .y || scanCell.y > m_logicalExtent.hi .y ) {
7196- continue ;
7197- }
71987201 }
7202+
7203+ if (isHuman && checkCellOutsideExtents (scanCell))
7204+ continue ;
7205+
71997206 processHierarchicalCell (scanCell, delta, parentCell,
72007207 goalCell, parentZone, examinedZones, numExZones, crusher, cellCount);
72017208 }
@@ -7214,20 +7221,19 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
72147221 ICoord2D delta;
72157222 delta.x = 0 ;
72167223 delta.y = -1 ; // Top side moves -1.
7224+
72177225 PathfindCell *cell = getCell (LAYER_GROUND, scanCell.x , scanCell.y );
7218- if (cell==NULL ) continue ;
7219- if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ())) {
7220- if (parentZone == m_zoneManager.getBlockZone (locomotorSurface,
7221- crusher, scanCell.x , scanCell.y , m_map)) {
7226+ if (!cell)
7227+ continue ;
7228+
7229+ if ( cell->hasInfo () && (cell->getClosed () || cell->getOpen ()) ) {
7230+ if (parentZone == m_zoneManager.getBlockZone (locomotorSurface, crusher, scanCell.x , scanCell.y , m_map))
72227231 break ;
7223- }
7224- }
7225- if (isHuman) {
7226- if (scanCell.x < m_logicalExtent.lo .x || scanCell.x > m_logicalExtent.hi .x ||
7227- scanCell.y < m_logicalExtent.lo .y || scanCell.y > m_logicalExtent.hi .y ) {
7228- continue ;
7229- }
72307232 }
7233+
7234+ if (isHuman && checkCellOutsideExtents (scanCell))
7235+ continue ;
7236+
72317237 processHierarchicalCell (scanCell, delta, parentCell,
72327238 goalCell, parentZone, examinedZones, numExZones, crusher, cellCount);
72337239 }
@@ -7247,20 +7253,19 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
72477253 ICoord2D delta;
72487254 delta.x = 0 ;
72497255 delta.y = 1 ; // Top side moves +1.
7256+
72507257 PathfindCell *cell = getCell (LAYER_GROUND, scanCell.x , scanCell.y );
7251- if (cell==NULL ) continue ;
7252- if (cell->hasInfo () && (cell->getClosed () || cell->getOpen ())) {
7253- if (parentZone == m_zoneManager.getBlockZone (locomotorSurface,
7254- crusher, scanCell.x , scanCell.y , m_map)) {
7258+ if (!cell)
7259+ continue ;
7260+
7261+ if ( cell->hasInfo () && (cell->getClosed () || cell->getOpen ()) ) {
7262+ if (parentZone == m_zoneManager.getBlockZone (locomotorSurface, crusher, scanCell.x , scanCell.y , m_map))
72557263 break ;
7256- }
7257- }
7258- if (isHuman) {
7259- if (scanCell.x < m_logicalExtent.lo .x || scanCell.x > m_logicalExtent.hi .x ||
7260- scanCell.y < m_logicalExtent.lo .y || scanCell.y > m_logicalExtent.hi .y ) {
7261- continue ;
7262- }
72637264 }
7265+
7266+ if (isHuman && checkCellOutsideExtents (scanCell))
7267+ continue ;
7268+
72647269 processHierarchicalCell (scanCell, delta, parentCell,
72657270 goalCell, parentZone, examinedZones, numExZones, crusher, cellCount);
72667271 }
0 commit comments