diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 2320101fc8..7bdaec90a7 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -140,7 +140,7 @@ namespace OpenRA.Graphics foreach (var t in world.Queries.WithTraitMultiple()) { - if (!t.Actor.IsVisible(player)) + if (!world.LocalShroud.IsVisible(t.Actor)) continue; var color = t.Trait.RadarSignatureColor(t.Actor); @@ -159,7 +159,7 @@ namespace OpenRA.Graphics var map = world.Map; var size = Util.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); Bitmap bitmap = new Bitmap(size, size); - if (world.LocalPlayer == null || world.LocalPlayer.Shroud == null) + if (world.LocalShroud.Disabled) return bitmap; var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), @@ -167,8 +167,6 @@ namespace OpenRA.Graphics var shroud = Color.Black.ToArgb(); var fog = Color.FromArgb(128, Color.Black).ToArgb(); - - var playerShroud = world.LocalPlayer.Shroud; unsafe { @@ -179,9 +177,9 @@ namespace OpenRA.Graphics { var mapX = x + map.Bounds.Left; var mapY = y + map.Bounds.Top; - if (!playerShroud.IsExplored(mapX, mapY)) + if (!world.LocalShroud.IsExplored(mapX, mapY)) *(c + (y * bitmapData.Stride >> 2) + x) = shroud; - else if (!playerShroud.IsVisible(mapX,mapY)) + else if (!world.LocalShroud.IsVisible(mapX,mapY)) *(c + (y * bitmapData.Stride >> 2) + x) = fog; } } diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 3ae71cda6a..86c869f2e9 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -79,9 +79,9 @@ namespace OpenRA.Graphics if (firstRow < 0) firstRow = 0; if (lastRow > map.Bounds.Height) lastRow = map.Bounds.Height; - if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.Disabled && world.LocalPlayer.Shroud.Bounds.HasValue) + if (world.LocalPlayer != null && !world.LocalShroud.Disabled && world.LocalShroud.Bounds.HasValue) { - var r = world.LocalPlayer.Shroud.Bounds.Value; + var r = world.LocalShroud.Bounds.Value; if (firstRow < r.Top - map.Bounds.Top) firstRow = r.Top - map.Bounds.Top; diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 7922f6e7ae..38bf341bc6 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -125,11 +125,9 @@ namespace OpenRA.Graphics public Rectangle ShroudBounds( World world ) { - var localPlayer = world.LocalPlayer; - if( localPlayer == null ) return world.Map.Bounds; - if( localPlayer.Shroud.Disabled ) return world.Map.Bounds; - if( !localPlayer.Shroud.Bounds.HasValue ) return world.Map.Bounds; - return Rectangle.Intersect( localPlayer.Shroud.Bounds.Value, world.Map.Bounds ); + if( world.LocalShroud.Disabled || !world.LocalShroud.Bounds.HasValue ) + return world.Map.Bounds; + return Rectangle.Intersect( world.LocalShroud.Bounds.Value, world.Map.Bounds ); } public Rectangle ViewBounds() diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 18957d7ee7..d9e183d6f8 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -31,7 +31,7 @@ namespace OpenRA.Graphics this.world = world; terrainRenderer = new TerrainRenderer(world, this); - shroudRenderer = new ShroudRenderer(world.WorldActor.Trait(), world.Map); + shroudRenderer = new ShroudRenderer(world); uiOverlay = new UiOverlay(); palette = new HardwarePalette(world.Map); @@ -53,9 +53,8 @@ namespace OpenRA.Graphics Rectangle GetBoundsRect() { - var r = (world.LocalPlayer != null && !world.LocalPlayer.Shroud.Disabled && world.LocalPlayer.Shroud.Bounds.HasValue)? - world.LocalPlayer.Shroud.Bounds.Value : world.Map.Bounds; - r.Intersect(world.Map.Bounds); + var r = (!world.LocalShroud.Disabled && world.LocalShroud.Bounds.HasValue)? + Rectangle.Intersect(world.LocalShroud.Bounds.Value,world.Map.Bounds) : world.Map.Bounds; var left = (int)(Game.CellSize * r.Left - Game.viewport.Location.X); var top = (int)(Game.CellSize * r.Top - Game.viewport.Location.Y); @@ -135,20 +134,6 @@ namespace OpenRA.Graphics Game.Renderer.LineRenderer.DrawLine(a, a + c, color, color); } - void DrawBins(RectangleF bounds) - { - DrawBox(bounds, Color.Red); - if (world.LocalPlayer != null) - DrawBox(world.LocalPlayer.Shroud.Bounds.Value, Color.Blue); - - for (var j = 0; j < world.Map.MapSize.Y; - j += world.WorldActor.Info.Traits.Get().BinSize) - { - Game.Renderer.LineRenderer.DrawLine(new float2(0, j * Game.CellSize), new float2(world.Map.MapSize.X * Game.CellSize, j * Game.CellSize), Color.Black, Color.Black); - Game.Renderer.LineRenderer.DrawLine(new float2(j * Game.CellSize, 0), new float2(j * Game.CellSize, world.Map.MapSize.Y * Game.CellSize), Color.Black, Color.Black); - } - } - public void DrawSelectionBox(Actor selectedUnit, Color c) { var bounds = selectedUnit.GetBounds(true); diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index fa40836bcc..b64e33fddb 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -40,7 +40,7 @@ namespace OpenRA public readonly PlayerReference PlayerRef; public bool IsBot; - public Shroud Shroud { get { return World.WorldActor.Trait(); }} + public Shroud Shroud { get { return World.LocalShroud; }} public World World { get; private set; } public Player(World world, PlayerReference pr, int index) diff --git a/OpenRA.Game/ShroudRenderer.cs b/OpenRA.Game/ShroudRenderer.cs index b3f04e7d4b..a250c537e8 100644 --- a/OpenRA.Game/ShroudRenderer.cs +++ b/OpenRA.Game/ShroudRenderer.cs @@ -23,26 +23,16 @@ namespace OpenRA bool dirty = true; Map map; - public ShroudRenderer(Traits.Shroud shroud, Map map) + public ShroudRenderer(World world) { - this.shroud = shroud; - this.map = map; + this.shroud = world.LocalShroud; + this.map = world.Map; sprites = new Sprite[map.MapSize.X, map.MapSize.Y]; fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y]; shroud.Dirty += () => dirty = true; } - public bool IsExplored(int x, int y) - { - return (shroud == null) ? true : shroud.IsExplored(x,y); - } - - public bool IsVisible(int x, int y) - { - return (shroud == null) ? true : shroud.IsVisible(x,y); - } - static readonly byte[][] SpecialShroudTiles = { new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, @@ -65,49 +55,49 @@ namespace OpenRA Sprite ChooseShroud(int i, int j) { - if( !IsExplored( i, j ) ) return shadowBits[ 0xf ]; + if( !shroud.IsExplored( i, j ) ) return shadowBits[ 0xf ]; // bits are for unexploredness: up, right, down, left var v = 0; // bits are for unexploredness: TL, TR, BR, BL var u = 0; - if( !IsExplored( i, j - 1 ) ) { v |= 1; u |= 3; } - if( !IsExplored( i + 1, j ) ) { v |= 2; u |= 6; } - if( !IsExplored( i, j + 1 ) ) { v |= 4; u |= 12; } - if( !IsExplored( i - 1, j ) ) { v |= 8; u |= 9; } + if( !shroud.IsExplored( i, j - 1 ) ) { v |= 1; u |= 3; } + if( !shroud.IsExplored( i + 1, j ) ) { v |= 2; u |= 6; } + if( !shroud.IsExplored( i, j + 1 ) ) { v |= 4; u |= 12; } + if( !shroud.IsExplored( i - 1, j ) ) { v |= 8; u |= 9; } var uSides = u; - if( !IsExplored( i - 1, j - 1 ) ) u |= 1; - if( !IsExplored( i + 1, j - 1 ) ) u |= 2; - if( !IsExplored( i + 1, j + 1 ) ) u |= 4; - if( !IsExplored( i - 1, j + 1 ) ) u |= 8; + if( !shroud.IsExplored( i - 1, j - 1 ) ) u |= 1; + if( !shroud.IsExplored( i + 1, j - 1 ) ) u |= 2; + if( !shroud.IsExplored( i + 1, j + 1 ) ) u |= 4; + if( !shroud.IsExplored( i - 1, j + 1 ) ) u |= 8; return shadowBits[ SpecialShroudTiles[ u ^ uSides ][ v ] ]; } Sprite ChooseFog(int i, int j) { - if (!IsVisible(i,j)) return shadowBits[0xf]; - if (!IsExplored(i, j)) return shadowBits[0xf]; + if (!shroud.IsVisible(i,j)) return shadowBits[0xf]; + if (!shroud.IsExplored(i, j)) return shadowBits[0xf]; // bits are for unexploredness: up, right, down, left var v = 0; // bits are for unexploredness: TL, TR, BR, BL var u = 0; - if (!IsVisible(i, j - 1)) { v |= 1; u |= 3; } - if (!IsVisible(i + 1, j)) { v |= 2; u |= 6; } - if (!IsVisible(i, j + 1)) { v |= 4; u |= 12; } - if (!IsVisible(i - 1, j)) { v |= 8; u |= 9; } + if (!shroud.IsVisible(i, j - 1)) { v |= 1; u |= 3; } + if (!shroud.IsVisible(i + 1, j)) { v |= 2; u |= 6; } + if (!shroud.IsVisible(i, j + 1)) { v |= 4; u |= 12; } + if (!shroud.IsVisible(i - 1, j)) { v |= 8; u |= 9; } var uSides = u; - if (!IsVisible(i - 1, j - 1)) u |= 1; - if (!IsVisible(i + 1, j - 1)) u |= 2; - if (!IsVisible(i + 1, j + 1)) u |= 4; - if (!IsVisible(i - 1, j + 1)) u |= 8; + if (!shroud.IsVisible(i - 1, j - 1)) u |= 1; + if (!shroud.IsVisible(i + 1, j - 1)) u |= 2; + if (!shroud.IsVisible(i + 1, j + 1)) u |= 4; + if (!shroud.IsVisible(i - 1, j + 1)) u |= 8; return shadowBits[SpecialShroudTiles[u ^ uSides][v]]; } diff --git a/OpenRA.Game/Traits/Player/DeveloperMode.cs b/OpenRA.Game/Traits/Player/DeveloperMode.cs index 90dcb10825..27f6f08cf0 100644 --- a/OpenRA.Game/Traits/Player/DeveloperMode.cs +++ b/OpenRA.Game/Traits/Player/DeveloperMode.cs @@ -77,7 +77,7 @@ namespace OpenRA.Traits { DisableShroud ^= true; if (self.World.LocalPlayer == self.Owner) - self.World.LocalPlayer.Shroud.Disabled = DisableShroud; + self.World.LocalShroud.Disabled = DisableShroud; break; } case "DevPathDebug": diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 742fb3454e..1f7c1f0e4a 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -73,7 +73,7 @@ namespace OpenRA.Traits Color RadarSignatureColor(Actor self); } - public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } + public interface IVisibilityModifier { bool IsVisible(Actor self); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } public interface IHasLocation { diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 657ca69a07..95e829abb9 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -38,15 +38,11 @@ namespace OpenRA.Traits foreach( var rt in world.WorldActor.TraitsImplementing() ) rt.info.PaletteIndex = wr.GetPaletteIndex(rt.info.Palette); - Shroud shroud = null; - if( world.LocalPlayer != null ) - shroud = world.LocalPlayer.Shroud; - for (int x = minx; x < maxx; x++) for (int y = miny; y < maxy; y++) { - if (shroud != null && !shroud.IsExplored(new int2(x, y))) - continue; + if (!world.LocalShroud.IsExplored(new int2(x, y))) + continue; var c = content[x, y]; if (c.image != null) diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 65cd1e07cf..689d0710f5 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -213,6 +213,14 @@ namespace OpenRA.Traits return visibleCells[x,y] != 0; } - + + // Actors are hidden under shroud, but not under fog by default + public bool IsVisible(Actor a) + { + if (a.TraitsImplementing().Any(t => !t.IsVisible(a))) + return false; + + return disabled || a.Owner == a.World.LocalPlayer || GetVisOrigins(a).Any(o => IsExplored(o)); + } } } diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 9b87cd17d6..9ea9ab052e 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -149,7 +149,7 @@ namespace OpenRA.Widgets IEnumerable SelectActorsInBox(World world, float2 a, float2 b) { return world.FindUnits(a, b) - .Where( x => x.HasTrait() && x.IsVisible(world.LocalPlayer) ) + .Where( x => x.HasTrait() && world.LocalShroud.IsVisible(x) ) .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) .OrderByDescending(g => g.Key) .Select( g => g.AsEnumerable() ) diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 5209b36f67..581d4e1fa2 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -44,6 +44,7 @@ namespace OpenRA { get { return players.ContainsKey(localPlayerIndex) ? players[localPlayerIndex] : null; } } + public readonly Shroud LocalShroud; public void SetLocalPlayer(int index) { @@ -51,7 +52,6 @@ namespace OpenRA } public readonly Actor WorldActor; - public readonly Map Map; public readonly TileSet TileSet; @@ -98,6 +98,8 @@ namespace OpenRA SharedRandom = new XRandom(orderManager.LobbyInfo.GlobalSettings.RandomSeed); WorldActor = CreateActor( "World", new TypeDictionary() ); + LocalShroud = WorldActor.Trait(); + Queries = new AllQueries(this); // Add players diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index b3747912c7..2e6564cacf 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -24,7 +24,7 @@ namespace OpenRA public static IEnumerable FindUnitsAtMouse(this World world, int2 mouseLocation) { var loc = mouseLocation + Game.viewport.Location; - return FindUnits(world, loc, loc).Where(a => a.IsVisible(world.LocalPlayer)); + return FindUnits(world, loc, loc).Where(a => world.LocalShroud.IsVisible(a)); } public static IEnumerable FindUnits(this World world, float2 a, float2 b) @@ -72,22 +72,6 @@ namespace OpenRA return world.TileSet.Terrain[world.GetTerrainType(cell)]; } - public static bool IsVisible(this Actor a, Player byPlayer) /* must never be relied on in synced code! */ - { - if (byPlayer == null) return true; // Observer - if (a.World.LocalPlayer != null && a.World.LocalPlayer.Shroud.Disabled) - return true; - - var shroud = a.World.WorldActor.Trait(); - if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud - return false; - - if (a.TraitsImplementing().Any(t => !t.IsVisible(a, byPlayer))) - return false; - - return true; - } - public static int2 ClampToWorld( this World world, int2 xy ) { return xy.Clamp(world.Map.Bounds); diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index e37e5002a4..86d3200acf 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -214,7 +214,6 @@ namespace OpenRA.Mods.RA return inRange .Where(a => a.Owner != null && self.Owner.Stances[a.Owner] == Stance.Enemy) .Where(a => HasAnyValidWeapons(Target.FromActor(a))) - .Where(a => !a.HasTrait() || a.Trait().IsVisible(a, self.Owner)) .OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared) .FirstOrDefault(); } diff --git a/OpenRA.Mods.RA/Buildings/BibLayer.cs b/OpenRA.Mods.RA/Buildings/BibLayer.cs index 1c16ac52cd..3fce473f61 100755 --- a/OpenRA.Mods.RA/Buildings/BibLayer.cs +++ b/OpenRA.Mods.RA/Buildings/BibLayer.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Buildings { if (!cliprect.Contains(kv.Key.X, kv.Key.Y)) continue; - if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(kv.Key)) + if (!world.LocalShroud.IsExplored(kv.Key)) continue; bibSprites[kv.Value.type - 1][kv.Value.image].DrawAt( wr, diff --git a/OpenRA.Mods.RA/Chronoshiftable.cs b/OpenRA.Mods.RA/Chronoshiftable.cs index bcb306bf33..7883d98f8c 100755 --- a/OpenRA.Mods.RA/Chronoshiftable.cs +++ b/OpenRA.Mods.RA/Chronoshiftable.cs @@ -40,12 +40,13 @@ namespace OpenRA.Mods.RA } } + // Can't be used in synced code public virtual bool CanChronoshiftTo(Actor self, int2 targetLocation) { // Todo: Allow enemy units to be chronoshifted into bad terrain to kill them return self.HasTrait() && self.Trait().CanEnterCell(targetLocation) && - (self.World.LocalPlayer == null || self.World.LocalPlayer.Shroud.IsExplored(targetLocation)); + (self.World.LocalShroud.IsExplored(targetLocation)); } public virtual bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere) diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index 713689c969..d1be3a0f53 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA if (remainingTime > 0) return rs; - if (Cloaked && IsVisible(self, self.World.LocalPlayer)) + if (Cloaked && IsVisible(self)) return rs.Select(a => a.WithPalette("shadow")); else return new Renderable[] { }; @@ -101,14 +101,6 @@ namespace OpenRA.Mods.RA public bool Cloaked { get { return remainingTime == 0; } } - public bool IsVisible(Actor self, Player byPlayer) - { - if (!Cloaked || self.Owner.Stances[byPlayer] == Stance.Ally) - return true; - - return self.World.Queries.WithTrait().Any(a => a.Actor.Owner == byPlayer && (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get().Range); - } - public bool IsVisible(Actor self) { return !Cloaked || self.Owner == self.World.LocalPlayer; diff --git a/OpenRA.Mods.RA/ConquestVictoryConditions.cs b/OpenRA.Mods.RA/ConquestVictoryConditions.cs index 839c6ef767..d9c0f13654 100644 --- a/OpenRA.Mods.RA/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.RA/ConquestVictoryConditions.cs @@ -49,8 +49,8 @@ namespace OpenRA.Mods.RA foreach (var a in self.World.Queries.OwnedBy[self.Owner]) a.Kill(a); - self.Owner.Shroud.Disabled = true; - + if (self.Owner == self.World.LocalPlayer) + self.World.LocalShroud.Disabled = true; } public void Win(Actor self) @@ -59,7 +59,8 @@ namespace OpenRA.Mods.RA self.Owner.WinState = WinState.Won; Game.Debug("{0} is victorious.".F(self.Owner.PlayerName)); - self.Owner.Shroud.Disabled = true; + if (self.Owner == self.World.LocalPlayer) + self.World.LocalShroud.Disabled = true; } } diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs index 05fe4297c4..07cd43638f 100755 --- a/OpenRA.Mods.RA/Effects/Contrail.cs +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -73,19 +73,13 @@ namespace OpenRA.Mods.RA Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B); - // LocalPlayer is null on shellmap - Shroud shroud = null; - if (self.World.LocalPlayer != null) - shroud = self.World.LocalPlayer.Shroud; - for (int i = positions.Count - 1; i >= 1; --i) { var conPos = positions[i]; var nextPos = positions[i - 1]; - if (shroud == null || - shroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) || - shroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos))) + if (self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) || + self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos))) { Game.Renderer.LineRenderer.DrawLine(conPos, nextPos, trailStart, trailEnd); diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 8c7e0a8371..ae2aef910a 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -209,7 +209,7 @@ namespace OpenRA.Mods.RA public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor) { // Don't leak info about resources under the shroud - if (!self.World.LocalPlayer.Shroud.IsExplored(location)) return false; + if (!self.World.LocalShroud.IsExplored(location)) return false; var res = self.World.WorldActor.Trait().GetResource( location ); var info = self.Info.Traits.Get(); diff --git a/OpenRA.Mods.RA/InvisibleToOthers.cs b/OpenRA.Mods.RA/InvisibleToOthers.cs index b1ccf2273a..40fd4e7798 100644 --- a/OpenRA.Mods.RA/InvisibleToOthers.cs +++ b/OpenRA.Mods.RA/InvisibleToOthers.cs @@ -18,9 +18,9 @@ namespace OpenRA.Mods.RA class InvisibleToOthers : IRenderModifier, IVisibilityModifier, IRadarColorModifier { - public bool IsVisible(Actor self, Player byPlayer) + public bool IsVisible(Actor self) { - return self.Owner == byPlayer; + return self.World.LocalPlayer == null || self.Owner == self.World.LocalPlayer; } public Color RadarColorOverride(Actor self) diff --git a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs index 026eee64da..b962cf6fe7 100644 --- a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs @@ -14,34 +14,15 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class FrozenUnderFogInfo : ITraitInfo + class FrozenUnderFogInfo : TraitInfo {} + + class FrozenUnderFog : IRenderModifier { - public object Create(ActorInitializer init) { return new FrozenUnderFog(init.self); } - } - - class FrozenUnderFog : IRenderModifier, IVisibilityModifier - { - Shroud shroud; - Renderable[] cache = { }; - - public FrozenUnderFog(Actor self) - { - shroud = self.World.WorldActor.Trait(); - } - - public bool IsVisible(Actor self, Player byPlayer) - { - return self.World.LocalPlayer == null - || self.Owner == byPlayer - || self.World.LocalPlayer.Shroud.Disabled - || Shroud.GetVisOrigins(self).Any(o => self.World.Map.IsInMap(o) && shroud.visibleCells[o.X, o.Y] != 0); - } - + Renderable[] cache = { }; public IEnumerable ModifyRender(Actor self, IEnumerable r) { - if (IsVisible(self, self.World.LocalPlayer)) + if (self.World.LocalShroud.IsVisible(self)) cache = r.ToArray(); - return cache; } } diff --git a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs index f43751d565..7d620b8316 100644 --- a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs @@ -9,36 +9,24 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.RA { - class HiddenUnderFogInfo : ITraitInfo - { - public object Create(ActorInitializer init) { return new HiddenUnderFog(init.self); } - } + class HiddenUnderFogInfo : TraitInfo {} class HiddenUnderFog : IRenderModifier, IVisibilityModifier { - Shroud shroud; - - public HiddenUnderFog(Actor self) + public bool IsVisible(Actor self) { - shroud = self.World.WorldActor.Trait(); - } - - public bool IsVisible(Actor self, Player byPlayer) - { - return self.World.LocalPlayer == null - || self.Owner == byPlayer - || self.World.LocalPlayer.Shroud.Disabled - || shroud.visibleCells[self.Location.X, self.Location.Y] > 0; + return Shroud.GetVisOrigins(self).Any(o => self.World.LocalShroud.IsVisible(o)); } static Renderable[] Nothing = { }; public IEnumerable ModifyRender(Actor self, IEnumerable r) { - return IsVisible(self, self.World.LocalPlayer) ? r : Nothing; + return IsVisible(self) ? r : Nothing; } } } diff --git a/OpenRA.Mods.RA/TargetableCloaked.cs b/OpenRA.Mods.RA/TargetableCloaked.cs index bfea0e8040..6bc162c62a 100644 --- a/OpenRA.Mods.RA/TargetableCloaked.cs +++ b/OpenRA.Mods.RA/TargetableCloaked.cs @@ -7,7 +7,8 @@ * see LICENSE. */ #endregion - + +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -32,5 +33,14 @@ namespace OpenRA.Mods.RA get { return (Cloak.Cloaked) ? info.CloakedTargetTypes : info.TargetTypes;} } + + // Todo: Finish me + public bool TargetableBy(Actor self, Actor byActor) + { + if (!Cloak.Cloaked || self.Owner == byActor.Owner || self.Owner.Stances[byActor.Owner] == Stance.Ally) + return true; + + return self.World.Queries.WithTrait().Any(a => (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get().Range); + } } } diff --git a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs b/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs index d25f428eb6..d3e1d1f168 100755 --- a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Widgets } var actor = world.FindUnitsAtMouse(Viewport.LastMousePos).FirstOrDefault(); - if (actor == null || !actor.IsVisible(world.LocalPlayer)) + if (actor == null) return; var text = actor.Info.Traits.Contains()