From 3ac6739a8de7661dbce415f9004fca60070039f1 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 1 Oct 2016 12:31:13 +0200 Subject: [PATCH 1/3] Target.FromActor never returns a TargetType.FrozenActor --- OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs index b50d1bdbe7..ea43794824 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Scripting public void Attack(Actor targetActor, bool allowMove = true, bool forceAttack = false) { var target = Target.FromActor(targetActor); - if (!target.IsValidFor(Self) || target.Type == TargetType.FrozenActor) + if (!target.IsValidFor(Self)) Log.Write("lua", "{1} is an invalid target for {0}!", Self, targetActor); if (!targetActor.Info.HasTraitInfo() && !Self.Owner.CanTargetActor(targetActor)) From 5d2a6ff2e742791a548bdbcd308b2ef3579ee32d Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 4 Oct 2016 10:02:18 +0200 Subject: [PATCH 2/3] Add a CanTarget method to lua --- OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs index ea43794824..4140b949b4 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/CombatProperties.cs @@ -98,5 +98,11 @@ namespace OpenRA.Mods.Common.Scripting attackBase.AttackTarget(target, true, allowMove, forceAttack); } + + [Desc("Checks if the targeted actor is a valid target for this actor.")] + public bool CanTarget(Actor targetActor) + { + return Target.FromActor(targetActor).IsValidFor(Self); + } } } From 47968aabdc8a6a6cbdbc9cf9f3559ba01816b255 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 4 Oct 2016 10:04:59 +0200 Subject: [PATCH 3/3] Fix yaks trying to attack invalid targets --- mods/ra/maps/allies-04/allies04-AI.lua | 7 +++---- mods/ra/maps/allies-05a/allies05a-AI.lua | 6 ++---- mods/ra/maps/evacuation/evacuation.lua | 2 +- mods/ra/maps/exodus/exodus.lua | 17 ++++++++--------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/mods/ra/maps/allies-04/allies04-AI.lua b/mods/ra/maps/allies-04/allies04-AI.lua index 50d1807fd6..3a3ceaa924 100644 --- a/mods/ra/maps/allies-04/allies04-AI.lua +++ b/mods/ra/maps/allies-04/allies04-AI.lua @@ -236,15 +236,14 @@ end TargetAndAttack = function(yak, target) if not target or target.IsDead or (not target.IsInWorld) then - local enemies = Utils.Where(Map.ActorsInWorld, function(self) return self.Owner == player and self.HasProperty("Health") end) + local enemies = Utils.Where(Map.ActorsInWorld, function(self) return self.Owner == player and self.HasProperty("Health") and yak.CanTarget(self) end) + if #enemies > 0 then target = Utils.Random(enemies) - else - yak.Wait(DateTime.Seconds(5)) end end - if target and yak.AmmoCount() > 0 then + if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then yak.Attack(target) else yak.ReturnToBase() diff --git a/mods/ra/maps/allies-05a/allies05a-AI.lua b/mods/ra/maps/allies-05a/allies05a-AI.lua index 2803e1d6bd..d766fc2425 100644 --- a/mods/ra/maps/allies-05a/allies05a-AI.lua +++ b/mods/ra/maps/allies-05a/allies05a-AI.lua @@ -257,15 +257,13 @@ end TargetAndAttack = function(yak, target) if not target or target.IsDead or (not target.IsInWorld) then - local enemies = Utils.Where(Map.ActorsInWorld, function(self) return self.Owner == greece and self.HasProperty("Health") end) + local enemies = Utils.Where(Map.ActorsInWorld, function(self) return self.Owner == greece and self.HasProperty("Health") and yak.CanTarget(self) end) if #enemies > 0 then target = Utils.Random(enemies) - else - yak.Wait(DateTime.Seconds(5)) end end - if target and yak.AmmoCount() > 0 then + if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then yak.Attack(target) else yak.ReturnToBase() diff --git a/mods/ra/maps/evacuation/evacuation.lua b/mods/ra/maps/evacuation/evacuation.lua index 0c0772ebba..44db3d3ec6 100644 --- a/mods/ra/maps/evacuation/evacuation.lua +++ b/mods/ra/maps/evacuation/evacuation.lua @@ -75,7 +75,7 @@ end Yak = nil YakAttack = function(yak) local targets = Map.ActorsInCircle(YakAttackPoint.CenterPosition, WDist.FromCells(10), function(a) - return a.Owner == allies1 and not a.IsDead and a ~= Einstein and a ~= Tanya and a ~= Engineer + return a.Owner == allies1 and not a.IsDead and a ~= Einstein and a ~= Tanya and a ~= Engineer and yak.CanTarget(a) end) if (#targets > 0) then diff --git a/mods/ra/maps/exodus/exodus.lua b/mods/ra/maps/exodus/exodus.lua index cd7c038002..959976f023 100644 --- a/mods/ra/maps/exodus/exodus.lua +++ b/mods/ra/maps/exodus/exodus.lua @@ -204,31 +204,30 @@ ManageSovietUnits = function() Utils.Do(scatteredUnits, IdleHunt) end -AircraftTargets = function() +AircraftTargets = function(yak) local targets = Utils.Where(Map.ActorsInWorld, function(a) - return (a.Owner == allies1 or a.Owner == allies2) and a.HasProperty("Health") + return (a.Owner == allies1 or a.Owner == allies2) and a.HasProperty("Health") and yak.CanTarget(a) end) - -- prefer mobile units + -- Prefer mobile units table.sort(targets, function(a, b) return a.HasProperty("Move") and not b.HasProperty("Move") end) return targets end YakAttack = function(yak, target) - if not target or target.IsDead or (not target.IsInWorld) then - local targets = AircraftTargets() + if not target or target.IsDead or (not target.IsInWorld) or (not yak.CanTarget(target)) then + local targets = AircraftTargets(yak) if #targets > 0 then target = Utils.Random(targets) - else - yak.Wait(DateTime.Seconds(5)) end end - if target and yak.AmmoCount() > 0 then + if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then yak.Attack(target) else - yak.ReturnToBase() -- includes yak.Resupply() + -- Includes yak.Resupply() + yak.ReturnToBase() end yak.CallFunc(function()