version 2/101030 by Erik Temple
Example: *** Automap with Localized Compass Rose - This example shows how we can add new graphlinking functionality to the map. We may want to take advantage of the fact that the map indicates exits from the player's location to use them as a kind of compass rose, allowing us to click on the paths out of the room to go in the indicated direction (thanks to Jon Ingold for suggesting this idea.)
We do this by setting a special graphic hyperlink over the tiles that depict exits from the room occupied by the player. We use a table (the Table of Directional Correspondences) to match the appropriate direction to the tile number. We will set a graphic hyperlink using the name of the direction itself as the link identifier, and then convert this direction into a replacement command after the link has been clicked.
We begin by altering the map-renderer element itself, substituting a new rule for the extension's map-renderer display rule. This rule is essentially a copy of the map-renderer display rule. We change only the last few lines, where the graphlink is set. If the current tile number is found in the Table of Directional Correspondences, we set a directional hyperlink. If the current tile number is not in the table, then we either set no link or, if the tile number corresponds to part of a room, we set a hyperlink to the room.
The Table of Directional Correspondences includes only the tile numbers of directional connectors surrounding the player's current location; in other words, those referred to be the Automap extension as "full". It would probably be best to alter the image files for these tile numbers with arrows or some other graphic indication that clicking on the connector will move the player. I haven't bothered to do that here, but it would be simple enough to add using programs such as Photoshop, Illustrator, Inkscape, or GIMP.
"Automap with Localized Compass Rose"
Include Glimmr Automap by Erik Temple.
Include Glimmr Automap Tileset by Erik Temple.
Include Glimmr Bitmap Font by Erik Temple.
[Before looking for the first time:
say "This is a small example for Glimmr Automap, a graphical front-end to Mark Tilford's Automap extension. It generates a map as the player explores the world of the game, with very little effort needed on the part of the author.[paragraph break]This example is the same as the Automapping the Manse example, but it adds the ability to click on the connectors leading out from the PC's location (the blue highlighted room) to go in that direction. This allows the player to navigate the map purely by clicking: Clicking on the exit of the location can take the player to an unvisited room, while clicking on an already visited room on the map issues the command GO TO <ROOM>.[paragraph break]Probably the best thing would be to modify the images for the exit tiles to add arrows that would make for a partial compass rose surrounding the current location, but I haven't bothered...[paragraph break][italic type]Instructions[roman type]:[line break] Zoom the map by using the + and - buttons.[line break] Click on the query button, then click on a room to identify it by name."]
The map-renderer plus internal compass rule is listed instead of the map-renderer display rule in the element display rules.
An element display rule for the map-renderer (this is the map-renderer plus internal compass rule):
let tilesetting be the associated tileset of map-renderer;
let scan be 0;
let row be the win-y of the map-renderer;
let column be the win-x of the map-renderer;
let xx be the tile-width of the tilesetting * scaling factor of the current window as an integer;
let yy be the tile-height of the tilesetting * scaling factor of the current window as an integer;
unless the background tint of the map-renderer is g-placenullcol:
draw a rectangle (color background tint of the map-renderer) in (the current window) at (column) by (row) with dimensions (map-width of map-renderer * scaling factor of the current window as an integer) by (map-height of map-renderer * scaling factor of the current window as an integer);
#if utilizing Glimmr debugging;
say "[>console][GLAM]Drawing background rectangle (glulx color-value [background tint of map-renderer]) from ([win-x], [win-y]) to ([win-x + (map-width of map-renderer * scaling factor of the current window as an integer)], [win-y + (map-height of map-renderer * scaling factor of the current window as an integer)]) for element [i][map-renderer][/i] in [i][current window][/i].[<]";
unless using the no post-processing option:
follow the automap post-processing rules;
repeat with count running from 1 to (map height * map width):
increase scan by 1;
if scan > map width:
increase row by yy;
change column to the win-x of the map-renderer;
let scan be 1;
let V be the map glyph of count;
if there is a char of V in the translation-table of the tilesetting:
choose row with a char of V in the translation-table of the tilesetting;
let the current tile be tile entry;
drscimage (current tile) in (current window) at (column) by (row) with dimensions (xx) by (yy);
if using the automap hyperlinks option:
if there is a char of V in the Table of Directional Correspondences:
choose row with a char of V in the Table of Directional Correspondences;
set a graphlink in the current window identified as dir entry from column by row to (column + xx) by (row + yy) as "", ignoring redundant links;
otherwise if linked room-ID of count > 0:
set a graphlink in the current window identified as map-renderer from column by row to (column + xx) by (row + yy) as linked room-ID of count, ignoring redundant links;
increase column by xx;
#if utilizing Glimmr debugging;
say "[>console][GLAM]Drawing element [i]map-renderer[/i] in [i][current window][/i] at origin ([win-x of map-renderer], [win-y of map-renderer]), dimensions [map width * xx] x [map height * yy] pixels ([map width] x [map height] tiles).[line break][if the automap hyperlinks option is active][GLAM]Hyperlinks set for linked room-ID and directional movement, as provided.[end if][<]";
An automap graphlink rule for a direction (called the way) (this is the direction-selecting graphlink rule):
let current-direction be indexed text;
let current-direction be "[way]";
let current-direction be "[current-direction in upper case]";
now glulx replacement command is "[current-direction]";
Table of Directional Correspondences
That's all that's required to add the compass rose functionality. The rest of the example is identical to the "Automapping the Manse" example above.
Use automap hide paths through closed doors.
The display status of UI-query is g-active.
The map-window is a map-display window spawned by the main-window. The position is g-placeabove. The measurement of the map-window is 50. The associated canvas of the map-window is the map-canvas.
The map-canvas is a g-canvas. The associated canvas of a g-element is the map-canvas.
When play begins:
follow the opening up the map window rules.
Understand "[any room]" as going by name. Understand "go to [any room]" as going by name.
Going by name is an action applying to one thing.
Check going by name:
if the noun is the location, say "You're already in [the location]." instead;
if the noun is not adjacent and the noun is unvisited, say "That noun did not make sense in this context." instead.
Carry out going by name:
let aim be the best route from the location to the noun, using doors;
if aim is not a direction, say "You can't think how to get there from here." instead;
say "(heading [aim])[command clarification break]";
try going aim;
if the location is not the noun, say "You'll have to stop here."
Automap graphlink rule for a room (called the target):
let target-text be the printed name of the target in upper case;
change glulx replacement command to "GO TO [target-text]";
The Front Lawn is south of the Porch.
The East Lawn is northeast of the Front Lawn. The West Lawn is northwest of the Front Lawn.
The Rear Lawn is northwest of the East Lawn. Southwest of the Rear Lawn is the West Lawn.
The front door is a closed door. It is inside from the porch and outside from the Foyer. "The front door is [if the front door is open]open[otherwise]closed[end if]."
The Dining Room is east of the Foyer. The Living Room is west of the Foyer. The Kitchen is north of the Dining Room. Bottom of the Stairs is north of the Living Room.
The Hallway is east of Bottom of the Stairs, north of the Foyer, and west of the Kitchen.
Top of the Stairs is up from Bottom of the Stairs. Master Bedroom is east of Top of the Stairs. Master Bath is east of the Master Bedroom. West Hall is south of Top of the Stairs. East Hall is east of West Hall and south of the Master Bedroom. East of East Hall is Front Bedroom.
A tree is scenery in Rear Lawn. "Looks climbable." Instead of climbing the tree: try going up.
Up from the Rear Lawn is Treetop. "A tall tree grows here. Large branches scrape against the house." The description of Treetop is "You could climb into the house through the window. Type IN."
A window is an open door. It is not openable. "The window is open." The window is inside from the Treetop and outside from the Master Bedroom.
Before constructing the status line:
unless Master Bedroom is placed 0 and 1 from Treetop, say "*** Error placing Treetop ***".