Update Target.lua

- Fixed escort problem
This commit is contained in:
Frank
2020-11-19 19:51:58 +01:00
parent 0c07a660ee
commit afb63a7331
+39 -13
View File
@@ -113,7 +113,7 @@ _TARGETID=0
--- TARGET class version.
-- @field #string version
TARGET.version="0.2.0"
TARGET.version="0.2.1"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@@ -232,11 +232,13 @@ function TARGET:AddObject(Object)
self:AddObject(object)
end
--[[
elseif Object:IsInstanceOf("GROUP") then
for _,unit in pairs(Object:GetUnits()) do
self:_AddObject(unit)
end
]]
else
@@ -427,15 +429,27 @@ function TARGET:OnEventUnitDeadOrLost(EventData)
-- Debug info.
self:T(self.lid..string.format("EVENT: Unit %s dead or lost!", tostring(EventData.IniUnitName)))
-- Get target.
local target=self:GetTargetByName(EventData.IniUnitName)
local deadnow=false
if not target then
target=self:GetTargetByName(EventData.IniGroupName)
-- Target
local target=self:GetTargetByName(EventData.IniGroupName)
if target then
local N=self:CountObjectives(target)
if N==0 then
deadnow=true
end
else
target=self:GetTargetByName(EventData.IniUnitName)
if target then
deadnow=true
end
end
-- Check if this is one of ours.
if target and target.Status==TARGET.ObjectStatus.ALIVE then
if deadnow and target.Status==TARGET.ObjectStatus.ALIVE then
-- Debug message.
self:T(self.lid..string.format("EVENT: target unit %s dead or lost ==> destroyed", tostring(target.Name)))
@@ -989,16 +1003,13 @@ function TARGET:GetObject()
return nil
end
--- Count alive targets.
--- Count alive objects.
-- @param #TARGET self
-- @param #TARGET.Object Target Target objective.
-- @return #number Number of alive target objects.
function TARGET:CountTargets()
function TARGET:CountObjectives(Target)
local N=0
for _,_target in pairs(self.targets) do
local Target=_target --#TARGET.Object
local N=1
if Target.Type==TARGET.ObjectType.GROUP then
@@ -1049,6 +1060,21 @@ function TARGET:CountTargets()
self:E(self.lid.."ERROR: Unknown target type! Cannot count targets")
end
return N
end
--- Count alive targets.
-- @param #TARGET self
-- @return #number Number of alive target objects.
function TARGET:CountTargets()
local N=0
for _,_target in pairs(self.targets) do
local Target=_target --#TARGET.Object
N=N+self:CountObjectives(Target)
end
return N