Fixes issue with SetDetectionLimit

Optimized the detection intervals + fixed bugs with player detection.
This commit is contained in:
FlightControl 2019-08-11 09:46:25 +02:00
commit 596b3ddb4a
5 changed files with 55 additions and 14 deletions

View File

@ -4056,6 +4056,7 @@ do -- AI_A2G_DISPATCHER
local TaskReport = REPORT:New() local TaskReport = REPORT:New()
local DefenseTotal = 0
for DefenderGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do for DefenderGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
local DefenderGroup = DefenderGroup -- Wrapper.Group#GROUP local DefenderGroup = DefenderGroup -- Wrapper.Group#GROUP
@ -4089,12 +4090,15 @@ do -- AI_A2G_DISPATCHER
end end
end end
-- for DefenderGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
-- DefenseTotal = DefenseTotal + 1
-- end
local Report = REPORT:New( "\nTactical Overview" ) local Report = REPORT:New( "\nTactical Overview" )
local DefenderGroupCount = 0 local DefenderGroupCount = 0
local DefendersTotal = 0 local DefendersTotal = 0
local DefenseTotal = 0
-- Now that all obsolete tasks are removed, loop through the detected targets. -- Now that all obsolete tasks are removed, loop through the detected targets.
--for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do --for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do
@ -4149,7 +4153,10 @@ do -- AI_A2G_DISPATCHER
end end
end end
if EngageCoordinate and ( ( self.DefenseLimit and DefenseTotal < self.DefenseLimit ) or true ) then -- There needs to be an EngageCoordinate.
-- If self.DefenseLimit is set (thus limit the amount of defenses to one zone), then only start a new defense if the maximum has not been reached.
-- If self.DefenseLimit has not been set, there is an unlimited amount of zones to be defended.
if ( EngageCoordinate and ( self.DefenseLimit and DefenseTotal < self.DefenseLimit ) or not self.DefenseLimit ) then
do do
local DefendersTotal, DefendersEngaged, DefendersMissing, Friendlies = self:Evaluate_SEAD( DetectedItem ) -- Returns a SET_UNIT with the SEAD targets to be engaged... local DefendersTotal, DefendersEngaged, DefendersMissing, Friendlies = self:Evaluate_SEAD( DetectedItem ) -- Returns a SET_UNIT with the SEAD targets to be engaged...
if DefendersMissing > 0 then if DefendersMissing > 0 then

View File

@ -1819,7 +1819,7 @@ do -- COORDINATE
--- Returns if a Coordinate is in a certain Radius of this Coordinate in 2D plane using the X and Z axis. --- Returns if a Coordinate is in a certain Radius of this Coordinate in 2D plane using the X and Z axis.
-- @param #COORDINATE self -- @param #COORDINATE self
-- @param #COORDINATE ToCoordinate The coordinate that will be tested if it is in the radius of this coordinate. -- @param #COORDINATE Coordinate The coordinate that will be tested if it is in the radius of this coordinate.
-- @param #number Radius The radius of the circle on the 2D plane around this coordinate. -- @param #number Radius The radius of the circle on the 2D plane around this coordinate.
-- @return #boolean true if in the Radius. -- @return #boolean true if in the Radius.
function COORDINATE:IsInRadius( Coordinate, Radius ) function COORDINATE:IsInRadius( Coordinate, Radius )

View File

@ -562,18 +562,38 @@ do -- DETECTION_BASE
end end
-- Count alive(!) groups only. Solves issue #1173 https://github.com/FlightControl-Master/MOOSE/issues/1173 -- Count alive(!) groups only. Solves issue #1173 https://github.com/FlightControl-Master/MOOSE/issues/1173
self.DetectionCount = self.DetectionSet:CountAlive() self.DetectionCount = self:CountAliveRecce()
self.DetectionSet:ForEachGroupAlive( local DetectionInterval = self.DetectionCount / ( self.RefreshTimeInterval - 1 )
self:ForEachAliveRecce(
function( DetectionGroup ) function( DetectionGroup )
self:__Detection( DetectDelay, DetectionGroup, DetectionTimeStamp ) -- Process each detection asynchronously. self:__Detection( DetectDelay, DetectionGroup, DetectionTimeStamp ) -- Process each detection asynchronously.
DetectDelay = DetectDelay + 1 DetectDelay = DetectDelay + DetectionInterval
end end
) )
self:__Detect( -self.RefreshTimeInterval ) self:__Detect( -self.RefreshTimeInterval )
end end
--- @param #DETECTION_BASE self
-- @param #number The amount of alive recce.
function DETECTION_BASE:CountAliveRecce()
return self.DetectionSet:CountAlive()
end
--- @param #DETECTION_BASE self
function DETECTION_BASE:ForEachAliveRecce( IteratorFunction, ... )
self:F2( arg )
self.DetectionSet:ForEachGroupAlive( IteratorFunction, arg )
return self
end
--- @param #DETECTION_BASE self --- @param #DETECTION_BASE self
-- @param #string From The From State string. -- @param #string From The From State string.
@ -1412,14 +1432,14 @@ do -- DETECTION_BASE
world.searchObjects( Object.Category.UNIT, SphereSearch, FindNearByFriendlies, TargetData ) world.searchObjects( Object.Category.UNIT, SphereSearch, FindNearByFriendlies, TargetData )
DetectedItem.PlayersNearBy = nil DetectedItem.PlayersNearBy = nil
local DetectionZone = ZONE_UNIT:New( "DetectionPlayers", DetectedUnit, self.FriendliesRange )
_DATABASE:ForEachPlayer( _DATABASE:ForEachPlayer(
--- @param Wrapper.Unit#UNIT PlayerUnit --- @param Wrapper.Unit#UNIT PlayerUnit
function( PlayerUnitName ) function( PlayerUnitName )
local PlayerUnit = UNIT:FindByName( PlayerUnitName ) local PlayerUnit = UNIT:FindByName( PlayerUnitName )
if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then if PlayerUnit and PlayerUnit:GetCoordinate():IsInRadius( DetectedUnitCoord, self.FriendliesRange ) then
--if PlayerUnit and PlayerUnit:IsInZone(DetectionZone) then
local PlayerUnitCategory = PlayerUnit:GetDesc().category local PlayerUnitCategory = PlayerUnit:GetDesc().category

View File

@ -44,15 +44,15 @@ do -- DETECTION_ZONES
--- DETECTION_ZONES constructor. --- DETECTION_ZONES constructor.
-- @param #DETECTION_ZONES self -- @param #DETECTION_ZONES self
-- @param Core.Set#SET_ZONE_RADIUS DetectionSetZone The @{Set} of ZONE_RADIUS. -- @param Core.Set#SET_ZONE DetectionSetZone The @{Set} of ZONE_RADIUS.
-- @param DCS#Coalition.side DetectionCoalition The coalition of the detection. -- @param DCS#Coalition.side DetectionCoalition The coalition of the detection.
-- @return #DETECTION_ZONES -- @return #DETECTION_ZONES
function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition ) function DETECTION_ZONES:New( DetectionSetZone, DetectionCoalition )
-- Inherits from DETECTION_BASE -- Inherits from DETECTION_BASE
local self = BASE:Inherit( self, DETECTION_BASE:New( DetectionSetZone ) ) local self = BASE:Inherit( self, DETECTION_BASE:New( DetectionSetZone ) ) -- #DETECTION_ZONES
self.DetectionSetZone = DetectionSetZone self.DetectionSetZone = DetectionSetZone -- Core.Set#SET_ZONE
self.DetectionCoalition = DetectionCoalition self.DetectionCoalition = DetectionCoalition
self._SmokeDetectedUnits = false self._SmokeDetectedUnits = false
@ -64,6 +64,22 @@ do -- DETECTION_ZONES
return self return self
end end
--- @param #DETECTION_ZONES self
-- @param #number The amount of alive recce.
function DETECTION_ZONES:CountAliveRecce()
return self.DetectionSetZone:Count()
end
--- @param #DETECTION_ZONES self
function DETECTION_ZONES:ForEachAliveRecce( IteratorFunction, ... )
self:F2( arg )
self.DetectionSetZone:ForEachZone( IteratorFunction, arg )
return self
end
--- Report summary of a detected item using a given numeric index. --- Report summary of a detected item using a given numeric index.
-- @param #DETECTION_ZONES self -- @param #DETECTION_ZONES self
@ -396,7 +412,5 @@ do -- DETECTION_ZONES
return IsDetected return IsDetected
end end
end end

View File

@ -63,7 +63,7 @@ POSITIONABLE.__.Cargo = {}
-- @param #string PositionableName The POSITIONABLE name -- @param #string PositionableName The POSITIONABLE name
-- @return #POSITIONABLE self -- @return #POSITIONABLE self
function POSITIONABLE:New( PositionableName ) function POSITIONABLE:New( PositionableName )
local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) ) local self = BASE:Inherit( self, IDENTIFIABLE:New( PositionableName ) ) -- #POSITIONABLE
self.PositionableName = PositionableName self.PositionableName = PositionableName
return self return self