Re: Counting elements in a bitvector?

From: Thomas Arp (t_arp@stofanet.dk)
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)))
      count++;

  return count;
}

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


Welcor

Note: Mailer code.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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