From 68b4856a4382f3f2a07cccc975a9470523801e64 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Tue, 20 Feb 2018 20:56:06 +0300 Subject: [PATCH] Fix the issue with capturing a driver killed CV. --- .../Traits/Player/ProductionQueue.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index 6290ecd4a983..31868f477c22 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -101,6 +101,9 @@ public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement, INotifyOw public string Faction { get; private set; } [Sync] public bool IsValidFaction { get; private set; } + bool anyEnabledProduction = false; + bool anyUnpausedProduction = false; + public ProductionQueue(ActorInitializer init, Actor playerActor, ProductionQueueInfo info) { self = init.Self; @@ -252,16 +255,30 @@ void ITick.Tick(Actor self) protected virtual void Tick(Actor self) { // PERF: Avoid LINQ when checking whether all production traits are disabled/paused - var anyEnabledProduction = false; - var anyUnpausedProduction = false; + var wasDisabled = !anyEnabledProduction; + + anyEnabledProduction = false; + anyUnpausedProduction = false; foreach (var p in productionTraits) { anyEnabledProduction |= !p.IsTraitDisabled; anyUnpausedProduction |= !p.IsTraitPaused; } + if (wasDisabled && anyEnabledProduction) + { + self.World.AddFrameEndTask(_ => + { + self.Owner.PlayerActor.Trait().Update(); + CacheProducibles(self.Owner.PlayerActor); + }); + } + if (!anyEnabledProduction) + { + self.Owner.PlayerActor.Trait().Remove(this); ClearQueue(); + } Enabled = IsValidFaction && anyEnabledProduction;