diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index cbfc695c81..aeece72891 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -54,8 +54,8 @@ namespace OpenRA.Traits // Cache of visibility that was added, so no matter what crazy trait code does, it // can't make us invalid. - readonly Dictionary visibility = new Dictionary(); - readonly Dictionary generation = new Dictionary(); + readonly Dictionary visibility = new Dictionary(); + readonly Dictionary generation = new Dictionary(); [Sync] bool disabled; public bool Disabled @@ -135,11 +135,8 @@ namespace OpenRA.Traits return ProjectedCellsInRange(map, map.CenterOfCell(cell), range); } - public void AddProjectedVisibility(Actor a, PPos[] visible) + public void AddProjectedVisibility(object key, PPos[] visible) { - if (!a.Owner.IsAlliedWith(self.Owner)) - return; - foreach (var puv in visible) { // Force cells outside the visible bounds invisible @@ -151,17 +148,17 @@ namespace OpenRA.Traits explored[uv] = true; } - if (visibility.ContainsKey(a)) + if (visibility.ContainsKey(key)) throw new InvalidOperationException("Attempting to add duplicate actor visibility"); - visibility[a] = visible; + visibility[key] = visible; Invalidate(visible); } - public void RemoveVisibility(Actor a) + public void RemoveVisibility(object key) { PPos[] visible; - if (!visibility.TryGetValue(a, out visible)) + if (!visibility.TryGetValue(key, out visible)) return; foreach (var puv in visible) @@ -171,64 +168,35 @@ namespace OpenRA.Traits visibleCount[(MPos)puv]--; } - visibility.Remove(a); + visibility.Remove(key); Invalidate(visible); } - public void AddProjectedShroudGeneration(Actor a, PPos[] shrouded) + public void AddProjectedShroudGeneration(object key, PPos[] shrouded) { - if (a.Owner.IsAlliedWith(self.Owner)) - return; - foreach (var uv in shrouded) generatedShroudCount[(MPos)uv]++; - if (generation.ContainsKey(a)) + if (generation.ContainsKey(key)) throw new InvalidOperationException("Attempting to add duplicate shroud generation"); - generation[a] = shrouded; + generation[key] = shrouded; Invalidate(shrouded); } - public void RemoveShroudGeneration(Actor a) + public void RemoveShroudGeneration(object key) { PPos[] shrouded; - if (!generation.TryGetValue(a, out shrouded)) + if (!generation.TryGetValue(key, out shrouded)) return; foreach (var uv in shrouded) generatedShroudCount[(MPos)uv]--; - generation.Remove(a); + generation.Remove(key); Invalidate(shrouded); } - public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance) - { - if (oldStance == newStance) - return; - - foreach (var a in w.Actors.Where(a => a.Owner == player)) - { - PPos[] visible = null; - PPos[] shrouded = null; - foreach (var p in self.World.Players) - { - if (p.Shroud.visibility.TryGetValue(self, out visible)) - { - p.Shroud.RemoveVisibility(self); - p.Shroud.AddProjectedVisibility(self, visible); - } - - if (p.Shroud.generation.TryGetValue(self, out shrouded)) - { - p.Shroud.RemoveShroudGeneration(self); - p.Shroud.AddProjectedShroudGeneration(self, shrouded); - } - } - } - } - public void ExploreProjectedCells(World world, IEnumerable cells) { var changed = new HashSet(); diff --git a/OpenRA.Mods.Common/Traits/CreatesShroud.cs b/OpenRA.Mods.Common/Traits/CreatesShroud.cs index 4ff16dcb37..eb291a0243 100644 --- a/OpenRA.Mods.Common/Traits/CreatesShroud.cs +++ b/OpenRA.Mods.Common/Traits/CreatesShroud.cs @@ -20,8 +20,15 @@ namespace OpenRA.Mods.Common.Traits { public CreatesShroud(Actor self, CreatesShroudInfo info) : base(self, info) { } - protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) { p.Shroud.AddProjectedShroudGeneration(self, uv); } - protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveShroudGeneration(self); } + + protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) + { + if (!self.Owner.IsAlliedWith(p)) + p.Shroud.AddProjectedShroudGeneration(this, uv); + } + + protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveShroudGeneration(this); } + protected override bool IsDisabled(Actor self) { return self.IsDisabled(); } } } \ No newline at end of file diff --git a/OpenRA.Mods.Common/Traits/RevealsShroud.cs b/OpenRA.Mods.Common/Traits/RevealsShroud.cs index 654650cd19..4d904dbe03 100644 --- a/OpenRA.Mods.Common/Traits/RevealsShroud.cs +++ b/OpenRA.Mods.Common/Traits/RevealsShroud.cs @@ -20,7 +20,13 @@ namespace OpenRA.Mods.Common.Traits { public RevealsShroud(Actor self, RevealsShroudInfo info) : base(self, info) { } - protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) { p.Shroud.AddProjectedVisibility(self, uv); } - protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveVisibility(self); } + + protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) + { + if (self.Owner.IsAlliedWith(p)) + p.Shroud.AddProjectedVisibility(this, uv); + } + + protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveVisibility(this); } } }