Move ChildActivity handling into base Activity class.

This commit is contained in:
tovl
2019-04-30 22:45:02 +02:00
committed by teinarss
parent 37379daf3c
commit b9c302a73a
43 changed files with 139 additions and 342 deletions

View File

@@ -102,13 +102,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -125,7 +118,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{
if (dat <= aircraft.LandAltitude)
QueueChild(self, new TakeOff(self, target), true);
QueueChild(new TakeOff(self, target));
else
VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
@@ -136,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities
}
else if (dat <= aircraft.LandAltitude)
{
QueueChild(self, new TakeOff(self, target), true);
QueueChild(new TakeOff(self, target));
return this;
}

View File

@@ -65,13 +65,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -121,7 +114,7 @@ namespace OpenRA.Mods.Common.Activities
// If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity
if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
{
QueueChild(self, new ReturnToBase(self, aircraft.Info.AbortOnResupply), true);
QueueChild(new ReturnToBase(self, aircraft.Info.AbortOnResupply));
return this;
}
@@ -139,7 +132,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Fly towards the last known position
QueueChild(self, new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red), true);
QueueChild(new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red));
return this;
}
@@ -148,21 +141,21 @@ namespace OpenRA.Mods.Common.Activities
var isAirborne = self.World.Map.DistanceAboveTerrain(pos).Length >= aircraft.Info.MinAirborneAltitude;
if (!isAirborne)
QueueChild(self, new TakeOff(self), true);
QueueChild(new TakeOff(self));
if (attackAircraft.Info.AttackType == AirAttackType.Strafe)
{
if (target.IsInRange(pos, attackAircraft.GetMinimumRange()))
QueueChild(self, new FlyTimed(ticksUntilTurn, self), true);
QueueChild(new FlyTimed(ticksUntilTurn, self));
QueueChild(self, new Fly(self, target, target.CenterPosition, Color.Red), true);
QueueChild(self, new FlyTimed(ticksUntilTurn, self));
QueueChild(new Fly(self, target, target.CenterPosition, Color.Red));
QueueChild(new FlyTimed(ticksUntilTurn, self));
}
else
{
var minimumRange = attackAircraft.GetMinimumRangeVersusTarget(target);
if (!target.IsInRange(pos, lastVisibleMaximumRange) || target.IsInRange(pos, minimumRange))
QueueChild(self, new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red), true);
QueueChild(new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red));
else if (isAirborne) // Don't use 'else' to avoid conflict with TakeOff
Fly.VerticalTakeOffOrLandTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
}

View File

@@ -47,13 +47,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -96,7 +89,7 @@ namespace OpenRA.Mods.Common.Activities
}
wasMovingWithinRange = true;
QueueChild(self, aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor), true);
QueueChild(aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return this;
}
}

View File

@@ -73,13 +73,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || target.Type == TargetType.Invalid)
{
if (landingInitiated)
@@ -94,7 +87,7 @@ namespace OpenRA.Mods.Common.Activities
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
if (dat > aircraft.LandAltitude && dat < aircraft.Info.CruiseAltitude)
{
QueueChild(self, new TakeOff(self), true);
QueueChild(new TakeOff(self));
return this;
}
@@ -125,7 +118,7 @@ namespace OpenRA.Mods.Common.Activities
if (!newLocation.HasValue)
{
Cancel(self, true);
QueueChild(self, aircraft.MoveTo(landingCell, 0), true);
QueueChild(aircraft.MoveTo(landingCell, 0));
return this;
}
@@ -140,10 +133,10 @@ namespace OpenRA.Mods.Common.Activities
// Move towards landing location
if (aircraft.Info.VTOL && (pos - targetPosition).HorizontalLengthSquared != 0)
{
QueueChild(self, new Fly(self, Target.FromPos(targetPosition)), true);
QueueChild(new Fly(self, Target.FromPos(targetPosition)));
if (desiredFacing != -1)
QueueChild(self, new Turn(self, desiredFacing));
QueueChild(new Turn(self, desiredFacing));
return this;
}
@@ -199,11 +192,11 @@ namespace OpenRA.Mods.Common.Activities
turnRadius = Fly.CalculateTurnRadius(aircraft.Info.Speed, aircraft.Info.TurnSpeed);
// Move along approach trajectory.
QueueChild(self, new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3)), true);
QueueChild(self, new Fly(self, Target.FromPos(w2)), true);
QueueChild(new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3)));
QueueChild(new Fly(self, Target.FromPos(w2)));
// Fix a problem when the airplane is sent to land near the landing cell
QueueChild(self, new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)), true);
QueueChild(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)));
finishedApproach = true;
return this;
}
@@ -216,9 +209,9 @@ namespace OpenRA.Mods.Common.Activities
{
// Maintain holding pattern.
if (aircraft.Info.CanHover)
QueueChild(self, new Wait(25), true);
QueueChild(new Wait(25));
else
QueueChild(self, new FlyCircle(self, 25), true);
QueueChild(new FlyCircle(self, 25));
self.NotifyBlocker(blockingCells);
finishedApproach = false;

View File

@@ -68,13 +68,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
// Special case: Don't kill other deploy hotkey activities.
if (aircraft.ForceLanding)
@@ -113,15 +106,14 @@ namespace OpenRA.Mods.Common.Activities
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;
var target = Target.FromPos(nearestResupplier.CenterPosition + randomPosition);
QueueChild(self, new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green), true);
QueueChild(new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
}
return this;
}
QueueChild(self, new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green),
true);
QueueChild(self, new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport), true);
QueueChild(new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
QueueChild(new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
return this;
}
@@ -140,13 +132,13 @@ namespace OpenRA.Mods.Common.Activities
facing = 192;
aircraft.MakeReservation(dest);
QueueChild(self, new Land(self, Target.FromActor(dest), offset, facing), true);
QueueChild(self, new Resupply(self, dest, WDist.Zero), true);
QueueChild(new Land(self, Target.FromActor(dest), offset, facing));
QueueChild(new Resupply(self, dest, WDist.Zero));
if (aircraft.Info.TakeOffOnResupply && !alwaysLand)
QueueChild(self, new TakeOff(self));
QueueChild(new TakeOff(self));
}
else
QueueChild(self, new Fly(self, Target.FromActor(dest)), true);
QueueChild(new Fly(self, Target.FromActor(dest)));
resupplied = true;
return this;

View File

@@ -64,13 +64,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
@@ -100,7 +93,7 @@ namespace OpenRA.Mods.Common.Activities
if (!aircraft.Info.VTOL && assignTargetOnFirstRun)
return NextActivity;
QueueChild(self, new AttackMoveActivity(self, () => move.MoveToTarget(self, target)), true);
QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, target)));
moveToRallyPoint = false;
return this;
}