Skip to content
Open
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
58 changes: 25 additions & 33 deletions Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5543,48 +5543,40 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
layer = TheTerrainLogic->getLayerForDestination(groupDest);
}

Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Int i = cell.x;
Int j = cell.y;
// Check the center cell
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
return true;
}

Int delta=1;
Int count;
// TheSuperHackers @info Expanding counter-clockwise spiral search around center cell C. Each full lap walks right->up->left->down.
// After every pair of directions (right+up, then left+down) length of the segment grows by 1.
//
// <------ 12
// 4 3 2 11
// 5 C 1 10
// 6 7 8 9
//
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int segmentLength = 1;
const ICoord2D directions[4] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };
while (limit>0) {
for (count = delta; count>0; count--) {
i++;
limit--;
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
return true;
}
}
for (count = delta; count>0; count--) {
j++;
limit--;
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
return true;
}
}
delta++;
for (count = delta; count>0; count--) {
i--;
limit--;
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
return true;
for (Int dir = 0; dir < 4; dir++) {
for (Int count = segmentLength; count>0; count--) {
i+=directions[dir].x;
j+=directions[dir].y;
limit--;
if (checkForAdjust(obj, locomotorSet, isHuman, i, j, layer, iRadius, center, dest, groupDest)) {
return true;
}
}
}
for (count = delta; count>0; count--) {
j--;
limit--;
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
return true;
if (dir & 1) {
segmentLength++;
}
}
delta++;
}

if (groupDest) {
// Didn't work, so just do simple adjust.
return(adjustDestination(obj, locomotorSet, dest, nullptr));
Expand Down
Loading