From 3a0eb5554effbba0bb4d78954b1007c86cfff5ef Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Tue, 14 Jul 2015 20:01:29 +0100 Subject: [PATCH] Provide HasStance extension method for Stance enum, to avoid overhead of HasFlag method. --- OpenRA.Game/Traits/TraitsInterfaces.cs | 8 ++++++++ OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs | 2 +- OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs | 2 +- OpenRA.Mods.Common/Traits/Tooltip.cs | 2 +- OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs | 6 +++--- OpenRA.Mods.Common/Warheads/Warhead.cs | 4 ++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index d5856d24c9..0fb00d6296 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -32,6 +32,14 @@ namespace OpenRA.Traits Ally = 4, } + public static class StanceExts + { + public static bool HasStance(this Stance s, Stance stance) + { + return (s & stance) == stance; + } + } + [Flags] public enum ImpactType { diff --git a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs index cdee1d2959..e911a02c7e 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits return true; 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) diff --git a/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs b/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs index b1eb280991..9d45976aef 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits return true; var stance = self.Owner.Stances[byPlayer]; - return Info.AlwaysVisibleStances.HasFlag(stance) || IsVisibleInner(self, byPlayer); + return Info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); } public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) diff --git a/OpenRA.Mods.Common/Traits/Tooltip.cs b/OpenRA.Mods.Common/Traits/Tooltip.cs index 3ab2986d34..6bfb944c02 100644 --- a/OpenRA.Mods.Common/Traits/Tooltip.cs +++ b/OpenRA.Mods.Common/Traits/Tooltip.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public string TooltipForPlayerStance(Stance stance) { - if (stance == Stance.None || !GenericVisibility.HasFlag(stance)) + if (stance == Stance.None || !GenericVisibility.HasStance(stance)) return Name; if (GenericStancePrefix && stance == Stance.Ally) diff --git a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs index 9fbe748e11..75e803ea00 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeActorsNear.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits return; var stance = self.Owner.Stances[a.Owner]; - if (!info.ValidStances.HasFlag(stance)) + if (!info.ValidStances.HasStance(stance)) return; var um = a.TraitOrDefault(); @@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= info.Range.LengthSquared) { var stance = self.Owner.Stances[produced.Owner]; - if (!info.ValidStances.HasFlag(stance)) + if (!info.ValidStances.HasStance(stance)) return; var um = produced.TraitOrDefault(); @@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits return; var stance = self.Owner.Stances[a.Owner]; - if (!info.ValidStances.HasFlag(stance)) + if (!info.ValidStances.HasStance(stance)) return; var um = a.TraitOrDefault(); diff --git a/OpenRA.Mods.Common/Warheads/Warhead.cs b/OpenRA.Mods.Common/Warheads/Warhead.cs index cff1414ad0..7eb3bc0652 100644 --- a/OpenRA.Mods.Common/Warheads/Warhead.cs +++ b/OpenRA.Mods.Common/Warheads/Warhead.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Warheads return false; var stance = firedBy.Owner.Stances[victim.Owner]; - if (!ValidStances.HasFlag(stance)) + if (!ValidStances.HasStance(stance)) return false; // 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 var stance = firedBy.Owner.Stances[victim.Owner]; - if (!ValidStances.HasFlag(stance)) + if (!ValidStances.HasStance(stance)) return false; // A target type is valid if it is in the valid targets list, and not in the invalid targets list.