mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Progress
This commit is contained in:
parent
37a176e3ae
commit
2fb83c89af
@ -12,6 +12,8 @@
|
|||||||
--
|
--
|
||||||
-- @module AI_A2A
|
-- @module AI_A2A
|
||||||
|
|
||||||
|
BASE:TraceClass("AI_A2A")
|
||||||
|
|
||||||
|
|
||||||
--- @type AI_A2A
|
--- @type AI_A2A
|
||||||
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
-- @extends Core.Fsm#FSM_CONTROLLABLE
|
||||||
@ -72,6 +74,32 @@ function AI_A2A:New( AIGroup )
|
|||||||
self:ManageDamage( 1 )
|
self:ManageDamage( 1 )
|
||||||
|
|
||||||
self:SetStartState( "Stopped" )
|
self:SetStartState( "Stopped" )
|
||||||
|
|
||||||
|
self:AddTransition( "*", "Start", "Started" )
|
||||||
|
|
||||||
|
--- Start Handler OnBefore for AI_A2A
|
||||||
|
-- @function [parent=#AI_A2A] OnBeforeStart
|
||||||
|
-- @param #AI_A2A self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
-- @return #boolean
|
||||||
|
|
||||||
|
--- Start Handler OnAfter for AI_A2A
|
||||||
|
-- @function [parent=#AI_A2A] OnAfterStart
|
||||||
|
-- @param #AI_A2A self
|
||||||
|
-- @param #string From
|
||||||
|
-- @param #string Event
|
||||||
|
-- @param #string To
|
||||||
|
|
||||||
|
--- Start Trigger for AI_A2A
|
||||||
|
-- @function [parent=#AI_A2A] Start
|
||||||
|
-- @param #AI_A2A self
|
||||||
|
|
||||||
|
--- Start Asynchronous Trigger for AI_A2A
|
||||||
|
-- @function [parent=#AI_A2A] __Start
|
||||||
|
-- @param #AI_A2A self
|
||||||
|
-- @param #number Delay
|
||||||
|
|
||||||
self:AddTransition( "*", "Stop", "Stopped" )
|
self:AddTransition( "*", "Stop", "Stopped" )
|
||||||
|
|
||||||
@ -287,7 +315,7 @@ end
|
|||||||
function AI_A2A:onafterStart( Controllable, From, Event, To )
|
function AI_A2A:onafterStart( Controllable, From, Event, To )
|
||||||
self:F2()
|
self:F2()
|
||||||
|
|
||||||
self:__Status( 60 ) -- Check status status every 30 seconds.
|
self:__Status( 10 ) -- Check status status every 30 seconds.
|
||||||
|
|
||||||
self:HandleEvent( EVENTS.PilotDead, self.OnPilotDead )
|
self:HandleEvent( EVENTS.PilotDead, self.OnPilotDead )
|
||||||
self:HandleEvent( EVENTS.Crash, self.OnCrash )
|
self:HandleEvent( EVENTS.Crash, self.OnCrash )
|
||||||
@ -307,13 +335,14 @@ end
|
|||||||
|
|
||||||
--- @param #AI_A2A self
|
--- @param #AI_A2A self
|
||||||
function AI_A2A:onafterStatus()
|
function AI_A2A:onafterStatus()
|
||||||
self:F2()
|
self:F()
|
||||||
|
|
||||||
if self.Controllable and self.Controllable:IsAlive() then
|
if self.Controllable and self.Controllable:IsAlive() then
|
||||||
|
|
||||||
local RTB = false
|
local RTB = false
|
||||||
|
|
||||||
local Fuel = self.Controllable:GetUnit(1):GetFuel()
|
local Fuel = self.Controllable:GetUnit(1):GetFuel()
|
||||||
|
self:F({Fuel=Fuel})
|
||||||
if Fuel < self.PatrolFuelTresholdPercentage then
|
if Fuel < self.PatrolFuelTresholdPercentage then
|
||||||
self:E( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
|
self:E( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" )
|
||||||
local OldAIControllable = self.Controllable
|
local OldAIControllable = self.Controllable
|
||||||
@ -329,7 +358,9 @@ function AI_A2A:onafterStatus()
|
|||||||
|
|
||||||
-- TODO: Check GROUP damage function.
|
-- TODO: Check GROUP damage function.
|
||||||
local Damage = self.Controllable:GetLife()
|
local Damage = self.Controllable:GetLife()
|
||||||
if Damage <= self.PatrolDamageTreshold then
|
local InitialLife = self.Controllable:GetLife0()
|
||||||
|
self:F( { Damage = Damage, InitialLife = InitialLife, DamageTreshold = self.PatrolDamageTreshold } )
|
||||||
|
if ( Damage / InitialLife ) < self.PatrolDamageTreshold then
|
||||||
self:E( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
|
self:E( self.Controllable:GetName() .. " is damaged:" .. Damage .. ", RTB!" )
|
||||||
RTB = true
|
RTB = true
|
||||||
end
|
end
|
||||||
@ -337,7 +368,7 @@ function AI_A2A:onafterStatus()
|
|||||||
if RTB == true then
|
if RTB == true then
|
||||||
self:RTB()
|
self:RTB()
|
||||||
else
|
else
|
||||||
self:__Status( 60 ) -- Execute the Patrol event after 30 seconds.
|
self:__Status( 10 ) -- Execute the Patrol event after 30 seconds.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
--
|
--
|
||||||
-- @module AI_A2A_Cap
|
-- @module AI_A2A_Cap
|
||||||
|
|
||||||
|
BASE:TraceClass("AI_A2A_CAP")
|
||||||
|
|
||||||
--- @type AI_A2A_CAP
|
--- @type AI_A2A_CAP
|
||||||
-- @extends AI.AI_A2A_Patrol#AI_A2A_PATROL
|
-- @extends AI.AI_A2A_Patrol#AI_A2A_PATROL
|
||||||
@ -117,8 +118,6 @@ AI_A2A_CAP = {
|
|||||||
ClassName = "AI_A2A_CAP",
|
ClassName = "AI_A2A_CAP",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Creates a new AI_A2A_CAP object
|
--- Creates a new AI_A2A_CAP object
|
||||||
-- @param #AI_A2A_CAP self
|
-- @param #AI_A2A_CAP self
|
||||||
-- @param Wrapper.Group#GROUP AIGroup
|
-- @param Wrapper.Group#GROUP AIGroup
|
||||||
@ -343,11 +342,10 @@ end
|
|||||||
|
|
||||||
-- todo: need to fix this global function
|
-- todo: need to fix this global function
|
||||||
|
|
||||||
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
|
--- @param Wrapper.Group#GROUP AIGroup
|
||||||
function _NewEngageCapRoute( AIControllable )
|
function AI_A2A_CAP.AttackRoute( AIGroup )
|
||||||
|
|
||||||
AIControllable:T( "NewEngageRoute" )
|
local EngageZone = AIGroup:GetState( AIGroup, "EngageZone" ) -- AI.AI_Cap#AI_A2A_CAP
|
||||||
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_CAP
|
|
||||||
EngageZone:__Engage( 1 )
|
EngageZone:__Engage( 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -384,85 +382,71 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
|
|||||||
self:F( { AIGroup, From, Event, To, AttackSetUnit} )
|
self:F( { AIGroup, From, Event, To, AttackSetUnit} )
|
||||||
|
|
||||||
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
||||||
|
|
||||||
|
local FirstAttackUnit = self.AttackSetUnit:GetFirst()
|
||||||
|
|
||||||
|
if FirstAttackUnit then
|
||||||
|
|
||||||
|
if AIGroup:IsAlive() then
|
||||||
|
|
||||||
if AIGroup:IsAlive() then
|
local EngageRoute = {}
|
||||||
|
|
||||||
local EngageRoute = {}
|
--- Calculate the target route point.
|
||||||
|
local CurrentCoord = AIGroup:GetCoordinate()
|
||||||
--- Calculate the current route point.
|
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
|
||||||
local CurrentVec2 = self.Controllable:GetVec2()
|
local ToTargetSpeed = math.random( self.MinSpeed, self.MaxSpeed )
|
||||||
|
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||||
--TODO: Create GetAltitude function for GROUP, and delete GetUnit(1).
|
|
||||||
local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
|
--- Create a route point of type air.
|
||||||
local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
|
local ToPatrolRoutePoint = CurrentCoord:Translate( 5000, ToInterceptAngle ):RoutePointAir(
|
||||||
local ToEngageZoneSpeed = self.PatrolMaxSpeed
|
|
||||||
local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
|
|
||||||
self.PatrolAltType,
|
self.PatrolAltType,
|
||||||
POINT_VEC3.RoutePointType.TurningPoint,
|
POINT_VEC3.RoutePointType.TurningPoint,
|
||||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||||
ToEngageZoneSpeed,
|
ToTargetSpeed,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
EngageRoute[#EngageRoute+1] = CurrentRoutePoint
|
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
|
||||||
|
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
|
||||||
|
|
||||||
--- Find a random 2D point in PatrolZone.
|
|
||||||
local ToTargetVec2 = self.PatrolZone:GetRandomVec2()
|
|
||||||
self:T2( ToTargetVec2 )
|
|
||||||
|
|
||||||
--- Define Speed and Altitude.
|
|
||||||
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
|
|
||||||
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
|
|
||||||
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
|
|
||||||
|
|
||||||
--- Obtain a 3D @{Point} from the 2D point + altitude.
|
|
||||||
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
|
|
||||||
|
|
||||||
--- Create a route point of type air.
|
|
||||||
local ToPatrolRoutePoint = ToTargetPointVec3:RoutePointAir(
|
|
||||||
self.PatrolAltType,
|
|
||||||
POINT_VEC3.RoutePointType.TurningPoint,
|
|
||||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
|
||||||
ToTargetSpeed,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
|
|
||||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
|
||||||
|
|
||||||
AIGroup:OptionROEOpenFire()
|
|
||||||
AIGroup:OptionROTPassiveDefense()
|
|
||||||
|
|
||||||
local AttackTasks = {}
|
|
||||||
|
|
||||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
|
||||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
|
||||||
self:T( { AttackUnit, AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
|
||||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
|
||||||
AttackTasks[#AttackTasks+1] = AIGroup:TaskAttackUnit( AttackUnit )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
|
|
||||||
self.Controllable:WayPointInitialize( EngageRoute )
|
|
||||||
|
|
||||||
|
|
||||||
if #AttackTasks == 0 then
|
|
||||||
self:E("No targets found -> Going back to Patrolling")
|
|
||||||
self:__Abort( 1 )
|
|
||||||
self:__Route( 1 )
|
|
||||||
else
|
|
||||||
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
|
|
||||||
|
|
||||||
--- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ...
|
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||||
self.Controllable:SetState( self.Controllable, "EngageZone", self )
|
|
||||||
|
AIGroup:OptionROEOpenFire()
|
||||||
|
AIGroup:OptionROTPassiveDefense()
|
||||||
|
|
||||||
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageCapRoute" )
|
local AttackTasks = {}
|
||||||
|
|
||||||
|
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||||
|
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||||
|
self:T( { "Attacking Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||||
|
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||||
|
AttackTasks[#AttackTasks+1] = AIGroup:TaskAttackUnit( AttackUnit )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
|
||||||
|
self.Controllable:WayPointInitialize( EngageRoute )
|
||||||
|
|
||||||
|
|
||||||
|
if #AttackTasks == 0 then
|
||||||
|
self:E("No targets found -> Going back to Patrolling")
|
||||||
|
self:__Abort( 1 )
|
||||||
|
self:__Route( 1 )
|
||||||
|
else
|
||||||
|
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_CAP.AttackRoute" )
|
||||||
|
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
|
||||||
|
|
||||||
|
--- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ...
|
||||||
|
AIGroup:SetState( AIGroup, "EngageZone", self )
|
||||||
|
end
|
||||||
|
|
||||||
|
--- NOW ROUTE THE GROUP!
|
||||||
|
AIGroup:WayPointExecute( 1, 2 )
|
||||||
end
|
end
|
||||||
|
else
|
||||||
--- NOW ROUTE THE GROUP!
|
self:E("No targets found -> Going back to Patrolling")
|
||||||
self.Controllable:WayPointExecute( 1, 2 )
|
self:__Abort( 1 )
|
||||||
|
self:__Route( 1 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -56,11 +56,12 @@ do -- AI_A2A_DISPATCHER
|
|||||||
-- Inherits from DETECTION_MANAGER
|
-- Inherits from DETECTION_MANAGER
|
||||||
local self = BASE:Inherit( self, DETECTION_MANAGER:New( nil, Detection ) ) -- #AI_A2A_DISPATCHER
|
local self = BASE:Inherit( self, DETECTION_MANAGER:New( nil, Detection ) ) -- #AI_A2A_DISPATCHER
|
||||||
|
|
||||||
self.Detection = Detection
|
self.Detection = Detection -- Functional.Detection#DETECTION_AREAS
|
||||||
|
|
||||||
-- This table models the DefenderSquadron templates.
|
-- This table models the DefenderSquadron templates.
|
||||||
self.DefenderSquadrons = self.DefenderSquadrons or {} -- The Defender Squadrons.
|
self.DefenderSquadrons = {} -- The Defender Squadrons.
|
||||||
self.DefenderTasks = self.DefenderTasks or {} -- The Defenders Tasks.
|
self.DefenderSpawns = {}
|
||||||
|
self.DefenderTasks = {} -- The Defenders Tasks.
|
||||||
|
|
||||||
-- TODO: Check detection through radar.
|
-- TODO: Check detection through radar.
|
||||||
self.Detection:FilterCategories( Unit.Category.AIRPLANE, Unit.Category.HELICOPTER )
|
self.Detection:FilterCategories( Unit.Category.AIRPLANE, Unit.Category.HELICOPTER )
|
||||||
@ -158,46 +159,36 @@ do -- AI_A2A_DISPATCHER
|
|||||||
-- @param #number Delay
|
-- @param #number Delay
|
||||||
|
|
||||||
|
|
||||||
|
-- Subscribe to the CRASH event so that when planes are shot
|
||||||
|
-- by a Unit from the dispatcher, they will be removed from the detection...
|
||||||
|
-- This will avoid the detection to still "know" the shot unit until the next detection.
|
||||||
|
-- Otherwise, a new intercept or engage may happen for an already shot plane!
|
||||||
|
|
||||||
|
self:HandleEvent( EVENTS.Crash )
|
||||||
|
self:HandleEvent( EVENTS.Dead )
|
||||||
|
|
||||||
self:__Start( 5 )
|
self:__Start( 5 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
|
||||||
function AI_A2A_DISPATCHER:onafterCAP( From, Event, To, SquadronName )
|
|
||||||
|
|
||||||
self:F({SquadronName = SquadronName})
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
|
||||||
self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {}
|
|
||||||
|
|
||||||
local DefenderSquadron = self.DefenderSquadrons[SquadronName]
|
|
||||||
local Cap = DefenderSquadron.Cap
|
|
||||||
|
|
||||||
if Cap then
|
|
||||||
|
|
||||||
if self:CanCAP( SquadronName ) then
|
|
||||||
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
|
|
||||||
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
|
|
||||||
self:F( { AIGroup = AIGroup:GetName() } )
|
|
||||||
|
|
||||||
if AIGroup then
|
|
||||||
|
|
||||||
local Fsm = AI_A2A_CAP:New( AIGroup, Cap.Zone, Cap.FloorAltitude, Cap.CeilingAltitude, Cap.MinSpeed, Cap.MaxSpeed, Cap.AltType )
|
|
||||||
Fsm:SetDispatcher( self )
|
|
||||||
Fsm:__Patrol( 1 )
|
|
||||||
|
|
||||||
self:SetDefenderTask( AIGroup, "CAP", Fsm )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
error( "This squadron does not exist:" .. SquadronName )
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
--- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @param Core.Event#EVENTDATA EventData
|
||||||
|
function AI_A2A_DISPATCHER:OnEventCrash( EventData )
|
||||||
|
self.Detection:ForgetDetectedUnit( EventData.IniUnitName )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Calculates which AI friendlies are nearby the area
|
||||||
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @param DetectedItem
|
||||||
|
-- @return #number, Core.CommandCenter#REPORT
|
||||||
|
function AI_A2A_DISPATCHER:GetAIFriendliesNearBy( DetectedItem )
|
||||||
|
|
||||||
|
local FriendliesNearBy = self.Detection:GetFriendliesNearBy( DetectedItem )
|
||||||
|
|
||||||
|
return FriendliesNearBy
|
||||||
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
@ -226,6 +217,15 @@ do -- AI_A2A_DISPATCHER
|
|||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
function AI_A2A_DISPATCHER:ClearDefenderTask( AIGroup )
|
function AI_A2A_DISPATCHER:ClearDefenderTask( AIGroup )
|
||||||
|
if AIGroup:IsAlive() then
|
||||||
|
local Target = self.DefenderTasks[AIGroup].Target
|
||||||
|
local Message = "Clearing (" .. self.DefenderTasks[AIGroup].Type .. ") "
|
||||||
|
Message = Message .. AIGroup:GetName()
|
||||||
|
if Target then
|
||||||
|
Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
|
||||||
|
end
|
||||||
|
self:F( { Target = Message } )
|
||||||
|
end
|
||||||
self.DefenderTasks[AIGroup] = nil
|
self.DefenderTasks[AIGroup] = nil
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -237,8 +237,10 @@ do -- AI_A2A_DISPATCHER
|
|||||||
self.DefenderTasks[AIGroup] = self.DefenderTasks[AIGroup] or {}
|
self.DefenderTasks[AIGroup] = self.DefenderTasks[AIGroup] or {}
|
||||||
self.DefenderTasks[AIGroup].Type = Type
|
self.DefenderTasks[AIGroup].Type = Type
|
||||||
self.DefenderTasks[AIGroup].Fsm = Fsm
|
self.DefenderTasks[AIGroup].Fsm = Fsm
|
||||||
|
|
||||||
self:SetDefenderTaskTarget( AIGroup, Target )
|
if Target then
|
||||||
|
self:SetDefenderTaskTarget( AIGroup, Target )
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -247,9 +249,13 @@ do -- AI_A2A_DISPATCHER
|
|||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
-- @param Wrapper.Group#GROUP AIGroup
|
-- @param Wrapper.Group#GROUP AIGroup
|
||||||
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( AIGroup, Target )
|
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( AIGroup, Target )
|
||||||
|
|
||||||
|
local Message = "(" .. self.DefenderTasks[AIGroup].Type .. ") "
|
||||||
|
Message = Message .. AIGroup:GetName()
|
||||||
|
Message = Message .. ( Target and ( " target " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or ""
|
||||||
|
self:F( { Target = Message } )
|
||||||
if Target then
|
if Target then
|
||||||
AIGroup:MessageToAll( AIGroup:GetName().. " target " .. Target.Index, 300 )
|
AIGroup:MessageToAll( Message, 1200 )
|
||||||
self.DefenderTasks[AIGroup].Target = Target
|
self.DefenderTasks[AIGroup].Target = Target
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
@ -257,83 +263,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, Target, AIGroups )
|
-- @return #AI_A2A_DISPATCHER
|
||||||
|
|
||||||
self:F( { AIGroups = AIGroups } )
|
|
||||||
|
|
||||||
if AIGroups then
|
|
||||||
|
|
||||||
for AIGroupID, AIGroup in pairs( AIGroups ) do
|
|
||||||
|
|
||||||
local Fsm = self:GetDefenderTaskFsm( AIGroup )
|
|
||||||
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
|
||||||
|
|
||||||
self:SetDefenderTaskTarget( AIGroup, Target )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---
|
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
|
||||||
function AI_A2A_DISPATCHER:onafterINTERCEPT( From, Event, To, Target, DefendersMissing )
|
|
||||||
|
|
||||||
local ClosestDistance = 0
|
|
||||||
local ClosestDefenderSquadronName = nil
|
|
||||||
|
|
||||||
local AttackerCount = Target.Set:Count()
|
|
||||||
local DefendersCount = 0
|
|
||||||
|
|
||||||
while( DefendersCount < DefendersMissing ) do
|
|
||||||
|
|
||||||
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
|
|
||||||
for InterceptID, Intercept in pairs( DefenderSquadron.Intercept or {} ) do
|
|
||||||
|
|
||||||
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
|
|
||||||
local TargetCoord = Target.Set:GetFirst():GetCoordinate()
|
|
||||||
local Distance = SpawnCoord:Get2DDistance( TargetCoord )
|
|
||||||
|
|
||||||
if ClosestDistance == 0 or Distance < ClosestDistance then
|
|
||||||
ClosestDistance = Distance
|
|
||||||
ClosestDefenderSquadronName = SquadronName
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ClosestDefenderSquadronName then
|
|
||||||
|
|
||||||
local DefenderSquadron = self.DefenderSquadrons[ClosestDefenderSquadronName]
|
|
||||||
local Intercept = self.DefenderSquadrons[ClosestDefenderSquadronName].Intercept
|
|
||||||
|
|
||||||
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
|
|
||||||
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
|
|
||||||
self:F( { AIGroup = AIGroup:GetName() } )
|
|
||||||
|
|
||||||
if AIGroup then
|
|
||||||
|
|
||||||
DefendersCount = DefendersCount + AIGroup:GetSize()
|
|
||||||
|
|
||||||
local Fsm = AI_A2A_INTERCEPT:New( AIGroup, Intercept.MinSpeed, Intercept.MaxSpeed )
|
|
||||||
Fsm:SetDispatcher( self )
|
|
||||||
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
|
||||||
|
|
||||||
|
|
||||||
self:SetDefenderTask( AIGroup, "INTERCEPT", Fsm, Target )
|
|
||||||
|
|
||||||
function Fsm:onafterRTB()
|
|
||||||
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
|
|
||||||
local AIGroup = self:GetControllable()
|
|
||||||
AIGroup:MessageToAll( AIGroup:GetName().. " cleared " .. Dispatcher.DefenderTasks[AIGroup].Target.Index, 300 )
|
|
||||||
Dispatcher:ClearDefenderTask( AIGroup )
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
|
||||||
function AI_A2A_DISPATCHER:SetSquadron( SquadronName, AirbaseName, SpawnTemplates, Resources )
|
function AI_A2A_DISPATCHER:SetSquadron( SquadronName, AirbaseName, SpawnTemplates, Resources )
|
||||||
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
@ -348,18 +278,24 @@ do -- AI_A2A_DISPATCHER
|
|||||||
DefenderSquadron.Spawn = {}
|
DefenderSquadron.Spawn = {}
|
||||||
if type( SpawnTemplates ) == "string" then
|
if type( SpawnTemplates ) == "string" then
|
||||||
local SpawnTemplate = SpawnTemplates
|
local SpawnTemplate = SpawnTemplates
|
||||||
DefenderSquadron.Spawn[1] = SPAWN:New( SpawnTemplate )
|
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate )
|
||||||
|
DefenderSquadron.Spawn[1] = self.DefenderSpawns[SpawnTemplate]
|
||||||
else
|
else
|
||||||
for TemplateID, SpawnTemplate in pairs( SpawnTemplates ) do
|
for TemplateID, SpawnTemplate in pairs( SpawnTemplates ) do
|
||||||
DefenderSquadron.Spawn[#DefenderSquadron.Spawn+1] = SPAWN:New( SpawnTemplate )
|
self.DefenderSpawns[SpawnTemplate] = self.DefenderSpawns[SpawnTemplate] or SPAWN:New( SpawnTemplate )
|
||||||
|
DefenderSquadron.Spawn[#DefenderSquadron.Spawn+1] = self.DefenderSpawns[SpawnTemplate]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
DefenderSquadron.Resources = Resources
|
DefenderSquadron.Resources = Resources
|
||||||
|
|
||||||
|
self:SetOverhead( SquadronName, 1 )
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @return #AI_A2A_DISPATCHER
|
||||||
function AI_A2A_DISPATCHER:SetCAP( SquadronName, Zone, FloorAltitude, CeilingAltitude, MinSpeed, MaxSpeed, AltType )
|
function AI_A2A_DISPATCHER:SetCAP( SquadronName, Zone, FloorAltitude, CeilingAltitude, MinSpeed, MaxSpeed, AltType )
|
||||||
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
@ -388,6 +324,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @return #AI_A2A_DISPATCHER
|
||||||
function AI_A2A_DISPATCHER:SetCAPInterval( SquadronName, CapLimit, LowInterval, HighInterval, Probability )
|
function AI_A2A_DISPATCHER:SetCAPInterval( SquadronName, CapLimit, LowInterval, HighInterval, Probability )
|
||||||
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
@ -415,6 +352,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @return #AI_A2A_DISPATCHER
|
||||||
function AI_A2A_DISPATCHER:GetCAPDelay( SquadronName )
|
function AI_A2A_DISPATCHER:GetCAPDelay( SquadronName )
|
||||||
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
@ -442,9 +380,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
local Cap = DefenderSquadron.Cap
|
local Cap = DefenderSquadron.Cap
|
||||||
if Cap then
|
if Cap then
|
||||||
self:E( { Cap = Cap } )
|
|
||||||
local CapCount = self:CountCapAirborne( SquadronName )
|
local CapCount = self:CountCapAirborne( SquadronName )
|
||||||
self:F( { CapCount = CapCount, CapLimit = Cap.CapLimit } )
|
|
||||||
if CapCount < Cap.CapLimit then
|
if CapCount < Cap.CapLimit then
|
||||||
local Probability = math.random()
|
local Probability = math.random()
|
||||||
if Probability <= Cap.Probability then
|
if Probability <= Cap.Probability then
|
||||||
@ -459,6 +395,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
---
|
---
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @return #AI_A2A_DISPATCHER
|
||||||
function AI_A2A_DISPATCHER:SetINTERCEPT( SquadronName, MinSpeed, MaxSpeed )
|
function AI_A2A_DISPATCHER:SetINTERCEPT( SquadronName, MinSpeed, MaxSpeed )
|
||||||
|
|
||||||
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
@ -470,6 +407,44 @@ do -- AI_A2A_DISPATCHER
|
|||||||
Intercept.MaxSpeed = MaxSpeed
|
Intercept.MaxSpeed = MaxSpeed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
-- @param #string SquadronName The name of the squadron.
|
||||||
|
-- @param #number Overhead The %-tage of Units that dispatching command will allocate to intercept in surplus of detected amount of units.
|
||||||
|
-- The default overhead is 1, so equal balance. The @{#AI_A2A_DISPATCHER.SetOverhead}() method can be used to tweak the defense strength,
|
||||||
|
-- taking into account the plane types of the squadron. For example, a MIG-31 with full long-distance A2A missiles payload, may still be less effective than a F-15C with short missiles...
|
||||||
|
-- So in this case, one may want to use the Overhead method to allocate more defending planes as the amount of detected attacking planes.
|
||||||
|
-- The overhead must be given as a decimal value with 1 as the neutral value, which means that Overhead values:
|
||||||
|
--
|
||||||
|
-- * Higher than 1, will increase the defense unit amounts.
|
||||||
|
-- * Lower than 1, will decrease the defense unit amounts.
|
||||||
|
--
|
||||||
|
-- The amount of defending units is calculated by multiplying the amount of detected attacking planes as part of the detected group
|
||||||
|
-- multiplied by the Overhead and rounded up to the smallest integer.
|
||||||
|
--
|
||||||
|
-- The Overhead value set for a Squadron, can be programmatically adjusted (by using this SetOverhead method), to adjust the defense overhead during mission execution.
|
||||||
|
--
|
||||||
|
-- See example below.
|
||||||
|
--
|
||||||
|
-- @usage:
|
||||||
|
--
|
||||||
|
-- local Dispatcher = AI_A2A_DISPATCHER:New( EWR )
|
||||||
|
--
|
||||||
|
-- -- An overhead of 1,5 with 1 planes detected, will allocate 2 planes ( 1 * 1,5 ) = 1,5 => rounded up gives 2.
|
||||||
|
-- -- An overhead of 1,5 with 2 planes detected, will allocate 3 planes ( 2 * 1,5 ) = 3 => rounded up gives 3.
|
||||||
|
-- -- An overhead of 1,5 with 3 planes detected, will allocate 5 planes ( 3 * 1,5 ) = 4,5 => rounded up gives 5 planes.
|
||||||
|
-- -- An overhead of 1,5 with 4 planes detected, will allocate 6 planes ( 4 * 1,5 ) = 6 => rounded up gives 6 planes.
|
||||||
|
--
|
||||||
|
-- Dispatcher:SetOverhead( 1,5 )
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- @return #AI_A2A_DISPATCHER
|
||||||
|
function AI_A2A_DISPATCHER:SetOverhead( SquadronName, Overhead )
|
||||||
|
|
||||||
|
self.Overhead = Overhead
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Creates an SWEEP task when there are targets for it.
|
--- Creates an SWEEP task when there are targets for it.
|
||||||
@ -525,12 +500,12 @@ 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
|
||||||
|
|
||||||
for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
local DefenderTasks = self:GetDefenderTasks()
|
||||||
|
for AIGroup, DefenderTask in pairs( DefenderTasks ) do
|
||||||
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
||||||
if self:GetDefenderTaskTarget( AIGroup ) == Target then
|
local DefenderTask = self:GetDefenderTaskTarget( AIGroup )
|
||||||
if AIGroup:IsAlive() then
|
if DefenderTask and DefenderTask.Index == Target.Index then
|
||||||
AIUnitCount = AIUnitCount + AIGroup:GetSize()
|
AIUnitCount = AIUnitCount + AIGroup:GetSize()
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -541,7 +516,7 @@ do -- AI_A2A_DISPATCHER
|
|||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( DetectedItem, DefenderCount )
|
function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( DetectedItem, DefenderCount )
|
||||||
|
|
||||||
local ResultAIGroups = nil
|
local Friendlies = nil
|
||||||
|
|
||||||
local DetectedSet = DetectedItem.Set
|
local DetectedSet = DetectedItem.Set
|
||||||
local DetectedCount = DetectedSet:Count()
|
local DetectedCount = DetectedSet:Count()
|
||||||
@ -551,23 +526,20 @@ do -- AI_A2A_DISPATCHER
|
|||||||
for AIName, AIFriendly in pairs( AIFriendlies or {} ) do
|
for AIName, AIFriendly in pairs( AIFriendlies or {} ) do
|
||||||
-- We only allow to ENGAGE targets as long as the Units on both sides are balanced.
|
-- We only allow to ENGAGE targets as long as the Units on both sides are balanced.
|
||||||
if DetectedCount > DefenderCount then
|
if DetectedCount > DefenderCount then
|
||||||
local AIGroup = AIFriendly:GetGroup() -- Wrapper.Group#GROUP
|
local Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP
|
||||||
self:F( { AIFriendly = AIGroup } )
|
if Friendly and Friendly:IsAlive() then
|
||||||
if AIGroup and AIGroup:IsAlive() then
|
|
||||||
-- Ok, so we have a friendly near the potential target.
|
-- Ok, so we have a friendly near the potential target.
|
||||||
-- Now we need to check if the AIGroup has a Task.
|
-- Now we need to check if the AIGroup has a Task.
|
||||||
local DefenderTask = self:GetDefenderTask( AIGroup )
|
local DefenderTask = self:GetDefenderTask( Friendly )
|
||||||
self:F( {AIGroupTask = DefenderTask } )
|
|
||||||
if DefenderTask then
|
if DefenderTask then
|
||||||
-- The Task should be CAP or INTERCEPT
|
-- The Task should be CAP or INTERCEPT
|
||||||
self:F( { Type = DefenderTask.Type } )
|
|
||||||
if DefenderTask.Type == "CAP" or DefenderTask.Type == "INTERCEPT" then
|
if DefenderTask.Type == "CAP" or DefenderTask.Type == "INTERCEPT" 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 TargetSet
|
||||||
self:F( { Target = DefenderTask.Target } )
|
|
||||||
if DefenderTask.Target == nil then
|
if DefenderTask.Target == nil then
|
||||||
ResultAIGroups = ResultAIGroups or {}
|
Friendlies = Friendlies or {}
|
||||||
ResultAIGroups[AIGroup] = AIGroup
|
Friendlies[Friendly] = Friendly
|
||||||
DefenderCount = DefenderCount + AIGroup:GetSize()
|
DefenderCount = DefenderCount + Friendly:GetSize()
|
||||||
|
self:F( { Friendly = Friendly:GetName() } )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -577,9 +549,134 @@ do -- AI_A2A_DISPATCHER
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ResultAIGroups
|
return Friendlies
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
function AI_A2A_DISPATCHER:onafterCAP( From, Event, To, SquadronName )
|
||||||
|
|
||||||
|
self:F({SquadronName = SquadronName})
|
||||||
|
self.DefenderSquadrons[SquadronName] = self.DefenderSquadrons[SquadronName] or {}
|
||||||
|
self.DefenderSquadrons[SquadronName].Cap = self.DefenderSquadrons[SquadronName].Cap or {}
|
||||||
|
|
||||||
|
local DefenderSquadron = self.DefenderSquadrons[SquadronName]
|
||||||
|
local Cap = DefenderSquadron.Cap
|
||||||
|
|
||||||
|
if Cap then
|
||||||
|
|
||||||
|
if self:CanCAP( SquadronName ) then
|
||||||
|
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
|
||||||
|
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
|
||||||
|
self:F( { AIGroup = AIGroup:GetName() } )
|
||||||
|
|
||||||
|
if AIGroup then
|
||||||
|
|
||||||
|
local Fsm = AI_A2A_CAP:New( AIGroup, Cap.Zone, Cap.FloorAltitude, Cap.CeilingAltitude, Cap.MinSpeed, Cap.MaxSpeed, Cap.AltType )
|
||||||
|
Fsm:SetDispatcher( self )
|
||||||
|
Fsm:Start()
|
||||||
|
Fsm:__Patrol( 1 )
|
||||||
|
|
||||||
|
self:SetDefenderTask( AIGroup, "CAP", Fsm )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error( "This squadron does not exist:" .. SquadronName )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, Target, AIGroups )
|
||||||
|
|
||||||
|
self:F( { AIGroups = AIGroups } )
|
||||||
|
|
||||||
|
if AIGroups then
|
||||||
|
|
||||||
|
for AIGroupID, AIGroup in pairs( AIGroups ) do
|
||||||
|
|
||||||
|
local Fsm = self:GetDefenderTaskFsm( AIGroup )
|
||||||
|
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
||||||
|
|
||||||
|
self:SetDefenderTaskTarget( AIGroup, Target )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
|
function AI_A2A_DISPATCHER:onafterINTERCEPT( From, Event, To, Target, DefendersMissing, AIGroups )
|
||||||
|
|
||||||
|
local ClosestDistance = 0
|
||||||
|
local ClosestDefenderSquadronName = nil
|
||||||
|
|
||||||
|
local AttackerCount = Target.Set:Count()
|
||||||
|
local DefendersCount = 0
|
||||||
|
|
||||||
|
for AIGroupID, AIGroup in pairs( AIGroups or {} ) do
|
||||||
|
|
||||||
|
local Fsm = self:GetDefenderTaskFsm( AIGroup )
|
||||||
|
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
||||||
|
|
||||||
|
self:SetDefenderTaskTarget( AIGroup, Target )
|
||||||
|
|
||||||
|
DefendersCount = DefendersCount + AIGroup:GetSize()
|
||||||
|
end
|
||||||
|
|
||||||
|
while( DefendersCount < DefendersMissing ) do
|
||||||
|
|
||||||
|
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
|
||||||
|
for InterceptID, Intercept in pairs( DefenderSquadron.Intercept or {} ) do
|
||||||
|
|
||||||
|
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
|
||||||
|
local TargetCoord = Target.Set:GetFirst():GetCoordinate()
|
||||||
|
local Distance = SpawnCoord:Get2DDistance( TargetCoord )
|
||||||
|
|
||||||
|
if ClosestDistance == 0 or Distance < ClosestDistance then
|
||||||
|
ClosestDistance = Distance
|
||||||
|
ClosestDefenderSquadronName = SquadronName
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if ClosestDefenderSquadronName then
|
||||||
|
|
||||||
|
local DefenderSquadron = self.DefenderSquadrons[ClosestDefenderSquadronName]
|
||||||
|
local Intercept = self.DefenderSquadrons[ClosestDefenderSquadronName].Intercept
|
||||||
|
|
||||||
|
local Spawn = DefenderSquadron.Spawn[ math.random( 1, #DefenderSquadron.Spawn ) ]
|
||||||
|
local AIGroup = Spawn:SpawnAtAirbase( DefenderSquadron.Airbase )
|
||||||
|
self:F( { AIGroup = AIGroup:GetName() } )
|
||||||
|
|
||||||
|
if AIGroup then
|
||||||
|
|
||||||
|
DefendersCount = DefendersCount + AIGroup:GetSize()
|
||||||
|
|
||||||
|
local Fsm = AI_A2A_INTERCEPT:New( AIGroup, Intercept.MinSpeed, Intercept.MaxSpeed )
|
||||||
|
Fsm:SetDispatcher( self )
|
||||||
|
Fsm:Start()
|
||||||
|
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit
|
||||||
|
|
||||||
|
|
||||||
|
self:SetDefenderTask( AIGroup, "INTERCEPT", Fsm, Target )
|
||||||
|
|
||||||
|
function Fsm:onafterRTB()
|
||||||
|
self:F({"RTB"})
|
||||||
|
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
|
||||||
|
local AIGroup = self:GetControllable()
|
||||||
|
Dispatcher:ClearDefenderTask( AIGroup )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Creates an ENGAGE task when there are human friendlies airborne near the targets.
|
--- Creates an ENGAGE task when there are human friendlies airborne near the targets.
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
@ -619,63 +716,90 @@ do -- AI_A2A_DISPATCHER
|
|||||||
|
|
||||||
-- First, count the active AIGroups Units, targetting the DetectedSet
|
-- First, count the active AIGroups Units, targetting the DetectedSet
|
||||||
local DefenderCount = self:CountDefendersEngaged( Target )
|
local DefenderCount = self:CountDefendersEngaged( Target )
|
||||||
local DefendersMissing = AttackerCount - DefenderCount
|
local DefendersMissing = math.ceil( ( AttackerCount - DefenderCount ) * self.Overhead )
|
||||||
|
|
||||||
|
local Friendlies = self:CountDefendersToBeEngaged( Target, DefenderCount )
|
||||||
|
|
||||||
if Target.IsDetected == true then
|
if Target.IsDetected == true then
|
||||||
|
|
||||||
return DefendersMissing
|
return DefendersMissing, Friendlies
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Assigns A2A AI Tasks in relation to the detected items.
|
||||||
|
|
||||||
--- Calculates which friendlies are nearby the area
|
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
-- @param DetectedItem
|
-- @param Functional.Detection#DETECTION_BASE Detection The detection created by the @{Detection#DETECTION_BASE} derived object.
|
||||||
-- @return #number, Core.CommandCenter#REPORT
|
-- @return #boolean Return true if you want the task assigning to continue... false will cancel the loop.
|
||||||
function AI_A2A_DISPATCHER:GetFriendliesNearBy( Target )
|
function AI_A2A_DISPATCHER:ProcessDetected( Detection )
|
||||||
|
|
||||||
local DetectedSet = Target.Set
|
local AreaMsg = {}
|
||||||
local FriendlyUnitsNearBy = self.Detection:GetFriendliesNearBy( Target )
|
local TaskMsg = {}
|
||||||
|
local ChangeMsg = {}
|
||||||
|
|
||||||
local FriendlyTypes = {}
|
local TaskReport = REPORT:New()
|
||||||
local FriendliesCount = 0
|
|
||||||
|
|
||||||
if FriendlyUnitsNearBy then
|
|
||||||
local DetectedTreatLevel = DetectedSet:CalculateThreatLevelA2G()
|
for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
||||||
for FriendlyUnitName, FriendlyUnitData in pairs( FriendlyUnitsNearBy ) do
|
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
||||||
local FriendlyUnit = FriendlyUnitData -- Wrapper.Unit#UNIT
|
if not AIGroup:IsAlive() then
|
||||||
if FriendlyUnit:IsAirPlane() then
|
self:ClearDefenderTask( AIGroup )
|
||||||
local FriendlyUnitThreatLevel = FriendlyUnit:GetThreatLevel()
|
end
|
||||||
FriendliesCount = FriendliesCount + 1
|
end
|
||||||
local FriendlyType = FriendlyUnit:GetTypeName()
|
|
||||||
FriendlyTypes[FriendlyType] = FriendlyTypes[FriendlyType] and ( FriendlyTypes[FriendlyType] + 1 ) or 1
|
-- Now that all obsolete tasks are removed, loop through the detected targets.
|
||||||
if DetectedTreatLevel < FriendlyUnitThreatLevel + 2 then
|
for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do
|
||||||
end
|
|
||||||
|
local DetectedItem = DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem
|
||||||
|
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
||||||
|
local DetectedCount = DetectedSet:Count()
|
||||||
|
local DetectedZone = DetectedItem.Zone
|
||||||
|
|
||||||
|
self:F( { "Target ID", DetectedItem.ItemID } )
|
||||||
|
DetectedSet:Flush()
|
||||||
|
|
||||||
|
local DetectedID = DetectedItem.ID
|
||||||
|
local DetectionIndex = DetectedItem.Index
|
||||||
|
local DetectedItemChanged = DetectedItem.Changed
|
||||||
|
|
||||||
|
do
|
||||||
|
local Friendlies = self:EvaluateENGAGE( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
|
||||||
|
if Friendlies then
|
||||||
|
self:F( { AIGroups = Friendlies } )
|
||||||
|
self:ENGAGE( DetectedItem, Friendlies )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--self:E( { FriendliesCount = FriendliesCount } )
|
do
|
||||||
|
local DefendersMissing, Friendlies = self:EvaluateINTERCEPT( DetectedItem )
|
||||||
local FriendlyTypesReport = REPORT:New()
|
if DefendersMissing then
|
||||||
|
self:F( { DefendersMissing = DefendersMissing } )
|
||||||
if FriendliesCount > 0 then
|
self:INTERCEPT( DetectedItem, DefendersMissing, Friendlies )
|
||||||
for FriendlyType, FriendlyTypeCount in pairs( FriendlyTypes ) do
|
end
|
||||||
FriendlyTypesReport:Add( string.format("%d of %s", FriendlyTypeCount, FriendlyType ) )
|
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
FriendlyTypesReport:Add( "-" )
|
|
||||||
|
-- Show tactical situation
|
||||||
|
for Defender, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
||||||
|
local Defender = Defender -- Wrapper.Group#GROUP
|
||||||
|
local Message = string.format( "%s, %s", Defender:GetName(), DefenderTask.Type )
|
||||||
|
if DefenderTask.Target then
|
||||||
|
Message = Message .. " => " .. DefenderTask.Target.Index
|
||||||
|
end
|
||||||
|
self:F( { Tactical = Message } )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return FriendliesCount, FriendlyTypesReport
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
|
||||||
--- Calculates which HUMAN friendlies are nearby the area
|
--- Calculates which HUMAN friendlies are nearby the area
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
-- @param DetectedItem
|
-- @param DetectedItem
|
||||||
@ -722,71 +846,50 @@ do -- AI_A2A_DISPATCHER
|
|||||||
return PlayersCount, PlayerTypesReport
|
return PlayersCount, PlayerTypesReport
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Calculates which AI friendlies are nearby the area
|
--- Calculates which friendlies are nearby the area
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
-- @param #AI_A2A_DISPATCHER self
|
||||||
-- @param DetectedItem
|
-- @param DetectedItem
|
||||||
-- @return #number, Core.CommandCenter#REPORT
|
-- @return #number, Core.CommandCenter#REPORT
|
||||||
function AI_A2A_DISPATCHER:GetAIFriendliesNearBy( DetectedItem )
|
function AI_A2A_DISPATCHER:GetFriendliesNearBy( Target )
|
||||||
|
|
||||||
local FriendliesNearBy = self.Detection:GetFriendliesNearBy( DetectedItem )
|
local DetectedSet = Target.Set
|
||||||
|
local FriendlyUnitsNearBy = self.Detection:GetFriendliesNearBy( Target )
|
||||||
|
|
||||||
return FriendliesNearBy
|
local FriendlyTypes = {}
|
||||||
end
|
local FriendliesCount = 0
|
||||||
|
|
||||||
|
if FriendlyUnitsNearBy then
|
||||||
--- Assigns A2A AI Tasks in relation to the detected items.
|
local DetectedTreatLevel = DetectedSet:CalculateThreatLevelA2G()
|
||||||
-- @param #AI_A2A_DISPATCHER self
|
for FriendlyUnitName, FriendlyUnitData in pairs( FriendlyUnitsNearBy ) do
|
||||||
-- @param Functional.Detection#DETECTION_BASE Detection The detection created by the @{Detection#DETECTION_BASE} derived object.
|
local FriendlyUnit = FriendlyUnitData -- Wrapper.Unit#UNIT
|
||||||
-- @return #boolean Return true if you want the task assigning to continue... false will cancel the loop.
|
if FriendlyUnit:IsAirPlane() then
|
||||||
function AI_A2A_DISPATCHER:ProcessDetected( Detection )
|
local FriendlyUnitThreatLevel = FriendlyUnit:GetThreatLevel()
|
||||||
|
FriendliesCount = FriendliesCount + 1
|
||||||
local AreaMsg = {}
|
local FriendlyType = FriendlyUnit:GetTypeName()
|
||||||
local TaskMsg = {}
|
FriendlyTypes[FriendlyType] = FriendlyTypes[FriendlyType] and ( FriendlyTypes[FriendlyType] + 1 ) or 1
|
||||||
local ChangeMsg = {}
|
if DetectedTreatLevel < FriendlyUnitThreatLevel + 2 then
|
||||||
|
end
|
||||||
local TaskReport = REPORT:New()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Now that all obsolete tasks are removed, loop through the detected targets.
|
|
||||||
for DetectedItemID, DetectedItem in pairs( Detection:GetDetectedItems() ) do
|
|
||||||
|
|
||||||
local DetectedItem = DetectedItem -- Functional.Detection#DETECTION_BASE.DetectedItem
|
|
||||||
local DetectedSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
|
||||||
local DetectedCount = DetectedSet:Count()
|
|
||||||
local DetectedZone = DetectedItem.Zone
|
|
||||||
|
|
||||||
self:F( { "Targets in DetectedItem", DetectedItem.ItemID, DetectedSet:Count() } )
|
|
||||||
|
|
||||||
for AIGroup, DefenderTask in pairs( self:GetDefenderTasks() ) do
|
|
||||||
local AIGroup = AIGroup -- Wrapper.Group#GROUP
|
|
||||||
if not AIGroup:IsAlive() then
|
|
||||||
self:ClearDefenderTask( AIGroup )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local DetectedID = DetectedItem.ID
|
|
||||||
local A2A_Index = DetectedItem.Index
|
|
||||||
local DetectedItemChanged = DetectedItem.Changed
|
|
||||||
|
|
||||||
do
|
end
|
||||||
local AIGroups = self:EvaluateENGAGE( DetectedItem ) -- Returns a SetUnit if there are targets to be INTERCEPTed...
|
|
||||||
self:F( { AIGroups = AIGroups } )
|
|
||||||
if AIGroups then
|
|
||||||
self:ENGAGE( DetectedItem, AIGroups )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
do
|
--self:E( { FriendliesCount = FriendliesCount } )
|
||||||
local DefendersMissing = self:EvaluateINTERCEPT( DetectedItem )
|
|
||||||
self:F( { DefendersMissing = DefendersMissing } )
|
local FriendlyTypesReport = REPORT:New()
|
||||||
if DefendersMissing then
|
|
||||||
self:INTERCEPT( DetectedItem, DefendersMissing )
|
if FriendliesCount > 0 then
|
||||||
end
|
for FriendlyType, FriendlyTypeCount in pairs( FriendlyTypes ) do
|
||||||
|
FriendlyTypesReport:Add( string.format("%d of %s", FriendlyTypeCount, FriendlyType ) )
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
FriendlyTypesReport:Add( "-" )
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
|
||||||
|
return FriendliesCount, FriendlyTypesReport
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
end
|
||||||
@ -132,7 +132,7 @@ function AI_A2A_INTERCEPT:New( AIGroup, MinSpeed, MaxSpeed )
|
|||||||
|
|
||||||
self.PatrolAltType = "RADIO"
|
self.PatrolAltType = "RADIO"
|
||||||
|
|
||||||
self:AddTransition( { "Stopped", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT.
|
self:AddTransition( { "Started", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_A2A_INTERCEPT.
|
||||||
|
|
||||||
--- OnBefore Transition Handler for Event Engage.
|
--- OnBefore Transition Handler for Event Engage.
|
||||||
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeEngage
|
-- @function [parent=#AI_A2A_INTERCEPT] OnBeforeEngage
|
||||||
@ -314,7 +314,6 @@ function AI_A2A_INTERCEPT.InterceptRoute( AIControllable )
|
|||||||
AIControllable:T( "NewEngageRoute" )
|
AIControllable:T( "NewEngageRoute" )
|
||||||
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_INTERCEPT
|
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_INTERCEPT
|
||||||
EngageZone:__Engage( 1 )
|
EngageZone:__Engage( 1 )
|
||||||
AIControllable:MessageToAll( AIControllable:GetName() .. " Engaging", 15 )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #AI_A2A_INTERCEPT self
|
--- @param #AI_A2A_INTERCEPT self
|
||||||
@ -350,63 +349,71 @@ function AI_A2A_INTERCEPT:onafterEngage( AIGroup, From, Event, To, AttackSetUnit
|
|||||||
self:F( { AIGroup, From, Event, To, AttackSetUnit} )
|
self:F( { AIGroup, From, Event, To, AttackSetUnit} )
|
||||||
|
|
||||||
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
|
||||||
|
|
||||||
if AIGroup:IsAlive() then
|
|
||||||
|
|
||||||
local EngageRoute = {}
|
|
||||||
|
|
||||||
--- Calculate the current route point.
|
|
||||||
|
|
||||||
local CurrentCoord = AIGroup:GetCoordinate()
|
|
||||||
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
|
|
||||||
local ToTargetSpeed = math.random( self.MinSpeed, self.MaxSpeed )
|
|
||||||
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
|
||||||
|
|
||||||
--- Create a route point of type air.
|
|
||||||
local ToPatrolRoutePoint = CurrentCoord:Translate( 5000, ToInterceptAngle ):RoutePointAir(
|
|
||||||
self.PatrolAltType,
|
|
||||||
POINT_VEC3.RoutePointType.TurningPoint,
|
|
||||||
POINT_VEC3.RoutePointAction.TurningPoint,
|
|
||||||
ToTargetSpeed,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
|
|
||||||
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
|
|
||||||
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
|
|
||||||
|
|
||||||
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
|
||||||
|
|
||||||
AIGroup:OptionROEOpenFire()
|
|
||||||
AIGroup:OptionROTPassiveDefense()
|
|
||||||
|
|
||||||
local AttackTasks = {}
|
|
||||||
|
|
||||||
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
|
||||||
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
|
||||||
self:T( { "Intercepting Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
|
||||||
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
|
||||||
AttackTasks[#AttackTasks+1] = AIGroup:TaskAttackUnit( AttackUnit )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
|
|
||||||
AIGroup:WayPointInitialize( EngageRoute )
|
|
||||||
|
|
||||||
|
|
||||||
if #AttackTasks == 0 then
|
|
||||||
self:E("No targets found -> Going RTB")
|
|
||||||
self:__RTB( 1 )
|
|
||||||
else
|
|
||||||
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_INTERCEPT.InterceptRoute" )
|
|
||||||
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
|
|
||||||
|
|
||||||
--- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ...
|
|
||||||
AIGroup:SetState( AIGroup, "EngageZone", self )
|
|
||||||
end
|
|
||||||
|
|
||||||
--- NOW ROUTE THE GROUP!
|
|
||||||
AIGroup:WayPointExecute( 1, 2 )
|
|
||||||
|
|
||||||
|
local FirstAttackUnit = self.AttackSetUnit:GetFirst()
|
||||||
|
|
||||||
|
if FirstAttackUnit then
|
||||||
|
|
||||||
|
if AIGroup:IsAlive() then
|
||||||
|
|
||||||
|
local EngageRoute = {}
|
||||||
|
|
||||||
|
--- Calculate the target route point.
|
||||||
|
|
||||||
|
local CurrentCoord = AIGroup:GetCoordinate()
|
||||||
|
local ToTargetCoord = self.AttackSetUnit:GetFirst():GetCoordinate()
|
||||||
|
local ToTargetSpeed = math.random( self.MinSpeed, self.MaxSpeed )
|
||||||
|
local ToInterceptAngle = CurrentCoord:GetAngleDegrees( CurrentCoord:GetDirectionVec3( ToTargetCoord ) )
|
||||||
|
|
||||||
|
--- Create a route point of type air.
|
||||||
|
local ToPatrolRoutePoint = CurrentCoord:Translate( 5000, ToInterceptAngle ):RoutePointAir(
|
||||||
|
self.PatrolAltType,
|
||||||
|
POINT_VEC3.RoutePointType.TurningPoint,
|
||||||
|
POINT_VEC3.RoutePointAction.TurningPoint,
|
||||||
|
ToTargetSpeed,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
self:F( { Angle = ToInterceptAngle, ToTargetSpeed = ToTargetSpeed } )
|
||||||
|
self:T2( { self.MinSpeed, self.MaxSpeed, ToTargetSpeed } )
|
||||||
|
|
||||||
|
EngageRoute[#EngageRoute+1] = ToPatrolRoutePoint
|
||||||
|
|
||||||
|
AIGroup:OptionROEOpenFire()
|
||||||
|
AIGroup:OptionROTPassiveDefense()
|
||||||
|
|
||||||
|
local AttackTasks = {}
|
||||||
|
|
||||||
|
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
|
||||||
|
local AttackUnit = AttackUnit -- Wrapper.Unit#UNIT
|
||||||
|
self:T( { "Intercepting Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsAir() } )
|
||||||
|
if AttackUnit:IsAlive() and AttackUnit:IsAir() then
|
||||||
|
AttackTasks[#AttackTasks+1] = AIGroup:TaskAttackUnit( AttackUnit )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
|
||||||
|
AIGroup:WayPointInitialize( EngageRoute )
|
||||||
|
|
||||||
|
|
||||||
|
if #AttackTasks == 0 then
|
||||||
|
self:E("No targets found -> Going RTB")
|
||||||
|
self:__RTB( 1 )
|
||||||
|
else
|
||||||
|
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_INTERCEPT.InterceptRoute" )
|
||||||
|
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
|
||||||
|
|
||||||
|
--- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ...
|
||||||
|
AIGroup:SetState( AIGroup, "EngageZone", self )
|
||||||
|
end
|
||||||
|
|
||||||
|
--- NOW ROUTE THE GROUP!
|
||||||
|
AIGroup:WayPointExecute( 1, 2 )
|
||||||
|
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self:E("No targets found -> Going RTB")
|
||||||
|
self:__RTB( 1 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -179,7 +179,7 @@ function AI_A2A_PATROL:New( AIGroup, PatrolZone, PatrolFloorAltitude, PatrolCeil
|
|||||||
-- defafult PatrolAltType to "RADIO" if not specified
|
-- defafult PatrolAltType to "RADIO" if not specified
|
||||||
self.PatrolAltType = PatrolAltType or "RADIO"
|
self.PatrolAltType = PatrolAltType or "RADIO"
|
||||||
|
|
||||||
self:AddTransition( "Stopped", "Patrol", "Patrolling" )
|
self:AddTransition( "Started", "Patrol", "Patrolling" )
|
||||||
|
|
||||||
--- OnBefore Transition Handler for Event Patrol.
|
--- OnBefore Transition Handler for Event Patrol.
|
||||||
-- @function [parent=#AI_A2A_PATROL] OnBeforePatrol
|
-- @function [parent=#AI_A2A_PATROL] OnBeforePatrol
|
||||||
|
|||||||
@ -87,7 +87,7 @@ function MESSAGE:New( MessageText, MessageDuration, MessageCategory )
|
|||||||
|
|
||||||
self.MessageDuration = MessageDuration or 5
|
self.MessageDuration = MessageDuration or 5
|
||||||
self.MessageTime = timer.getTime()
|
self.MessageTime = timer.getTime()
|
||||||
self.MessageText = MessageText
|
self.MessageText = MessageText:gsub("^\n","",1):gsub("\n$","",1)
|
||||||
|
|
||||||
self.MessageSent = false
|
self.MessageSent = false
|
||||||
self.MessageGroup = false
|
self.MessageGroup = false
|
||||||
|
|||||||
@ -611,7 +611,7 @@ do -- DETECTION_BASE
|
|||||||
if self.AcceptZones then
|
if self.AcceptZones then
|
||||||
for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do
|
for AcceptZoneID, AcceptZone in pairs( self.AcceptZones ) do
|
||||||
local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE
|
local AcceptZone = AcceptZone -- Core.Zone#ZONE_BASE
|
||||||
if AcceptZone:IsPointVec2InZone( DetectedObjectVec2 ) == false then
|
if AcceptZone:IsVec2InZone( DetectedObjectVec2 ) == false then
|
||||||
DetectionAccepted = false
|
DetectionAccepted = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -759,6 +759,25 @@ do -- DETECTION_BASE
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Forget a Unit from a DetectionItem
|
||||||
|
-- @param #DETECTION_BASE self
|
||||||
|
-- @param #string UnitName The UnitName that needs to be forgotten from the DetectionItem Sets.
|
||||||
|
-- @return #DETECTION_BASE
|
||||||
|
function DETECTION_BASE:ForgetDetectedUnit( UnitName )
|
||||||
|
self:F2()
|
||||||
|
|
||||||
|
local DetectedItems = self:GetDetectedItems()
|
||||||
|
|
||||||
|
for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do
|
||||||
|
local DetectedSet = self:GetDetectedSet( DetectedItemIndex )
|
||||||
|
if DetectedSet then
|
||||||
|
DetectedSet:RemoveUnitsByName( UnitName )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Make a DetectionSet table. This function will be overridden in the derived clsses.
|
--- Make a DetectionSet table. This function will be overridden in the derived clsses.
|
||||||
-- @param #DETECTION_BASE self
|
-- @param #DETECTION_BASE self
|
||||||
|
|||||||
@ -228,6 +228,36 @@ function CONTROLLABLE:GetLife()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the initial health.
|
||||||
|
-- @param #CONTROLLABLE self
|
||||||
|
-- @return #number The controllable health value (unit or group average).
|
||||||
|
-- @return #nil The controllable is not existing or alive.
|
||||||
|
function CONTROLLABLE:GetLife0()
|
||||||
|
self:F2( self.ControllableName )
|
||||||
|
|
||||||
|
local DCSControllable = self:GetDCSObject()
|
||||||
|
|
||||||
|
if DCSControllable then
|
||||||
|
local UnitLife = 0
|
||||||
|
local Units = self:GetUnits()
|
||||||
|
if #Units == 1 then
|
||||||
|
local Unit = Units[1] -- Wrapper.Unit#UNIT
|
||||||
|
UnitLife = Unit:GetLife0()
|
||||||
|
else
|
||||||
|
local UnitLifeTotal = 0
|
||||||
|
for UnitID, Unit in pairs( Units ) do
|
||||||
|
local Unit = Unit -- Wrapper.Unit#UNIT
|
||||||
|
UnitLifeTotal = UnitLifeTotal + Unit:GetLife0()
|
||||||
|
end
|
||||||
|
UnitLife = UnitLifeTotal / #Units
|
||||||
|
end
|
||||||
|
return UnitLife
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Tasks
|
-- Tasks
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user