[CODE] map snippet

From: Peter Howkins (marutan@x-stream.co.uk)
Date: 04/28/00


I get lost on muds. So I wrote a short snippet for printing out an
ascii graphical map of the surrounding rooms. Indicating what exits
are available in rooms, n, s, e and w.

Example map of 'The Temple of Midgaard' (will look odd in
proportianally spaced font)
<pre>
    |
    O
    |
    |
 O--#--O
   /|
    |
   -O-
    |
</pre>

Hope it may be useful for someone and that OE hasn't messed up the
formating of the code :).

Peter

-------------------------
-- In act.informative.c, near top, prototype func
ACMD(do_map);

-- act.informative.c, wherever, actually funcs
void map_draw_room(char map[9][10], int x, int y, room_rnum rnum,
struct char_data *ch)
{
  int door;

  map[y][x] = 'O';

  for (door = 0; door < NUM_OF_DIRS; door++) {
    if (world[rnum].dir_option[door] &&
world[rnum].dir_option[door]->to_room
        != NOWHERE && !EXIT_FLAGGED(world[rnum].dir_option[door],
EX_CLOSED)) {
      switch (door) {
        case NORTH: map[y-1][x]   = '|'; break;
        case EAST:  map[y][x+1]   = '-'; break;
        case SOUTH: map[y+1][x]   = '|'; break;
        case WEST:  map[y][x-1]   = '-'; break;
        case UP:    map[y-1][x+1] = '/'; break;
        case DOWN:  map[y+1][x-1] = '/'; break;
      }
    }
  }
}

ACMD(do_map)
{
  int door, i;
  char map[9][10];

  /* blank the map */
  for(i=0;i<9;i++) {
    strcpy(map[i], "         ");
  }

  /* print out exits */
  map_draw_room(map, 4, 4, ch->in_room, ch);
  for (door = 0; door < NUM_OF_DIRS; door++) {
    if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE &&
 !EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED)) {
      switch (door) {
        case NORTH: map_draw_room(map, 4, 1,EXIT(ch,door)->to_room,
ch); break;
        case EAST:  map_draw_room(map, 7, 4,EXIT(ch,door)->to_room,
ch); break;
        case SOUTH: map_draw_room(map, 4, 7,EXIT(ch,door)->to_room,
ch); break;
        case WEST:  map_draw_room(map, 1, 4,EXIT(ch,door)->to_room,
ch); break;
      }
    }
  }

  /* make it obvious what room they are in */
  map[4][4] = '#';

  /* print out the map */
  for(i=0;i<9;i++) {
    sprintf(buf2, "%s\r\n", map[i]);
    send_to_char(buf2, ch);
  }
}

-- In interpreter.c
  { "map"      , POS_RESTING , do_map      , 0, 0 },
---------------------------

---
Peter Howkins
marutan@marutan.net
http://www.marutan.net
http://www.arcsite.de/hp/flibble/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT