@@ -5543,48 +5543,40 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
55435543 layer = TheTerrainLogic->getLayerForDestination (groupDest);
55445544 }
55455545
5546- Int limit = MAX_ADJUSTMENT_CELL_COUNT ;
5547- Int i, j;
5548- i = cell.x ;
5549- j = cell.y ;
5546+ Int i = cell.x ;
5547+ Int j = cell.y ;
5548+ // Check the center cell
55505549 if (checkForAdjust (obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
55515550 return true ;
55525551 }
55535552
5554- Int delta=1 ;
5555- Int count;
5553+ // TheSuperHackers @info Expanding counter-clockwise spiral search around center cell C. Each full lap walks right->up->left->down.
5554+ // After every pair of directions (right+up, then left+down) length of the segment grows by 1.
5555+ //
5556+ // <------ 12
5557+ // 4 3 2 11
5558+ // 5 C 1 10
5559+ // 6 7 8 9
5560+ //
5561+ Int limit = MAX_ADJUSTMENT_CELL_COUNT ;
5562+ Int segmentLength = 1 ;
5563+ const ICoord2D directions[4 ] = { {1 , 0 }, {0 , 1 }, {-1 , 0 }, {0 , -1 } };
55565564 while (limit>0 ) {
5557- for (count = delta; count>0 ; count--) {
5558- i++;
5559- limit--;
5560- if (checkForAdjust (obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
5561- return true ;
5562- }
5563- }
5564- for (count = delta; count>0 ; count--) {
5565- j++;
5566- limit--;
5567- if (checkForAdjust (obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
5568- return true ;
5569- }
5570- }
5571- delta++;
5572- for (count = delta; count>0 ; count--) {
5573- i--;
5574- limit--;
5575- if (checkForAdjust (obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
5576- return true ;
5565+ for (Int dir = 0 ; dir < 4 ; dir++) {
5566+ for (Int count = segmentLength; count>0 ; count--) {
5567+ i+=directions[dir].x ;
5568+ j+=directions[dir].y ;
5569+ limit--;
5570+ if (checkForAdjust (obj, locomotorSet, isHuman, i, j, layer, iRadius, center, dest, groupDest)) {
5571+ return true ;
5572+ }
55775573 }
5578- }
5579- for (count = delta; count>0 ; count--) {
5580- j--;
5581- limit--;
5582- if (checkForAdjust (obj, locomotorSet, isHuman, i,j, layer, iRadius, center, dest, groupDest)) {
5583- return true ;
5574+ if (dir & 1 ) {
5575+ segmentLength++;
55845576 }
55855577 }
5586- delta++;
55875578 }
5579+
55885580 if (groupDest) {
55895581 // Didn't work, so just do simple adjust.
55905582 return (adjustDestination (obj, locomotorSet, dest, nullptr ));
0 commit comments