From fb23ac1d55fc32f74b7768a187d6b2c498a53069 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 16 Mar 2019 09:51:09 +0100 Subject: [PATCH] Updates to make the tasking work correctly. --- Moose Development/Moose/AI/AI_A2G_Dispatcher.lua | 2 +- Moose Development/Moose/Core/Set.lua | 14 ++++++++++++++ Moose Development/Moose/Functional/Detection.lua | 16 ++++++---------- .../Moose/Functional/DetectionZones.lua | 11 +++++------ .../Moose/Tasking/Task_A2G_Dispatcher.lua | 7 ++++--- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua index d87424f98..fad800e7d 100644 --- a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua @@ -3985,7 +3985,7 @@ do -- AI_A2G_DISPATCHER else -- TODO: prio 1, what is this index stuff again, simplify it. if DefenderTask.Target then - self:F( { Target = DefenderTask.Target } ) + self:F( { TargetIndex = DefenderTask.Target.Index } ) local AttackerItem = Detection:GetDetectedItemByIndex( DefenderTask.Target.Index ) if not AttackerItem then self:F( { "Removing obsolete Target:", DefenderTask.Target.Index } ) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index eb210335a..4399c92f7 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -130,6 +130,20 @@ do -- SET_BASE return self end + + --- Clear the Objects in the Set. + -- @param #SET_BASE self + -- @return #SET_BASE self + function SET_BASE:Clear() + + for Name, Object in pairs( self.Set ) do + self:Remove( Name ) + end + + return self + end + + --- Finds an @{Core.Base#BASE} object based on the object Name. -- @param #SET_BASE self diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index e07c092be..6bebb8c5d 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1524,18 +1524,14 @@ do -- DETECTION_BASE local DetectedItem = {} self.DetectedItemCount = self.DetectedItemCount + 1 self.DetectedItemMax = self.DetectedItemMax + 1 - - if DetectedItemKey then - self.DetectedItems[DetectedItemKey] = DetectedItem - else - self.DetectedItems[self.DetectedItemMax] = DetectedItem - end - - self.DetectedItemsByIndex[self.DetectedItemMax] = DetectedItem - + + self.DetectedItems[DetectedItemKey] = DetectedItem + + local DetectedItemIndex = DetectedItemKey or self.DetectedItemMax + self.DetectedItemsByIndex[DetectedItemIndex] = DetectedItem + DetectedItem.Index = DetectedItemIndex DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes() - DetectedItem.Index = DetectedItemKey or self.DetectedItemMax DetectedItem.ItemID = ItemPrefix .. "." .. self.DetectedItemMax DetectedItem.ID = self.DetectedItemMax DetectedItem.Removed = false diff --git a/Moose Development/Moose/Functional/DetectionZones.lua b/Moose Development/Moose/Functional/DetectionZones.lua index 0b10e2b44..c44ef9efe 100644 --- a/Moose Development/Moose/Functional/DetectionZones.lua +++ b/Moose Development/Moose/Functional/DetectionZones.lua @@ -261,8 +261,8 @@ do -- DETECTION_ZONES local DetectedUnits = SET_UNIT:New() - -- First go through all detected sets, and check if there are new detected units, match all existing detected units and identify undetected units. - -- Regroup when needed, split groups when needed. + -- First go through all zones, and check if there are new Zones. + -- New Zones become a new DetectedItem. for ZoneName, DetectionZone in pairs( self.DetectionSetZone:GetSet() ) do local DetectedItem = self:GetDetectedItemByKey( ZoneName ) @@ -276,6 +276,8 @@ do -- DETECTION_ZONES -- Scan the zone DetectionZone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) + -- For all the units in the zone, + -- check if they are of the same coalition to be included. local ZoneUnits = DetectionZone:GetScannedUnits() for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do local UnitName = DCSUnit:getName() @@ -289,11 +291,8 @@ do -- DETECTION_ZONES end end end - end - - - + -- Now all the tests should have been build, now make some smoke and flares... -- We also report here the friendlies within the detected areas. diff --git a/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua index 499efcf89..b7ae6ba17 100644 --- a/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua @@ -633,7 +633,7 @@ do -- TASK_A2G_DISPATCHER --DetectedSet:Flush( self ) local DetectedItemID = DetectedItem.ID - local TaskIndex = DetectedItem.ID + local TaskIndex = DetectedItem.Index local DetectedItemChanged = DetectedItem.Changed self:F( { DetectedItemChanged = DetectedItemChanged, DetectedItemID = DetectedItemID, TaskIndex = TaskIndex } ) @@ -649,6 +649,7 @@ do -- TASK_A2G_DISPATCHER if TargetSetUnit then if Task:IsInstanceOf( TASK_A2G_SEAD ) then Task:SetTargetSetUnit( TargetSetUnit ) + Task:SetDetection( Detection, DetectedItem ) Task:UpdateTaskInfo( DetectedItem ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) else @@ -659,7 +660,7 @@ do -- TASK_A2G_DISPATCHER if TargetSetUnit then if Task:IsInstanceOf( TASK_A2G_CAS ) then Task:SetTargetSetUnit( TargetSetUnit ) - Task:SetDetection( Detection, TaskIndex ) + Task:SetDetection( Detection, DetectedItem ) Task:UpdateTaskInfo( DetectedItem ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) else @@ -671,7 +672,7 @@ do -- TASK_A2G_DISPATCHER if TargetSetUnit then if Task:IsInstanceOf( TASK_A2G_BAI ) then Task:SetTargetSetUnit( TargetSetUnit ) - Task:SetDetection( Detection, TaskIndex ) + Task:SetDetection( Detection, DetectedItem ) Task:UpdateTaskInfo( DetectedItem ) TargetsReport:Add( Detection:GetChangeText( DetectedItem ) ) else