/**************************************************************************** * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | * * -----------------------------------------------------------| \\._.// * * SmaugWiz (C) 1998 by Russ Pillsbury (Windows NT version) | (0...0) * * -----------------------------------------------------------| ).:.( * * SMAUG (C) 1994, 1995, 1996 by Derek Snider | {o o} * * -----------------------------------------------------------| / ' ' \ * * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, |~'~.VxvxV.~'~* * Scryn, Swordbearer, Rennard, Tricops, and Gorog. | * * ------------------------------------------------------------------------ * * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael * * Chastain, Michael Quan, and Mitchell Tse. * * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, * * Michael Seifert, Hans Henrik Staerfeldt, Tom Madsen, and Katja Nyboe. * * ------------------------------------------------------------------------ * * Smaug BitVector Implementation file * ***************************************************************************/ #include "stdafx.h" #include "smaug.h" #include "BitVector.h" // SetBits sets all the bits from the input vector, and does not // modify any other bits. void CBitVector::SetBits (const CBitVector& in) { for (int i=0; i < 4; ++i) bits [i] |= in.bits [i]; } // ClearBits clears all the bits which are set in the input vector, // and does not modify any other bits. void CBitVector::ClearBits (const CBitVector& in) { for (int i=0; i < 4; ++i) bits [i] &= ~in.bits [i]; } const CBitVector& CBitVector::operator= (const CBitVector& in) { for (int i=0; i < 4; ++i) bits [i] = in.bits [i]; return *this; } BOOL CBitVector::operator== (const CBitVector& in) const { for (int i=0; i < 4; ++i) if (bits [i] != in.bits [i]) return FALSE; return TRUE; } // Read a BitVector from a static string void CBitVector::Parse (char*& pLine) { for (int i=0; i < 4; ++i) { bits [i] = ParseNumber (pLine); if (*pLine != '&') break; ++pLine; } } void CBitVector::ParseString (char*& pLine, const char* names [], int size) { char *word; while (*pLine) { word = ParseWord (pLine); int len = strlen (word); if (word [len-1] == '~') word [len-1] = 0; for (int i=0; i < size; ++i) if (! stricmp (names [i], word)) { SetBit (i); break; } } } CString CBitVector::PrintVector () const { CString s; char nbuf [64]; int i, j; for (i=3; i > 0; --i) if (bits [i]) break; for (j=0; j <= i; ++j) { sprintf (nbuf, "%d", bits [j]); s += nbuf; if (j < i) s += '&'; } return s; } CString CBitVector::PrintString (const char* names [], int size) const { CString s; BOOL bFirst = TRUE; for (int i=0; i < size; ++i) if (IsSet (i)) { if (! bFirst) s += ' '; s += names [i]; bFirst = FALSE; } return s; } int ConvertBvToBit (int bv) { int bit = -1; for (int i=0; i < 32; ++i) if (bv & (1 << i)) { bit = i; break; } return bit; }