Change to do_scan

Login to reply  Page: « < 1 of 1 > »
04 Mar 2010 - 19:252407
Change to do_scan
Going through the 3.61 changelog, I noticed that the "scan" command had been implemented in act.informative.c.

But I think it's pretty poorly written, it's difficult to figure out and it wouldn't be easy to add more than 3 rooms scanned.

Here's a proposed revision:


ACMD(do_scan)
{
  int door;
  char buf[MAX_STRING_LENGTH];

  int range;
  int maxrange = 3;

  room_rnum scanned_room = IN_ROOM(ch);

  if (IS_AFFECTED(ch, AFF_BLIND)) {
    send_to_char(ch, "You can't see a damned thing, you're blind!\r\n");
    return;
  }

  for (door = 0; door < NUM_OF_DIRS; door++) {
    for (range = 1; range<= maxrange; range++) {
      if (world[scanned_room].dir_option[door] &&
       !IS_SET(world[scanned_room].dir_option[door]->exit_info, EX_CLOSED)) {
        scanned_room = world[scanned_room].dir_option[door]->to_room;
        if (world[scanned_room].people)
          list_scanned_chars(world[scanned_room].people, ch, range - 1, door);
      }                  // end of if
      else
        break;
    }                    // end of range
    scanned_room = IN_ROOM(ch);
  }                      // end of directions
} // end of do_scan

Note that, unlike the present version of scan, the code doesn't stop when it sees someone. Also, it would be easy to change maxrange, either through skills or set to a constant elsewhere (in cedit maybe?).

I also removed the check for darkness, which can be added before the list_scanned_chars call.

I also made some aesthetic changes to list_scanned_chars, showing them in a table rather than the "x, y, and z" format.



Last edited by zman (04 Mar 2010 - 19:29)
07 Mar 2010 - 01:122412
Thanks, that does make it more readable, you can get rid of 'buf' too. It will go into the next release.


__________________
Rumble
The Builder Academy
tbamud.com 9091
Login to reply  Page: « < 1 of 1 > »