Split out an ActivityUtils class.

This commit is contained in:
Paul Chote
2016-01-14 21:50:11 +00:00
parent e46fc644c1
commit 0039a2bdbf
32 changed files with 120 additions and 98 deletions

View File

@@ -52,12 +52,12 @@ namespace OpenRA.Mods.Common.Activities
// TODO: This should fire each weapon at its maximum range
if (attackPlane != null && target.IsInRange(self.CenterPosition, attackPlane.Armaments.Select(a => a.Weapon.MinRange).Min()))
inner = Util.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
inner = ActivityUtils.SequenceActivities(new FlyTimed(ticksUntilTurn, self), new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
else
inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
inner = ActivityUtils.SequenceActivities(new Fly(self, target), new FlyTimed(ticksUntilTurn, self));
}
inner = Util.RunActivity(self, inner);
inner = ActivityUtils.RunActivity(self, inner);
return this;
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
return Util.SequenceActivities(new Fly(self, target, minRange, maxRange), this);
return ActivityUtils.SequenceActivities(new Fly(self, target, minRange, maxRange), this);
}
}
}

View File

@@ -61,13 +61,13 @@ namespace OpenRA.Mods.Common.Activities
self.CancelActivity();
self.SetTargetLine(newTarget, Color.Green);
return Util.SequenceActivities(new HeliFly(self, newTarget));
return ActivityUtils.SequenceActivities(new HeliFly(self, newTarget));
}
// If all ammo pools are depleted and none reload automatically, return to helipad to reload and then move to next activity
// TODO: This should check whether there is ammo left that is actually suitable for the target
if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
return Util.SequenceActivities(new HeliReturnToBase(self), NextActivity);
return ActivityUtils.SequenceActivities(new HeliReturnToBase(self), NextActivity);
var dist = target.CenterPosition - self.CenterPosition;

View File

@@ -47,9 +47,9 @@ namespace OpenRA.Mods.Common.Activities
.ClosestTo(self);
if (nearestHpad == null)
return Util.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
else
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
}
heli.MakeReservation(dest);
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
var exit = dest.Info.TraitInfos<ExitInfo>().FirstOrDefault();
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
return Util.SequenceActivities(
return ActivityUtils.SequenceActivities(
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(self, initialFacing),
new HeliLand(self, false),

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
if (host == null)
return NextActivity;
return Util.SequenceActivities(
return ActivityUtils.SequenceActivities(
aircraft.GetResupplyActivities(host).Append(NextActivity).ToArray());
}
}

View File

@@ -106,12 +106,12 @@ namespace OpenRA.Mods.Common.Activities
self.CancelActivity();
if (nearestAfld != null)
return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle(self));
return ActivityUtils.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle(self));
else
return new FlyCircle(self);
}
return Util.SequenceActivities(
return ActivityUtils.SequenceActivities(
new Fly(self, Target.FromPos(w1)),
new Fly(self, Target.FromPos(w2)),
new Fly(self, Target.FromPos(w3)),

View File

@@ -78,11 +78,11 @@ namespace OpenRA.Mods.Common.Activities
// Try to move within range
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
return ActivityUtils.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
if (facing.Facing != desiredFacing)
return Util.SequenceActivities(new Turn(self, desiredFacing), this);
return ActivityUtils.SequenceActivities(new Turn(self, desiredFacing), this);
attack.DoAttack(self, Target, armaments);

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
// No refineries exist; check again after delay defined in Harvester.
if (harv.LinkedProc == null)
return Util.SequenceActivities(new Wait(harv.Info.SearchForDeliveryBuildingDelay), this);
return ActivityUtils.SequenceActivities(new Wait(harv.Info.SearchForDeliveryBuildingDelay), this);
var proc = harv.LinkedProc;
var iao = proc.Trait<IAcceptResources>();
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in notify)
n.MovingToRefinery(self, proc.Location + iao.DeliveryOffset, next);
return Util.SequenceActivities(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), this);
return ActivityUtils.SequenceActivities(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), this);
}
if (!isDocking)
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
iao.OnDock(self, this);
}
return Util.SequenceActivities(new Wait(10), this);
return ActivityUtils.SequenceActivities(new Wait(10), this);
}
// Cannot be cancelled

View File

@@ -252,10 +252,10 @@ namespace OpenRA.Mods.Common.Activities
Activity CanceledTick(Actor self)
{
if (inner == null)
return Util.RunActivity(self, NextActivity);
return ActivityUtils.RunActivity(self, NextActivity);
inner.Cancel(self);
inner.Queue(NextActivity);
return Util.RunActivity(self, inner);
return ActivityUtils.RunActivity(self, inner);
}
public override Activity Tick(Actor self)
@@ -272,7 +272,7 @@ namespace OpenRA.Mods.Common.Activities
return CanceledTick(self);
// Run inner activity/InsideTick
inner = inner == this ? InsideTick(self) : Util.RunActivity(self, inner);
inner = inner == this ? InsideTick(self) : ActivityUtils.RunActivity(self, inner);
// If we are finished, move on to next activity
if (inner == null && nextState == State.Done)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);
if ((nearest - mobile.ToCell).LengthSquared > 2)
return Util.SequenceActivities(new MoveAdjacentTo(self, target), this);
return ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this);
if (!capturable.CaptureInProgress)
capturable.BeginCapture(self);

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities
var deliver = new DeliverResources(self);
if (harv.IsFull)
return Util.SequenceActivities(deliver, NextActivity);
return ActivityUtils.SequenceActivities(deliver, NextActivity);
var closestHarvestablePosition = ClosestHarvestablePos(self);
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Activities
}
var randFrames = self.World.SharedRandom.Next(100, 175);
return Util.SequenceActivities(NextActivity, new Wait(randFrames), this);
return ActivityUtils.SequenceActivities(NextActivity, new Wait(randFrames), this);
}
else
{
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
if (territory != null)
{
if (!territory.ClaimResource(self, closestHarvestablePosition.Value))
return Util.SequenceActivities(new Wait(25), next);
return ActivityUtils.SequenceActivities(new Wait(25), next);
}
// If not given a direct order, assume ordered to the first resource location we find:
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in notify)
n.MovingToResources(self, closestHarvestablePosition.Value, next);
return Util.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), next);
return ActivityUtils.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), next);
}
}

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
var current = facing.Facing;
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
if (desired != current)
return Util.SequenceActivities(new Turn(self, desired), this);
return ActivityUtils.SequenceActivities(new Turn(self, desired), this);
}
var resource = resLayer.Harvest(self.Location);
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
t.Harvested(self, resource);
return Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this);
return ActivityUtils.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this);
}
}
}

View File

@@ -53,8 +53,8 @@ namespace OpenRA.Mods.Common.Activities
case State.Turn:
dockingState = State.Dock;
if (IsDragRequired)
return Util.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
return Util.SequenceActivities(new Turn(self, DockAngle), this);
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this);
case State.Dock:
if (Refinery.IsInWorld && !Refinery.IsDead)
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
Harv.LastLinkedProc = Harv.LinkedProc;
Harv.LinkProc(self, null);
if (IsDragRequired)
return Util.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity);
return ActivityUtils.SequenceActivities(new Drag(self, EndDrag, StartDrag, DragLength), NextActivity);
return NextActivity;
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
if (target == null)
return this;
return Util.SequenceActivities(
return ActivityUtils.SequenceActivities(
new AttackMoveActivity(self, new Move(self, target.Location, WDist.FromCells(2))),
new Wait(25),
this);

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
if (inner == null)
return NextActivity;
inner = Util.RunActivity(self, inner);
inner = ActivityUtils.RunActivity(self, inner);
return this;
}

View File

@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.Activities
if (target.IsInRange(self.CenterPosition, maxRange) && !target.IsInRange(self.CenterPosition, minRange))
{
var wait = new WaitFor(() => !target.IsValidFor(self) || target.CenterPosition != cachedPosition);
return Util.SequenceActivities(wait, path, this);
return ActivityUtils.SequenceActivities(wait, path, this);
}
return Util.SequenceActivities(path, this);
return ActivityUtils.SequenceActivities(path, this);
}
}
}

View File

@@ -182,7 +182,7 @@ namespace OpenRA.Mods.Common.Activities
if (firstFacing != mobile.Facing)
{
path.Add(nextCell.Value.First);
return Util.SequenceActivities(new Turn(self, firstFacing), this);
return ActivityUtils.SequenceActivities(new Turn(self, firstFacing), this);
}
else
{

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
inner.Cancel(self);
self.SetTargetLine(Target.FromCell(self.World, targetPosition), Color.Green);
return Util.RunActivity(self, new AttackMoveActivity(self, mobile.MoveTo(targetPosition, 0)));
return ActivityUtils.RunActivity(self, new AttackMoveActivity(self, mobile.MoveTo(targetPosition, 0)));
}
// Inner move order has completed.
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Ticks the inner move activity to actually move the actor.
inner = Util.RunActivity(self, inner);
inner = ActivityUtils.RunActivity(self, inner);
return this;
}

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Activities
{
self.NotifyBlocker(BlockedExitCells(actor));
return Util.SequenceActivities(new Wait(10), this);
return ActivityUtils.SequenceActivities(new Wait(10), this);
}
cargo.Unload(self);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
inner = Util.RunActivity(self, inner);
inner = ActivityUtils.RunActivity(self, inner);
return this;
}

View File

@@ -424,7 +424,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsPlane)
return new Fly(self, target, WDist.FromCells(3), WDist.FromCells(5));
return Util.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
return ActivityUtils.SequenceActivities(new HeliFly(self, target), new Turn(self, Info.InitialFacing));
}
public Activity MoveIntoTarget(Actor self, Target target)
@@ -439,11 +439,11 @@ namespace OpenRA.Mods.Common.Traits
{
// TODO: Ignore repulsion when moving
if (IsPlane)
return Util.SequenceActivities(
return ActivityUtils.SequenceActivities(
new CallFunc(() => SetVisualPosition(self, fromPos)),
new Fly(self, Target.FromPos(toPos)));
return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)),
return ActivityUtils.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)),
new HeliFly(self, Target.FromPos(toPos)));
}
@@ -538,7 +538,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsPlane)
{
self.QueueActivity(order.Queued, Util.SequenceActivities(
self.QueueActivity(order.Queued, ActivityUtils.SequenceActivities(
new ReturnToBase(self, order.TargetActor),
new ResupplyAircraft(self)));
}

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
Game.Sound.Play(attack.info.ChargeAudio, self.CenterPosition);
return Util.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
return ActivityUtils.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
}
}
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
attack.DoAttack(self, target);
return Util.SequenceActivities(new Wait(attack.info.ChargeDelay), this);
return ActivityUtils.SequenceActivities(new Wait(attack.info.ChargeDelay), this);
}
}
}

View File

@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
attack.Target = target;
if (move != null)
return Util.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this);
}
return NextActivity;

View File

@@ -682,7 +682,7 @@ namespace OpenRA.Mods.Common.Traits
var notifyBlocking = new CallFunc(() => self.NotifyBlocker(cellInfo.Cell));
var waitFor = new WaitFor(() => CanEnterCell(cellInfo.Cell));
var move = new Move(self, cellInfo.Cell);
self.QueueActivity(Util.SequenceActivities(notifyBlocking, waitFor, move));
self.QueueActivity(ActivityUtils.SequenceActivities(notifyBlocking, waitFor, move));
Log.Write("debug", "OnNudge (notify next blocking actor, wait and move) #{0} from {1} to {2}",
self.ActorID, self.Location, cellInfo.Cell);
@@ -797,7 +797,7 @@ namespace OpenRA.Mods.Common.Traits
var delta = toPos - fromPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing;
return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
return ActivityUtils.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
}
public void ModifyDeathActorInit(Actor self, TypeDictionary init)

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(target, Color.Green);
self.CancelActivity();
self.QueueActivity(new WaitForTransport(self, Util.SequenceActivities(new MoveAdjacentTo(self, target),
self.QueueActivity(new WaitForTransport(self, ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target),
new CallFunc(() => AfterReachActivities(self, order, movement)))));
TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement)));