Skip to content

Commit 263c6a0

Browse files
Maullerxezon
authored andcommitted
unify(pathfinder): Merge PathfindCell class from Zero Hour (TheSuperHackers#2381)
1 parent fe12f1d commit 263c6a0

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
class Bridge;
3838
class Object;
39-
class PathfindCell;
40-
class PathfindZoneManager;
4139
class Weapon;
40+
class PathfindZoneManager;
41+
class PathfindCell;
4242

4343
// How close is close enough when moving.
4444

@@ -356,13 +356,13 @@ class PathfindCell
356356
inline UnsignedInt getCostSoFar() const {return m_info->m_costSoFar;}
357357
inline UnsignedInt getTotalCost() const {return m_info->m_totalCost;}
358358

359-
inline void setCostSoFar(UnsignedInt cost) {m_info->m_costSoFar = cost;}
360-
inline void setTotalCost(UnsignedInt cost) {m_info->m_totalCost = cost;}
359+
inline void setCostSoFar(UnsignedInt cost) { if( m_info ) m_info->m_costSoFar = cost;}
360+
inline void setTotalCost(UnsignedInt cost) { if( m_info ) m_info->m_totalCost = cost;}
361361

362362
void setParentCell(PathfindCell* parent);
363363
void clearParentCell();
364364
void setParentCellHierarchical(PathfindCell* parent);
365-
inline PathfindCell* getParentCell() const {return m_info->m_pathParent?m_info->m_pathParent->m_cell: nullptr;}
365+
inline PathfindCell* getParentCell() const {return m_info ? m_info->m_pathParent ? m_info->m_pathParent->m_cell : nullptr : nullptr;}
366366

367367
Bool startPathfind( PathfindCell *goalCell );
368368
Bool getPinched() const {return m_pinched;}
@@ -590,7 +590,7 @@ class PathfindServicesInterface {
590590
virtual Path *findPath( Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from,
591591
const Coord3D *to )=0; ///< Find a short, valid path between given locations
592592
/** Find a short, valid path to a location NEAR the to location.
593-
This succeds when the destination is unreachable (like inside a building).
593+
This succeeds when the destination is unreachable (like inside a building).
594594
If the destination is unreachable, it will adjust the to point. */
595595
virtual Path *findClosestPath( Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from,
596596
Coord3D *to, Bool blocked, Real pathCostMultiplier, Bool moveAllies )=0;
@@ -619,7 +619,7 @@ class Pathfinder : PathfindServicesInterface, public Snapshot
619619
private:
620620
virtual Path *findPath( Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from, const Coord3D *to); ///< Find a short, valid path between given locations
621621
/** Find a short, valid path to a location NEAR the to location.
622-
This succeds when the destination is unreachable (like inside a building).
622+
This succeeds when the destination is unreachable (like inside a building).
623623
If the destination is unreachable, it will adjust the to point. */
624624
virtual Path *findClosestPath( Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from,
625625
Coord3D *to, Bool blocked, Real pathCostMultiplier, Bool moveAllies );

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,11 @@ UnsignedInt PathfindCell::costToGoal( PathfindCell *goal )
19571957

19581958
UnsignedInt PathfindCell::costToHierGoal( PathfindCell *goal )
19591959
{
1960-
DEBUG_ASSERTCRASH(m_info, ("Has to have info."));
1960+
if( !m_info )
1961+
{
1962+
DEBUG_CRASH( ("Has to have info.") );
1963+
return 100000; //...patch hack 1.01
1964+
}
19611965
Int dx = m_info->m_pos.x - goal->getXIndex();
19621966
Int dy = m_info->m_pos.y - goal->getYIndex();
19631967
Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*sqrt(dx*dx + dy*dy) + 0.5f);

0 commit comments

Comments
 (0)