diff --git a/OpenRA.Game/Traits/Modifiers/HiddenUnderFog.cs b/OpenRA.Game/Traits/Modifiers/HiddenUnderFog.cs index ba5efc288b..ba7f637c27 100644 --- a/OpenRA.Game/Traits/Modifiers/HiddenUnderFog.cs +++ b/OpenRA.Game/Traits/Modifiers/HiddenUnderFog.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; -namespace OpenRA.Traits.Render +namespace OpenRA.Traits { class HiddenUnderFogInfo : ITraitInfo { @@ -36,13 +36,17 @@ namespace OpenRA.Traits.Render shroud = self.World.WorldActor.traits.Get(); } + public bool IsVisible(Actor self) + { + return self.World.LocalPlayer == null + || self.Owner == self.World.LocalPlayer + || shroud.visibleCells[self.Location.X, self.Location.Y] > 0; + } + static Renderable[] Nothing = { }; public IEnumerable ModifyRender(Actor self, IEnumerable r) { - if (self.World.LocalPlayer == null || self.Owner == self.World.LocalPlayer || shroud.visibleCells[self.Location.X, self.Location.Y] > 0) - return r; - else - return Nothing; + return IsVisible(self) ? r : Nothing; } } } diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index b0c6a8b1dc..8ab2c4d40c 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -81,7 +81,7 @@ namespace OpenRA public static IEnumerable FindUnitsAtMouse(this World world, int2 mouseLocation) { var loc = mouseLocation + Game.viewport.Location; - return FindUnits(world, loc, loc); + return FindUnits(world, loc, loc).Where(a => a.IsVisible()); } public static IEnumerable FindUnits(this World world, float2 a, float2 b) @@ -147,15 +147,18 @@ namespace OpenRA public static bool IsVisible(this Actor a) { var shroud = a.World.WorldActor.traits.Get(); - return a.traits.Contains() - ? Shroud.GetVisOrigins(a).Any(o => shroud.visibleCells[o.X, o.Y] > 0) - : Shroud.GetVisOrigins(a).Any(o => shroud.exploredCells[o.X, o.Y]); + if (!Shroud.GetVisOrigins(a).Any(o => shroud.exploredCells[o.X, o.Y])) // covered by shroud + return false; + + var huf = a.traits.GetOrDefault(); // hidden under fog + if (huf != null && !huf.IsVisible(a)) + return false; + + return true; } public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft) { - - var buildingMaxBounds = bi.Dimensions; if( Rules.Info[ buildingName ].Traits.Contains() ) buildingMaxBounds.Y += 1;