Re: Bitvectors

From: Mike Stilson (
Date: 01/04/02

On Fri, Jan 04, 2002 at 11:41:10AM -0600, David Cole wrote:
>> What about changing it to an array in char_specials_saved
>> (affected_by[4]) then change the definitions to
>> #define AFF_FLAGGED(ch, num, flag) (IS_SET(AFF_FLAGS(ch), (num)), (flag))
>> #define AFF_FLAGS(ch, num) ((ch)->char_specials_saved.affected_by[(num)])
>> #define IS_AFFECTED(ch, num, flag) (AFF_FLAGGED((ch), (num), (skill))
>In all honestly I liked to use the array, it looked allot cleaner & an more
>friendly. I was looking through the Vision source code, and I believe it
>used arrays, was very well done, and looked pretty simple. However my

No idea.  never looked at the vision source.
Actually to make it cleaner I'd change it all around to either bitfields
or at least change AFF_xxx from something like 1<<x to enums and then a
function to determine the correct array to use, but that'd be a helluva
lot of recoding.

>knowledge with arrays is rough at best, and I couldn't quit seem to grasp
>how to make it work with ASCII pfiles, It keep complaining about me using
>AFF_FLAGS(ch) = PFILE_AFF_FLAGGED (Something to that affect).

(note: I'd rather replace the hard-coded '4' with a define like:
#define NUM_AFF_ARRAYS 4 or something but anyway...

for(i=0;i<4;i++) AFF_FLAGS(ch, i) = PFILE_AFF_FLAGGED or whatever.
It'd need to match the macros above.

>Have you used this method with having acsii pfiles? If so, how did you over
>come the above?

I use a database for mine, but it'd be trivial.
(repeat for 1,2,3)
(pseudo-code from memory)

fbprintf(fl, "Afff:\n");
for(i=0;i<4;i++) fbprintf(fl, %Ld\n", AFF_FLAGS(ch, i));

if str_cmp(tag, 'Afff') {
        i = 0;
        while(i < 4) {
                fbgetline(fl, line);
                AFF_FLAGS(ch, i++) = atol(line);

Of course, you could also define them as unsigned long long int's if
your compiler supports it and use 64 bits/flag, but that was discussed
at length in other threads.


   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT