From 380fd19af4a20e69ad534b2c5906e1abeb1f7318 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sun, 15 Feb 2026 02:23:08 +0100 Subject: [PATCH 1/2] Removed function Pathfinder::pathDestination. --- .../GameEngine/Include/GameLogic/AIPathfind.h | 3 - .../Source/GameLogic/AI/AIPathfind.cpp | 245 ------------------ 2 files changed, 248 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h index a7ab136c909..7a45586731f 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h @@ -780,9 +780,6 @@ class Pathfinder : PathfindServicesInterface, public Snapshot Bool centerInCell, Int radius, const ICoord2D &startCellNdx, const Object *obj, Int attackDistance); - Bool pathDestination( Object *obj, const LocomotorSet& locomotorSet, Coord3D *dest, - PathfindLayerEnum layer, const Coord3D *groupDest); ///< Checks cost between given locations - Int checkPathCost(Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from, const Coord3D *to); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index f6f4c98fc5d..0278629264c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -8103,251 +8103,6 @@ void Pathfinder::clip( Coord3D *from, Coord3D *to ) } -Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet, Coord3D *dest, - PathfindLayerEnum layer, const Coord3D *groupDest) -{ - //CRCDEBUG_LOG(("Pathfinder::pathDestination()")); - if (m_isMapReady == false) return false; - - if (!obj) return false; - - Int cellCount = 0; - - Coord3D adjustTo = *groupDest; - Coord3D *to = &adjustTo; - DEBUG_ASSERTCRASH(m_openList== nullptr && m_closedList == nullptr, ("Dangling lists.")); - // create unique "mark" values for open and closed cells for this pathfind invocation - - Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false; - - PathfindLayerEnum desiredLayer = TheTerrainLogic->getLayerForDestination(dest); - // determine desired - PathfindCell *desiredCell = getClippedCell( desiredLayer, dest ); - if (desiredCell == nullptr) - return FALSE; - - PathfindLayerEnum goalLayer = TheTerrainLogic->getLayerForDestination(to); - // determine goal cell - PathfindCell *goalCell = getClippedCell( goalLayer, to ); - if (goalCell == nullptr) - return FALSE; - - - Bool isHuman = true; - if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) { - isHuman = false; // computer gets to cheat. - } - Bool center; - Int radius; - getRadiusAndCenter(obj, radius, center); - - // determine start cell - ICoord2D startCellNdx; - worldToCell(dest, &startCellNdx); - PathfindCell *parentCell = getCell( layer, startCellNdx.x, startCellNdx.y ); - if (parentCell == nullptr) - return FALSE; - ICoord2D pos2d; - worldToCell(to, &pos2d); - if (!goalCell->allocateInfo(pos2d)) { - return FALSE; - } - - if (parentCell!=goalCell) { - if (!parentCell->allocateInfo(startCellNdx)) { -#if RETAIL_COMPATIBLE_PATHFINDING - if (!s_useFixedPathfinding) { - desiredCell->releaseInfo(); - } -#endif - goalCell->releaseInfo(); - return FALSE; - } - } - - PathfindCell *closestCell = nullptr; - Real closestDistanceSqr = FLT_MAX; - Coord3D closestPos; - - if (validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), parentCell ) == false) { - parentCell->releaseInfo(); - goalCell->releaseInfo(); - return FALSE; - } - - parentCell->startPathfind(goalCell); - - // initialize "open" list to contain start cell - m_openList = parentCell; - - // "closed" list is initially empty - m_closedList = nullptr; - - // - // Continue search until "open" list is empty, or - // until goal is found. - // - while( m_openList != nullptr ) - { - // take head cell off of open list - it has lowest estimated total path cost - parentCell = m_openList; - m_openList = parentCell->removeFromOpenList(m_openList); - - Coord3D pos; - // put parent cell onto closed list - its evaluation is finished - m_closedList = parentCell->putOnClosedList( m_closedList ); - if (checkForAdjust(obj, locomotorSet, isHuman, parentCell->getXIndex(), parentCell->getYIndex(), parentCell->getLayer(), - radius, center, &pos, groupDest)) { - Int dx = IABS(goalCell->getXIndex()-parentCell->getXIndex()); - Int dy = IABS(goalCell->getYIndex()-parentCell->getYIndex()); - Real distSqr = dx*dx+dy*dy; - - if (distSqr < closestDistanceSqr) { - closestCell = parentCell; - closestDistanceSqr = distSqr; - closestPos = pos; - } else { - continue; - } - } else { - continue; - } - - if (cellCount > MAX_CELL_COUNT) { - continue; - } - // Check to see if we can change layers in this cell. - checkChangeLayers(parentCell); - - // expand search to neighboring orthogonal cells - static ICoord2D delta[] = - { - { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }, - { 1, 1 }, { -1, 1 }, { -1, -1 }, { 1, -1 } - }; - const Int numNeighbors = 8; - const Int firstDiagonal = 4; - ICoord2D newCellCoord; - PathfindCell *newCell; - const Int adjacent[5] = {0, 1, 2, 3, 0}; - Bool neighborFlags[8] = { 0 }; - - UnsignedInt newCostSoFar = 0; - - for( int i=0; igetXIndex() + delta[i].x; - newCellCoord.y = parentCell->getYIndex() + delta[i].y; - - // get the neighboring cell - newCell = getCell(parentCell->getLayer(), newCellCoord.x, newCellCoord.y ); - - // check if cell is on the map - if (newCell == nullptr) - continue; - - // check if this neighbor cell is already on the open (waiting to be tried) - // or closed (already tried) lists - Bool onList = false; - if (newCell->hasInfo()) { - if (newCell->getOpen() || newCell->getClosed()) - { - // already on one of the lists - onList = true; - } - } - if (i>=firstDiagonal) { - // make sure one of the adjacent sides is open. - if (!neighborFlags[adjacent[i-4]] && !neighborFlags[adjacent[i-3]]) { - continue; - } - } - - if (!validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), newCell, parentCell )) { - continue; - } - - neighborFlags[i] = true; - - if (!newCell->allocateInfo(newCellCoord)) { - // Out of cells for pathing... -#if RETAIL_COMPATIBLE_PATHFINDING - if (s_useFixedPathfinding) -#endif - { - cleanOpenAndClosedLists(); - goalCell->releaseInfo(); - } - return cellCount; - } - cellCount++; - - newCostSoFar = newCell->costSoFar( parentCell ); - newCell->setBlockedByAlly(false); - - // check if this neighbor cell is already on the open (waiting to be tried) - // or closed (already tried) lists - if (onList) - { - // already on one of the lists - if existing costSoFar is less, - // the new cell is on a longer path, so skip it - if (newCell->getCostSoFar() <= newCostSoFar) - continue; - } - - // keep track of path we're building - point back to cell we moved here from - newCell->setParentCell(parentCell) ; - - // store cost of this path - newCell->setCostSoFar(newCostSoFar); - - Int costRemaining = 0; - if (goalCell) { - costRemaining = newCell->costToGoal( goalCell ); - } - - newCell->setTotalCost(newCell->getCostSoFar() + costRemaining) ; - - // if newCell was on closed list, remove it from the list - if (newCell->getClosed()) - m_closedList = newCell->removeFromClosedList( m_closedList ); - - // if the newCell was already on the open list, remove it so it can be re-inserted in order - if (newCell->getOpen()) - m_openList = newCell->removeFromOpenList( m_openList ); - - // insert newCell in open list such that open list is sorted, smallest total path cost first - m_openList = newCell->putOnSortedOpenList( m_openList ); - } - } - -#if defined(RTS_DEBUG) - if (closestCell) { - debugShowSearch(true); - *dest = closestPos; - } else { - debugShowSearch(true); - } -#endif - m_isTunneling = false; -#if RETAIL_COMPATIBLE_PATHFINDING - if (!s_useFixedPathfinding) { - cleanOpenAndClosedLists(); - goalCell->releaseInfo(); - } - else -#endif - { - cleanOpenAndClosedLists(); - parentCell->releaseInfo(); - goalCell->releaseInfo(); - } - - return false; -} - struct TightenPathStruct { Object *obj; From 50dc0902065746a26b347344d956e4adc9f13006 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sun, 15 Feb 2026 02:24:47 +0100 Subject: [PATCH 2/2] Replicated in Generals. --- .../GameEngine/Include/GameLogic/AIPathfind.h | 3 - .../Source/GameLogic/AI/AIPathfind.cpp | 245 ------------------ 2 files changed, 248 deletions(-) diff --git a/Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h b/Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h index d147c9650c5..4ac885778cc 100644 --- a/Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h +++ b/Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h @@ -772,9 +772,6 @@ class Pathfinder : PathfindServicesInterface, public Snapshot Bool centerInCell, Int radius, const ICoord2D &startCellNdx, const Object *obj, Int attackDistance); - Bool pathDestination( Object *obj, const LocomotorSet& locomotorSet, Coord3D *dest, - PathfindLayerEnum layer, const Coord3D *groupDest); ///< Checks cost between given locations - Int checkPathCost(Object *obj, const LocomotorSet& locomotorSet, const Coord3D *from, const Coord3D *to); diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 2e2dc8822cd..794cde8e5d0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -7699,251 +7699,6 @@ void Pathfinder::clip( Coord3D *from, Coord3D *to ) } -Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet, Coord3D *dest, - PathfindLayerEnum layer, const Coord3D *groupDest) -{ - //CRCDEBUG_LOG(("Pathfinder::pathDestination()")); - if (m_isMapReady == false) return false; - - if (!obj) return false; - - Int cellCount = 0; - - Coord3D adjustTo = *groupDest; - Coord3D *to = &adjustTo; - DEBUG_ASSERTCRASH(m_openList== nullptr && m_closedList == nullptr, ("Dangling lists.")); - // create unique "mark" values for open and closed cells for this pathfind invocation - - Bool isCrusher = obj ? obj->getCrusherLevel() > 0 : false; - - PathfindLayerEnum desiredLayer = TheTerrainLogic->getLayerForDestination(dest); - // determine desired - PathfindCell *desiredCell = getClippedCell( desiredLayer, dest ); - if (desiredCell == nullptr) - return FALSE; - - PathfindLayerEnum goalLayer = TheTerrainLogic->getLayerForDestination(to); - // determine goal cell - PathfindCell *goalCell = getClippedCell( goalLayer, to ); - if (goalCell == nullptr) - return FALSE; - - - Bool isHuman = true; - if (obj && obj->getControllingPlayer() && (obj->getControllingPlayer()->getPlayerType()==PLAYER_COMPUTER)) { - isHuman = false; // computer gets to cheat. - } - Bool center; - Int radius; - getRadiusAndCenter(obj, radius, center); - - // determine start cell - ICoord2D startCellNdx; - worldToCell(dest, &startCellNdx); - PathfindCell *parentCell = getCell( layer, startCellNdx.x, startCellNdx.y ); - if (parentCell == nullptr) - return FALSE; - ICoord2D pos2d; - worldToCell(to, &pos2d); - if (!goalCell->allocateInfo(pos2d)) { - return FALSE; - } - - if (parentCell!=goalCell) { - if (!parentCell->allocateInfo(startCellNdx)) { -#if RETAIL_COMPATIBLE_PATHFINDING - if (!s_useFixedPathfinding) { - desiredCell->releaseInfo(); - } -#endif - goalCell->releaseInfo(); - return FALSE; - } - } - - PathfindCell *closestCell = nullptr; - Real closestDistanceSqr = FLT_MAX; - Coord3D closestPos; - - if (validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), parentCell ) == false) { - parentCell->releaseInfo(); - goalCell->releaseInfo(); - return FALSE; - } - - parentCell->startPathfind(goalCell); - - // initialize "open" list to contain start cell - m_openList = parentCell; - - // "closed" list is initially empty - m_closedList = nullptr; - - // - // Continue search until "open" list is empty, or - // until goal is found. - // - while( m_openList != nullptr ) - { - // take head cell off of open list - it has lowest estimated total path cost - parentCell = m_openList; - m_openList = parentCell->removeFromOpenList(m_openList); - - Coord3D pos; - // put parent cell onto closed list - its evaluation is finished - m_closedList = parentCell->putOnClosedList( m_closedList ); - if (checkForAdjust(obj, locomotorSet, isHuman, parentCell->getXIndex(), parentCell->getYIndex(), parentCell->getLayer(), - radius, center, &pos, groupDest)) { - Int dx = IABS(goalCell->getXIndex()-parentCell->getXIndex()); - Int dy = IABS(goalCell->getYIndex()-parentCell->getYIndex()); - Real distSqr = dx*dx+dy*dy; - - if (distSqr < closestDistanceSqr) { - closestCell = parentCell; - closestDistanceSqr = distSqr; - closestPos = pos; - } else { - continue; - } - } else { - continue; - } - - if (cellCount > MAX_CELL_COUNT) { - continue; - } - // Check to see if we can change layers in this cell. - checkChangeLayers(parentCell); - - // expand search to neighboring orthogonal cells - static ICoord2D delta[] = - { - { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }, - { 1, 1 }, { -1, 1 }, { -1, -1 }, { 1, -1 } - }; - const Int numNeighbors = 8; - const Int firstDiagonal = 4; - ICoord2D newCellCoord; - PathfindCell *newCell; - const Int adjacent[5] = {0, 1, 2, 3, 0}; - Bool neighborFlags[8] = { 0 }; - - UnsignedInt newCostSoFar = 0; - - for( int i=0; igetXIndex() + delta[i].x; - newCellCoord.y = parentCell->getYIndex() + delta[i].y; - - // get the neighboring cell - newCell = getCell(parentCell->getLayer(), newCellCoord.x, newCellCoord.y ); - - // check if cell is on the map - if (newCell == nullptr) - continue; - - // check if this neighbor cell is already on the open (waiting to be tried) - // or closed (already tried) lists - Bool onList = false; - if (newCell->hasInfo()) { - if (newCell->getOpen() || newCell->getClosed()) - { - // already on one of the lists - onList = true; - } - } - if (i>=firstDiagonal) { - // make sure one of the adjacent sides is open. - if (!neighborFlags[adjacent[i-4]] && !neighborFlags[adjacent[i-3]]) { - continue; - } - } - - if (!validMovementPosition( isCrusher, locomotorSet.getValidSurfaces(), newCell, parentCell )) { - continue; - } - - neighborFlags[i] = true; - - if (!newCell->allocateInfo(newCellCoord)) { - // Out of cells for pathing... -#if RETAIL_COMPATIBLE_PATHFINDING - if (s_useFixedPathfinding) -#endif - { - cleanOpenAndClosedLists(); - goalCell->releaseInfo(); - } - return cellCount; - } - cellCount++; - - newCostSoFar = newCell->costSoFar( parentCell ); - newCell->setBlockedByAlly(false); - - // check if this neighbor cell is already on the open (waiting to be tried) - // or closed (already tried) lists - if (onList) - { - // already on one of the lists - if existing costSoFar is less, - // the new cell is on a longer path, so skip it - if (newCell->getCostSoFar() <= newCostSoFar) - continue; - } - - // keep track of path we're building - point back to cell we moved here from - newCell->setParentCell(parentCell) ; - - // store cost of this path - newCell->setCostSoFar(newCostSoFar); - - Int costRemaining = 0; - if (goalCell) { - costRemaining = newCell->costToGoal( goalCell ); - } - - newCell->setTotalCost(newCell->getCostSoFar() + costRemaining) ; - - // if newCell was on closed list, remove it from the list - if (newCell->getClosed()) - m_closedList = newCell->removeFromClosedList( m_closedList ); - - // if the newCell was already on the open list, remove it so it can be re-inserted in order - if (newCell->getOpen()) - m_openList = newCell->removeFromOpenList( m_openList ); - - // insert newCell in open list such that open list is sorted, smallest total path cost first - m_openList = newCell->putOnSortedOpenList( m_openList ); - } - } - -#if defined(RTS_DEBUG) - if (closestCell) { - debugShowSearch(true); - *dest = closestPos; - } else { - debugShowSearch(true); - } -#endif - m_isTunneling = false; -#if RETAIL_COMPATIBLE_PATHFINDING - if (!s_useFixedPathfinding) { - cleanOpenAndClosedLists(); - goalCell->releaseInfo(); - } - else -#endif - { - cleanOpenAndClosedLists(); - parentCell->releaseInfo(); - goalCell->releaseInfo(); - } - - return false; -} - struct TightenPathStruct { Object *obj;