Merge pull request #12315 from obrakmann/activities-pt1
Activities re-write, part 1 (aka the boring bits)
This commit is contained in:
@@ -18,14 +18,25 @@ namespace OpenRA.Activities
|
||||
public abstract class Activity
|
||||
{
|
||||
public Activity NextActivity { get; set; }
|
||||
public bool IsInterruptible { get; protected set; }
|
||||
protected bool IsCanceled { get; private set; }
|
||||
|
||||
public Activity()
|
||||
{
|
||||
IsInterruptible = true;
|
||||
}
|
||||
|
||||
public abstract Activity Tick(Actor self);
|
||||
|
||||
public virtual void Cancel(Actor self)
|
||||
public virtual bool Cancel(Actor self)
|
||||
{
|
||||
if (!IsInterruptible)
|
||||
return false;
|
||||
|
||||
IsCanceled = true;
|
||||
NextActivity = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void Queue(Activity activity)
|
||||
@@ -46,7 +57,7 @@ namespace OpenRA.Activities
|
||||
{
|
||||
public static IEnumerable<Target> GetTargetQueue(this Actor self)
|
||||
{
|
||||
return self.GetCurrentActivity()
|
||||
return self.CurrentActivity
|
||||
.Iterate(u => u.NextActivity)
|
||||
.TakeWhile(u => u != null)
|
||||
.SelectMany(u => u.GetTargets(self));
|
||||
|
||||
@@ -16,25 +16,18 @@ namespace OpenRA.Activities
|
||||
public class CallFunc : Activity
|
||||
{
|
||||
public CallFunc(Action a) { this.a = a; }
|
||||
public CallFunc(Action a, bool interruptable)
|
||||
public CallFunc(Action a, bool interruptible)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
IsInterruptible = interruptible;
|
||||
}
|
||||
|
||||
Action a;
|
||||
bool interruptable;
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (a != null) a();
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
public override void Cancel(Actor self)
|
||||
{
|
||||
if (interruptable)
|
||||
base.Cancel(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA
|
||||
public bool IsInWorld { get; internal set; }
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
Activity currentActivity;
|
||||
public Activity CurrentActivity { get; private set; }
|
||||
|
||||
public Group Group;
|
||||
public int Generation;
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA
|
||||
public IOccupySpace OccupiesSpace { get; private set; }
|
||||
public ITargetable[] Targetables { get; private set; }
|
||||
|
||||
public bool IsIdle { get { return currentActivity == null; } }
|
||||
public bool IsIdle { get { return CurrentActivity == null; } }
|
||||
public bool IsDead { get { return Disposed || (health != null && health.IsDead); } }
|
||||
|
||||
public CPos Location { get { return OccupiesSpace.TopLeft; } }
|
||||
@@ -161,7 +161,7 @@ namespace OpenRA
|
||||
public void Tick()
|
||||
{
|
||||
var wasIdle = IsIdle;
|
||||
currentActivity = ActivityUtils.RunActivity(this, currentActivity);
|
||||
CurrentActivity = ActivityUtils.RunActivity(this, CurrentActivity);
|
||||
|
||||
if (!wasIdle && IsIdle)
|
||||
foreach (var n in TraitsImplementing<INotifyBecomingIdle>())
|
||||
@@ -200,21 +200,18 @@ namespace OpenRA
|
||||
|
||||
public void QueueActivity(Activity nextActivity)
|
||||
{
|
||||
if (currentActivity == null)
|
||||
currentActivity = nextActivity;
|
||||
if (CurrentActivity == null)
|
||||
CurrentActivity = nextActivity;
|
||||
else
|
||||
currentActivity.Queue(nextActivity);
|
||||
CurrentActivity.Queue(nextActivity);
|
||||
}
|
||||
|
||||
public void CancelActivity()
|
||||
public bool CancelActivity()
|
||||
{
|
||||
if (currentActivity != null)
|
||||
currentActivity.Cancel(this);
|
||||
}
|
||||
if (CurrentActivity != null)
|
||||
return CurrentActivity.Cancel(this);
|
||||
|
||||
public Activity GetCurrentActivity()
|
||||
{
|
||||
return currentActivity;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
||||
Reference in New Issue
Block a user