findPathTo happily paths into obstacles



  •  Just noticed this as moveTo returns OK even though the target position is an obstacle: 

    suppose you have a single wall at 10,10 surrounded by walkable terrain, then 

    new RoomPosition(9,10,'sim').findPathTo(10,10)

    will return

    [{"x":10,"y":10,"dx":1,"dy":0,"direction":3}]

    instead of an empty path as i would expect. 


  • YP

    This is what I expect. 

    You can moveTo a source for example .. so it needs to find a path even if you can't step on the destination pos. Otherwise you would have to select a walkable pos next to the source first to walk there.



  • Hmmm sources, i guess it could just calculate a path without the source position as the last step. So if your creep is right next to the source you get an empty path, if it is 2 fields away it gets a path with one step.. and so on.. 

    The main problem i have right now is that when i try to move a creep to an adjacent field with an obstacle on it, moveTo() returns OK but the creep doesn't actually move. So i'm having a hard time finding out if a creeps path is blocked by another (idle) creep. And that is happening because moveTo just checks if the path is not empty. 


  • YP

    changing any behavior of moveTo would brake code of many players, so it probably won't happen.

    moveTo can't know if a move will succeed.. the OK will only tell you that you successfully registered the intend to move to that spot. a second creep might move to the same location in the same tick .. then only one will succeed but this is not solved before the tick is over. 

    Also by default moveTo caches the path for 5 ticks .. so it won't even check if a creep is in the way in most cases... or it doges from the street but the creep is long gone.

    moveTo is fine for basic movement.. if you want to do advanced stuff you better write your own moving function.

    you can find the code of moveTo at https://github.com/screeps/engine/blob/0f27eb41e2aaa97cae792133fc2b67fd5fa5b741/src/game/creeps.js#L130



  • MoveTo does not actually move the creep, it schedules a move attempt and returns OK if that attempt was successfully scheduled.

    However I agree that the current situation is very annoying for scripting as you essentially need to track whether or not your creep has actually moved, and if not figure out why.



  • FindPath defaults to range 1. If you want to move directly into a spot you need to specify range 0.