Inform 7 Home Page / Documentation


§6.14. Adjacent rooms and routes through the map

Another useful adjective built into Inform is "adjacent". Two rooms are said to be adjacent if there is a map connection between them which does not pass through some barrier such as a door. This is easily tested:

if the Hallway is adjacent to the Study ...

We usually want to know about the places adjacent to the current scene of the action, so that is what the adjective "adjacent" means when applied to rooms. For instance:

if somebody is in an adjacent room, ...

As with the case of "visible", the adjective is a cut-down version of the more general relationship. This often happens: "worn" and "carried", for instance, imply "by the player" unless something else is specified.

If we want to ask a more direct question, we can obtain specific map connections as follows. (Recall that every map connection leads either to a door, to a room, or to nothing.) If we know which direction we want to look in, then the easiest thing is to use its relation - every direction in the map, say "north", has its own relation, say "mapped north of". So:

if the Ballroom is mapped north of the Hallway, ...

Alternatively, and particularly if the direction is not a constant,

room (direction) from/of (room) ... room

This phrase produces the room which the given map direction leads to, or the special value "nothing" if it leads nowhere. If it leads to a door, the result is the room through that door. Examples:

say "You look north into [the room north from the Garden]."
if the room north from the Garden is nothing, say "The grass leads nowhere."

door (direction) from/of (room) ... door

This phrase produces the door which the given map direction leads to, or the special value "nothing" if it leads nowhere or to a room. Examples:

let the barrier be the door north from the Garden;
if the barrier is a door, say "Well, [the barrier] is in the way.";

room-or-door (direction) from/of (room) ... object

This phrase produces the object which the given map direction leads to, which will always be either a room, a door or the special value "nothing". The phrase is used mainly by the Standard Rules, for technical reasons, and usually it's better to use "room ... from .. " or "door ... from ..." instead.

The map can be a great sprawling mass of rooms and doors connected together, and it can be quite hard to find a way through it one step at a time.

best route from (object) to (object) ... object

This phrase produces a direction to take in order to get from A to B by the shortest number of movements between rooms, or produces "nothing" if there is no way through at all. Example:

The description of the brass compass is "The dial points quiveringly to [best route from the location to the Lodestone Room]."

Best routes are ordinarily forbidden to go through doors, but if the suffix "using doors" is added as an option then any open or openable and unlocked door may be used on the way; and if "using even locked doors" is given, then any door at all will do. Since magnetism is no respecter of property, that seems right here:

The description of the brass compass is "The dial points quiveringly to [best route from the location to the Lodestone Room, using even locked doors]."

In practice this simple approach sometimes produces impossible journeys, rather the way Google Maps directions from New York to London would recommend driving down to the docks and then swimming. A more careful approach is to use:

best route from (object) to (object) through (description of objects) ... object

This phrase produces a direction to take in order to get from A to B by the shortest number of movements between rooms which match the given description, or produces "nothing" if there is no way through at all. Example:

best route from the Drawbridge to the Keep through visited rooms

The condition - in this case, that "visited rooms" must be used - also applies to both ends of the journey, so if either Drawbridge or Keep are unvisited then this is "nothing". (Similarly, saying something like "...through containers" would mean there is never a route.)

Lastly, the following phrases can find out how long the journey would be. (They are quite a bit faster than using the "best route..." phrases repeatedly and counting.)

number of moves from (object) to (object) ... number

This phrase produces the number of map connections which must be followed in order to get from A to B by the shortest number of movements between rooms. If A and B are the same, the answer is 0; if there is no route at all, the answer is -1. Example:

The description of the proximity gadget is "You are now [number of moves from the location to the Sundial] moves from the Sundial.";

number of moves from (object) to (object) through (description of objects) ... number

This phrase produces the number of map connections which must be followed in order to get from A to B by the shortest number of movements between rooms matching the given description. If A and B are the same, the answer is 0; if there is no route at all, or if either A or B fail to match the description themselve , the answer is -1.

Route-finding makes it possible to write quite sophisticated conditions concisely. But these sometimes run slowly, because they call for large amounts of computation. How rapidly Inform can find routes depends on which of two methods it uses. Both have advantages - one is fast but needs large amounts of memory, the other is slow but economical. We can choose between them with one of these two use options:

Use fast route-finding.
Use slow route-finding.

If neither is specified, "fast" is used where the project uses the Glulx virtual machine (see the Settings panel), and "slow" on the Z-machine, where memory is tighter. Fast route-finding is ideally suited to situations where dozens of characters are constantly route-finding through the map as they meander around in a landscape.

* See Indirect relations for route-finding through a relation rather than the map


arrow-up.png Start of Chapter 6: Descriptions
arrow-left.png Back to §6.13. To be able to see and touch
arrow-right.png Onward to §6.15. All, each and every

*ExampleMistress of Animals
A person who moves randomly between rooms of the map.

*ExampleAll Roads Lead to Mars
Layout where the player is allowed to wander any direction he likes, and the map will arrange itself in order so that he finds the correct "next" location.

**ExampleHotel Stechelberg
Signposts such as those provided on hiking paths in the Swiss Alps, which show the correct direction and hiking time to all other locations.

***ExampleA View of Green Hills
A LOOK [direction] command which allows the player to see descriptions of the nearby landscape.

***ExampleUnblinking
Finding a best route through light-filled rooms only, leaving aside any that might be dark.