Automap

version 4 by Mark Tilford

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2 - Exploration - determining how rooms should be placed relative to each other

    [ Unmap Room ]
    To unmap (r - a room):
        now r is not coregional with r;
        now r is not currently_mapped.

    To remap/explore (r - a room):
        unless r is explored, say "Error exploring [r] - BUG.";

    [ Explore Room ]
    To decide whether (r - a room) is explored:
        [say "Exploring [r].";]
        begin the automap work activity;
        begin the automap exploring activity;
        if r is a mappable room
        begin;
            if r is not currently_mapped begin;
                [say "Setting [r] to currently_mapped.";]
                now map_x of r is 0;
                now map_y of r is 0;
                now r is currently_mapped;
            end if;
            [say "mapped_room is [mapped_room].";]
            repeat with dir running through directions
            begin;
                if dir is region preserving and r has an exit to the dir
                begin;
                    let next_room be the room dir from the r;
                    [say "[mapped_room] : [dir] : [next_room].";]
                    if next_room is a mappable room
                    begin;
                        [if next_room is placed 1 and 1 from r, say "Huh.";]
                        let d be the distance dir from r;
                        let ddx be d times (the delta x of dir);
                        let ddy be d times (the delta y of dir);
                        unless next_room is placed ddx and ddy from r, say "Error exploring [dir] from [r].";
                    end if;
                end if;
            end repeat;
        end if;
        end the automap exploring activity;
        end the automap work activity;
        decide yes.

    [ Recenter Region : Recoordinate the rooms in a region so that the minimum x and the minimum y of the region are 0. ]
    To recenter the region of (r - a mappable room):
        let min_x be the map_x of r;
        let min_y be the map_y of r;
        repeat with loop_room running through all mappable rooms coregional with r begin;
            if the map_x of loop_room is less than min_x, now min_x is the map_x of loop_room;
            if the map_y of loop_room is less than min_y, now min_y is the map_y of loop_room;
        end repeat;
        repeat with loop_room running through all mappable rooms coregional with r begin;
            now the map_x of loop_room is the map_x of loop_room - min_x;
            now the map_y of loop_room is the map_y of loop_room - min_y;
        end repeat.
            

    [ Join Regions : decide whether (nr - mappable room) is placed (dx - a number) and (dy - a number) from (or - mappable room):]
    To decide whether (new room - mappable room) is placed (dx - a number) and (dy - a number) from (old room - mappable room):
        [ If the either room isn't currently_mapped, do nothing. ]
        if new room is not currently_mapped or old room is not currently_mapped, decide yes;
        [say "Trying to place [new room] at ([dx], [dy]) relative to [old room].";]
        [say "Normal decision.";]
        [now old room is currently_mapped;]
        [ if they're in the same region, check whether the placements are consistent. ]
        if new room is coregional with old room begin;
            [say "The coregional test.";]
            if map_x of new room is map_x of old room plus dx and map_y of new room is map_y of old room plus dy, decide yes;
            decide no;
        end if;
        [ otherwise, join the two regions ]
        let delta_x be (map_x of old room) + dx - (map_x of new room);
        let delta_y be (map_y of old room) + dy - (map_y of new room);
        repeat with loop_room running through all mappable rooms coregional with new room
        begin;
            now map_x of loop_room is (map_x of loop_room) + (delta_x);
            now map_y of loop_room is map_y of loop_room + delta_y;
        end repeat;
        now old room is coregional with new room;
        recenter the region of old room;
        decide yes.
        
    To decide whether (r - a room) is not explored:
        if r is explored, decide no; decide yes.
        
    To decide whether (r - a room) has an exit to the/-- (d - a direction):
        if the automap hide paths through closed doors option is not active and the room-or-door d from r is a closed door, decide no;
        If the room d from r is a room, decide yes; decide no.