Re: [SNIPPET] [CODE] The Mapsnippet

From: Francis Hotchkiss (fhotch@buffnet.net)
Date: 12/13/98


> It was a long time since I last asked about this thing. I have managed
> to get it to work, that is why I release this little snippet for all
That's ok, I'll still help you with problems if you can be specific about
them.

> you MUD-admins who wishes to have an Automap in your MUD. Only one
> problem remains, color. I cannot seem to get color on the characters
> without getting them all scattered around, making the map unreadable.
The easiest way to add color to the map would be to first add the
Easy-Color 2 patch, and then use its color codes like this:
sprintf, buf("Hi! I'm learning to use easycolor, this is &Bbright blue&n,
this is normal, this is &cdark cyan&n.\r\n", ch);


> #define MAP_WIDTH 5
> #define MAP_HEIGHT 5
> #define MAP_ROOMS (MAP_WIDTH * MAP_HEIGHT)
The reason i told you to do it this way is so you can make a dynamically
sized map(which i'm finishing up on mine right now).
(By dynamic i mean that, mortals can only see a max 12x12, immortas 30x30,
and imp's 80x24 (assumming you don't lag out first(that's a lot of data)),
and to save time and such, the game only maps what a char can see of the
map(morts only map 144 rooms, immorts map 900 rooms, etc.... It's really
cool :) )

>   char map_chars[MAP_ROOMS][5];
the 5 yields enough space for the symbol and color ocde. Example(using
below symbols):
sprintf(map_chars[1], "&B%s", sector_symbols[0]);
This would yield a bright blue # going to the char.

>   const char *sector_symbols[] = {
>    "#",
>    ":",
>    "*",
...
>    ".",
>    "*"
>   };
I'd do these like this:
const char *sector_symbols[] = {
  "&Y#",
  "&W:",                  /* Or whatever color you want to use for each of
these */
  "&Y*",
...
  "&y.",
  "&G*"
};

>   map_rnum[17] = IN_ROOM(ch);
I made a small function that returns the value of the center of the map:
(replace the dynamic size variables with static ones if you like)
#define ROUNDL(d) ((long) ((d) + ((d) > 0 ? 0.5 : -0.5)))

int wild_cr(struct char_data *ch) {
  float center = (float) 0;

  if ((GET_MAP_HEIGHT(ch)%2) == 0) {
        center = ((float)GET_MAP_HEIGHT(ch) / (float)2);
        center *= (float)GET_MAP_WIDTH(ch);
        center -= ((float)GET_MAP_WIDTH(ch) / (float)2);
  } else if ((GET_MAP_HEIGHT(ch)%2) == 1) {
        center = ((float)GET_MAP_HEIGHT(ch) / (float)2);
        center *= (float)GET_MAP_WIDTH(ch);
        center = (float)(ROUNDL(center));
  } else
        center = (float) 0;

  return (int) center;
}

>   if (CAN_GO(ch, 0)) {
>     map_rnum[12] = EXIT(ch, 0)->to_room;
>     sprintf(map_chars[12], sector_symbols[SECT(map_rnum[12])]);
[SNIPPED LONG EXCESSIVE CODE]
why do this all the long hard way?
just pop the mapping lines in a for loop.
int order[] = {13, 8, 14, 18, 12, 9, 19, 17, 7, 3, 15, 23, 11, 4, 5, 10,
20, 25, 24, 22, 21, 16, 6, 1, 2 , -1};
int i, j;
for (i = 0; order[i] != -1, i++) {
/*  map a single room, checks it's doors for surrounding rooms and set
their rnum's in the array */ // following loop from my code, remove dynamic
variables if needed
        for (door = NORTH; door < NUM_OF_DIRS; door++) {
          if (world[j].dir_option[door] && world[j].dir_option[door]->to_room !=
NOWHERE) {
                if (!IS_SET(world[j].dir_option[door]->exit_info, EX_NOMAP)) {
                  if ((door == NORTH) && (r_n > 0)) {
                        w_map[r_n] = world[j].dir_option[door]->to_room;
                  } else if ((door == EAST) && (r_e%GET_MAP_WIDTH(ch))) {
                        w_map[r_e] = world[j].dir_option[door]->to_room;
                  } else if ((door == SOUTH) && (r_s <= wild_rms(ch))) {
                        w_map[r_s] = world[j].dir_option[door]->to_room;
                  } else if ((door == WEST) && (r_w%GET_MAP_WIDTH(ch))) {
                        w_map[r_w] = world[j].dir_option[door]->to_room;
                  }
                }
          }
        }
        sprintf(w_room[rm], sectors[world[j].sector_type]);

}

> &y===&rMAP&y===&n
>     %s
>    %s%s%s
>   %s%sC%s%s
>    %s%s%s
>     %s
> &y=========&n\r\n\r\n",
>              map_chars[11],
>              map_chars[10],
>              map_chars[12],
>              map_chars[20],
>              map_chars[15],
>              map_chars[16],
>              map_chars[18],
>              map_chars[19],
>              map_chars[24],
>              map_chars[22],
>              map_chars[21],
>              map_chars[23]);
>   send_to_char(buf, ch);
> }
i'd make this a for loop also(this is the exact code from my map.c):
  /* now the routine that actually sets up the dynamic wilderness map */
  *buf = '\0';
  for (cnt = 1; cnt <= j; cnt++) {
        sprintf(buf1,"%1s",w_room[cnt]);
        strcat(buf, buf1);
        if ((cnt%GET_MAP_WIDTH(ch))==0)
          strcat(buf, "\r\n&n");
  }
  strcat(buf, "&n");
  send_to_char(buf, ch);

I havea variable in there for dynamic size, but you can replace it(easy to
figure it out :) )

> What can be wrong? This is the only remaining thing to do to get this
> little snippet to work 100%.
Nothing is wrong, you just didn't provide enough space for a normal color
code defined in screen.h, you had enough for an easy-color code

>
> > Christoffer <

-Astaroth


     +------------------------------------------------------------+
     | 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 : 12/15/00 PST