From 0f9591464a67d9ff87e207d734033318b1649482 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 15 Mar 2019 09:57:50 +0100 Subject: [PATCH 1/9] First version --- Moose Development/Moose/Core/Zone.lua | 4 +- .../Moose/Functional/Detection.lua | 647 +++++++++++++++++- 2 files changed, 636 insertions(+), 15 deletions(-) diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 2c00f48f5..70fb83ca3 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -631,8 +631,8 @@ end -- * @{ZONE_RADIUS.IsNoneInZone}(): Scan if the zone is empty. -- @{#ZONE_RADIUS. -- @param #ZONE_RADIUS self --- @param ObjectCategories --- @param UnitCategories +-- @param ObjectCategories An array of categories of the objects to find in the zone. +-- @param UnitCategories An array of unit categories of the objects to find in the zone. -- @usage -- self.Zone:Scan() -- local IsAttacked = self.Zone:IsSomeInZoneOfCoalition( self.Coalition ) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index c3eb65ccd..31f148f36 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -305,9 +305,9 @@ do -- DETECTION_BASE --- DETECTION constructor. -- @param #DETECTION_BASE self - -- @param Core.Set#SET_GROUP DetectionSetGroup The @{Set} of GROUPs in the Forward Air Controller role. + -- @param Core.Set#SET_BASE DetectionSet The @{Set} that is used to detect the units. -- @return #DETECTION_BASE self - function DETECTION_BASE:New( DetectionSetGroup ) + function DETECTION_BASE:New( DetectionSet ) -- Inherits from BASE local self = BASE:Inherit( self, FSM:New() ) -- #DETECTION_BASE @@ -316,7 +316,7 @@ do -- DETECTION_BASE self.DetectedItemMax = 0 self.DetectedItems = {} - self.DetectionSetGroup = DetectionSetGroup + self.DetectionSet = DetectionSet self.RefreshTimeInterval = 30 @@ -398,7 +398,7 @@ do -- DETECTION_BASE -- @param #string To The To State string. self:AddTransition( "Detecting", "Detect", "Detecting" ) - self:AddTransition( "Detecting", "DetectionGroup", "Detecting" ) + self:AddTransition( "Detecting", "Detection", "Detecting" ) --- OnBefore Transition Handler for Event Detect. -- @function [parent=#DETECTION_BASE] OnBeforeDetect @@ -540,10 +540,11 @@ do -- DETECTION_BASE self.DetectedObjects[DetectionObjectName].Distance = 10000000 end - for DetectionGroupID, DetectionGroupData in pairs( self.DetectionSetGroup:GetSet() ) do + + for DetectionID, DetectionData in pairs( self.DetectionSet:GetSet() ) do --self:F( { DetectionGroupData } ) - self:F( { DetectionGroup = DetectionGroupData:GetName() } ) - self:__DetectionGroup( DetectDelay, DetectionGroupData, DetectionTimeStamp ) -- Process each detection asynchronously. + self:F( { DetectionGroup = DetectionData:GetName() } ) + self:__Detection( DetectDelay, DetectionData, DetectionTimeStamp ) -- Process each detection asynchronously. self.DetectionCount = self.DetectionCount + 1 DetectDelay = DetectDelay + 1 end @@ -555,7 +556,7 @@ do -- DETECTION_BASE -- @param #string To The To State string. -- @param Wrapper.Group#GROUP DetectionGroup The Group detecting. -- @param #number DetectionTimeStamp Time stamp of detection event. - function DETECTION_BASE:onafterDetectionGroup( From, Event, To, DetectionGroup, DetectionTimeStamp ) + function DETECTION_BASE:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) --self:F( { DetectedObjects = self.DetectedObjects } ) @@ -563,16 +564,16 @@ do -- DETECTION_BASE local HasDetectedObjects = false - if DetectionGroup:IsAlive() then + if Detection:IsAlive() then --self:T( { "DetectionGroup is Alive", DetectionGroup:GetName() } ) - local DetectionGroupName = DetectionGroup:GetName() - local DetectionUnit = DetectionGroup:GetUnit(1) + local DetectionGroupName = Detection:GetName() + local DetectionUnit = Detection:GetUnit(1) local DetectedUnits = {} - local DetectedTargets = DetectionGroup:GetDetectedTargets( + local DetectedTargets = Detection:GetDetectedTargets( self.DetectVisual, self.DetectOptical, self.DetectRadar, @@ -624,7 +625,7 @@ do -- DETECTION_BASE local DetectedObjectVec3 = DetectedObject:getPoint() local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z } - local DetectionGroupVec3 = DetectionGroup:GetVec3() + local DetectionGroupVec3 = Detection:GetVec3() local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z } local Distance = ( ( DetectedObjectVec3.x - DetectionGroupVec3.x )^2 + @@ -2819,3 +2820,623 @@ do -- DETECTION_AREAS end end + +do -- DETECTION_ZONES + + --- @type DETECTION_ZONES + -- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. + -- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange. + -- @extends Functional.Detection#DETECTION_BASE + + --- Detect units within the battle zone for a list of @{Wrapper.Group}s detecting targets following (a) detection method(s), + -- and will build a list (table) of @{Core.Set#SET_UNIT}s containing the @{Wrapper.Unit#UNIT}s detected. + -- The class is group the detected units within zones given a DetectedZoneRange parameter. + -- A set with multiple detected zones will be created as there are groups of units detected. + -- + -- ## 4.1) Retrieve the Detected Unit Sets and Detected Zones + -- + -- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DECTECTION_BASE} and + -- the methods to manage the DetectedItems[].Zone(s) is implemented in @{Functional.Detection#DETECTION_ZONES}. + -- + -- Retrieve the DetectedItems[].Set with the method @{Functional.Detection#DETECTION_BASE.GetDetectedSet}(). A @{Core.Set#SET_UNIT} object will be returned. + -- + -- Retrieve the formed @{Zone@ZONE_UNIT}s as a result of the grouping the detected units within the DetectionZoneRange, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZones}(). + -- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZoneCount}(). + -- If you want to obtain a specific zone from the DetectedZones, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZone}() with a given index. + -- + -- ## 4.4) Flare or Smoke detected units + -- + -- Use the methods @{Functional.Detection#DETECTION_ZONES.FlareDetectedUnits}() or @{Functional.Detection#DETECTION_ZONES.SmokeDetectedUnits}() to flare or smoke the detected units when a new detection has taken place. + -- + -- ## 4.5) Flare or Smoke or Bound detected zones + -- + -- Use the methods: + -- + -- * @{Functional.Detection#DETECTION_ZONES.FlareDetectedZones}() to flare in a color + -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to smoke in a color + -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to bound with a tire with a white flag + -- + -- the detected zones when a new detection has taken place. + -- + -- @field #DETECTION_ZONES + DETECTION_ZONES = { + ClassName = "DETECTION_ZONES", + DetectionZoneRange = nil, + } + + + --- DETECTION_ZONES constructor. + -- @param #DETECTION_ZONES self + -- @param Core.Set#SET_ZONE_RADIUS DetectionSetZoneRadius The @{Set} of ZONE_RADIUS. + -- @param DCS#Coalition.side DetectionCoalition The coalition of the detection. + -- @return #DETECTION_ZONES + function DETECTION_ZONES:New( DetectionSetZoneRadius, DetectionCoalition ) + + -- Inherits from DETECTION_BASE + local self = BASE:Inherit( self, DETECTION_BASE:New() ) + + self.DetectionSetZoneRadius = DetectionSetZoneRadius + self.DetectionCoalition = DetectionCoalition + + self._SmokeDetectedUnits = false + self._FlareDetectedUnits = false + self._SmokeDetectedZones = false + self._FlareDetectedZones = false + self._BoundDetectedZones = false + + return self + end + + + --- Report summary of a detected item using a given numeric index. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem. + -- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for. + -- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use. + -- @return Core.Report#REPORT The report of the detection items. + function DETECTION_ZONES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings ) + self:F( { DetectedItem = DetectedItem } ) + + local DetectedItemID = self:GetDetectedItemID( DetectedItem ) + + if DetectedItem then + local DetectedSet = self:GetDetectedSet( DetectedItem ) + local ReportSummaryItem + + local DetectedZone = self:GetDetectedItemZone( DetectedItem ) + local DetectedItemCoordinate = DetectedZone:GetCoordinate() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) + + local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem ) + local DetectedItemsCount = DetectedSet:Count() + local DetectedItemsTypes = DetectedSet:GetTypeNames() + + local Report = REPORT:New() + Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) + 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("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) ) + + return Report + end + + return nil + end + + --- Report detailed of a detection result. + -- @param #DETECTION_ZONES self + -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. + -- @return #string + function DETECTION_ZONES:DetectedReportDetailed( AttackGroup ) --R2.1 Fixed missing report + self:F() + + local Report = REPORT:New() + for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do + local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem + local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup ) + Report:SetTitle( "Detected areas:" ) + Report:Add( ReportSummary:Text() ) + end + + local ReportText = Report:Text() + + return ReportText + end + + + --- Calculate the optimal intercept point of the DetectedItem. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem + function DETECTION_ZONES:CalculateIntercept( DetectedItem ) + + local DetectedCoord = DetectedItem.Coordinate + local DetectedSpeed = DetectedCoord:GetVelocity() + local DetectedHeading = DetectedCoord:GetHeading() + + if self.Intercept then + local DetectedSet = DetectedItem.Set + -- todo: speed + + local TranslateDistance = DetectedSpeed * self.InterceptDelay + + local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading ) + + DetectedItem.InterceptCoord = InterceptCoord + else + DetectedItem.InterceptCoord = DetectedCoord + end + + end + + + + --- Smoke the detected units + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:SmokeDetectedUnits() + self:F2() + + self._SmokeDetectedUnits = true + return self + end + + --- Flare the detected units + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:FlareDetectedUnits() + self:F2() + + self._FlareDetectedUnits = true + return self + end + + --- Smoke the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:SmokeDetectedZones() + self:F2() + + self._SmokeDetectedZones = true + return self + end + + --- Flare the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:FlareDetectedZones() + self:F2() + + self._FlareDetectedZones = true + return self + end + + --- Bound the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:BoundDetectedZones() + self:F2() + + self._BoundDetectedZones = true + return self + end + + --- Make text documenting the changes of the detected zone. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem + -- @return #string The Changes text + function DETECTION_ZONES:GetChangeText( DetectedItem ) + self:F( DetectedItem ) + + local MT = {} + + for ChangeCode, ChangeData in pairs( DetectedItem.Changes ) do + + if ChangeCode == "AA" then + MT[#MT+1] = "Detected new area " .. ChangeData.ID .. ". The center target is a " .. ChangeData.ItemUnitType .. "." + end + + if ChangeCode == "RAU" then + MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". Removed the center target." + end + + if ChangeCode == "AAU" then + MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". The new center target is a " .. ChangeData.ItemUnitType .. "." + end + + if ChangeCode == "RA" then + MT[#MT+1] = "Removed old area " .. ChangeData.ID .. ". No more targets in this area." + end + + if ChangeCode == "AU" then + local MTUT = {} + for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do + if ChangeUnitType ~= "ID" then + MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType + end + end + MT[#MT+1] = "Detected for area " .. ChangeData.ID .. " new target(s) " .. table.concat( MTUT, ", " ) .. "." + end + + if ChangeCode == "RU" then + local MTUT = {} + for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do + if ChangeUnitType ~= "ID" then + MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType + end + end + MT[#MT+1] = "Removed for area " .. ChangeData.ID .. " invisible or destroyed target(s) " .. table.concat( MTUT, ", " ) .. "." + end + + end + + return table.concat( MT, "\n" ) + + end + + + --- Make a DetectionSet table. This function will be overridden in the derived clsses. + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:CreateDetectionItems() + + + self:F( "Checking Detected Items for new Detected Units ..." ) + --self:F( { DetectedObjects = self.DetectedObjects } ) + + -- 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. + for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do + + local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem + + if DetectedItem then + + self:T2( { "Detected Item ID: ", DetectedItemID } ) + + local Zone = DetectedItem.Zone -- Core.Zone#ZONE_RADIUS + + -- Scan the zone + Zone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) + + local ZoneUnits = Zone:GetScannedUnits() + for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do + local UnitName = DCSUnit:getName() + local ZoneUnit = UNIT:FindByName( UnitName ) + local ZoneUnitCoalition = ZoneUnit:GetCoalition() + if ZoneUnitCoalition == self.DetectionCoalition then + DetectedItem.Set:AddUnit( ZoneUnit ) + 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. + + for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do + + local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem + local DetectedSet = DetectedItem.Set + local DetectedFirstUnit = DetectedSet:GetFirst() + local DetectedZone = DetectedItem.Zone + + -- Set the last known coordinate to the detection item. + local DetectedZoneCoord = DetectedZone:GetCoordinate() + self:SetDetectedItemCoordinate( DetectedItem, DetectedZoneCoord, DetectedFirstUnit ) + + self:CalculateIntercept( DetectedItem ) + + -- We search for friendlies nearby. + -- If there weren't any friendlies nearby, and now there are friendlies nearby, we flag the area as "changed". + -- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed". + -- This is for the A2G dispatcher to detect if there is a change in the tactical situation. + local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) + self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table + local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) + if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then + DetectedItem.Changed = true + end + + self:SetDetectedItemThreatLevel( DetectedItem ) -- Calculate A2G threat level + self:NearestRecce( DetectedItem ) + + + if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then + DetectedZone.ZoneUNIT:SmokeRed() + end + + --DetectedSet:Flush( self ) + + DetectedSet:ForEachUnit( + --- @param Wrapper.Unit#UNIT DetectedUnit + function( DetectedUnit ) + if DetectedUnit:IsAlive() then + --self:T( "Detected Set #" .. DetectedItem.ID .. ":" .. DetectedUnit:GetName() ) + if DETECTION_ZONES._FlareDetectedUnits or self._FlareDetectedUnits then + DetectedUnit:FlareGreen() + end + if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then + DetectedUnit:SmokeGreen() + end + end + end + ) + if DETECTION_ZONES._FlareDetectedZones or self._FlareDetectedZones then + DetectedZone:FlareZone( SMOKECOLOR.White, 30, math.random( 0,90 ) ) + end + if DETECTION_ZONES._SmokeDetectedZones or self._SmokeDetectedZones then + DetectedZone:SmokeZone( SMOKECOLOR.White, 30 ) + end + + if DETECTION_ZONES._BoundDetectedZones or self._BoundDetectedZones then + self.CountryID = DetectedSet:GetFirst():GetCountry() + DetectedZone:BoundZone( 12, self.CountryID ) + end + end + + end + + --- @param #DETECTION_ZONES self + -- @param #string From The From State string. + -- @param #string Event The Event string. + -- @param #string To The To State string. + -- @param Detection The element on which the detection is based. + -- @param #number DetectionTimeStamp Time stamp of detection event. + function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) + + --self:F( { DetectedObjects = self.DetectedObjects } ) + + self.DetectionRun = self.DetectionRun + 1 + + local HasDetectedObjects = false + + if Detection:IsAlive() then + + --self:T( { "DetectionGroup is Alive", DetectionGroup:GetName() } ) + + local DetectionGroupName = Detection:GetName() + local DetectionUnit = Detection:GetUnit(1) + + local DetectedUnits = {} + + local DetectedTargets = Detection:GetDetectedTargets( + self.DetectVisual, + self.DetectOptical, + self.DetectRadar, + self.DetectIRST, + self.DetectRWR, + self.DetectDLINK + ) + + self:F( { DetectedTargets = DetectedTargets } ) + + for DetectionObjectID, Detection in pairs( DetectedTargets ) do + local DetectedObject = Detection.object -- DCS#Object + + if DetectedObject and DetectedObject:isExist() and DetectedObject.id_ < 50000000 then -- and ( DetectedObject:getCategory() == Object.Category.UNIT or DetectedObject:getCategory() == Object.Category.STATIC ) then + local DetectedObjectName = DetectedObject:getName() + if not self.DetectedObjects[DetectedObjectName] then + self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {} + self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName + self.DetectedObjects[DetectedObjectName].Object = DetectedObject + end + end + end + + for DetectionObjectName, DetectedObjectData in pairs( self.DetectedObjects ) do + + local DetectedObject = DetectedObjectData.Object + + if DetectedObject:isExist() then + + local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity = DetectionUnit:IsTargetDetected( + DetectedObject, + self.DetectVisual, + self.DetectOptical, + self.DetectRadar, + self.DetectIRST, + self.DetectRWR, + self.DetectDLINK + ) + + --self:T2( { TargetIsDetected = TargetIsDetected, TargetIsVisible = TargetIsVisible, TargetLastTime = TargetLastTime, TargetKnowType = TargetKnowType, TargetKnowDistance = TargetKnowDistance, TargetLastPos = TargetLastPos, TargetLastVelocity = TargetLastVelocity } ) + + -- Only process if the target is visible. Detection also returns invisible units. + --if Detection.visible == true then + + local DetectionAccepted = true + + local DetectedObjectName = DetectedObject:getName() + local DetectedObjectType = DetectedObject:getTypeName() + + local DetectedObjectVec3 = DetectedObject:getPoint() + local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z } + local DetectionGroupVec3 = Detection:GetVec3() + local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z } + + local Distance = ( ( DetectedObjectVec3.x - DetectionGroupVec3.x )^2 + + ( DetectedObjectVec3.y - DetectionGroupVec3.y )^2 + + ( DetectedObjectVec3.z - DetectionGroupVec3.z )^2 + ) ^ 0.5 / 1000 + + local DetectedUnitCategory = DetectedObject:getDesc().category + + --self:F( { "Detected Target:", DetectionGroupName, DetectedObjectName, DetectedObjectType, Distance, DetectedUnitCategory } ) + + -- Calculate Acceptance + + DetectionAccepted = self._.FilterCategories[DetectedUnitCategory] ~= nil and DetectionAccepted or false + + -- if Distance > 15000 then + -- if DetectedUnitCategory == Unit.Category.GROUND_UNIT or DetectedUnitCategory == Unit.Category.SHIP then + -- if DetectedObject:hasSensors( Unit.SensorType.RADAR, Unit.RadarType.AS ) == false then + -- DetectionAccepted = false + -- end + -- end + -- end + + if self.AcceptRange and Distance * 1000 > self.AcceptRange then + DetectionAccepted = false + end + + if self.AcceptZones then + local AnyZoneDetection = false + for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do + local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE + if AcceptZone:IsVec2InZone( DetectedObjectVec2 ) then + AnyZoneDetection = true + end + end + if not AnyZoneDetection then + DetectionAccepted = false + end + end + + if self.RejectZones then + for RejectZoneID, RejectZone in pairs( self.RejectZones ) do + local RejectZone = RejectZone -- Core.Zone#ZONE_BASE + if RejectZone:IsPointVec2InZone( DetectedObjectVec2 ) == true then + DetectionAccepted = false + end + end + end + + -- Calculate additional probabilities + + if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.DistanceProbability then + local DistanceFactor = Distance / 4 + local DistanceProbabilityReversed = ( 1 - self.DistanceProbability ) * DistanceFactor + local DistanceProbability = 1 - DistanceProbabilityReversed + DistanceProbability = DistanceProbability * 30 / 300 + local Probability = math.random() -- Selects a number between 0 and 1 + --self:T( { Probability, DistanceProbability } ) + if Probability > DistanceProbability then + DetectionAccepted = false + end + end + + if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.AlphaAngleProbability then + local NormalVec2 = { x = DetectedObjectVec2.x - DetectionGroupVec2.x, y = DetectedObjectVec2.y - DetectionGroupVec2.y } + local AlphaAngle = math.atan2( NormalVec2.y, NormalVec2.x ) + local Sinus = math.sin( AlphaAngle ) + local AlphaAngleProbabilityReversed = ( 1 - self.AlphaAngleProbability ) * ( 1 - Sinus ) + local AlphaAngleProbability = 1 - AlphaAngleProbabilityReversed + + AlphaAngleProbability = AlphaAngleProbability * 30 / 300 + + local Probability = math.random() -- Selects a number between 0 and 1 + --self:T( { Probability, AlphaAngleProbability } ) + if Probability > AlphaAngleProbability then + DetectionAccepted = false + end + + end + + if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.ZoneProbability then + + for ZoneDataID, ZoneData in pairs( self.ZoneProbability ) do + self:F({ZoneData}) + local ZoneObject = ZoneData[1] -- Core.Zone#ZONE_BASE + local ZoneProbability = ZoneData[2] -- #number + ZoneProbability = ZoneProbability * 30 / 300 + + if ZoneObject:IsPointVec2InZone( DetectedObjectVec2 ) == true then + local Probability = math.random() -- Selects a number between 0 and 1 + --self:T( { Probability, ZoneProbability } ) + if Probability > ZoneProbability then + DetectionAccepted = false + break + end + end + end + end + + if DetectionAccepted then + + HasDetectedObjects = true + + self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {} + self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName + + if TargetIsDetected and TargetIsDetected == true then + self.DetectedObjects[DetectedObjectName].IsDetected = TargetIsDetected + end + + if TargetIsDetected and TargetIsVisible and TargetIsVisible == true then + self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsDetected and TargetIsVisible + end + + if TargetIsDetected and not self.DetectedObjects[DetectedObjectName].KnowType then + self.DetectedObjects[DetectedObjectName].KnowType = TargetIsDetected and TargetKnowType + end + self.DetectedObjects[DetectedObjectName].KnowDistance = TargetKnowDistance -- Detection.distance -- TargetKnowDistance + self.DetectedObjects[DetectedObjectName].LastTime = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastTime + self.DetectedObjects[DetectedObjectName].LastPos = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastPos + self.DetectedObjects[DetectedObjectName].LastVelocity = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastVelocity + + if not self.DetectedObjects[DetectedObjectName].Distance or ( Distance and self.DetectedObjects[DetectedObjectName].Distance > Distance ) then + self.DetectedObjects[DetectedObjectName].Distance = Distance + end + + self.DetectedObjects[DetectedObjectName].DetectionTimeStamp = DetectionTimeStamp + + self:F( { DetectedObject = self.DetectedObjects[DetectedObjectName] } ) + + local DetectedUnit = UNIT:FindByName( DetectedObjectName ) + + DetectedUnits[DetectedObjectName] = DetectedUnit + else + -- if beyond the DetectionRange then nullify... + self:F( { DetectedObject = "No more detection for " .. DetectedObjectName } ) + if self.DetectedObjects[DetectedObjectName] then + self.DetectedObjects[DetectedObjectName] = nil + end + end + + --self:T2( self.DetectedObjects ) + else + -- The previously detected object does not exist anymore, delete from the cache. + self:F( "Removing from DetectedObjects: " .. DetectionObjectName ) + self.DetectedObjects[DetectionObjectName] = nil + end + end + + if HasDetectedObjects then + self:__Detected( 0.1, DetectedUnits ) + end + + end + + if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then + + -- 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 + 300 <= 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. + 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. + if DetectedItem then + self:__DetectedItem( 0.1, DetectedItem ) + end + end + + self:__Detect( self.RefreshTimeInterval ) + end + + end + + + end + + +end From 044b5cba7ca7ff8dfbf11d6a4306ec33896c3ef6 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 15 Mar 2019 11:01:06 +0100 Subject: [PATCH 2/9] Updates --- .../Moose/Functional/Detection.lua | 322 +++--------------- 1 file changed, 45 insertions(+), 277 deletions(-) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 31f148f36..9367f4493 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1550,9 +1550,9 @@ do -- DETECTION_BASE -- @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. -- @return #DETECTION_BASE.DetectedItem - function DETECTION_BASE:AddDetectedItemZone( DetectedItemKey, Set, Zone ) + function DETECTION_BASE:AddDetectedItemZone( ItemPrefix, DetectedItemKey, Set, Zone ) - local DetectedItem = self:AddDetectedItem( "AREA", DetectedItemKey, Set ) + local DetectedItem = self:AddDetectedItem( ItemPrefix, DetectedItemKey, Set ) DetectedItem.Zone = Zone @@ -2742,7 +2742,7 @@ do -- DETECTION_AREAS if AddedToDetectionArea == false then -- New detection area - local DetectedItem = self:AddDetectedItemZone( nil, + local DetectedItem = self:AddDetectedItemZone( "AREA", nil, SET_UNIT:New():FilterDeads():FilterCrashes(), ZONE_UNIT:New( DetectedUnitName, DetectedUnit, self.DetectionZoneRange ) ) @@ -2867,15 +2867,15 @@ do -- DETECTION_ZONES --- DETECTION_ZONES constructor. -- @param #DETECTION_ZONES self - -- @param Core.Set#SET_ZONE_RADIUS DetectionSetZoneRadius The @{Set} of ZONE_RADIUS. + -- @param Core.Set#SET_ZONE_RADIUS DetectionSetZone The @{Set} of ZONE_RADIUS. -- @param DCS#Coalition.side DetectionCoalition The coalition of the detection. -- @return #DETECTION_ZONES - function DETECTION_ZONES:New( DetectionSetZoneRadius, DetectionCoalition ) + function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition ) -- Inherits from DETECTION_BASE local self = BASE:Inherit( self, DETECTION_BASE:New() ) - self.DetectionSetZoneRadius = DetectionSetZoneRadius + self.DetectionSetZone = DetectionSetZone self.DetectionCoalition = DetectionCoalition self._SmokeDetectedUnits = false @@ -3081,33 +3081,37 @@ do -- DETECTION_ZONES self:F( "Checking Detected Items for new Detected Units ..." ) - --self:F( { DetectedObjects = self.DetectedObjects } ) + + 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. - for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do + for ZoneName, DetectionZone in pairs( self.DetectionSetZones:GetSet() ) do - local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem + local DetectedItem = self:GetDetectedItemByKey( ZoneName ) + + if DetectedItem == nil then + DetectedItem = self:AddDetectedItemZone( "ZONE", ZoneName, nil, DetectionZone ) + end + + local DetectedItemSetUnit = self - if DetectedItem then + -- Scan the zone + DetectionZone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) - self:T2( { "Detected Item ID: ", DetectedItemID } ) - - local Zone = DetectedItem.Zone -- Core.Zone#ZONE_RADIUS - - -- Scan the zone - Zone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) - - local ZoneUnits = Zone:GetScannedUnits() - for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do - local UnitName = DCSUnit:getName() - local ZoneUnit = UNIT:FindByName( UnitName ) - local ZoneUnitCoalition = ZoneUnit:GetCoalition() - if ZoneUnitCoalition == self.DetectionCoalition then - DetectedItem.Set:AddUnit( ZoneUnit ) + local ZoneUnits = DetectionZone:GetScannedUnits() + for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do + local UnitName = DCSUnit:getName() + local ZoneUnit = UNIT:FindByName( UnitName ) + local ZoneUnitCoalition = ZoneUnit:GetCoalition() + if ZoneUnitCoalition == self.DetectionCoalition then + if DetectedUnits:FindUnit( UnitName ) ~= nil then + DetectedItemSetUnit:AddUnit( ZoneUnit ) + DetectedUnits:AddUnit( ZoneUnit ) end end end + end @@ -3177,266 +3181,30 @@ do -- DETECTION_ZONES end - --- @param #DETECTION_ZONES self - -- @param #string From The From State string. - -- @param #string Event The Event string. - -- @param #string To The To State string. - -- @param Detection The element on which the detection is based. - -- @param #number DetectionTimeStamp Time stamp of detection event. - function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) - - --self:F( { DetectedObjects = self.DetectedObjects } ) - - self.DetectionRun = self.DetectionRun + 1 - - local HasDetectedObjects = false - - if Detection:IsAlive() then - - --self:T( { "DetectionGroup is Alive", DetectionGroup:GetName() } ) - - local DetectionGroupName = Detection:GetName() - local DetectionUnit = Detection:GetUnit(1) - - local DetectedUnits = {} - - local DetectedTargets = Detection:GetDetectedTargets( - self.DetectVisual, - self.DetectOptical, - self.DetectRadar, - self.DetectIRST, - self.DetectRWR, - self.DetectDLINK - ) - - self:F( { DetectedTargets = DetectedTargets } ) - - for DetectionObjectID, Detection in pairs( DetectedTargets ) do - local DetectedObject = Detection.object -- DCS#Object - - if DetectedObject and DetectedObject:isExist() and DetectedObject.id_ < 50000000 then -- and ( DetectedObject:getCategory() == Object.Category.UNIT or DetectedObject:getCategory() == Object.Category.STATIC ) then - local DetectedObjectName = DetectedObject:getName() - if not self.DetectedObjects[DetectedObjectName] then - self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {} - self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName - self.DetectedObjects[DetectedObjectName].Object = DetectedObject - end - end - end - - for DetectionObjectName, DetectedObjectData in pairs( self.DetectedObjects ) do - - local DetectedObject = DetectedObjectData.Object - - if DetectedObject:isExist() then - - local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity = DetectionUnit:IsTargetDetected( - DetectedObject, - self.DetectVisual, - self.DetectOptical, - self.DetectRadar, - self.DetectIRST, - self.DetectRWR, - self.DetectDLINK - ) - - --self:T2( { TargetIsDetected = TargetIsDetected, TargetIsVisible = TargetIsVisible, TargetLastTime = TargetLastTime, TargetKnowType = TargetKnowType, TargetKnowDistance = TargetKnowDistance, TargetLastPos = TargetLastPos, TargetLastVelocity = TargetLastVelocity } ) - - -- Only process if the target is visible. Detection also returns invisible units. - --if Detection.visible == true then - - local DetectionAccepted = true - - local DetectedObjectName = DetectedObject:getName() - local DetectedObjectType = DetectedObject:getTypeName() - - local DetectedObjectVec3 = DetectedObject:getPoint() - local DetectedObjectVec2 = { x = DetectedObjectVec3.x, y = DetectedObjectVec3.z } - local DetectionGroupVec3 = Detection:GetVec3() - local DetectionGroupVec2 = { x = DetectionGroupVec3.x, y = DetectionGroupVec3.z } - - local Distance = ( ( DetectedObjectVec3.x - DetectionGroupVec3.x )^2 + - ( DetectedObjectVec3.y - DetectionGroupVec3.y )^2 + - ( DetectedObjectVec3.z - DetectionGroupVec3.z )^2 - ) ^ 0.5 / 1000 - - local DetectedUnitCategory = DetectedObject:getDesc().category - - --self:F( { "Detected Target:", DetectionGroupName, DetectedObjectName, DetectedObjectType, Distance, DetectedUnitCategory } ) - - -- Calculate Acceptance - - DetectionAccepted = self._.FilterCategories[DetectedUnitCategory] ~= nil and DetectionAccepted or false - - -- if Distance > 15000 then - -- if DetectedUnitCategory == Unit.Category.GROUND_UNIT or DetectedUnitCategory == Unit.Category.SHIP then - -- if DetectedObject:hasSensors( Unit.SensorType.RADAR, Unit.RadarType.AS ) == false then - -- DetectionAccepted = false - -- end - -- end - -- end - - if self.AcceptRange and Distance * 1000 > self.AcceptRange then - DetectionAccepted = false - end - - if self.AcceptZones then - local AnyZoneDetection = false - for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do - local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE - if AcceptZone:IsVec2InZone( DetectedObjectVec2 ) then - AnyZoneDetection = true - end - end - if not AnyZoneDetection then - DetectionAccepted = false - end - end - - if self.RejectZones then - for RejectZoneID, RejectZone in pairs( self.RejectZones ) do - local RejectZone = RejectZone -- Core.Zone#ZONE_BASE - if RejectZone:IsPointVec2InZone( DetectedObjectVec2 ) == true then - DetectionAccepted = false - end - end - end - - -- Calculate additional probabilities - - if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.DistanceProbability then - local DistanceFactor = Distance / 4 - local DistanceProbabilityReversed = ( 1 - self.DistanceProbability ) * DistanceFactor - local DistanceProbability = 1 - DistanceProbabilityReversed - DistanceProbability = DistanceProbability * 30 / 300 - local Probability = math.random() -- Selects a number between 0 and 1 - --self:T( { Probability, DistanceProbability } ) - if Probability > DistanceProbability then - DetectionAccepted = false - end - end - - if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.AlphaAngleProbability then - local NormalVec2 = { x = DetectedObjectVec2.x - DetectionGroupVec2.x, y = DetectedObjectVec2.y - DetectionGroupVec2.y } - local AlphaAngle = math.atan2( NormalVec2.y, NormalVec2.x ) - local Sinus = math.sin( AlphaAngle ) - local AlphaAngleProbabilityReversed = ( 1 - self.AlphaAngleProbability ) * ( 1 - Sinus ) - local AlphaAngleProbability = 1 - AlphaAngleProbabilityReversed - - AlphaAngleProbability = AlphaAngleProbability * 30 / 300 - - local Probability = math.random() -- Selects a number between 0 and 1 - --self:T( { Probability, AlphaAngleProbability } ) - if Probability > AlphaAngleProbability then - DetectionAccepted = false - end - - end - - if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.ZoneProbability then - - for ZoneDataID, ZoneData in pairs( self.ZoneProbability ) do - self:F({ZoneData}) - local ZoneObject = ZoneData[1] -- Core.Zone#ZONE_BASE - local ZoneProbability = ZoneData[2] -- #number - ZoneProbability = ZoneProbability * 30 / 300 - - if ZoneObject:IsPointVec2InZone( DetectedObjectVec2 ) == true then - local Probability = math.random() -- Selects a number between 0 and 1 - --self:T( { Probability, ZoneProbability } ) - if Probability > ZoneProbability then - DetectionAccepted = false - break - end - end - end - end - - if DetectionAccepted then - - HasDetectedObjects = true - - self.DetectedObjects[DetectedObjectName] = self.DetectedObjects[DetectedObjectName] or {} - self.DetectedObjects[DetectedObjectName].Name = DetectedObjectName - - if TargetIsDetected and TargetIsDetected == true then - self.DetectedObjects[DetectedObjectName].IsDetected = TargetIsDetected - end - - if TargetIsDetected and TargetIsVisible and TargetIsVisible == true then - self.DetectedObjects[DetectedObjectName].IsVisible = TargetIsDetected and TargetIsVisible - end - - if TargetIsDetected and not self.DetectedObjects[DetectedObjectName].KnowType then - self.DetectedObjects[DetectedObjectName].KnowType = TargetIsDetected and TargetKnowType - end - self.DetectedObjects[DetectedObjectName].KnowDistance = TargetKnowDistance -- Detection.distance -- TargetKnowDistance - self.DetectedObjects[DetectedObjectName].LastTime = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastTime - self.DetectedObjects[DetectedObjectName].LastPos = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastPos - self.DetectedObjects[DetectedObjectName].LastVelocity = ( TargetIsDetected and TargetIsVisible == false ) and TargetLastVelocity - - if not self.DetectedObjects[DetectedObjectName].Distance or ( Distance and self.DetectedObjects[DetectedObjectName].Distance > Distance ) then - self.DetectedObjects[DetectedObjectName].Distance = Distance - end - - self.DetectedObjects[DetectedObjectName].DetectionTimeStamp = DetectionTimeStamp - - self:F( { DetectedObject = self.DetectedObjects[DetectedObjectName] } ) - - local DetectedUnit = UNIT:FindByName( DetectedObjectName ) - - DetectedUnits[DetectedObjectName] = DetectedUnit - else - -- if beyond the DetectionRange then nullify... - self:F( { DetectedObject = "No more detection for " .. DetectedObjectName } ) - if self.DetectedObjects[DetectedObjectName] then - self.DetectedObjects[DetectedObjectName] = nil - end - end - - --self:T2( self.DetectedObjects ) - else - -- The previously detected object does not exist anymore, delete from the cache. - self:F( "Removing from DetectedObjects: " .. DetectionObjectName ) - self.DetectedObjects[DetectionObjectName] = nil - end - end - - if HasDetectedObjects then - self:__Detected( 0.1, DetectedUnits ) - end - - end - - if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then - - -- 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 + 300 <= DetectionTimeStamp then - self.DetectedObjects[DetectedObjectName].IsDetected = false - end - end + --- @param #DETECTION_ZONES self + -- @param #string From The From State string. + -- @param #string Event The Event string. + -- @param #string To The To State string. + -- @param Detection The element on which the detection is based. + -- @param #number DetectionTimeStamp Time stamp of detection event. + function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) - self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method. - 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. - if DetectedItem then - self:__DetectedItem( 0.1, DetectedItem ) - end + self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method. + + 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. + if DetectedItem then + self:__DetectedItem( 0.1, DetectedItem ) end - - self:__Detect( self.RefreshTimeInterval ) end + + self:__Detect( self.RefreshTimeInterval ) end - end + end From 3b520ab0c413b9fcf230caa8c502160b646e58db Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 15 Mar 2019 12:39:06 +0100 Subject: [PATCH 3/9] New detection method based on zones and scanning. --- .../Moose/AI/AI_A2A_Dispatcher.lua | 2 +- Moose Development/Moose/Core/Set.lua | 2 +- .../Moose/Functional/Designate.lua | 10 +- .../Moose/Functional/Detection.lua | 416 +----------------- .../Moose/Functional/DetectionZones.lua | 403 +++++++++++++++++ Moose Development/Moose/Functional/Escort.lua | 8 +- Moose Development/Moose/Modules.lua | 1 + 7 files changed, 431 insertions(+), 411 deletions(-) create mode 100644 Moose Development/Moose/Functional/DetectionZones.lua diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index 9b9370bb3..7396cb7a6 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -1688,7 +1688,7 @@ do -- AI_A2A_DISPATCHER -- Add the CAP to the EWR network. - local RecceSet = self.Detection:GetDetectionSetGroup() + local RecceSet = self.Detection:GetDetectionSet() RecceSet:FilterPrefixes( DefenderSquadron.TemplatePrefixes ) RecceSet:FilterStart() diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index e4e2c3edf..eb210335a 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -148,7 +148,7 @@ do -- SET_BASE function SET_BASE:GetSet() self:F2() - return self.Set + return self.Set or {} end --- Gets a list of the Names of the Objects in the Set. diff --git a/Moose Development/Moose/Functional/Designate.lua b/Moose Development/Moose/Functional/Designate.lua index b8b1c24bb..7d6f09d26 100644 --- a/Moose Development/Moose/Functional/Designate.lua +++ b/Moose Development/Moose/Functional/Designate.lua @@ -469,7 +469,7 @@ do -- DESIGNATE self.CC = CC self.Detection = Detection self.AttackSet = AttackSet - self.RecceSet = Detection:GetDetectionSetGroup() + self.RecceSet = Detection:GetDetectionSet() self.Recces = {} self.Designating = {} self:SetDesignateName() @@ -1182,7 +1182,7 @@ do -- DESIGNATE local DetectedItem = self.Detection:GetDetectedItemByIndex( Index ) - local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem ) + local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem ) local MarkingCount = 0 local MarkedTypes = {} @@ -1352,7 +1352,7 @@ do -- DESIGNATE end local DetectedItem = self.Detection:GetDetectedItemByIndex( Index ) - local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem ) + local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem ) local Recces = self.Recces @@ -1377,7 +1377,7 @@ do -- DESIGNATE function DESIGNATE:onafterSmoke( From, Event, To, Index, Color ) local DetectedItem = self.Detection:GetDetectedItemByIndex( Index ) - local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem ) + local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem ) local TargetSetUnitCount = TargetSetUnit:Count() local MarkedCount = 0 @@ -1422,7 +1422,7 @@ do -- DESIGNATE function DESIGNATE:onafterIlluminate( From, Event, To, Index ) local DetectedItem = self.Detection:GetDetectedItemByIndex( Index ) - local TargetSetUnit = self.Detection:GetDetectedSet( DetectedItem ) + local TargetSetUnit = self.Detection:GetDetectedItemSet( DetectedItem ) local TargetUnit = TargetSetUnit:GetFirst() if TargetUnit then diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 9367f4493..d44edf334 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -541,11 +541,11 @@ do -- DETECTION_BASE end + self.DetectionCount = self.DetectionSet:Count() for DetectionID, DetectionData in pairs( self.DetectionSet:GetSet() ) do --self:F( { DetectionGroupData } ) self:F( { DetectionGroup = DetectionData:GetName() } ) self:__Detection( DetectDelay, DetectionData, DetectionTimeStamp ) -- Process each detection asynchronously. - self.DetectionCount = self.DetectionCount + 1 DetectDelay = DetectDelay + 1 end end @@ -839,7 +839,7 @@ do -- DETECTION_BASE local DetectedItems = self:GetDetectedItems() for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do - local DetectedSet = self:GetDetectedSet( DetectedItem ) + local DetectedSet = self:GetDetectedItemSet( DetectedItem ) if DetectedSet then DetectedSet:RemoveUnitsByName( UnitName ) end @@ -1552,6 +1552,8 @@ do -- DETECTION_BASE -- @return #DETECTION_BASE.DetectedItem function DETECTION_BASE:AddDetectedItemZone( ItemPrefix, DetectedItemKey, Set, Zone ) + self:F( { ItemPrefix, DetectedItemKey, Set, Zone } ) + local DetectedItem = self:AddDetectedItem( ItemPrefix, DetectedItemKey, Set ) DetectedItem.Zone = Zone @@ -1662,7 +1664,7 @@ do -- DETECTION_BASE -- @param #DETECTION_BASE self -- @param #DETECTION_BASE.DetectedItem DetectedItem -- @return Core.Set#SET_UNIT DetectedSet - function DETECTION_BASE:GetDetectedSet( DetectedItem ) + function DETECTION_BASE:GetDetectedItemSet( DetectedItem ) local DetectedSetUnit = DetectedItem and DetectedItem.Set if DetectedSetUnit then @@ -1811,13 +1813,13 @@ do -- DETECTION_BASE return nil end - --- Get the detection Groups. + --- Get the Detection Set. -- @param #DETECTION_BASE self - -- @return Core.Set#SET_GROUP - function DETECTION_BASE:GetDetectionSetGroup() + -- @return Core.Set#SET_BASE + function DETECTION_BASE:GetDetectionSet() - local DetectionSetGroup = self.DetectionSetGroup - return DetectionSetGroup + local DetectionSet = self.DetectionSet + return DetectionSet end --- Find the nearest Recce of the DetectedItem. @@ -1829,7 +1831,7 @@ do -- DETECTION_BASE local NearestRecce = nil local DistanceRecce = 1000000000 -- Units are not further than 1000000 km away from an area :-) - for RecceGroupName, RecceGroup in pairs( self.DetectionSetGroup:GetSet() ) do + for RecceGroupName, RecceGroup in pairs( self.DetectionSet:GetSet() ) do if RecceGroup and RecceGroup:IsAlive() then for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do if RecceUnit:IsActive() then @@ -2034,7 +2036,7 @@ do -- DETECTION_UNITS local DetectedFirstUnitCoord = DetectedFirstUnit:GetCoordinate() self:SetDetectedItemCoordinate( DetectedItem, DetectedFirstUnitCoord, DetectedFirstUnit ) - self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table + self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table self:SetDetectedItemThreatLevel( DetectedItem ) self:NearestRecce( DetectedItem ) @@ -2269,7 +2271,7 @@ do -- DETECTION_TYPES local DetectedUnitCoord = DetectedFirstUnit:GetCoordinate() self:SetDetectedItemCoordinate( DetectedItem, DetectedUnitCoord, DetectedFirstUnit ) - self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table + self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table self:SetDetectedItemThreatLevel( DetectedItem ) self:NearestRecce( DetectedItem ) end @@ -2287,7 +2289,7 @@ do -- DETECTION_TYPES function DETECTION_TYPES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings ) self:F( { DetectedItem = DetectedItem } ) - local DetectedSet = self:GetDetectedSet( DetectedItem ) + local DetectedSet = self:GetDetectedItemSet( DetectedItem ) local DetectedItemID = self:GetDetectedItemID( DetectedItem ) self:T( DetectedItem ) @@ -2409,7 +2411,7 @@ do -- DETECTION_AREAS local DetectedItemID = self:GetDetectedItemID( DetectedItem ) if DetectedItem then - local DetectedSet = self:GetDetectedSet( DetectedItem ) + local DetectedSet = self:GetDetectedItemSet( DetectedItem ) local ReportSummaryItem local DetectedZone = self:GetDetectedItemZone( DetectedItem ) @@ -2774,7 +2776,7 @@ do -- DETECTION_AREAS -- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed". -- This is for the A2G dispatcher to detect if there is a change in the tactical situation. local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) - self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table + self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSet } ) -- Fill the Friendlies table local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then DetectedItem.Changed = true @@ -2821,390 +2823,4 @@ do -- DETECTION_AREAS end -do -- DETECTION_ZONES - - --- @type DETECTION_ZONES - -- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. - -- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange. - -- @extends Functional.Detection#DETECTION_BASE - - --- Detect units within the battle zone for a list of @{Wrapper.Group}s detecting targets following (a) detection method(s), - -- and will build a list (table) of @{Core.Set#SET_UNIT}s containing the @{Wrapper.Unit#UNIT}s detected. - -- The class is group the detected units within zones given a DetectedZoneRange parameter. - -- A set with multiple detected zones will be created as there are groups of units detected. - -- - -- ## 4.1) Retrieve the Detected Unit Sets and Detected Zones - -- - -- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DECTECTION_BASE} and - -- the methods to manage the DetectedItems[].Zone(s) is implemented in @{Functional.Detection#DETECTION_ZONES}. - -- - -- Retrieve the DetectedItems[].Set with the method @{Functional.Detection#DETECTION_BASE.GetDetectedSet}(). A @{Core.Set#SET_UNIT} object will be returned. - -- - -- Retrieve the formed @{Zone@ZONE_UNIT}s as a result of the grouping the detected units within the DetectionZoneRange, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZones}(). - -- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZoneCount}(). - -- If you want to obtain a specific zone from the DetectedZones, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZone}() with a given index. - -- - -- ## 4.4) Flare or Smoke detected units - -- - -- Use the methods @{Functional.Detection#DETECTION_ZONES.FlareDetectedUnits}() or @{Functional.Detection#DETECTION_ZONES.SmokeDetectedUnits}() to flare or smoke the detected units when a new detection has taken place. - -- - -- ## 4.5) Flare or Smoke or Bound detected zones - -- - -- Use the methods: - -- - -- * @{Functional.Detection#DETECTION_ZONES.FlareDetectedZones}() to flare in a color - -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to smoke in a color - -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to bound with a tire with a white flag - -- - -- the detected zones when a new detection has taken place. - -- - -- @field #DETECTION_ZONES - DETECTION_ZONES = { - ClassName = "DETECTION_ZONES", - DetectionZoneRange = nil, - } - - - --- DETECTION_ZONES constructor. - -- @param #DETECTION_ZONES self - -- @param Core.Set#SET_ZONE_RADIUS DetectionSetZone The @{Set} of ZONE_RADIUS. - -- @param DCS#Coalition.side DetectionCoalition The coalition of the detection. - -- @return #DETECTION_ZONES - function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition ) - - -- Inherits from DETECTION_BASE - local self = BASE:Inherit( self, DETECTION_BASE:New() ) - - self.DetectionSetZone = DetectionSetZone - self.DetectionCoalition = DetectionCoalition - - self._SmokeDetectedUnits = false - self._FlareDetectedUnits = false - self._SmokeDetectedZones = false - self._FlareDetectedZones = false - self._BoundDetectedZones = false - - return self - end - - - --- Report summary of a detected item using a given numeric index. - -- @param #DETECTION_ZONES self - -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem. - -- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for. - -- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use. - -- @return Core.Report#REPORT The report of the detection items. - function DETECTION_ZONES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings ) - self:F( { DetectedItem = DetectedItem } ) - - local DetectedItemID = self:GetDetectedItemID( DetectedItem ) - - if DetectedItem then - local DetectedSet = self:GetDetectedSet( DetectedItem ) - local ReportSummaryItem - - local DetectedZone = self:GetDetectedItemZone( DetectedItem ) - local DetectedItemCoordinate = DetectedZone:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) - - local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem ) - local DetectedItemsCount = DetectedSet:Count() - local DetectedItemsTypes = DetectedSet:GetTypeNames() - - local Report = REPORT:New() - Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) - 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("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) ) - - return Report - end - - return nil - end - - --- Report detailed of a detection result. - -- @param #DETECTION_ZONES self - -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. - -- @return #string - function DETECTION_ZONES:DetectedReportDetailed( AttackGroup ) --R2.1 Fixed missing report - self:F() - - local Report = REPORT:New() - for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do - local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem - local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup ) - Report:SetTitle( "Detected areas:" ) - Report:Add( ReportSummary:Text() ) - end - - local ReportText = Report:Text() - - return ReportText - end - - - --- Calculate the optimal intercept point of the DetectedItem. - -- @param #DETECTION_ZONES self - -- @param #DETECTION_BASE.DetectedItem DetectedItem - function DETECTION_ZONES:CalculateIntercept( DetectedItem ) - - local DetectedCoord = DetectedItem.Coordinate - local DetectedSpeed = DetectedCoord:GetVelocity() - local DetectedHeading = DetectedCoord:GetHeading() - - if self.Intercept then - local DetectedSet = DetectedItem.Set - -- todo: speed - - local TranslateDistance = DetectedSpeed * self.InterceptDelay - - local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading ) - - DetectedItem.InterceptCoord = InterceptCoord - else - DetectedItem.InterceptCoord = DetectedCoord - end - - end - - - - --- Smoke the detected units - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:SmokeDetectedUnits() - self:F2() - - self._SmokeDetectedUnits = true - return self - end - - --- Flare the detected units - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:FlareDetectedUnits() - self:F2() - - self._FlareDetectedUnits = true - return self - end - - --- Smoke the detected zones - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:SmokeDetectedZones() - self:F2() - - self._SmokeDetectedZones = true - return self - end - - --- Flare the detected zones - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:FlareDetectedZones() - self:F2() - - self._FlareDetectedZones = true - return self - end - - --- Bound the detected zones - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:BoundDetectedZones() - self:F2() - - self._BoundDetectedZones = true - return self - end - - --- Make text documenting the changes of the detected zone. - -- @param #DETECTION_ZONES self - -- @param #DETECTION_BASE.DetectedItem DetectedItem - -- @return #string The Changes text - function DETECTION_ZONES:GetChangeText( DetectedItem ) - self:F( DetectedItem ) - - local MT = {} - - for ChangeCode, ChangeData in pairs( DetectedItem.Changes ) do - - if ChangeCode == "AA" then - MT[#MT+1] = "Detected new area " .. ChangeData.ID .. ". The center target is a " .. ChangeData.ItemUnitType .. "." - end - - if ChangeCode == "RAU" then - MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". Removed the center target." - end - - if ChangeCode == "AAU" then - MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". The new center target is a " .. ChangeData.ItemUnitType .. "." - end - - if ChangeCode == "RA" then - MT[#MT+1] = "Removed old area " .. ChangeData.ID .. ". No more targets in this area." - end - - if ChangeCode == "AU" then - local MTUT = {} - for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do - if ChangeUnitType ~= "ID" then - MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType - end - end - MT[#MT+1] = "Detected for area " .. ChangeData.ID .. " new target(s) " .. table.concat( MTUT, ", " ) .. "." - end - - if ChangeCode == "RU" then - local MTUT = {} - for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do - if ChangeUnitType ~= "ID" then - MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType - end - end - MT[#MT+1] = "Removed for area " .. ChangeData.ID .. " invisible or destroyed target(s) " .. table.concat( MTUT, ", " ) .. "." - end - - end - - return table.concat( MT, "\n" ) - - end - - - --- Make a DetectionSet table. This function will be overridden in the derived clsses. - -- @param #DETECTION_ZONES self - -- @return #DETECTION_ZONES self - function DETECTION_ZONES:CreateDetectionItems() - - - self:F( "Checking Detected Items for new Detected Units ..." ) - - 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. - for ZoneName, DetectionZone in pairs( self.DetectionSetZones:GetSet() ) do - - local DetectedItem = self:GetDetectedItemByKey( ZoneName ) - - if DetectedItem == nil then - DetectedItem = self:AddDetectedItemZone( "ZONE", ZoneName, nil, DetectionZone ) - end - - local DetectedItemSetUnit = self - - -- Scan the zone - DetectionZone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) - - local ZoneUnits = DetectionZone:GetScannedUnits() - for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do - local UnitName = DCSUnit:getName() - local ZoneUnit = UNIT:FindByName( UnitName ) - local ZoneUnitCoalition = ZoneUnit:GetCoalition() - if ZoneUnitCoalition == self.DetectionCoalition then - if DetectedUnits:FindUnit( UnitName ) ~= nil then - DetectedItemSetUnit:AddUnit( ZoneUnit ) - DetectedUnits:AddUnit( ZoneUnit ) - 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. - - for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do - - local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem - local DetectedSet = DetectedItem.Set - local DetectedFirstUnit = DetectedSet:GetFirst() - local DetectedZone = DetectedItem.Zone - -- Set the last known coordinate to the detection item. - local DetectedZoneCoord = DetectedZone:GetCoordinate() - self:SetDetectedItemCoordinate( DetectedItem, DetectedZoneCoord, DetectedFirstUnit ) - - self:CalculateIntercept( DetectedItem ) - - -- We search for friendlies nearby. - -- If there weren't any friendlies nearby, and now there are friendlies nearby, we flag the area as "changed". - -- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed". - -- This is for the A2G dispatcher to detect if there is a change in the tactical situation. - local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) - self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table - local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) - if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then - DetectedItem.Changed = true - end - - self:SetDetectedItemThreatLevel( DetectedItem ) -- Calculate A2G threat level - self:NearestRecce( DetectedItem ) - - - if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then - DetectedZone.ZoneUNIT:SmokeRed() - end - - --DetectedSet:Flush( self ) - - DetectedSet:ForEachUnit( - --- @param Wrapper.Unit#UNIT DetectedUnit - function( DetectedUnit ) - if DetectedUnit:IsAlive() then - --self:T( "Detected Set #" .. DetectedItem.ID .. ":" .. DetectedUnit:GetName() ) - if DETECTION_ZONES._FlareDetectedUnits or self._FlareDetectedUnits then - DetectedUnit:FlareGreen() - end - if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then - DetectedUnit:SmokeGreen() - end - end - end - ) - if DETECTION_ZONES._FlareDetectedZones or self._FlareDetectedZones then - DetectedZone:FlareZone( SMOKECOLOR.White, 30, math.random( 0,90 ) ) - end - if DETECTION_ZONES._SmokeDetectedZones or self._SmokeDetectedZones then - DetectedZone:SmokeZone( SMOKECOLOR.White, 30 ) - end - - if DETECTION_ZONES._BoundDetectedZones or self._BoundDetectedZones then - self.CountryID = DetectedSet:GetFirst():GetCountry() - DetectedZone:BoundZone( 12, self.CountryID ) - end - end - - end - - --- @param #DETECTION_ZONES self - -- @param #string From The From State string. - -- @param #string Event The Event string. - -- @param #string To The To State string. - -- @param Detection The element on which the detection is based. - -- @param #number DetectionTimeStamp Time stamp of detection event. - function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) - - self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method. - - 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. - if DetectedItem then - self:__DetectedItem( 0.1, DetectedItem ) - end - end - - self:__Detect( self.RefreshTimeInterval ) - - end - - - - - -end diff --git a/Moose Development/Moose/Functional/DetectionZones.lua b/Moose Development/Moose/Functional/DetectionZones.lua new file mode 100644 index 000000000..614dce0ec --- /dev/null +++ b/Moose Development/Moose/Functional/DetectionZones.lua @@ -0,0 +1,403 @@ +do -- DETECTION_ZONES + + --- @type DETECTION_ZONES + -- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. + -- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange. + -- @extends Functional.Detection#DETECTION_BASE + + --- (old, to be revised ) Detect units within the battle zone for a list of @{Core.Zone}s detecting targets following (a) detection method(s), + -- and will build a list (table) of @{Core.Set#SET_UNIT}s containing the @{Wrapper.Unit#UNIT}s detected. + -- The class is group the detected units within zones given a DetectedZoneRange parameter. + -- A set with multiple detected zones will be created as there are groups of units detected. + -- + -- ## 4.1) Retrieve the Detected Unit Sets and Detected Zones + -- + -- The methods to manage the DetectedItems[].Set(s) are implemented in @{Functional.Detection#DECTECTION_BASE} and + -- the methods to manage the DetectedItems[].Zone(s) is implemented in @{Functional.Detection#DETECTION_ZONES}. + -- + -- Retrieve the DetectedItems[].Set with the method @{Functional.Detection#DETECTION_BASE.GetDetectedSet}(). A @{Core.Set#SET_UNIT} object will be returned. + -- + -- Retrieve the formed @{Zone@ZONE_UNIT}s as a result of the grouping the detected units within the DetectionZoneRange, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZones}(). + -- To understand the amount of zones created, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZoneCount}(). + -- If you want to obtain a specific zone from the DetectedZones, use the method @{Functional.Detection#DETECTION_BASE.GetDetectionZone}() with a given index. + -- + -- ## 4.4) Flare or Smoke detected units + -- + -- Use the methods @{Functional.Detection#DETECTION_ZONES.FlareDetectedUnits}() or @{Functional.Detection#DETECTION_ZONES.SmokeDetectedUnits}() to flare or smoke the detected units when a new detection has taken place. + -- + -- ## 4.5) Flare or Smoke or Bound detected zones + -- + -- Use the methods: + -- + -- * @{Functional.Detection#DETECTION_ZONES.FlareDetectedZones}() to flare in a color + -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to smoke in a color + -- * @{Functional.Detection#DETECTION_ZONES.SmokeDetectedZones}() to bound with a tire with a white flag + -- + -- the detected zones when a new detection has taken place. + -- + -- @field #DETECTION_ZONES + DETECTION_ZONES = { + ClassName = "DETECTION_ZONES", + DetectionZoneRange = nil, + } + + + --- DETECTION_ZONES constructor. + -- @param #DETECTION_ZONES self + -- @param Core.Set#SET_ZONE_RADIUS DetectionSetZone The @{Set} of ZONE_RADIUS. + -- @param DCS#Coalition.side DetectionCoalition The coalition of the detection. + -- @return #DETECTION_ZONES + function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition ) + + -- Inherits from DETECTION_BASE + local self = BASE:Inherit( self, DETECTION_BASE:New( DetectionSetZone ) ) + + self.DetectionSetZone = DetectionSetZone + self.DetectionCoalition = DetectionCoalition + + self._SmokeDetectedUnits = false + self._FlareDetectedUnits = false + self._SmokeDetectedZones = false + self._FlareDetectedZones = false + self._BoundDetectedZones = false + + return self + end + + + --- Report summary of a detected item using a given numeric index. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem. + -- @param Wrapper.Group#GROUP AttackGroup The group to get the settings for. + -- @param Core.Settings#SETTINGS Settings (Optional) Message formatting settings to use. + -- @return Core.Report#REPORT The report of the detection items. + function DETECTION_ZONES:DetectedItemReportSummary( DetectedItem, AttackGroup, Settings ) + self:F( { DetectedItem = DetectedItem } ) + + local DetectedItemID = self:GetDetectedItemID( DetectedItem ) + + if DetectedItem then + local DetectedSet = self:GetDetectedItemSet( DetectedItem ) + local ReportSummaryItem + + local DetectedZone = self:GetDetectedItemZone( DetectedItem ) + local DetectedItemCoordinate = DetectedZone:GetCoordinate() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup, Settings ) + + local ThreatLevelA2G = self:GetDetectedItemThreatLevel( DetectedItem ) + local DetectedItemsCount = DetectedSet:Count() + local DetectedItemsTypes = DetectedSet:GetTypeNames() + + local Report = REPORT:New() + Report:Add(DetectedItemID .. ", " .. DetectedItemCoordText) + 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("Detected: %s", DetectedItem.IsDetected and "yes" or "no" ) ) + + return Report + end + + return nil + end + + --- Report detailed of a detection result. + -- @param #DETECTION_ZONES self + -- @param Wrapper.Group#GROUP AttackGroup The group to generate the report for. + -- @return #string + function DETECTION_ZONES:DetectedReportDetailed( AttackGroup ) --R2.1 Fixed missing report + self:F() + + local Report = REPORT:New() + for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do + local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem + local ReportSummary = self:DetectedItemReportSummary( DetectedItem, AttackGroup ) + Report:SetTitle( "Detected areas:" ) + Report:Add( ReportSummary:Text() ) + end + + local ReportText = Report:Text() + + return ReportText + end + + + --- Calculate the optimal intercept point of the DetectedItem. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem + function DETECTION_ZONES:CalculateIntercept( DetectedItem ) + + local DetectedCoord = DetectedItem.Coordinate + local DetectedSpeed = DetectedCoord:GetVelocity() + local DetectedHeading = DetectedCoord:GetHeading() + + if self.Intercept then + local DetectedSet = DetectedItem.Set + -- todo: speed + + local TranslateDistance = DetectedSpeed * self.InterceptDelay + + local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading ) + + DetectedItem.InterceptCoord = InterceptCoord + else + DetectedItem.InterceptCoord = DetectedCoord + end + + end + + + + --- Smoke the detected units + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:SmokeDetectedUnits() + self:F2() + + self._SmokeDetectedUnits = true + return self + end + + --- Flare the detected units + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:FlareDetectedUnits() + self:F2() + + self._FlareDetectedUnits = true + return self + end + + --- Smoke the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:SmokeDetectedZones() + self:F2() + + self._SmokeDetectedZones = true + return self + end + + --- Flare the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:FlareDetectedZones() + self:F2() + + self._FlareDetectedZones = true + return self + end + + --- Bound the detected zones + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:BoundDetectedZones() + self:F2() + + self._BoundDetectedZones = true + return self + end + + --- Make text documenting the changes of the detected zone. + -- @param #DETECTION_ZONES self + -- @param #DETECTION_BASE.DetectedItem DetectedItem + -- @return #string The Changes text + function DETECTION_ZONES:GetChangeText( DetectedItem ) + self:F( DetectedItem ) + + local MT = {} + + for ChangeCode, ChangeData in pairs( DetectedItem.Changes ) do + + if ChangeCode == "AA" then + MT[#MT+1] = "Detected new area " .. ChangeData.ID .. ". The center target is a " .. ChangeData.ItemUnitType .. "." + end + + if ChangeCode == "RAU" then + MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". Removed the center target." + end + + if ChangeCode == "AAU" then + MT[#MT+1] = "Changed area " .. ChangeData.ID .. ". The new center target is a " .. ChangeData.ItemUnitType .. "." + end + + if ChangeCode == "RA" then + MT[#MT+1] = "Removed old area " .. ChangeData.ID .. ". No more targets in this area." + end + + if ChangeCode == "AU" then + local MTUT = {} + for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do + if ChangeUnitType ~= "ID" then + MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType + end + end + MT[#MT+1] = "Detected for area " .. ChangeData.ID .. " new target(s) " .. table.concat( MTUT, ", " ) .. "." + end + + if ChangeCode == "RU" then + local MTUT = {} + for ChangeUnitType, ChangeUnitCount in pairs( ChangeData ) do + if ChangeUnitType ~= "ID" then + MTUT[#MTUT+1] = ChangeUnitCount .. " of " .. ChangeUnitType + end + end + MT[#MT+1] = "Removed for area " .. ChangeData.ID .. " invisible or destroyed target(s) " .. table.concat( MTUT, ", " ) .. "." + end + + end + + return table.concat( MT, "\n" ) + + end + + + --- Make a DetectionSet table. This function will be overridden in the derived clsses. + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES self + function DETECTION_ZONES:CreateDetectionItems() + + + self:F( "Checking Detected Items for new Detected Units ..." ) + + 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. + for ZoneName, DetectionZone in pairs( self.DetectionSetZone:GetSet() ) do + + local DetectedItem = self:GetDetectedItemByKey( ZoneName ) + + if DetectedItem == nil then + DetectedItem = self:AddDetectedItemZone( "ZONE", ZoneName, nil, DetectionZone ) + end + + local DetectedItemSetUnit = self:GetDetectedItemSet( DetectedItem ) + + -- Scan the zone + DetectionZone:Scan( { Object.Category.UNIT }, { Unit.Category.GROUND_UNIT } ) + + local ZoneUnits = DetectionZone:GetScannedUnits() + for DCSUnitID, DCSUnit in pairs( ZoneUnits ) do + local UnitName = DCSUnit:getName() + local ZoneUnit = UNIT:FindByName( UnitName ) + local ZoneUnitCoalition = ZoneUnit:GetCoalition() + if ZoneUnitCoalition == self.DetectionCoalition then + if DetectedItemSetUnit:FindUnit( UnitName ) == nil and DetectedUnits:FindUnit( UnitName ) == nil then + self:F( "Adding " .. UnitName ) + DetectedItemSetUnit:AddUnit( ZoneUnit ) + DetectedUnits:AddUnit( ZoneUnit ) + 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. + + for DetectedItemID, DetectedItemData in pairs( self.DetectedItems ) do + + local DetectedItem = DetectedItemData -- #DETECTION_BASE.DetectedItem + local DetectedSet = self:GetDetectedItemSet( DetectedItem ) + local DetectedFirstUnit = DetectedSet:GetFirst() + local DetectedZone = self:GetDetectedItemZone( DetectedItem ) + + -- Set the last known coordinate to the detection item. + local DetectedZoneCoord = DetectedZone:GetCoordinate() + self:SetDetectedItemCoordinate( DetectedItem, DetectedZoneCoord, DetectedFirstUnit ) + + self:CalculateIntercept( DetectedItem ) + + -- We search for friendlies nearby. + -- If there weren't any friendlies nearby, and now there are friendlies nearby, we flag the area as "changed". + -- If there were friendlies nearby, and now there aren't any friendlies nearby, we flag the area as "changed". + -- This is for the A2G dispatcher to detect if there is a change in the tactical situation. + local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) + self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table + local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) + if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then + DetectedItem.Changed = true + end + + self:SetDetectedItemThreatLevel( DetectedItem ) -- Calculate A2G threat level + --self:NearestRecce( DetectedItem ) + + + if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then + DetectedZone:SmokeZone( SMOKECOLOR.Red, 30 ) + end + + --DetectedSet:Flush( self ) + + DetectedSet:ForEachUnit( + --- @param Wrapper.Unit#UNIT DetectedUnit + function( DetectedUnit ) + if DetectedUnit:IsAlive() then + --self:T( "Detected Set #" .. DetectedItem.ID .. ":" .. DetectedUnit:GetName() ) + if DETECTION_ZONES._FlareDetectedUnits or self._FlareDetectedUnits then + DetectedUnit:FlareGreen() + end + if DETECTION_ZONES._SmokeDetectedUnits or self._SmokeDetectedUnits then + DetectedUnit:SmokeGreen() + end + end + end + ) + if DETECTION_ZONES._FlareDetectedZones or self._FlareDetectedZones then + DetectedZone:FlareZone( SMOKECOLOR.White, 30, math.random( 0,90 ) ) + end + if DETECTION_ZONES._SmokeDetectedZones or self._SmokeDetectedZones then + DetectedZone:SmokeZone( SMOKECOLOR.White, 30 ) + end + + if DETECTION_ZONES._BoundDetectedZones or self._BoundDetectedZones then + self.CountryID = DetectedSet:GetFirst():GetCountry() + DetectedZone:BoundZone( 12, self.CountryID ) + end + end + + end + + --- @param #DETECTION_ZONES self + -- @param #string From The From State string. + -- @param #string Event The Event string. + -- @param #string To The To State string. + -- @param Detection The element on which the detection is based. + -- @param #number DetectionTimeStamp Time stamp of detection event. + function DETECTION_ZONES:onafterDetection( From, Event, To, Detection, DetectionTimeStamp ) + + self.DetectionRun = self.DetectionRun + 1 + if self.DetectionCount > 0 and self.DetectionRun == self.DetectionCount then + self:CreateDetectionItems() -- Polymorphic call to Create/Update the DetectionItems list for the DETECTION_ class grouping method. + + 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. + if DetectedItem then + self:__DetectedItem( 0.1, DetectedItem ) + end + end + self:__Detect( self.RefreshTimeInterval ) + end + end + + + --- Set IsDetected flag for the DetectedItem, which can have more units. + -- @param #DETECTION_ZONES self + -- @return #DETECTION_ZONES.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_ZONES:UpdateDetectedItemDetection( DetectedItem ) + + local IsDetected = true + + DetectedItem.IsDetected = true + + return IsDetected + end + + + +end \ No newline at end of file diff --git a/Moose Development/Moose/Functional/Escort.lua b/Moose Development/Moose/Functional/Escort.lua index 89d77425c..43686ba06 100644 --- a/Moose Development/Moose/Functional/Escort.lua +++ b/Moose Development/Moose/Functional/Escort.lua @@ -872,7 +872,7 @@ function ESCORT:_AttackTarget( DetectedItem ) EscortGroup:OptionROTPassiveDefense() EscortGroup:SetState( EscortGroup, "Escort", self ) - local DetectedSet = self.Detection:GetDetectedSet( DetectedItem ) + local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem ) local Tasks = {} @@ -895,7 +895,7 @@ function ESCORT:_AttackTarget( DetectedItem ) else - local DetectedSet = self.Detection:GetDetectedSet( DetectedItem ) + local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem ) local Tasks = {} @@ -934,7 +934,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItem ) EscortGroupAttack:OptionROEOpenFire() EscortGroupAttack:OptionROTVertical() - local DetectedSet = self.Detection:GetDetectedSet( DetectedItem ) + local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem ) local Tasks = {} @@ -956,7 +956,7 @@ function ESCORT:_AssistTarget( EscortGroupAttack, DetectedItem ) ) else - local DetectedSet = self.Detection:GetDetectedSet( DetectedItem ) + local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem ) local Tasks = {} diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index 5909ab54a..162e605fd 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -48,6 +48,7 @@ __Moose.Include( 'Scripts/Moose/Functional/Escort.lua' ) __Moose.Include( 'Scripts/Moose/Functional/MissileTrainer.lua' ) __Moose.Include( 'Scripts/Moose/Functional/ATC_Ground.lua' ) __Moose.Include( 'Scripts/Moose/Functional/Detection.lua' ) +__Moose.Include( 'Scripts/Moose/Functional/DetectionZones.lua' ) __Moose.Include( 'Scripts/Moose/Functional/Designate.lua' ) __Moose.Include( 'Scripts/Moose/Functional/RAT.lua' ) __Moose.Include( 'Scripts/Moose/Functional/Range.lua' ) From 87a44f7f7f430eba90bfb2746e7e4f3bcc2ff2fd Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 15 Mar 2019 13:08:48 +0100 Subject: [PATCH 4/9] Still need to fix that index issue. --- .../Moose/AI/AI_A2G_Dispatcher.lua | 2 ++ .../Moose/Functional/Detection.lua | 4 ++- .../Moose/Functional/DetectionZones.lua | 32 +++++++++---------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua index 0e64be634..d87424f98 100644 --- a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua @@ -3983,7 +3983,9 @@ do -- AI_A2G_DISPATCHER self:ClearDefenderTask( DefenderGroup ) end else + -- TODO: prio 1, what is this index stuff again, simplify it. if DefenderTask.Target then + self:F( { Target = DefenderTask.Target } ) 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/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index d44edf334..e07c092be 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1627,7 +1627,9 @@ do -- DETECTION_BASE -- @return #DETECTION_BASE.DetectedItem function DETECTION_BASE:GetDetectedItemByIndex( Index ) - self:F( { DetectedItemsByIndex = self.DetectedItemsByIndex } ) + self:I( { DetectedItemsByIndex = self.DetectedItemsByIndex } ) + + self:I( { self.DetectedItemsByIndex } ) local DetectedItem = self.DetectedItemsByIndex[Index] if DetectedItem then diff --git a/Moose Development/Moose/Functional/DetectionZones.lua b/Moose Development/Moose/Functional/DetectionZones.lua index 614dce0ec..0b10e2b44 100644 --- a/Moose Development/Moose/Functional/DetectionZones.lua +++ b/Moose Development/Moose/Functional/DetectionZones.lua @@ -127,22 +127,22 @@ do -- DETECTION_ZONES function DETECTION_ZONES:CalculateIntercept( DetectedItem ) local DetectedCoord = DetectedItem.Coordinate - local DetectedSpeed = DetectedCoord:GetVelocity() - local DetectedHeading = DetectedCoord:GetHeading() - - if self.Intercept then - local DetectedSet = DetectedItem.Set - -- todo: speed - - local TranslateDistance = DetectedSpeed * self.InterceptDelay - - local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading ) - - DetectedItem.InterceptCoord = InterceptCoord - else - DetectedItem.InterceptCoord = DetectedCoord - end - +-- local DetectedSpeed = DetectedCoord:GetVelocity() +-- local DetectedHeading = DetectedCoord:GetHeading() +-- +-- if self.Intercept then +-- local DetectedSet = DetectedItem.Set +-- -- todo: speed +-- +-- local TranslateDistance = DetectedSpeed * self.InterceptDelay +-- +-- local InterceptCoord = DetectedCoord:Translate( TranslateDistance, DetectedHeading ) +-- +-- DetectedItem.InterceptCoord = InterceptCoord +-- else +-- DetectedItem.InterceptCoord = DetectedCoord +-- end + DetectedItem.InterceptCoord = DetectedCoord end From fb23ac1d55fc32f74b7768a187d6b2c498a53069 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 16 Mar 2019 09:51:09 +0100 Subject: [PATCH 5/9] 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 From cff4f60923a692130acbbd66a8032e1ae32634de Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 16 Mar 2019 12:13:39 +0100 Subject: [PATCH 6/9] Improvements on reporting. --- Moose Development/Moose/Tasking/TaskInfo.lua | 57 +++++++------------ .../Moose/Tasking/Task_Capture_Dispatcher.lua | 10 +++- .../Moose/Tasking/Task_Capture_Zone.lua | 11 ++-- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Moose Development/Moose/Tasking/TaskInfo.lua b/Moose Development/Moose/Tasking/TaskInfo.lua index 95c14ee58..0e7c54885 100644 --- a/Moose Development/Moose/Tasking/TaskInfo.lua +++ b/Moose Development/Moose/Tasking/TaskInfo.lua @@ -306,65 +306,51 @@ function TASKINFO:Report( Report, Detail, ReportGroup, Task ) for Key, Data in UTILS.spairs( self.Info.Set, function( t, a, b ) return t[a].Order < t[b].Order end ) do - self:F( { Key = Key, Detail = Detail, Data = Data } ) - if Data.Detail:find( Detail ) then local Text = "" - if Key == "TaskName" then + if Key == "TaskName" then Key = nil Text = Data.Data - end - if Key == "Coordinate" then + elseif Key == "Coordinate" then local Coordinate = Data.Data -- Core.Point#COORDINATE Text = Coordinate:ToString( ReportGroup:GetUnit(1), nil, Task ) - end - if Key == "Threat" then + elseif Key == "Threat" then local DataText = Data.Data -- #string Text = DataText - end - if Key == "Counting" then + elseif Key == "Counting" then local DataText = Data.Data -- #string Text = DataText - end - if Key == "Targets" then + elseif Key == "Targets" then local DataText = Data.Data -- #string Text = DataText - end - if Key == "QFE" then + elseif Key == "QFE" then local Coordinate = Data.Data -- Core.Point#COORDINATE Text = Coordinate:ToStringPressure( ReportGroup:GetUnit(1), nil, Task ) - end - if Key == "Temperature" then + elseif Key == "Temperature" then local Coordinate = Data.Data -- Core.Point#COORDINATE Text = Coordinate:ToStringTemperature( ReportGroup:GetUnit(1), nil, Task ) - end - if Key == "Wind" then + elseif Key == "Wind" then local Coordinate = Data.Data -- Core.Point#COORDINATE Text = Coordinate:ToStringWind( ReportGroup:GetUnit(1), nil, Task ) - end - if Key == "Cargo" then + elseif Key == "Cargo" then + local DataText = Data.Data -- #string + Text = DataText + elseif Key == "Friendlies" then + local DataText = Data.Data -- #string + Text = DataText + elseif Key == "Players" then + local DataText = Data.Data -- #string + Text = DataText + else local DataText = Data.Data -- #string Text = DataText end - if Key == "Friendlies" then - local DataText = Data.Data -- #string - Text = DataText - end - if Key == "Players" then - local DataText = Data.Data -- #string - Text = DataText - end - if Line < math.floor( Data.Order / 10 ) then if Line == 0 then - if Text ~= "" then - Report:AddIndent( LineReport:Text( ", " ), "-" ) - end + Report:AddIndent( LineReport:Text( ", " ), "-" ) else - if Text ~= "" then - Report:AddIndent( LineReport:Text( ", " ) ) - end + Report:AddIndent( LineReport:Text( ", " ) ) end LineReport = REPORT:New() Line = math.floor( Data.Order / 10 ) @@ -373,8 +359,9 @@ function TASKINFO:Report( Report, Detail, ReportGroup, Task ) if Text ~= "" then LineReport:Add( ( Key and ( Key .. ":" ) or "" ) .. Text ) end + end end + Report:AddIndent( LineReport:Text( ", " ) ) - end diff --git a/Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua index d37ad7d5d..c38ed065f 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Dispatcher.lua @@ -246,6 +246,7 @@ do -- TASK_CAPTURE_DISPATCHER -- Here we need to check if the pilot is still existing. -- Task = self:RemoveTask( TaskIndex ) end + end -- Now that all obsolete tasks are removed, loop through the Zone tasks. @@ -257,25 +258,32 @@ do -- TASK_CAPTURE_DISPATCHER CaptureZone.Task.TaskPrefix = CaptureZone.TaskPrefix -- We keep the TaskPrefix for further reference! Mission:AddTask( CaptureZone.Task ) TaskReport:Add( TaskName ) + CaptureZone.Task:UpdateTaskInfo() + function CaptureZone.Task.OnEnterSuccess( Task, From, Event, To ) self:Success( Task ) + CaptureZone.Task:UpdateTaskInfo() end function CaptureZone.Task.OnEnterCancelled( Task, From, Event, To ) self:Cancelled( Task ) + CaptureZone.Task:UpdateTaskInfo() end - + function CaptureZone.Task.OnEnterFailed( Task, From, Event, To ) self:Failed( Task ) + CaptureZone.Task:UpdateTaskInfo() end function CaptureZone.Task.OnEnterAborted( Task, From, Event, To ) self:Aborted( Task ) + CaptureZone.Task:UpdateTaskInfo() end -- Now broadcast the onafterCargoPickedUp event to the Task Cargo Dispatcher. function CaptureZone.Task.OnAfterCaptured( Task, From, Event, To, TaskUnit ) self:Captured( Task, Task.TaskPrefix, TaskUnit ) + CaptureZone.Task:UpdateTaskInfo() end end diff --git a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua index 8a56784ea..589a35c3c 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua @@ -219,12 +219,13 @@ do -- TASK_CAPTURE_ZONE --- Instantiates a new TASK_CAPTURE_ZONE. -- @param #TASK_CAPTURE_ZONE self - function TASK_CAPTURE_ZONE:UpdateTaskInfo() - + function TASK_CAPTURE_ZONE:UpdateTaskInfo( DetectedItem ) + local ZoneCoordinate = self.ZoneGoal:GetZone():GetCoordinate() - self.TaskInfo:AddCoordinate( ZoneCoordinate, 0, "SOD" ) - self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD" ) - self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD" ) + self.TaskInfo:AddTaskName( 0, "MSOD", true ) + self.TaskInfo:AddCoordinate( ZoneCoordinate, 1, "SOD", true ) + self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD", true ) + self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD", true ) end From 837361e899e28628c34b8a470d0db0c028538ea4 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 16 Mar 2019 12:57:14 +0100 Subject: [PATCH 7/9] Updates --- Moose Development/Moose/Tasking/Task_Capture_Zone.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua index 589a35c3c..79d4817df 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua @@ -226,6 +226,8 @@ do -- TASK_CAPTURE_ZONE self.TaskInfo:AddCoordinate( ZoneCoordinate, 1, "SOD", true ) self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD", true ) self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD", true ) + --local ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() + --self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 10, "MOD", true ) end From 0ea5c7fa48bc0e9ca17274d8bec45c30f5a0cfcd Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 17 Mar 2019 07:33:28 +0100 Subject: [PATCH 8/9] Updated bug in Detection and other classes. Now only alive units are considered when broadcasting a message to a SET_GROUP. Made DESIGNATE crash in certain cases. --- Moose Development/Moose/Functional/Designate.lua | 2 +- Moose Development/Moose/Functional/Detection.lua | 10 +++++----- Moose Development/Moose/Wrapper/Positionable.lua | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Functional/Designate.lua b/Moose Development/Moose/Functional/Designate.lua index 7d6f09d26..a11aa21b8 100644 --- a/Moose Development/Moose/Functional/Designate.lua +++ b/Moose Development/Moose/Functional/Designate.lua @@ -1393,7 +1393,7 @@ do -- DESIGNATE self:F( "Smoking ..." ) local RecceGroup = self.RecceSet:FindNearestGroupFromPointVec2(SmokeUnit:GetPointVec2()) - local RecceUnit = RecceGroup:GetUnit( 1 ) + local RecceUnit = RecceGroup:GetUnit( 1 ) -- Wrapper.Unit#UNIT if RecceUnit then diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 6bebb8c5d..76b3d0274 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1524,12 +1524,12 @@ do -- DETECTION_BASE local DetectedItem = {} self.DetectedItemCount = self.DetectedItemCount + 1 self.DetectedItemMax = self.DetectedItemMax + 1 - + + + DetectedItemKey = DetectedItemKey or self.DetectedItemMax self.DetectedItems[DetectedItemKey] = DetectedItem - - local DetectedItemIndex = DetectedItemKey or self.DetectedItemMax - self.DetectedItemsByIndex[DetectedItemIndex] = DetectedItem - DetectedItem.Index = DetectedItemIndex + self.DetectedItemsByIndex[DetectedItemKey] = DetectedItem + DetectedItem.Index = DetectedItemKey DetectedItem.Set = Set or SET_UNIT:New():FilterDeads():FilterCrashes() DetectedItem.ItemID = ItemPrefix .. "." .. self.DetectedItemMax diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 70d7a3c15..09d17a92c 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -1101,7 +1101,7 @@ function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Nam local DCSObject = self:GetDCSObject() if DCSObject then if DCSObject:isExist() then - MessageSetGroup:ForEachGroup( + MessageSetGroup:ForEachGroupAlive( function( MessageGroup ) self:GetMessage( Message, Duration, Name ):ToGroup( MessageGroup ) end From ece7fc3ea9dfe5a10e634e308975a4604ba1e8bd Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 17 Mar 2019 08:20:42 +0100 Subject: [PATCH 9/9] Threat level report for TASK_CAPTURE_ZONE --- .../Moose/AI/AI_A2G_Dispatcher.lua | 20 ++++++++++++++++--- Moose Development/Moose/Core/Zone.lua | 14 +++++++++++++ .../Moose/Tasking/DetectionManager.lua | 2 ++ Moose Development/Moose/Tasking/TaskInfo.lua | 2 +- .../Moose/Tasking/Task_Capture_Zone.lua | 7 ++++--- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua index fad800e7d..2a568b220 100644 --- a/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2G_Dispatcher.lua @@ -3467,6 +3467,20 @@ do -- AI_A2G_DISPATCHER end end + function Fsm:onafterPatrolRoute( Defender, From, Event, To, AttackSetUnit ) + self:F({"Defender PatrolRoute", Defender:GetName()}) + self:GetParent(self).onafterPatrolRoute( self, Defender, From, Event, To, AttackSetUnit ) + + local DefenderName = Defender:GetName() + local Dispatcher = self:GetDispatcher() -- #AI_A2G_DISPATCHER + local Squadron = Dispatcher:GetSquadronFromDefender( Defender ) + if Squadron then + Dispatcher:MessageToPlayers( "Squadron " .. Squadron.Name .. ", " .. DefenderName .. " returning." ) + end + + Dispatcher:ClearDefenderTaskTarget( Defender ) + end + function Fsm:onafterRTB( Defender, From, Event, To ) self:F({"Defender RTB", Defender:GetName()}) self:GetParent(self).onafterRTB( self, Defender, From, Event, To ) @@ -3564,15 +3578,15 @@ do -- AI_A2G_DISPATCHER end end - function Fsm:OnAfterEngageRoute( Defender, From, Event, To, AttackSetUnit ) + function Fsm:onafterEngageRoute( Defender, From, Event, To, AttackSetUnit ) self:F({"Engage Route", Defender:GetName()}) - --self:GetParent(self).onafterBirth( self, Defender, From, Event, To ) + self:GetParent(self).onafterEngageRoute( self, Defender, From, Event, To, AttackSetUnit ) local DefenderName = Defender:GetName() local Dispatcher = Fsm:GetDispatcher() -- #AI_A2G_DISPATCHER local Squadron = Dispatcher:GetSquadronFromDefender( Defender ) - if FirstUnit then + if Squadron then local FirstUnit = AttackSetUnit:GetFirst() local Coordinate = FirstUnit:GetCoordinate() -- Core.Point#COORDINATE diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 70fb83ca3..8c6d420e6 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -704,6 +704,20 @@ function ZONE_RADIUS:GetScannedUnits() end +function ZONE_RADIUS:GetScannedSetUnit() + + local SetUnit = SET_UNIT:New() + + if self.ScanData then + for ObjectID, UnitObject in pairs( self.ScanData.Units ) do + SetUnit:AddUnit( UNIT:FindByName(UnitObject:getName() ) ) + end + end + + return SetUnit +end + + function ZONE_RADIUS:CountScannedCoalitions() local Count = 0 diff --git a/Moose Development/Moose/Tasking/DetectionManager.lua b/Moose Development/Moose/Tasking/DetectionManager.lua index 04eab84a8..b641ac1c3 100644 --- a/Moose Development/Moose/Tasking/DetectionManager.lua +++ b/Moose Development/Moose/Tasking/DetectionManager.lua @@ -239,6 +239,8 @@ do -- DETECTION MANAGER -- @param #string Message The message to be sent. -- @return #DETECTION_MANGER self function DETECTION_MANAGER:MessageToPlayers( Message ) + + self:F( { Message = Message } ) if self.CC then self.CC:MessageToCoalition( Message ) diff --git a/Moose Development/Moose/Tasking/TaskInfo.lua b/Moose Development/Moose/Tasking/TaskInfo.lua index 0e7c54885..8f2d6231a 100644 --- a/Moose Development/Moose/Tasking/TaskInfo.lua +++ b/Moose Development/Moose/Tasking/TaskInfo.lua @@ -162,7 +162,7 @@ end -- @param #boolean Keep (optional) If true, this would indicate that the planned taskinfo would be persistent when the task is completed, so that the original planned task info is used at the completed reports. -- @return #TASKINFO self function TASKINFO:AddThreat( ThreatText, ThreatLevel, Order, Detail, Keep ) - self:AddInfo( "Threat", ThreatText .. " [" .. string.rep( "■", ThreatLevel ) .. string.rep( "□", 10 - ThreatLevel ) .. "]", Order, Detail, Keep ) + self:AddInfo( "Threat", " [" .. string.rep( "■", ThreatLevel ) .. string.rep( "□", 10 - ThreatLevel ) .. "]:" .. ThreatText, Order, Detail, Keep ) return self end diff --git a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua index 79d4817df..aa41cd7de 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua @@ -47,7 +47,7 @@ do -- TASK_ZONE_GOAL -- @param Tasking.Mission#MISSION Mission -- @param Core.Set#SET_GROUP SetGroup The set of groups for which the Task can be assigned. -- @param #string TaskName The name of the Task. - -- @param Core.ZoneGoal#ZONE_GOAL ZoneGoal + -- @param Core.ZoneGoalCoalition#ZONE_GOAL_COALITION ZoneGoal -- @return #TASK_ZONE_GOAL self function TASK_ZONE_GOAL:New( Mission, SetGroup, TaskName, ZoneGoal, TaskType, TaskBriefing ) local self = BASE:Inherit( self, TASK:New( Mission, SetGroup, TaskName, TaskType, TaskBriefing ) ) -- #TASK_ZONE_GOAL @@ -226,8 +226,9 @@ do -- TASK_CAPTURE_ZONE self.TaskInfo:AddCoordinate( ZoneCoordinate, 1, "SOD", true ) self.TaskInfo:AddText( "Zone Name", self.ZoneGoal:GetZoneName(), 10, "MOD", true ) self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD", true ) - --local ThreatLevel, ThreatText = self.TargetSetUnit:CalculateThreatLevelA2G() - --self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 10, "MOD", true ) + local SetUnit = self.ZoneGoal.Zone:GetScannedSetUnit() + local ThreatLevel, ThreatText = SetUnit:CalculateThreatLevelA2G() + self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 20, "MOD", true ) end