Skip to content

Commit bb37a9b

Browse files
Maullerxezon
authored andcommitted
unify(pathfinder): Merge PathfindCell::setTypeAsObstacle() and PathfindCell::removeObstacle() from Zero Hour (TheSuperHackers#2381)
1 parent b0a9a7c commit bb37a9b

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ class PathfindCell
301301
PathfindCell();
302302
~PathfindCell();
303303

304-
void setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoord2D &pos ); ///< flag this cell as an obstacle, from the given one
305-
void removeObstacle( Object *obstacle ); ///< flag this cell as an obstacle, from the given one
304+
Bool setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoord2D &pos ); ///< flag this cell as an obstacle, from the given one
305+
Bool removeObstacle( Object *obstacle ); ///< unflag this cell as an obstacle, from the given one
306306
void setType( CellType type ); ///< set the cell type
307307
CellType getType() const { return (CellType)m_type; } ///< get the cell type
308308
CellFlags getFlags() const { return (CellFlags)m_flags; } ///< get the cell type

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,11 +1545,12 @@ inline ObjectID PathfindCell::getObstacleID() const
15451545

15461546
/**
15471547
* Flag this cell as an obstacle, from the given one.
1548+
* Return true if cell was flagged.
15481549
*/
1549-
void PathfindCell::setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoord2D &pos )
1550+
Bool PathfindCell::setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoord2D &pos )
15501551
{
15511552
if (m_type!=PathfindCell::CELL_CLEAR && m_type != PathfindCell::CELL_IMPASSABLE) {
1552-
return;
1553+
return false;
15531554
}
15541555

15551556
Bool isRubble = false;
@@ -1565,15 +1566,15 @@ void PathfindCell::setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoo
15651566
m_obstacleIsTransparent = false;
15661567
#if RETAIL_COMPATIBLE_PATHFINDING_ALLOCATION
15671568
if (s_useFixedPathfinding) {
1568-
return;
1569+
return true;
15691570
}
15701571

15711572
if (m_info) {
15721573
m_info->m_obstacleID = INVALID_ID;
15731574
releaseInfo();
15741575
}
15751576
#endif
1576-
return;
1577+
return true;
15771578
}
15781579

15791580
m_type = PathfindCell::CELL_OBSTACLE;
@@ -1584,21 +1585,21 @@ void PathfindCell::setTypeAsObstacle( Object *obstacle, Bool isFence, const ICoo
15841585
// TheSuperHackers @info In retail mode we need to track orphaned cells set as obstacles so we can cleanup and failover properly
15851586
// So we always make sure to set and clear the local obstacle data on the PathfindCell regardless of retail compat or not
15861587
if (s_useFixedPathfinding) {
1587-
return;
1588+
return true;
15881589
}
15891590

15901591
if (!m_info) {
15911592
m_info = PathfindCellInfo::getACellInfo(this, pos);
15921593
if (!m_info) {
15931594
DEBUG_CRASH(("Not enough PathFindCellInfos in pool."));
1594-
return;
1595+
return false;
15951596
}
15961597
}
15971598
m_info->m_obstacleID = obstacle->getID();
15981599
m_info->m_obstacleIsFence = isFence;
15991600
m_info->m_obstacleIsTransparent = obstacle->isKindOf(KINDOF_CAN_SEE_THROUGH_STRUCTURE);
16001601
#endif
1601-
return;
1602+
return true;
16021603
}
16031604

16041605
/**
@@ -1632,36 +1633,37 @@ void PathfindCell::setType( CellType type )
16321633

16331634
/**
16341635
* Unflag this cell as an obstacle, from the given one.
1636+
* Return true if this cell was previously flagged as an obstacle by this object.
16351637
*/
1636-
void PathfindCell::removeObstacle( Object *obstacle )
1638+
Bool PathfindCell::removeObstacle( Object *obstacle )
16371639
{
16381640
if (m_type == PathfindCell::CELL_RUBBLE) {
16391641
m_type = PathfindCell::CELL_CLEAR;
16401642
}
16411643
#if RETAIL_COMPATIBLE_PATHFINDING_ALLOCATION
16421644
if (s_useFixedPathfinding) {
1643-
if (m_obstacleID != obstacle->getID()) return;
1645+
if (m_obstacleID != obstacle->getID()) return false;
16441646
m_type = PathfindCell::CELL_CLEAR;
16451647
m_obstacleID = INVALID_ID;
16461648
m_obstacleIsFence = false;
16471649
m_obstacleIsTransparent = false;
1648-
return;
1650+
return true;
16491651
}
16501652

1651-
if (!m_info) return;
1652-
if (m_info->m_obstacleID != obstacle->getID()) return;
1653+
if (!m_info) return false;
1654+
if (m_info->m_obstacleID != obstacle->getID()) return false;
16531655
m_type = PathfindCell::CELL_CLEAR;
16541656
m_info->m_obstacleID = INVALID_ID;
16551657
releaseInfo();
16561658

16571659
#else
1658-
if (m_obstacleID != obstacle->getID()) return;
1660+
if (m_obstacleID != obstacle->getID()) return false;
16591661
m_type = PathfindCell::CELL_CLEAR;
16601662
#endif
16611663
m_obstacleID = INVALID_ID;
16621664
m_obstacleIsFence = false;
16631665
m_obstacleIsTransparent = false;
1664-
return;
1666+
return true;
16651667
}
16661668

16671669
/// put self on "open" list in ascending cost order, return new list

0 commit comments

Comments
 (0)