I really dunno how to word this question... Basically, instead of doing this:
if (unitWeapon == mapLaser || unitWeapon == mapRailGun || ...)
I want to do something like this:
if (unitWeapon == anEdenWeapon)
Where that will return true if the unit's weapon is a weapon available to Eden.
I'm pretty sure this is doable (and relatively easy), I just forget how...
I don't know of anything built in. You probably just have to write your own function.
bool IsEdenWeapon(weaponType)
{
switch(weaponType)
{
case mapLaser:
case mapRailGun:
// ...
return true; // Use switch case fall through (no "break" statement)
}
// Nope
return false;
}
if (IsEdenWeapon(weaponType))
{
// Eden weapon type code goes here
}
// Or for the alternate case
if (!IsEdenWeapon(weaponType))
{
// Non-Eden weapon type code goes here
}
Well, there is now. I thought that would be useful generic functionality, so I added some functions to the OP2Helper project.
bool IsEdenOnlyWeapon(map_id weaponType);
bool IsPlymouthOnlyWeapon(map_id weaponType);
bool IsCommonWeapon(map_id weaponType);
bool IsEdenWeapon(map_id weaponType); // Common or Eden only
bool IsPlymouthWeapon(map_id weaponType); // Common or Plymouth only
Enums are basically just named constants. They don't really provide any if shortcuts. At least not in C++. If you arrange the constants nicely though, you can get some degree of shortcuts. But we're dealing with an already specified set of constants which we can't reorder, and they're not ordered nicely.
If you could reorder constants to keep releated ones consecutive, you can do something like:
if (weaponType >= mapLaser && weaponType <= mapAcidCloud)
{
// ....
}
Mind you, you might want to add secondary constants in a case like that, such as mapEdenFirstWeapon, mapEdenLastWeapon. It would make the if statement slightly clearer, and the needed additions to the enum would be fairly obvious in meaning.
enum map_id
{
// ...
mapEdenFirstWeapon,
mapLaser = mapEdenFirstWeapon,
// ...
mapAcidCloud,
mapEdenLastWeapon = mapAcidCloud,
// ...
};
I'm not sure if you can use the enum constants within the enum declaration though, so the values on the right of the = might need to be actual numbers.
But yeah, irrelevant.