Re: Checking to see how meny mobs are in a zone and in a room

From: Johan Eenfeldt (d95joe@csd.uu.se)
Date: 04/09/96


On Tue, 9 Apr 1996, JRhone wrote:

> > Is there any way i can see how meny of a certen mob(ie Vnum 1348) are in a room
> > and in a zone.  Is there some way to earch this.  I just want a number returned
> > being the number of that mob in the zone or room.  Any easy ways to do this or
> > does it take a bunch of code?

[some code snipped]

> int num_mob_zone(int mvnum, int zone)
> {
>   int count = 0;
>   int i;
> 
>   for (i=0; i <= top_of_world; i++)
>     if((real_room(i) > 0) && world[i].zone == zone && world[i].people)
          ^^^^^^^^^^^^^^^^
Why are you doing this?

real_room() finds the rnum of a given virtual number, and have nothing to do 
with the index of the world array. i is the rnum of the room (as you use 
later). So, what you are checking is if there exists a room with the 
virtual number of the rooms rnum. Or have I missed something?

As a sidenote it is a somewhat costly function to use for a loop going 
through every single room in the MUD, as it in turn would search through the 
world each time...

>       count += num_mob_room(mvnum, i);
>   return count;
> }
> 
> thats only one way to do this, you could just scan character_list
> and check the room / zone yer mob is in, 
> and im sure there are others

If your world array is sorted as in the standard edition and you want to 
do some easy optimizing, you could for example stop searching after you 
reach the end of the zone you are checking, and perhaps use binary search 
to find the beginning of it.

Or if you trust the correctness of your zonefiles you might use the 
zone_table to find the beginning/end of the zone.

Or... ;-)


/ Johan Eenfeldt
  Student, Computer Science Department @ the University of Uppsala
  d95joe@csd.uu.se



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