QueuedActivity's Insert is broken

This commit is contained in:
alzeih
2011-03-18 00:18:57 +13:00
committed by Paul Chote
parent 4e89326134
commit 255bac6aff
64 changed files with 218 additions and 251 deletions

View File

@@ -31,7 +31,7 @@ namespace OpenRA
[Sync] [Sync]
public Player Owner; public Player Owner;
private IActivity currentActivity; private Activity currentActivity;
public Group Group; public Group Group;
internal Actor(World world, string name, TypeDictionary initDict ) internal Actor(World world, string name, TypeDictionary initDict )
@@ -121,7 +121,14 @@ namespace OpenRA
public bool IsInWorld { get; internal set; } public bool IsInWorld { get; internal set; }
public void QueueActivity( IActivity nextActivity ) public void QueueActivity( bool queued, Activity nextActivity )
{
if( !queued )
CancelActivity();
QueueActivity( nextActivity );
}
public void QueueActivity( Activity nextActivity )
{ {
if( currentActivity == null ) if( currentActivity == null )
currentActivity = nextActivity; currentActivity = nextActivity;
@@ -135,7 +142,7 @@ namespace OpenRA
currentActivity.Cancel( this ); currentActivity.Cancel( this );
} }
public IActivity GetCurrentActivity() public Activity GetCurrentActivity()
{ {
return currentActivity; return currentActivity;
} }

View File

@@ -15,12 +15,15 @@ using System.Text;
namespace OpenRA.Traits.Activities namespace OpenRA.Traits.Activities
{ {
public abstract class CancelableActivity : IActivity public class Activity
{ {
protected IActivity NextActivity { get; private set; } public Activity NextActivity { get; set; }
protected bool IsCanceled { get; private set; } protected bool IsCanceled { get; private set; }
public abstract IActivity Tick( Actor self ); public virtual Activity Tick( Actor self )
{
return this;
}
protected virtual bool OnCancel( Actor self ) { return true; } protected virtual bool OnCancel( Actor self ) { return true; }
public void Cancel( Actor self ) public void Cancel( Actor self )
@@ -32,7 +35,7 @@ namespace OpenRA.Traits.Activities
NextActivity.Cancel( self ); NextActivity.Cancel( self );
} }
public void Queue( IActivity activity ) public virtual void Queue( Activity activity )
{ {
if( NextActivity != null ) if( NextActivity != null )
NextActivity.Queue( activity ); NextActivity.Queue( activity );
@@ -40,9 +43,9 @@ namespace OpenRA.Traits.Activities
NextActivity = activity; NextActivity = activity;
} }
public virtual IEnumerable<float2> GetCurrentPath() public virtual IEnumerable<Target> GetTargetQueue( Actor self )
{ {
yield break; yield break;
} }
} }
} }

View File

@@ -237,12 +237,12 @@ namespace OpenRA.Traits
if (activity != null && mobile != null) if (activity != null && mobile != null)
{ {
var alt = new float2(0, -mobile.Altitude); var alt = new float2(0, -mobile.Altitude);
var path = activity.GetCurrentPath(); var targets = activity.GetTargetQueue(self);
var start = self.CenterLocation + alt; var start = self.CenterLocation + alt;
var c = Color.Green; var c = Color.Green;
foreach (var step in path) foreach (var step in targets.Select(p => p.CenterLocation))
{ {
var stp = step + alt; var stp = step + alt;
Game.Renderer.LineRenderer.DrawLine(stp + new float2(-1, -1), stp + new float2(-1, 1), c, c); Game.Renderer.LineRenderer.DrawLine(stp + new float2(-1, -1), stp + new float2(-1, 1), c, c);

View File

@@ -12,6 +12,8 @@ namespace OpenRA.Traits
{ {
public struct Target // a target: either an actor, or a fixed location. public struct Target // a target: either an actor, or a fixed location.
{ {
public static Target[] NoTargets = {};
Actor actor; Actor actor;
Player owner; Player owner;
int2 pos; int2 pos;

View File

@@ -203,14 +203,6 @@ namespace OpenRA.Traits
IBotInfo Info { get; } IBotInfo Info { get; }
} }
public interface IActivity
{
IActivity Tick(Actor self);
void Cancel(Actor self);
void Queue(IActivity activity);
IEnumerable<float2> GetCurrentPath();
}
public interface IRenderOverlay { void Render(WorldRenderer wr); } public interface IRenderOverlay { void Render(WorldRenderer wr); }
public interface INotifyIdle { void TickIdle(Actor self); } public interface INotifyIdle { void TickIdle(Actor self); }

View File

@@ -14,6 +14,7 @@ using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Support; using OpenRA.Support;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
@@ -103,13 +104,13 @@ namespace OpenRA.Traits
return new Renderable(s, loc.Round(), pal, (int)self.CenterLocation.Y); return new Renderable(s, loc.Round(), pal, (int)self.CenterLocation.Y);
} }
public static IActivity SequenceActivities(params IActivity[] acts) public static Activity SequenceActivities(params Activity[] acts)
{ {
return acts.Reverse().Aggregate( return acts.Reverse().Aggregate(
(next, a) => { a.Queue( next ); return a; }); (next, a) => { a.Queue( next ); return a; });
} }
public static IActivity RunActivity( Actor self, IActivity act ) public static Activity RunActivity( Actor self, Activity act )
{ {
while( act != null ) while( act != null )
{ {

View File

@@ -19,7 +19,7 @@ using System;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
public class HarvesterDockSequence : IActivity public class HarvesterDockSequence : Activity
{ {
enum State enum State
{ {
@@ -49,9 +49,7 @@ namespace OpenRA.Mods.Cnc
endDock = proc.Trait<IHasLocation>().PxPosition + new int2(-15,8); endDock = proc.Trait<IHasLocation>().PxPosition + new int2(-15,8);
} }
IActivity NextActivity { get; set; } public override Activity Tick(Actor self)
public IActivity Tick(Actor self)
{ {
switch (state) switch (state)
{ {
@@ -82,22 +80,15 @@ namespace OpenRA.Mods.Cnc
throw new InvalidOperationException("Invalid harvester dock state"); throw new InvalidOperationException("Invalid harvester dock state");
} }
public void Cancel(Actor self) protected override bool OnCancel(Actor self)
{ {
state = State.Undock; state = State.Undock;
return true;
} }
public void Queue( IActivity activity ) public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
if( NextActivity != null ) yield return Target.FromActor(proc);
NextActivity.Queue( activity );
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
} }
} }
} }

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Cnc
} }
} }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
return new AttackActivity( newTarget ); return new AttackActivity( newTarget );
} }
@@ -137,12 +137,12 @@ namespace OpenRA.Mods.Cnc
return State == PopupState.Closed ? Info.ClosedDamageMultiplier : 1f; return State == PopupState.Closed ? Info.ClosedDamageMultiplier : 1f;
} }
class AttackActivity : CancelableActivity class AttackActivity : Activity
{ {
readonly Target target; readonly Target target;
public AttackActivity( Target newTarget ) { this.target = newTarget; } public AttackActivity( Target newTarget ) { this.target = newTarget; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || !target.IsValid ) return NextActivity; if( IsCanceled || !target.IsValid ) return NextActivity;

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc
public TiberiumRefinery(Actor self, TiberiumRefineryInfo info) public TiberiumRefinery(Actor self, TiberiumRefineryInfo info)
: base(self, info as OreRefineryInfo) {} : base(self, info as OreRefineryInfo) {}
public override IActivity DockSequence(Actor harv, Actor self) public override Activity DockSequence(Actor harv, Actor self)
{ {
return new HarvesterDockSequence(harv, self); return new HarvesterDockSequence(harv, self);
} }

View File

@@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
/* non-turreted attack */ /* non-turreted attack */
public class Attack : CancelableActivity public class Attack : Activity
{ {
protected Target Target; protected Target Target;
ITargetable targetable; ITargetable targetable;
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities
public Attack(Target target, int range) : this(target, range, true) {} public Attack(Target target, int range) : this(target, range, true) {}
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
var attack = self.Trait<AttackBase>(); var attack = self.Trait<AttackBase>();
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Activities
return ret; return ret;
} }
protected virtual IActivity InnerTick( Actor self, AttackBase attack ) protected virtual Activity InnerTick( Actor self, AttackBase attack )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var facing = self.Trait<IFacing>(); var facing = self.Trait<IFacing>();

View File

@@ -11,10 +11,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class CallFunc : IActivity public class CallFunc : Activity
{ {
public CallFunc(Action a) { this.a = a; } public CallFunc(Action a) { this.a = a; }
public CallFunc(Action a, bool interruptable) public CallFunc(Action a, bool interruptable)
@@ -25,33 +26,30 @@ namespace OpenRA.Mods.RA.Activities
Action a; Action a;
bool interruptable; bool interruptable;
IActivity NextActivity { get; set; }
public IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (a != null) a(); if (a != null) a();
return NextActivity; return NextActivity;
} }
public void Cancel(Actor self) protected override bool OnCancel(Actor self)
{ {
if (!interruptable) if (!interruptable)
return; return false;
a = null; a = null;
NextActivity = null; return true;
} }
public void Queue( IActivity activity ) public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
if( NextActivity != null ) if (NextActivity != null)
NextActivity.Queue( activity ); foreach (var target in NextActivity.GetTargetQueue(self))
else {
NextActivity = activity; yield return target;
} }
public IEnumerable<float2> GetCurrentPath()
{
yield break; yield break;
} }
} }

View File

@@ -14,13 +14,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class CaptureActor : CancelableActivity class CaptureActor : Activity
{ {
Actor target; Actor target;
public CaptureActor(Actor target) { this.target = target; } public CaptureActor(Actor target) { this.target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity; if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -15,15 +15,13 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class DeliverResources : IActivity public class DeliverResources : Activity
{ {
IActivity NextActivity { get; set; }
bool isDocking; bool isDocking;
public DeliverResources() { } public DeliverResources() { }
public IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( NextActivity != null ) if( NextActivity != null )
return NextActivity; return NextActivity;
@@ -51,21 +49,20 @@ namespace OpenRA.Mods.RA.Activities
return Util.SequenceActivities( new Wait(10), this ); return Util.SequenceActivities( new Wait(10), this );
} }
public void Cancel(Actor self) protected override bool OnCancel(Actor self)
{ {
// TODO: allow canceling of deliver orders? // TODO: allow canceling of deliver orders?
return false;
} }
public void Queue( IActivity activity ) public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
if( NextActivity != null ) if (NextActivity != null)
NextActivity.Queue( activity ); foreach (var target in NextActivity.GetTargetQueue(self))
else {
NextActivity = activity; yield return target;
} }
public IEnumerable<float2> GetCurrentPath()
{
yield break; yield break;
} }
} }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class Demolish : CancelableActivity class Demolish : Activity
{ {
Actor target; Actor target;
int delay; int delay;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
this.delay = delay; this.delay = delay;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity; if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -15,7 +15,7 @@ using OpenRA.Mods.RA.Effects;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class DonateSupplies : CancelableActivity class DonateSupplies : Activity
{ {
Actor target; Actor target;
int payload; int payload;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
this.payload = payload; this.payload = payload;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity; if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -17,12 +17,12 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Enter : CancelableActivity public class Enter : Activity
{ {
readonly Actor target; readonly Actor target;
public Enter( Actor target ) { this.target = target; } public Enter( Actor target ) { this.target = target; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || target.Destroyed || !target.IsInWorld ) if( IsCanceled || target.Destroyed || !target.IsInWorld )
return NextActivity; return NextActivity;

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class EnterTransport : CancelableActivity class EnterTransport : Activity
{ {
public Actor transport; public Actor transport;
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Activities
this.transport = transport; this.transport = transport;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (transport == null || !transport.IsInWorld) return NextActivity; if (transport == null || !transport.IsInWorld) return NextActivity;

View File

@@ -14,7 +14,7 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Follow : CancelableActivity public class Follow : Activity
{ {
Target Target; Target Target;
int Range; int Range;
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities
Range = range; Range = range;
} }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (!Target.IsValid) return NextActivity; if (!Target.IsValid) return NextActivity;

View File

@@ -13,14 +13,15 @@ using OpenRA.Mods.RA.Render;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Move;
using System.Collections.Generic;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Harvest : CancelableActivity public class Harvest : Activity
{ {
bool isHarvesting = false; bool isHarvesting = false;
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( isHarvesting ) return this; if( isHarvesting ) return this;
if( IsCanceled ) return NextActivity; if( IsCanceled ) return NextActivity;
@@ -74,5 +75,10 @@ namespace OpenRA.Mods.RA.Activities
})); }));
self.QueueActivity(new Harvest()); self.QueueActivity(new Harvest());
} }
public override IEnumerable<Target> GetTargetQueue( Actor self )
{
yield return Target.FromPos(self.Location);
}
} }
} }

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Activities
public Heal(Target target, int range, bool allowMovement) public Heal(Target target, int range, bool allowMovement)
: base(target, range, allowMovement) {} : base(target, range, allowMovement) {}
protected override IActivity InnerTick( Actor self, AttackBase attack ) protected override Activity InnerTick( Actor self, AttackBase attack )
{ {
if (Target.IsActor && Target.Actor.GetDamageState() == DamageState.Undamaged) if (Target.IsActor && Target.Actor.GetDamageState() == DamageState.Undamaged)
return NextActivity; return NextActivity;

View File

@@ -14,12 +14,12 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class Infiltrate : CancelableActivity class Infiltrate : Activity
{ {
Actor target; Actor target;
public Infiltrate(Actor target) { this.target = target; } public Infiltrate(Actor target) { this.target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity; if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -18,9 +18,9 @@ namespace OpenRA.Mods.RA.Activities
{ {
// assumes you have Minelayer on that unit // assumes you have Minelayer on that unit
class LayMines : CancelableActivity class LayMines : Activity
{ {
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class Leap : CancelableActivity class Leap : Activity
{ {
Target target; Target target;
int2 initialLocation; int2 initialLocation;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Activities
Sound.Play("dogg5p.aud", self.CenterLocation); Sound.Play("dogg5p.aud", self.CenterLocation);
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if( moveFraction == 0 && IsCanceled ) return NextActivity; if( moveFraction == 0 && IsCanceled ) return NextActivity;
if (!target.IsValid) return NextActivity; if (!target.IsValid) return NextActivity;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class MakeAnimation : CancelableActivity class MakeAnimation : Activity
{ {
readonly bool Reversed; readonly bool Reversed;
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Activities
bool complete = false; bool complete = false;
bool started = false; bool started = false;
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (!started) if (!started)

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class MoveAdjacentTo : CancelableActivity public class MoveAdjacentTo : Activity
{ {
readonly Actor target; readonly Actor target;
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities
this.target = target; this.target = target;
} }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity; if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity;

View File

@@ -11,26 +11,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class QueuedActivity : IActivity public class QueuedActivity : Activity
{ {
public QueuedActivity(Action<QueuedActivity> a) { this.a = a; } public QueuedActivity(Action<QueuedActivity> a) { this.a = a; }
public QueuedActivity(Action<QueuedActivity> a, bool interruptable) public QueuedActivity(Action<QueuedActivity> a, bool interruptable)
{ {
this.a = a; this.a = a;
this.interruptable = interruptable;
} }
Action<QueuedActivity> a; Action<QueuedActivity> a;
private bool interruptable = true;
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self) { return Run(self); } public override Activity Tick(Actor self) { return Run(self); }
public IActivity Run(Actor self) public Activity Run(Actor self)
{ {
if (a != null) if (a != null)
a(this); a(this);
@@ -38,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity; return NextActivity;
} }
public void Insert(IActivity activity) public void Insert( Activity activity )
{ {
if (activity == null) if (activity == null)
return; return;
@@ -46,29 +44,12 @@ namespace OpenRA.Mods.RA.Activities
NextActivity = activity; NextActivity = activity;
} }
public void Cancel(Actor self) public override IEnumerable<Target> GetTargetQueue( Actor self )
{
if (!interruptable)
return;
a = null;
NextActivity = null;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{ {
if (NextActivity != null) if (NextActivity != null)
foreach (var path in NextActivity.GetCurrentPath()) foreach (var target in NextActivity.GetTargetQueue(self))
{ {
yield return path; yield return target;
} }
yield break; yield break;

View File

@@ -18,7 +18,7 @@ using System;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class RAHarvesterDockSequence : IActivity public class RAHarvesterDockSequence : Activity
{ {
enum State enum State
{ {
@@ -42,10 +42,8 @@ namespace OpenRA.Mods.RA
harv = self.Trait<Harvester>(); harv = self.Trait<Harvester>();
ru = self.Trait<RenderUnit>(); ru = self.Trait<RenderUnit>();
} }
IActivity NextActivity { get; set; } public override Activity Tick(Actor self)
public IActivity Tick(Actor self)
{ {
switch (state) switch (state)
{ {
@@ -72,22 +70,15 @@ namespace OpenRA.Mods.RA
throw new InvalidOperationException("Invalid harvester dock state"); throw new InvalidOperationException("Invalid harvester dock state");
} }
public void Cancel(Actor self) protected override bool OnCancel(Actor self)
{ {
state = State.Undock; state = State.Undock;
return true;
} }
public void Queue( IActivity activity ) public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
if( NextActivity != null ) yield return Target.FromActor(proc);
NextActivity.Queue( activity );
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
} }
} }
} }

View File

@@ -15,13 +15,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Rearm : CancelableActivity public class Rearm : Activity
{ {
int remainingTicks = ticksPerPip; int remainingTicks = ticksPerPip;
const int ticksPerPip = 25 * 2; const int ticksPerPip = 25 * 2;
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>(); var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();

View File

@@ -13,9 +13,9 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class RemoveSelf : CancelableActivity public class RemoveSelf : Activity
{ {
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
self.Destroy(); self.Destroy();

View File

@@ -15,14 +15,14 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Repair : CancelableActivity public class Repair : Activity
{ {
int remainingTicks; int remainingTicks;
Actor host; Actor host;
public Repair(Actor host) { this.host = host; } public Repair(Actor host) { this.host = host; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (host != null && !host.IsInWorld) return NextActivity; if (host != null && !host.IsInWorld) return NextActivity;

View File

@@ -14,13 +14,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class RepairBuilding : CancelableActivity class RepairBuilding : Activity
{ {
Actor target; Actor target;
public RepairBuilding(Actor target) { this.target = target; } public RepairBuilding(Actor target) { this.target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity; if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -16,9 +16,9 @@ using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class Sell : CancelableActivity class Sell : Activity
{ {
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var h = self.TraitOrDefault<Health>(); var h = self.TraitOrDefault<Health>();
var si = self.Info.Traits.Get<SellableInfo>(); var si = self.Info.Traits.Get<SellableInfo>();

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Teleport : CancelableActivity public class Teleport : Activity
{ {
int2 destination; int2 destination;
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities
this.destination = destination; this.destination = destination;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
self.TraitsImplementing<ITeleportable>().FirstOrDefault().SetPosition(self, destination); self.TraitsImplementing<ITeleportable>().FirstOrDefault().SetPosition(self, destination);
return NextActivity; return NextActivity;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
class Transform : CancelableActivity class Transform : Activity
{ {
public readonly string ToActor = null; public readonly string ToActor = null;
public int2 Offset = new int2(0,0); public int2 Offset = new int2(0,0);
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities
this.ToActor = toActor; this.ToActor = toActor;
} }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Turn : CancelableActivity public class Turn : Activity
{ {
int desiredFacing; int desiredFacing;
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities
this.desiredFacing = desiredFacing; this.desiredFacing = desiredFacing;
} }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var facing = self.Trait<IFacing>(); var facing = self.Trait<IFacing>();

View File

@@ -17,7 +17,7 @@ using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class UnloadCargo : CancelableActivity public class UnloadCargo : Activity
{ {
int2? ChooseExitTile(Actor self, Actor cargo) int2? ChooseExitTile(Actor self, Actor cargo)
{ {
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
return null; return null;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities namespace OpenRA.Mods.RA.Activities
{ {
public class Wait : CancelableActivity public class Wait : Activity
{ {
int remainingTicks; int remainingTicks;
bool interruptable = true; bool interruptable = true;
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
this.interruptable = interruptable; this.interruptable = interruptable;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (remainingTicks-- == 0) return NextActivity; if (remainingTicks-- == 0) return NextActivity;
return this; return this;

View File

@@ -10,6 +10,7 @@
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.RA.Air
{ {
public AttackHeli(Actor self, AttackHeliInfo info) : base(self, info) { } public AttackHeli(Actor self, AttackHeliInfo info) : base(self, info) { }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
return new HeliAttack( newTarget ); return new HeliAttack( newTarget );
} }

View File

@@ -10,6 +10,7 @@
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.RA.Air
{ {
public AttackPlane(Actor self, AttackPlaneInfo info) : base(self, info) { } public AttackPlane(Actor self, AttackPlaneInfo info) : base(self, info) { }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
return new FlyAttack( newTarget ); return new FlyAttack( newTarget );
} }

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Air
} }
} }
class FallToEarth : CancelableActivity class FallToEarth : Activity
{ {
int acceleration = 0; int acceleration = 0;
int spin = 0; int spin = 0;
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Air
acceleration = self.World.SharedRandom.Next(2) * 2 - 1; acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var aircraft = self.Trait<Aircraft>(); var aircraft = self.Trait<Aircraft>();
if (aircraft.Altitude <= 0) if (aircraft.Altitude <= 0)

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class Fly : CancelableActivity public class Fly : Activity
{ {
public readonly int2 Pos; public readonly int2 Pos;
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Air
public static Fly ToPx( int2 px ) { return new Fly( px ); } public static Fly ToPx( int2 px ) { return new Fly( px ); }
public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
@@ -47,9 +47,9 @@ namespace OpenRA.Mods.RA.Air
return this; return this;
} }
public override IEnumerable<float2> GetCurrentPath() public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
yield return Pos; yield return Target.FromPos(Pos);
} }
} }

View File

@@ -13,14 +13,14 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class FlyAttack : CancelableActivity public class FlyAttack : Activity
{ {
readonly Target Target; readonly Target Target;
IActivity inner; Activity inner;
public FlyAttack(Target target) { Target = target; } public FlyAttack(Target target) { Target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if( !Target.IsValid ) if( !Target.IsValid )
Cancel( self ); Cancel( self );
@@ -52,13 +52,13 @@ namespace OpenRA.Mods.RA.Air
} }
} }
public class FlyAttackLoop : CancelableActivity public class FlyAttackLoop : Activity
{ {
int2 Target; int2 Target;
public FlyAttackLoop(int2 target) { Target = target; } public FlyAttackLoop(int2 target) { Target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if( IsCanceled ) return NextActivity; if( IsCanceled ) return NextActivity;

View File

@@ -14,9 +14,9 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class FlyCircle : CancelableActivity public class FlyCircle : Activity
{ {
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
@@ -34,10 +34,5 @@ namespace OpenRA.Mods.RA.Air
FlyUtil.Fly(self, cruiseAltitude); FlyUtil.Fly(self, cruiseAltitude);
return this; return this;
} }
public override IEnumerable<float2> GetCurrentPath()
{
yield break;
}
} }
} }

View File

@@ -13,13 +13,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class FlyTimed : CancelableActivity public class FlyTimed : Activity
{ {
int remainingTicks; int remainingTicks;
public FlyTimed(int ticks) { remainingTicks = ticks; } public FlyTimed(int ticks) { remainingTicks = ticks; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if( IsCanceled ) return NextActivity; if( IsCanceled ) return NextActivity;
var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
@@ -29,11 +29,11 @@ namespace OpenRA.Mods.RA.Air
} }
} }
public class FlyOffMap : CancelableActivity public class FlyOffMap : Activity
{ {
public bool Interruptible = true; public bool Interruptible = true;
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
if (IsCanceled || !self.World.Map.IsInMap(self.Location)) return NextActivity; if (IsCanceled || !self.World.Map.IsInMap(self.Location)) return NextActivity;

View File

@@ -15,12 +15,12 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class HeliAttack : CancelableActivity public class HeliAttack : Activity
{ {
Target target; Target target;
public HeliAttack( Target target ) { this.target = target; } public HeliAttack( Target target ) { this.target = target; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (!target.IsValid) return NextActivity; if (!target.IsValid) return NextActivity;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
class HeliFly : CancelableActivity class HeliFly : Activity
{ {
public readonly int2 Dest; public readonly int2 Dest;
public HeliFly(int2 dest) public HeliFly(int2 dest)
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Air
Dest = dest; Dest = dest;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
@@ -50,9 +50,9 @@ namespace OpenRA.Mods.RA.Air
return this; return this;
} }
public override IEnumerable<float2> GetCurrentPath() public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
yield return Dest; yield return Target.FromPos(Dest);
} }
} }
} }

View File

@@ -13,13 +13,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
class HeliLand : CancelableActivity class HeliLand : Activity
{ {
public HeliLand(bool requireSpace) { this.requireSpace = requireSpace; } public HeliLand(bool requireSpace) { this.requireSpace = requireSpace; }
bool requireSpace; bool requireSpace;
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var aircraft = self.Trait<Aircraft>(); var aircraft = self.Trait<Aircraft>();

View File

@@ -15,7 +15,7 @@ using OpenRA.Mods.RA.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class HeliReturn : CancelableActivity public class HeliReturn : Activity
{ {
static Actor ChooseHelipad(Actor self) static Actor ChooseHelipad(Actor self)
{ {
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Air
!Reservable.IsReserved(a)); !Reservable.IsReserved(a));
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var dest = ChooseHelipad(self); var dest = ChooseHelipad(self);

View File

@@ -15,13 +15,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class Land : CancelableActivity public class Land : Activity
{ {
Target Target; Target Target;
public Land(Target t) { Target = t; } public Land(Target t) { Target = t; }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (!Target.IsValid) if (!Target.IsValid)
Cancel(self); Cancel(self);

View File

@@ -11,6 +11,7 @@
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {

View File

@@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class ReturnToBase : CancelableActivity public class ReturnToBase : Activity
{ {
bool isCalculated; bool isCalculated;
Actor dest; Actor dest;
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Air
this.dest = dest; this.dest = dest;
} }
public override IActivity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
if (!isCalculated) if (!isCalculated)

View File

@@ -14,6 +14,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -172,7 +173,7 @@ namespace OpenRA.Mods.RA
return (order.OrderString == "Attack" || order.OrderString == "AttackHold") ? "Attack" : null; return (order.OrderString == "Attack" || order.OrderString == "AttackHold") ? "Attack" : null;
} }
public abstract IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove); public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove);
public bool HasAnyValidWeapons(Target t) { return Weapons.Any(w => w.IsValidAgainst(self.World, t)); } public bool HasAnyValidWeapons(Target t) { return Weapons.Any(w => w.IsValidAgainst(self.World, t)); }
public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); } public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); }

View File

@@ -10,6 +10,7 @@
using System; using System;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -40,7 +41,7 @@ namespace OpenRA.Mods.RA
return true; return true;
} }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
var weapon = ChooseWeaponForTarget(newTarget); var weapon = ChooseWeaponForTarget(newTarget);
if( weapon == null ) if( weapon == null )

View File

@@ -11,6 +11,7 @@
using System; using System;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA
self.QueueActivity(new Leap(self, target)); self.QueueActivity(new Leap(self, target));
} }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
var weapon = ChooseWeaponForTarget(newTarget); var weapon = ChooseWeaponForTarget(newTarget);
if( weapon == null ) if( weapon == null )

View File

@@ -10,6 +10,7 @@
using System; using System;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -23,7 +24,7 @@ namespace OpenRA.Mods.RA
public AttackMedic(Actor self, AttackMedicInfo info) public AttackMedic(Actor self, AttackMedicInfo info)
: base( self, info ) {} : base( self, info ) {}
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
var weapon = ChooseWeaponForTarget(newTarget); var weapon = ChooseWeaponForTarget(newTarget);
if( weapon == null ) if( weapon == null )

View File

@@ -73,12 +73,12 @@ namespace OpenRA.Mods.RA
} }
} }
class AttackMoveActivity : CancelableActivity class AttackMoveActivity : Activity
{ {
IActivity inner; Activity inner;
public AttackMoveActivity( IActivity inner ) { this.inner = inner; } public AttackMoveActivity( Activity inner ) { this.inner = inner; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
self.Trait<AutoTarget>().ScanAndAttack(self, true, false); self.Trait<AutoTarget>().ScanAndAttack(self, true, false);

View File

@@ -32,17 +32,17 @@ namespace OpenRA.Mods.RA
return base.CanAttack( self, target ) && !isBuilding; return base.CanAttack( self, target ) && !isBuilding;
} }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
return new SetTarget( newTarget ); return new SetTarget( newTarget );
} }
class SetTarget : CancelableActivity class SetTarget : Activity
{ {
readonly Target target; readonly Target target;
public SetTarget( Target target ) { this.target = target; } public SetTarget( Target target ) { this.target = target; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || !target.IsValid ) if( IsCanceled || !target.IsValid )
return NextActivity; return NextActivity;

View File

@@ -47,17 +47,17 @@ namespace OpenRA.Mods.RA
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime; timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
} }
public override IActivity GetAttackActivity( Actor self, Target newTarget, bool allowMove ) public override Activity GetAttackActivity( Actor self, Target newTarget, bool allowMove )
{ {
return new TeslaAttack( newTarget ); return new TeslaAttack( newTarget );
} }
class TeslaAttack : CancelableActivity class TeslaAttack : Activity
{ {
readonly Target target; readonly Target target;
public TeslaAttack( Target target ) { this.target = target; } public TeslaAttack( Target target ) { this.target = target; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || !target.IsValid ) return NextActivity; if( IsCanceled || !target.IsValid ) return NextActivity;
@@ -70,12 +70,12 @@ namespace OpenRA.Mods.RA
} }
} }
class TeslaZap : CancelableActivity class TeslaZap : Activity
{ {
readonly Target target; readonly Target target;
public TeslaZap( Target target ) { this.target = target; } public TeslaZap( Target target ) { this.target = target; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || !target.IsValid ) return NextActivity; if( IsCanceled || !target.IsValid ) return NextActivity;

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA
DoAttack( self, target ); DoAttack( self, target );
} }
public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove)
{ {
return new AttackActivity( newTarget ); return new AttackActivity( newTarget );
} }
@@ -64,12 +64,12 @@ namespace OpenRA.Mods.RA
bool buildComplete = false; bool buildComplete = false;
public void BuildingComplete(Actor self) { buildComplete = true; } public void BuildingComplete(Actor self) { buildComplete = true; }
class AttackActivity : CancelableActivity class AttackActivity : Activity
{ {
readonly Target target; readonly Target target;
public AttackActivity( Target newTarget ) { this.target = newTarget; } public AttackActivity( Target newTarget ) { this.target = newTarget; }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if( IsCanceled || !target.IsValid ) return NextActivity; if( IsCanceled || !target.IsValid ) return NextActivity;

View File

@@ -10,6 +10,7 @@
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -39,7 +40,7 @@ namespace OpenRA.Mods.RA
}); });
if (info.InitialActivity != null) if (info.InitialActivity != null)
a.QueueActivity(Game.CreateObject<IActivity>(info.InitialActivity)); a.QueueActivity(Game.CreateObject<Activity>(info.InitialActivity));
}); });
} }
} }

View File

@@ -10,13 +10,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Move namespace OpenRA.Mods.RA.Move
{ {
public class Drag : IActivity public class Drag : Activity
{ {
IActivity NextActivity { get; set; }
int2 endLocation; int2 endLocation;
int2 startLocation; int2 startLocation;
int length; int length;
@@ -29,7 +28,7 @@ namespace OpenRA.Mods.RA.Move
} }
int ticks = 0; int ticks = 0;
public IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
var mobile = self.Trait<Mobile>(); var mobile = self.Trait<Mobile>();
mobile.PxPosition = int2.Lerp(startLocation, endLocation, ticks, length - 1); mobile.PxPosition = int2.Lerp(startLocation, endLocation, ticks, length - 1);
@@ -43,19 +42,14 @@ namespace OpenRA.Mods.RA.Move
return this; return this;
} }
public void Cancel(Actor self) { } protected override bool OnCancel(Actor self)
{
public void Queue( IActivity activity ) return false;
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
} }
public IEnumerable<float2> GetCurrentPath() public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
yield return endLocation; yield return Target.FromPos(endLocation);
} }
} }
} }

View File

@@ -457,11 +457,11 @@ namespace OpenRA.Mods.RA.Move
} }
} }
public IActivity ScriptedMove(int2 cell) { return new Move(cell); } public Activity ScriptedMove(int2 cell) { return new Move(cell); }
public IActivity MoveTo(int2 cell, int nearEnough) { return new Move(cell, nearEnough); } public Activity MoveTo(int2 cell, int nearEnough) { return new Move(cell, nearEnough); }
public IActivity MoveTo(int2 cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } public Activity MoveTo(int2 cell, Actor ignoredActor) { return new Move(cell, ignoredActor); }
public IActivity MoveWithinRange(Actor target, int range) { return new Move(target, range); } public Activity MoveWithinRange(Actor target, int range) { return new Move(target, range); }
public IActivity MoveWithinRange(Target target, int range) { return new Move(target, range); } public Activity MoveWithinRange(Target target, int range) { return new Move(target, range); }
public IActivity MoveTo(Func<List<int2>> pathFunc) { return new Move(pathFunc); } public Activity MoveTo(Func<List<int2>> pathFunc) { return new Move(pathFunc); }
} }
} }

View File

@@ -19,7 +19,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Mods.RA.Move namespace OpenRA.Mods.RA.Move
{ {
class Move : CancelableActivity class Move : Activity
{ {
int2? destination; int2? destination;
int nearEnough; int nearEnough;
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA.Move
return path; return path;
} }
public override IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
var mobile = self.Trait<Mobile>(); var mobile = self.Trait<Mobile>();
@@ -239,16 +239,16 @@ namespace OpenRA.Mods.RA.Move
return true; return true;
} }
public override IEnumerable<float2> GetCurrentPath() public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
if( path != null ) if( path != null )
return Enumerable.Reverse(path).Select( c => (float2)Util.CenterOfCell(c) ); return Enumerable.Reverse(path).Select( c => Target.FromCell(c) );
if( destination != null ) if( destination != null )
return new float2[] { destination.Value }; return new Target[] { Target.FromPos(destination.Value) };
return new float2[ 0 ]; return Target.NoTargets;
} }
abstract class MovePart : IActivity abstract class MovePart : Activity
{ {
public readonly Move move; public readonly Move move;
public readonly int2 from, to; public readonly int2 from, to;
@@ -267,17 +267,17 @@ namespace OpenRA.Mods.RA.Move
this.moveFractionTotal = ( ( to - from ) * 3 ).Length; this.moveFractionTotal = ( ( to - from ) * 3 ).Length;
} }
public void Cancel( Actor self ) protected override bool OnCancel( Actor self )
{ {
move.Cancel( self ); return move.OnCancel( self );
} }
public void Queue( IActivity activity ) public override void Queue( Activity activity )
{ {
move.Queue( activity ); move.Queue( activity );
} }
public IActivity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
var mobile = self.Trait<Mobile>(); var mobile = self.Trait<Mobile>();
var ret = InnerTick( self, mobile ); var ret = InnerTick( self, mobile );
@@ -290,7 +290,7 @@ namespace OpenRA.Mods.RA.Move
return ret; return ret;
} }
IActivity InnerTick( Actor self, Mobile mobile ) Activity InnerTick( Actor self, Mobile mobile )
{ {
moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell); moveFraction += mobile.MovementSpeedForCell(self, mobile.toCell);
if( moveFraction <= moveFractionTotal ) if( moveFraction <= moveFractionTotal )
@@ -315,9 +315,9 @@ namespace OpenRA.Mods.RA.Move
protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent ); protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent );
public IEnumerable<float2> GetCurrentPath() public override IEnumerable<Target> GetTargetQueue( Actor self )
{ {
return move.GetCurrentPath(); return move.GetTargetQueue(self);
} }
} }

View File

@@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render; using OpenRA.Mods.RA.Render;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA
bool preventDock = false; bool preventDock = false;
public int2 DeliverOffset { get { return Info.DockOffset; } } public int2 DeliverOffset { get { return Info.DockOffset; } }
public virtual IActivity DockSequence(Actor harv, Actor self) public virtual Activity DockSequence(Actor harv, Actor self)
{ {
return new RAHarvesterDockSequence(harv, self); return new RAHarvesterDockSequence(harv, self);
} }