Rename FlyCircle to FlyIdle and make it tick TickIdle

It now handles both hovering and circling aircraft, for consistency.
This commit is contained in:
reaperrr
2019-07-18 17:36:09 +02:00
committed by teinarss
parent ce29dcad87
commit 801f5ba525
4 changed files with 24 additions and 24 deletions

View File

@@ -9,22 +9,26 @@
*/
#endregion
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
public class FlyCircle : Activity
public class FlyIdle : Activity
{
readonly Aircraft aircraft;
readonly int turnSpeedOverride;
readonly INotifyIdle[] tickIdles;
readonly int turnSpeed;
int remainingTicks;
public FlyCircle(Actor self, int ticks = -1, int turnSpeedOverride = -1)
public FlyIdle(Actor self, int ticks = -1)
{
aircraft = self.Trait<Aircraft>();
tickIdles = self.TraitsImplementing<INotifyIdle>().ToArray();
turnSpeed = aircraft.Info.IdleTurnSpeed > -1 ? aircraft.Info.IdleTurnSpeed : aircraft.TurnSpeed;
remainingTicks = ticks;
this.turnSpeedOverride = turnSpeedOverride;
}
public override bool Tick(Actor self)
@@ -32,26 +36,25 @@ namespace OpenRA.Mods.Common.Activities
if (remainingTicks == 0 || (NextActivity != null && remainingTicks < 0))
return true;
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
Cancel(self);
return true;
}
if (IsCanceling)
if (aircraft.ForceLanding || IsCanceling)
return true;
if (remainingTicks > 0)
remainingTicks--;
// We can't possibly turn this fast
var desiredFacing = aircraft.Facing + 64;
foreach (var tickIdle in tickIdles)
tickIdle.TickIdle(self);
// This override is necessary, otherwise aircraft with CanSlide would circle sideways
var move = aircraft.FlyStep(aircraft.Facing);
if (!aircraft.Info.CanHover)
{
// We can't possibly turn this fast
var desiredFacing = aircraft.Facing + 64;
Fly.FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move, turnSpeedOverride);
// This override is necessary, otherwise aircraft with CanSlide would circle sideways
var move = aircraft.FlyStep(aircraft.Facing);
Fly.FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move, turnSpeed);
}
return false;
}

View File

@@ -215,10 +215,7 @@ namespace OpenRA.Mods.Common.Activities
if (!aircraft.CanLand(blockingCells, target.Actor))
{
// Maintain holding pattern.
if (aircraft.Info.CanHover)
QueueChild(new Wait(25));
else
QueueChild(new FlyCircle(self, 25));
QueueChild(new FlyIdle(self, 25));
self.NotifyBlocker(blockingCells);
finishedApproach = false;

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Activities
}
QueueChild(new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
QueueChild(new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
QueueChild(new FlyIdle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
return false;
}

View File

@@ -712,8 +712,8 @@ namespace OpenRA.Mods.Common.Traits
self.QueueActivity(new TakeOff(self));
else if (Info.IdleBehavior == IdleBehaviorType.Land && Info.LandableTerrainTypes.Count > 0)
self.QueueActivity(new Land(self));
else if (!Info.CanHover)
self.QueueActivity(new FlyCircle(self, -1, Info.IdleTurnSpeed > -1 ? Info.IdleTurnSpeed : TurnSpeed));
else
self.QueueActivity(new FlyIdle(self));
}
}