Yeah, just ditch all the if, else if, constructs and make it a big || set.

if( (IS_RESTRICT_CLASS(obj, REST_CLASS_WITCH) && ch->class==CLASS_WITCH) ||
   (IS_RESTRICT_CLASS(obj, REST_CLASS_CLERIC) && ch->class==CLASS_CLERIC) ||
   //etc......
  )
  return TRUE;
else
  return FALSE;

but other than that? not that I can think of (though, I do believe the low 
level code, a big || set
is a tad quicker, especially with "first-out" operations)...

you COULD re-write the system, instead of having IS_RESTRICT_CLASS check 
against REST_CLASS_WITCH,
have it simply check against CLASS_WITCH, then you'd be able to do it in a 
simple for loop (going from the first class
to the last), but yeah, that might be more work than it's worth to ya....

In all seriousness though, if it works as is, no MAJOR reason to switch it.


-Icechild


-----Original Message-----
From: Mervine, Keith [mailto: [EMAIL PROTECTED]
Sent: 4/11/2003 at 2:43 PM
To: <[email protected]>
Subject:  Is there a better way to do this check?
Message:

>Greetings,
>       Is there (im sure there is) a better way to do this check?
>It's to check class and compare the items restrictclass var to it to
>Make sure the characters class can use it....
>
>bool can_wear_class(CHAR_DATA *ch, OBJ_DATA *obj){
>   if (!obj->restrictclass)
>        return TRUE; //no restrictions
>
>        if (IS_RESTRICT_CLASS(obj, REST_CLASS_WITCH) &&
>ch->class==CLASS_WITCH)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_CLERIC) && ch->class
>==CLASS_CLERIC)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_THIEF) &&
>ch->class==CLASS_THIEF)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_WARRIOR) &&
>ch->class==CLASS_WARRIOR)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_PALADIN) && ch->class
>==CLASS_PALADIN)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_DARK_PALADIN) &&
>ch->class==CLASS_DARK_PALADIN)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_NINJA) &&
>ch->class==CLASS_NINJA)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_RANGER) && ch->class
>==CLASS_RANGER)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_WARLOCK) &&
>ch->class==CLASS_WARLOCK)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_SAMURAI) &&
>ch->class==CLASS_SAMURAI)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_VAMPIRE) && ch->class
>==CLASS_VAMPIRE)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_NECROMANCER) &&
>ch->class==CLASS_NECROMANCER)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_PSIONICIST) &&
>ch->class==CLASS_PSIONICIST)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_WATER_ELEM) &&
>ch->class==CLASS_WATER_ELEM)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_AIR_ELEM) &&
>ch->class==CLASS_AIR_ELEM)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_FIRE_ELEM) && ch->class
>==CLASS_FIRE_ELEM)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_EARTH_ELEM) &&
>ch->class==CLASS_EARTH_ELEM)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_LIGHT_ELEM) &&
>ch->class==CLASS_LIGHT_ELEM)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_ASSASSIN) &&
>ch->class==CLASS_ASSASSIN)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_MONK) &&
>ch->class==CLASS_MONK)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_BARD) &&
>ch->class==CLASS_BARD)
>        return TRUE;
>   else if (IS_RESTRICT_CLASS(obj, REST_CLASS_DRUID) &&
>ch->class==CLASS_DRUID)
>        return TRUE;
>
>
>   return FALSE; //didn't succeed at any comparison checks
>}
>
>
>Keith Mervine
>"Non Omnis Moriar"
>"Growing old is mandatory, growing up is optional"
>Service Management Application Developer
>International Monetary Fund
>[EMAIL PROTECTED]
>202-623-7610
>
>
>--
>ROM mailing list
>[email protected]
>http://www.rom.org/cgi-bin/mailman/listinfo/rom





Reply via email to