Re: [CODE] Virtual Map

From: Sammy (samedi@DHC.NET)
Date: 05/21/98


On Thu, 21 May 1998, Christoffer Lundberg wrote:

I don't normally answer these, since it's one of the first things you'd
learn if you took a C class or spent a couple bucks for a used C book, but
in the interest of preventing more reposts...

> act.informative.c: In function `look_at_vmap_room':
> act.informative.c:920: warning: int format, pointer arg (arg 4)

This means a printf, sprintf, fprintf (etc) funciton is being told to look
for an integer, and you're passing it a pointer.

>   const char *symbol[] = {
>     "&Gf&n",
>     "&gF&n",
>     "&ym&n",
>     "&KM&n",
>     "&B~&n",
>     "&k#&n",
>     "&YD&n",
>     "&r#&n",
>     "&WC&n",
>     "&WV&n",
>     "\n"
>   };

These are pointers (aka strings, aka char arrays).

>   sprintf(buf, "%s%c%c%c%c%c\r\n", buf, symbol[vmap1[y+2][x-2]],
>                                         symbol[vmap1[y+2][x-1]],
>                                         symbol[vmap1[y+2][x]],
>                                         symbol[vmap1[y+2][x+1]],
>                                         symbol[vmap1[y+2][x+2]]);

%c is the format code for a char variable (not int, and definitely not
char *).  Change the %c's to %s's.

Here's my version of the same function.  This was written for a mud that
didn't have any form of inline color at the time, so I didn't use a symbol
array.  If that were added (with a second dimension for night symbols)
this would probably be a drop-in replacement that would be easier to work
with.  You can easily adjust the amount of viewable terrain for different
weather effects, or give imms more visibility, etc.

void show_map(struct char_data * ch)
{
  int x, y;
  char map[2048];
  int range, lit = FALSE;

  if(weather_info.sunlight == SUN_DARK)
    range = 1;
  else {
    range = 3;
    lit = TRUE;
  }

  *map = '\0';

  for(y = ch->worldy - range; y <= ch->worldy + range; y++) {
    sprintf(map, "%s%s", map, lit ? "   " : "     ");
    for(x = ch->worldx - range; x <= ch->worldx + range; x++) {
      if(x < 0 || y < 0 || x > 199 || y > 199)
        sprintf(map, "%s ", map);
      else if(x == ch->worldx && y == ch->worldy)
        sprintf(map, "%s%s%s*", map, lit ? CCBOLD(ch, C_NRM) :
          CCNRM(ch, C_NRM), CCWHT(ch, C_NRM));
      else {
      switch (world_map[x][y]) {
        case VNUM_PLAINS:
          sprintf(map, "%s%s%s,", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCGRN(ch, C_NRM));
          break;
        case VNUM_DESERT:
          sprintf(map, "%s%s%s.", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCYEL(ch, C_NRM));
          break;
        case VNUM_MOUNTAIN:
          sprintf(map, "%s%s%s^", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCMAG(ch, C_NRM));
          break;
        case VNUM_FOREST:
          sprintf(map, "%s%s%sT", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCGRN(ch, C_NRM));
          break;
        case VNUM_ROAD:
          sprintf(map, "%s%s%s+", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCCYN(ch, C_NRM));
          break;
        case VNUM_WATER:
          sprintf(map, "%s%s%s~", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCBLU(ch, C_NRM));
          break;
        default:
          sprintf(map, "%s%s%s#", map, lit ? CCBOLD(ch, C_NRM) :
            CCNRM(ch, C_NRM), CCRED(ch, C_NRM));
      }
      }
    }
    sprintf(map, "%s%s\r\n", map, CCNRM(ch, C_NRM));
  }
  send_to_char(map, ch);
}

Sam


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



This archive was generated by hypermail 2b30 : 12/15/00 PST