Tidy up Activity.Cancel(), make Tick abstract

This commit is contained in:
Paul Chote
2011-04-16 13:18:22 +12:00
parent 0a67c68c45
commit 4f83e994d0
14 changed files with 47 additions and 54 deletions

View File

@@ -5,24 +5,17 @@ using System.Text;
namespace OpenRA.Traits.Activities namespace OpenRA.Traits.Activities
{ {
public class Activity public abstract class Activity
{ {
public Activity NextActivity { get; set; } public Activity NextActivity { get; set; }
protected bool IsCanceled { get; private set; } protected bool IsCanceled { get; private set; }
public virtual Activity Tick( Actor self ) public abstract Activity Tick( Actor self );
{
return this;
}
protected virtual bool OnCancel( Actor self ) { return true; }
public virtual void Cancel( Actor self ) public virtual void Cancel( Actor self )
{ {
IsCanceled = OnCancel( self ); IsCanceled = true;
if( IsCanceled ) NextActivity = null;
NextActivity = null;
else if (NextActivity != null)
NextActivity.Cancel( self );
} }
public virtual void Queue( Activity activity ) public virtual void Queue( Activity activity )

View File

@@ -80,10 +80,10 @@ namespace OpenRA.Mods.Cnc
throw new InvalidOperationException("Invalid harvester dock state"); throw new InvalidOperationException("Invalid harvester dock state");
} }
protected override bool OnCancel(Actor self) public override void Cancel(Actor self)
{ {
state = State.Undock; state = State.Undock;
return true; base.Cancel(self);
} }
public override IEnumerable<Target> GetTargets( Actor self ) public override IEnumerable<Target> GetTargets( Actor self )

View File

@@ -33,13 +33,10 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity; return NextActivity;
} }
protected override bool OnCancel(Actor self) public override void Cancel(Actor self)
{ {
if (!interruptable) if (interruptable)
return false; base.Cancel(self);
a = null;
return true;
} }
} }
} }

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
// TODO: wtf is this?
if( NextActivity != null ) if( NextActivity != null )
return NextActivity; return NextActivity;
@@ -48,11 +49,8 @@ namespace OpenRA.Mods.RA.Activities
} }
return Util.SequenceActivities( new Wait(10), this ); return Util.SequenceActivities( new Wait(10), this );
} }
protected override bool OnCancel(Actor self) // Cannot be cancelled
{ public override void Cancel(Actor self) { }
// TODO: allow canceling of deliver orders?
return false;
}
} }
} }

View File

@@ -30,7 +30,6 @@ namespace OpenRA.Mods.RA.Activities
bool started = false; bool started = false;
public override Activity Tick( Actor self ) public override Activity Tick( Actor self )
{ {
if (IsCanceled) return NextActivity;
if (!started) if (!started)
{ {
var rb = self.Trait<RenderBuilding>(); var rb = self.Trait<RenderBuilding>();
@@ -51,7 +50,7 @@ namespace OpenRA.Mods.RA.Activities
return complete ? NextActivity : this; return complete ? NextActivity : this;
} }
// Not actually cancellable // Cannot be cancelled
protected override bool OnCancel( Actor self ) { return false; } public override void Cancel( Actor self ) { }
} }
} }

View File

@@ -70,10 +70,10 @@ namespace OpenRA.Mods.RA
throw new InvalidOperationException("Invalid harvester dock state"); throw new InvalidOperationException("Invalid harvester dock state");
} }
protected override bool OnCancel(Actor self) public override void Cancel(Actor self)
{ {
state = State.Undock; state = State.Undock;
return true; base.Cancel(self);
} }
public override IEnumerable<Target> GetTargets( Actor self ) public override IEnumerable<Target> GetTargets( Actor self )

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities
return this; return this;
} }
// Not actually cancellable // Cannot be cancelled
protected override bool OnCancel( Actor self ) { return false; } public override void Cancel( Actor self ) { }
} }
} }

View File

@@ -27,15 +27,16 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
if (remainingTicks-- == 0) return NextActivity; return (remainingTicks-- == 0) ? NextActivity: this;
return this;
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
if( !interruptable ) return false; if( !interruptable )
return;
remainingTicks = 0; remainingTicks = 0;
return true; base.Cancel(self);
} }
} }
} }

View File

@@ -73,6 +73,7 @@ namespace OpenRA.Mods.RA.Air
return this; return this;
} }
protected override bool OnCancel(Actor self) { return false; } // Cannot be cancelled
public override void Cancel( Actor self ) { }
} }
} }

View File

@@ -44,11 +44,12 @@ namespace OpenRA.Mods.RA.Air
return this; return this;
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
if( inner != null ) if( inner != null )
inner.Cancel( self ); inner.Cancel( self );
return base.OnCancel( self );
base.Cancel( self );
} }
} }

View File

@@ -36,14 +36,17 @@ namespace OpenRA.Mods.RA.Air
public override Activity 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;
FlyUtil.Fly(self, targetAltitude); FlyUtil.Fly(self, targetAltitude);
return this; return this;
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
return Interruptible; if (Interruptible)
base.Cancel(self);
} }
} }
} }

View File

@@ -90,11 +90,12 @@ namespace OpenRA.Mods.RA
return this; return this;
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
if( inner != null ) if( inner != null )
inner.Cancel( self ); inner.Cancel( self );
return base.OnCancel( self );
base.Cancel( self );
} }
} }
} }

View File

@@ -42,14 +42,12 @@ namespace OpenRA.Mods.RA.Move
return this; return this;
} }
protected override bool OnCancel(Actor self)
{
return false;
}
public override IEnumerable<Target> GetTargets( Actor self ) public override IEnumerable<Target> GetTargets( Actor self )
{ {
yield return Target.FromPos(endLocation); yield return Target.FromPos(endLocation);
} }
// Cannot be cancelled
public override void Cancel( Actor self ) { }
} }
} }

View File

@@ -233,10 +233,10 @@ namespace OpenRA.Mods.RA.Move
return Pair.New(nextCell, subCell); return Pair.New(nextCell, subCell);
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
path = new List<int2>(); path = new List<int2>();
return true; base.Cancel(self);
} }
public override IEnumerable<Target> GetTargets( Actor self ) public override IEnumerable<Target> GetTargets( Actor self )
@@ -267,9 +267,10 @@ namespace OpenRA.Mods.RA.Move
this.moveFractionTotal = ( ( to - from ) * 3 ).Length; this.moveFractionTotal = ( ( to - from ) * 3 ).Length;
} }
protected override bool OnCancel( Actor self ) public override void Cancel( Actor self )
{ {
return move.OnCancel( self ); move.Cancel( self );
base.Cancel( self );
} }
public override void Queue( Activity activity ) public override void Queue( Activity activity )