Skip to content

Commit 172362c

Browse files
Maullerxezon
authored andcommitted
refactor(pathfinder): Simplify and improve readability of Pathfinder::internalFindPath (#1620)
1 parent 6c6e05b commit 172362c

File tree

2 files changed

+8
-40
lines changed

2 files changed

+8
-40
lines changed

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5829,30 +5829,14 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
58295829
// to ignore obstacle cells until it reaches a cell that is no longer
58305830
// classified as an obstacle. At that point, the pathfind behaves normally.
58315831
//
5832-
if (parentCell->getType() == PathfindCell::CELL_OBSTACLE) {
5833-
m_isTunneling = true;
5834-
}
5835-
else {
5836-
m_isTunneling = false;
5837-
}
5832+
m_isTunneling = parentCell->getType() == PathfindCell::CELL_OBSTACLE;
58385833

58395834
Int zone1, zone2;
58405835
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
58415836
zone1 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, parentCell->getZone());
58425837
zone2 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, goalCell->getZone());
58435838

5844-
if (layer==LAYER_WALL && zone1 == 0) {
5845-
#if RETAIL_COMPATIBLE_PATHFINDING
5846-
if (s_useFixedPathfinding)
5847-
#endif
5848-
{
5849-
goalCell->releaseInfo();
5850-
parentCell->releaseInfo();
5851-
}
5852-
return NULL;
5853-
}
5854-
5855-
if (destinationLayer==LAYER_WALL && zone2 == 0) {
5839+
if ( (layer==LAYER_WALL && zone1 == 0) || (destinationLayer==LAYER_WALL && zone2 == 0) ) {
58565840
#if RETAIL_COMPATIBLE_PATHFINDING
58575841
if (s_useFixedPathfinding)
58585842
#endif
@@ -5881,15 +5865,15 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
58815865
}
58825866

58835867
// sanity check - if destination is invalid, can't path there
5884-
if (validMovementPosition( isCrusher, destinationLayer, locomotorSet, to ) == false) {
5868+
if (!validMovementPosition( isCrusher, destinationLayer, locomotorSet, to )) {
58855869
m_isTunneling = false;
58865870
goalCell->releaseInfo();
58875871
parentCell->releaseInfo();
58885872
return NULL;
58895873
}
58905874

58915875
// sanity check - if source is invalid, we have to cheat
5892-
if (validMovementPosition( isCrusher, layer, locomotorSet, from ) == false) {
5876+
if (!validMovementPosition( isCrusher, layer, locomotorSet, from )) {
58935877
// somehow we got to an impassable location.
58945878
m_isTunneling = true;
58955879
}

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,30 +6129,14 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
61296129
// to ignore obstacle cells until it reaches a cell that is no longer
61306130
// classified as an obstacle. At that point, the pathfind behaves normally.
61316131
//
6132-
if (parentCell->getType() == PathfindCell::CELL_OBSTACLE) {
6133-
m_isTunneling = true;
6134-
}
6135-
else {
6136-
m_isTunneling = false;
6137-
}
6132+
m_isTunneling = parentCell->getType() == PathfindCell::CELL_OBSTACLE;
61386133

61396134
Int zone1, zone2;
61406135
Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false;
61416136
zone1 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, parentCell->getZone());
61426137
zone2 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, goalCell->getZone());
61436138

6144-
if (layer==LAYER_WALL && zone1 == 0) {
6145-
#if RETAIL_COMPATIBLE_PATHFINDING
6146-
if (s_useFixedPathfinding)
6147-
#endif
6148-
{
6149-
goalCell->releaseInfo();
6150-
parentCell->releaseInfo();
6151-
}
6152-
return NULL;
6153-
}
6154-
6155-
if (destinationLayer==LAYER_WALL && zone2 == 0) {
6139+
if ( (layer==LAYER_WALL && zone1 == 0) || (destinationLayer==LAYER_WALL && zone2 == 0) ) {
61566140
#if RETAIL_COMPATIBLE_PATHFINDING
61576141
if (s_useFixedPathfinding)
61586142
#endif
@@ -6181,15 +6165,15 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
61816165
}
61826166

61836167
// sanity check - if destination is invalid, can't path there
6184-
if (validMovementPosition( isCrusher, destinationLayer, locomotorSet, to ) == false) {
6168+
if (!validMovementPosition( isCrusher, destinationLayer, locomotorSet, to )) {
61856169
m_isTunneling = false;
61866170
goalCell->releaseInfo();
61876171
parentCell->releaseInfo();
61886172
return NULL;
61896173
}
61906174

61916175
// sanity check - if source is invalid, we have to cheat
6192-
if (validMovementPosition( isCrusher, layer, locomotorSet, from ) == false) {
6176+
if (!validMovementPosition( isCrusher, layer, locomotorSet, from )) {
61936177
// somehow we got to an impassable location.
61946178
m_isTunneling = true;
61956179
}

0 commit comments

Comments
 (0)