Re: [Newbie] How do I add races and hometowns?

From: Juliano Ravasi Ferraz (jferraz@linkway.com.br)
Date: 06/15/01


> void do_auto_exits(struct char_data * ch)
> {
>  int door, slen = 0;
>
>  *buf = '\0';
>
>  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))
>     slen += sprintf(buf + slen, "%c ", LOWER(*dirs[door]));
>   else if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE &&
>       EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED))
>     slen += sprintf(buf + slen, "!%c ", LOWER(*dirs[door]));
>
>   sprintf(buf2, "%s[ Exits: %s]%s\r\n", CCYN(ch, C_NRM),
>           *buf ? buf: None ", CCNRM(ch, C_NRM));
>
>   send_to_char(buf2, ch);
> }

Weak and dumb implementation. The same checks are made twice. I should
suggest changing the for loop to something like this:

  for (door = 0; door < NUM_OF_DIRS; door++)
    if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE) {
      if (EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED))
        slen += sprintf(buf + slen, "!%c ", LOWER(*dirs[door]));
      else
        slen += sprintf(buf + slen, "%c ", LOWER(*dirs[door]));
    }

It is simple, clean and easy to read. Or you could try something even
more clean:

  for (door = 0; door < NUM_OF_DIRS; door++)
    if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE)
      slen += sprintf(buf + slen, "%s%c ", LOWER(*dirs[door]),
                      EXIT_FLAGGED(EXIT(ch, door), EX_CLOSED) ? "!" :
"");

--
Just don't tell the asylum you saw me here

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST