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:
@@ -113,7 +113,7 @@ _TARGETID=0
|
|||||||
|
|
||||||
--- TARGET class version.
|
--- TARGET class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
TARGET.version="0.2.0"
|
TARGET.version="0.2.1"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@@ -231,12 +231,14 @@ function TARGET:AddObject(Object)
|
|||||||
for _,object in pairs(set.Set) do
|
for _,object in pairs(set.Set) do
|
||||||
self:AddObject(object)
|
self:AddObject(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
elseif Object:IsInstanceOf("GROUP") then
|
elseif Object:IsInstanceOf("GROUP") then
|
||||||
|
|
||||||
for _,unit in pairs(Object:GetUnits()) do
|
for _,unit in pairs(Object:GetUnits()) do
|
||||||
self:_AddObject(unit)
|
self:_AddObject(unit)
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
@@ -427,15 +429,27 @@ function TARGET:OnEventUnitDeadOrLost(EventData)
|
|||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:T(self.lid..string.format("EVENT: Unit %s dead or lost!", tostring(EventData.IniUnitName)))
|
self:T(self.lid..string.format("EVENT: Unit %s dead or lost!", tostring(EventData.IniUnitName)))
|
||||||
|
|
||||||
-- Get target.
|
local deadnow=false
|
||||||
local target=self:GetTargetByName(EventData.IniUnitName)
|
|
||||||
|
|
||||||
if not target then
|
-- Target
|
||||||
target=self:GetTargetByName(EventData.IniGroupName)
|
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
|
end
|
||||||
|
|
||||||
-- Check if this is one of ours.
|
-- 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.
|
-- Debug message.
|
||||||
self:T(self.lid..string.format("EVENT: target unit %s dead or lost ==> destroyed", tostring(target.Name)))
|
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
|
return nil
|
||||||
end
|
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.
|
--- Count alive targets.
|
||||||
-- @param #TARGET self
|
-- @param #TARGET self
|
||||||
@@ -1000,54 +1073,7 @@ function TARGET:CountTargets()
|
|||||||
for _,_target in pairs(self.targets) do
|
for _,_target in pairs(self.targets) do
|
||||||
local Target=_target --#TARGET.Object
|
local Target=_target --#TARGET.Object
|
||||||
|
|
||||||
if Target.Type==TARGET.ObjectType.GROUP then
|
N=N+self:CountObjectives(Target)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user