[BUG] moveTo() with swapmy rooms



  • I think I saw it mentioned here before, but when I try to move to a position in the room that's really spawmy, my creep will avoid the swamp area by going along the edge of the room where there is no swamp but this makes it change rooms to whatever room it borders. Has there been any news on if this issue will be fixed or if this is a programming issue we need to solve ourselves? Why not just make the edge positions have a calculated fatigue value higher than swamp, but not actually fatigue the creep when it moves there. 



  • As far as I know, this isn't a bug. If the target you are trying to move to using Creep.prototype.moveTo (which uses RoomPosition.prototype.findPathTo) is in a different room, it will just path to the nearest exit that goes to the room you need to enter. In this case it does not take into account the terrain in the other room. Then when you enter the new room you are in the same room as the target so it calculates the optimal path, even if that path has to leave the room to avoid some swamps, and in the case that you do leave the room, moveTo goes back to pathing to the nearest exit since you arent in the same room as the target anymore.

    1. You tell your creep to move from room A to a position in room B.
    2. The moveTo function says "Hey, you're trying to leave the room, so lets just go to the nearest exit, regardless of what is in the next room."
    3. Your creep reaches the nearest exit, and transitions from room A to room B.
    4. Now that your creep is in the same room as the target, moveTo says "Nice! We are in the same room as the target now, so i'll calculate the optimal path to get to it! Hmm there are a lot of swamps near me, it would be optimal to go back through room A, and go around these swamps, and then come back to room B."
    5. Your creep goes back to room A.
    6. moveTo now says "We're not in the same room as the target anymore, lets go to the nearest exit!"
    7. move to step 3 and repeat.

    This often results in frustration for new players (I know it drove me nuts when i started), but it does make some sense. I'm sure there are a dozen different ways of solving it. One of the easiest ways in some cases is to check if the creep is in the same room as the target, and if so, set the maxRooms option to 1 so that it wont search outside of the room for the optimal path. Other options involve using Pathfinder yourself or using your own movement function to keep using the path even when you go back to the previous room, etc. Others could probably give you better ideas on other solutions.


  • Culture

    >  if this is a programming issue we need to solve ourselves?

    Yes, it is.

    > Why not just make the edge positions have a calculated fatigue value higher than swamp, but not actually fatigue the creep when it moves there. 

    You can do this yourself - check out `PathFinder` and its related `CostMatrix`es.