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

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

View File

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

View File

@@ -14,13 +14,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class CaptureActor : CancelableActivity
class CaptureActor : Activity
{
Actor 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 (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

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

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class Demolish : CancelableActivity
class Demolish : Activity
{
Actor target;
int delay;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
this.delay = delay;
}
public override IActivity Tick(Actor self)
public override Activity Tick(Actor self)
{
if (IsCanceled) 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
{
class DonateSupplies : CancelableActivity
class DonateSupplies : Activity
{
Actor target;
int payload;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
this.payload = payload;
}
public override IActivity Tick(Actor self)
public override Activity Tick(Actor self)
{
if (IsCanceled) 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
{
public class Enter : CancelableActivity
public class Enter : Activity
{
readonly Actor 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 )
return NextActivity;

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class EnterTransport : CancelableActivity
class EnterTransport : Activity
{
public Actor transport;
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Activities
this.transport = transport;
}
public override IActivity Tick(Actor self)
public override Activity Tick(Actor self)
{
if (IsCanceled) 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
{
public class Follow : CancelableActivity
public class Follow : Activity
{
Target Target;
int Range;
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities
Range = range;
}
public override IActivity Tick( Actor self )
public override Activity Tick( Actor self )
{
if (IsCanceled) return NextActivity;
if (!Target.IsValid) return NextActivity;

View File

@@ -13,14 +13,15 @@ using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
using System.Collections.Generic;
namespace OpenRA.Mods.RA.Activities
{
public class Harvest : CancelableActivity
public class Harvest : Activity
{
bool isHarvesting = false;
public override IActivity Tick( Actor self )
public override Activity Tick( Actor self )
{
if( isHarvesting ) return this;
if( IsCanceled ) return NextActivity;
@@ -74,5 +75,10 @@ namespace OpenRA.Mods.RA.Activities
}));
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)
: 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)
return NextActivity;

View File

@@ -14,12 +14,12 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class Infiltrate : CancelableActivity
class Infiltrate : Activity
{
Actor 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 (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
class LayMines : CancelableActivity
class LayMines : Activity
{
public override IActivity Tick( Actor self )
public override Activity Tick( Actor self )
{
if (IsCanceled) return NextActivity;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class Leap : CancelableActivity
class Leap : Activity
{
Target target;
int2 initialLocation;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Activities
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 (!target.IsValid) return NextActivity;

View File

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

View File

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

View File

@@ -11,26 +11,24 @@
using System;
using System.Collections.Generic;
using OpenRA.Traits;
using OpenRA.Traits.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, bool interruptable)
{
this.a = a;
this.interruptable = interruptable;
}
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)
a(this);
@@ -38,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity;
}
public void Insert(IActivity activity)
public void Insert( Activity activity )
{
if (activity == null)
return;
@@ -46,29 +44,12 @@ namespace OpenRA.Mods.RA.Activities
NextActivity = activity;
}
public void Cancel(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()
public override IEnumerable<Target> GetTargetQueue( Actor self )
{
if (NextActivity != null)
foreach (var path in NextActivity.GetCurrentPath())
foreach (var target in NextActivity.GetTargetQueue(self))
{
yield return path;
yield return target;
}
yield break;

View File

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

View File

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

View File

@@ -13,9 +13,9 @@ using OpenRA.Traits.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;
self.Destroy();

View File

@@ -15,14 +15,14 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class Repair : CancelableActivity
public class Repair : Activity
{
int remainingTicks;
Actor 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 (host != null && !host.IsInWorld) return NextActivity;

View File

@@ -14,13 +14,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
class RepairBuilding : CancelableActivity
class RepairBuilding : Activity
{
Actor 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 (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;

View File

@@ -16,9 +16,9 @@ using OpenRA.Mods.RA.Buildings;
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 si = self.Info.Traits.Get<SellableInfo>();

View File

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

View File

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

View File

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

View File

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

View File

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