Skip to content

Commit 8207c68

Browse files
bugfix(pathfinder): Fix inaccurate single unit movement destinations when unobstructed (#2296)
1 parent ac11215 commit 8207c68

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5529,12 +5529,12 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
55295529
Bool center;
55305530
getRadiusAndCenter(obj, iRadius, center);
55315531
ICoord2D cell;
5532-
Coord3D adjustDest = *dest;
5532+
Coord3D cellDest = *dest;
55335533
if (!center) {
5534-
adjustDest.x += PATHFIND_CELL_SIZE_F/2;
5535-
adjustDest.y += PATHFIND_CELL_SIZE_F/2;
5534+
cellDest.x += PATHFIND_CELL_SIZE_F/2;
5535+
cellDest.y += PATHFIND_CELL_SIZE_F/2;
55365536
}
5537-
worldToCell( &adjustDest, &cell );
5537+
worldToCell( &cellDest, &cell );
55385538
PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination(dest);
55395539
if (groupDest) {
55405540
layer = TheTerrainLogic->getLayerForDestination(groupDest);
@@ -5543,9 +5543,24 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
55435543
Int i = cell.x;
55445544
Int j = cell.y;
55455545
// Check the center cell
5546-
if (checkForAdjust(obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
5546+
#if RETAIL_COMPATIBLE_PATHFINDING
5547+
if (checkForAdjust(obj, locomotorSet, isHuman, i, j, layer, iRadius, center, dest, groupDest)) {
5548+
return true;
5549+
}
5550+
#else
5551+
Coord3D adjustDest = *dest;
5552+
if (checkForAdjust(obj, locomotorSet, isHuman, i, j, layer, iRadius, center, &adjustDest, groupDest)) {
5553+
// TheSuperHackers @bugfix stephanmeesters 15/06/2026 Destination adjustment always snaps to the nearest grid cell
5554+
// even when no adjustment is necessary because there are no obstructions. For single units this adjustment
5555+
// can be skipped in order to provide more accurate movement, which is especially noticeable for chinooks.
5556+
const Bool singleUnit = obj && obj->getGroup() && obj->getGroup()->getCount() == 1;
5557+
const Bool useExactDestination = isHuman && singleUnit;
5558+
if (!useExactDestination) {
5559+
*dest = adjustDest;
5560+
}
55475561
return true;
55485562
}
5563+
#endif
55495564

55505565
// TheSuperHackers @info Expanding counter-clockwise spiral search around center cell C. Each full lap walks right->up->left->down.
55515566
// After every pair of directions (right+up, then left+down) length of the segment grows by 1.

0 commit comments

Comments
 (0)