Use MakeAnimation for selling; Support selling non-buildings

This commit is contained in:
Paul Chote
2011-04-10 11:03:42 +12:00
parent e4d8680bd5
commit fe4fd8cab0
3 changed files with 19 additions and 47 deletions

View File

@@ -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<Health>();
var si = self.Info.Traits.Get<SellableInfo>();
@@ -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<RenderSimple>().anim.HasSequence("make")
? self.Trait<RenderSimple>().anim.GetSequence( "make" ).Length : 0;
foreach( var ns in self.TraitsImplementing<INotifySold>() )
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<float2> GetCurrentPath()
{
yield break;
}
// Not actually cancellable
protected override bool OnCancel( Actor self ) { return false; }
}
}

View File

@@ -64,7 +64,6 @@
<Compile Include="Activities\EnterTransport.cs" />
<Compile Include="Air\FlyCircle.cs" />
<Compile Include="Air\EjectOnDeath.cs" />
<Compile Include="Buildings\Sellable.cs" />
<Compile Include="Effects\CashTick.cs" />
<Compile Include="GivesBounty.cs" />
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
@@ -106,7 +105,6 @@
<Compile Include="Buildings\FootprintUtils.cs" />
<Compile Include="Buildings\LineBuild.cs" />
<Compile Include="Buildings\PowerManager.cs" />
<Compile Include="Buildings\Sell.cs" />
<Compile Include="Buildings\TechTree.cs" />
<Compile Include="Buildings\Util.cs" />
<Compile Include="ProximityCaptor.cs" />
@@ -342,6 +340,8 @@
<Compile Include="AnnounceOnBuild.cs" />
<Compile Include="Capturable.cs" />
<Compile Include="Activities\MakeAnimation.cs" />
<Compile Include="Activities\Sell.cs" />
<Compile Include="Sellable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -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<Sellable>
{
@@ -27,6 +29,12 @@ namespace OpenRA.Mods.RA.Buildings
if (order.OrderString == "Sell")
{
self.CancelActivity();
if (self.HasTrait<RenderBuilding>() && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
self.QueueActivity(new MakeAnimation(self, true));
foreach( var ns in self.TraitsImplementing<INotifySold>() )
ns.Selling( self );
self.QueueActivity(new Sell());
}
}