mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
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.
This commit is contained in:
@@ -1348,11 +1348,12 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @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] = self.DefenderTasks[Defender] or {}
|
||||||
self.DefenderTasks[Defender].Type = Type
|
self.DefenderTasks[Defender].Type = Type
|
||||||
self.DefenderTasks[Defender].Fsm = Fsm
|
self.DefenderTasks[Defender].Fsm = Fsm
|
||||||
|
self.DefenderTasks[Defender].SquadronName = SquadronName
|
||||||
|
|
||||||
if Target then
|
if Target then
|
||||||
self:SetDefenderTaskTarget( Defender, Target )
|
self:SetDefenderTaskTarget( Defender, Target )
|
||||||
@@ -1580,14 +1581,15 @@ do -- AI_A2A_DISPATCHER
|
|||||||
local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER
|
local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER
|
||||||
local ScheduleID = Cap.ScheduleID
|
local ScheduleID = Cap.ScheduleID
|
||||||
local Variance = ( Cap.HighInterval - Cap.LowInterval ) / 2
|
local Variance = ( Cap.HighInterval - Cap.LowInterval ) / 2
|
||||||
local Median = Cap.LowInterval + Variance
|
local Repeat = Cap.LowInterval + Variance
|
||||||
local Randomization = Variance / Median
|
local Randomization = Variance / Repeat
|
||||||
local Start = math.random( 1, Cap.HighInterval )
|
local Start = math.random( 1, Cap.HighInterval )
|
||||||
|
|
||||||
if ScheduleID then
|
if ScheduleID then
|
||||||
Scheduler:Stop( ScheduleID )
|
Scheduler:Stop( ScheduleID )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Cap.ScheduleID = Scheduler:Schedule( self, self.SchedulerCAP, { SquadronName }, Start, Repeat, Randomization )
|
||||||
else
|
else
|
||||||
error( "This squadron does not exist:" .. SquadronName )
|
error( "This squadron does not exist:" .. SquadronName )
|
||||||
end
|
end
|
||||||
@@ -2471,12 +2473,14 @@ do -- AI_A2A_DISPATCHER
|
|||||||
local DefenderSquadron = self.DefenderSquadrons[SquadronName]
|
local DefenderSquadron = self.DefenderSquadrons[SquadronName]
|
||||||
if DefenderSquadron then
|
if DefenderSquadron then
|
||||||
for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
||||||
if DefenderTask.Type == "CAP" then
|
if DefenderTask.SquadronName == SquadronName then
|
||||||
if AIGroup:IsAlive() then
|
if DefenderTask.Type == "CAP" then
|
||||||
-- Check if the CAP is patrolling or engaging. If not, this is not a valid CAP, even if it is alive!
|
if AIGroup:IsAlive() then
|
||||||
-- The CAP could be damaged, lost control, or out of fuel!
|
-- Check if the CAP is patrolling or engaging. If not, this is not a valid CAP, even if it is alive!
|
||||||
if DefenderTask.Fsm:Is( "Patrolling" ) or DefenderTask.Fsm:Is( "Engaging" ) or DefenderTask.Fsm:Is( "Refuelling" )then
|
-- The CAP could be damaged, lost control, or out of fuel!
|
||||||
CapCount = CapCount + 1
|
if DefenderTask.Fsm:Is( "Patrolling" ) or DefenderTask.Fsm:Is( "Engaging" ) or DefenderTask.Fsm:Is( "Refuelling" )then
|
||||||
|
CapCount = CapCount + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2494,12 +2498,17 @@ do -- AI_A2A_DISPATCHER
|
|||||||
-- First, count the active AIGroups Units, targetting the DetectedSet
|
-- First, count the active AIGroups Units, targetting the DetectedSet
|
||||||
local AIUnitCount = 0
|
local AIUnitCount = 0
|
||||||
|
|
||||||
|
self:E( "Counting Defenders Engaged for Attacker:" )
|
||||||
|
local DetectedSet = Target.Set
|
||||||
|
DetectedSet:Flush()
|
||||||
|
|
||||||
local DefenderTasks = self:GetDefenderTasks()
|
local DefenderTasks = self:GetDefenderTasks()
|
||||||
for AIGroup, DefenderTask in pairs( DefenderTasks ) do
|
for AIGroup, DefenderTask in pairs( DefenderTasks ) do
|
||||||
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
||||||
local DefenderTask = self:GetDefenderTaskTarget( AIGroup )
|
local DefenderTask = self:GetDefenderTaskTarget( AIGroup )
|
||||||
if DefenderTask and DefenderTask.Index == Target.Index then
|
if DefenderTask and DefenderTask.Index == Target.Index then
|
||||||
AIUnitCount = AIUnitCount + AIGroup:GetSize()
|
AIUnitCount = AIUnitCount + AIGroup:GetSize()
|
||||||
|
self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2587,7 +2596,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
Fsm:Start()
|
Fsm:Start()
|
||||||
Fsm:__Patrol( 2 )
|
Fsm:__Patrol( 2 )
|
||||||
|
|
||||||
self:SetDefenderTask( DefenderCAP, "CAP", Fsm )
|
self:SetDefenderTask( SquadronName, DefenderCAP, "CAP", Fsm )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2742,7 +2751,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
Fsm:__Engage( 2, DetectedItem.Set ) -- Engage on the TargetSetUnit
|
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 )
|
function Fsm:onafterRTB( Defender, From, Event, To )
|
||||||
@@ -2875,14 +2884,14 @@ do -- AI_A2A_DISPATCHER
|
|||||||
self:ClearDefenderTask( AIGroup )
|
self:ClearDefenderTask( AIGroup )
|
||||||
else
|
else
|
||||||
if DefenderTask.Target then
|
if DefenderTask.Target then
|
||||||
local Target = Detection:GetDetectedItem( DefenderTask.Target.Index )
|
local AttackerItem = Detection:GetDetectedItem( DefenderTask.Target.Index )
|
||||||
if not Target then
|
if not AttackerItem then
|
||||||
self:F( { "Removing obsolete Target:", DefenderTask.Target.Index } )
|
self:F( { "Removing obsolete Target:", DefenderTask.Target.Index } )
|
||||||
self:ClearDefenderTaskTarget( AIGroup )
|
self:ClearDefenderTaskTarget( AIGroup )
|
||||||
|
|
||||||
else
|
else
|
||||||
if DefenderTask.Target.Set then
|
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:F( { "All Targets destroyed in Target, removing:", DefenderTask.Target.Index } )
|
||||||
self:ClearDefenderTaskTarget( AIGroup )
|
self:ClearDefenderTaskTarget( AIGroup )
|
||||||
end
|
end
|
||||||
@@ -2968,7 +2977,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
Report:Add( string.format( "\n - %d Tasks", TaskCount ) )
|
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 )
|
trigger.action.outText( Report:Text( "\n" ), 25 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user