From 8bb3d5a76020b4a0dfaa145ae0291eeb1b91eeb1 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Mon, 28 Aug 2017 11:33:37 +0200 Subject: [PATCH] Fixed CAP not counting correctly * CAP now counts correctly per squadron. The specified amount of CAP will work now. * CAP now schedules at different start times, and have different repeat times. More random. --- .../Moose/AI/AI_A2A_Dispatcher.lua | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index c5880e09d..8d62b61c8 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -1348,11 +1348,12 @@ do -- AI_A2A_DISPATCHER --- -- @param #AI_A2A_DISPATCHER self - function AI_A2A_DISPATCHER:SetDefenderTask( Defender, Type, Fsm, Target ) + function AI_A2A_DISPATCHER:SetDefenderTask( SquadronName, Defender, Type, Fsm, Target ) self.DefenderTasks[Defender] = self.DefenderTasks[Defender] or {} self.DefenderTasks[Defender].Type = Type self.DefenderTasks[Defender].Fsm = Fsm + self.DefenderTasks[Defender].SquadronName = SquadronName if Target then self:SetDefenderTaskTarget( Defender, Target ) @@ -1580,14 +1581,15 @@ do -- AI_A2A_DISPATCHER local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER local ScheduleID = Cap.ScheduleID local Variance = ( Cap.HighInterval - Cap.LowInterval ) / 2 - local Median = Cap.LowInterval + Variance - local Randomization = Variance / Median + local Repeat = Cap.LowInterval + Variance + local Randomization = Variance / Repeat local Start = math.random( 1, Cap.HighInterval ) if ScheduleID then Scheduler:Stop( ScheduleID ) end + Cap.ScheduleID = Scheduler:Schedule( self, self.SchedulerCAP, { SquadronName }, Start, Repeat, Randomization ) else error( "This squadron does not exist:" .. SquadronName ) end @@ -2471,12 +2473,14 @@ do -- AI_A2A_DISPATCHER local DefenderSquadron = self.DefenderSquadrons[SquadronName] if DefenderSquadron then for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do - if DefenderTask.Type == "CAP" then - if AIGroup:IsAlive() then - -- Check if the CAP is patrolling or engaging. If not, this is not a valid CAP, even if it is alive! - -- The CAP could be damaged, lost control, or out of fuel! - if DefenderTask.Fsm:Is( "Patrolling" ) or DefenderTask.Fsm:Is( "Engaging" ) or DefenderTask.Fsm:Is( "Refuelling" )then - CapCount = CapCount + 1 + if DefenderTask.SquadronName == SquadronName then + if DefenderTask.Type == "CAP" then + if AIGroup:IsAlive() then + -- Check if the CAP is patrolling or engaging. If not, this is not a valid CAP, even if it is alive! + -- The CAP could be damaged, lost control, or out of fuel! + if DefenderTask.Fsm:Is( "Patrolling" ) or DefenderTask.Fsm:Is( "Engaging" ) or DefenderTask.Fsm:Is( "Refuelling" )then + CapCount = CapCount + 1 + end end end end @@ -2494,12 +2498,17 @@ do -- AI_A2A_DISPATCHER -- First, count the active AIGroups Units, targetting the DetectedSet local AIUnitCount = 0 + self:E( "Counting Defenders Engaged for Attacker:" ) + local DetectedSet = Target.Set + DetectedSet:Flush() + local DefenderTasks = self:GetDefenderTasks() for AIGroup, DefenderTask in pairs( DefenderTasks ) do local AIGroup = AIGroup -- Wrapper.Group#GROUP local DefenderTask = self:GetDefenderTaskTarget( AIGroup ) if DefenderTask and DefenderTask.Index == Target.Index then AIUnitCount = AIUnitCount + AIGroup:GetSize() + self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() ) end end @@ -2587,7 +2596,7 @@ do -- AI_A2A_DISPATCHER Fsm:Start() Fsm:__Patrol( 2 ) - self:SetDefenderTask( DefenderCAP, "CAP", Fsm ) + self:SetDefenderTask( SquadronName, DefenderCAP, "CAP", Fsm ) end end end @@ -2742,7 +2751,7 @@ do -- AI_A2A_DISPATCHER Fsm:__Engage( 2, DetectedItem.Set ) -- Engage on the TargetSetUnit - self:SetDefenderTask( DefenderGCI, "GCI", Fsm, DetectedItem ) + self:SetDefenderTask( ClosestDefenderSquadronName, DefenderGCI, "GCI", Fsm, DetectedItem ) function Fsm:onafterRTB( Defender, From, Event, To ) @@ -2875,14 +2884,14 @@ do -- AI_A2A_DISPATCHER self:ClearDefenderTask( AIGroup ) else if DefenderTask.Target then - local Target = Detection:GetDetectedItem( DefenderTask.Target.Index ) - if not Target then + local AttackerItem = Detection:GetDetectedItem( DefenderTask.Target.Index ) + if not AttackerItem then self:F( { "Removing obsolete Target:", DefenderTask.Target.Index } ) self:ClearDefenderTaskTarget( AIGroup ) - else if DefenderTask.Target.Set then - if DefenderTask.Target.Set:Count() == 0 then + local AttackerCount = DefenderTask.Target.Set:Count() + if AttackerCount == 0 then self:F( { "All Targets destroyed in Target, removing:", DefenderTask.Target.Index } ) self:ClearDefenderTaskTarget( AIGroup ) end @@ -2968,7 +2977,7 @@ do -- AI_A2A_DISPATCHER end Report:Add( string.format( "\n - %d Tasks", TaskCount ) ) - self:T( Report:Text( "\n" ) ) + self:E( Report:Text( "\n" ) ) trigger.action.outText( Report:Text( "\n" ), 25 ) end