The "&" operation basically make a comparison between two sets of bit flags. In this case, it takes the value(s) of match, compares it to the room flag, and re-sets match to contain only matching flags. It kind of works like this:
01010101
& 11110001
------------
= 01010001
It only matches if both are set, so this is kind of filtering everything else out of the equation. In this case, I beleive that it is, and please anyone correct me if I am wrong, checking to see if whats supplied in the match variable is an exact match to the room flags. Now I'm not great with bitwise code, but if match and the rooms flags weren't exactly the same, then the result would not be equal to match, and so the code in the if check only gets executed if match has the same value as room_flags, at which point it puts the room in an array of rooms to be printed, I would assume?
If this is the circumstance, and you want to use xBV's, you could make a small function, if one doesn't already exist that just loops through the array of integers in the extended bitvectors and compares index 0 to index 0, 1 to 1, etc, and if all of them match, then add it to the list. You would also need to convert match to an extended bitvector, and set it with the extended bitvector functions.
[EDIT]
K, so a quick check came up with this:
#define xSAME_BITS(var, bit) (ext_same_bits(&(var), &(bit)))
/* for use by xSAME_BITS() -- works like == */
bool ext_same_bits(EXT_BV * var, EXT_BV * bits)
{
int x;
for (x = 0; x < XBI; x++)
if (var->bits[x] != bits->bits[x])
return FALSE;
return TRUE;
}
This should produce the same effect. Hope this helps.
[EDIT2]
Sure seem to be alot of edits lately, huh? Anyways, after looking at that again, its not checking for an exact match, its checking to see if all the flags specified in match are also in room_flags, but allows for more than just the ones specified, so you probably want to use xHAS_BITS(var, bit) instead.
You should be able to use ch_printf (ch, "\n\rRoom Vnums\n\r");
for (cou = 0; cou < MAX_KEY_HASH; cou++)
{
if ( room_index_hash[cou] )
for (pRoom = room_index_hash[cou]; pRoom; pRoom = pRoom->next)
{
if (pRoom->vnum >= lo && pRoom->vnum <= hi)
{
if ( xHAS_BITs(pRoom->room_flag, match)
&& hit_cou < DIAG_RF_MAX_SIZE)
vnum[hit_cou++] = pRoom->vnum;
}
}
}
Not tested, but lemme know. |