Replace LandOnCondition with landing when paused

This commit is contained in:
reaperrr
2019-10-22 13:37:22 +02:00
committed by Paul Chote
parent ac44367440
commit 16c2062d9d

View File

@@ -139,10 +139,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Boolean expression defining the condition under which the regular (non-force) move cursor is disabled.")] [Desc("Boolean expression defining the condition under which the regular (non-force) move cursor is disabled.")]
public readonly BooleanExpression RequireForceMoveCondition = null; public readonly BooleanExpression RequireForceMoveCondition = null;
[Desc("Condition when this aircraft should land as soon as possible and refuse to take off. ",
"This only applies while the aircraft is above terrain which is listed in LandableTerrainTypes.")]
public readonly BooleanExpression LandOnCondition;
public int GetInitialFacing() { return InitialFacing; } public int GetInitialFacing() { return InitialFacing; }
public WDist GetCruiseAltitude() { return CruiseAltitude; } public WDist GetCruiseAltitude() { return CruiseAltitude; }
@@ -237,7 +233,6 @@ namespace OpenRA.Mods.Common.Traits
MovementType movementTypes; MovementType movementTypes;
WPos cachedPosition; WPos cachedPosition;
int cachedFacing; int cachedFacing;
bool? landNow;
public Aircraft(ActorInitializer init, AircraftInfo info) public Aircraft(ActorInitializer init, AircraftInfo info)
: base(info) : base(info)
@@ -282,18 +277,10 @@ namespace OpenRA.Mods.Common.Traits
foreach (var observer in base.GetVariableObservers()) foreach (var observer in base.GetVariableObservers())
yield return observer; yield return observer;
if (Info.LandOnCondition != null)
yield return new VariableObserver(ForceLandConditionChanged, Info.LandOnCondition.Variables);
if (Info.RequireForceMoveCondition != null) if (Info.RequireForceMoveCondition != null)
yield return new VariableObserver(RequireForceMoveConditionChanged, Info.RequireForceMoveCondition.Variables); yield return new VariableObserver(RequireForceMoveConditionChanged, Info.RequireForceMoveCondition.Variables);
} }
void ForceLandConditionChanged(Actor self, IReadOnlyDictionary<string, int> variables)
{
landNow = Info.LandOnCondition.Evaluate(variables);
}
void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions) void RequireForceMoveConditionChanged(Actor self, IReadOnlyDictionary<string, int> conditions)
{ {
requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions); requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions);
@@ -350,16 +337,16 @@ namespace OpenRA.Mods.Common.Traits
protected virtual void Tick(Actor self) protected virtual void Tick(Actor self)
{ {
// Add land activity if LandOnCondition resolves to true and the actor can land at the current location. // Add land activity if Aircraft trait is paused and the actor can land at the current location.
if (!ForceLanding && landNow.HasValue && landNow.Value && airborne && CanLand(self.Location) if (!ForceLanding && IsTraitPaused && airborne && CanLand(self.Location)
&& !((self.CurrentActivity is Land) || self.CurrentActivity is Turn)) && !((self.CurrentActivity is Land) || self.CurrentActivity is Turn))
{ {
self.QueueActivity(false, new Land(self)); self.QueueActivity(false, new Land(self));
ForceLanding = true; ForceLanding = true;
} }
// Add takeoff activity if LandOnCondition resolves to false and the actor should not land when idle. // Add takeoff activity if Aircraft trait is not paused and the actor should not land when idle.
if (ForceLanding && landNow.HasValue && !landNow.Value && !cruising && !(self.CurrentActivity is TakeOff)) if (ForceLanding && !IsTraitPaused && !cruising && !(self.CurrentActivity is TakeOff))
{ {
ForceLanding = false; ForceLanding = false;