Ensuring that only alive groups are handled, trying to solve the menu issues.

Optimizing the threatlevel boxes.
This commit is contained in:
FlightControl_Master 2017-12-11 11:08:15 +01:00
parent 18a15332fe
commit 02c671bd63
6 changed files with 53 additions and 36 deletions

View File

@ -719,20 +719,22 @@ end
--- Gets the Set. --- Gets the Set.
-- @param #SET_GROUP self -- @param #SET_GROUP self
-- @return #SET_GROUP self -- @return #SET_GROUP self
--function SET_BASE:GetSet() function SET_GROUP:GetAliveSet()
-- self:F2() self:F2()
--
-- -- Clean the Set before returning with only the alive Groups. local AliveSet = SET_GROUP:New()
-- for GroupName, GroupObject in pairs( self.Set ) do
-- if GroupObject then -- Clean the Set before returning with only the alive Groups.
-- if not GroupObject:IsAlive() then for GroupName, GroupObject in pairs( self.Set ) do
-- self:Remove( GroupName ) if GroupObject then
-- end if GroupObject:IsAlive() then
-- end AliveSet:Add( GroupName, GroupObject )
-- end end
-- end
-- return self.Set end
--end
return AliveSet
end
--- Add GROUP(s) to SET_GROUP. --- Add GROUP(s) to SET_GROUP.
@ -984,7 +986,7 @@ function SET_GROUP:FindInDatabase( Event )
return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName] return Event.IniDCSGroupName, self.Database[Event.IniDCSGroupName]
end end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP, providing the GROUP and optional parameters. --- Iterate the SET_GROUP and call an iterator function for each GROUP object, providing the GROUP and optional parameters.
-- @param #SET_GROUP self -- @param #SET_GROUP self
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter. -- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
-- @return #SET_GROUP self -- @return #SET_GROUP self
@ -996,6 +998,18 @@ function SET_GROUP:ForEachGroup( IteratorFunction, ... )
return self return self
end end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP object, providing the GROUP and optional parameters.
-- @param #SET_GROUP self
-- @param #function IteratorFunction The function that will be called when there is an alive GROUP in the SET_GROUP. The function needs to accept a GROUP parameter.
-- @return #SET_GROUP self
function SET_GROUP:ForEachGroupAlive( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self:GetAliveSet() )
return self
end
--- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence completely in a @{Zone}, providing the GROUP and optional parameters to the called function. --- Iterate the SET_GROUP and call an iterator function for each **alive** GROUP presence completely in a @{Zone}, providing the GROUP and optional parameters to the called function.
-- @param #SET_GROUP self -- @param #SET_GROUP self
-- @param Core.Zone#ZONE ZoneObject The Zone to be tested for. -- @param Core.Zone#ZONE ZoneObject The Zone to be tested for.

View File

@ -424,7 +424,7 @@ do -- DESIGNATE
self.FlashStatusMenu = {} self.FlashStatusMenu = {}
self.AttackSet:ForEachGroup( self.AttackSet:ForEachGroupAlive(
--- @param Wrapper.Group#GROUP GroupReport --- @param Wrapper.Group#GROUP GroupReport
function( AttackGroup ) function( AttackGroup )
@ -688,7 +688,7 @@ do -- DESIGNATE
self:F("Removing") self:F("Removing")
-- This Detection is obsolete, remove from the designate scope -- This Detection is obsolete, remove from the designate scope
self.Designating[DesignateIndex] = nil self.Designating[DesignateIndex] = nil
self.AttackSet:ForEachGroup( self.AttackSet:ForEachGroupAlive(
--- @param Wrapper.Group#GROUP AttackGroup --- @param Wrapper.Group#GROUP AttackGroup
function( AttackGroup ) function( AttackGroup )
if AttackGroup:IsAlive() == true then if AttackGroup:IsAlive() == true then
@ -714,7 +714,7 @@ do -- DESIGNATE
if DetectedItem.DistanceRecce <= self.MaximumDistanceDesignations then if DetectedItem.DistanceRecce <= self.MaximumDistanceDesignations then
if self.Designating[DesignateIndex] == nil then if self.Designating[DesignateIndex] == nil then
-- ok, we added one item to the designate scope. -- ok, we added one item to the designate scope.
self.AttackSet:ForEachGroup( self.AttackSet:ForEachGroupAlive(
function( AttackGroup ) function( AttackGroup )
local DetectionText = self.Detection:DetectedItemReportSummary( DesignateIndex, AttackGroup ):Text( ", " ) local DetectionText = self.Detection:DetectedItemReportSummary( DesignateIndex, AttackGroup ):Text( ", " )
self.CC:GetPositionable():MessageToGroup( "Targets detected at \n" .. DetectionText, 10, AttackGroup, self.DesignateName ) self.CC:GetPositionable():MessageToGroup( "Targets detected at \n" .. DetectionText, 10, AttackGroup, self.DesignateName )
@ -760,7 +760,7 @@ do -- DESIGNATE
Duration = Duration or 10 Duration = Duration or 10
self.AttackSet:ForEachGroup( self.AttackSet:ForEachGroupAlive(
--- @param Wrapper.Group#GROUP GroupReport --- @param Wrapper.Group#GROUP GroupReport
function( AttackGroup ) function( AttackGroup )
@ -785,7 +785,7 @@ do -- DESIGNATE
local DesignationReport = REPORT:New( "Marking Targets:\n" ) local DesignationReport = REPORT:New( "Marking Targets:\n" )
self.RecceSet:ForEachGroup( self.RecceSet:ForEachGroupAlive(
function( RecceGroup ) function( RecceGroup )
local RecceUnits = RecceGroup:GetUnits() local RecceUnits = RecceGroup:GetUnits()
for UnitID, RecceData in pairs( RecceUnits ) do for UnitID, RecceData in pairs( RecceUnits ) do
@ -812,7 +812,7 @@ do -- DESIGNATE
self.AttackSet:Flush() self.AttackSet:Flush()
self.AttackSet:ForEachGroup( self.AttackSet:ForEachGroupAlive(
--- @param Wrapper.Group#GROUP GroupReport --- @param Wrapper.Group#GROUP GroupReport
function( AttackGroup ) function( AttackGroup )

View File

@ -2004,7 +2004,7 @@ do -- DETECTION_UNITS
local Report = REPORT:New() local Report = REPORT:New()
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
Report:Add( string.format( "Threat: [%s]", string.rep( "", ThreatLevelA2G ) ) ) Report:Add( string.format( "Threat: [%s]", string.rep( "", ThreatLevelA2G ), string.rep( "", 10-ThreatLevelA2G ) ) )
Report:Add( string.format("Type: %s%s", UnitCategoryText, UnitDistanceText ) ) Report:Add( string.format("Type: %s%s", UnitCategoryText, UnitDistanceText ) )
return Report return Report
end end
@ -2236,7 +2236,7 @@ do -- DETECTION_TYPES
local Report = REPORT:New() local Report = REPORT:New()
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
Report:Add( string.format( "Threat: [%s]", string.rep( "", ThreatLevelA2G ) ) ) Report:Add( string.format( "Threat: [%s%s]", string.rep( "", ThreatLevelA2G ), string.rep( "", 10-ThreatLevelA2G ) ) )
Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemType ) ) Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemType ) )
return Report return Report
end end
@ -2387,7 +2387,7 @@ do -- DETECTION_AREAS
local Report = REPORT:New() local Report = REPORT:New()
Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText)
Report:Add( string.format( "Threat: [%s]", string.rep( "", ThreatLevelA2G ) ) ) Report:Add( string.format( "Threat: [%s]", string.rep( "", ThreatLevelA2G ), string.rep( "", 10-ThreatLevelA2G ) ) )
Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemsTypes ) ) Report:Add( string.format("Type: %2d of %s", DetectedItemsCount, DetectedItemsTypes ) )
return Report return Report

View File

@ -619,7 +619,7 @@ function TASK:MessageToGroups( Message )
local Mission = self:GetMission() local Mission = self:GetMission()
local CC = Mission:GetCommandCenter() local CC = Mission:GetCommandCenter()
for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetAliveSet() ) do
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
CC:MessageToGroup( Message, TaskGroup, TaskGroup:GetName() ) CC:MessageToGroup( Message, TaskGroup, TaskGroup:GetName() )
end end
@ -631,7 +631,7 @@ end
function TASK:SendBriefingToAssignedGroups() function TASK:SendBriefingToAssignedGroups()
self:F2() self:F2()
for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetAliveSet() ) do
if self:IsGroupAssigned( TaskGroup ) then if self:IsGroupAssigned( TaskGroup ) then
TaskGroup:Message( self.TaskBriefing, 60 ) TaskGroup:Message( self.TaskBriefing, 60 )
@ -645,7 +645,7 @@ end
function TASK:UnAssignFromGroups() function TASK:UnAssignFromGroups()
self:F2() self:F2()
for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupName, TaskGroup in pairs( self.SetGroup:GetAliveSet() ) do
if self:IsGroupAssigned(TaskGroup) then if self:IsGroupAssigned(TaskGroup) then
self:UnAssignFromGroup( TaskGroup ) self:UnAssignFromGroup( TaskGroup )
end end
@ -660,7 +660,7 @@ end
function TASK:HasAliveUnits() function TASK:HasAliveUnits()
self:F() self:F()
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetAliveSet() ) do
if self:IsStateAssigned() then if self:IsStateAssigned() then
if self:IsGroupAssigned( TaskGroup ) then if self:IsGroupAssigned( TaskGroup ) then
for TaskUnitID, TaskUnit in pairs( TaskGroup:GetUnits() ) do for TaskUnitID, TaskUnit in pairs( TaskGroup:GetUnits() ) do
@ -685,7 +685,7 @@ function TASK:SetMenu( MenuTime ) --R2.1 Mission Reports and Task Reports added.
self:F( { self:GetName(), MenuTime } ) self:F( { self:GetName(), MenuTime } )
--self.SetGroup:Flush() --self.SetGroup:Flush()
for TaskGroupID, TaskGroupData in pairs( self.SetGroup:GetSet() ) do for TaskGroupID, TaskGroupData in pairs( self.SetGroup:GetAliveSet() ) do
local TaskGroup = TaskGroupData -- Wrapper.Group#GROUP local TaskGroup = TaskGroupData -- Wrapper.Group#GROUP
if TaskGroup:IsAlive() == true and TaskGroup:GetPlayerNames() then if TaskGroup:IsAlive() == true and TaskGroup:GetPlayerNames() then
@ -799,7 +799,7 @@ end
function TASK:RemoveMenu( MenuTime ) function TASK:RemoveMenu( MenuTime )
self:F( { self:GetName(), MenuTime } ) self:F( { self:GetName(), MenuTime } )
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetAliveSet() ) do
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
if TaskGroup:IsAlive() == true and TaskGroup:GetPlayerNames() then if TaskGroup:IsAlive() == true and TaskGroup:GetPlayerNames() then
self:RefreshMenus( TaskGroup, MenuTime ) self:RefreshMenus( TaskGroup, MenuTime )
@ -1508,7 +1508,7 @@ function TASK:GetPlayerCount() --R2.1 Get a count of the players.
local PlayerCount = 0 local PlayerCount = 0
-- Loop each Unit active in the Task, and find Player Names. -- Loop each Unit active in the Task, and find Player Names.
for TaskGroupID, PlayerGroup in pairs( self:GetGroups():GetSet() ) do for TaskGroupID, PlayerGroup in pairs( self:GetGroups():GetAliveSet() ) do
local PlayerGroup = PlayerGroup -- Wrapper.Group#GROUP local PlayerGroup = PlayerGroup -- Wrapper.Group#GROUP
if self:IsGroupAssigned( PlayerGroup ) then if self:IsGroupAssigned( PlayerGroup ) then
local PlayerNames = PlayerGroup:GetPlayerNames() local PlayerNames = PlayerGroup:GetPlayerNames()
@ -1528,7 +1528,7 @@ function TASK:GetPlayerNames() --R2.1 Get a map of the players.
local PlayerNameMap = {} local PlayerNameMap = {}
-- Loop each Unit active in the Task, and find Player Names. -- Loop each Unit active in the Task, and find Player Names.
for TaskGroupID, PlayerGroup in pairs( self:GetGroups():GetSet() ) do for TaskGroupID, PlayerGroup in pairs( self:GetGroups():GetAliveSet() ) do
local PlayerGroup = PlayerGroup -- Wrapper.Group#GROUP local PlayerGroup = PlayerGroup -- Wrapper.Group#GROUP
if self:IsGroupAssigned( PlayerGroup ) then if self:IsGroupAssigned( PlayerGroup ) then
local PlayerNames = PlayerGroup:GetPlayerNames() local PlayerNames = PlayerGroup:GetPlayerNames()

View File

@ -367,7 +367,8 @@ do -- TASK_A2A_INTERCEPT
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self:SetInfo( "Coordinate", TargetCoordinate, 0 ) self:SetInfo( "Coordinate", TargetCoordinate, 0 )
self:SetInfo( "Threat", "[" .. string.rep( "", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 ) local ThreatLevel = self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G()
self:SetInfo( "Threat", "[" .. string.rep( "", ThreatLevel ) .. string.rep( "", 10 - ThreatLevel ) .. "]", 11 )
if self.Detection then if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:Count() local DetectedItemsCount = self.TargetSetUnit:Count()
@ -523,7 +524,8 @@ do -- TASK_A2A_SWEEP
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self:SetInfo( "Coordinate", TargetCoordinate, 0 ) self:SetInfo( "Coordinate", TargetCoordinate, 0 )
self:SetInfo( "Assumed Threat", "[" .. string.rep( "", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 ) local ThreatLevel = self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G()
self:SetInfo( "Assumed Threat", "[" .. string.rep( "", ThreatLevel ) .. string.rep( "", 10 - ThreatLevel ) .. "]", 11 )
if self.Detection then if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:Count() local DetectedItemsCount = self.TargetSetUnit:Count()
@ -672,7 +674,8 @@ do -- TASK_A2A_ENGAGE
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate() local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self:SetInfo( "Coordinate", TargetCoordinate, 0 ) self:SetInfo( "Coordinate", TargetCoordinate, 0 )
self:SetInfo( "Threat", "[" .. string.rep( "", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 ) local ThreatLevel = self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G()
self:SetInfo( "Threat", "[" .. string.rep( "", ThreatLevel ) .. string.rep( "", 10 - ThreatLevel ) .. "]", 11 )
if self.Detection then if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:Count() local DetectedItemsCount = self.TargetSetUnit:Count()

View File

@ -353,7 +353,7 @@ do -- TASK_A2G
else else
ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G()
end end
self:SetInfo( "Threat", ThreatText .. " [" .. string.rep( "", ThreatLevel ) .. "]", 11 ) self:SetInfo( "Threat", ThreatText .. " [" .. string.rep( "", ThreatLevel ) .. string.rep( "", 10 - ThreatLevel ) .. "]", 11 )
if self.Detection then if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:Count() local DetectedItemsCount = self.TargetSetUnit:Count()