mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Update Target.lua
- Fixed escort problem
This commit is contained in:
parent
0c07a660ee
commit
afb63a7331
@ -113,7 +113,7 @@ _TARGETID=0
|
||||
|
||||
--- TARGET class version.
|
||||
-- @field #string version
|
||||
TARGET.version="0.2.0"
|
||||
TARGET.version="0.2.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@ -231,12 +231,14 @@ function TARGET:AddObject(Object)
|
||||
for _,object in pairs(set.Set) do
|
||||
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,6 +1003,65 @@ function TARGET:GetObject()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Count alive objects.
|
||||
-- @param #TARGET self
|
||||
-- @param #TARGET.Object Target Target objective.
|
||||
-- @return #number Number of alive target objects.
|
||||
function TARGET:CountObjectives(Target)
|
||||
|
||||
local N=1
|
||||
|
||||
if Target.Type==TARGET.ObjectType.GROUP then
|
||||
|
||||
local target=Target.Object --Wrapper.Group#GROUP
|
||||
|
||||
local units=target:GetUnits()
|
||||
|
||||
for _,_unit in pairs(units or {}) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive()~=nil and unit:GetLife()>1 then
|
||||
N=N+1
|
||||
end
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.UNIT then
|
||||
|
||||
local target=Target.Object --Wrapper.Unit#UNIT
|
||||
|
||||
if target and target:IsAlive() and target:GetLife()>1 then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.STATIC then
|
||||
|
||||
local target=Target.Object --Wrapper.Static#STATIC
|
||||
|
||||
if target and target:IsAlive() then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.SCENERY then
|
||||
|
||||
if Target.Status==TARGET.ObjectStatus.ALIVE then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.AIRBASE then
|
||||
|
||||
if Target.Status==TARGET.ObjectStatus.ALIVE then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.COORDINATE then
|
||||
|
||||
-- No target we can check!
|
||||
|
||||
else
|
||||
self:E(self.lid.."ERROR: Unknown target type! Cannot count targets")
|
||||
end
|
||||
|
||||
return N
|
||||
end
|
||||
|
||||
--- Count alive targets.
|
||||
-- @param #TARGET self
|
||||
@ -1000,54 +1073,7 @@ function TARGET:CountTargets()
|
||||
for _,_target in pairs(self.targets) do
|
||||
local Target=_target --#TARGET.Object
|
||||
|
||||
if Target.Type==TARGET.ObjectType.GROUP then
|
||||
|
||||
local target=Target.Object --Wrapper.Group#GROUP
|
||||
|
||||
local units=target:GetUnits()
|
||||
|
||||
for _,_unit in pairs(units or {}) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive()~=nil and unit:GetLife()>1 then
|
||||
N=N+1
|
||||
end
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.UNIT then
|
||||
|
||||
local target=Target.Object --Wrapper.Unit#UNIT
|
||||
|
||||
if target and target:IsAlive() and target:GetLife()>1 then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.STATIC then
|
||||
|
||||
local target=Target.Object --Wrapper.Static#STATIC
|
||||
|
||||
if target and target:IsAlive() then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.SCENERY then
|
||||
|
||||
if Target.Status==TARGET.ObjectStatus.ALIVE then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.AIRBASE then
|
||||
|
||||
if Target.Status==TARGET.ObjectStatus.ALIVE then
|
||||
N=N+1
|
||||
end
|
||||
|
||||
elseif Target.Type==TARGET.ObjectType.COORDINATE then
|
||||
|
||||
-- No target we can check!
|
||||
|
||||
else
|
||||
self:E(self.lid.."ERROR: Unknown target type! Cannot count targets")
|
||||
end
|
||||
N=N+self:CountObjectives(Target)
|
||||
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user