diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 9acd1b7307..6d0b976e1a 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -254,7 +254,7 @@ namespace OpenRA.Mods.Common.Activities // turnSpeed -> divide into 256 to get the number of ticks per complete rotation // speed -> multiply to get distance travelled per rotation (circumference) // 45 -> divide by 2*pi to get the turn radius: 45==256/(2*pi), with some extra leeway - return 45 * speed / turnSpeed; + return turnSpeed > 0 ? 45 * speed / turnSpeed : 0; } } } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index a9ee63c569..8f01b38da1 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -29,8 +29,8 @@ namespace OpenRA.Mods.Common.Traits LeaveMap, } - public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IMoveInfo, ICruiseAltitudeInfo, - IActorPreviewInitInfo, IEditorActorOptions, IObservesVariablesInfo + public class AircraftInfo : PausableConditionalTraitInfo, IPositionableInfo, IFacingInfo, IMoveInfo, ICruiseAltitudeInfo, + IActorPreviewInitInfo, IEditorActorOptions { [Desc("Behavior when aircraft becomes idle. Options are Land, ReturnToBase, LeaveMap, and None.", "'Land' will behave like 'None' (hover or circle) if a suitable landing site is not available.")] @@ -139,20 +139,20 @@ namespace OpenRA.Mods.Common.Traits [Desc("Boolean expression defining the condition under which the regular (non-force) move cursor is disabled.")] 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 WDist GetCruiseAltitude() { return CruiseAltitude; } - public virtual object Create(ActorInitializer init) { return new Aircraft(init, this); } + public override object Create(ActorInitializer init) { return new Aircraft(init, this); } IEnumerable IActorPreviewInitInfo.ActorPreviewInits(ActorInfo ai, ActorPreviewType type) { yield return new FacingInit(PreviewFacing); } - [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 IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary(); } bool IOccupySpaceInfo.SharesCell { get { return false; } } @@ -189,13 +189,12 @@ namespace OpenRA.Mods.Common.Traits } } - public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier, - INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, INotifyBecomingIdle, - IActorPreviewInitModifier, IIssueDeployOrder, IObservesVariables, ICreationActivity + public class Aircraft : PausableConditionalTrait, ITick, ISync, IFacing, IPositionable, IMove, + INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, INotifyBecomingIdle, ICreationActivity, + IActorPreviewInitModifier, IDeathActorInitModifier, IIssueDeployOrder, IIssueOrder, IResolveOrder, IOrderVoice { static readonly Pair[] NoCells = { }; - public readonly AircraftInfo Info; readonly Actor self; Repairable repairable; @@ -241,8 +240,8 @@ namespace OpenRA.Mods.Common.Traits bool? landNow; public Aircraft(ActorInitializer init, AircraftInfo info) + : base(info) { - Info = info; self = init.Self; if (init.Contains()) @@ -278,8 +277,11 @@ namespace OpenRA.Mods.Common.Traits return pos; } - public virtual IEnumerable GetVariableObservers() + public override IEnumerable GetVariableObservers() { + foreach (var observer in base.GetVariableObservers()) + yield return observer; + if (Info.LandOnCondition != null) yield return new VariableObserver(ForceLandConditionChanged, Info.LandOnCondition.Variables); @@ -297,12 +299,7 @@ namespace OpenRA.Mods.Common.Traits requireForceMove = Info.RequireForceMoveCondition.Evaluate(conditions); } - void INotifyCreated.Created(Actor self) - { - Created(self); - } - - protected virtual void Created(Actor self) + protected override void Created(Actor self) { repairable = self.TraitOrDefault(); rearmable = self.TraitOrDefault(); @@ -312,6 +309,8 @@ namespace OpenRA.Mods.Common.Traits notifyMoving = self.TraitsImplementing().ToArray(); positionOffsets = self.TraitsImplementing().ToArray(); overrideAircraftLanding = self.TraitOrDefault(); + + base.Created(self); } void INotifyAddedToWorld.AddedToWorld(Actor self)