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
Suppose we want a restless sort of character always pacing from room to room. It is quite easy to use adjacency to achieve this effect:
"Mistress of Animals"
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.
Artemis is a woman in Thebes.
Every turn:
if Artemis is in a room (called the current space):
let next space be a random room which is adjacent to the current space;
if Artemis is visible, say "Artemis heads to [the next space].";
move Artemis to next space;
if Artemis is visible, say "Artemis arrives from [the current space]."
Test me with "z / z / z / z / z / z".
Of course, it helps that Artemis is the sort to like open spaces. The implementation would become more complicated if there were doors which might block transit between these locations.
|
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.
|
|
Suppose we want to allow the player to wander freely in any direction, but ourselves maintain control over the order in which he encounters the rooms. This sort of effect emphasizes the order of the story-telling over any kind of rigorous simulation of space; on multiple play-throughs, the player might not find all the same rooms in the same locations.
"All Roads Lead to Mars"
Before going a direction (called way) when a room (called next location) is not visited:
let further place be the room the way from the location;
if further place is a room, continue the action;
change the way exit of the location to the next location;
let reverse be the opposite of the way;
change the reverse exit of the next location to the location.
The Open Plain is a room. "A wide-open grassy expanse, from which you could really go any way at all."
The Hilly Place is a room. "The grassland gives way to a somewhat more hilly area, though there is still very little to guide you any particular way."
The Stream is a room. "This is the third place you've been today, and so the stream is welcome. How refreshing!"
Test me with "n / s / e / e".
If we wanted still to be able to find routes between places, we could define a relationship of connection between rooms, which we would add to as we went along.
|
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.
|
|
The following rule appends a paragraph to every room description. We need not worry about doors (despite the pass in the Bernese Oberland known figuratively as the "Little Door").
"Hotel Stechelberg"
After looking:
say "Yellow arms on the signpost point:-[line break]";
repeat with destination running through interesting rooms:
let the way be the best route from the location to the destination;
if the way is a direction, say " [way] for [the destination]: [number of moves from the location to the destination] Std."
Hotel Stechelberg is a room. "The wooden hiking inn at the end of the road, with flowerboxes, canton flags, outdoor tables and a triangular paddock for the cows contesting the annual Miss Stechelberg competition. Otto and Marianne do cheerful innkeeper things, while the sun blazes from a gentian-blue sky."
A room can be dull or interesting. A room is usually dull.
North of Hotel Stechelberg is Trummelbachfalle. North of Trummelbachfalle is Lauterbrunnen. Lauterbrunnen is interesting.
Southeast of Hotel Stechelberg is Trachsellauenen. Trachsellauenen is interesting.
Test me with "look".
With a bit more work, the result might be:
Hotel Stechelberg
The wooden hiking inn at the end of the road, with flowerboxes, canton flags, outdoor tables and a triangular paddock for the cows contesting the annual Miss Stechelberg competition. Otto and Marianne do cheerful innkeeper things, while the sun blazes from a gentian-blue sky.
Yellow arms on the signpost point:-
north for Lauterbrunnen: 2 Std.
west for Sefinental: 2 Std.
west for Schilthorn: 6 Std.
southeast for Trachsellauenen: 1 Std.
southeast for Oberhornsee: 3 Std.
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.
"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 we're simulating a situation where the player needs to travel through lit areas only, but we want to give him some hints about which way might be safe. Here we'll find our best route through light-filled rooms.
The slightly tricky part is that it's not necessarily easy to tell whether a room has a lamp in it. We may say "if the Crypt is lighted", but that only tells us whether it has been declared to be inherently lighted or dark, not whether it happens to contain a light source that the player would be able to see if he went in.
The easiest way to get around this is to create an object -- the light-meter; place it in the target location; and check whether it "can see" a lit object. This preserves all the usual rules about open and closed containers, transparency, etc.
"Unblinking"
Section 1 - Procedure
The light-meter is a privately-named scenery thing.
Definition: a room (called the target room) is light-filled:
if the target room is lighted:
yes;
move the light-meter to the target room;
let the answer be false;
if the light-meter can see a lit thing:
now the answer is true;
now the light-meter is nowhere;
decide on the answer.
That done, we're free to use our best-route phrases to choose a particular route.
Section 2 - Scenario
The Tomb of Angels is a room. "This ancient underground tomb is lightless but for a few shafts from the surface. Everywhere in the shadows are carved angels, their faces worn away by water and pollution, their wings little more than nubs."
The Upward Path is above the Tomb of Angels. It is dark. "The staircase switches back on itself many times as it ascends towards the Crash Site."
A container called the sarcophagus is in the Upward Path. It is closed and openable. "A sarcophagus rests in the niche here, [if open]the lid pushed aside[otherwise]the lid firmly in place[end if]."
The Crash Site is above the Upward Path. "The ceiling has wholly caved in here, and the belly of the spaceship above you is visible -- including the escape hatch."
A candle is a kind of thing. A candle is usually lit. The player carries four candles.
After looking when the location is not the Crash Site:
if the best route from the location to the Crash Site through light-filled rooms is a direction (called next way):
say "It looks like there's a safe, lit path [if the number of moves from the location to the Crash Site through light-filled rooms is 1]straight[otherwise]if you go[end if] [next way].";
otherwise:
say "It looks like there is no fully lit path from here to the Crash Site."
Test me with "up / drop candle / down / up / take the candle / open sarcophagus / put candle in sarcophagus / down / up / close sarcophagus / d".
An important word of caution: this method would give false negatives if there were a backdrop lightsource, such as the moon, providing light to the Upward Path. This is because backdrops are actually moved around the map by Inform during play, following the player around. So if the moon backdrop is in the Crash Site with the player, it will not be in the Upward Path as well -- even if it's scheduled to move there as soon as the player does.