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;
|
||||
NextActivity = null;
|
||||
OnCancel();
|
||||
IsCanceled = OnCancel();
|
||||
if( IsCanceled )
|
||||
NextActivity = null;
|
||||
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(); }
|
||||
|
||||
Reference in New Issue
Block a user