make more activities cancelable. remove many uses of CurrentActivity is T
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits.Activities
|
||||
{
|
||||
@@ -48,5 +48,10 @@ namespace OpenRA.Traits.Activities
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield return endLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,8 @@
|
||||
|
||||
namespace OpenRA.Traits.Activities
|
||||
{
|
||||
class Idle : IActivity
|
||||
class Idle : CancelableActivity
|
||||
{
|
||||
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;
|
||||
}
|
||||
public override IActivity Tick(Actor self) { return NextActivity; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,9 +247,17 @@ namespace OpenRA.Traits.Activities
|
||||
return nextCell;
|
||||
}
|
||||
|
||||
protected override void OnCancel()
|
||||
protected override bool OnCancel()
|
||||
{
|
||||
path = new List<int2>();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
if( path == null )
|
||||
return new float2[ 0 ];
|
||||
return Enumerable.Reverse(path).Select( c => Util.CenterOfCell(c) );
|
||||
}
|
||||
|
||||
abstract class MovePart : IActivity
|
||||
@@ -312,6 +320,11 @@ namespace OpenRA.Traits.Activities
|
||||
}
|
||||
|
||||
protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent );
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
return move.GetCurrentPath();
|
||||
}
|
||||
}
|
||||
|
||||
class MoveFirstHalf : MovePart
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits.Activities
|
||||
{
|
||||
class Sell : IActivity
|
||||
@@ -63,5 +65,10 @@ namespace OpenRA.Traits.Activities
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,14 +321,6 @@ namespace OpenRA.Traits
|
||||
return Info.Speed * Info.TerrainSpeeds[type].Speed * modifier / 100f;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath(Actor self)
|
||||
{
|
||||
var move = self.GetCurrentActivity() as Move;
|
||||
if (move == null || move.path == null) return new float2[] { };
|
||||
|
||||
return Enumerable.Reverse(move.path).Select( c => Util.CenterOfCell(c) );
|
||||
}
|
||||
|
||||
public void AddInfluence()
|
||||
{
|
||||
uim.Add( self, this );
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace OpenRA.Traits
|
||||
if (mobile != null)
|
||||
{
|
||||
var alt = new float2(0, -mobile.Altitude);
|
||||
var path = mobile.GetCurrentPath(self);
|
||||
var path = self.GetCurrentActivity().GetCurrentPath();
|
||||
var start = self.CenterLocation + alt;
|
||||
|
||||
var c = Color.Green;
|
||||
|
||||
@@ -113,7 +113,6 @@ namespace OpenRA.Traits
|
||||
public interface IMove : ITeleportable
|
||||
{
|
||||
float MovementSpeedForCell(Actor self, int2 cell);
|
||||
IEnumerable<float2> GetCurrentPath(Actor self);
|
||||
int Altitude { get; set; }
|
||||
}
|
||||
|
||||
@@ -173,6 +172,7 @@ namespace OpenRA.Traits
|
||||
IActivity Tick(Actor self);
|
||||
void Cancel(Actor self);
|
||||
void Queue(IActivity activity);
|
||||
IEnumerable<float2> GetCurrentPath();
|
||||
}
|
||||
|
||||
public abstract class CancelableActivity : IActivity
|
||||
@@ -181,13 +181,15 @@ namespace OpenRA.Traits
|
||||
protected bool IsCanceled { get; private set; }
|
||||
|
||||
public abstract IActivity Tick( Actor self );
|
||||
protected virtual void OnCancel() {}
|
||||
protected virtual bool OnCancel() { return true; }
|
||||
|
||||
public void Cancel( Actor self )
|
||||
{
|
||||
IsCanceled = true;
|
||||
IsCanceled = OnCancel();
|
||||
if( IsCanceled )
|
||||
NextActivity = null;
|
||||
OnCancel();
|
||||
else
|
||||
NextActivity.Cancel( self );
|
||||
}
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
@@ -197,6 +199,11 @@ namespace OpenRA.Traits
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRenderOverlay { void Render(); }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Traits;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
@@ -51,5 +51,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user