Can I restrict character pathfinding?

Say I’ve got a map, and a character will be plodding towards random destinations all over it, one after the other, for eternity.

Now there are some rooms I don’t want them to enter. The map is such that no matter where A and B are, there’s always physically a way for the person to get to B from A while avoiding the no-no rooms, but such paths will require the character to take not-the-most-direct-route.

I couldn’t work out a way for the pathfinding routine to take this kind of thing into account. I could trick it if I could physically deactivate the routes into the no-no rooms temporarily (whenever paths were decided) and restore them immediately after, but I don’t think you can do this. I don’t think doors can act in such a manner, either?

Is there a way to do what I’m thinking about here? I wondered if it might be relations, though I imagined that would take a lot of setting up.

You need to define an adjective that defines whether a room is usable for a path or not, for example passable or impassable, then you can give the impassable property for rooms you don’t want included in the path, and instruct the pathfinding code to use only passable rooms:

A room can be passable or impassable. A room is usually passable.

To take the next step to (destination - a room):
   let way be the best route from the location to destination through passable rooms;
   try going way.

– Eric

Thanks Eric. That makes it really easy.

  • Wade