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 SequenceActivities with ChildActivity in several activities. #16348

Merged
merged 1 commit into from Mar 25, 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
21 changes: 19 additions & 2 deletions OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs
Expand Up @@ -91,6 +91,13 @@ public ChargeAttack(AttackTesla attack, Target target)

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

if (IsCanceling || !attack.CanAttack(self, target))
return NextActivity;
obrakmann marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -103,7 +110,9 @@ public override Activity Tick(Actor self)
if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
Game.Sound.Play(SoundType.World, attack.info.ChargeAudio, self.CenterPosition);

return ActivityUtils.SequenceActivities(self, new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
QueueChild(self, new Wait(attack.info.InitialChargeDelay), true);
QueueChild(self, new ChargeFire(attack, target));
return this;
}
}

Expand All @@ -120,6 +129,13 @@ public ChargeFire(AttackTesla attack, Target target)

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

if (IsCanceling || !attack.CanAttack(self, target))
return NextActivity;

Expand All @@ -128,7 +144,8 @@ public override Activity Tick(Actor self)

attack.DoAttack(self, target);

return ActivityUtils.SequenceActivities(self, new Wait(attack.info.ChargeDelay), this);
QueueChild(self, new Wait(attack.info.ChargeDelay), true);
return this;
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions OpenRA.Mods.Common/Activities/Hunt.cs
Expand Up @@ -33,17 +33,23 @@ public Hunt(Actor self)

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

if (IsCanceling)
return NextActivity;

var target = targets.ClosestTo(self);
if (target == null)
return this;

return ActivityUtils.SequenceActivities(self,
new AttackMoveActivity(self, () => move.MoveTo(target.Location, 2)),
new Wait(25),
this);
QueueChild(self, new AttackMoveActivity(self, () => move.MoveTo(target.Location, 2)), true);
QueueChild(self, new Wait(25));
return this;
}
}
}
12 changes: 9 additions & 3 deletions OpenRA.Mods.Common/Activities/Move/Follow.cs
Expand Up @@ -47,6 +47,13 @@ public class Follow : Activity

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

if (IsCanceling)
return NextActivity;

Expand Down Expand Up @@ -83,9 +90,8 @@ public override Activity Tick(Actor self)

// Move into range
wasMovingWithinRange = true;
return ActivityUtils.SequenceActivities(self,
move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor),
this);
QueueChild(self, move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor), true);
return this;
}
}
}
11 changes: 9 additions & 2 deletions OpenRA.Mods.Common/Activities/UnloadCargo.cs
Expand Up @@ -55,6 +55,13 @@ IEnumerable<CPos> BlockedExitCells(Actor passenger)

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

cargo.Unloading = false;
if (IsCanceling || cargo.IsEmpty(self))
return NextActivity;
Expand All @@ -75,8 +82,8 @@ public override Activity Tick(Actor self)
if (exitSubCell == null)
{
self.NotifyBlocker(BlockedExitCells(actor));

return ActivityUtils.SequenceActivities(self, new Wait(10), this);
QueueChild(self, new Wait(10), true);
return this;
}

cargo.Unload(self);
Expand Down
12 changes: 9 additions & 3 deletions OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
Expand Up @@ -176,6 +176,13 @@ public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttac

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

if (IsCanceling)
{
// Cancel the requested target, but keep firing on it while in range
Expand Down Expand Up @@ -275,9 +282,8 @@ public override Activity Tick(Actor self)
}

wasMovingWithinRange = true;
return ActivityUtils.SequenceActivities(self,
move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red),
this);
QueueChild(self, move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red), true);
return this;
}
}
}
Expand Down