Search code examples
screeps

Is it possible to have creeps swap positions moving simultaneously?


Using the moveTo() function, creeps will try to path around other creeps and this can make things inefficient when trying to minimize the amount of roads needed for creeps to get across each other. Is it possible to either have 2 creeps move simultaneously so that they could swap spaces if they are trying to get through each other or to have them swap spaces as an action?


Solution

  • Yes, that is possible. The moveTo() method has multiple different options that you can provide as input. You should look at the API documentation, but one of the options is ignoreCreeps. The default value for this is false. This means other creeps are counted as obstructions.

    Changing this to true requires a little bit of preperation. At a minimum I recommend to have some kind of stuck detection. If a creep tries to move, but are standing still for multiple ticks, it should trigger an alternative approach.

    One such approach could be to investigate what it is that is standing in the way. If the obstruction is another creep, the creep could attempt to call the moveTo() operation of the obstructing creep.