From 227b80d6c2336e686c0f82d6bd15533dcd3d7f7c Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 27 Mar 2017 18:14:24 +0100 Subject: [PATCH] Add support for removing segments when parent nodes are removed. --- .../Traits/Buildings/LineBuild.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index a66fed98d5..ee52a2dbd1 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -51,16 +51,21 @@ namespace OpenRA.Mods.Common.Traits [Desc("Actor type for line-built segments (defaults to same actor).")] public readonly string SegmentType = null; + [Desc("Delete generated segments when destroyed or sold.")] + public readonly bool SegmentsRequireNode = false; + public object Create(ActorInitializer init) { return new LineBuild(init, this); } } - public class LineBuild : INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyLineBuildSegmentsChanged + public class LineBuild : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyLineBuildSegmentsChanged { + readonly LineBuildInfo info; readonly Actor[] parentNodes = new Actor[0]; HashSet segments; public LineBuild(ActorInitializer init, LineBuildInfo info) { + this.info = info; if (init.Contains()) parentNodes = init.Get().Value(init.World); } @@ -95,6 +100,17 @@ namespace OpenRA.Mods.Common.Traits if (!parent.Disposed) foreach (var n in parent.TraitsImplementing()) n.SegmentRemoved(parent, self); + + if (info.SegmentsRequireNode && segments != null) + foreach (var s in segments) + s.Dispose(); + } + + void INotifyKilled.Killed(Actor self, AttackInfo e) + { + if (info.SegmentsRequireNode && segments != null) + foreach (var s in segments) + s.Kill(e.Attacker); } } }