This commit is contained in:
FlightControl 2017-06-12 16:25:05 +02:00
parent f56b2229a7
commit 1ea916ec73
5 changed files with 65 additions and 21 deletions

View File

@ -221,6 +221,7 @@ function AI_A2A:New( AIGroup )
self:AddTransition( "*", "Return", "Returning" )
self:AddTransition( "*", "Home", "Home" )
self:AddTransition( "*", "LostControl", "LostControl" )
self:AddTransition( "*", "Fuel", "Fuel" )
self:AddTransition( "*", "Damaged", "Damaged" )
@ -415,7 +416,7 @@ function AI_A2A:onafterStatus()
end
if RTB == true then
self:RTB()
self:__RTB( 0.5 )
else
self:__Status( 10 ) -- Execute the Patrol event after 30 seconds.
end
@ -428,7 +429,7 @@ function AI_A2A.RTBRoute( AIGroup )
AIGroup:E( { "RTBRoute:", AIGroup:GetName() } )
local _AI_A2A = AIGroup:GetState( AIGroup, "AI_A2A" ) -- #AI_A2A
_AI_A2A:RTB()
_AI_A2A:__RTB( 0.5 )
end
--- @param #AI_A2A self
@ -436,14 +437,14 @@ end
function AI_A2A:onafterRTB( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } )
self:E( "Group " .. self.Controllable:GetName() .. " ... RTB! ( " .. self:GetState() .. " )" )
self:E( "Group " .. self.Controllable:GetName() .. " ... Returning! ( " .. self:GetState() .. " )" )
if AIGroup and AIGroup:IsAlive() then
self.CheckStatus = false
self:ClearTargetDistance()
local EngageRoute = {}
--- Calculate the target route point.
@ -456,8 +457,9 @@ function AI_A2A:onafterRTB( AIGroup, From, Event, To )
local Distance = CurrentCoord:Get2DDistance( ToTargetCoord )
local ToAirbaseCoord = CurrentCoord:Translate( 5000, ToAirbaseAngle )
if Distance > 10000 then
ToAirbaseCoord = ToTargetCoord
if Distance < 5000 then
self:Home()
return
end
--- Create a route point of type air.
local ToPatrolRoutePoint = ToAirbaseCoord:RoutePointAir(
@ -492,6 +494,19 @@ function AI_A2A:onafterRTB( AIGroup, From, Event, To )
end
--- @param #AI_A2A self
-- @param Wrapper.Group#GROUP AIGroup
function AI_A2A:onafterHome( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } )
self:E( "Group " .. self.Controllable:GetName() .. " ... Home! ( " .. self:GetState() .. " )" )
if AIGroup and AIGroup:IsAlive() then
end
end
--- @param #AI_A2A self
function AI_A2A:onafterDead()

View File

@ -351,7 +351,7 @@ end
function AI_A2A_CAP.AttackRoute( AIGroup )
local EngageZone = AIGroup:GetState( AIGroup, "EngageZone" ) -- AI.AI_Cap#AI_A2A_CAP
EngageZone:Engage()
EngageZone:__Engage( 0.5 )
end
--- @param #AI_A2A_CAP self
@ -373,7 +373,7 @@ end
-- @param #string To The To State string.
function AI_A2A_CAP:onafterAbort( AIGroup, From, Event, To )
AIGroup:ClearTasks()
self:Route()
self:__Route( 0.5 )
end
@ -435,8 +435,7 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
if #AttackTasks == 0 then
self:E("No targets found -> Going back to Patrolling")
self:Abort()
self:Route()
self:__Abort( 0.5 )
else
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_CAP.AttackRoute" )
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
@ -450,8 +449,7 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
end
else
self:E("No targets found -> Going back to Patrolling")
self:Abort()
self:Route()
self:__Abort( 0.5 )
end
end

View File

@ -1035,7 +1035,7 @@ do -- AI_A2A_DISPATCHER
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
self.Defenders[ DefenderName ] = Squadron
Squadron.Resources = Squadron.Resources - 1
Squadron.Resources = Squadron.Resources - Defender:GetSize()
self:F( { DefenderName = DefenderName, SquadronResources = Squadron.Resources } )
end
@ -1043,7 +1043,7 @@ do -- AI_A2A_DISPATCHER
function AI_A2A_DISPATCHER:RemoveDefenderFromSquadron( Squadron, Defender )
self.Defenders = self.Defenders or {}
local DefenderName = Defender:GetName()
Squadron.Resources = Squadron.Resources + 1
Squadron.Resources = Squadron.Resources + Defender:GetSize()
self.Defenders[ DefenderName ] = nil
self:F( { DefenderName = DefenderName, SquadronResources = Squadron.Resources } )
end
@ -1312,15 +1312,28 @@ do -- AI_A2A_DISPATCHER
self:SetDefenderTask( DefenderGCI, "GCI", Fsm, Target )
function Fsm:onafterRTB( AIGroup, From, Event, To )
function Fsm:onafterRTB( Defender, From, Event, To )
self:F({"GCI RTB"})
self:GetParent(self).onafterRTB( self, AIGroup, From, Event, To )
self:GetParent(self).onafterRTB( self, Defender, From, Event, To )
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
local AIGroup = self:GetControllable()
Dispatcher:ClearDefenderTaskTarget( AIGroup )
end
--- @param #AI_A2A_DISPATCHER self
function Fsm:onafterHome( Defender, From, Event, To )
self:F({"GCI Home"})
self:GetParent(self).onafterHome( self, Defender, From, Event, To )
local Dispatcher = self:GetDispatcher() -- #AI_A2A_DISPATCHER
local AIGroup = self:GetControllable()
local Squadron = self:GetSquadronFromDefender( Defender )
if self:GetSquadronLanding( Squadron.Name ) == AI_A2A_DISPATCHER.Landing.NearAirbase then
Dispatcher:RemoveDefenderFromSquadron( Squadron, Defender )
Defender:Destroy()
end
end
end
end
end
@ -1457,7 +1470,7 @@ do -- AI_A2A_DISPATCHER
for Defender, DefenderTask in pairs( self:GetDefenderTasks() ) do
local Defender = Defender -- Wrapper.Group#GROUP
if DefenderTask.Target and DefenderTask.Target.Index == DetectedItem.Index then
Report:Add( string.format( " - %s ( %s - %s )", Defender:GetName(), DefenderTask.Type, DefenderTask.Fsm:GetState() ) )
Report:Add( string.format( " - %s ( %s - %s ) %s", Defender:GetName(), DefenderTask.Type, DefenderTask.Fsm:GetState(), Defender:HasTask() == true and "Executing" or "Idle" ) )
end
end
end

View File

@ -315,7 +315,7 @@ function AI_A2A_GCI.InterceptRoute( AIControllable )
AIControllable:T( "NewEngageRoute" )
local EngageZone = AIControllable:GetState( AIControllable, "EngageZone" ) -- AI.AI_Cap#AI_A2A_GCI
EngageZone:Engage()
EngageZone:__Engage( 0.5 )
end
--- @param #AI_A2A_GCI self
@ -338,7 +338,7 @@ end
function AI_A2A_GCI:onafterAbort( AIGroup, From, Event, To )
AIGroup:ClearTasks()
self:Return()
self:RTB()
self:__RTB( 0.5 )
end
@ -405,7 +405,7 @@ function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
if #AttackTasks == 0 then
self:E("No targets found -> Going RTB")
self:Return()
self:RTB()
self:__RTB( 0.5 )
else
AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, #AttackTasks, "AI_A2A_GCI.InterceptRoute" )
EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks )
@ -421,7 +421,7 @@ function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
else
self:E("No targets found -> Going RTB")
self:Return()
self:RTB()
self:__RTB( 0.5 )
end
end

View File

@ -352,6 +352,24 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
return nil
end
--- Checking the Task Queue of the controllable. Returns false if no task is on the queue. true if there is a task.
-- @param #CONTROLLABLE self
-- @return Wrapper.Controllable#CONTROLLABLE self
function CONTROLLABLE:HasTask() --R2.2
local HasTaskResult = false
local DCSControllable = self:GetDCSObject()
if DCSControllable then
local Controller = self:_GetController()
HasTaskResult = Controller:hasTask()
end
return HasTaskResult
end
--- Return a condition section for a controlled task.
-- @param #CONTROLLABLE self