The Reliques of Tolti-Aph

An interactive fiction by Graham Nelson (2005) - the Inform 7 source text

Home page

Contents
Previous
Next

Complete text
Section E(c) - Spatial coordinates

A spatial coordinate is a kind of value. <9,24,24> specifies a spatial coordinate with parts maze level, easting (without leading zeros), northing (without leading zeros). A room has a spatial coordinate called grid position. Definition: A room is unlocated if its grid position is <0,0,0>. Definition: A room is located if it is not unlocated.[1]

To decide which number is the current maze level:
    let L be the maze level part of the grid position of the location;
    decide on L.

The previous maze level is a number that varies.

Every turn:
    if the location is a labyrinth room and the location is not the Hedge Archway
    begin;
        if the current maze level is not the previous maze level
        begin;
            if the current maze level is 1, say "You blink in the shadowy, but natural twilight, feeling a faint breeze on your face once again. You are back in the familiar hedge-maze at the surface.";
            if the previous maze level is 1, say "Underground, the labyrinth continues with clean-cut, magically lit passages.";
        end if;
    end if;
    change the previous maze level to the current maze level.

A direction has a spatial coordinate called vector. North has vector <0,0,1>. South has vector <0,0,24>. East has vector <0,1,0>. West has vector <0,24,0>. Down has vector <1,0,0>. Up has vector <9,0,0>.[2] Definition: A direction is vectorial if its vector is not <0,0,0>.[3] Definition: A direction is vertical if it is up or it is down.

To decide which spatial coordinate is the vector sum of (V1 - a spatial coordinate) and (V2 - a spatial coordinate):
    let L be the maze level part of V1 plus the maze level part of V2;
    let L be the remainder after dividing L by 10;
    let E be the easting part of V1 plus the easting part of V2;
    let E be the remainder after dividing E by 25;
    let N be the northing part of V1 plus the northing part of V2;
    let N be the remainder after dividing N by 25;
    if L is 0 or L is 9, decide on <0,0,0>;
    if E is 0 or E is 24, decide on <0,0,0>;
    if N is 0 or N is 24, decide on <0,0,0>;
    let the sum be the spatial coordinate with maze level part L easting part E northing part N;
    decide on the sum.[4]

To decide which spatial coordinate is the vector difference of (V1 - a spatial coordinate) and (V2 - a spatial coordinate):
    let L be the maze level part of V1 minus the maze level part of V2;
    let L be the remainder after dividing L by 10;
    let E be the easting part of V1 minus the easting part of V2;
    let E be the remainder after dividing E by 25;
    let N be the northing part of V1 minus the northing part of V2;
    let N be the remainder after dividing N by 25;
    let the sum be the spatial coordinate with maze level part L easting part E northing part N;
    decide on the sum.

Notes

[1]. Inform does not automatically construct un- prefixes: they're too unpredictable in English. For instance, in ROTA "undead" has a definition which is by no means equivalent to "not dead".

[2]. As this demonstrates, Inform allows us to add to or modify even the most fundamental built-in concepts.

[3]. For instance, "northeast" and "outside" are non-vectorial directions in this sense. The Maze occupies a cubical lattice and never has connections in those directions.

[4]. All of that remainder-after-dividing stuff is to enable us to have relative vectors with negative entries, in effect. Thus a single move west is achieved by adding <0,24,0> to the position, because 24 is the same as -1 when we are dealing only with numbers in the range 0 to 24. However, the maze does not "wrap around": the legal grid positions are where L must be 1 to 8, and E and N must be 1 to 23, with the special value <0,0,0> being reserved as a "no position at all" value.