[code][advanced]

From: William Long (bill@LONGBOYZ.EROLS.COM)
Date: 01/19/98


i want to implement a few changes to the zone files.  i want my builders
to be able to specify not only the maximum number
of mobs in the game, but also max number in zone and room for it to
load. i also want to be able to specify a percentage load.
i got the zone file structure and the reset command structure all set
fine and integrated with my OLC.

ran into a bit of a problem tho.  i figured i'd make a few quick
functions that would check for the number of mobs in the zone and room
and return a true or false if the mob/object was okay to load.  so i
wrote a quick one to start at the first mob in a room(didnt make it to
the zone checks before i ran into trouble) and count each mob in the
room that had the same vnum as the one i wanted to load.  if the number
of existing mobs/objects was >= the max number, return a false.  that
worked like a charm.  the only thing is, when the mud executes the first
heartbeat for mob movement the mud crashes.  i tried it several
different ways but in each case the mud crashed.   what i think is
happening is that when i traverse the list of mobs in the room i'm
missing something really dumb.

has anybody ever tried to implement something like this? if so, did you
run into any problems and if so what did you do to fix it?

i can get around it by making two linked lists which hold the mob vnum
and which room it exists in and then each time traverse the whole list
and count the times it occurs in a room but that is terribly
inefficient.

any help would be most appreciated.

thanks

bill

--
Son of Ra, Brother of Poseidon

  ps i have included a copy of the one function and where it gets called
if anybody wants to look at it.   disregard the debugging statements :)

--8<--

int mobs_lessthan_maxmobroom(mob_num mrnum, room_num rrnum, int num_max) {

  int x=0;
  struct char_data *mob;
  mob_num mvnum;

  mob=read_mobile(mrnum, REAL);
  mvnum=GET_MOB_VNUM(mob);
printf("room vnum is %ld\n\r", world[rrnum].number);
printf("max is %d  ", num_max);

  //get room its going into to check for mobs in that room
  //search all the mobs in that room, compare vnums of mobs.

  for(mob=world[rrnum].people;mob;mob = mob->next_in_room)
    if (IS_NPC(mob)) {
      printf("mvnum is %ld mob vnum=%ld\n\r", mvnum, GET_MOB_VNUM(mob));
      if (mvnum == GET_MOB_VNUM(mob))
        x++;
    }

printf(" x is %d \n\r", x);

  if(x < num_max) return 1;
  else return 0;
}



THEN IN reset_zone...........

void reset_zone(int zone)
{
  int cmd_no, last_cmd = 0;
  struct char_data *mob = NULL;
  struct obj_data *obj, *obj_to;

  for (cmd_no = 0; ZCMD.command != 'S'; cmd_no++) {

    if (ZCMD.if_flag && !last_cmd)
      continue;

    switch (ZCMD.command) {
    case '*':                   /* ignore command */
      last_cmd = 0;
      break;

    case 'M':                   /* read a mobile */
printf("arg1 is %ld arg3 is %ld arg5 is %d\n\r", ZCMD.arg1, ZCMD.arg3, ZCMD.arg$
//      if (!mobs_lessthan_maxmobroom(ZCMD.arg1, ZCMD.arg3, ZCMD.arg5)){
//        last_cmd=0;
//        break;}
//      mobs_lessthan_maxmobroom(ZCMD.arg1, ZCMD.arg3, ZCMD.arg5);
      if (mob_index[ZCMD.arg1].number < ZCMD.arg2){
        mob = read_mobile(ZCMD.arg1, REAL);
          char_to_room(mob, ZCMD.arg3);
          last_cmd = 1;
      }
      else last_cmd = 0;
      break;

--8<--


     +------------------------------------------------------------+
     | 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