RA Harvester docking sequence.

This commit is contained in:
Paul Chote
2011-01-04 14:19:50 +13:00
parent 76216b8dd9
commit ece50b0d57
8 changed files with 176 additions and 90 deletions

View File

@@ -24,6 +24,7 @@ namespace OpenRA.Mods.Cnc
enum State enum State
{ {
Wait, Wait,
Turn,
Dragin, Dragin,
Dock, Dock,
Loop, Loop,
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.Cnc
public HarvesterDockSequence(Actor self, Actor proc) public HarvesterDockSequence(Actor self, Actor proc)
{ {
this.proc = proc; this.proc = proc;
state = State.Dragin; state = State.Turn;
harv = self.Trait<Harvester>(); harv = self.Trait<Harvester>();
rb = proc.Trait<RenderBuilding>(); rb = proc.Trait<RenderBuilding>();
startDock = self.Trait<IHasLocation>().PxPosition; startDock = self.Trait<IHasLocation>().PxPosition;
@@ -56,6 +57,9 @@ namespace OpenRA.Mods.Cnc
{ {
case State.Wait: case State.Wait:
return this; return this;
case State.Turn:
state = State.Dragin;
return Util.SequenceActivities(new Turn(112), this);
case State.Dragin: case State.Dragin:
state = State.Dock; state = State.Dock;
return Util.SequenceActivities(new Drag(startDock, endDock, 12), this); return Util.SequenceActivities(new Drag(startDock, endDock, 12), this);

View File

@@ -19,69 +19,11 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
class TiberiumRefineryDockActionInfo : TraitInfo<TiberiumRefineryDockAction> {} class TiberiumRefineryDockActionInfo : TraitInfo<TiberiumRefineryDockAction> {}
class TiberiumRefineryDockAction : IAcceptOreDockAction, ITick, INotifyDamage, INotifySold, INotifyCapture class TiberiumRefineryDockAction : OreRefineryDockAction
{ {
Actor dockedHarv = null; public override IActivity DockSequence(Actor harv, Actor self)
bool preventDock = false;
public void OnDock(Actor self, Actor harv, DeliverResources dockOrder)
{ {
var mobile = harv.Trait<Mobile>(); return new HarvesterDockSequence(harv, self);
var harvester = harv.Trait<Harvester>();
harv.QueueActivity( new Turn(112) );
if (!preventDock)
{
harv.QueueActivity( new CallFunc( () => dockedHarv = harv, false ) );
harv.QueueActivity( new HarvesterDockSequence(harv, self) );
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
}
// Tell the harvester to start harvesting
// TODO: This belongs on the harv idle activity
harv.QueueActivity( new CallFunc( () =>
{
if (harvester.LastHarvestedCell != int2.Zero)
{
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
harv.SetTargetLine(Target.FromCell(harvester.LastHarvestedCell), Color.Red, false);
}
harv.QueueActivity( new Harvest() );
}));
}
public void Tick(Actor self)
{
// Harvester was killed while unloading
if (dockedHarv != null && dockedHarv.IsDead())
{
self.Trait<RenderBuilding>().CancelCustomAnim(self);
dockedHarv = null;
}
}
void CancelDock(Actor self)
{
preventDock = true;
// Cancel the dock sequence
if (dockedHarv != null && !dockedHarv.IsDead())
dockedHarv.CancelActivity();
}
public void Selling (Actor self) { CancelDock(self); }
public void Sold (Actor self) {}
public void Damaged (Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
CancelDock(self);
}
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
{
if (dockedHarv != null)
dockedHarv.ChangeOwner(newOwner);
} }
} }
} }

View File

@@ -0,0 +1,94 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Collections.Generic;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using System;
namespace OpenRA.Mods.RA
{
public class RAHarvesterDockSequence : IActivity
{
enum State
{
Wait,
Turn,
Dock,
Loop,
Undock,
Complete
};
readonly Actor proc;
readonly Harvester harv;
readonly RenderUnit ru;
State state;
public RAHarvesterDockSequence(Actor self, Actor proc)
{
this.proc = proc;
state = State.Turn;
harv = self.Trait<Harvester>();
ru = self.Trait<RenderUnit>();
}
IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
{
switch (state)
{
case State.Wait:
return this;
case State.Turn:
state = State.Dock;
return Util.SequenceActivities(new Turn(64), this);
case State.Dock:
ru.PlayCustomAnimation(self, "dock", () => {ru.PlayCustomAnimRepeating(self, "dock-loop"); state = State.Loop;});
state = State.Wait;
return this;
case State.Loop:
if (harv.TickUnload(self, proc))
state = State.Undock;
return this;
case State.Undock:
ru.PlayCustomAnimBackwards(self, "dock", () => state = State.Complete);
state = State.Wait;
return this;
case State.Complete:
return NextActivity;
}
throw new InvalidOperationException("Invalid harvester dock state");
}
public void Cancel(Actor self)
{
state = State.Undock;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
}
}
}

View File

@@ -328,6 +328,7 @@
<Compile Include="SupportPowers\SupportPowerManager.cs" /> <Compile Include="SupportPowers\SupportPowerManager.cs" />
<Compile Include="Buildings\ShakeOnDeath.cs" /> <Compile Include="Buildings\ShakeOnDeath.cs" />
<Compile Include="Buildings\SoundOnDamageTransition.cs" /> <Compile Include="Buildings\SoundOnDamageTransition.cs" />
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -17,43 +17,73 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class OreRefineryDockActionInfo : TraitInfo<OreRefineryDockAction> {} public class OreRefineryDockActionInfo : TraitInfo<OreRefineryDockAction> {}
class OreRefineryDockAction : IAcceptOreDockAction, INotifyCapture public class OreRefineryDockAction : IAcceptOreDockAction, INotifyCapture
{ {
public virtual IActivity DockSequence(Actor harv, Actor self)
{
return new RAHarvesterDockSequence(harv, self);
}
Actor dockedHarv = null; Actor dockedHarv = null;
bool preventDock = false;
public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) public void OnDock(Actor self, Actor harv, DeliverResources dockOrder)
{ {
var mobile = harv.Trait<Mobile>();
var harvester = harv.Trait<Harvester>(); var harvester = harv.Trait<Harvester>();
if (harv.Trait<IFacing>().Facing != 64)
harv.QueueActivity (new Turn (64));
harv.QueueActivity (new CallFunc (() => if (!preventDock)
{ {
dockedHarv = harv; harv.QueueActivity( new CallFunc( () => dockedHarv = harv, false ) );
var renderUnit = harv.Trait<RenderUnit> (); harv.QueueActivity( DockSequence(harv, self) );
if (renderUnit.anim.CurrentSequence.Name != "empty") harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
renderUnit.PlayCustomAnimation (harv, "empty", () => }
{
harvester.Deliver(harv, self); // Tell the harvester to start harvesting
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) ); // TODO: This belongs on the harv idle activity
harv.QueueActivity( new CallFunc( () =>
if (harvester.LastHarvestedCell != int2.Zero) {
{ if (harvester.LastHarvestedCell != int2.Zero)
var mobile = harv.Trait<Mobile>(); {
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) ); harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
harv.SetTargetLine(Target.FromCell(harvester.LastHarvestedCell), Color.Red, false); harv.SetTargetLine(Target.FromCell(harvester.LastHarvestedCell), Color.Red, false);
} }
harv.QueueActivity( new Harvest() ); harv.QueueActivity( new Harvest() );
});
})); }));
} }
public void Tick(Actor self)
{
// Harvester was killed while unloading
if (dockedHarv != null && dockedHarv.IsDead())
{
self.Trait<RenderBuilding>().CancelCustomAnim(self);
dockedHarv = null;
}
}
void CancelDock(Actor self)
{
preventDock = true;
// Cancel the dock sequence
if (dockedHarv != null && !dockedHarv.IsDead())
dockedHarv.CancelActivity();
}
public void Selling (Actor self) { CancelDock(self); }
public void Sold (Actor self) {}
public void Damaged (Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
CancelDock(self);
}
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner) public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
{ {
if (dockedHarv != null) if (dockedHarv != null)
dockedHarv.ChangeOwner(newOwner); dockedHarv.ChangeOwner(newOwner);
} }
} }

View File

@@ -37,7 +37,19 @@ namespace OpenRA.Mods.RA.Render
{ {
anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); }); anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); });
} }
public void PlayCustomAnimRepeating(Actor self, string name)
{
anim.PlayThen(name,
() => { PlayCustomAnimRepeating(self, name); });
}
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
{
anim.PlayBackwardsThen(name,
() => { anim.PlayRepeating("idle"); a(); });
}
bool isSmoking; bool isSmoking;
bool canSmoke; bool canSmoke;

View File

@@ -291,6 +291,7 @@ HARV:
Harvester: Harvester:
Capacity: 20 Capacity: 20
Resources: Ore,Gems Resources: Ore,Gems
UnloadTicksPerBale: 1
Health: Health:
HP: 600 HP: 600
Armor: Armor:

View File

@@ -370,10 +370,12 @@ harv:
Start: 32 Start: 32
Length: 8 Length: 8
Facings: 8 Facings: 8
empty: dock:
Start: 96 Start: 96
Length: 15 Length: 8
dock-loop:
Start: 104
Length: 7
1tnk: 1tnk:
idle: idle:
Start: 0 Start: 0