Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
245 changes: 0 additions & 245 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<numNeighbors; i++ )
{
neighborFlags[i] = false;
// determine neighbor cell to try
newCellCoord.x = parentCell->getXIndex() + 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;
Expand Down
3 changes: 0 additions & 3 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/AIPathfind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading
Loading