From 2a0a7541ba1e55f73750e261984659ede3eef99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Husti=C4=87?= Date: Fri, 9 Oct 2015 23:22:59 +0200 Subject: [PATCH 1/2] Gets AttackMove to work with 'Defend' stance --- OpenRA.Mods.Common/Traits/AutoTarget.cs | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 5f5feb8836..8a45e5fcb5 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -104,8 +104,9 @@ namespace OpenRA.Mods.Common.Traits return; Aggressor = attacker; - if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend)) - Attack(self, Aggressor); + var allowMove = info.AllowMovement && Stance != UnitStance.Defend; + if (at == null || !at.IsReachableTarget(at.Target, allowMove)) + Attack(self, Aggressor, allowMove); } public void TickIdle(Actor self) @@ -113,9 +114,9 @@ namespace OpenRA.Mods.Common.Traits if (Stance < UnitStance.Defend || !info.TargetWhenIdle) return; - var allowMovement = info.AllowMovement && Stance != UnitStance.Defend; - if (at == null || !at.IsReachableTarget(at.Target, allowMovement)) - ScanAndAttack(self, allowMovement); + var allowMove = info.AllowMovement && Stance != UnitStance.Defend; + if (at == null || !at.IsReachableTarget(at.Target, allowMove)) + ScanAndAttack(self, allowMove); } public void Tick(Actor self) @@ -143,15 +144,15 @@ namespace OpenRA.Mods.Common.Traits { var targetActor = ScanForTarget(self, null, allowMove); if (targetActor != null) - Attack(self, targetActor); + Attack(self, targetActor, allowMove); } - void Attack(Actor self, Actor targetActor) + void Attack(Actor self, Actor targetActor, bool allowMove) { TargetedActor = targetActor; var target = Target.FromActor(targetActor); self.SetTargetLine(target, Color.Red, false); - attack.AttackTarget(target, false, info.AllowMovement && Stance != UnitStance.Defend); + attack.AttackTarget(target, false, allowMove); } Actor ChooseTarget(Actor self, WDist range, bool allowMove) @@ -168,10 +169,16 @@ namespace OpenRA.Mods.Common.Traits // Select only the first compatible armament for each actor: if this actor is selected // it will be thanks to the first armament anyways, since that is the first selection // criterion - .Select(a => new KeyValuePair( - attack.ChooseArmamentsForTarget(Target.FromActor(a), false) - .Where(arm => allowMove || arm.MaxRange().Length > (a.CenterPosition - self.CenterPosition).Length) - .FirstOrDefault(), a)) + .Select(a => + { + var target = Target.FromActor(a); + return new KeyValuePair( + attack.ChooseArmamentsForTarget(target, false) + .Where(arm => allowMove + || (target.IsInRange(self.CenterPosition, arm.MaxRange()) + && !target.IsInRange(self.CenterPosition, arm.Weapon.MinRange))) + .FirstOrDefault(), a); + }) .Where(kv => kv.Key != null && kv.Value.TraitOrDefault() == null) .GroupBy(kv => kv.Key, kv => kv.Value) From 1ba81d7c97bc9ddcf85d41880d6806d6f62448db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Husti=C4=87?= Date: Sat, 10 Oct 2015 11:48:14 +0200 Subject: [PATCH 2/2] Fixes bad comment in UpgradeRules https://github.com/OpenRA/OpenRA/pull/8768/files#r41694572 --- OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 3bca6a0490..b022e125c8 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -2200,9 +2200,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (engineVersion < 20151005) { - // Move certain properties from Parachutable to new WithParachute trait - // Add dependency traits to actors implementing Parachutable - // Make otherwise targetable parachuting actors untargetable + // Units with AutoHeal have it replaced by AutoTarget var heal = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AutoHeal")); if (heal != null) { @@ -2219,6 +2217,7 @@ namespace OpenRA.Mods.Common.UtilityCommands node.Value.Nodes.Remove(heal); } + // Units with AttackMedic have it replaced by an appropriate AttackFrontal var atkmedic = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AttackMedic")); if (atkmedic != null) {