Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ checking enum flags
    text
    copied!<p>In one of my classes, I have an integer that stores a set of enum flags like so:</p> <pre><code>enum AttackFlags { Contact = 1, //Move connects with target Projectile = 2, //Attack is projectile based Unblockable = 4, //Attack can not be blocked UncounterableLv1 = 8, //Attack can't be countered except by extreme counter attack skills/status effects UncounterableLv2 = 16, //Attack can not be countered Flinches = 32, //Has a chance to stun the enemy, pushing back their next turn Unreflectable = 64, //Attack penetrates reflect. Only checked for Magic attacks IgnoreDefenderStatusEffects = 128, //Ignores active status effects on the defender IgnoreAttackerStatusEffects = 256, //Ignores active status effects on the attacker IgnoreDefenderAbilities = 512, //Ignore the defenders abilities IgnoreAttackerAbilities = 1024, //Ignore the attackers abilities IgnoreArmorRating = 2048, //Ignore the defensive boosts of armor IgnoreWeaponRating = 4096, //Ignore the attack boost from weapons HighCritical = 8192, //The move has an increased chance to crit CausesStatus = 16384, //Can the move cause status effects? Elemental = 32768, //Is the move elemental based? Unimplemented = 65536, //has the move been implemented yet? ModsTimer = 131072, //Does it have an effect on the target or users timer? Heals = 262144, //Does the move heal? SecondaryEffects = 524288, //Attack has additional effects besides basic attack PhysicalAttackFlag = 1048576, //Is the Class Physically based? I.E. blocked by Protect and Shield MagicAttackFlag = 2097152, //Is the move Magically Based? I.E. is it affected by things like Shell MultiHit = 4194304, //Does it enxcapsulate more then 1 hit SingleUse = 8388608, //Attack can only be used once per battle DoesNotCauseDamage = 16777216 }; class Attack { int AtkFlags; //Stores AttackFlags |'d together } </code></pre> <p>I'd like to add a method to my Attack class with the following signature</p> <pre><code>bool HasAttackFlags(int flags); </code></pre> <p>flags would be numerous AttackFlags |'d together. If I only wanted to check against a single flag, I could just &amp; AtkFlags and flags together, but because I have to check against multiple possible flags this won't work. How can I properly check for multiple flags? I'd like to avoid passing a vector/set of flags to check against as simply |'ing a set of flags together is simpler then constructing a vector/set</p> <p>Thanks in advance</p> <p>EDIT:</p> <p>To clarify what I mean, I might have the following</p> <pre><code>Attack atk; atk.AtkFlags = Contact | Projectile | Heals | MagicAttackFlag; </code></pre> <p>Then later, I'd want to check the flags on atk like so:</p> <pre><code>bool res = atk.HasAttackFlags(Contact | Projectile); </code></pre> <p>res should be true and conversely</p> <pre><code>bool res = atk.HasAttackFlags(Contact | Unreflectable); </code></pre> <p>should be false becase AtkFlags does not contain both Contact adn Unreflectable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload