Skip to content

Commit 487e5ce

Browse files
Maullerxezon
authored andcommitted
refactor(pathfinder): Simplify and improve readability of Pathfinder::getMoveAwayFromPath (#1620)
1 parent 3ce09e5 commit 487e5ce

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9596,7 +9596,9 @@ if (g_UT_startTiming) return false;
95969596
Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
95979597
Path *pathToAvoid, Object *otherObj2, Path *pathToAvoid2)
95989598
{
9599-
if (m_isMapReady == false) return NULL; // Should always be ok.
9599+
if (!m_isMapReady)
9600+
return NULL; // Should always be ok.
9601+
96009602
#ifdef DEBUG_LOGGING
96019603
Int startTimeMS = ::GetTickCount();
96029604
#endif
@@ -9627,11 +9629,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96279629
}
96289630
worldToCell(&startPos, &startCellNdx);
96299631
PathfindCell *parentCell = getClippedCell( obj->getLayer(), obj->getPosition() );
9630-
if (parentCell == NULL)
9632+
if (!parentCell)
96319633
return NULL;
9632-
if (!obj->getAIUpdateInterface()) {
9633-
return NULL; // shouldn't happen, but can't move it without an ai.
9634-
}
9634+
9635+
if (!obj->getAIUpdateInterface()) // shouldn't happen, but can't move it without an ai.
9636+
return NULL;
9637+
96359638
const LocomotorSet& locomotorSet = obj->getAIUpdateInterface()->getLocomotorSet();
96369639

96379640
m_isTunneling = false;
@@ -9686,12 +9689,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
96869689
bounds.hi.y = cellCenter.y+boxHalfWidth;
96879690
PathNode *node;
96889691
Bool overlap = false;
9689-
if (obj) {
9690-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
9691-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
9692-
//overlap = true;
9693-
}
9694-
}
9692+
96959693
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
96969694
Coord2D start, end;
96979695
start.x = node->getPosition()->x;
@@ -9703,12 +9701,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
97039701
break;
97049702
}
97059703
}
9706-
if (otherObj) {
9707-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
9708-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
9709-
//overlap = true;
9710-
}
9711-
}
9704+
97129705
if (!overlap && pathToAvoid2) {
97139706
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
97149707
Coord2D start, end;

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10020,7 +10020,9 @@ if (g_UT_startTiming) return false;
1002010020
Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1002110021
Path *pathToAvoid, Object *otherObj2, Path *pathToAvoid2)
1002210022
{
10023-
if (m_isMapReady == false) return NULL; // Should always be ok.
10023+
if (!m_isMapReady)
10024+
return NULL; // Should always be ok.
10025+
1002410026
#ifdef DEBUG_LOGGING
1002510027
Int startTimeMS = ::GetTickCount();
1002610028
#endif
@@ -10051,11 +10053,12 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1005110053
}
1005210054
worldToCell(&startPos, &startCellNdx);
1005310055
PathfindCell *parentCell = getClippedCell( obj->getLayer(), obj->getPosition() );
10054-
if (parentCell == NULL)
10056+
if (!parentCell)
1005510057
return NULL;
10056-
if (!obj->getAIUpdateInterface()) {
10057-
return NULL; // shouldn't happen, but can't move it without an ai.
10058-
}
10058+
10059+
if (!obj->getAIUpdateInterface()) // shouldn't happen, but can't move it without an ai.
10060+
return NULL;
10061+
1005910062
const LocomotorSet& locomotorSet = obj->getAIUpdateInterface()->getLocomotorSet();
1006010063

1006110064
m_isTunneling = false;
@@ -10110,12 +10113,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1011010113
bounds.hi.y = cellCenter.y+boxHalfWidth;
1011110114
PathNode *node;
1011210115
Bool overlap = false;
10113-
if (obj) {
10114-
if (bounds.lo.x<obj->getPosition()->x && bounds.hi.x>obj->getPosition()->x &&
10115-
bounds.lo.y<obj->getPosition()->y && bounds.hi.y>obj->getPosition()->y) {
10116-
//overlap = true;
10117-
}
10118-
}
10116+
1011910117
for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1012010118
Coord2D start, end;
1012110119
start.x = node->getPosition()->x;
@@ -10127,12 +10125,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1012710125
break;
1012810126
}
1012910127
}
10130-
if (otherObj) {
10131-
if (bounds.lo.x<otherObj->getPosition()->x && bounds.hi.x>otherObj->getPosition()->x &&
10132-
bounds.lo.y<otherObj->getPosition()->y && bounds.hi.y>otherObj->getPosition()->y) {
10133-
//overlap = true;
10134-
}
10135-
}
10128+
1013610129
if (!overlap && pathToAvoid2) {
1013710130
for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) {
1013810131
Coord2D start, end;

0 commit comments

Comments
 (0)