From 1518da1062a63f59b74a85b738295fd287fefa15 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 5 Feb 2017 11:33:52 +0000 Subject: [PATCH] Fix KillSelf behaviour for out-of-world actors. --- OpenRA.Mods.Common/Traits/KillsSelf.cs | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/KillsSelf.cs b/OpenRA.Mods.Common/Traits/KillsSelf.cs index 7714115366..79f2f562a4 100644 --- a/OpenRA.Mods.Common/Traits/KillsSelf.cs +++ b/OpenRA.Mods.Common/Traits/KillsSelf.cs @@ -34,18 +34,35 @@ namespace OpenRA.Mods.Common.Traits lifetime = Util.RandomDelay(self.World, info.Delay); } - public void AddedToWorld(Actor self) + protected override void TraitEnabled(Actor self) + { + // Actors can be created without being added to the world + // We want to make sure that this only triggers once they are inserted into the world + if (lifetime == 0 && self.IsInWorld) + Kill(self); + } + + void INotifyAddedToWorld.AddedToWorld(Actor self) { if (!IsTraitDisabled) TraitEnabled(self); } - protected override void TraitEnabled(Actor self) + void ITick.Tick(Actor self) { - if (self.IsDead) + if (!self.IsInWorld || self.IsDead || IsTraitDisabled) return; - if (lifetime > 0) + if (!self.World.Map.Contains(self.Location)) + return; + + if (lifetime-- <= 0) + Kill(self); + } + + void Kill(Actor self) + { + if (self.IsDead) return; if (Info.RemoveInstead || !self.Info.HasTraitInfo()) @@ -53,22 +70,5 @@ namespace OpenRA.Mods.Common.Traits else self.Kill(self); } - - void ITick.Tick(Actor self) - { - if (self.IsDead || IsTraitDisabled) - return; - - if (!self.World.Map.Contains(self.Location)) - return; - - if (lifetime-- == 0) - { - if (Info.RemoveInstead || !self.Info.HasTraitInfo()) - self.Dispose(); - else - self.Kill(self); - } - } } }