make more activities cancelable. remove many uses of CurrentActivity is T

This commit is contained in:
Bob
2010-09-22 11:53:58 +12:00
parent e2eae7973b
commit c16a515224
19 changed files with 95 additions and 101 deletions

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
@@ -48,5 +49,10 @@ namespace OpenRA.Mods.RA.Activities
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
}
}
}

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
@@ -60,5 +61,10 @@ namespace OpenRA.Mods.RA.Activities
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
}
}
}

View File

@@ -9,7 +9,7 @@
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
@@ -43,6 +43,11 @@ namespace OpenRA.Mods.RA.Activities
FlyUtil.Fly(self, cruiseAltitude);
return this;
}
public override IEnumerable<float2> GetCurrentPath()
{
yield return Pos;
}
}
public static class FlyUtil

View File

@@ -28,35 +28,21 @@ namespace OpenRA.Mods.RA.Activities
}
}
public class FlyOffMap : IActivity
public class FlyOffMap : CancelableActivity
{
IActivity NextActivity { get; set; }
bool isCanceled;
public bool Interruptible = true;
public IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
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);
return this;
}
public void Cancel(Actor self)
protected override bool OnCancel()
{
if (Interruptible)
{
isCanceled = true;
NextActivity = null;
}
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
return Interruptible;
}
}
}

View File

@@ -15,14 +15,14 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Activities
{
public class Harvest : IActivity
public class Harvest : CancelableActivity
{
IActivity NextActivity { get; set; }
bool isHarvesting = false;
public IActivity Tick( Actor self )
public override IActivity Tick( Actor self )
{
if( isHarvesting ) return this;
if( IsCanceled ) return NextActivity;
if( NextActivity != null ) return NextActivity;
var harv = self.Trait<Harvester>();
@@ -72,15 +72,5 @@ namespace OpenRA.Mods.RA.Activities
}));
self.QueueActivity(new Harvest());
}
public void Cancel(Actor self) { }
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
}
}
}

View File

@@ -9,7 +9,7 @@
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
@@ -53,5 +53,10 @@ namespace OpenRA.Mods.RA.Activities
return this;
}
public override IEnumerable<float2> GetCurrentPath()
{
yield return Dest;
}
}
}

View File

@@ -6,11 +6,11 @@
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
#endregion
using System.Collections.Generic;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA.Activities
{
@@ -51,5 +51,10 @@ namespace OpenRA.Mods.RA.Activities
else
NextActivity = activity;
}
public IEnumerable<float2> GetCurrentPath()
{
yield break;
}
}
}

View File

@@ -33,9 +33,11 @@ namespace OpenRA.Mods.RA.Activities
public override IActivity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if( t == 0 && IsCanceled ) return NextActivity;
if (!target.IsValid) return NextActivity;
self.Trait<AttackLeap>().IsLeaping = true;
t += (1f / delay);
self.CenterLocation = float2.Lerp(initialLocation, target.CenterLocation, t);
@@ -47,6 +49,7 @@ namespace OpenRA.Mods.RA.Activities
if (target.IsActor)
target.Actor.Kill(self);
self.Trait<AttackLeap>().IsLeaping = false;
return NextActivity;
}

View File

@@ -12,11 +12,10 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{
public class Wait : IActivity
public class Wait : CancelableActivity
{
int remainingTicks;
bool interruptable = true;
IActivity NextActivity { get; set; }
public Wait(int period) { remainingTicks = period; }
public Wait(int period, bool interruptable)
@@ -25,27 +24,17 @@ namespace OpenRA.Mods.RA.Activities
this.interruptable = interruptable;
}
public virtual IActivity Tick(Actor self)
public override IActivity Tick(Actor self)
{
if (remainingTicks-- == 0) return NextActivity;
return this;
}
public void Cancel(Actor self)
protected override bool OnCancel()
{
if (!interruptable)
return;
if( !interruptable ) return false;
remainingTicks = 0;
NextActivity = null;
}
public void Queue( IActivity activity )
{
if( NextActivity != null )
NextActivity.Queue( activity );
else
NextActivity = activity;
return true;
}
}
}

View File

@@ -70,14 +70,6 @@ namespace OpenRA.Mods.RA
|| Info.RepairBuildings.Contains( a.Info.Name );
}
public virtual IEnumerable<float2> GetCurrentPath(Actor self)
{
var move = self.GetCurrentActivity() as Activities.Fly;
if (move == null) return new float2[] { };
return new float2[] { move.Pos };
}
public bool CanEnterCell(int2 location) { return true; }
public float MovementSpeedForCell(Actor self, int2 cell)

View File

@@ -19,6 +19,8 @@ namespace OpenRA.Mods.RA
class AttackLeap : AttackBase
{
internal bool IsLeaping;
public AttackLeap(Actor self)
: base(self) {}
@@ -27,7 +29,7 @@ namespace OpenRA.Mods.RA
base.Tick(self);
if (!target.IsValid) return;
if (self.GetCurrentActivity() is Leap) return;
if (IsLeaping) return;
var weapon = self.Trait<AttackBase>().Weapons[0].Info;
if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize

View File

@@ -171,13 +171,5 @@ namespace OpenRA.Mods.RA
return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
return (5 / d.LengthSquared) * d;
}
public override IEnumerable<float2> GetCurrentPath(Actor self)
{
var move = self.GetCurrentActivity() as Activities.HeliFly;
if (move == null) return new float2[] { };
return new float2[] { move.Dest };
}
}
}