Re: Room Bits

From: Hades (tourach@cyber1.servtech.com)
Date: 03/08/96


> 
> Hello All-
> 
> I am curious as to whether or not there is a way (and I'm sure there is) 
> to temporarily set a bit on a room if something else is true. For 
> example: I want to make a NOMAGIC flag for objects. I want any room that 
> the nomagic object is in to be flagged NOMAGIC as long as the object is 
> in that rom, and then remove the bit when the object is removed.
> 
> Is there some way to do something perhaps like this:
> 
> if((ITEM_FLAGGED, ITEM_NOMAGIC) && (!ROOM_FLAGGED, ROOM_NOMAGIC) &&
>   (/* the object is in the room */))
> 
>      code here to turn on the NOMAGIC bit
> 
> 
> I am not a C newbie but I am not the expert that many of you seem to be. 
> Any help would be appreciated as I can't find anywhere in the code where 
> a room bit is set temporarily.
> 

Well here's my suggestion. Kinda. :)

In the function char_from_room(ch) you'd have to do something like this:
(This function is in english of course, I'm not figgering out the code here)

if(the_char_who's_leaving has an object flagged as !MAGIC &&
   no other object in the room  or on a char in the room has an obj flagged
   as !magic) {
   REMOVE_BIT(the !MAGIC bit)
  }

Of course thgis is complicated. IUt involves checking every piece of eq
equipped by the char and in his inv and in containers (if they are to work
within containers). If he DOES have one, then you have to check to see if
there are others (if you dont, and 2 are in that room, and he leaves, the
!MAGIC flag will be removed). So you then have to check the rooms contents,
then the eq and inv of every mob/pc in that room. Then if no eq in there is
!MAGIC, then remove the bit.

And in chaar_to_room(ch, <room>); you'd need:

if(ch has some !MAGIC gear somewhere and !ROOM_FLAGGED(!magic))
  set no magic flag on room.

That would make it so whenever a char entered a room it'd be flagged, and
it'd be unflagged if necessary when he left. A char cannot leave or enter a
room without using the char_to and char_from rooms functions, so this is the
safest place to put this code.

Actually, instead of checking every thing in the room on the char_from_room,
this would be easier:

(approxmate c code)

for(obj = object_list; obj; obj = obj->next) {
  if(!IS_SET(OBJ_FLAGS(obj), ITEM_NOMAGIC))
    continue;
  if(obj->in_room == ch->in_room)
    doit = 1;
  if(obj->worn_by == ch)
    doit = 1;
  if(obj->carried_by == ch)
    doit = 1;
  if(obj->worn_by)
    if(obj->worn_by->in_room == ch->in_room)
      doit = 1;
  if(obj->carried_by)
    if(obj->carried_by->in_room == ch->in_room)
      doit = 1;
  if(doit)
    nomagic_items_in_room++;
}

if(nomagic_items_in_room < 2)
  REMOVE_BIT(ROOM_FLAGS(ch->in_room), ROOM_NOMAGIC);

Now that is a bad hack at doing it, as it searches through every damn object
in the game and checks to see if it's in the same room as a character and if
it's !MAGIC, then it counts up that number of objects. if there is 1 or 0,
removbe the bit, if it's 2+, then leave the bit alone.

The problem with this? EVERY time a char or mob leaves a room it will scan
the entire object list. now that's just a bad idea. LAG. If you have as many
mobs as I do, I'd say that's about 300 mobs moving every 2 seconds. That
means it's running through the object list *300* times every 2 seconds.
That's a bad idea.

An alternate choicce? And more efficient? Basically copy the object_list
structure and make nomagic_object_list, and everytime an obj loads or is
extracted, check it for being !MAGIC, then add it to or remove it from that
list. That wayt if only 5 !MAGIC items are loadeds, you only check a list of
5 objects rather than 1500 or so (or however many objects you have loaded).
Much quicker and much more efficient.

My overall estimation though: !MAGIC items that effect a room are just WAY
too much hassle to try and code. I'd find an alternate choice.

Ooh, just got an even better idea. But this would only work if the !MAGIC
item was equipped (and with minor changes, if in inv, but would not work if
on the floor in a room). If a char picks up or equipps a !MAGIC object, then
have it set a !MAGIC flag on the char. Then, when he enters or leaves, just
check the chars in the room for the !MAGIC flag. if they are flagged, then
set the room's flag. Much quicker and easier.

Man why don't I think of these things before I write up a huge email with
code only to realize my firstr line of thinking sucked? :)

Hades the confused imp of Ebon Mists



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