Clean up the detection code. It is complicated

This commit is contained in:
FlightControl_Master 2018-03-17 05:23:44 +01:00
parent 0f18b29144
commit 9be9277a08
7 changed files with 128 additions and 216 deletions

View File

@ -784,7 +784,7 @@ do -- DETECTION_BASE
local DetectedItems = self:GetDetectedItems() local DetectedItems = self:GetDetectedItems()
for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do
local DetectedSet = self:GetDetectedSet( DetectedItemIndex ) local DetectedSet = self:GetDetectedSet( DetectedItem )
if DetectedSet then if DetectedSet then
DetectedSet:RemoveUnitsByName( UnitName ) DetectedSet:RemoveUnitsByName( UnitName )
end end
@ -1458,23 +1458,26 @@ do -- DETECTION_BASE
-- The DetectedItem is a table and contains a SET_UNIT in the field Set. -- The DetectedItem is a table and contains a SET_UNIT in the field Set.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param ItemPrefix -- @param ItemPrefix
-- @param #string DetectedItemIndex The index of the DetectedItem. -- @param DetectedItemKey The key of the DetectedItem.
-- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added. -- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added.
-- @return #DETECTION_BASE.DetectedItem -- @return #DETECTION_BASE.DetectedItem
function DETECTION_BASE:AddDetectedItem( ItemPrefix, DetectedItemIndex, Set ) function DETECTION_BASE:AddDetectedItem( ItemPrefix, DetectedItemKey, Set )
local DetectedItem = {} local DetectedItem = {}
self.DetectedItemCount = self.DetectedItemCount + 1 self.DetectedItemCount = self.DetectedItemCount + 1
self.DetectedItemMax = self.DetectedItemMax + 1 self.DetectedItemMax = self.DetectedItemMax + 1
if DetectedItemIndex then if DetectedItemKey then
self.DetectedItems[DetectedItemIndex] = DetectedItem self.DetectedItems[DetectedItemKey] = DetectedItem
else else
self.DetectedItems[self.DetectedItemMax] = DetectedItem self.DetectedItemsByIndex[self.DetectedItemMax] = DetectedItem
end end
self.DetectedItemsByIndex[self.DetectedItemMax] = DetectedItem
DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes() DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes()
DetectedItem.Index = DetectedItemIndex or self.DetectedItemMax DetectedItem.Index = DetectedItemKey or self.DetectedItemMax
DetectedItem.ItemID = ItemPrefix .. "." .. self.DetectedItemMax DetectedItem.ItemID = ItemPrefix .. "." .. self.DetectedItemMax
DetectedItem.ID = self.DetectedItemMax DetectedItem.ID = self.DetectedItemMax
DetectedItem.Removed = false DetectedItem.Removed = false
@ -1485,13 +1488,13 @@ do -- DETECTION_BASE
--- Adds a new DetectedItem to the DetectedItems list. --- Adds a new DetectedItem to the DetectedItems list.
-- The DetectedItem is a table and contains a SET_UNIT in the field Set. -- The DetectedItem is a table and contains a SET_UNIT in the field Set.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #string DetectedItemIndex The index of the DetectedItem. -- @param DetectedItemKey The key of the DetectedItem.
-- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added. -- @param Core.Set#SET_UNIT Set (optional) The Set of Units to be added.
-- @param Core.Zone#ZONE_UNIT Zone (optional) The Zone to be added where the Units are located. -- @param Core.Zone#ZONE_UNIT Zone (optional) The Zone to be added where the Units are located.
-- @return #DETECTION_BASE.DetectedItem -- @return #DETECTION_BASE.DetectedItem
function DETECTION_BASE:AddDetectedItemZone( DetectedItemIndex, Set, Zone ) function DETECTION_BASE:AddDetectedItemZone( DetectedItemKey, Set, Zone )
local DetectedItem = self:AddDetectedItem( "AREA", DetectedItemIndex, Set ) local DetectedItem = self:AddDetectedItem( "AREA", DetectedItemKey, Set )
DetectedItem.Zone = Zone DetectedItem.Zone = Zone
@ -1501,12 +1504,16 @@ do -- DETECTION_BASE
--- Removes an existing DetectedItem from the DetectedItems list. --- Removes an existing DetectedItem from the DetectedItems list.
-- The DetectedItem is a table and contains a SET_UNIT in the field Set. -- The DetectedItem is a table and contains a SET_UNIT in the field Set.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number DetectedItemIndex The index or position in the DetectedItems list where the item needs to be removed. -- @param DetectedItemKey The key in the DetectedItems list where the item needs to be removed.
function DETECTION_BASE:RemoveDetectedItem( DetectedItemIndex ) function DETECTION_BASE:RemoveDetectedItem( DetectedItemKey )
if self.DetectedItems[DetectedItemIndex] then local DetectedItem = self.DetectedItems[DetectedItemKey]
if DetectedItem then
self.DetectedItemCount = self.DetectedItemCount - 1 self.DetectedItemCount = self.DetectedItemCount - 1
self.DetectedItems[DetectedItemIndex] = nil local DetectedItemIndex = DetectedItem.Index
self.DetectedItemsByIndex[DetectedItemIndex] = nil
self.DetectedItems[DetectedItemKey] = nil
end end
end end
@ -1528,14 +1535,31 @@ do -- DETECTION_BASE
return DetectedCount return DetectedCount
end end
--- Get a detected item using a given Key.
-- @param #DETECTION_BASE self
-- @param Key
-- @return #DETECTION_BASE.DetectedItem
function DETECTION_BASE:GetDetectedItemByKey( Key )
self:F( { DetectedItems = self.DetectedItems } )
local DetectedItem = self.DetectedItems[Key]
if DetectedItem then
return DetectedItem
end
return nil
end
--- Get a detected item using a given numeric index. --- Get a detected item using a given numeric index.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #number Index
-- @return #DETECTION_BASE.DetectedItem -- @return #DETECTION_BASE.DetectedItem
function DETECTION_BASE:GetDetectedItem( Index ) function DETECTION_BASE:GetDetectedItemByIndex( Index )
self:F( { DetectedItems = self.DetectedItems } ) self:F( { DetectedItemsByIndex = self.DetectedItemsByIndex } )
local DetectedItem = self.DetectedItems[Index]
local DetectedItem = self.DetectedItemsByIndex[Index]
if DetectedItem then if DetectedItem then
return DetectedItem return DetectedItem
end end
@ -1545,16 +1569,11 @@ do -- DETECTION_BASE
--- Get a detected ItemID using a given numeric index. --- Get a detected ItemID using a given numeric index.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @return #string DetectedItemID -- @return #string DetectedItemID
function DETECTION_BASE:GetDetectedItemID( Index ) --R2.1 function DETECTION_BASE:GetDetectedItemID( DetectedItem ) --R2.1
local DetectedItem = self.DetectedItems[Index] return DetectedItem and DetectedItem.ItemID or ""
if DetectedItem then
return DetectedItem.ItemID
end
return ""
end end
--- Get a detected ID using a given numeric index. --- Get a detected ID using a given numeric index.
@ -1563,7 +1582,7 @@ do -- DETECTION_BASE
-- @return #string DetectedItemID -- @return #string DetectedItemID
function DETECTION_BASE:GetDetectedID( Index ) --R2.1 function DETECTION_BASE:GetDetectedID( Index ) --R2.1
local DetectedItem = self.DetectedItems[Index] local DetectedItem = self.DetectedItemsByIndex[Index]
if DetectedItem then if DetectedItem then
return DetectedItem.ID return DetectedItem.ID
end end
@ -1573,12 +1592,11 @@ do -- DETECTION_BASE
--- Get the @{Set#SET_UNIT} of a detecttion area using a given numeric index. --- Get the @{Set#SET_UNIT} of a detecttion area using a given numeric index.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #DETECTION_BASE.DetectedItem DetectedItem
-- @return Core.Set#SET_UNIT DetectedSet -- @return Core.Set#SET_UNIT DetectedSet
function DETECTION_BASE:GetDetectedSet( Index ) function DETECTION_BASE:GetDetectedSet( DetectedItem )
local DetectedItem = self:GetDetectedItem( Index ) local DetectedSetUnit = DetectedItem and DetectedItem.Set
local DetectedSetUnit = DetectedItem.Set
if DetectedSetUnit then if DetectedSetUnit then
return DetectedSetUnit return DetectedSetUnit
end end
@ -1623,11 +1641,11 @@ do -- DETECTION_BASE
--- Get the @{Zone#ZONE_UNIT} of a detection area using a given numeric index. --- Get the @{Zone#ZONE_UNIT} of a detection area using a given numeric index.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @return Core.Zone#ZONE_UNIT DetectedZone -- @return Core.Zone#ZONE_UNIT DetectedZone
function DETECTION_BASE:GetDetectedItemZone( Index ) function DETECTION_BASE:GetDetectedItemZone( DetectedItem )
local DetectedZone = self.DetectedItems[Index].Zone local DetectedZone = DetectedItem and DetectedItem.Zone
if DetectedZone then if DetectedZone then
return DetectedZone return DetectedZone
end end
@ -1642,7 +1660,7 @@ do -- DETECTION_BASE
--- Set the detected item coordinate. --- Set the detected item coordinate.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #DETECTION_BASE.DetectedItem The DetectedItem to set the coordinate at. -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem to set the coordinate at.
-- @param Core.Point#COORDINATE Coordinate The coordinate to set the last know detected position at. -- @param Core.Point#COORDINATE Coordinate The coordinate to set the last know detected position at.
-- @param Wrapper.Unit#UNIT DetectedItemUnit The unit to set the heading and altitude from. -- @param Wrapper.Unit#UNIT DetectedItemUnit The unit to set the heading and altitude from.
-- @return #DETECTION_BASE -- @return #DETECTION_BASE
@ -1662,12 +1680,10 @@ do -- DETECTION_BASE
--- Get the detected item coordinate. --- Get the detected item coordinate.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem to set the coordinate at.
-- @return Core.Point#COORDINATE -- @return Core.Point#COORDINATE
function DETECTION_BASE:GetDetectedItemCoordinate( Index ) function DETECTION_BASE:GetDetectedItemCoordinate( DetectedItem )
self:F( { Index = Index } ) self:F( { DetectedItem = DetectedItem } )
local DetectedItem = self:GetDetectedItem( Index )
if DetectedItem then if DetectedItem then
return DetectedItem.Coordinate return DetectedItem.Coordinate
@ -1693,12 +1709,10 @@ do -- DETECTION_BASE
--- Get the detected item coordinate. --- Get the detected item coordinate.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param #number Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @return #number ThreatLevel -- @return #number ThreatLevel
function DETECTION_BASE:GetDetectedItemThreatLevel( Index ) function DETECTION_BASE:GetDetectedItemThreatLevel( DetectedItem )
self:F( { Index = Index } ) self:F( { DetectedItem = DetectedItem } )
local DetectedItem = self:GetDetectedItem( Index )
if DetectedItem then if DetectedItem then
self:F( { ThreatLevel = DetectedItem.ThreatLevel, ThreatText = DetectedItem.ThreatText } ) self:F( { ThreatLevel = DetectedItem.ThreatLevel, ThreatText = DetectedItem.ThreatText } )
@ -1709,27 +1723,13 @@ do -- DETECTION_BASE
end end
--- Menu of a detected item using a given numeric index.
-- @param #DETECTION_BASE self
-- @param Index
-- @return #string
function DETECTION_BASE:DetectedItemMenu( Index, AttackGroup )
self:F( Index )
return nil
end
--- Report summary of a detected item using a given numeric index. --- Report summary of a detected item using a given numeric index.
-- @param #DETECTION_BASE self -- @param #DETECTION_BASE self
-- @param Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for.
-- @param Core.Settings#SETTINGS Settings Message formatting settings to use. -- @param Core.Settings#SETTINGS Settings Message formatting settings to use.
-- @return Core.Report#REPORT -- @return Core.Report#REPORT
function DETECTION_BASE:DetectedItemReportSummary( Index, AttackGroup, Settings ) function DETECTION_BASE:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
self:F( Index ) self:F( Index )
return nil return nil
end end
@ -1766,7 +1766,7 @@ do -- DETECTION_BASE
for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do
if RecceUnit:IsActive() then if RecceUnit:IsActive() then
local RecceUnitCoord = RecceUnit:GetCoordinate() local RecceUnitCoord = RecceUnit:GetCoordinate()
local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem.Index ) ) local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem ) )
if Distance < DistanceRecce then if Distance < DistanceRecce then
DistanceRecce = Distance DistanceRecce = Distance
NearestRecce = RecceUnit NearestRecce = RecceUnit
@ -1930,10 +1930,10 @@ do -- DETECTION_UNITS
if DetectedUnit then if DetectedUnit then
local DetectedTypeName = DetectedUnit:GetTypeName() local DetectedTypeName = DetectedUnit:GetTypeName()
local DetectedItem = self:GetDetectedItem( DetectedUnitName ) local DetectedItem = self:GetDetectedItemByKey( DetectedUnitName )
if not DetectedItem then if not DetectedItem then
self:T( "Added new DetectedItem" ) self:T( "Added new DetectedItem" )
DetectedItem = self:AddDetectedItem( "UNIT" ) DetectedItem = self:AddDetectedItem( "UNIT", DetectedUnitName )
DetectedItem.TypeName = DetectedUnit:GetTypeName() DetectedItem.TypeName = DetectedUnit:GetTypeName()
DetectedItem.Name = DetectedObject.Name DetectedItem.Name = DetectedObject.Name
DetectedItem.IsVisible = DetectedObject.IsVisible DetectedItem.IsVisible = DetectedObject.IsVisible
@ -1969,48 +1969,17 @@ do -- DETECTION_UNITS
end end
--- Menu of a DetectedItem using a given numeric index.
-- @param #DETECTION_UNITS self
-- @param Index
-- @return #string
function DETECTION_UNITS:DetectedItemMenu( Index, AttackGroup )
self:F( Index )
local DetectedItem = self:GetDetectedItem( Index )
local DetectedSet = self:GetDetectedSet( Index )
local DetectedItemID = self:GetDetectedItemID( Index )
self:T( DetectedSet )
if DetectedSet then
local ReportSummary = ""
local UnitDistanceText = ""
local UnitCategoryText = ""
local DetectedItemCoordinate = self:GetDetectedItemCoordinate( Index )
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup )
ReportSummary = string.format(
"%s - %s",
DetectedItemID,
DetectedItemCoordText
)
self:T( ReportSummary )
return ReportSummary
end
end
--- Report summary of a DetectedItem using a given numeric index. --- Report summary of a DetectedItem using a given numeric index.
-- @param #DETECTION_UNITS self -- @param #DETECTION_UNITS self
-- @param Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for.
-- @param Core.Settings#SETTINGS Settings Message formatting settings to use. -- @param Core.Settings#SETTINGS Settings Message formatting settings to use.
-- @return Core.Report#REPORT The report of the detection items. -- @return Core.Report#REPORT The report of the detection items.
function DETECTION_UNITS:DetectedItemReportSummary( Index, AttackGroup, Settings ) function DETECTION_UNITS:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
self:F( { Index, self.DetectedItems } ) self:F( { DetectedItem = DetectedItem } )
local DetectedItem = self:GetDetectedItem( Index ) local DetectedItemID = self:GetDetectedItemID( DetectedItem )
local DetectedItemID = self:GetDetectedItemID( Index )
if DetectedItem then if DetectedItem then
local ReportSummary = "" local ReportSummary = ""
@ -2040,10 +2009,10 @@ do -- DETECTION_UNITS
end end
--TODO: solve Index reference --TODO: solve Index reference
local DetectedItemCoordinate = self:GetDetectedItemCoordinate( Index ) local DetectedItemCoordinate = self:GetDetectedItemCoordinate( DetectedItem )
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings )
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( Index ) local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
local Report = REPORT:New() local Report = REPORT:New()
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
@ -2063,9 +2032,9 @@ do -- DETECTION_UNITS
self:F() self:F()
local Report = REPORT:New() local Report = REPORT:New()
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do
local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem
local ReportSummary = self:DetectedItemReportSummary( DetectedItemID, AttackGroup ) local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup )
Report:SetTitle( "Detected units:" ) Report:SetTitle( "Detected units:" )
Report:Add( ReportSummary:Text() ) Report:Add( ReportSummary:Text() )
end end
@ -2195,10 +2164,10 @@ do -- DETECTION_TYPES
if DetectedUnit then if DetectedUnit then
local DetectedTypeName = DetectedUnit:GetTypeName() local DetectedTypeName = DetectedUnit:GetTypeName()
local DetectedItem = self:GetDetectedItem( DetectedTypeName ) local DetectedItem = self:GetDetectedItemByKey( DetectedTypeName )
if not DetectedItem then if not DetectedItem then
DetectedItem = self:AddDetectedItem( "TYPE" ) DetectedItem = self:AddDetectedItem( "TYPE", DetectedTypeName )
DetectedItem.TypeName = DetectedUnit:GetTypeName() DetectedItem.TypeName = DetectedTypeName
end end
DetectedItem.Set:AddUnit( DetectedUnit ) DetectedItem.Set:AddUnit( DetectedUnit )
@ -2229,53 +2198,26 @@ do -- DETECTION_TYPES
end end
--- Menu of a DetectedItem using a given numeric index.
-- @param #DETECTION_TYPES self
-- @param Index
-- @return #string
function DETECTION_TYPES:DetectedItemMenu( DetectedTypeName, AttackGroup )
self:F( DetectedTypeName )
local DetectedItem = self:GetDetectedItem( DetectedTypeName )
local DetectedItemID = self:GetDetectedItemID( DetectedTypeName )
if DetectedItem then
local DetectedItemCoordinate = self:GetDetectedItemCoordinate( DetectedTypeName )
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup )
local ReportSummary = string.format(
"%s - %s",
DetectedItemID,
DetectedItemCoordText
)
self:T( ReportSummary )
return ReportSummary
end
end
--- Report summary of a DetectedItem using a given numeric index. --- Report summary of a DetectedItem using a given numeric index.
-- @param #DETECTION_TYPES self -- @param #DETECTION_TYPES self
-- @param Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for.
-- @param Core.Settings#SETTINGS Settings Message formatting settings to use. -- @param Core.Settings#SETTINGS Settings Message formatting settings to use.
-- @return Core.Report#REPORT The report of the detection items. -- @return Core.Report#REPORT The report of the detection items.
function DETECTION_TYPES:DetectedItemReportSummary( DetectedTypeName, AttackGroup, Settings ) function DETECTION_TYPES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
self:F( DetectedTypeName ) self:F( { DetectedItem = DetectedItem } )
local DetectedItem = self:GetDetectedItem( DetectedTypeName ) local DetectedSet = self:GetDetectedSet( DetectedItem )
local DetectedSet = self:GetDetectedSet( DetectedTypeName ) local DetectedItemID = self:GetDetectedItemID( DetectedItem )
local DetectedItemID = self:GetDetectedItemID( DetectedTypeName )
self:T( DetectedItem ) self:T( DetectedItem )
if DetectedItem then if DetectedItem then
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedTypeName ) local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
local DetectedItemsCount = DetectedSet:Count() local DetectedItemsCount = DetectedSet:Count()
local DetectedItemType = DetectedItem.TypeName local DetectedItemType = DetectedItem.TypeName
local DetectedItemCoordinate = self:GetDetectedItemCoordinate( DetectedTypeName ) local DetectedItemCoordinate = self:GetDetectedItemCoordinate( DetectedItem )
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings )
local Report = REPORT:New() local Report = REPORT:New()
@ -2294,9 +2236,9 @@ do -- DETECTION_TYPES
self:F() self:F()
local Report = REPORT:New() local Report = REPORT:New()
for DetectedItemTypeName, DetectedItem in pairs( self.DetectedItems ) do for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do
local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem
local ReportSummary = self:DetectedItemReportSummary( DetectedItemTypeName, AttackGroup ) local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup )
Report:SetTitle( "Detected types:" ) Report:SetTitle( "Detected types:" )
Report:Add( ReportSummary:Text() ) Report:Add( ReportSummary:Text() )
end end
@ -2375,57 +2317,26 @@ do -- DETECTION_AREAS
end end
--- Menu of a detected item using a given numeric index.
-- @param #DETECTION_AREAS self
-- @param Index
-- @return #string
function DETECTION_AREAS:DetectedItemMenu( Index, AttackGroup )
self:F( Index )
local DetectedItem = self:GetDetectedItem( Index )
local DetectedItemID = self:GetDetectedItemID( Index )
if DetectedItem then
local DetectedSet = self:GetDetectedSet( Index )
local ReportSummaryItem
local DetectedZone = self:GetDetectedItemZone( Index )
local DetectedItemCoordinate = DetectedZone:GetCoordinate()
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup )
local ReportSummary = string.format(
"%s - %s",
DetectedItemID,
DetectedItemCoordText
)
return ReportSummary
end
return nil
end
--- Report summary of a detected item using a given numeric index. --- Report summary of a detected item using a given numeric index.
-- @param #DETECTION_AREAS self -- @param #DETECTION_AREAS self
-- @param Index -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem.
-- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for. -- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for.
-- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use. -- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use.
-- @return Core.Report#REPORT The report of the detection items. -- @return Core.Report#REPORT The report of the detection items.
function DETECTION_AREAS:DetectedItemReportSummary( Index, AttackGroup, Settings ) function DETECTION_AREAS:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings )
self:F( Index ) self:F( { DetectedItem = DetectedItem } )
local DetectedItem = self:GetDetectedItem( Index ) local DetectedItemID = self:GetDetectedItemID( DetectedItem )
local DetectedItemID = self:GetDetectedItemID( Index )
if DetectedItem then if DetectedItem then
local DetectedSet = self:GetDetectedSet( Index ) local DetectedSet = self:GetDetectedSet( DetectedItem )
local ReportSummaryItem local ReportSummaryItem
local DetectedZone = self:GetDetectedItemZone( Index ) local DetectedZone = self:GetDetectedItemZone( DetectedItem )
local DetectedItemCoordinate = DetectedZone:GetCoordinate() local DetectedItemCoordinate = DetectedZone:GetCoordinate()
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings )
local ThreatLevelA2G = self:GetDetectedItemThreatLevel( Index ) local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem )
local DetectedItemsCount = DetectedSet:Count() local DetectedItemsCount = DetectedSet:Count()
local DetectedItemsTypes = DetectedSet:GetTypeNames() local DetectedItemsTypes = DetectedSet:GetTypeNames()
@ -2450,7 +2361,7 @@ do -- DETECTION_AREAS
local Report = REPORT:New() local Report = REPORT:New()
for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do
local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem
local ReportSummary = self:DetectedItemReportSummary( DetectedItemIndex, AttackGroup ) local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup )
Report:SetTitle( "Detected areas:" ) Report:SetTitle( "Detected areas:" )
Report:Add( ReportSummary:Text() ) Report:Add( ReportSummary:Text() )
end end

View File

@ -846,8 +846,8 @@ function _Resume( EscortGroup )
end end
--- @param #ESCORT self --- @param #ESCORT self
-- @param #number DetectedItemID -- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
function ESCORT:_AttackTarget( DetectedItemID ) function ESCORT:_AttackTarget( DetectedItem )
local EscortGroup = self.EscortGroup -- Wrapper.Group#GROUP local EscortGroup = self.EscortGroup -- Wrapper.Group#GROUP
self:E( EscortGroup ) self:E( EscortGroup )
@ -861,7 +861,7 @@ function ESCORT:_AttackTarget( DetectedItemID )
EscortGroup:OptionROTPassiveDefense() EscortGroup:OptionROTPassiveDefense()
EscortGroup:SetState( EscortGroup, "Escort", self ) EscortGroup:SetState( EscortGroup, "Escort", self )
local DetectedSet = self.Detection:GetDetectedSet( DetectedItemID ) local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
local Tasks = {} local Tasks = {}
@ -884,7 +884,7 @@ function ESCORT:_AttackTarget( DetectedItemID )
else else
local DetectedSet = self.Detection:GetDetectedSet( DetectedItemID ) local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
local Tasks = {} local Tasks = {}
@ -910,8 +910,9 @@ function ESCORT:_AttackTarget( DetectedItemID )
end end
--- ---
-- @param #number DetectedItemID --- @param #ESCORT self
function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItemID ) -- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItem )
local EscortGroup = self.EscortGroup local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient local EscortClient = self.EscortClient
@ -922,7 +923,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItemID )
EscortGroupAttack:OptionROEOpenFire() EscortGroupAttack:OptionROEOpenFire()
EscortGroupAttack:OptionROTVertical() EscortGroupAttack:OptionROTVertical()
local DetectedSet = self.Detection:GetDetectedSet( DetectedItemID ) local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
local Tasks = {} local Tasks = {}
@ -944,7 +945,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItemID )
) )
else else
local DetectedSet = self.Detection:GetDetectedSet( DetectedItemID ) local DetectedSet = self.Detection:GetDetectedSet( DetectedItem )
local Tasks = {} local Tasks = {}
@ -1162,11 +1163,11 @@ function ESCORT:_ReportTargetsScheduler()
local ClientEscortTargets = EscortGroupData.Detection local ClientEscortTargets = EscortGroupData.Detection
--local EscortUnit = EscortGroupData:GetUnit( 1 ) --local EscortUnit = EscortGroupData:GetUnit( 1 )
for DetectedItemID, DetectedItem in pairs( DetectedItems ) do for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do
self:E( { DetectedItemID, DetectedItem } ) self:E( { DetectedItemIndex, DetectedItem } )
-- Remove the sub menus of the Attack menu of the Escort for the EscortGroup. -- Remove the sub menus of the Attack menu of the Escort for the EscortGroup.
local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItemID, EscortGroupData.EscortGroup, _DATABASE:GetPlayerSettings( self.EscortClient:GetPlayerName() ) ) local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItem, EscortGroupData.EscortGroup, _DATABASE:GetPlayerSettings( self.EscortClient:GetPlayerName() ) )
if ClientEscortGroupName == EscortGroupName then if ClientEscortGroupName == EscortGroupName then
@ -1180,7 +1181,7 @@ function ESCORT:_ReportTargetsScheduler()
self.EscortMenuAttackNearbyTargets, self.EscortMenuAttackNearbyTargets,
ESCORT._AttackTarget, ESCORT._AttackTarget,
self, self,
DetectedItemID DetectedItem
) )
else else
if self.EscortMenuTargetAssistance then if self.EscortMenuTargetAssistance then
@ -1195,7 +1196,7 @@ function ESCORT:_ReportTargetsScheduler()
ESCORT._AssistTarget, ESCORT._AssistTarget,
self, self,
EscortGroupData.EscortGroup, EscortGroupData.EscortGroup,
DetectedItemID DetectedItem
) )
end end
end end

View File

@ -875,7 +875,7 @@ end
function TASK:MenuMarkToGroup( TaskGroup ) function TASK:MenuMarkToGroup( TaskGroup )
self:F() self:F()
self:UpdateTaskInfo() self:UpdateTaskInfo( self.DetectedItem )
local Report = REPORT:New():SetIndent( 0 ) local Report = REPORT:New():SetIndent( 0 )
@ -1380,14 +1380,14 @@ do -- Links
--- Set detection of a task --- Set detection of a task
-- @param #TASK self -- @param #TASK self
-- @param Function.Detection#DETECTION_BASE Detection -- @param Function.Detection#DETECTION_BASE Detection
-- @param #number DetectedItemIndex -- @param DetectedItem
-- @return #TASK -- @return #TASK
function TASK:SetDetection( Detection, DetectedItemIndex ) function TASK:SetDetection( Detection, DetectedItem )
self:E({DetectedItemIndex,Detection}) self:E( { DetectedItem, Detection } )
self.Detection = Detection self.Detection = Detection
self.DetectedItemIndex = DetectedItemIndex self.DetectedItem = DetectedItem
end end
end end
@ -1420,7 +1420,7 @@ end
-- @return #string -- @return #string
function TASK:ReportOverview( ReportGroup ) function TASK:ReportOverview( ReportGroup )
self:UpdateTaskInfo() self:UpdateTaskInfo( self.DetectedItem )
-- List the name of the Task. -- List the name of the Task.
local TaskName = self:GetName() local TaskName = self:GetName()
@ -1480,7 +1480,7 @@ end
-- @return #string -- @return #string
function TASK:ReportDetails( ReportGroup ) function TASK:ReportDetails( ReportGroup )
self:UpdateTaskInfo() self:UpdateTaskInfo( self.DetectedItem )
local Report = REPORT:New():SetIndent( 3 ) local Report = REPORT:New():SetIndent( 3 )

View File

@ -308,16 +308,16 @@ do -- TASK_A2A
--- @param #TASK_A2A self --- @param #TASK_A2A self
function TASK_A2A:UpdateTaskInfo() function TASK_A2A:UpdateTaskInfo( DetectedItem )
if self:IsStatePlanned() or self:IsStateAssigned() then if self:IsStatePlanned() or self:IsStateAssigned() then
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() local TargetCoordinate = DetectedItem and self.Detection:GetDetectedItemCoordinate( DetectedItem ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self.TaskInfo:AddTaskName( 0, "MSOD" ) self.TaskInfo:AddTaskName( 0, "MSOD" )
self.TaskInfo:AddCoordinate( TargetCoordinate, 1, "SOD" ) self.TaskInfo:AddCoordinate( TargetCoordinate, 1, "SOD" )
local ThreatLevel, ThreatText local ThreatLevel, ThreatText
if self.Detection then if DetectedItem then
ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( DetectedItem )
else else
ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G()
end end

View File

@ -307,16 +307,16 @@ do -- TASK_A2G
end end
--- @param #TASK_A2G self --- @param #TASK_A2G self
function TASK_A2G:UpdateTaskInfo() function TASK_A2G:UpdateTaskInfo( DetectedItem )
if self:IsStatePlanned() or self:IsStateAssigned() then if self:IsStatePlanned() or self:IsStateAssigned() then
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() local TargetCoordinate = DetectedItem and self.Detection:GetDetectedItemCoordinate( self.DetectedItem ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self.TaskInfo:AddTaskName( 0, "MSOD" ) self.TaskInfo:AddTaskName( 0, "MSOD" )
self.TaskInfo:AddCoordinate( TargetCoordinate, 1, "SOD" ) self.TaskInfo:AddCoordinate( TargetCoordinate, 1, "SOD" )
local ThreatLevel, ThreatText local ThreatLevel, ThreatText
if self.Detection then if DetectedItem then
ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) ThreatLevel, ThreatText = self.Detection:GetDetectedItemThreatLevel( self.DetectedItem )
else else
ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G()
end end

View File

@ -612,7 +612,7 @@ do -- TASK_A2G_DISPATCHER
if TargetSetUnit then if TargetSetUnit then
if Task:IsInstanceOf( TASK_A2G_SEAD ) then if Task:IsInstanceOf( TASK_A2G_SEAD ) then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
else else
Task:Cancel() Task:Cancel()
@ -623,7 +623,7 @@ do -- TASK_A2G_DISPATCHER
if Task:IsInstanceOf( TASK_A2G_CAS ) then if Task:IsInstanceOf( TASK_A2G_CAS ) then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:SetDetection( Detection, TaskIndex ) Task:SetDetection( Detection, TaskIndex )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
else else
Task:Cancel() Task:Cancel()
@ -635,7 +635,7 @@ do -- TASK_A2G_DISPATCHER
if Task:IsInstanceOf( TASK_A2G_BAI ) then if Task:IsInstanceOf( TASK_A2G_BAI ) then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:SetDetection( Detection, TaskIndex ) Task:SetDetection( Detection, TaskIndex )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) )
else else
Task:Cancel() Task:Cancel()
@ -663,7 +663,7 @@ do -- TASK_A2G_DISPATCHER
local TargetSetUnit = self:EvaluateSEAD( DetectedItem ) -- Returns a SetUnit if there are targets to be SEADed... local TargetSetUnit = self:EvaluateSEAD( DetectedItem ) -- Returns a SetUnit if there are targets to be SEADed...
if TargetSetUnit then if TargetSetUnit then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
else else
Task:Cancel() Task:Cancel()
Task = self:RemoveTask( TaskIndex ) Task = self:RemoveTask( TaskIndex )
@ -674,7 +674,7 @@ do -- TASK_A2G_DISPATCHER
if TargetSetUnit then if TargetSetUnit then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:SetDetection( Detection, TaskIndex ) Task:SetDetection( Detection, TaskIndex )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
else else
Task:Cancel() Task:Cancel()
Task = self:RemoveTask( TaskIndex ) Task = self:RemoveTask( TaskIndex )
@ -685,7 +685,7 @@ do -- TASK_A2G_DISPATCHER
if TargetSetUnit then if TargetSetUnit then
Task:SetTargetSetUnit( TargetSetUnit ) Task:SetTargetSetUnit( TargetSetUnit )
Task:SetDetection( Detection, TaskIndex ) Task:SetDetection( Detection, TaskIndex )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
else else
Task:Cancel() Task:Cancel()
Task = self:RemoveTask( TaskIndex ) Task = self:RemoveTask( TaskIndex )
@ -730,7 +730,7 @@ do -- TASK_A2G_DISPATCHER
self.Tasks[TaskIndex] = Task self.Tasks[TaskIndex] = Task
Task:SetTargetZone( DetectedZone ) Task:SetTargetZone( DetectedZone )
Task:SetDispatcher( self ) Task:SetDispatcher( self )
Task:UpdateTaskInfo() Task:UpdateTaskInfo( DetectedItem )
Mission:AddTask( Task ) Mission:AddTask( Task )
TaskReport:Add( Task:GetName() ) TaskReport:Add( Task:GetName() )

View File

@ -810,7 +810,7 @@ do -- TASK_CARGO
end end
--- @param #TASK_CARGO self --- @param #TASK_CARGO self
function TASK_CARGO:UpdateTaskInfo() function TASK_CARGO:UpdateTaskInfo( DetectedItem )
if self:IsStatePlanned() or self:IsStateAssigned() then if self:IsStatePlanned() or self:IsStateAssigned() then
self.TaskInfo:AddTaskName( 0, "MSOD" ) self.TaskInfo:AddTaskName( 0, "MSOD" )