From 774f2e08524f3c6a160a0e70ad5b27f433fe04d2 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 24 Oct 2020 12:19:42 +0200 Subject: [PATCH] Fix Production.cs not properly using INotifyCreated --- OpenRA.Mods.Common/Traits/Production.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Production.cs b/OpenRA.Mods.Common/Traits/Production.cs index dff46206a9..84a79083ce 100644 --- a/OpenRA.Mods.Common/Traits/Production.cs +++ b/OpenRA.Mods.Common/Traits/Production.cs @@ -27,19 +27,24 @@ namespace OpenRA.Mods.Common.Traits public override object Create(ActorInitializer init) { return new Production(init, this); } } - public class Production : PausableConditionalTrait, INotifyCreated + public class Production : PausableConditionalTrait { - readonly Lazy rp; + RallyPoint rp; public string Faction { get; private set; } public Production(ActorInitializer init, ProductionInfo info) : base(info) { - rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault()); Faction = init.GetValue(init.Self.Owner.Faction.InternalName); } + protected override void Created(Actor self) + { + rp = self.TraitOrDefault(); + base.Created(self); + } + public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits) { var exit = CPos.Zero; @@ -71,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits else initialFacing = exitinfo.Facing.Value; - exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List { exit }; + exitLocations = rp != null && rp.Path.Count > 0 ? rp.Path : new List { exit }; td.Add(new LocationInit(exit)); td.Add(new CenterPositionInit(spawn)); @@ -101,10 +106,10 @@ namespace OpenRA.Mods.Common.Traits protected virtual Exit SelectExit(Actor self, ActorInfo producee, string productionType, Func p) { - if (!rp.IsValueCreated || rp.Value.Path.Count == 0) + if (rp == null || rp.Path.Count == 0) return self.RandomExitOrDefault(self.World, productionType, p); - return self.NearestExitOrDefault(self.World.Map.CenterOfCell(rp.Value.Path[0]), productionType, p); + return self.NearestExitOrDefault(self.World.Map.CenterOfCell(rp.Path[0]), productionType, p); } protected Exit SelectExit(Actor self, ActorInfo producee, string productionType)