Make Tick return bool

This commit is contained in:
tovl
2019-05-14 21:13:25 +02:00
committed by teinarss
parent 09c1611239
commit 3790169db9
49 changed files with 328 additions and 318 deletions

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length <= 0)
{
@@ -43,7 +43,8 @@ namespace OpenRA.Mods.Common.Activities
}
self.Kill(self);
return null;
Cancel(self);
return true;
}
if (info.Spins)
@@ -56,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
move -= new WVec(WDist.Zero, WDist.Zero, info.Velocity);
aircraft.SetPosition(self, aircraft.CenterPosition + move);
return this;
return false;
}
}
}

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Activities
return true;
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
@@ -122,15 +122,15 @@ namespace OpenRA.Mods.Common.Activities
else
VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
return NextActivity;
return true;
}
else if (dat <= aircraft.LandAltitude)
{
QueueChild(new TakeOff(self, target));
return this;
return false;
}
bool targetIsHiddenActor;
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Activities
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return NextActivity;
return true;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
var pos = aircraft.GetPosition();
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Activities
var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(pos, maxRange);
var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(pos, minRange);
if (insideMaxRange && !insideMinRange)
return NextActivity;
return true;
var move = aircraft.Info.CanHover ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
@@ -166,7 +166,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.Info.CanHover && insideMinRange)
{
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move);
return this;
return false;
}
// The next move would overshoot, so consider it close enough or set final position if CanHover
@@ -186,11 +186,11 @@ namespace OpenRA.Mods.Common.Activities
if (dat != aircraft.Info.CruiseAltitude)
{
Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
}
return NextActivity;
return true;
}
if (!aircraft.Info.CanHover)
@@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Activities
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
public override IEnumerable<Target> GetTargets(Actor self)

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Activities
}
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
@@ -73,16 +73,16 @@ namespace OpenRA.Mods.Common.Activities
{
// Cancel the requested target, but keep firing on it while in range
attackAircraft.ClearRequestedTarget();
return NextActivity;
return true;
}
// Check that AttackFollow hasn't cancelled the target by modifying attack.Target
// Having both this and AttackFollow modify that field is a horrible hack.
if (hasTicked && attackAircraft.RequestedTarget.Type == TargetType.Invalid)
return NextActivity;
return true;
if (attackAircraft.IsTraitPaused)
return this;
return false;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
@@ -108,14 +108,14 @@ namespace OpenRA.Mods.Common.Activities
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
{
attackAircraft.ClearRequestedTarget();
return NextActivity;
return true;
}
// 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(new ReturnToBase(self, aircraft.Info.AbortOnResupply));
return this;
return false;
}
var pos = self.CenterPosition;
@@ -128,12 +128,12 @@ namespace OpenRA.Mods.Common.Activities
if (checkTarget.IsInRange(pos, lastVisibleMaximumRange))
{
attackAircraft.ClearRequestedTarget();
return NextActivity;
return true;
}
// Fly towards the last known position
QueueChild(new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red));
return this;
return false;
}
var delta = attackAircraft.GetTargetPosition(pos, target) - pos;
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Activities
Fly.VerticalTakeOffOrLandTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
}
return this;
return false;
}
void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)

View File

@@ -27,20 +27,20 @@ namespace OpenRA.Mods.Common.Activities
this.turnSpeedOverride = turnSpeedOverride;
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (remainingTicks == 0 || (NextActivity != null && remainingTicks < 0))
return NextActivity;
return true;
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
Cancel(self);
return NextActivity;
return true;
}
if (IsCanceling)
return NextActivity;
return true;
if (remainingTicks > 0)
remainingTicks--;
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities
Fly.FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move, turnSpeedOverride);
return this;
return false;
}
}
}

View File

@@ -45,14 +45,14 @@ namespace OpenRA.Mods.Common.Activities
lastVisibleTarget = Target.FromPos(initialTargetPosition.Value);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceling)
return NextActivity;
return true;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Activities
// If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
// Either we are in range and can see the target, or we've lost track of it and should give up
if (wasMovingWithinRange && targetIsHiddenActor)
return NextActivity;
return true;
wasMovingWithinRange = false;
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Activities
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return NextActivity;
return true;
var pos = self.CenterPosition;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
@@ -85,12 +85,12 @@ namespace OpenRA.Mods.Common.Activities
if (checkTarget.IsInRange(pos, maxRange) && !checkTarget.IsInRange(pos, minRange))
{
Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return useLastVisibleTarget ? NextActivity : this;
return useLastVisibleTarget;
}
wasMovingWithinRange = true;
QueueChild(aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return this;
return false;
}
}
}

View File

@@ -23,20 +23,20 @@ namespace OpenRA.Mods.Common.Activities
aircraft = self.Trait<Aircraft>();
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
Cancel(self);
return NextActivity;
return true;
}
if (IsCanceling || !self.World.Map.Contains(self.Location))
return NextActivity;
return true;
Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
}
}

View File

@@ -27,21 +27,21 @@ namespace OpenRA.Mods.Common.Activities
cruiseAltitude = aircraft.Info.CruiseAltitude;
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
Cancel(self);
return NextActivity;
return true;
}
if (IsCanceling || remainingTicks-- == 0)
return NextActivity;
return true;
Fly.FlyTick(self, aircraft, aircraft.Facing, cruiseAltitude);
return this;
return false;
}
}
}

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities
target = Target.FromCell(self.World, self.Location);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (IsCanceling || target.Type == TargetType.Invalid)
{
@@ -88,15 +88,15 @@ namespace OpenRA.Mods.Common.Activities
if (dat > aircraft.LandAltitude && dat < aircraft.Info.CruiseAltitude)
{
QueueChild(new TakeOff(self));
return this;
return false;
}
aircraft.RemoveInfluence();
return NextActivity;
return true;
}
}
else
return NextActivity;
return true;
}
var pos = aircraft.GetPosition();
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Activities
// We are already at the landing location.
if ((targetPosition - pos).LengthSquared == 0)
return NextActivity;
return true;
// Look for free landing cell
if (target.Type == TargetType.Terrain && !landingInitiated)
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Activities
{
Cancel(self, true);
QueueChild(aircraft.MoveTo(landingCell, 0));
return this;
return false;
}
if (newLocation.Value != landingCell)
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Activities
if (desiredFacing != -1)
QueueChild(new Turn(self, desiredFacing));
return this;
return false;
}
if (!aircraft.Info.VTOL && !finishedApproach)
@@ -198,7 +198,7 @@ namespace OpenRA.Mods.Common.Activities
// Fix a problem when the airplane is sent to land near the landing cell
QueueChild(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)));
finishedApproach = true;
return this;
return false;
}
if (!landingInitiated)
@@ -215,7 +215,7 @@ namespace OpenRA.Mods.Common.Activities
self.NotifyBlocker(blockingCells);
finishedApproach = false;
return this;
return false;
}
if (aircraft.Info.LandingSounds.Length > 0)
@@ -231,9 +231,9 @@ namespace OpenRA.Mods.Common.Activities
{
var landAltitude = self.World.Map.DistanceAboveTerrain(targetPosition) + aircraft.LandAltitude;
if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, landAltitude))
return this;
return false;
return NextActivity;
return true;
}
var d = targetPosition - pos;
@@ -244,13 +244,13 @@ namespace OpenRA.Mods.Common.Activities
{
var landingAltVec = new WVec(WDist.Zero, WDist.Zero, aircraft.LandAltitude);
aircraft.SetPosition(self, targetPosition + landingAltVec);
return NextActivity;
return true;
}
var landingAlt = self.World.Map.DistanceAboveTerrain(targetPosition) + aircraft.LandAltitude;
Fly.FlyTick(self, aircraft, d.Yaw.Facing, landingAlt);
return this;
return false;
}
}
}

View File

@@ -66,12 +66,12 @@ namespace OpenRA.Mods.Common.Activities
&& rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
// Special case: Don't kill other deploy hotkey activities.
if (aircraft.ForceLanding)
return NextActivity;
return true;
// If a Cancel was triggered at this point, it's unlikely that previously queued child activities finished,
// so 'resupplied' needs to be set to false, else it + abortOnResupply might cause another Cancel
@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Activities
self.CancelActivity();
if (resupplied || IsCanceling || self.IsDead)
return NextActivity;
return true;
if (dest == null || dest.IsDead || !Reservable.IsAvailableFor(dest, self))
dest = ChooseResupplier(self, true);
@@ -109,17 +109,17 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
}
return this;
return false;
}
QueueChild(new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
QueueChild(new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
return this;
return false;
}
// Prevent an infinite loop in case we'd return to the activity that called ReturnToBase in the first place. Go idle instead.
self.CancelActivity();
return NextActivity;
return true;
}
if (ShouldLandAtBuilding(self, dest))
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(new Fly(self, Target.FromActor(dest)));
resupplied = true;
return this;
return false;
}
}
}

View File

@@ -62,13 +62,13 @@ namespace OpenRA.Mods.Common.Activities
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
Cancel(self);
return NextActivity;
return true;
}
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
@@ -78,12 +78,12 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.Info.VTOL)
{
Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
else
{
Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return this;
return false;
}
}
@@ -91,14 +91,14 @@ namespace OpenRA.Mods.Common.Activities
if (moveToRallyPoint && NextActivity == null)
{
if (!aircraft.Info.VTOL && assignTargetOnFirstRun)
return NextActivity;
return true;
QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, target)));
moveToRallyPoint = false;
return this;
return false;
}
return NextActivity;
return true;
}
}
}