Provide HasStance extension method for Stance enum, to avoid overhead of HasFlag method.

This commit is contained in:
RoosterDragon
2015-07-14 20:01:29 +01:00
parent 6113892276
commit 3a0eb5554e
6 changed files with 16 additions and 8 deletions

View File

@@ -32,6 +32,14 @@ namespace OpenRA.Traits
Ally = 4, Ally = 4,
} }
public static class StanceExts
{
public static bool HasStance(this Stance s, Stance stance)
{
return (s & stance) == stance;
}
}
[Flags] [Flags]
public enum ImpactType public enum ImpactType
{ {

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
return true; return true;
var stance = self.Owner.Stances[byPlayer]; var stance = self.Owner.Stances[byPlayer];
return info.AlwaysVisibleStances.HasFlag(stance) || visible[byPlayer]; return info.AlwaysVisibleStances.HasStance(stance) || visible[byPlayer];
} }
public void Tick(Actor self) public void Tick(Actor self)

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
return true; return true;
var stance = self.Owner.Stances[byPlayer]; var stance = self.Owner.Stances[byPlayer];
return Info.AlwaysVisibleStances.HasFlag(stance) || IsVisibleInner(self, byPlayer); return Info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer);
} }
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r) public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
public string TooltipForPlayerStance(Stance stance) public string TooltipForPlayerStance(Stance stance)
{ {
if (stance == Stance.None || !GenericVisibility.HasFlag(stance)) if (stance == Stance.None || !GenericVisibility.HasStance(stance))
return Name; return Name;
if (GenericStancePrefix && stance == Stance.Ally) if (GenericStancePrefix && stance == Stance.Ally)

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
var stance = self.Owner.Stances[a.Owner]; var stance = self.Owner.Stances[a.Owner];
if (!info.ValidStances.HasFlag(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<UpgradeManager>();
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.LengthSquared) if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.LengthSquared)
{ {
var stance = self.Owner.Stances[produced.Owner]; var stance = self.Owner.Stances[produced.Owner];
if (!info.ValidStances.HasFlag(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = produced.TraitOrDefault<UpgradeManager>(); var um = produced.TraitOrDefault<UpgradeManager>();
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
var stance = self.Owner.Stances[a.Owner]; var stance = self.Owner.Stances[a.Owner];
if (!info.ValidStances.HasFlag(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<UpgradeManager>();

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Warheads
return false; return false;
var stance = firedBy.Owner.Stances[victim.Owner]; var stance = firedBy.Owner.Stances[victim.Owner];
if (!ValidStances.HasFlag(stance)) if (!ValidStances.HasStance(stance))
return false; return false;
// A target type is valid if it is in the valid targets list, and not in the invalid targets list. // A target type is valid if it is in the valid targets list, and not in the invalid targets list.
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Warheads
// AffectsParent checks do not make sense for FrozenActors, so skip to stance checks // AffectsParent checks do not make sense for FrozenActors, so skip to stance checks
var stance = firedBy.Owner.Stances[victim.Owner]; var stance = firedBy.Owner.Stances[victim.Owner];
if (!ValidStances.HasFlag(stance)) if (!ValidStances.HasStance(stance))
return false; return false;
// A target type is valid if it is in the valid targets list, and not in the invalid targets list. // A target type is valid if it is in the valid targets list, and not in the invalid targets list.