From fe4fd8cab07d1e71a81357af68b6d3e950eb89df Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 10 Apr 2011 11:03:42 +1200 Subject: [PATCH] Use MakeAnimation for selling; Support selling non-buildings --- .../{Buildings => Activities}/Sell.cs | 52 +++---------------- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 4 +- OpenRA.Mods.RA/{Buildings => }/Sellable.cs | 10 +++- 3 files changed, 19 insertions(+), 47 deletions(-) rename OpenRA.Mods.RA/{Buildings => Activities}/Sell.cs (58%) rename OpenRA.Mods.RA/{Buildings => }/Sellable.cs (68%) diff --git a/OpenRA.Mods.RA/Buildings/Sell.cs b/OpenRA.Mods.RA/Activities/Sell.cs similarity index 58% rename from OpenRA.Mods.RA/Buildings/Sell.cs rename to OpenRA.Mods.RA/Activities/Sell.cs index b114da5224..ca1ffe1f87 100755 --- a/OpenRA.Mods.RA/Buildings/Sell.cs +++ b/OpenRA.Mods.RA/Activities/Sell.cs @@ -11,18 +11,14 @@ using System.Collections.Generic; using OpenRA.Traits; using OpenRA.Mods.RA.Effects; - -namespace OpenRA.Mods.RA.Buildings +using OpenRA.Traits.Activities; +using OpenRA.Mods.RA.Buildings; + +namespace OpenRA.Mods.RA.Activities { - class Sell : IActivity + class Sell : CancelableActivity { - IActivity NextActivity { get; set; } - - bool started; - - int framesRemaining; - - void DoSell(Actor self) + public override IActivity Tick(Actor self) { var h = self.TraitOrDefault(); var si = self.Info.Traits.Get(); @@ -41,42 +37,10 @@ namespace OpenRA.Mods.RA.Buildings self.World.AddFrameEndTask(w => w.Add(new CashTick(refund, 30, 2, self.CenterLocation, self.Owner.ColorRamp.GetColor(0)))); self.Destroy(); - } - - public IActivity Tick(Actor self) - { - if( !started ) - { - framesRemaining = self.Trait().anim.HasSequence("make") - ? self.Trait().anim.GetSequence( "make" ).Length : 0; - - foreach( var ns in self.TraitsImplementing() ) - ns.Selling( self ); - - started = true; - } - else if( framesRemaining <= 0 ) - DoSell( self ); - - else - --framesRemaining; - return this; } - public void Cancel(Actor self) { /* never gonna give you up.. */ } - - public void Queue( IActivity activity ) - { - if( NextActivity != null ) - NextActivity.Queue( activity ); - else - NextActivity = activity; - } - - public IEnumerable GetCurrentPath() - { - yield break; - } + // Not actually cancellable + protected override bool OnCancel( Actor self ) { return false; } } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 5980a0a4c9..287d4242f8 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -64,7 +64,6 @@ - @@ -106,7 +105,6 @@ - @@ -342,6 +340,8 @@ + + diff --git a/OpenRA.Mods.RA/Buildings/Sellable.cs b/OpenRA.Mods.RA/Sellable.cs similarity index 68% rename from OpenRA.Mods.RA/Buildings/Sellable.cs rename to OpenRA.Mods.RA/Sellable.cs index bb2e0a6695..9649c883c4 100644 --- a/OpenRA.Mods.RA/Buildings/Sellable.cs +++ b/OpenRA.Mods.RA/Sellable.cs @@ -12,8 +12,10 @@ using System; using System.Collections.Generic; using OpenRA.Orders; using OpenRA.Traits; +using OpenRA.Mods.RA.Render; +using OpenRA.Mods.RA.Activities; -namespace OpenRA.Mods.RA.Buildings +namespace OpenRA.Mods.RA { class SellableInfo : TraitInfo { @@ -27,6 +29,12 @@ namespace OpenRA.Mods.RA.Buildings if (order.OrderString == "Sell") { self.CancelActivity(); + if (self.HasTrait() && self.Info.Traits.Get().HasMakeAnimation) + self.QueueActivity(new MakeAnimation(self, true)); + + foreach( var ns in self.TraitsImplementing() ) + ns.Selling( self ); + self.QueueActivity(new Sell()); } }