ID:138615
 
Okay, I am trying to use bitvectors but I am not sure how I would check and set/clear them.
Say I have the following:
#define A 1 #define ACT_IS_NPC (A) /* Auto set for mobs */
Now, say further that all mobs have a variable EFFECTS. How would I:
A) Set the ACT_IS_NPC flag in EFFECTS
B) Check to see if that flag is set for a mob
C) Clear that flag for a mob

Thanks for the help!
-James
On 5/4/00 10:07 am jmurph wrote:

#define A 1
#define ACT_IS_NPC (A) /* Auto set for mobs */
</code>
Now, say further that all mobs have a variable EFFECTS. How would I:
A) Set the ACT_IS_NPC flag in EFFECTS

mob.EFFECTS |= ACT_IS_NPC

B) Check to see if that flag is set for a mob

if(mob.EFFECTS&ACT_IS_NPC)
...

C) Clear that flag for a mob

mob.EFFECTS &= ~ACT_IS_NPC

There is an explanation of bit vectors in the old DUNG board somewhere (I think the topic is "bit fields"). That might help.

This all said, it would probably be wiser just to use a list to store effects. Bit fields, while efficient, are limiting (since you can only use up to 32 different fields (2^32 = sizeof(int)) and are also hard to read in the code.