Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pseudo-childactivities in several activities. #16379

Merged
merged 2 commits into from Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Activities/CaptureActor.cs
Expand Up @@ -136,9 +136,10 @@ protected override void OnActorDispose(Actor self)
base.OnActorDispose(self);
}

protected override void OnCancel(Actor self)
public override void Cancel(Actor self, bool keepQueue = false)
{
CancelCapture(self);
base.Cancel(self, keepQueue);
}

void CancelCapture(Actor self)
Expand Down
40 changes: 10 additions & 30 deletions OpenRA.Mods.Common/Activities/Enter.cs
Expand Up @@ -20,7 +20,7 @@ public enum EnterBehaviour { Exit, Suicide, Dispose }

public abstract class Enter : Activity
{
enum EnterState { Approaching, Waiting, Entering, Exiting }
enum EnterState { Approaching, Entering, Exiting }

readonly IMove move;
readonly Color? targetLineColor;
Expand Down Expand Up @@ -57,12 +57,6 @@ protected Enter(Actor self, Target target, Color? targetLineColor = null)
/// </summary>
protected virtual void OnEnterComplete(Actor self, Actor targetActor) { }

/// <summary>
/// Called when the activity is cancelled to allow subclasses to clean up their own state.
/// </summary>
protected virtual void OnCancel(Actor self) { }

Activity moveActivity;
public override Activity Tick(Actor self)
{
// Update our view of the target
Expand All @@ -86,18 +80,17 @@ public override Activity Tick(Actor self)

// We need to wait for movement to finish before transitioning to
// the next state or next activity
if (moveActivity != null)
if (ChildActivity != null)
{
moveActivity = ActivityUtils.RunActivity(self, moveActivity);
if (moveActivity != null)
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}

// Note that lastState refers to what we have just *finished* doing
switch (lastState)
{
case EnterState.Approaching:
case EnterState.Waiting:
{
// NOTE: We can safely cancel in this case because we know the
// actor has finished any in-progress move activities
Expand All @@ -111,12 +104,10 @@ public override Activity Tick(Actor self)
// We are not next to the target - lets fix that
if (target.Type != TargetType.Invalid && !move.CanEnterTargetNow(self, target))
{
lastState = EnterState.Approaching;

// Target lines are managed by this trait, so we do not pass targetLineColor
var initialTargetPosition = (useLastVisibleTarget ? lastVisibleTarget : target).CenterPosition;
moveActivity = ActivityUtils.RunActivity(self, move.MoveToTarget(self, target, initialTargetPosition));
break;
QueueChild(self, move.MoveToTarget(self, target, initialTargetPosition), true);
return this;
}

// We are next to where we thought the target should be, but it isn't here
Expand All @@ -128,7 +119,7 @@ public override Activity Tick(Actor self)
if (TryStartEnter(self, target.Actor))
{
lastState = EnterState.Entering;
moveActivity = ActivityUtils.RunActivity(self, move.MoveIntoTarget(self, target));
QueueChild(self, move.MoveIntoTarget(self, target), true);
return this;
}

Expand All @@ -137,8 +128,7 @@ public override Activity Tick(Actor self)
if (IsCanceling)
return NextActivity;

lastState = EnterState.Waiting;
break;
return this;
}

case EnterState.Entering:
Expand All @@ -149,8 +139,8 @@ public override Activity Tick(Actor self)
OnEnterComplete(self, target.Actor);

lastState = EnterState.Exiting;
moveActivity = ActivityUtils.RunActivity(self, move.MoveIntoWorld(self, self.Location));
break;
QueueChild(self, move.MoveIntoWorld(self, self.Location), true);
return this;
}

case EnterState.Exiting:
Expand All @@ -159,15 +149,5 @@ public override Activity Tick(Actor self)

return this;
}

public override void Cancel(Actor self, bool keepQueue = false)
{
OnCancel(self);

if (!IsCanceling && moveActivity != null)
moveActivity.Cancel(self);

base.Cancel(self, keepQueue);
}
}
}
26 changes: 9 additions & 17 deletions OpenRA.Mods.Common/Activities/EnterTransport.cs
Expand Up @@ -68,14 +68,16 @@ protected override void OnEnterComplete(Actor self, Actor targetActor)
});
}

protected override void OnCancel(Actor self)
protected override void OnLastRun(Actor self)
{
passenger.Unreserve(self);
}

protected override void OnLastRun(Actor self)
public override void Cancel(Actor self, bool keepQueue = false)
{
passenger.Unreserve(self);

base.Cancel(self, keepQueue);
}
}

Expand All @@ -84,23 +86,21 @@ class EnterTransports : Activity
readonly string type;
readonly Passenger passenger;

Activity enterTransport;

public EnterTransports(Actor self, Target primaryTarget)
{
passenger = self.Trait<Passenger>();
if (primaryTarget.Type == TargetType.Actor)
type = primaryTarget.Actor.Info.Name;

enterTransport = new EnterTransport(self, primaryTarget);
QueueChild(self, new EnterTransport(self, primaryTarget));
}

public override Activity Tick(Actor self)
{
if (enterTransport != null)
if (ChildActivity != null)
{
enterTransport = ActivityUtils.RunActivity(self, enterTransport);
if (enterTransport != null)
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}

Expand All @@ -126,19 +126,11 @@ public override Activity Tick(Actor self)

if (transport != null)
{
enterTransport = ActivityUtils.RunActivity(self, new EnterTransport(self, Target.FromActor(transport)));
QueueChild(self, ActivityUtils.RunActivity(self, new EnterTransport(self, Target.FromActor(transport))), true);
return this;
}

return NextActivity;
}

public override void Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceling && enterTransport != null)
enterTransport.Cancel(self);

base.Cancel(self, keepQueue);
}
}
}
25 changes: 8 additions & 17 deletions OpenRA.Mods.Common/Activities/WaitForTransport.cs
Expand Up @@ -19,34 +19,25 @@ public class WaitForTransport : Activity
{
readonly ICallForTransport transportable;

Activity inner;

public WaitForTransport(Actor self, Activity innerActivity)
{
transportable = self.TraitOrDefault<ICallForTransport>();
inner = innerActivity;
QueueChild(self, innerActivity);
}

public override Activity Tick(Actor self)
{
if (inner == null)
if (ChildActivity != null)
{
if (transportable != null)
transportable.MovementCancelled(self);

return NextActivity;
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}

inner = ActivityUtils.RunActivity(self, inner);
return this;
}

public override void Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceling && inner != null)
inner.Cancel(self);
if (transportable != null)
transportable.MovementCancelled(self);

base.Cancel(self, keepQueue);
return NextActivity;
}
}
}