Automap

version 4 by Mark Tilford

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 1 - Global constants, Memory management, Kinds, and verbs

    Use automap manual exploration translates as (- Constant AUTOMAP_MANUAL_EXPLORATION 1; -).
    Use automap manual display translates as (- Constant AUTOMAP_MANUAL_DISPLAY 1; -).
    Use automap visible background translates as (- Constant AUTOMAP_VISIBLE_BACKGROUND 1; -).
    Use automap hide paths through closed doors translates as (- Constant AUTOMAP_HIDE_CLOSED_DOORS 1; -).

    Use automap reserved area of at least 400 translates as (- Constant USEOP_MAP_ALLOC_AREA {N}; -).
    Use automap static allocation translates as (- Constant AUTOMAP_ALLOCATE_STATIC 1; -).
    Use automap hyperlinks translates as (- Constant AUTOMAP_HYPERLINKS 1; -).

    [Use automap draw debug variables translates as (- Constant AUTOMAP_DRAW_DEBUG_VARIABLES 1; -).]

    [Include Text Capture by Eric Eve.
    Use maximum capture buffer length of at least 512.]

    Include (-

    Constant AUTOMAP_CHAR_IN 3;
    Constant AUTOMAP_CHAR_OUT 4;
    Constant AUTOMAP_CHAR_INOUT 5;

    Constant AUTOMAP_CHAR_PRESENT_IN 6;
    Constant AUTOMAP_CHAR_PRESENT_OUT 7;
    Constant AUTOMAP_CHAR_PRESENT_INOUT 8;

    Constant AUTOMAP_CHAR_DARK 9;
    Constant AUTOMAP_CHAR_PRESENT_DARK 10;

    #ifdef TARGET_ZCODE;
        #ifndef AUTOMAP_ALLOCATE_STATIC;
            Constant AUTOMAP_ALLOCATE_STATIC 1;
        #endif;
    #endif;

    #ifdef AUTOMAP_ALLOCATE_STATIC;
        Constant MAP_ALLOC_AREA USEOP_MAP_ALLOC_AREA;
        Array Automap_Chars -> MAP_ALLOC_AREA;
        #ifdef AUTOMAP_HYPERLINKS;
            Global Automap_links --> MAP_ALLOC_AREA;
        #endif;
    #ifnot;
        Global MAP_ALLOC_AREA = 0;
        Global Automap_Chars = 0;
        Global printed_nomalloc_message = 0;
        #ifdef AUTOMAP_HYPERLINKS;
            Global Automap_links = 0;
        #endif;
    #endif;


    Global MAP_WIDTH = 0;
    Global MAP_HEIGHT = 0;

    [ Reserve_Map_Memory rows cols link_memory;
        if (rows == 0) {
            rows = 0;
            cols = 0;
            return;
        }
        if (rows * cols > MAP_ALLOC_AREA) {
            !#ifdef TARGET_ZCODE;
            #ifdef AUTOMAP_ALLOCATE_STATIC;
                if (rows > MAP_ALLOC_AREA) {
                    MAP_WIDTH = 0;
                    MAP_HEIGHT = 0;
                    return;
                }
                MAP_HEIGHT = rows;
                MAP_WIDTH = MAP_ALLOC_AREA / rows;
                return;
            #ifnot;
                if (~~check_for_malloc()) {
                    if ( (+ current zoom +) == (+ map absent +) )
                        return;
                    if (~~Printed_nomalloc_message) {
                        print "[Your interpreter does not support dynamic memory allocation. Automap features will not function.]^";
                        Printed_nomalloc_message = true;
                    }
                    (+ current zoom +) = (+ map absent +);
                    return;
                }
                printed_nomalloc_message = false;
                if (Automap_Chars ~= 0) {
                    @mfree Automap_Chars;
                    Automap_Chars = 0;
                }
                MAP_ALLOC_AREA = rows * cols;
                @malloc MAP_ALLOC_AREA Automap_Chars;
                if (Automap_Chars == 0) {
                    MAP_ALLOC_AREA = 0;
                    MAP_WIDTH = 0;
                    MAP_HEIGHT = 0;
                    rfalse;
                }
                #ifdef AUTOMAP_HYPERLINKS;
                    if (Automap_Links ~= 0) {
                        @mfree Automap_links;
                        Automap_Links = 0;
                    }
                    link_memory = MAP_ALLOC_AREA * WORDSIZE;
                    @malloc link_memory Automap_links;
                #endif;
            #endif;
        }
        MAP_WIDTH = cols;
        MAP_HEIGHT = rows;
    ];
        
    [ Check_for_malloc rv;
        #ifndef AUTOMAP_ALLOCATE_STATIC;
        @gestalt 7 0 rv;
        return rv;
        #ifnot;
        return 1;
        #endif;
    ];
    !#Endif;
    -) after "Definitions.i6t".

    To decide whether there is no dynamic allocation conflict:
        (- Check_for_malloc() -).

    To reserve automap memory of (rows - a number) rows by (cols - a number) cols/columns : (- Reserve_Map_Memory ({rows}, {cols}) ;-).
    To reserve automap memory of (cols - a number) cols/columns by (rows - a number) rows: (- Reserve_Map_Memory ({rows}, {cols}) ;-).
    To reserve automap memory of (rows - a number) by (cols - a number): (- Reserve_Map_Memory ({rows}, {cols}) ;-).
    To reserve automap memory of (rows - a number) rows: (- Reserve_Map_Memory ({rows}, VM_ScreenWidth()-2); -).

    Include Basic Screen Effects by Emily Short.

    [A Mappable Room is a kind of room.
    A mappable room has a number called map_x.
    A mappable room has a number called map_y.

    A mappable room can be currently_mapped. A mappable room is usually not currently_mapped.]

    A room can be mappable or unmappable. A room is usually mappable.
    A room has a number called map_x. A room has a number called map_y.
    A room can be currently_mapped. A room is usually not currently_mapped.

    To decide what number is the distance (d - a direction) from (r - a room): decide on 1.

    [Coregionality relates mappable rooms to each other in groups. The verb to be coregional with implies the coregionality relation.]
    Coregionality relates rooms to each other in groups. The verb to be coregional with implies the coregionality relation.

    Map zoomedness is a kind of value. The Map zoomednesses are map zoomed out, map zoomed in, and map absent.

    Current zoom is a map zoomedness that varies. [The current zoom is map zoomed in.] [The current zoom is map absent.]

    To report dynamic allocation conflict:
        say "[bracket]Your interpreter does not support dynamic allocation, so the automap will not function.[close bracket][line break]";
        now current zoom is map absent;
            
    Zooming in is an action out of world applying to nothing. Understand "zoom in" as zooming in.
    Carry out zooming in: if there is no dynamic allocation conflict begin; say "Zooming in!"; now current zoom is map zoomed in; otherwise; report dynamic allocation conflict; end if.

    Zooming out is an action out of world applying to nothing. Understand "zoom out" as zooming out.
    Carry out zooming out:
        if there is no dynamic allocation conflict begin; say "Zooming out!"; now current zoom is map zoomed out; otherwise; report dynamic allocation conflict; end if.

    Zooming away is an action out of world applying to nothing. Understand "zoom away" as zooming away. Carry out zooming away: say "Removing map."; now current zoom is map absent.

    ZoomingMisc is an action out of world applying to nothing. Understand "zoom" as zoomingmisc.
    Carry out zoomingmisc:
        if there is no dynamic allocation conflict begin;
            if current zoom is map zoomed in begin;
                try zooming out;
            otherwise if current zoom is map zoomed out;
                try zooming away;
            otherwise;
                try zooming in;
            end if;
        otherwise;
            report dynamic allocation conflict;
        end if.


    Map displayness is a kind of value. The map displaynesses are map display ascii, map display automatic, map display fancy, map display unicode. Current displayness is a map displayness that varies.

    Map displaying unicode is an action out of world applying to nothing. Understand "map unicode" as map displaying unicode. Carry out map displaying unicode: now current displayness is map display unicode; say "Displaying map with unicode character set.".

    Map displaying fancy is an action out of world applying to nothing. Understand "map fancy" as map displaying fancy. Understand "map font 3" as map displaying fancy. Understand "map beyond zork" as map displaying fancy. Carry out map displaying fancy: now current displayness is map display fancy; say "Displaying map with fancy character set.".

    Map displaying ascii is an action out of world applying to nothing. Understand "map simple/ascii/plain" as map displaying ascii. Carry out map displaying ascii: now current displayness is map display ascii; say "Displaying map with simple character set.".
    Gargoyle workaround is an action out of world applying to nothing. Understand "gargoyle bug workaround" as gargoyle workaround. Carry out gargoyle workaround: now current displayness is map display ascii; say "Activating workaround for buggy interpreter.".

    Map displaying automatic is an action out of world applying to nothing. Understand "map auto" as map displaying automatic. Carry out map displaying automatic: now current displayness is map display automatic; say "Displaying map with automatic character set."

    Automap work is an activity. ["Catchall activity in case the author wants to do something different while doing automap related activity."]

    Automap exploring is an activity. ["Check a room, and join all adjacent rooms which are currently_mapped to its automap region."]

    Automap drawing is an activity. ["writing the array that shows the automap."]

    To decide whether (dir - a direction) is region preserving:
    if dir is north or dir is east or dir is west or dir is south or dir is northeast or dir is southeast or dir is northwest or dir is southwest, decide yes;
    if dir is up or dir is down or dir is inside or dir is outside, decide no;
    say "Error: Bad direction [dir]!"; decide no.

    To decide what number is the delta x of (dir - a direction):
    if dir is west or dir is northwest or dir is southwest, decide on -1;
    if dir is east or dir is northeast or dir is southeast, decide on 1;
    decide on 0.

    To decide what number is the delta y of (dir - a direction):
    if dir is north or dir is northwest or dir is northeast, decide on -1;
    if dir is south or dir is southwest or dir is southeast, decide on 1;
    decide on 0.


    [Understand north south path as 40.]
    To decide what number is automap in: decide on 3.
    To decide what number is automap out: decide on 4.
    To decide what number is automap inout: decide on 5.
    To decide what number is automap present in: decide on 6.
    To decide what number is automap present out: decide on 7.
    To decide what number is automap present inout: decide on 8.
    To decide what number is automap dark: decide on 9.
    To decide what number is automap present dark: decide on 10.

    To decide what number is north south path: decide on 2.
    To decide what number is east west path: decide on 1.
    To decide what number is ne sw path: decide on 35.
    To decide what number is nw se path: decide on 36.
    To decide what number is diagonal cross: decide on 90.
    To decide what number is orthogonal cross: decide on 91.
    To decide what number is south wall: decide on 38.
    To decide what number is north wall: decide on 39.
    To decide what number is east wall: decide on 40.
    To decide what number is west wall: decide on 41.
    To decide what number is north exit: decide on 42.
    To decide what number is south exit: decide on 43.
    To decide what number is east exit: decide on 44.
    To decide what number is west exit: decide on 45.
    To decide what number is sw corner: decide on 46.
    To decide what number is nw corner: decide on 47.
    To decide what number is ne corner: decide on 48.
    To decide what number is se corner: decide on 49.
    To decide what number is sw exit: decide on 50.
    To decide what number is nw exit: decide on 51.
    To decide what number is ne exit: decide on 52.
    To decide what number is se exit: decide on 53.
    To decide what number is up arrow: decide on 92.
    To decide what number is down arrow: decide on 93.
    To decide what number is up down arrow: decide on 94.
    To decide what number is question arrow: decide on 96.

    To decide what number is empty cell: decide on 32.
    To decide what number is full room: decide on 54.
    To decide what number is empty room: decide on 95.

    To decide what number is full south wall: decide on 55.
    To decide what number is full north wall: decide on 56.
    To decide what number is full east wall: decide on 57.
    To decide what number is full west wall: decide on 58.
    To decide what number is full north exit: decide on 59.
    To decide what number is full south exit: decide on 60.
    To decide what number is full east exit: decide on 61.
    To decide what number is full west exit: decide on 62.
    To decide what number is full sw corner: decide on 63.
    To decide what number is full nw corner: decide on 64.
    To decide what number is full ne corner: decide on 65.
    To decide what number is full se corner: decide on 66.
    To decide what number is full sw exit: decide on 67.
    To decide what number is full nw exit: decide on 68.
    To decide what number is full ne exit: decide on 69.
    To decide what number is full se exit: decide on 70.
    To decide what number is full up arrow: decide on 123.
    To decide what number is full down arrow: decide on 124.
    To decide what number is full up down arrow: decide on 125.
    To decide what number is full question arrow: decide on 126.



    To decide what number is map width:
        (- MAP_WIDTH -);
    To decide what number is map height:
        (- MAP_HEIGHT -);