Find closest across rooms
-
Hi,
I'm trying to find the closest objects from an array of objects that could be across differents room.
I tried pos.findClosestByRange but it only work if it's in the same room (The documentation doesn't say it by the way).
Also I tried wit pos.GetRangeTo but it return infinity.
So do we have to process RoomName and calculate by ourself the distance ?
Thanks,
Shadow_Bird
-
Hi,
no that's not directly possible.
A simple way may be to count rooms between two locations and use amount * 50 as distance for comparison. Or something like that. Room name processing may be an option as well (which is actually happening in getRoomLinearDistance).
Or maybe have a look here...
Regards
-
It would theoretically be costly if you already have a list of all the objects you are interested in. But it will be CPU-costly.
You can use http://support.screeps.com/hc/en-us/articles/207023879-PathFinder#search and pass it an array of targets even across multiple rooms. It will then give you the path to the closest target.
-
Yes, thats closestByPath, surely quite costly.
But he seems to be interested in closestByRange. Thats calculatable using coordinates only - at a medium cost.
-
Indeed I'm more interested with distance rather than path because it's only to choose the closest spawn from a flag.. And the pathfinder is very costly.
@cyberblast I didn't have time to check the pathfinder docs and getRoomLinearDistance, yet
-
I also posted a custom implementation to calulate room distance here:
But this will only calculate how far away the rooms are to each other (in rooms), not exact pos distance from within two different rooms.