Mail Archives: djgpp/1997/07/21/13:09:57
First:
The "&&" operator is for logical "and" (ie if (a>1 && b>2), not
for bitwise anding.
Try the following instead:
/****
int has_item(int equip, int item) {
return (equip & item);
}
/****
This will return 0 if item is not in equip, or non-zero (eg: true)
if it is. Make sure that all of your items' bits don't step on each other
unless they are mutually exclusive. For example you could have.
/****
#define BIG_ROCK 1 // Could also use const ints
#define HELMET 2
#define A_LITTLE_FOOD 4
#define SOME_FOOD 12
#define A_LOT_OF_FOOD 28
#define STILLETTO 32
/****
In this example, BIG_ROCK uses bit 0, HELMET uses bit 1, FOOD uses
bits 2, 3 and 4, and STILLETTO uses bit 5. (Note that if you ask if a
character with SOME_FOOD, or A_LOT_OF_FOOD, has A_LITTLE_FOOD, it will
return true, etc...).
Hope this helps.
--Insomnia
--Sleep is for the weak!
- Raw text -