From 983d8ac39ea23d8deb4b29ca7bd691b20722701e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 25 Oct 2016 20:30:39 +0100 Subject: [PATCH] Add passive visibility type. --- OpenRA.Game/Traits/World/Shroud.cs | 23 +++++++++++++++++++--- OpenRA.Mods.Common/Traits/RevealsShroud.cs | 13 ++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 87d71f7931..e79b717cf6 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -40,7 +40,7 @@ namespace OpenRA.Traits public class Shroud : ISync, INotifyCreated { - public enum SourceType : byte { Shroud, Visibility } + public enum SourceType : byte { PassiveVisibility, Shroud, Visibility } public event Action> CellsChanged; enum ShroudCellType : byte { Shroud, Fog, Visible } @@ -64,6 +64,7 @@ namespace OpenRA.Traits readonly Dictionary sources = new Dictionary(); // Per-cell count of each source type, used to resolve the final cell type + readonly CellLayer passiveVisibleCount; readonly CellLayer visibleCount; readonly CellLayer generatedShroudCount; readonly CellLayer explored; @@ -97,6 +98,7 @@ namespace OpenRA.Traits // Enabled at runtime on first use bool shroudGenerationEnabled; + bool passiveVisibilityEnabled; public Shroud(Actor self, ShroudInfo info) { @@ -104,6 +106,7 @@ namespace OpenRA.Traits this.info = info; map = self.World.Map; + passiveVisibleCount = new CellLayer(map); visibleCount = new CellLayer(map); generatedShroudCount = new CellLayer(map); explored = new CellLayer(map); @@ -130,7 +133,13 @@ namespace OpenRA.Traits var type = ShroudCellType.Shroud; if (explored[uv] && (!shroudGenerationEnabled || generatedShroudCount[uv] == 0 || visibleCount[uv] > 0)) - type = visibleCount[uv] > 0 ? ShroudCellType.Visible: ShroudCellType.Fog; + { + var count = visibleCount[uv]; + if (passiveVisibilityEnabled) + count += passiveVisibleCount[uv]; + + type = count > 0 ? ShroudCellType.Visible : ShroudCellType.Fog; + } resolvedType[uv] = type; } @@ -182,6 +191,11 @@ namespace OpenRA.Traits var uv = (MPos)puv; switch (type) { + case SourceType.PassiveVisibility: + passiveVisibilityEnabled = true; + passiveVisibleCount[uv]++; + explored[uv] = true; + break; case SourceType.Visibility: visibleCount[uv]++; explored[uv] = true; @@ -210,6 +224,9 @@ namespace OpenRA.Traits var uv = (MPos)puv; switch (state.Type) { + case SourceType.PassiveVisibility: + passiveVisibleCount[uv]--; + break; case SourceType.Visibility: visibleCount[uv]--; break; @@ -281,7 +298,7 @@ namespace OpenRA.Traits foreach (var puv in map.ProjectedCellBounds) { var uv = (MPos)puv; - var visible = visibleCount[uv] > 0; + var visible = visibleCount[uv] + passiveVisibleCount[uv] > 0; if (explored[uv] != visible) { explored[uv] = visible; diff --git a/OpenRA.Mods.Common/Traits/RevealsShroud.cs b/OpenRA.Mods.Common/Traits/RevealsShroud.cs index 05c487d87d..1c66e6a8c5 100644 --- a/OpenRA.Mods.Common/Traits/RevealsShroud.cs +++ b/OpenRA.Mods.Common/Traits/RevealsShroud.cs @@ -18,22 +18,31 @@ namespace OpenRA.Mods.Common.Traits [Desc("Stance the watching player needs to see the shroud removed.")] public readonly Stance ValidStances = Stance.Ally; + [Desc("Can this actor reveal shroud generated by the GeneratesShroud trait?")] + public readonly bool RevealGeneratedShroud = true; + public override object Create(ActorInitializer init) { return new RevealsShroud(init.Self, this); } } public class RevealsShroud : AffectsShroud { readonly RevealsShroudInfo info; + readonly Shroud.SourceType type; public RevealsShroud(Actor self, RevealsShroudInfo info) - : base(self, info) { this.info = info; } + : base(self, info) + { + this.info = info; + type = info.RevealGeneratedShroud ? Shroud.SourceType.Visibility + : Shroud.SourceType.PassiveVisibility; + } protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) { if (!info.ValidStances.HasStance(p.Stances[self.Owner])) return; - p.Shroud.AddSource(this, Shroud.SourceType.Visibility, uv); + p.Shroud.AddSource(this, type, uv); } protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveSource(this); }