From 502ed6a0e72ce099faef7bb7bd1c152d85996978 Mon Sep 17 00:00:00 2001 From: penev92 Date: Mon, 19 Jan 2015 16:25:50 +0200 Subject: [PATCH] Add SpriteHarvesterDockSequence and VoxelHarvesterDockSequence Pass drag-related info from Refinery to HarvesterDockSequence --- .../Activities/TDHarvesterDockSequence.cs | 93 ------------------- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 2 - .../Traits/Buildings/TiberianDawnRefinery.cs | 31 ------- .../Activities/HarvesterDockSequence.cs | 92 ++++++++++-------- .../Activities/SpriteHarvesterDockSequence.cs | 40 ++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/Traits/Buildings/Refinery.cs | 22 ++++- .../Activities/VoxelHarvesterDockSequence.cs | 62 +++---------- .../Traits/Buildings/TiberianSunRefinery.cs | 2 +- 9 files changed, 126 insertions(+), 219 deletions(-) delete mode 100644 OpenRA.Mods.Cnc/Activities/TDHarvesterDockSequence.cs delete mode 100644 OpenRA.Mods.Cnc/Traits/Buildings/TiberianDawnRefinery.cs create mode 100644 OpenRA.Mods.RA/Activities/SpriteHarvesterDockSequence.cs diff --git a/OpenRA.Mods.Cnc/Activities/TDHarvesterDockSequence.cs b/OpenRA.Mods.Cnc/Activities/TDHarvesterDockSequence.cs deleted file mode 100644 index 7d06746beb..0000000000 --- a/OpenRA.Mods.Cnc/Activities/TDHarvesterDockSequence.cs +++ /dev/null @@ -1,93 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2015 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 COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using OpenRA.Activities; -using OpenRA.Mods.Common.Activities; -using OpenRA.Mods.Common.Traits; -using OpenRA.Mods.RA.Traits; -using OpenRA.Traits; - -namespace OpenRA.Mods.Cnc.Activities -{ - public class TDHarvesterDockSequence : Activity - { - enum State { Wait, Turn, DragIn, Dock, Loop, Undock, DragOut } - static readonly WVec DockOffset = new WVec(-640, 341, 0); - - readonly Actor proc; - readonly Harvester harv; - readonly RenderUnit ru; - State state; - - WPos startDock, endDock; - public TDHarvesterDockSequence(Actor self, Actor proc) - { - this.proc = proc; - state = State.Turn; - harv = self.Trait(); - ru = self.Trait(); - startDock = self.CenterPosition; - endDock = proc.CenterPosition + DockOffset; - } - - public override Activity Tick(Actor self) - { - switch (state) - { - case State.Wait: - return this; - case State.Turn: - state = State.DragIn; - return Util.SequenceActivities(new Turn(self, 112), this); - case State.DragIn: - state = State.Dock; - return Util.SequenceActivities(new Drag(self, startDock, endDock, 12), this); - case State.Dock: - ru.PlayCustomAnimation(self, "dock", () => - { - ru.PlayCustomAnimRepeating(self, "dock-loop"); - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Docked(proc, self); - state = State.Loop; - }); - state = State.Wait; - return this; - case State.Loop: - if (!proc.IsInWorld || proc.IsDead || harv.TickUnload(self, proc)) - state = State.Undock; - return this; - case State.Undock: - ru.PlayCustomAnimBackwards(self, "dock", () => state = State.DragOut); - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Undocked(proc, self); - state = State.Wait; - return this; - case State.DragOut: - return Util.SequenceActivities(new Drag(self, endDock, startDock, 12), NextActivity); - } - - throw new InvalidOperationException("Invalid harvester dock state"); - } - - public override void Cancel(Actor self) - { - state = State.Undock; - } - - public override IEnumerable GetTargets(Actor self) - { - yield return Target.FromActor(proc); - } - } -} diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 3a68cef952..8f03a6b05a 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -67,12 +67,10 @@ - - diff --git a/OpenRA.Mods.Cnc/Traits/Buildings/TiberianDawnRefinery.cs b/OpenRA.Mods.Cnc/Traits/Buildings/TiberianDawnRefinery.cs deleted file mode 100644 index 1c91c952fa..0000000000 --- a/OpenRA.Mods.Cnc/Traits/Buildings/TiberianDawnRefinery.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2015 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 COPYING. - */ -#endregion - -using OpenRA.Activities; -using OpenRA.Mods.Cnc.Activities; -using OpenRA.Mods.RA.Traits; - -namespace OpenRA.Mods.Cnc.Traits -{ - public class TiberianDawnRefineryInfo : RefineryInfo - { - public override object Create(ActorInitializer init) { return new TiberianDawnRefinery(init.Self, this); } - } - - public class TiberianDawnRefinery : Refinery - { - public TiberianDawnRefinery(Actor self, RefineryInfo info) : base(self, info) { } - - public override Activity DockSequence(Actor harv, Actor self) - { - return new TDHarvesterDockSequence(harv, self); - } - } -} diff --git a/OpenRA.Mods.RA/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.RA/Activities/HarvesterDockSequence.cs index 0c2775f7e0..34c7549963 100644 --- a/OpenRA.Mods.RA/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.RA/Activities/HarvesterDockSequence.cs @@ -12,65 +12,69 @@ using System; using System.Collections.Generic; using OpenRA.Activities; using OpenRA.Mods.Common.Activities; -using OpenRA.Mods.Common.Traits; using OpenRA.Mods.RA.Traits; using OpenRA.Traits; -namespace OpenRA.Mods.RA +namespace OpenRA.Mods.RA.Activities { public class HarvesterDockSequence : Activity { - enum State { Wait, Turn, Dock, Loop, Undock, Complete } + protected enum State { Wait, Turn, Dock, Loop, Undock, Complete } - readonly Actor proc; - readonly int angle; - readonly Harvester harv; - readonly RenderUnit ru; - State state; + protected readonly Actor Refinery; + protected readonly Harvester Harv; + protected readonly int DockAngle; + protected readonly bool IsDragRequired; + protected readonly WVec DragOffset; + protected readonly int DragLength; + protected readonly WPos StartDrag; + protected readonly WPos EndDrag; + + protected State dockingState; - public HarvesterDockSequence(Actor self, Actor proc, int angle) + public HarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) { - this.proc = proc; - this.angle = angle; - state = State.Turn; - harv = self.Trait(); - ru = self.Trait(); + dockingState = State.Turn; + Refinery = refinery; + DockAngle = dockAngle; + IsDragRequired = isDragRequired; + DragOffset = dragOffset; + DragLength = dragLength; + Harv = self.Trait(); + StartDrag = self.CenterPosition; + EndDrag = refinery.CenterPosition + DragOffset; } public override Activity Tick(Actor self) { - switch (state) + switch (dockingState) { case State.Wait: return this; case State.Turn: - state = State.Dock; - return Util.SequenceActivities(new Turn(self, angle), this); + dockingState = State.Dock; + if (IsDragRequired) + return Util.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this); + return Util.SequenceActivities(new Turn(self, DockAngle), this); case State.Dock: - ru.PlayCustomAnimation(self, "dock", () => - { - ru.PlayCustomAnimRepeating(self, "dock-loop"); - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Docked(proc, self); - state = State.Loop; - }); - state = State.Wait; - return this; + if (Refinery.IsInWorld && !Refinery.IsDead) + foreach (var nd in Refinery.TraitsImplementing()) + nd.Docked(Refinery, self); + return OnStateDock(self); case State.Loop: - if (!proc.IsInWorld || proc.IsDead || harv.TickUnload(self, proc)) - state = State.Undock; + if (!Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery)) + dockingState = State.Undock; return this; case State.Undock: - ru.PlayCustomAnimBackwards(self, "dock", () => state = State.Complete); - state = State.Wait; - return this; + return OnStateUndock(self); case State.Complete: - harv.LastLinkedProc = harv.LinkedProc; - harv.LinkProc(self, null); - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Undocked(proc, self); + if (Refinery.IsInWorld && !Refinery.IsDead) + foreach (var nd in Refinery.TraitsImplementing()) + nd.Undocked(Refinery, self); + Harv.LastLinkedProc = Harv.LinkedProc; + Harv.LinkProc(self, null); + if (IsDragRequired) + return Util.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity); return NextActivity; } @@ -79,13 +83,23 @@ namespace OpenRA.Mods.RA public override void Cancel(Actor self) { - state = State.Undock; + dockingState = State.Undock; base.Cancel(self); } public override IEnumerable GetTargets(Actor self) { - yield return Target.FromActor(proc); + yield return Target.FromActor(Refinery); + } + + public virtual Activity OnStateDock(Actor self) + { + throw new NotImplementedException("Base class HarvesterDockSequence does not implement method OnStateDock!"); + } + + public virtual Activity OnStateUndock(Actor self) + { + throw new NotImplementedException("Base class HarvesterDockSequence does not implement method OnStateUndock!"); } } } \ No newline at end of file diff --git a/OpenRA.Mods.RA/Activities/SpriteHarvesterDockSequence.cs b/OpenRA.Mods.RA/Activities/SpriteHarvesterDockSequence.cs new file mode 100644 index 0000000000..aeaa57db77 --- /dev/null +++ b/OpenRA.Mods.RA/Activities/SpriteHarvesterDockSequence.cs @@ -0,0 +1,40 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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 COPYING. + */ +#endregion + +using OpenRA.Activities; +using OpenRA.Mods.Common.Traits; + +namespace OpenRA.Mods.RA.Activities +{ + public class SpriteHarvesterDockSequence : HarvesterDockSequence + { + readonly RenderUnit ru; + + public SpriteHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) + : base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength) + { + ru = self.Trait(); + } + + public override Activity OnStateDock(Actor self) + { + ru.PlayCustomAnimation(self, "dock", () => ru.PlayCustomAnimRepeating(self, "dock-loop")); + dockingState = State.Loop; + return this; + } + + public override Activity OnStateUndock(Actor self) + { + ru.PlayCustomAnimBackwards(self, "dock", () => dockingState = State.Complete); + dockingState = State.Wait; + return this; + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 40afa75aba..5d339dc13e 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -70,6 +70,7 @@ + diff --git a/OpenRA.Mods.RA/Traits/Buildings/Refinery.cs b/OpenRA.Mods.RA/Traits/Buildings/Refinery.cs index c7c9e71025..8e6b8ab0bb 100644 --- a/OpenRA.Mods.RA/Traits/Buildings/Refinery.cs +++ b/OpenRA.Mods.RA/Traits/Buildings/Refinery.cs @@ -20,15 +20,25 @@ namespace OpenRA.Mods.RA.Traits { public class RefineryInfo : ITraitInfo { + [Desc("Actual harvester facing when docking, 0-255 counter-clock-wise.")] + public readonly int DockAngle = 0; + [Desc("Docking cell relative to top-left cell.")] - public readonly CVec DockOffset = new CVec(1, 2); + public readonly CVec DockOffset = CVec.Zero; + + [Desc("Does the refinery require the harvester to be dragged in?")] + public readonly bool IsDragRequired = false; + + [Desc("Vector by which the harvester will be dragged when docking.")] + public readonly WVec DragOffset = WVec.Zero; + + [Desc("In how many steps to perform the dragging?")] + public readonly int DragLength = 0; public readonly bool ShowTicks = true; public readonly int TickLifetime = 30; public readonly int TickVelocity = 2; public readonly int TickRate = 10; - [Desc("Actual harvester facing when docking, 0-255 counter-clock-wise.")] - public readonly int DockAngle = 64; public virtual object Create(ActorInitializer init) { return new Refinery(init.Self, this); } } @@ -48,6 +58,10 @@ namespace OpenRA.Mods.RA.Traits public bool AllowDocking { get { return !preventDock; } } public CVec DeliveryOffset { get { return info.DockOffset; } } + public int DeliveryAngle { get { return info.DockAngle; } } + public bool IsDragRequired { get { return info.IsDragRequired; } } + public WVec DragOffset { get { return info.DragOffset; } } + public int DragLength { get { return info.DragLength; } } public Refinery(Actor self, RefineryInfo info) { @@ -59,7 +73,7 @@ namespace OpenRA.Mods.RA.Traits public virtual Activity DockSequence(Actor harv, Actor self) { - return new HarvesterDockSequence(harv, self, info.DockAngle); + return new SpriteHarvesterDockSequence(harv, self, DeliveryAngle, IsDragRequired, DragOffset, DragLength); } public IEnumerable> GetLinkedHarvesters() diff --git a/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs b/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs index 1077b65a25..d60cc3ec12 100644 --- a/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs +++ b/OpenRA.Mods.TS/Activities/VoxelHarvesterDockSequence.cs @@ -8,70 +8,34 @@ */ #endregion -using System; -using System.Collections.Generic; using OpenRA.Activities; -using OpenRA.Mods.Common.Activities; -using OpenRA.Mods.RA.Traits; +using OpenRA.Mods.RA.Activities; using OpenRA.Mods.TS.Traits; -using OpenRA.Traits; namespace OpenRA.Mods.TS.Activities { - public class VoxelHarvesterDockSequence : Activity + public class VoxelHarvesterDockSequence : HarvesterDockSequence { - enum State { Turn, Dock, Loop, Undock } - - readonly Actor proc; - readonly Harvester harv; readonly WithVoxelUnloadBody body; - State state; - public VoxelHarvesterDockSequence(Actor self, Actor proc) + public VoxelHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) + : base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength) { - this.proc = proc; - state = State.Turn; - harv = self.Trait(); body = self.Trait(); } - public override Activity Tick(Actor self) + public override Activity OnStateDock(Actor self) { - switch (state) - { - case State.Turn: - state = State.Dock; - return Util.SequenceActivities(new Turn(self, 160), this); - case State.Dock: - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Docked(proc, self); - state = State.Loop; - body.Docked = true; - return this; - case State.Loop: - if (!proc.IsInWorld || proc.IsDead || harv.TickUnload(self, proc)) - state = State.Undock; - return this; - case State.Undock: - if (proc.IsInWorld && !proc.IsDead) - foreach (var nd in proc.TraitsImplementing()) - nd.Undocked(proc, self); - body.Docked = false; - return NextActivity; - } - - throw new InvalidOperationException("Invalid harvester dock state"); + body.Docked = true; + dockingState = State.Loop; + return this; } - public override void Cancel(Actor self) + public override Activity OnStateUndock(Actor self) { - state = State.Undock; - } - - public override IEnumerable GetTargets(Actor self) - { - yield return Target.FromActor(proc); + body.Docked = false; + dockingState = State.Complete; + return this; } } -} +} \ No newline at end of file diff --git a/OpenRA.Mods.TS/Traits/Buildings/TiberianSunRefinery.cs b/OpenRA.Mods.TS/Traits/Buildings/TiberianSunRefinery.cs index 490d4fd6ec..9eaf300ee8 100644 --- a/OpenRA.Mods.TS/Traits/Buildings/TiberianSunRefinery.cs +++ b/OpenRA.Mods.TS/Traits/Buildings/TiberianSunRefinery.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.TS.Traits public override Activity DockSequence(Actor harv, Actor self) { - return new VoxelHarvesterDockSequence(harv, self); + return new VoxelHarvesterDockSequence(harv, self, DeliveryAngle, IsDragRequired, DragOffset, DragLength); } } }