Re: Counting elements in a bitvector?

From: Thomas Arp (
Date: 08/26/02

From: "Mark Garringer" <zizazat@HOTMAIL.COM>
> What I would like to do is based on the number of guilds you are in, use
> that as a modifier to the generic XP formula. But how would I go about
> counting the number of guild flags that the player has?

int count_guilds(struct char_data *ch)
  int i, count = 0;

  for (i = 0;i < 32;i++)
    if (IS_SET(GET_GUILD_BITVECTOR(ch), (1<<i)))

  return count;

Assuming you're using a 32 bit wide integer to keep the bitvector, and
GET_GUILD_BITVECTOR() points to the guild info.


Note: Mailer code.

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

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