Fix yaks trying to attack invalid targets

This commit is contained in:
abcdefg30
2016-10-04 10:04:59 +02:00
parent 5d2a6ff2e7
commit 47968aabdc
4 changed files with 14 additions and 18 deletions

View File

@@ -236,15 +236,14 @@ end
TargetAndAttack = function(yak, target) TargetAndAttack = function(yak, target)
if not target or target.IsDead or (not target.IsInWorld) then 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 if #enemies > 0 then
target = Utils.Random(enemies) target = Utils.Random(enemies)
else
yak.Wait(DateTime.Seconds(5))
end end
end end
if target and yak.AmmoCount() > 0 then if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then
yak.Attack(target) yak.Attack(target)
else else
yak.ReturnToBase() yak.ReturnToBase()

View File

@@ -257,15 +257,13 @@ end
TargetAndAttack = function(yak, target) TargetAndAttack = function(yak, target)
if not target or target.IsDead or (not target.IsInWorld) then 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 if #enemies > 0 then
target = Utils.Random(enemies) target = Utils.Random(enemies)
else
yak.Wait(DateTime.Seconds(5))
end end
end end
if target and yak.AmmoCount() > 0 then if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then
yak.Attack(target) yak.Attack(target)
else else
yak.ReturnToBase() yak.ReturnToBase()

View File

@@ -75,7 +75,7 @@ end
Yak = nil Yak = nil
YakAttack = function(yak) YakAttack = function(yak)
local targets = Map.ActorsInCircle(YakAttackPoint.CenterPosition, WDist.FromCells(10), function(a) 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) end)
if (#targets > 0) then if (#targets > 0) then

View File

@@ -204,31 +204,30 @@ ManageSovietUnits = function()
Utils.Do(scatteredUnits, IdleHunt) Utils.Do(scatteredUnits, IdleHunt)
end end
AircraftTargets = function() AircraftTargets = function(yak)
local targets = Utils.Where(Map.ActorsInWorld, function(a) 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) end)
-- prefer mobile units -- Prefer mobile units
table.sort(targets, function(a, b) return a.HasProperty("Move") and not b.HasProperty("Move") end) table.sort(targets, function(a, b) return a.HasProperty("Move") and not b.HasProperty("Move") end)
return targets return targets
end end
YakAttack = function(yak, target) YakAttack = function(yak, target)
if not target or target.IsDead or (not target.IsInWorld) then if not target or target.IsDead or (not target.IsInWorld) or (not yak.CanTarget(target)) then
local targets = AircraftTargets() local targets = AircraftTargets(yak)
if #targets > 0 then if #targets > 0 then
target = Utils.Random(targets) target = Utils.Random(targets)
else
yak.Wait(DateTime.Seconds(5))
end end
end end
if target and yak.AmmoCount() > 0 then if target and yak.AmmoCount() > 0 and yak.CanTarget(target) then
yak.Attack(target) yak.Attack(target)
else else
yak.ReturnToBase() -- includes yak.Resupply() -- Includes yak.Resupply()
yak.ReturnToBase()
end end
yak.CallFunc(function() yak.CallFunc(function()