diff --git a/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs b/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs index d49d7e7fc6..9863b68b79 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BaseProvider.cs @@ -27,12 +27,14 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new BaseProvider(init.Self, this); } } - public class BaseProvider : ITick, IRenderAboveShroudWhenSelected, ISelectionBar + public class BaseProvider : ITick, INotifyCreated, IRenderAboveShroudWhenSelected, ISelectionBar { public readonly BaseProviderInfo Info; readonly DeveloperMode devMode; readonly Actor self; + Building building; + int total; int progress; bool allyBuildEnabled; @@ -46,6 +48,11 @@ namespace OpenRA.Mods.Common.Traits allyBuildEnabled = self.World.WorldActor.Trait().AllyBuildRadiusEnabled; } + void INotifyCreated.Created(Actor self) + { + building = self.TraitOrDefault(); + } + void ITick.Tick(Actor self) { if (progress > 0) @@ -59,6 +66,9 @@ namespace OpenRA.Mods.Common.Traits public bool Ready() { + if (building != null && building.Locked) + return false; + return devMode.FastBuild || progress == 0; } diff --git a/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs index c0ad9f5904..5cb752e90a 100644 --- a/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ClassicProductionQueue.cs @@ -55,9 +55,6 @@ namespace OpenRA.Mods.Common.Traits { if (x.Actor.Owner == self.Owner && x.Trait.Info.Produces.Contains(Info.Type)) { - var b = x.Actor.TraitOrDefault(); - if (b != null && b.Locked) - continue; isActive = true; break; } diff --git a/OpenRA.Mods.Common/Traits/Production.cs b/OpenRA.Mods.Common/Traits/Production.cs index 459e9c6cb0..2681f8d816 100644 --- a/OpenRA.Mods.Common/Traits/Production.cs +++ b/OpenRA.Mods.Common/Traits/Production.cs @@ -28,13 +28,15 @@ namespace OpenRA.Mods.Common.Traits public virtual object Create(ActorInitializer init) { return new Production(init, this); } } - public class Production + public class Production : INotifyCreated { readonly Lazy rp; public readonly ProductionInfo Info; public string Faction { get; private set; } + Building building; + public Production(ActorInitializer init, ProductionInfo info) { Info = info; @@ -42,6 +44,11 @@ namespace OpenRA.Mods.Common.Traits Faction = init.Contains() ? init.Get() : init.Self.Owner.Faction.InternalName; } + void INotifyCreated.Created(Actor self) + { + building = self.TraitOrDefault(); + } + public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant) { var exit = CPos.Zero; @@ -122,7 +129,7 @@ namespace OpenRA.Mods.Common.Traits public virtual bool Produce(Actor self, ActorInfo producee, string factionVariant) { - if (Reservable.IsReserved(self)) + if (Reservable.IsReserved(self) || (building != null && building.Locked)) return false; // Pick a spawn/exit point pair diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs index 473acc789c..1440f12236 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits.Render public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.Self, this); } } - public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete + public class WithBuildingPlacedAnimation : INotifyBuildingPlaced, INotifyBuildComplete, INotifySold, INotifyTransform { readonly WithBuildingPlacedAnimationInfo info; readonly WithSpriteBody wsb; @@ -35,12 +35,26 @@ namespace OpenRA.Mods.Common.Traits.Render buildComplete = !self.Info.HasTraitInfo(); } - public void BuildingComplete(Actor self) + void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; } - public void BuildingPlaced(Actor self) + void INotifySold.Sold(Actor self) { } + void INotifySold.Selling(Actor self) + { + buildComplete = false; + } + + void INotifyTransform.BeforeTransform(Actor self) + { + buildComplete = false; + } + + void INotifyTransform.OnTransform(Actor self) { } + void INotifyTransform.AfterTransform(Actor self) { } + + void INotifyBuildingPlaced.BuildingPlaced(Actor self) { if (buildComplete) wsb.PlayCustomAnimation(self, info.Sequence, () => wsb.CancelCustomAnimation(self)); diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs index a2c45a6735..63119f436f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedOverlay.cs @@ -55,32 +55,32 @@ namespace OpenRA.Mods.Common.Traits.Render rs.Add(anim, info.Palette, info.IsPlayerPalette); } - public void BuildingComplete(Actor self) + void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; visible = false; } - public void Sold(Actor self) { } - public void Selling(Actor self) + void INotifySold.Sold(Actor self) { } + void INotifySold.Selling(Actor self) { buildComplete = false; } - public void BeforeTransform(Actor self) + void INotifyTransform.BeforeTransform(Actor self) { buildComplete = false; } - public void OnTransform(Actor self) { } - public void AfterTransform(Actor self) { } + void INotifyTransform.OnTransform(Actor self) { } + void INotifyTransform.AfterTransform(Actor self) { } - public void DamageStateChanged(Actor self, AttackInfo e) + void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e) { overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name)); } - public void BuildingPlaced(Actor self) + void INotifyBuildingPlaced.BuildingPlaced(Actor self) { visible = true; overlay.PlayThen(overlay.CurrentSequence.Name, () => visible = false);