From 7ddd6aab930c451fef0c9c9150da1610e2d022f7 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 8 Apr 2015 00:31:40 +0200 Subject: [PATCH] Make helicopters move backwards when target is too close 'Too close' as in closer than weapons' MinRange. --- OpenRA.Mods.Common/Activities/Air/HeliAttack.cs | 13 +++++++++++++ OpenRA.Mods.Common/Traits/Attack/AttackBase.cs | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index 576fc75edc..0e2839bd6f 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -57,6 +57,19 @@ namespace OpenRA.Mods.Common.Activities if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRange())) helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); + // Fly backwards from the target + // TODO: Same problem as with MaximumRange + if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRange())) + { + // Facing 0 doesn't work with the following position change + var facing = 1; + if (desiredFacing != 0) + facing = desiredFacing; + else if (helicopter.Facing != 0) + facing = helicopter.Facing; + helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(-facing)); + } + attackHeli.DoAttack(self, target); return this; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index ae9ba6267a..a76bccee40 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -157,6 +157,15 @@ namespace OpenRA.Mods.Common.Traits return Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World, self)); } + public WRange GetMinimumRange() + { + if (IsTraitDisabled) + return WRange.Zero; + + return Armaments.Where(a => !a.IsTraitDisabled) + .Select(a => a.Weapon.MinRange).Min(); + } + public WRange GetMaximumRange() { if (IsTraitDisabled)