Add LandOnCondition to the trait Aircraft which triggers a landing and prevents takeoffs while the condition is met
This commit is contained in:
committed by
atlimit8
parent
c4d2fdbd83
commit
1d1802a163
@@ -57,6 +57,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || !target.IsValidFor(self))
|
if (IsCanceled || !target.IsValidFor(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (aircraft.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (!target.IsValidFor(self))
|
if (!target.IsValidFor(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || !target.IsValidFor(self))
|
if (IsCanceled || !target.IsValidFor(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || !self.World.Map.Contains(self.Location))
|
if (IsCanceled || !self.World.Map.Contains(self.Location))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || remainingTicks-- == 0)
|
if (IsCanceled || remainingTicks-- == 0)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (helicopter.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || !target.IsValidFor(self))
|
if (IsCanceled || !target.IsValidFor(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (helicopter.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled || !target.IsValidFor(self))
|
if (IsCanceled || !target.IsValidFor(self))
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (helicopter.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
// Special case: Don't kill other deploy hotkey activities.
|
||||||
|
if (heli.ForceLanding)
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
if (IsCanceled)
|
if (IsCanceled)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
// Special case: Don't kill other deploy hotkey activities.
|
||||||
|
if (plane.ForceLanding)
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
if (IsCanceled || self.IsDead)
|
if (IsCanceled || self.IsDead)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// Refuse to take off if it would land immediately again.
|
||||||
|
if (aircraft.ForceLanding)
|
||||||
|
{
|
||||||
|
Cancel(self);
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
aircraft.UnReserve();
|
aircraft.UnReserve();
|
||||||
|
|
||||||
var host = aircraft.GetActorBelow();
|
var host = aircraft.GetActorBelow();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using OpenRA.Activities;
|
|||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Orders;
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -39,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly int TurnSpeed = 255;
|
public readonly int TurnSpeed = 255;
|
||||||
public readonly int Speed = 1;
|
public readonly int Speed = 1;
|
||||||
|
|
||||||
[Desc("Minimum altitude where this aircraft is considered airborne")]
|
[Desc("Minimum altitude where this aircraft is considered airborne.")]
|
||||||
public readonly int MinAirborneAltitude = 1;
|
public readonly int MinAirborneAltitude = 1;
|
||||||
public readonly HashSet<string> LandableTerrainTypes = new HashSet<string>();
|
public readonly HashSet<string> LandableTerrainTypes = new HashSet<string>();
|
||||||
|
|
||||||
@@ -100,6 +101,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
yield return new FacingInit(PreviewFacing);
|
yield return new FacingInit(PreviewFacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Desc("Condition when this aircraft should land as soon as possible and refuse to take off.")]
|
||||||
|
public readonly BooleanExpression LandOnCondition;
|
||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); }
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); }
|
||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier,
|
public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier,
|
||||||
INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, IActorPreviewInitModifier, IIssueDeployOrder
|
INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, IActorPreviewInitModifier, IIssueDeployOrder, IObservesVariables
|
||||||
{
|
{
|
||||||
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
||||||
|
|
||||||
@@ -142,6 +146,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public int TurnSpeed { get { return Info.TurnSpeed; } }
|
public int TurnSpeed { get { return Info.TurnSpeed; } }
|
||||||
public Actor ReservedActor { get; private set; }
|
public Actor ReservedActor { get; private set; }
|
||||||
public bool MayYieldReservation { get; private set; }
|
public bool MayYieldReservation { get; private set; }
|
||||||
|
public bool ForceLanding { get; private set; }
|
||||||
|
|
||||||
bool airborne;
|
bool airborne;
|
||||||
bool cruising;
|
bool cruising;
|
||||||
@@ -152,6 +157,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool isMoving;
|
bool isMoving;
|
||||||
bool isMovingVertically;
|
bool isMovingVertically;
|
||||||
WPos cachedPosition;
|
WPos cachedPosition;
|
||||||
|
bool? landNow;
|
||||||
|
|
||||||
public Aircraft(ActorInitializer init, AircraftInfo info)
|
public Aircraft(ActorInitializer init, AircraftInfo info)
|
||||||
{
|
{
|
||||||
@@ -171,6 +177,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
IsPlane = !info.CanHover;
|
IsPlane = !info.CanHover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerable<VariableObserver> GetVariableObservers()
|
||||||
|
{
|
||||||
|
if (Info.LandOnCondition != null)
|
||||||
|
yield return new VariableObserver(ForceLandConditionChanged, Info.LandOnCondition.Variables);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ForceLandConditionChanged(Actor self, IReadOnlyDictionary<string, int> variables)
|
||||||
|
{
|
||||||
|
landNow = Info.LandOnCondition.Evaluate(variables);
|
||||||
|
}
|
||||||
|
|
||||||
public void Created(Actor self)
|
public void Created(Actor self)
|
||||||
{
|
{
|
||||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||||
@@ -208,6 +225,33 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.QueueActivity(new TakeOff(self));
|
self.QueueActivity(new TakeOff(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add land activity if LandOnCondidion resolves to true and the actor can land at the current location.
|
||||||
|
if (landNow.HasValue && landNow.Value && airborne && CanLand(self.Location)
|
||||||
|
&& !(self.CurrentActivity is HeliLand || self.CurrentActivity is Turn))
|
||||||
|
{
|
||||||
|
self.CancelActivity();
|
||||||
|
|
||||||
|
if (Info.TurnToLand)
|
||||||
|
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||||
|
|
||||||
|
self.QueueActivity(new HeliLand(self, true));
|
||||||
|
|
||||||
|
ForceLanding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add takeoff activity if LandOnCondidion resolves to false and the actor should not land when idle.
|
||||||
|
if (landNow.HasValue && !landNow.Value && !cruising && !(self.CurrentActivity is TakeOff))
|
||||||
|
{
|
||||||
|
ForceLanding = false;
|
||||||
|
|
||||||
|
if (!Info.LandWhenIdle)
|
||||||
|
{
|
||||||
|
self.CancelActivity();
|
||||||
|
|
||||||
|
self.QueueActivity(new TakeOff(self));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var oldCachedPosition = cachedPosition;
|
var oldCachedPosition = cachedPosition;
|
||||||
cachedPosition = self.CenterPosition;
|
cachedPosition = self.CenterPosition;
|
||||||
isMoving = (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0;
|
isMoving = (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user