Distance

I’m considering the amount of time it takes to go from one location to another in-game. One of the mechanics I’m considering is distance. I’m not sure about implementation, though. I can’t quite wrap my head around how it would work. Is this even a plausible thing to implement in I7? It seems like a three-part relation - Room A is related via Number B to Room C.

I think I should be able to handle it similarly to how directions work:

The West End is west of the East Bay. The West End is 2 miles from the East Bay.

But looking through the standard rules, I cannot for the life of me figure out how this was done. Is it all in I6? Hard-coded? I’m not entirely sure I even want to implement this, given the potential issues that could arise. I could make all rooms equidistant, or fake it with regions or something, but before I look at workarounds, I’d be interested to know what the deal is.

There might be a way to piggyback on the existing adjacency relation somehow, though it wouldn’t be straightforward (relations can’t take properties).

On the other hand, it seems to me that when it actually comes time to fill in this information for all of your locations, you won’t want to have to type a sentence-length declaration for each distance. A table would be more succinct, and combined with a phrase, you could use it to find the distance whenever you needed it (whether that’s to set the travel time during the going action, or to describe the distance when an NPC is giving directions).

Of course, creating such a table and keeping it up to date is a nuisance. Here is a way to autogenerate the table with a default value for distance. The table is output to a separate file so that it can use tabs appropriately. You would then cut and paste the table into your story file and customize it with values that differ from the default.

[code]Owl Hill is a room. The Gully is east of Owl Hill. The Town is south of the Gully. The Foothills are west of Owl Hill. The Cliff is west of the Foothills.

Section - Distance Table (not for release)
The file of Distance Table is called “DistTable”.

To say tab:
(- glk_put_char_uni(9); -)

When play begins:
write “Table of Distances[line break]a-terminus[tab]b-terminus[tab]distance[line break]” to the file of distance table;
repeat with a-terminus running through rooms:
repeat with b-terminus running through rooms:
if a-terminus is adjacent to b-terminus:
append “[a-terminus][tab][b-terminus][tab]1[line break]” to the file of distance table.[/code]

In the generated table there are two entries for each map connection, one entry for each direction. With a little more work, you could make the table more compact (one entry per connection), which would be a better choice as long as you don’t need the distances between rooms to be nonreciprocal. This is the resulting table, copied direct from the file:

Table of Distances a-terminus b-terminus distance Owl Hill Gully 1 Owl Hill Foothills 1 Gully Owl Hill 1 Gully Town 1 Town Gully 1 Foothills Owl Hill 1 Foothills Cliff 1 Cliff Foothills 1

(Note that you could also have the game build the table in the same way, supplying your exceptions through a custom phrase, but that would take up valuable start-up time.)

Anyway, even if you don’t use a table to solve this problem, hopefully you’ll find the autogenerate-code-to-a-file technique useful…

–Erik

Inform doesn’t support three-way relations.

Map connections aren’t defined as a relation. Yeah, they’re all defined in I6. (Adjacency is a relation, but it’s two-way – it ignores direction.)

Erik posted everything else I was going to say. :slight_smile:

No doubt. There’s some excellent potential there on all kinds of fronts. It’s totally going into my scrapbook of useful code.

Thanks for the clarification on directions. I keep thinking there’s things I don’t need to know, and then situations come up and it’s really helpful to know them. Some kind of important life lesson in there, no doubt.