diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 1b811cf74..9f8f5c805 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1140,11 +1140,31 @@ do -- DETECTION_BASE end - do -- NearBy calculations + do -- Friendly calculations + + --- This will allow during friendly search any recce or detection unit to be also considered as a friendly. + -- By default, recce aren't considered friendly, because that would mean that a recce would be also an attacking friendly, + -- and this is wrong. + -- However, in a CAP situation, when the CAP is part of an EWR network, the CAP is also an attacker. + -- This, this method allows to register for a detection the CAP unit name prefixes to be considered CAP. + -- @param #DETECTION_BASE self + -- @param #string FriendlyPrefixes A string or a list of prefixes. + -- @return #DETECTION_BASE + function DETECTION_BASE:SetFriendlyPrefixes( FriendlyPrefixes ) + + self.FriendlyPrefixes = FriendlyPrefixes or {} + if type( FriendlyPrefixes ) ~= "table" then + FriendlyPrefixes = { FriendlyPrefixes } + end + for PrefixID, Prefix in pairs( FriendlyPrefixes ) do + self.FriendlyPrefixes[Prefix] = Prefix + end + return self + end --- Returns if there are friendlies nearby the FAC units ... -- @param #DETECTION_BASE self - -- @return #boolean trhe if there are friendlies nearby + -- @return #boolean true if there are friendlies nearby function DETECTION_BASE:IsFriendliesNearBy( DetectedItem ) return DetectedItem.FriendliesNearBy ~= nil or false @@ -1249,9 +1269,26 @@ do -- DETECTION_BASE local FoundUnitName = FoundDCSUnit:getName() local FoundUnitGroupName = FoundDCSUnit:getGroup():getName() local EnemyUnitName = DetectedUnit:GetName() + local FoundUnitInReportSetGroup = ReportSetGroup:FindGroup( FoundUnitGroupName ) ~= nil + self:T( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } ) - --self:F( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } ) +-- if FoundUnitInReportSetGroup == true then +-- -- If the recce was part of the friendlies found, then check if the recce is part of the allowed friendly unit prefixes. +-- for Prefix, PrefixData in pairs( self.FriendlyPrefixes or {} ) do +-- --self:T3( { "FriendlyPrefix:", Prefix } ) +-- -- In case a match is found (so a recce unit name is part of the friendly prefixes), then report that recce to be part of the friendlies. +-- -- This is important if CAP planes (so planes using their own radar) to be scanning for targets as part of the EWR network. +-- -- But CAP planes are also attackers, so they need to be considered friendlies too! +-- -- I chose to use prefixes because it is the fastest way to check. +-- if string.find( FoundUnitName, Prefix:gsub ("-", "%%-"), 1 ) then +-- FoundUnitInReportSetGroup = false +-- break +-- end +-- end +-- end + + self:F( { "Friendlies search:", FoundUnitName, FoundUnitCoalition, EnemyUnitName, EnemyCoalition, FoundUnitInReportSetGroup } ) if FoundUnitCoalition ~= EnemyCoalition and FoundUnitInReportSetGroup == false then local FriendlyUnit = UNIT:Find( FoundDCSUnit ) @@ -1259,13 +1296,14 @@ do -- DETECTION_BASE local FriendlyUnitCategory = FriendlyUnit:GetDesc().category self:T( { FriendlyUnitCategory = FriendlyUnitCategory, FriendliesCategory = self.FriendliesCategory } ) - if ( not self.FriendliesCategory ) or ( self.FriendliesCategory and ( self.FriendliesCategory == FriendlyUnitCategory ) ) then + --if ( not self.FriendliesCategory ) or ( self.FriendliesCategory and ( self.FriendliesCategory == FriendlyUnitCategory ) ) then DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} DetectedItem.FriendliesNearBy[FriendlyUnitName] = FriendlyUnit local Distance = DetectedUnitCoord:Get2DDistance( FriendlyUnit:GetCoordinate() ) DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} DetectedItem.FriendliesDistance[Distance] = FriendlyUnit - end + self:T( { FriendlyUnitName = FriendlyUnitName, Distance = Distance } ) + --end return true end