From 03ba031153bd9c5ea5822390e1a24bc2e4cc2bc9 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Mon, 12 Mar 2018 19:58:59 +0100 Subject: [PATCH] To ensure that A2G tasking does not get confused between BAI and CAS and back to BAI --- .../Moose/Functional/Detection.lua | 57 +++++++------------ .../Moose/Tasking/Task_A2G_Dispatcher.lua | 15 +++-- 2 files changed, 29 insertions(+), 43 deletions(-) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index d696bf3d9..3364da210 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1173,34 +1173,26 @@ do -- DETECTION_BASE -- @usage -- -- Only allow Ships and Vehicles to be part of the friendly team. -- Detection:SetFriendlyCategories( { Unit.Category.SHIP, Unit.Category.GROUND_UNIT } ) - function DETECTION_BASE:FilterFriendlyCategories( FriendlyCategories ) - - self.FriendlyCategories = self.FriendlyCategories or {} - if type( FriendlyCategories ) ~= "table" then - FriendlyCategories = { FriendlyCategories } - end - for ID, FriendlyCategory in pairs( FriendlyCategories ) do - self:F( { FriendlyCategory = FriendlyCategory } ) - self.FriendlyCategories[FriendlyCategory] = FriendlyCategory - end - return self - end --- Returns if there are friendlies nearby the FAC units ... -- @param #DETECTION_BASE self + -- @param DetectedItem + -- @param Dcs.DCSUnit#Unit.Category Category The category of the unit. -- @return #boolean true if there are friendlies nearby - function DETECTION_BASE:IsFriendliesNearBy( DetectedItem ) + function DETECTION_BASE:IsFriendliesNearBy( DetectedItem, Category ) self:F( { "FriendliesNearBy Test", DetectedItem.FriendliesNearBy } ) - return DetectedItem.FriendliesNearBy ~= nil or false + return ( DetectedItem.FriendliesNearBy and DetectedItem.FriendliesNearBy[Category] ~= nil ) or false end --- Returns friendly units nearby the FAC units ... -- @param #DETECTION_BASE self + -- @param DetectedItem + -- @param Dcs.DCSUnit#Unit.Category Category The category of the unit. -- @return #map<#string,Wrapper.Unit#UNIT> The map of Friendly UNITs. - function DETECTION_BASE:GetFriendliesNearBy( DetectedItem ) + function DETECTION_BASE:GetFriendliesNearBy( DetectedItem, Category ) - return DetectedItem.FriendliesNearBy + return DetectedItem.FriendliesNearBy[Category] end --- Returns if there are friendlies nearby the intercept ... @@ -1307,28 +1299,18 @@ do -- DETECTION_BASE end end - local FoundUnitOfOtherCategory = false - - if FoundUnitOfOtherCategory == false then - -- Now we check if the found unit is one of the allowed friendly categories. - for ID, FriendlyCategory in pairs( self.FriendlyCategories or {} ) do - self:F( { "Friendly Category:", FriendlyCategory = FriendlyCategory, FoundUnitCategory = FoundUnitCategory } ) - if FriendlyCategory ~= FoundUnitCategory then - FoundUnitOfOtherCategory = true - break - end - end - end - self:F( { "Friendlies near Target:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } ) - if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false and FoundUnitOfOtherCategory == false then + if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then local FriendlyUnit = UNIT:Find( FoundDCSUnit ) local FriendlyUnitName = FriendlyUnit:GetName() local FriendlyUnitCategory = FriendlyUnit:GetDesc().category - + + -- Friendlies are sorted per unit category. DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} - DetectedItem.FriendliesNearBy[FriendlyUnitName] = FriendlyUnit + DetectedItem.FriendliesNearBy[FoundUnitCategory] = DetectedItem.FriendliesNearBy[FoundUnitCategory] or {} + DetectedItem.FriendliesNearBy[FoundUnitCategory][FriendlyUnitName] = FriendlyUnit + local Distance = DetectedUnitCoord:Get2DDistance( FriendlyUnit:GetCoordinate() ) DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} DetectedItem.FriendliesDistance[Distance] = FriendlyUnit @@ -1355,14 +1337,15 @@ do -- DETECTION_BASE if ( not self.FriendliesCategory ) or ( self.FriendliesCategory and ( self.FriendliesCategory == PlayerUnitCategory ) ) then - DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} local PlayerUnitName = PlayerUnit:GetName() DetectedItem.PlayersNearBy = DetectedItem.PlayersNearBy or {} DetectedItem.PlayersNearBy[PlayerUnitName] = PlayerUnit + -- Friendlies are sorted per unit category. DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} - DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit + DetectedItem.FriendliesNearBy[PlayerUnitCategory] = DetectedItem.FriendliesNearBy[PlayerUnitCategory] or {} + DetectedItem.FriendliesNearBy[PlayerUnitCategory][PlayerUnitName] = PlayerUnit local Distance = DetectedUnitCoord:Get2DDistance( PlayerUnit:GetCoordinate() ) DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} @@ -2793,10 +2776,10 @@ do -- DETECTION_AREAS -- 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 OldFriendliesNearby = self:IsFriendliesNearBy( DetectedItem ) + local OldFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) self:ReportFriendliesNearBy( { DetectedItem = DetectedItem, ReportSetGroup = self.DetectionSetGroup } ) -- Fill the Friendlies table - local NewFriendliesNearby = self:IsFriendliesNearBy( DetectedItem ) - if OldFriendliesNearby ~= NewFriendliesNearby then + local NewFriendliesNearbyGround = self:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) + if OldFriendliesNearbyGround ~= NewFriendliesNearbyGround then DetectedItem.Changed = true end diff --git a/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua index 5200c7733..49da08fa0 100644 --- a/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2G_Dispatcher.lua @@ -58,8 +58,7 @@ do -- TASK_A2G_DISPATCHER self.Detection = Detection self.Mission = Mission - self.Detection:FilterCategories( { Unit.Category.GROUND_UNIT, Unit.Category.SHIP } ) - self.Detection:FilterFriendlyCategories( { Unit.Category.GROUND_UNIT } ) + self.Detection:FilterCategories( { Unit.Category.GROUND_UNIT } ) self:AddTransition( "Started", "Assign", "Started" ) @@ -119,9 +118,11 @@ do -- TASK_A2G_DISPATCHER local DetectedZone = DetectedItem.Zone - -- Determine if the set has radar targets. If it does, construct a SEAD task. + -- Determine if the set has ground units. + -- There should be ground unit friendlies nearby. Airborne units are valid friendlies types. + -- And there shouldn't be any radar. local GroundUnitCount = DetectedSet:HasGroundUnits() - local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem ) + local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) -- Are there friendlies nearby of type GROUND_UNIT? local RadarCount = DetectedSet:HasSEAD() if RadarCount == 0 and GroundUnitCount > 0 and FriendliesNearBy == true then @@ -149,9 +150,11 @@ do -- TASK_A2G_DISPATCHER local DetectedZone = DetectedItem.Zone - -- Determine if the set has radar targets. If it does, construct a SEAD task. + -- Determine if the set has ground units. + -- There shouldn't be any ground unit friendlies nearby. + -- And there shouldn't be any radar. local GroundUnitCount = DetectedSet:HasGroundUnits() - local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem ) + local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem, Unit.Category.GROUND_UNIT ) -- Are there friendlies nearby of type GROUND_UNIT? local RadarCount = DetectedSet:HasSEAD() if RadarCount == 0 and GroundUnitCount > 0 and FriendliesNearBy == false then