refactor activity queueing

This commit is contained in:
Bob
2010-09-22 10:13:13 +12:00
parent 271a3eea8d
commit ef665df2e9
37 changed files with 229 additions and 236 deletions

View File

@@ -151,16 +151,9 @@ namespace OpenRA
public void QueueActivity( IActivity nextActivity )
{
if( currentActivity == null )
{
currentActivity = nextActivity;
return;
}
var act = currentActivity;
while( act.NextActivity != null )
{
act = act.NextActivity;
}
act.NextActivity = nextActivity;
else
currentActivity.Queue( nextActivity );
}
public void CancelActivity()

View File

@@ -14,7 +14,7 @@ namespace OpenRA.Traits.Activities
{
public class Drag : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
float2 endLocation;
float2 startLocation;
@@ -40,5 +40,13 @@ namespace OpenRA.Traits.Activities
}
public void Cancel(Actor self) { }
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -12,9 +12,17 @@ namespace OpenRA.Traits.Activities
{
class Idle : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
public IActivity Tick(Actor self) { return NextActivity; }
public void Cancel(Actor self) {}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Traits.Activities
{
public class Move : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
int2? destination;
int nearEnough;
@@ -164,9 +164,7 @@ namespace OpenRA.Traits.Activities
Log.Write("debug", "Turn: #{0} from {1} to {2}",
self.ActorID, mobile.Facing, firstFacing);
return new Turn( firstFacing )
{ NextActivity = this }
.Tick( self );
return Util.SequenceActivities( new Turn( firstFacing ), this ).Tick( self );
}
else
{
@@ -261,6 +259,14 @@ namespace OpenRA.Traits.Activities
NextActivity = null;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
abstract class MovePart : IActivity
{
public readonly Move move;
@@ -280,11 +286,14 @@ namespace OpenRA.Traits.Activities
this.moveFractionTotal = (int)(( to - from ).Length*3);
}
public IActivity NextActivity { get { return move; } set { move.NextActivity = value; } }
public void Cancel( Actor self )
{
NextActivity.Cancel( self );
move.Cancel( self );
}
public void Queue( IActivity activity )
{
move.Queue( activity );
}
public IActivity Tick( Actor self )

View File

@@ -10,18 +10,13 @@
namespace OpenRA.Traits.Activities
{
public class RemoveSelf : IActivity
public class RemoveSelf : CancelableActivity
{
bool isCanceled;
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
self.Destroy();
return null;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -12,7 +12,7 @@ namespace OpenRA.Traits.Activities
{
class Sell : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
bool started;
@@ -55,5 +55,13 @@ namespace OpenRA.Traits.Activities
}
public void Cancel(Actor self) { /* never gonna give you up.. */ }
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -12,9 +12,8 @@ using System.Linq;
namespace OpenRA.Traits.Activities
{
public class Turn : IActivity
public class Turn : CancelableActivity
{
public IActivity NextActivity { get; set; }
int desiredFacing;
public Turn( int desiredFacing )
@@ -22,8 +21,9 @@ namespace OpenRA.Traits.Activities
this.desiredFacing = desiredFacing;
}
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if (IsCanceled) return NextActivity;
var facing = self.Trait<IFacing>();
if( desiredFacing == facing.Facing )
@@ -32,11 +32,5 @@ namespace OpenRA.Traits.Activities
return this;
}
public void Cancel( Actor self )
{
desiredFacing = self.Trait<IFacing>().Facing;
NextActivity = null;
}
}
}

View File

@@ -170,9 +170,33 @@ namespace OpenRA.Traits
public interface IActivity
{
IActivity NextActivity { get; set; }
IActivity Tick(Actor self);
void Cancel(Actor self);
void Queue(IActivity activity);
}
public abstract class CancelableActivity : IActivity
{
protected IActivity NextActivity { get; private set; }
protected bool IsCanceled { get; private set; }
public abstract IActivity Tick( Actor self );
protected virtual void OnCancel() {}
public void Cancel( Actor self )
{
IsCanceled = true;
NextActivity = null;
OnCancel();
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
public interface IRenderOverlay { void Render(); }

View File

@@ -113,7 +113,7 @@ namespace OpenRA.Traits
public static IActivity SequenceActivities(params IActivity[] acts)
{
return acts.Reverse().Aggregate(
(next, a) => { a.NextActivity = next; return a; });
(next, a) => { a.Queue( next ); return a; });
}
public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
/* non-turreted attack */
public class Attack : IActivity
public class Attack : CancelableActivity
{
Target Target;
int Range;
@@ -26,10 +26,11 @@ namespace OpenRA.Mods.RA.Activities
Range = range;
}
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if (IsCanceled) return NextActivity;
var facing = self.Trait<IFacing>();
if (!Target.IsValid)
return NextActivity;
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities
var targetCell = Util.CellContaining(Target.CenterLocation);
if ((targetCell - self.Location).LengthSquared >= Range * Range)
return new Move( Target, Range ) { NextActivity = this };
return Util.SequenceActivities( new Move( Target, Range ), this );
var desiredFacing = Util.GetFacing((targetCell - self.Location).ToFloat2(), 0);
var renderUnit = self.TraitOrDefault<RenderUnit>();
@@ -47,7 +48,7 @@ namespace OpenRA.Mods.RA.Activities
if (Util.QuantizeFacing(facing.Facing, numDirs)
!= Util.QuantizeFacing(desiredFacing, numDirs))
{
return new Turn( desiredFacing ) { NextActivity = this };
return Util.SequenceActivities( new Turn( desiredFacing ), this );
}
var attack = self.Trait<AttackBase>();
@@ -55,7 +56,5 @@ namespace OpenRA.Mods.RA.Activities
attack.DoAttack(self);
return this;
}
public void Cancel(Actor self) { Target = Target.None; }
}
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Activities
Action a;
bool interruptable;
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
{
@@ -40,5 +40,13 @@ namespace OpenRA.Mods.RA.Activities
a = null;
NextActivity = null;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -12,16 +12,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class CaptureBuilding : IActivity
class CaptureBuilding : CancelableActivity
{
Target target;
public CaptureBuilding(Actor target) { this.target = Target.FromActor(target); }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if (!target.IsValid) return NextActivity;
if ((target.Actor.Location - self.Location).Length > 1)
return NextActivity;
@@ -41,7 +40,5 @@ namespace OpenRA.Mods.RA.Activities
});
return NextActivity;
}
public void Cancel(Actor self) { target = Target.None; NextActivity = null; }
}
}

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA.Activities
{
public class DeliverResources : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
bool isDocking;
@@ -32,25 +32,33 @@ namespace OpenRA.Mods.RA.Activities
harv.ChooseNewProc(self, null);
if (harv.LinkedProc == null) // no procs exist; check again in 1s.
return new Wait(25) { NextActivity = this };
return Util.SequenceActivities( new Wait(25), this );
var proc = harv.LinkedProc;
if( self.Location != proc.Location + proc.Trait<IAcceptOre>().DeliverOffset )
{
return new Move(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0) { NextActivity = this };
return Util.SequenceActivities( new Move(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0), this );
}
else if (!isDocking)
{
isDocking = true;
proc.Trait<IAcceptOre>().OnDock(self, this);
}
return new Wait(10) { NextActivity = this };
return Util.SequenceActivities( new Wait(10), this );
}
public void Cancel(Actor self)
{
// TODO: allow canceling of deliver orders?
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -13,15 +13,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class Demolish : IActivity
class Demolish : CancelableActivity
{
Target target;
public IActivity NextActivity { get; set; }
public Demolish( Actor target ) { this.target = Target.FromActor(target); }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if( IsCanceled ) return NextActivity;
if (!target.IsValid) return NextActivity;
if ((target.Actor.Location - self.Location).Length > 1)
return NextActivity;
@@ -31,7 +31,5 @@ namespace OpenRA.Mods.RA.Activities
() => { if (target.IsValid) target.Actor.Kill(self); })));
return NextActivity;
}
public void Cancel(Actor self) { target = Target.None; NextActivity = null; }
}
}

View File

@@ -12,10 +12,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class EnterTransport : IActivity
class EnterTransport : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
public Actor transport;
public EnterTransport(Actor self, Actor transport)
@@ -23,9 +21,9 @@ namespace OpenRA.Mods.RA.Activities
this.transport = transport;
}
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
if (transport == null || !transport.IsInWorld) return NextActivity;
var cargo = transport.Trait<Cargo>();
@@ -43,7 +41,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -14,21 +14,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Fly : IActivity
public class Fly : CancelableActivity
{
public readonly float2 Pos;
bool isCanceled;
public Fly(float2 pos) { Pos = pos; }
public Fly(int2 pos) { Pos = Util.CenterOfCell(pos); }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
var d = Pos - self.CenterLocation;
if (d.LengthSquared < 50) /* close enough */
@@ -46,8 +43,6 @@ namespace OpenRA.Mods.RA.Activities
FlyUtil.Fly(self, cruiseAltitude);
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
public static class FlyUtil

View File

@@ -12,15 +12,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class FlyAttack : IActivity
public class FlyAttack : CancelableActivity
{
public IActivity NextActivity { get; set; }
Target Target;
public FlyAttack(Target target) { Target = target; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if (!Target.IsValid)
return NextActivity;
@@ -33,29 +33,22 @@ namespace OpenRA.Mods.RA.Activities
new FlyTimed(50),
this);
}
public void Cancel(Actor self) { Target = Target.None; NextActivity = null; }
}
public class FlyCircle : IActivity
public class FlyCircle : CancelableActivity
{
public IActivity NextActivity { get; set; }
int2 Target;
bool isCanceled;
public FlyCircle(int2 target) { Target = target; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled)
return NextActivity;
if( IsCanceled ) return NextActivity;
return Util.SequenceActivities(
new Fly(Util.CenterOfCell(Target)),
new FlyTimed(50),
this);
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -12,27 +12,25 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class FlyTimed : IActivity
public class FlyTimed : CancelableActivity
{
public IActivity NextActivity { get; set; }
int remainingTicks;
public FlyTimed(int ticks) { remainingTicks = ticks; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if( IsCanceled ) return NextActivity;
var targetAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
if (remainingTicks-- == 0) return NextActivity;
FlyUtil.Fly(self, targetAltitude);
return this;
}
public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; }
}
public class FlyOffMap : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
bool isCanceled;
public bool Interruptible = true;
@@ -52,6 +50,13 @@ namespace OpenRA.Mods.RA.Activities
NextActivity = null;
}
}
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class Follow : IActivity
public class Follow : CancelableActivity
{
Target Target;
int Range;
@@ -24,24 +24,18 @@ namespace OpenRA.Mods.RA.Activities
Range = range;
}
public IActivity NextActivity { get; set; }
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if (!Target.IsValid)
return NextActivity;
if (IsCanceled) return NextActivity;
if (!Target.IsValid) return NextActivity;
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
if( !inRange )
return new Move( Target, Range ) { NextActivity = this };
if( inRange ) return this;
return this;
}
public void Cancel(Actor self)
{
Target = Target.None;
var ret = new Move( Target, Range );
ret.Queue( this );
return ret;
}
}
}

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Activities
{
public class Harvest : IActivity
{
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
bool isHarvesting = false;
public IActivity Tick( Actor self )
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities
harv.LastHarvestedCell = self.Location;
if( harv.IsFull )
return new DeliverResources { NextActivity = NextActivity };
return Util.SequenceActivities( new DeliverResources(), NextActivity );
if (HarvestThisTile(self))
return this;
@@ -74,5 +74,13 @@ namespace OpenRA.Mods.RA.Activities
}
public void Cancel(Actor self) { }
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -14,17 +14,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class HeliAttack : IActivity
public class HeliAttack : CancelableActivity
{
Target target;
public HeliAttack( Target target ) { this.target = target; }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (!target.IsValid)
return NextActivity;
if (IsCanceled) return NextActivity;
if (!target.IsValid) return NextActivity;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
@@ -53,7 +51,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { target = Target.None; NextActivity = null; }
}
}

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class HeliFly : IActivity
class HeliFly : CancelableActivity
{
public readonly float2 Dest;
public HeliFly(float2 dest)
@@ -22,13 +22,9 @@ namespace OpenRA.Mods.RA.Activities
Dest = dest;
}
public IActivity NextActivity { get; set; }
bool isCanceled;
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled)
return NextActivity;
if (IsCanceled) return NextActivity;
var info = self.Info.Traits.Get<HelicopterInfo>();
var aircraft = self.Trait<Aircraft>();
@@ -57,7 +53,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -12,17 +12,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class HeliLand : IActivity
class HeliLand : CancelableActivity
{
public HeliLand(bool requireSpace) { this.requireSpace = requireSpace; }
bool requireSpace;
bool isCanceled;
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
var aircraft = self.Trait<Aircraft>();
if (aircraft.Altitude == 0)
return NextActivity;
@@ -33,7 +31,5 @@ namespace OpenRA.Mods.RA.Activities
--aircraft.Altitude;
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -14,11 +14,8 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class HeliReturn : IActivity
public class HeliReturn : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
static Actor ChooseHelipad(Actor self)
{
var rearmBuildings = self.Info.Traits.Get<HelicopterInfo>().RearmBuildings;
@@ -27,9 +24,9 @@ namespace OpenRA.Mods.RA.Activities
!Reservable.IsReserved(a));
}
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
var dest = ChooseHelipad(self);
var initialFacing = self.Info.Traits.Get<AircraftInfo>().InitialFacing;
@@ -54,7 +51,5 @@ namespace OpenRA.Mods.RA.Activities
new Rearm(),
NextActivity);
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
this.delay = delay;
}
public IActivity NextActivity { get; set; }
IActivity NextActivity { get; set; }
bool active = true;
public IActivity Tick(Actor self)
@@ -43,5 +43,13 @@ namespace OpenRA.Mods.RA.Activities
active = false;
NextActivity = null;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -12,14 +12,14 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class Infiltrate : IActivity
class Infiltrate : CancelableActivity
{
Actor target;
public Infiltrate(Actor target) { this.target = target; }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if (target == null || target.IsDead()) return NextActivity;
if (target.Owner == self.Owner) return NextActivity;
@@ -30,7 +30,5 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
}
public void Cancel(Actor self) { target = null; NextActivity = null; }
}
}

View File

@@ -14,21 +14,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Land : IActivity
public class Land : CancelableActivity
{
bool isCanceled;
Target Target;
public Land(Target t) { Target = t; }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (!Target.IsValid)
Cancel(self);
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
var d = Target.CenterLocation - self.CenterLocation;
if (d.LengthSquared < 50) /* close enough */
@@ -49,7 +46,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -17,14 +17,11 @@ namespace OpenRA.Mods.RA.Activities
{
// assumes you have Minelayer on that unit
class LayMines : IActivity
class LayMines : CancelableActivity
{
bool canceled = false;
public IActivity NextActivity { get; set; }
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if (canceled) return NextActivity;
if (IsCanceled) return NextActivity;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (!limitedAmmo.HasAmmo())
@@ -37,8 +34,11 @@ namespace OpenRA.Mods.RA.Activities
if (rearmTarget == null)
return new Wait(20);
return new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget)
{ NextActivity = new Rearm() { NextActivity = new Repair(rearmTarget) { NextActivity = this } } };
return Util.SequenceActivities(
new Move(Util.CellContaining(rearmTarget.CenterLocation), rearmTarget),
new Rearm(),
new Repair(rearmTarget),
this );
}
var ml = self.Trait<Minelayer>();
@@ -46,14 +46,14 @@ namespace OpenRA.Mods.RA.Activities
ShouldLayMine(self, self.Location))
{
LayMine(self);
return new Wait(20) { NextActivity = this }; // a little wait after placing each mine, for show
return Util.SequenceActivities( new Wait(20), this ); // a little wait after placing each mine, for show
}
for (var n = 0; n < 20; n++) // dont get stuck forever here
{
var p = ml.minefield.Random(self.World.SharedRandom);
if (ShouldLayMine(self, p))
return new Move(p, 0) { NextActivity = this };
return Util.SequenceActivities( new Move(p, 0), this );
}
// todo: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield.
@@ -80,7 +80,5 @@ namespace OpenRA.Mods.RA.Activities
new OwnerInit( self.Owner ),
}));
}
public void Cancel( Actor self ) { canceled = true; NextActivity = null; }
}
}

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class Leap : IActivity
class Leap : CancelableActivity
{
Target target;
float2 initialLocation;
@@ -31,12 +31,10 @@ namespace OpenRA.Mods.RA.Activities
Sound.Play("dogg5p.aud", self.CenterLocation);
}
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (!target.IsValid)
return NextActivity;
if (IsCanceled) return NextActivity;
if (!target.IsValid) return NextActivity;
t += (1f / delay);
@@ -54,7 +52,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { target = new Target(); NextActivity = null; }
}
}

View File

@@ -14,17 +14,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Rearm : IActivity
public class Rearm : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
int remainingTicks = ticksPerPip;
const int ticksPerPip = 25 * 2;
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (limitedAmmo == null) return NextActivity;
@@ -43,7 +41,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -14,18 +14,16 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Repair : IActivity
public class Repair : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
int remainingTicks;
Actor host;
public Repair(Actor host) { this.host = host; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
if (host != null && !host.IsInWorld) return NextActivity;
if (remainingTicks == 0)
{
@@ -58,7 +56,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -12,16 +12,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
class RepairBuilding : IActivity
class RepairBuilding : CancelableActivity
{
Target target;
public RepairBuilding(Actor target) { this.target = Target.FromActor(target); }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if (!target.IsValid) return NextActivity;
if ((target.Actor.Location - self.Location).Length > 1)
return NextActivity;
@@ -35,7 +34,5 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
}
public void Cancel(Actor self) { target = Target.None; NextActivity = null; }
}
}

View File

@@ -14,11 +14,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class ReturnToBase : IActivity
public class ReturnToBase : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
bool isCalculated;
Actor dest;
@@ -88,9 +85,9 @@ namespace OpenRA.Mods.RA.Activities
this.dest = dest;
}
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
if (!isCalculated)
Calculate(self);
@@ -101,7 +98,5 @@ namespace OpenRA.Mods.RA.Activities
new Land(Target.FromActor(dest)),
NextActivity);
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -13,10 +13,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Teleport : IActivity
public class Teleport : CancelableActivity
{
public IActivity NextActivity { get; set; }
int2 destination;
public Teleport(int2 destination)
@@ -24,12 +22,10 @@ namespace OpenRA.Mods.RA.Activities
this.destination = destination;
}
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
self.TraitsImplementing<IMove>().FirstOrDefault().SetPosition(self, destination);
return NextActivity;
}
public void Cancel(Actor self) { }
}
}

View File

@@ -17,12 +17,11 @@ using OpenRA.FileFormats;
namespace OpenRA.Mods.RA.Activities
{
class Transform : IActivity
class Transform : CancelableActivity
{
string actor = null;
int2 offset;
string[] sounds = null;
bool isCanceled;
int facing;
RenderBuilding rb;
@@ -35,9 +34,6 @@ namespace OpenRA.Mods.RA.Activities
rb = self.TraitOrDefault<RenderBuilding>();
}
public IActivity NextActivity { get; set; }
void DoTransform(Actor self)
{
// Hack: repeat the first frame of the make anim instead
@@ -70,9 +66,9 @@ namespace OpenRA.Mods.RA.Activities
}
bool started = false;
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
if (started) return this;
if (rb == null)
@@ -88,7 +84,5 @@ namespace OpenRA.Mods.RA.Activities
}
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -16,11 +16,8 @@ using System.Drawing;
namespace OpenRA.Mods.RA.Activities
{
public class UnloadCargo : IActivity
public class UnloadCargo : CancelableActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
int2? ChooseExitTile(Actor self, Actor cargo)
{
// is anyone still hogging this tile?
@@ -38,16 +35,16 @@ namespace OpenRA.Mods.RA.Activities
return null;
}
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (IsCanceled) return NextActivity;
// if we're a thing that can turn, turn to the
// right facing for the unload animation
var facing = self.TraitOrDefault<IFacing>();
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
if (facing != null && facing.Facing != unloadFacing)
return new Turn(unloadFacing) { NextActivity = this };
return Util.SequenceActivities( new Turn(unloadFacing), this );
// todo: handle the BS of open/close sequences, which are inconsistent,
// for reasons that probably make good sense to the westwood guys.
@@ -82,7 +79,5 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public void Cancel(Actor self) { NextActivity = null; isCanceled = true; }
}
}

View File

@@ -16,6 +16,7 @@ namespace OpenRA.Mods.RA.Activities
{
int remainingTicks;
bool interruptable = true;
IActivity NextActivity { get; set; }
public Wait(int period) { remainingTicks = period; }
public Wait(int period, bool interruptable)
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.RA.Activities
this.interruptable = interruptable;
}
public IActivity Tick(Actor self)
public virtual IActivity Tick(Actor self)
{
if (remainingTicks-- == 0) return NextActivity;
return this;
@@ -38,6 +39,13 @@ namespace OpenRA.Mods.RA.Activities
remainingTicks = 0;
NextActivity = null;
}
public IActivity NextActivity { get; set; }
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}