Code Submission for 'scan' command! - Beta version?

From: Pink Floyd (floyd@south.mit.edu)
Date: 08/03/95


Well, here's my first attempt at writing a 'scan' command.  It lets players 
look in the cardinal directions and search for any players/mobs in any room
up to 3 squares away.  It seems like it works fine, I can't find any bugs.
Please reply if you find bugs/like it/have a better idea/whatever. To Jeremy
Elson, you can consider this a submission for 3.0 GAMMA ;)
You should be able to slap this right into act.informative.c, make an entry
in interpreter.c and yer golden!
Thanks for your attention...

/* functions and macros for 'scan' command */
void list_scanned_chars(struct char_data * list, struct char_data * ch, int distance, int door)
{
  const char *how_far[] = {
   "close by",
   "a ways off",
   "far off to the"
  };

  struct char_data *i;
  *buf = '\0';

  for (i = list; i; i = i->next_in_room) {
    if (!CAN_SEE(ch, i))
      continue; 
/* you may want to add other checks in here, perhaps something special
   for Rangers, maybe check terrain, whatever.. */
    if (!*buf)
      sprintf(buf, "You see %s", GET_NAME(i));
    if (i->next_in_room) {
      if (i->next_in_room->next_in_room)
        sprintf(buf2, ", %s", GET_NAME(i->next_in_room));
      else sprintf(buf2, " and %s", GET_NAME(i->next_in_room));
    } else
        sprintf(buf2, " %s %s.\r\n", how_far[distance], dirs[door]);
    strcat(buf, buf2);      


  }
  send_to_char(buf, ch);
}

/* utils.h: #define EXIT(ch, door)  (world[(ch)->in_room].dir_option[door]) */
#define _2ND_EXIT(ch, door) (world[EXIT(ch, door)->to_room].dir_option[door])
#define _3RD_EXIT(ch, door) (world[_2ND_EXIT(ch, door)->to_room].dir_option[doo\r])


ACMD(do_scan)
{
/* >scan
   You quickly scan the area.
   You see John, a large horse and Frank close by north.
   You see a small rabbit a ways off south.
   You see a huge dragon and a griffon far off to the west.

*make scan a skill (ranger?) with a prof. check in each dir. ?
*/
  int door;

  *buf = '\0';

  if (IS_AFFECTED(ch, AFF_BLIND)) {
    send_to_char("You can't see a damned thing, you're blind!\r\n", ch);
    return;
  }
  /* may want to add more restrictions here, too */
  send_to_char("You quickly scan the area.\r\n", ch);
  for (door = 0; door < NUM_OF_DIRS - 2; door++) /* don't scan up/down */
    if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE &&
        !IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED)) {
      if (world[EXIT(ch, door)->to_room].people) {
   list_scanned_chars(world[EXIT(ch, door)->to_room].people, ch, 0, door);
      } else if (_2ND_EXIT(ch, door) && _2ND_EXIT(ch, door)->to_room != 
          NOWHERE && !IS_SET(_2ND_EXIT(ch, door)->exit_info, EX_CLOSED)) {
/* check the second room away */
        if (world[_2ND_EXIT(ch, door)->to_room].people) {
   list_scanned_chars(world[_2ND_EXIT(ch, door)->to_room].people, ch, 1, door);
	} else if (_3RD_EXIT(ch, door) && _3RD_EXIT(ch, door)->to_room !=
               NOWHERE && !IS_SET(_3RD_EXIT(ch, door)->exit_info, EX_CLOSED)) {
/* check the third room */
            if (world[_3RD_EXIT(ch, door)->to_room].people) {
   list_scanned_chars(world[_3RD_EXIT(ch, door)->to_room].people, ch, 2, door);
            }

	  }
      }
    }                
}



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