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
4 changes: 0 additions & 4 deletions Core/GameEngine/Include/GameLogic/AIPathfind.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ class PathNode : public MemoryPoolObject
/// given a list, prepend this node, return new list
PathNode *prependToList( PathNode *list );

/// given a list, append this node, return new list. slow implementation.
/// @todo optimize this
PathNode *appendToList( PathNode *list );

/// given a node, append to this node
void append( PathNode *list );

Expand Down
51 changes: 16 additions & 35 deletions Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,6 @@ PathNode *PathNode::prependToList( PathNode *list )
return this;
}

//-----------------------------------------------------------------------------------
/// given a list, append this node, return new list. slow implementation.
/// @todo optimize this
PathNode *PathNode::appendToList( PathNode *list )
{
if (list == nullptr)
{
m_next = nullptr;
m_prev = nullptr;
return this;
}

PathNode *tail;
for( tail = list; tail->m_next; tail = tail->m_next )
;

tail->m_next = this;
m_prev = tail;
m_next = nullptr;

return list;
}

//-----------------------------------------------------------------------------------
/// given a node, append new node to this.
Expand Down Expand Up @@ -437,7 +415,14 @@ void Path::appendNode( const Coord3D *pos, PathfindLayerEnum layer )
node->setPosition( pos );
node->setLayer(layer);

m_path = node->appendToList( m_path );
if (m_pathTail)
{
m_pathTail->append(node);
}
else
{
m_path = node->prependToList(nullptr);
}

if (m_isOptimized && m_pathTail)
{
Expand Down Expand Up @@ -6184,6 +6169,7 @@ struct ExamineCellsStruct
const LocomotorSet *theLoco;
Bool centerInCell;
Bool isHuman;
Bool isCrusher;
Int radius;
const Object *obj;
PathfindCell *goalCell;
Expand All @@ -6192,10 +6178,9 @@ struct ExamineCellsStruct
/*static*/ Int Pathfinder::examineCellsCallback(Pathfinder* pathfinder, PathfindCell* from, PathfindCell* to, Int to_x, Int to_y, void* userData)
{
ExamineCellsStruct* d = (ExamineCellsStruct*)userData;
Bool isCrusher = d->obj ? d->obj->getCrusherLevel() > 0 : false;
if (d->thePathfinder->m_isTunneling) return 1; // abort.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary? Could maybe be changed to an assertion given that it's already checked at the call site.

if (from && to) {
if (!d->thePathfinder->validMovementPosition( isCrusher, d->theLoco->getValidSurfaces(), to, from )) {
if (!d->thePathfinder->validMovementPosition( d->isCrusher, d->theLoco->getValidSurfaces(), to, from )) {
return 1;
}
if ( (to->getLayer() == LAYER_GROUND) && !d->thePathfinder->m_zoneManager.isPassable(to_x, to_y) ) {
Expand Down Expand Up @@ -6297,6 +6282,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
info.radius = radius;
info.obj = obj;
info.isHuman = isHuman;
info.isCrusher = isCrusher;
info.goalCell = goalCell;
ICoord2D start, end;
start.x = parentCell->getXIndex();
Expand All @@ -6322,6 +6308,11 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *

UnsignedInt newCostSoFar = 0;

Coord3D fromPos;
fromPos.x = parentCell->getXIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.y = parentCell->getYIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.z = TheTerrainLogic->getGroundHeight(fromPos.x , fromPos.y);
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.

for( int i=0; i<numNeighbors; i++ )
{
neighborFlags[i] = false;
Expand Down Expand Up @@ -6360,11 +6351,6 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
// do the gravity check here
if ( locomotorSet.isDownhillOnly() )
{
Coord3D fromPos;
fromPos.x = parentCell->getXIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.y = parentCell->getYIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.z = TheTerrainLogic->getGroundHeight(fromPos.x , fromPos.y);

Coord3D toPos;
toPos.x = newCellCoord.x * PATHFIND_CELL_SIZE_F ;
toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ;
Expand Down Expand Up @@ -6430,11 +6416,6 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
}

if (newCell->getType() == PathfindCell::CELL_CLIFF && !newCell->getPinched() ) {
Coord3D fromPos;
fromPos.x = parentCell->getXIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.y = parentCell->getYIndex() * PATHFIND_CELL_SIZE_F ;
fromPos.z = TheTerrainLogic->getGroundHeight(fromPos.x , fromPos.y);

Coord3D toPos;
toPos.x = newCellCoord.x * PATHFIND_CELL_SIZE_F ;
toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ;
Expand Down
Loading