§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 themselves, 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.pngStart of Chapter 6: Descriptions
arrow-left.pngBack to §6.13. To be able to see and touch
arrow-right.pngOnward 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.

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

Suppose a game in which the player is wandering an open landscape with long vistas, allowing him to LOOK in some direction, or even look at an adjacent location.

paste.png "A View of Green Hills"

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Understand "look [direction]" as facing.

Facing is an action applying to one visible thing.

Carry out facing:
    let the viewed item be the room noun from the location;
    if the viewed item is not a room, say "You can't see anything promising that way." instead;
    try looking toward the viewed item.

In rules about action handling, "noun" refers to the first object that the player has mentioned in his command, so if the player typed >LOOK WEST, "let the viewed item be the room noun from the location" would be processed as "let the viewed item be the room west from the location", and so on.

We can at need override the default behavior, if it is not going to be appropriate for the player to see the next room over. There is only sky above at any time, so...

Instead of facing up:
    say "Above you is bright sky."

Understand "look toward [any adjacent room]" as looking toward. Understand "examine [any adjacent room]" as looking toward.

Looking toward is an action applying to one visible thing.

Carry out looking toward:
    say "You make out [the noun] that way."

This design allows us to create descriptions for rooms (as seen from the outside) which will work regardless of where we're looking from. For instance:

Instead of looking toward Athens:
    say "Even from here you can make out the silhouette of the Acropolis."

Test me with "look north / look south / look up / look east / east / look west".

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

Suppose a game in which the player is wandering an open landscape with long vistas, allowing him to LOOK in some direction, or even look at an adjacent location.

paste.png "A View of Green Hills"

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Understand "look [direction]" as facing.

Facing is an action applying to one visible thing.

Carry out facing:
    let the viewed item be the room noun from the location;
    if the viewed item is not a room, say "You can't see anything promising that way." instead;
    try looking toward the viewed item.

In rules about action handling, "noun" refers to the first object that the player has mentioned in his command, so if the player typed >LOOK WEST, "let the viewed item be the room noun from the location" would be processed as "let the viewed item be the room west from the location", and so on.

We can at need override the default behavior, if it is not going to be appropriate for the player to see the next room over. There is only sky above at any time, so...

Instead of facing up:
    say "Above you is bright sky."

Understand "look toward [any adjacent room]" as looking toward. Understand "examine [any adjacent room]" as looking toward.

Looking toward is an action applying to one visible thing.

Carry out looking toward:
    say "You make out [the noun] that way."

This design allows us to create descriptions for rooms (as seen from the outside) which will work regardless of where we're looking from. For instance:

Instead of looking toward Athens:
    say "Even from here you can make out the silhouette of the Acropolis."

Test me with "look north / look south / look up / look east / east / look west".

Suppose a game in which the player is wandering an open landscape with long vistas, allowing him to LOOK in some direction, or even look at an adjacent location.

paste.png "A View of Green Hills"

Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes.

Understand "look [direction]" as facing.

Facing is an action applying to one visible thing.

Carry out facing:
    let the viewed item be the room noun from the location;
    if the viewed item is not a room, say "You can't see anything promising that way." instead;
    try looking toward the viewed item.

In rules about action handling, "noun" refers to the first object that the player has mentioned in his command, so if the player typed >LOOK WEST, "let the viewed item be the room noun from the location" would be processed as "let the viewed item be the room west from the location", and so on.

We can at need override the default behavior, if it is not going to be appropriate for the player to see the next room over. There is only sky above at any time, so...

Instead of facing up:
    say "Above you is bright sky."

Understand "look toward [any adjacent room]" as looking toward. Understand "examine [any adjacent room]" as looking toward.

Looking toward is an action applying to one visible thing.

Carry out looking toward:
    say "You make out [the noun] that way."

This design allows us to create descriptions for rooms (as seen from the outside) which will work regardless of where we're looking from. For instance:

Instead of looking toward Athens:
    say "Even from here you can make out the silhouette of the Acropolis."

Test me with "look north / look south / look up / look east / east / look west".