diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index b54c54f542..a2785ed52c 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -61,7 +61,6 @@ namespace OpenRA public Shroud Shroud; public World World { get; private set; } - readonly IFogVisibilityModifier[] fogVisibilities; readonly StanceColors stanceColors; static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true) @@ -134,8 +133,6 @@ namespace OpenRA PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); Shroud = PlayerActor.Trait(); - fogVisibilities = PlayerActor.TraitsImplementing().ToArray(); - // Enable the bot logic on the host IsBot = BotType != null; if (IsBot && Game.IsHost) @@ -172,28 +169,9 @@ namespace OpenRA public bool CanTargetActor(Actor a) { - // PERF: Avoid LINQ. - if (HasFogVisibility) - foreach (var fogVisibility in fogVisibilities) - if (fogVisibility.IsVisible(a)) - return true; - return CanViewActor(a); } - public bool HasFogVisibility - { - get - { - // PERF: Avoid LINQ. - foreach (var fogVisibility in fogVisibilities) - if (fogVisibility.HasFogVisibility()) - return true; - - return false; - } - } - public Color PlayerStanceColor(Actor a) { var player = a.World.RenderPlayer ?? a.World.LocalPlayer; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 6bfef115f7..5f5654f6a6 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -190,12 +190,6 @@ namespace OpenRA.Traits public interface IDefaultVisibility { bool IsVisible(Actor self, Player byPlayer); } public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } - public interface IFogVisibilityModifier - { - bool IsVisible(Actor actor); - bool HasFogVisibility(); - } - public interface IOccupySpaceInfo : ITraitInfoInterface { IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any); diff --git a/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs b/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs index f715bff223..0d206700b8 100644 --- a/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs +++ b/OpenRA.Mods.Cnc/Traits/GpsWatcher.cs @@ -11,8 +11,6 @@ using System.Collections.Generic; using System.Linq; -using OpenRA.Effects; -using OpenRA.Mods.Cnc.Effects; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -26,7 +24,7 @@ namespace OpenRA.Mods.Cnc.Traits interface IOnGpsRefreshed { void OnGpsRefresh(Actor self, Player player); } - class GpsWatcher : ISync, IFogVisibilityModifier + class GpsWatcher : ISync, IPreventsShroudReset { [Sync] public bool Launched { get; private set; } [Sync] public bool GrantedAllies { get; private set; } @@ -92,20 +90,11 @@ namespace OpenRA.Mods.Cnc.Traits tp.Trait.OnGpsRefresh(tp.Actor, owner); } - public bool HasFogVisibility() + bool IPreventsShroudReset.PreventShroudReset(Actor self) { return Granted || GrantedAllies; } - public bool IsVisible(Actor actor) - { - var gpsDot = actor.TraitOrDefault(); - if (gpsDot == null) - return false; - - return gpsDot.IsDotVisible(owner); - } - public void RegisterForOnGpsRefreshed(Actor actor, IOnGpsRefreshed toBeNotified) { notifyOnRefresh.Add(new TraitPair(actor, toBeNotified)); diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForExploration.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForExploration.cs index f4b9ac0e8a..62a76c0ce6 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForExploration.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForExploration.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -22,7 +23,9 @@ namespace OpenRA.Mods.Cnc.Traits void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator) { infiltrator.Owner.Shroud.Explore(self.Owner.Shroud); - if (!self.Owner.HasFogVisibility) + var preventReset = self.Owner.PlayerActor.TraitsImplementing() + .Any(p => p.PreventShroudReset(self)); + if (!preventReset) self.Owner.Shroud.ResetExploration(); } } diff --git a/OpenRA.Mods.Common/Traits/Crates/HideMapCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/HideMapCrateAction.cs index f1f13921b2..1fa4223e98 100644 --- a/OpenRA.Mods.Common/Traits/Crates/HideMapCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/HideMapCrateAction.cs @@ -9,6 +9,8 @@ */ #endregion +using System.Linq; + namespace OpenRA.Mods.Common.Traits { [Desc("Hides the entire map in shroud.")] @@ -33,7 +35,9 @@ namespace OpenRA.Mods.Common.Traits public override int GetSelectionShares(Actor collector) { // Don't hide the map if the shroud is force-revealed - if (collector.Owner.HasFogVisibility || collector.Owner.Shroud.ExploreMapEnabled) + var preventReset = collector.Owner.PlayerActor.TraitsImplementing() + .Any(p => p.PreventShroudReset(collector.Owner.PlayerActor)); + if (preventReset || collector.Owner.Shroud.ExploreMapEnabled) return 0; return base.GetSelectionShares(collector); diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 83c1bd39f8..4755ede064 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -382,4 +382,7 @@ namespace OpenRA.Mods.Common.Traits { IEnumerable> TargetableCells(); } + + [RequireExplicitImplementation] + public interface IPreventsShroudReset { bool PreventShroudReset(Actor self); } }