From 9dba85def54678ad606fa411d5f25d287f9e9b17 Mon Sep 17 00:00:00 2001 From: teees Date: Thu, 3 Dec 2015 10:13:18 +0100 Subject: [PATCH] Use heightmap to get correct groundlevel, fix additional behavior --- OpenRA.Mods.Common/Traits/Air/AttackPlane.cs | 8 ++++++-- OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Air/AttackPlane.cs b/OpenRA.Mods.Common/Traits/Air/AttackPlane.cs index d967592ae2..e590f756c4 100644 --- a/OpenRA.Mods.Common/Traits/Air/AttackPlane.cs +++ b/OpenRA.Mods.Common/Traits/Air/AttackPlane.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class AttackPlaneInfo : AttackFrontalInfo + public class AttackPlaneInfo : AttackFrontalInfo, Requires { [Desc("Delay, in game ticks, before turning to attack.")] public readonly int AttackTurnDelay = 50; @@ -25,11 +25,13 @@ namespace OpenRA.Mods.Common.Traits public class AttackPlane : AttackFrontal { public readonly AttackPlaneInfo AttackPlaneInfo; + readonly AircraftInfo aircraftInfo; public AttackPlane(Actor self, AttackPlaneInfo info) : base(self, info) { AttackPlaneInfo = info; + aircraftInfo = self.Info.TraitInfo(); } public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack) @@ -40,7 +42,9 @@ namespace OpenRA.Mods.Common.Traits protected override bool CanAttack(Actor self, Target target) { // Don't fire while landed or when outside the map. - return base.CanAttack(self, target) && self.CenterPosition.Z > 0 && self.World.Map.Contains(self.Location); + return base.CanAttack(self, target) + && self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length >= aircraftInfo.MinAirborneAltitude + && self.World.Map.Contains(self.Location); } } } diff --git a/OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs b/OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs index 1a2381ce79..f49db7a096 100644 --- a/OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs +++ b/OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs @@ -15,14 +15,24 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Return to a player owned RearmBuildings. If none available, head back to base and circle over it.")] - class ReturnOnIdleInfo : TraitInfo { } - - class ReturnOnIdle : INotifyIdle + public class ReturnOnIdleInfo : ITraitInfo, Requires { + public object Create(ActorInitializer init) { return new ReturnOnIdle(init.Self, this); } + } + + public class ReturnOnIdle : INotifyIdle + { + readonly AircraftInfo aircraftInfo; + + public ReturnOnIdle(Actor self, ReturnOnIdleInfo info) + { + aircraftInfo = self.Info.TraitInfo(); + } + public void TickIdle(Actor self) { // We're on the ground, let's stay there. - if (self.CenterPosition.Z == 0) + if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude) return; var airfield = ReturnToBase.ChooseAirfield(self, true);