Fixed non removal of Planned Tasks

This commit is contained in:
FlightControl
2017-05-24 11:49:03 +02:00
parent f3b49ecc0a
commit 89371378b7
2 changed files with 43 additions and 22 deletions

View File

@@ -512,7 +512,7 @@ do -- DETECTION_BASE
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
function DETECTION_BASE:onafterDetect(From,Event,To) function DETECTION_BASE:onafterDetect(From,Event,To)
self:E( {From,Event,To}) self:E( { From, Event, To } )
local DetectDelay = 0.1 local DetectDelay = 0.1
self.DetectionCount = 0 self.DetectionCount = 0
@@ -520,7 +520,7 @@ do -- DETECTION_BASE
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do
self:E( {DetectionGroupData}) --self:E( { DetectionGroupData } )
self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously. self:__DetectionGroup( DetectDelay, DetectionGroupData ) -- Process each detection asynchronously.
self.DetectionCount = self.DetectionCount + 1 self.DetectionCount = self.DetectionCount + 1
DetectDelay = DetectDelay + 0.1 DetectDelay = DetectDelay + 0.1
@@ -533,7 +533,7 @@ do -- DETECTION_BASE
-- @param #string To The To State string. -- @param #string To The To State string.
-- @param Wrapper.Group#GROUP DetectionGroup The Group detecting. -- @param Wrapper.Group#GROUP DetectionGroup The Group detecting.
function DETECTION_BASE:onafterDetectionGroup( From, Event, To, DetectionGroup ) function DETECTION_BASE:onafterDetectionGroup( From, Event, To, DetectionGroup )
self:E( {From,Event,To}) self:E( { From, Event, To } )
self.DetectionRun = self.DetectionRun + 1 self.DetectionRun = self.DetectionRun + 1
@@ -1563,7 +1563,7 @@ do -- DETECTION_UNITS
local DetectedUnit = DetectedUnitData -- Wrapper.Unit#UNIT local DetectedUnit = DetectedUnitData -- Wrapper.Unit#UNIT
local DetectedObject = nil local DetectedObject = nil
self:E( DetectedUnit ) --self:E( DetectedUnit )
if DetectedUnit:IsAlive() then if DetectedUnit:IsAlive() then
--self:E(DetectedUnit:GetName()) --self:E(DetectedUnit:GetName())
DetectedObject = self:GetDetectedObject( DetectedUnit:GetName() ) DetectedObject = self:GetDetectedObject( DetectedUnit:GetName() )
@@ -1924,8 +1924,8 @@ do -- DETECTION_TYPES
local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate() local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate()
local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup )
self:E( { DetectedItemID, --self:E( { DetectedItemID,
DetectedItemCoordText } ) -- DetectedItemCoordText } )
local ReportSummary = string.format( local ReportSummary = string.format(
"%s - %s", "%s - %s",
@@ -2374,6 +2374,9 @@ do -- DETECTION_AREAS
-- We don't need to add the DetectedObject to the area set, because it is already there ... -- We don't need to add the DetectedObject to the area set, because it is already there ...
break break
else
DetectedSet:Remove( DetectedUnitName )
self:AddChangeUnit( DetectedItem, "RU", DetectedUnit:GetTypeName() )
end end
end end
end end
@@ -2425,6 +2428,8 @@ do -- DETECTION_AREAS
end end
end end
-- We iterated through the existing detection areas and: -- We iterated through the existing detection areas and:
-- - We checked which units are still detected in each detection area. Those units were flagged as Identified. -- - We checked which units are still detected in each detection area. Those units were flagged as Identified.
-- - We recentered the detection area to new center units where it was needed. -- - We recentered the detection area to new center units where it was needed.
@@ -2488,11 +2493,14 @@ do -- DETECTION_AREAS
if DETECTION_AREAS._SmokeDetectedUnits or self._SmokeDetectedUnits then if DETECTION_AREAS._SmokeDetectedUnits or self._SmokeDetectedUnits then
DetectedZone.ZoneUNIT:SmokeRed() DetectedZone.ZoneUNIT:SmokeRed()
end end
--DetectedSet:Flush()
DetectedSet:ForEachUnit( DetectedSet:ForEachUnit(
--- @param Wrapper.Unit#UNIT DetectedUnit --- @param Wrapper.Unit#UNIT DetectedUnit
function( DetectedUnit ) function( DetectedUnit )
if DetectedUnit:IsAlive() then if DetectedUnit:IsAlive() then
self:T( "Detected Set #" .. DetectedItem.ItemID .. ":" .. DetectedUnit:GetName() ) --self:T( "Detected Set #" .. DetectedItem.ItemID .. ":" .. DetectedUnit:GetName() )
if DETECTION_AREAS._FlareDetectedUnits or self._FlareDetectedUnits then if DETECTION_AREAS._FlareDetectedUnits or self._FlareDetectedUnits then
DetectedUnit:FlareGreen() DetectedUnit:FlareGreen()
end end

View File

@@ -157,7 +157,7 @@ do -- TASK_A2A_DISPATCHER
-- @param #boolean DetectedItemID -- @param #boolean DetectedItemID
-- @param #boolean DetectedItemChange -- @param #boolean DetectedItemChange
-- @return Tasking.Task#TASK -- @return Tasking.Task#TASK
function TASK_A2A_DISPATCHER:EvaluateRemoveTask( Mission, Task, Detection, DetectedItem, DetectedItemID, DetectedItemChanged ) function TASK_A2A_DISPATCHER:EvaluateRemoveTask( Mission, Task, Detection, DetectedItem, DetectedItemIndex, DetectedItemChanged )
if Task then if Task then
@@ -183,16 +183,16 @@ do -- TASK_A2A_DISPATCHER
end end
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
DetectedSet:Flush() --DetectedSet:Flush()
self:E( { DetectedSetCount = DetectedSet:Count() } ) --self:E( { DetectedSetCount = DetectedSet:Count() } )
if DetectedSet:Count() == 0 then if DetectedSet:Count() == 0 then
Remove = true Remove = true
end end
if DetectedItemChanged == true or Remove then if DetectedItemChanged == true or Remove then
self:E( "Removing Tasking: " .. Task:GetTaskName() ) --self:E( "Removing Tasking: " .. Task:GetTaskName() )
Mission:RemoveTask( Task ) Mission:RemoveTask( Task )
self.Tasks[DetectedItemID] = nil self.Tasks[DetectedItemIndex] = nil
end end
end end
end end
@@ -228,7 +228,7 @@ do -- TASK_A2A_DISPATCHER
end end
self:E( { FriendliesCount = FriendliesCount } ) --self:E( { FriendliesCount = FriendliesCount } )
local FriendlyTypesReport = REPORT:New() local FriendlyTypesReport = REPORT:New()
@@ -261,7 +261,7 @@ do -- TASK_A2A_DISPATCHER
for PlayerUnitName, PlayerUnitData in pairs( PlayersNearBy ) do for PlayerUnitName, PlayerUnitData in pairs( PlayersNearBy ) do
local PlayerUnit = PlayerUnitData -- Wrapper.Unit#UNIT local PlayerUnit = PlayerUnitData -- Wrapper.Unit#UNIT
local PlayerName = PlayerUnit:GetPlayerName() local PlayerName = PlayerUnit:GetPlayerName()
self:E( { PlayerName = PlayerName, PlayerUnit = PlayerUnit } ) --self:E( { PlayerName = PlayerName, PlayerUnit = PlayerUnit } )
if PlayerUnit:IsAirPlane() and PlayerName ~= nil then if PlayerUnit:IsAirPlane() and PlayerName ~= nil then
local FriendlyUnitThreatLevel = PlayerUnit:GetThreatLevel() local FriendlyUnitThreatLevel = PlayerUnit:GetThreatLevel()
PlayersCount = PlayersCount + 1 PlayersCount = PlayersCount + 1
@@ -274,7 +274,7 @@ do -- TASK_A2A_DISPATCHER
end end
self:E( { PlayersCount = PlayersCount } ) --self:E( { PlayersCount = PlayersCount } )
local PlayerTypesReport = REPORT:New() local PlayerTypesReport = REPORT:New()
@@ -307,23 +307,36 @@ do -- TASK_A2A_DISPATCHER
if Mission:IsIDLE() or Mission:IsENGAGED() then if Mission:IsIDLE() or Mission:IsENGAGED() then
local TaskReport = REPORT:New() local TaskReport = REPORT:New()
-- Checking the task queue for the dispatcher, and removing any obsolete task!
for TaskIndex, Task in pairs( self.Tasks ) do
local DetectedItem = Detection:GetDetectedItem( TaskIndex )
if not DetectedItem then
local TaskText = Task:GetName()
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
Mission:GetCommandCenter():MessageToGroup( string.format( "Obsolete A2A task %s for %s removed.", TaskText, Mission:GetName() ), TaskGroup )
end
Mission:RemoveTask( Task )
self.Tasks[TaskIndex] = nil
end
end
--- First we need to the detected targets. -- Now that all obsolete tasks are removed, loop through the detected targets.
for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do
local DetectedItem = DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem local DetectedItem = DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
local DetectedCount = DetectedSet:Count() local DetectedCount = DetectedSet:Count()
local DetectedZone = DetectedItem.Zone local DetectedZone = DetectedItem.Zone
self:E( { "Targets in DetectedItem", DetectedItem.ItemID, DetectedSet:Count(), tostring( DetectedItem ) } ) --self:E( { "Targets in DetectedItem", DetectedItem.ItemID, DetectedSet:Count(), tostring( DetectedItem ) } )
DetectedSet:Flush() --DetectedSet:Flush()
local DetectedID = DetectedItem.ID local DetectedID = DetectedItem.ID
local DetectedIndex = DetectedItem.Index local TaskIndex = DetectedItem.Index
local DetectedItemChanged = DetectedItem.Changed local DetectedItemChanged = DetectedItem.Changed
local Task = self.Tasks[DetectedID] local Task = self.Tasks[TaskIndex]
Task = self:EvaluateRemoveTask( Mission, Task, Detection, DetectedItem, DetectedID, DetectedItemChanged ) -- Task will be removed if it is planned and changed. Task = self:EvaluateRemoveTask( Mission, Task, Detection, DetectedItem, TaskIndex, DetectedItemChanged ) -- Task will be removed if it is planned and changed.
-- Evaluate INTERCEPT -- Evaluate INTERCEPT
if not Task and DetectedCount > 0 then if not Task and DetectedCount > 0 then
@@ -338,7 +351,7 @@ do -- TASK_A2A_DISPATCHER
end end
if Task then if Task then
self.Tasks[DetectedID] = Task self.Tasks[TaskIndex] = Task
Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() ) Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() )
Task:SetDispatcher( self ) Task:SetDispatcher( self )
Mission:AddTask( Task ) Mission:AddTask( Task )