mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Respect Gci radius
* Corrected the calculation to the distance to the airbase, when the intercept calculation is used. Now the intercept point is not anymore interfering with the gci radius validation and gci radius is now correctly respected and validated.
This commit is contained in:
parent
e6c765c441
commit
2830bcb867
@ -1369,14 +1369,14 @@ do -- AI_A2A_DISPATCHER
|
||||
---
|
||||
-- @param #AI_A2A_DISPATCHER self
|
||||
-- @param Wrapper.Group#GROUP AIGroup
|
||||
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( Defender, Target )
|
||||
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( Defender, AttackerDetection )
|
||||
|
||||
local Message = "(" .. self.DefenderTasks[Defender].Type .. ") "
|
||||
Message = Message .. Defender:GetName()
|
||||
Message = Message .. ( Target and ( " target " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
|
||||
self:F( { Target = Message } )
|
||||
if Target then
|
||||
self.DefenderTasks[Defender].Target = Target
|
||||
Message = Message .. ( AttackerDetection and ( " target " .. AttackerDetection.Index .. " [" .. AttackerDetection.Set:Count() .. "]" ) ) or ""
|
||||
self:F( { AttackerDetection = Message } )
|
||||
if AttackerDetection then
|
||||
self.DefenderTasks[Defender].Target = AttackerDetection
|
||||
end
|
||||
return self
|
||||
end
|
||||
@ -2510,20 +2510,20 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
---
|
||||
-- @param #AI_A2A_DISPATCHER self
|
||||
function AI_A2A_DISPATCHER:CountDefendersEngaged( Target )
|
||||
function AI_A2A_DISPATCHER:CountDefendersEngaged( AttackerDetection )
|
||||
|
||||
-- First, count the active AIGroups Units, targetting the DetectedSet
|
||||
local AIUnitCount = 0
|
||||
|
||||
self:E( "Counting Defenders Engaged for Attacker:" )
|
||||
local DetectedSet = Target.Set
|
||||
local DetectedSet = AttackerDetection.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
|
||||
if DefenderTask and DefenderTask.Index == AttackerDetection.Index then
|
||||
AIUnitCount = AIUnitCount + AIGroup:GetSize()
|
||||
self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() )
|
||||
end
|
||||
@ -2534,18 +2534,18 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
---
|
||||
-- @param #AI_A2A_DISPATCHER self
|
||||
function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( DetectedItem, DefenderCount )
|
||||
function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( AttackerDetection, DefenderCount )
|
||||
|
||||
local Friendlies = nil
|
||||
|
||||
local DetectedSet = DetectedItem.Set
|
||||
local DetectedCount = DetectedSet:Count()
|
||||
local AttackerSet = AttackerDetection.Set
|
||||
local AttackerCount = AttackerSet:Count()
|
||||
|
||||
local AIFriendlies = self:GetAIFriendliesNearBy( DetectedItem )
|
||||
local DefenderFriendlies = self:GetAIFriendliesNearBy( AttackerDetection )
|
||||
|
||||
for FriendlyDistance, AIFriendly in UTILS.spairs( AIFriendlies or {} ) do
|
||||
for FriendlyDistance, AIFriendly in UTILS.spairs( DefenderFriendlies or {} ) do
|
||||
-- We only allow to ENGAGE targets as long as the Units on both sides are balanced.
|
||||
if DetectedCount > DefenderCount then
|
||||
if AttackerCount > DefenderCount then
|
||||
local Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP
|
||||
if Friendly and Friendly:IsAlive() then
|
||||
-- Ok, so we have a friendly near the potential target.
|
||||
@ -2554,7 +2554,7 @@ do -- AI_A2A_DISPATCHER
|
||||
if DefenderTask then
|
||||
-- The Task should be CAP or GCI
|
||||
if DefenderTask.Type == "CAP" or DefenderTask.Type == "GCI" then
|
||||
-- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the TargetSet
|
||||
-- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the AttackerSet
|
||||
if DefenderTask.Target == nil then
|
||||
if DefenderTask.Fsm:Is( "Returning" )
|
||||
or DefenderTask.Fsm:Is( "Patrolling" ) then
|
||||
@ -2650,16 +2650,16 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
---
|
||||
-- @param #AI_A2A_DISPATCHER self
|
||||
function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, Target, Defenders )
|
||||
function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, AttackerDetection, Defenders )
|
||||
|
||||
if Defenders then
|
||||
|
||||
for DefenderID, Defender in pairs( Defenders ) do
|
||||
|
||||
local Fsm = self:GetDefenderTaskFsm( Defender )
|
||||
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
||||
Fsm:__Engage( 1, AttackerDetection.Set ) -- Engage on the TargetSetUnit
|
||||
|
||||
self:SetDefenderTaskTarget( Defender, Target )
|
||||
self:SetDefenderTaskTarget( Defender, AttackerDetection )
|
||||
|
||||
end
|
||||
end
|
||||
@ -2667,32 +2667,35 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
---
|
||||
-- @param #AI_A2A_DISPATCHER self
|
||||
function AI_A2A_DISPATCHER:onafterGCI( From, Event, To, DetectedItem, DefendersMissing, Friendlies )
|
||||
function AI_A2A_DISPATCHER:onafterGCI( From, Event, To, AttackerDetection, DefendersMissing, DefenderFriendlies )
|
||||
|
||||
self:F( { From, Event, To, DetectedItem.Index, DefendersMissing, Friendlies } )
|
||||
self:F( { From, Event, To, AttackerDetection.Index, DefendersMissing, DefenderFriendlies } )
|
||||
|
||||
local AttackerSet = DetectedItem.Set
|
||||
local AttackerSet = AttackerDetection.Set
|
||||
local AttackerUnit = AttackerSet:GetFirst()
|
||||
|
||||
if AttackerUnit and AttackerUnit:IsAlive() then
|
||||
local AttackerCount = AttackerSet:Count()
|
||||
local DefendersCount = 0
|
||||
local DefenderCount = 0
|
||||
|
||||
for DefenderID, AIGroup in pairs( Friendlies or {} ) do
|
||||
for DefenderID, DefenderGroup in pairs( DefenderFriendlies or {} ) do
|
||||
|
||||
local Fsm = self:GetDefenderTaskFsm( AIGroup )
|
||||
local Fsm = self:GetDefenderTaskFsm( DefenderGroup )
|
||||
Fsm:__Engage( 1, AttackerSet ) -- Engage on the TargetSetUnit
|
||||
|
||||
self:SetDefenderTaskTarget( AIGroup, DetectedItem )
|
||||
self:SetDefenderTaskTarget( DefenderGroup, AttackerDetection )
|
||||
|
||||
DefendersCount = DefendersCount + AIGroup:GetSize()
|
||||
DefenderCount = DefenderCount + DefenderGroup:GetSize()
|
||||
end
|
||||
|
||||
DefendersCount = DefendersMissing
|
||||
DefenderCount = DefendersMissing
|
||||
|
||||
local ClosestDistance = 0
|
||||
local ClosestDefenderSquadronName = nil
|
||||
|
||||
local BreakLoop = false
|
||||
|
||||
while( DefendersCount > 0 and not BreakLoop ) do
|
||||
while( DefenderCount > 0 and not BreakLoop ) do
|
||||
self:F( { DefenderSquadrons = self.DefenderSquadrons } )
|
||||
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
|
||||
self:F( { GCI = DefenderSquadron.Gci } )
|
||||
@ -2700,18 +2703,19 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
self:F( { DefenderSquadron } )
|
||||
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
|
||||
--local TargetCoord = AttackerSet:GetFirst():GetCoordinate()
|
||||
local InterceptCoord = DetectedItem.InterceptCoord
|
||||
local AttackerCoord = AttackerUnit:GetCoordinate()
|
||||
local InterceptCoord = AttackerDetection.InterceptCoord
|
||||
self:F({InterceptCoord = InterceptCoord})
|
||||
if InterceptCoord then
|
||||
local Distance = SpawnCoord:Get2DDistance( InterceptCoord )
|
||||
self:F( { Distance = Distance, InterceptCoord = InterceptCoord } )
|
||||
local InterceptDistance = SpawnCoord:Get2DDistance( InterceptCoord )
|
||||
local AirbaseDistance = SpawnCoord:Get2DDistance( AttackerCoord )
|
||||
self:F( { InterceptDistance = InterceptDistance, AirbaseDistance = AirbaseDistance, InterceptCoord = InterceptCoord } )
|
||||
|
||||
if ClosestDistance == 0 or Distance < ClosestDistance then
|
||||
if ClosestDistance == 0 or InterceptDistance < ClosestDistance then
|
||||
|
||||
-- Only intercept if the distance to target is smaller or equal to the GciRadius limit.
|
||||
if Distance <= self.GciRadius then
|
||||
ClosestDistance = Distance
|
||||
if AirbaseDistance <= self.GciRadius then
|
||||
ClosestDistance = InterceptDistance
|
||||
ClosestDefenderSquadronName = SquadronName
|
||||
end
|
||||
end
|
||||
@ -2731,11 +2735,11 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
local DefenderOverhead = DefenderSquadron.Overhead or self.DefenderDefault.Overhead
|
||||
local DefenderGrouping = DefenderSquadron.Grouping or self.DefenderDefault.Grouping
|
||||
local DefendersNeeded = math.ceil( DefendersCount * DefenderOverhead )
|
||||
local DefendersNeeded = math.ceil( DefenderCount * DefenderOverhead )
|
||||
|
||||
self:F( { DefaultOverhead = self.DefenderDefault.Overhead, Overhead = DefenderOverhead } )
|
||||
self:F( { DefaultGrouping = self.DefenderDefault.Grouping, Grouping = DefenderGrouping } )
|
||||
self:F( { DefendersCount = DefendersCount, DefendersNeeded = DefendersNeeded } )
|
||||
self:F( { DefendersCount = DefenderCount, DefendersNeeded = DefendersNeeded } )
|
||||
|
||||
while ( DefendersNeeded > 0 ) do
|
||||
|
||||
@ -2757,7 +2761,7 @@ do -- AI_A2A_DISPATCHER
|
||||
|
||||
if DefenderGCI then
|
||||
|
||||
DefendersCount = DefendersCount - DefenderGrouping
|
||||
DefenderCount = DefenderCount - DefenderGrouping
|
||||
|
||||
local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.EngageMaxSpeed )
|
||||
Fsm:SetDispatcher( self )
|
||||
@ -2766,10 +2770,10 @@ do -- AI_A2A_DISPATCHER
|
||||
Fsm:SetDamageThreshold( self.DefenderDefault.DamageThreshold )
|
||||
Fsm:SetDisengageRadius( self.DisengageRadius )
|
||||
Fsm:Start()
|
||||
Fsm:__Engage( 2, DetectedItem.Set ) -- Engage on the TargetSetUnit
|
||||
Fsm:__Engage( 2, AttackerDetection.Set ) -- Engage on the TargetSetUnit
|
||||
|
||||
|
||||
self:SetDefenderTask( ClosestDefenderSquadronName, DefenderGCI, "GCI", Fsm, DetectedItem )
|
||||
self:SetDefenderTask( ClosestDefenderSquadronName, DefenderGCI, "GCI", Fsm, AttackerDetection )
|
||||
|
||||
|
||||
function Fsm:onafterRTB( Defender, From, Event, To )
|
||||
@ -2825,6 +2829,7 @@ do -- AI_A2A_DISPATCHER
|
||||
break
|
||||
end
|
||||
end -- if DefenderSquadron then
|
||||
end -- if AttackerUnit
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user