Finish Detection_error_with_units_and_types

This commit is contained in:
FlightControl_Master 2018-03-26 05:34:20 +02:00
commit 08cc4e3530
3 changed files with 29 additions and 9 deletions

View File

@ -826,7 +826,7 @@ function EVENT:onEvent( Event )
Event.TgtDCSUnit = Event.target Event.TgtDCSUnit = Event.target
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName() Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = STATIC:FindByName( Event.TgtDCSUnitName ) Event.TgtUnit = STATIC:FindByName( Event.TgtDCSUnitName, false )
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition() Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName() Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()

View File

@ -793,16 +793,16 @@ do -- DESIGNATE
-- @return #DESIGNATE -- @return #DESIGNATE
function DESIGNATE:DesignationScope() function DESIGNATE:DesignationScope()
local DetectedItems = self.Detection:GetDetectedItems() local DetectedItems = self.Detection:GetDetectedItemsByIndex()
local DetectedItemCount = 0 local DetectedItemCount = 0
for DesignateIndex, Designating in pairs( self.Designating ) do for DesignateIndex, Designating in pairs( self.Designating ) do
local DetectedItem = DetectedItems[DesignateIndex] local DetectedItem = self.Detection:GetDetectedItemByIndex( DesignateIndex )
if DetectedItem then if DetectedItem then
-- Check LOS... -- Check LOS...
local IsDetected = self.Detection:IsDetectedItemDetected( DetectedItem ) local IsDetected = self.Detection:IsDetectedItemDetected( DetectedItem )
self:F({IsDetected = IsDetected, DetectedItem }) self:F({IsDetected = IsDetected })
if IsDetected == false then if IsDetected == false then
self:F("Removing") self:F("Removing")
-- This Detection is obsolete, remove from the designate scope -- This Detection is obsolete, remove from the designate scope
@ -861,7 +861,7 @@ do -- DESIGNATE
-- @return #DESIGNATE -- @return #DESIGNATE
function DESIGNATE:CoordinateLase() function DESIGNATE:CoordinateLase()
local DetectedItems = self.Detection:GetDetectedItems() local DetectedItems = self.Detection:GetDetectedItemsByIndex()
for DesignateIndex, Designating in pairs( self.Designating ) do for DesignateIndex, Designating in pairs( self.Designating ) do
local DetectedItem = DetectedItems[DesignateIndex] local DetectedItem = DetectedItems[DesignateIndex]
@ -891,7 +891,7 @@ do -- DESIGNATE
if self.FlashStatusMenu[AttackGroup] or ( MenuAttackGroup and ( AttackGroup:GetName() == MenuAttackGroup:GetName() ) ) then if self.FlashStatusMenu[AttackGroup] or ( MenuAttackGroup and ( AttackGroup:GetName() == MenuAttackGroup:GetName() ) ) then
local DetectedReport = REPORT:New( "Targets ready for Designation:" ) local DetectedReport = REPORT:New( "Targets ready for Designation:" )
local DetectedItems = self.Detection:GetDetectedItems() local DetectedItems = self.Detection:GetDetectedItemsByIndex()
for DesignateIndex, Designating in pairs( self.Designating ) do for DesignateIndex, Designating in pairs( self.Designating ) do
local DetectedItem = DetectedItems[DesignateIndex] local DetectedItem = DetectedItems[DesignateIndex]

View File

@ -1517,7 +1517,8 @@ do -- DETECTION_BASE
end end
--- Get the detected @{Set#SET_BASE}s. --- Get the DetectedItems by Key.
-- This will return the DetectedItems collection, indexed by the Key, which can be any object that acts as the key of the detection.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @return #DETECTION_BASE.DetectedItems -- @return #DETECTION_BASE.DetectedItems
function DETECTION_BASE:GetDetectedItems() function DETECTION_BASE:GetDetectedItems()
@ -1525,6 +1526,15 @@ do -- DETECTION_BASE
return self.DetectedItems return self.DetectedItems
end end
--- Get the DetectedItems by Index.
-- This will return the DetectedItems collection, indexed by an internal numerical Index.
-- @param #DETECTION_BASE self
-- @return #DETECTION_BASE.DetectedItems
function DETECTION_BASE:GetDetectedItemsByIndex()
return self.DetectedItemsByIndex
end
--- Get the amount of SETs with detected objects. --- Get the amount of SETs with detected objects.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @return #number The amount of detected items. Note that the amount of detected items can differ with the reality, because detections are not real-time but doen in intervals! -- @return #number The amount of detected items. Note that the amount of detected items can differ with the reality, because detections are not real-time but doen in intervals!
@ -1880,7 +1890,7 @@ do -- DETECTION_UNITS
-- Loop the current detected items, and check if each object still exists and is detected. -- Loop the current detected items, and check if each object still exists and is detected.
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do for DetectedItemKey, DetectedItem in pairs( self.DetectedItems ) do
local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT
@ -1915,6 +1925,11 @@ do -- DETECTION_UNITS
DetectedItemSet:Remove( DetectedUnitName ) DetectedItemSet:Remove( DetectedUnitName )
end end
end end
if DetectedItemSet:Count() == 0 then
-- Now the Set is empty, meaning that a detected item has no units anymore.
-- Delete the DetectedItem from the detections
self:RemoveDetectedItem( DetectedItemKey )
end
end end
@ -2126,7 +2141,7 @@ do -- DETECTION_TYPES
-- Loop the current detected items, and check if each object still exists and is detected. -- Loop the current detected items, and check if each object still exists and is detected.
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do for DetectedItemKey, DetectedItem in pairs( self.DetectedItems ) do
local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT
local DetectedTypeName = DetectedItem.TypeName local DetectedTypeName = DetectedItem.TypeName
@ -2149,6 +2164,11 @@ do -- DETECTION_TYPES
DetectedItemSet:Remove( DetectedUnitName ) DetectedItemSet:Remove( DetectedUnitName )
end end
end end
if DetectedItemSet:Count() == 0 then
-- Now the Set is empty, meaning that a detected item has no units anymore.
-- Delete the DetectedItem from the detections
self:RemoveDetectedItem( DetectedItemKey )
end
end end