Edit: since attack.condition will occasionally have multiple values, a switch statement won't work!
So I have this enum which is going to grow:
enum Condition { Null = 0x0001,
SelfIsUnderground = 0x0002,
SelfIsGround = 0x0004,
SelfIsAir = 0x0008,
SelfIsWater = 0x0010,
OtherIsUnderground = 0x0020,
OtherIsGround = 0x0040,
OtherIsAir = 0x0080,
OtherIsWater = 0x0100,
Tile = 0x0200,
CONDITION_COUNTX = 0x03FF};
and this function which is also going to grow:
bool Attack::CanBeDone(Spirit* pSelf, Spirit* pTarget,Map* pMap)
{
if(this->condition!=Null)
{
if(this->condition & SelfIsUnderground)
if(pSelf->GetcurrentLayer()!=Underground)
return false;
if(this->condition & SelfIsGround)
if(pSelf->GetcurrentLayer()!=Ground)
return false;
if(this->condition & SelfIsAir)
if(pSelf->GetcurrentLayer()!=Air)
return false;
if(this->condition & SelfIsWater)
if(pSelf->GetcurrentLayer()!=Water)
return false;
if(this->condition & OtherIsUnderground)
if(pTarget->GetcurrentLayer()!=Underground)
return false;
if(this->condition & OtherIsGround)
if(pTarget->GetcurrentLayer()!=Ground)
return false;
...
Is there an alternative to writing over and over again:
if(this->condition & arg)
if(pSelf->GetcurrentLayer()!=value)
return false;
?
Bonus: Will it work if I give Condition::Null the value 0x0000, SelfIsUnderground 0x0001, SelfIsGround 0x0002 and go with powers of 2 again? Eventually, Tile would end up with the value 0x0100.