[Circle] [CODE] Help with get_char_scan_vis()

From: Sean P. Mountcastle (mountcas@pluto.ee.cua.edu)
Date: 08/23/96


Hey folks I need help with this function, it finds people in the room 
fine,  but it won't find people correctly within scanning  distance. It's 
for my missile weapons code.....anyway here's the function:


struct char_data *get_char_scan_vis(struct char_data * ch, char *name)
{
  struct char_data *i;
  int j = 0, number = 0, door;
  char tmpname[MAX_INPUT_LENGTH];
  char *tmp = tmpname;

  /* JE 7/18/94 :-) :-) */
  if (!str_cmp(name, "self") || !str_cmp(name, "me"))
    return ch;

  /* 0.<name> means PC with name */
  strcpy(tmp, name);
  if (!(number = get_number(&tmp)))
    return get_player_vis(ch, tmp, 1);

  /* First see if the person is in the same room */
  for (i = world[ch->in_room].people; i && j <= number; i = i->next_in_room)
     if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
      if (CAN_SEE(ch, i))
	if (++j == number)
	  return i;
  /* Now check the surrounding rooms */
  for (door = 0; door < NUM_OF_DIRS; door++) { 
    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) {
	for (i = world[ch->in_room].people; i && j <= number; i = i->next_in_room)
	  if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
	    if (CAN_SEE(ch, i))
	      if (++j == number)
		return i;
      } 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) {
	  for (i = world[_2ND_EXIT(ch, door)->to_room].people; i && j <= number; i = i->next_in_room)
	    if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
	      if (CAN_SEE(ch, i))
		if (++j == number)
		  return i;
	} 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) {
	    for (i = world[_3RD_EXIT(ch, door)->to_room].people; i && j <= number; i = i->next_in_room)
	      if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
		if (CAN_SEE(ch, i))
		  if (++j == number)
		    return i;
	  } else if (_4TH_EXIT(ch, door) && _4TH_EXIT(ch, door)->to_room !=
		   NOWHERE && !IS_SET(_4TH_EXIT(ch, door)->exit_info, EX_CLOSED)) {
	    /* check the third room */
	    if (world[_4TH_EXIT(ch, door)->to_room].people) {
	      for (i = world[_4TH_EXIT(ch, door)->to_room].people; i && j <= number; i = i->next_in_room)
		if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
		  if (CAN_SEE(ch, i))
		    if (++j == number)
		      return i;
	    } else if (_5TH_EXIT(ch, door) && _5TH_EXIT(ch, door)->to_room !=
		   NOWHERE && !IS_SET(_5TH_EXIT(ch, door)->exit_info, EX_CLOSED)) {
	      /* check the third room */
	      if (world[_5TH_EXIT(ch, door)->to_room].people) {
		for (i = world[_5TH_EXIT(ch, door)->to_room].people; i && j <= number; i = i->next_in_room)
		  if (isname(tmp, i->player.name) || is_abbrev(tmp, i->player.name))
		    if (CAN_SEE(ch, i))
		      if (++j == number)
			return i;
	      }
	    }
	  }
	}
      }
    }
  }
  return NULL;
}

	Thanks in advance for any help you could offer,
	
	-  Sean

Sean Mountcastle
----------------
Go climb a gravity well.
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



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