Re: Adding Mob Action Bitvectors

From: Tel Janin Aellinsar (icarus@Loomis.Berkshire.NET)
Date: 04/04/96


On Thu, 4 Apr 1996, Fionn Colvin wrote:

> Hi all,
>        In the Mud that I am writing I have 15 classes and 15 races. What 
> I would like to do is add some more Action Bitvectors for mobs so I can 
> have an aggressive one for each class and race, eg
> 
> MOB_AGGR_WARRIOR etc.
> 
> However, since the action bitvectors are assigned with letters, and at 
> current NOBLIND is already "r" how ca I add another 30? Has anyone else 
> added heaps for Action Bitvectors? If so how did you do it?
> 
> Any help would be greatly appreciated.
> 
> Thanks in advance
> 
> Fionn
> 

A hopefully brief explanation of bitvectors first.

As you might know, each byte is really 8 bits of either a zero or a one.  
Each bit represents a value of 2^n, where n is the position of the bit, 
starting at zero and counting right-to-left.  For example,

 000001000

The one here is in the n=3 position, so its value is 2^3.  This is why 
the range of a single byte is 0-256 - 8 bits of 1 in each slot is 256.  
(Sometimes the high bit has a 1 for a negative sign, 0 for a positive 
sign, which decreases the range maximum but adds negative numbers.)

The largest standard integer on an i386 or higher and a bunch of other 
computers is a doubleword (dword), which is the same an unsigned long int 
of 32 bits.  (There's also a quadword, qword, but I've never seen it 
used.)  Since each bitvector is really a slot in the bit field (2^n is 
the same as 1 << n, as in the circle code) you can only have up to 32 
different "flags" in a single variable.

If I understand your question correctly, you want to double the number of 
flags currently in use (adding another 30?).  This would require a 60-bit 
(or, more realistically, a 64-bit/8-byte) variable.  The problem is that 
this doesn't really work.  You've just run into one of the big problems 
of CircleMUD programmers.

Here are some possible remedies.  You may decide that the cure is worse 
than the disease, and I'd agree with you, for some of these.

1. Make each flag a variable.  So each "flag" is really a char, for example.
   The problem with this is that it sucks up memory and disk space at a
   truly ridiculous rate.

2. Use OS/2-style extended attributes.  These take up even more space,
   but you can give them creative names which are implementation-dependent
   rather than system-dependent.  For example, player health points could
   be "PlayerMaxHp" and you'd get at it via ExtAttrRead("PlayerMaxHp") or
   whatever.  Slow.  Messy.  Memory hog.  Standard stuff.

3. Make a second variable to hold the additional flags.  This requires
   hand-changing much of the code to use the correct variable automagically.

4. Cut out some unnecessary flags.  This is, for some people, unacceptable,
   and I can totally understand the reason why.

I'm sure I've missed some.  Anyone else care to chip in?

Next step: how to identify these.  Best suggestion I've heard so far is 
to use a special character, such as a ^.  So the following line:

abcdef^gh

is really interpreted as:

a | b | c | d | e | f | (z + g) | h

(z is in the second set of characters).

Another possibility is to use words, such as the names of the #defines.  
Again, it takes up space.

________________________________________________________________________
Tel Janin Aellinsar                       http://www.crocker.com/~icarus
McCoy Enterprises Corporation          Shayol Ghul Resort and Health Spa
Berserker Dragon, Knights of the Cosmos             icarus@BERKSHIRE.NET



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