mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge pull request #560 from FlightControl-Master/419-A2A-Tasking
A2A SWEEP Tasking
This commit is contained in:
commit
c6631356ea
@ -519,9 +519,11 @@ do -- DETECTION_BASE
|
|||||||
self.DetectionRun = 0
|
self.DetectionRun = 0
|
||||||
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
|
self:UnIdentifyAllDetectedObjects() -- Resets the DetectedObjectsIdentified table
|
||||||
|
|
||||||
|
local DetectionTimeStamp = timer.getTime()
|
||||||
|
|
||||||
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, DetectionTimeStamp ) -- Process each detection asynchronously.
|
||||||
self.DetectionCount = self.DetectionCount + 1
|
self.DetectionCount = self.DetectionCount + 1
|
||||||
DetectDelay = DetectDelay + 0.1
|
DetectDelay = DetectDelay + 0.1
|
||||||
end
|
end
|
||||||
@ -532,7 +534,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.
|
||||||
-- @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, DetectionTimeStamp )
|
||||||
self:E( { From, Event, To } )
|
self:E( { From, Event, To } )
|
||||||
|
|
||||||
self.DetectionRun = self.DetectionRun + 1
|
self.DetectionRun = self.DetectionRun + 1
|
||||||
@ -557,7 +559,7 @@ do -- DETECTION_BASE
|
|||||||
self.DetectDLINK
|
self.DetectDLINK
|
||||||
)
|
)
|
||||||
|
|
||||||
self:T( DetectedTargets )
|
self:F( DetectedTargets )
|
||||||
|
|
||||||
for DetectionObjectID, Detection in pairs( DetectedTargets ) do
|
for DetectionObjectID, Detection in pairs( DetectedTargets ) do
|
||||||
local DetectedObject = Detection.object -- Dcs.DCSWrapper.Object#Object
|
local DetectedObject = Detection.object -- Dcs.DCSWrapper.Object#Object
|
||||||
@ -592,7 +594,7 @@ do -- DETECTION_BASE
|
|||||||
|
|
||||||
local DetectedUnitCategory = DetectedObject:getDesc().category
|
local DetectedUnitCategory = DetectedObject:getDesc().category
|
||||||
|
|
||||||
self:T2( { "Detected Target:", DetectionGroupName, DetectedObjectName, Distance, DetectedUnitCategory } )
|
self:F( { "Detected Target:", DetectionGroupName, DetectedObjectName, Distance, DetectedUnitCategory } )
|
||||||
|
|
||||||
-- Calculate Acceptance
|
-- Calculate Acceptance
|
||||||
|
|
||||||
@ -676,6 +678,7 @@ do -- DETECTION_BASE
|
|||||||
|
|
||||||
self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {}
|
self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {}
|
||||||
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
|
self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName
|
||||||
|
self.DetectedObjects[DetectedObjectName].IsDetected = TargetIsDetected
|
||||||
self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsVisible
|
self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsVisible
|
||||||
self.DetectedObjects[DetectedObjectName].LastTime = TargetLastTime
|
self.DetectedObjects[DetectedObjectName].LastTime = TargetLastTime
|
||||||
self.DetectedObjects[DetectedObjectName].LastPos = TargetLastPos
|
self.DetectedObjects[DetectedObjectName].LastPos = TargetLastPos
|
||||||
@ -683,6 +686,7 @@ do -- DETECTION_BASE
|
|||||||
self.DetectedObjects[DetectedObjectName].KnowType = TargetKnowType
|
self.DetectedObjects[DetectedObjectName].KnowType = TargetKnowType
|
||||||
self.DetectedObjects[DetectedObjectName].KnowDistance = Detection.distance -- TargetKnowDistance
|
self.DetectedObjects[DetectedObjectName].KnowDistance = Detection.distance -- TargetKnowDistance
|
||||||
self.DetectedObjects[DetectedObjectName].Distance = Distance
|
self.DetectedObjects[DetectedObjectName].Distance = Distance
|
||||||
|
self.DetectedObjects[DetectedObjectName].DetectionTimeStamp = DetectionTimeStamp
|
||||||
|
|
||||||
local DetectedUnit = UNIT:FindByName( DetectedObjectName )
|
local DetectedUnit = UNIT:FindByName( DetectedObjectName )
|
||||||
|
|
||||||
@ -707,8 +711,22 @@ do -- DETECTION_BASE
|
|||||||
if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then
|
if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then
|
||||||
self:T( "--> Create Detection Sets" )
|
self:T( "--> Create Detection Sets" )
|
||||||
|
|
||||||
|
-- First check if all DetectedObjects were detected.
|
||||||
|
-- This is important. When there are DetectedObjects in the list, but were not detected,
|
||||||
|
-- And these remain undetected for more than 60 seconds, then these DetectedObjects will be flagged as not Detected.
|
||||||
|
-- IsDetected = false!
|
||||||
|
-- This is used in A2A_TASK_DISPATCHER to initiate fighter sweeping! The TASK_A2A_INTERCEPT tasks will be replaced with TASK_A2A_SWEEP tasks.
|
||||||
|
for DetectedObjectName, DetectedObject in pairs( self.DetectedObjects ) do
|
||||||
|
if self.DetectedObjects[DetectedObjectName].IsDetected == true and self.DetectedObjects[DetectedObjectName].DetectionTimeStamp + 60 <= DetectionTimeStamp then
|
||||||
|
self.DetectedObjects[DetectedObjectName].IsDetected = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method.
|
self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method.
|
||||||
self:CleanDetectionItems() -- Any DetectionItem that has a Set with zero elements in it, must be removed from the DetectionItems list.
|
for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do
|
||||||
|
self:UpdateDetectedItemDetection( DetectedItem )
|
||||||
|
self:CleanDetectionItem( DetectedItem, DetectedItemID ) -- Any DetectionItem that has a Set with zero elements in it, must be removed from the DetectionItems list.
|
||||||
|
end
|
||||||
|
|
||||||
self:__Detect( self.DetectionInterval )
|
self:__Detect( self.DetectionInterval )
|
||||||
end
|
end
|
||||||
@ -720,23 +738,19 @@ do -- DETECTION_BASE
|
|||||||
|
|
||||||
do -- DetectionItems Creation
|
do -- DetectionItems Creation
|
||||||
|
|
||||||
--- Make a DetectionSet table. This function will be overridden in the derived clsses.
|
-- Clean the DetectedItem table.
|
||||||
-- @param #DETECTION_BASE self
|
-- @param #DETECTION_BASE self
|
||||||
-- @return #DETECTION_BASE
|
-- @return #DETECTION_BASE
|
||||||
function DETECTION_BASE:CleanDetectionItems() --R2.1 Clean the DetectionItems list
|
function DETECTION_BASE:CleanDetectionItem( DetectedItem, DetectedItemID )
|
||||||
self:F2()
|
self:F2()
|
||||||
|
|
||||||
-- We clean all DetectedItems.
|
-- We clean all DetectedItems.
|
||||||
-- if there are any remaining DetectedItems with no Set Objects then the Item in the DetectedItems must be deleted.
|
-- if there are any remaining DetectedItems with no Set Objects then the Item in the DetectedItems must be deleted.
|
||||||
|
|
||||||
for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do
|
local DetectedSet = DetectedItem.Set
|
||||||
|
|
||||||
local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem
|
if DetectedSet:Count() == 0 then
|
||||||
local DetectedSet = DetectedItem.Set
|
self:RemoveDetectedItem( DetectedItemID )
|
||||||
|
|
||||||
if DetectedSet:Count() == 0 then
|
|
||||||
self:RemoveDetectedItem(DetectedItemID)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -1160,7 +1174,7 @@ do -- DETECTION_BASE
|
|||||||
--- @param Wrapper.Unit#UNIT PlayerUnit
|
--- @param Wrapper.Unit#UNIT PlayerUnit
|
||||||
function( PlayerUnitName )
|
function( PlayerUnitName )
|
||||||
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
||||||
if PlayerUnit:IsInZone(DetectionZone) then
|
if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
|
||||||
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
|
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
|
||||||
local PlayerUnitName = PlayerUnit:GetName()
|
local PlayerUnitName = PlayerUnit:GetName()
|
||||||
DetectedItem.PlayersNearBy = DetectedItem.PlayersNearBy or {}
|
DetectedItem.PlayersNearBy = DetectedItem.PlayersNearBy or {}
|
||||||
@ -1368,6 +1382,37 @@ do -- DETECTION_BASE
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set IsDetected flag for all DetectedItems.
|
||||||
|
-- @param #DETECTION_BASE self
|
||||||
|
-- @return #DETECTION_BASE.DetectedItem DetectedItem
|
||||||
|
-- @return #boolean true if at least one UNIT is detected from the DetectedSet, false if no UNIT was detected from the DetectedSet.
|
||||||
|
function DETECTION_BASE:UpdateDetectedItemDetection( DetectedItem )
|
||||||
|
|
||||||
|
local IsDetected = false
|
||||||
|
|
||||||
|
for UnitName, UnitData in pairs( DetectedItem.Set:GetSet() ) do
|
||||||
|
local DetectedObject = self.DetectedObjects[UnitName]
|
||||||
|
if DetectedObject.IsDetected then
|
||||||
|
IsDetected = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:F( { IsDetected = DetectedItem.IsDetected } )
|
||||||
|
|
||||||
|
DetectedItem.IsDetected = IsDetected
|
||||||
|
|
||||||
|
return IsDetected
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Checks if there is at least one UNIT detected in the Set of the the DetectedItem.
|
||||||
|
-- @param #DETECTION_BASE self
|
||||||
|
-- @return #boolean true if at least one UNIT is detected from the DetectedSet, false if no UNIT was detected from the DetectedSet.
|
||||||
|
function DETECTION_BASE:IsDetectedItemDetected( DetectedItem )
|
||||||
|
|
||||||
|
return DetectedItem.IsDetected
|
||||||
|
end
|
||||||
|
|
||||||
do -- Coordinates
|
do -- Coordinates
|
||||||
|
|
||||||
--- Get the COORDINATE of a detection item using a given numeric index.
|
--- Get the COORDINATE of a detection item using a given numeric index.
|
||||||
@ -2325,6 +2370,7 @@ do -- DETECTION_AREAS
|
|||||||
for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do
|
for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do
|
||||||
|
|
||||||
local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem
|
local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem
|
||||||
|
|
||||||
if DetectedItem then
|
if DetectedItem then
|
||||||
|
|
||||||
self:T( { "Detected Item ID:", DetectedItemID } )
|
self:T( { "Detected Item ID:", DetectedItemID } )
|
||||||
|
|||||||
@ -40,6 +40,7 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
Mission = nil,
|
Mission = nil,
|
||||||
Detection = nil,
|
Detection = nil,
|
||||||
Tasks = {},
|
Tasks = {},
|
||||||
|
SweepZones = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -92,10 +93,11 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
local DetectedSet = DetectedItem.Set
|
local DetectedSet = DetectedItem.Set
|
||||||
local DetectedZone = DetectedItem.Zone
|
local DetectedZone = DetectedItem.Zone
|
||||||
|
|
||||||
|
-- Check if there is at least one UNIT in the DetectedSet is visible.
|
||||||
|
|
||||||
if true then
|
if DetectedItem.IsDetected == true then
|
||||||
|
|
||||||
-- Here we're doing something advanced... We're copying the DetectedSet, but making a new Set only with SEADable Radar units in it.
|
-- Here we're doing something advanced... We're copying the DetectedSet.
|
||||||
local TargetSetUnit = SET_UNIT:New()
|
local TargetSetUnit = SET_UNIT:New()
|
||||||
TargetSetUnit:SetDatabase( DetectedSet )
|
TargetSetUnit:SetDatabase( DetectedSet )
|
||||||
TargetSetUnit:FilterOnce() -- Filter but don't do any events!!! Elements are added manually upon each detection.
|
TargetSetUnit:FilterOnce() -- Filter but don't do any events!!! Elements are added manually upon each detection.
|
||||||
@ -106,6 +108,33 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Creates an SWEEP task when there are targets for it.
|
||||||
|
-- @param #TASK_A2A_DISPATCHER self
|
||||||
|
-- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
|
||||||
|
-- @return Set#SET_UNIT TargetSetUnit: The target set of units.
|
||||||
|
-- @return #nil If there are no targets to be set.
|
||||||
|
function TASK_A2A_DISPATCHER:EvaluateSWEEP( DetectedItem )
|
||||||
|
self:F( { DetectedItem.ItemID } )
|
||||||
|
|
||||||
|
local DetectedSet = DetectedItem.Set
|
||||||
|
local DetectedZone = DetectedItem.Zone
|
||||||
|
|
||||||
|
|
||||||
|
if DetectedItem.IsDetected == false then
|
||||||
|
|
||||||
|
-- Here we're doing something advanced... We're copying the DetectedSet.
|
||||||
|
local TargetSetUnit = SET_UNIT:New()
|
||||||
|
TargetSetUnit:SetDatabase( DetectedSet )
|
||||||
|
TargetSetUnit:FilterOnce() -- Filter but don't do any events!!! Elements are added manually upon each detection.
|
||||||
|
|
||||||
|
return TargetSetUnit
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Creates an ENGAGE task when there are human friendlies airborne near the targets.
|
--- Creates an ENGAGE task when there are human friendlies airborne near the targets.
|
||||||
-- @param #TASK_A2A_DISPATCHER self
|
-- @param #TASK_A2A_DISPATCHER self
|
||||||
-- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
|
-- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem
|
||||||
@ -120,9 +149,10 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
local PlayersCount, PlayersReport = self:GetPlayerFriendliesNearBy( DetectedItem )
|
local PlayersCount, PlayersReport = self:GetPlayerFriendliesNearBy( DetectedItem )
|
||||||
|
|
||||||
|
|
||||||
if PlayersCount > 0 then
|
-- Only allow ENGAGE when there are Players near the zone, and when the Area has detected items since the last run in a 60 seconds time zone.
|
||||||
|
if PlayersCount > 0 and DetectedItem.IsDetected == true then
|
||||||
|
|
||||||
-- Here we're doing something advanced... We're copying the DetectedSet, but making a new Set only with SEADable Radar units in it.
|
-- Here we're doing something advanced... We're copying the DetectedSet.
|
||||||
local TargetSetUnit = SET_UNIT:New()
|
local TargetSetUnit = SET_UNIT:New()
|
||||||
TargetSetUnit:SetDatabase( DetectedSet )
|
TargetSetUnit:SetDatabase( DetectedSet )
|
||||||
TargetSetUnit:FilterOnce() -- Filter but don't do any events!!! Elements are added manually upon each detection.
|
TargetSetUnit:FilterOnce() -- Filter but don't do any events!!! Elements are added manually upon each detection.
|
||||||
@ -168,6 +198,15 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
if IsPlayers == true then
|
if IsPlayers == true then
|
||||||
Remove = true
|
Remove = true
|
||||||
end
|
end
|
||||||
|
if DetectedItem.IsDetected == false then
|
||||||
|
Remove = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if TaskType == "SWEEP" then
|
||||||
|
if DetectedItem.IsDetected == true then
|
||||||
|
Remove = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
||||||
@ -338,6 +377,11 @@ do -- TASK_A2A_DISPATCHER
|
|||||||
local TargetSetUnit = self:EvaluateINTERCEPT( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
|
local TargetSetUnit = self:EvaluateINTERCEPT( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
|
||||||
if TargetSetUnit then
|
if TargetSetUnit then
|
||||||
Task = TASK_A2A_INTERCEPT:New( Mission, self.SetGroup, string.format( "INTERCEPT.%03d", DetectedID ), TargetSetUnit )
|
Task = TASK_A2A_INTERCEPT:New( Mission, self.SetGroup, string.format( "INTERCEPT.%03d", DetectedID ), TargetSetUnit )
|
||||||
|
else
|
||||||
|
local TargetSetUnit = self:EvaluateSWEEP( DetectedItem ) -- Returns a SetUnit
|
||||||
|
if TargetSetUnit then
|
||||||
|
Task = TASK_A2A_SWEEP:New( Mission, self.SetGroup, string.format( "SWEEP.%03d", DetectedID ), TargetSetUnit )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user