Implemented an important fix. Refuel airplanes also when they are engaging targets and the fuel treshold has been reached.

This commit is contained in:
FlightControl 2019-08-24 08:56:50 +02:00
parent f951aae3ee
commit 96a904c077
8 changed files with 54 additions and 17 deletions

View File

@ -278,6 +278,8 @@ function AI_A2A_CAP:New( AICap, PatrolZone, PatrolFloorAltitude, PatrolCeilingAl
-- @param #AI_A2A_CAP self -- @param #AI_A2A_CAP self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( { "Patrolling", "Engaging" }, "Refuel", "Refuelling" )
return self return self
end end

View File

@ -279,6 +279,8 @@ function AI_A2A_GCI:New( AIIntercept, EngageMinSpeed, EngageMaxSpeed )
-- @param #AI_A2A_GCI self -- @param #AI_A2A_GCI self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( { "Patrolling", "Engaging" }, "Refuel", "Refuelling" )
return self return self
end end

View File

@ -62,12 +62,14 @@ end
-- @param #string To The To State string. -- @param #string To The To State string.
function AI_A2G_BAI:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit ) function AI_A2G_BAI:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit )
self:F( { DefenderGroup, From, Event, To, AttackSetUnit} ) self:I( { DefenderGroup, From, Event, To, AttackSetUnit} )
local DefenderGroupName = DefenderGroup:GetName() local DefenderGroupName = DefenderGroup:GetName()
local AttackCount = AttackSetUnit:Count() local AttackCount = AttackSetUnit:Count()
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
if AttackCount > 0 then if AttackCount > 0 then
if DefenderGroup:IsAlive() then if DefenderGroup:IsAlive() then
@ -151,3 +153,14 @@ function AI_A2G_BAI:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
self:__RTB( self.TaskDelay ) self:__RTB( self.TaskDelay )
end end
end end
--- @param Wrapper.Group#GROUP AIEngage
function AI_A2G_BAI.Resume( AIEngage, Fsm )
AIEngage:F( { "AI_A2G_BAI.Resume:", AIEngage:GetName() } )
if AIEngage:IsAlive() then
Fsm:__Reset( Fsm.TaskDelay )
Fsm:__EngageRoute( Fsm.TaskDelay, Fsm.AttackSetUnit )
end
end

View File

@ -66,6 +66,8 @@ function AI_A2G_CAS:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
local DefenderGroupName = DefenderGroup:GetName() local DefenderGroupName = DefenderGroup:GetName()
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
local AttackCount = AttackSetUnit:Count() local AttackCount = AttackSetUnit:Count()
if AttackCount > 0 then if AttackCount > 0 then
@ -148,3 +150,13 @@ function AI_A2G_CAS:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
end end
end end
--- @param Wrapper.Group#GROUP AIEngage
function AI_A2G_CAS.Resume( AIEngage, Fsm )
AIEngage:F( { "AI_A2G_CAS.Resume:", AIEngage:GetName() } )
if AIEngage:IsAlive() then
Fsm:__Reset( Fsm.TaskDelay )
Fsm:__EngageRoute( Fsm.TaskDelay, Fsm.AttackSetUnit )
end
end

View File

@ -304,6 +304,8 @@ function AI_A2G_ENGAGE:New( AIGroup, EngageMinSpeed, EngageMaxSpeed, EngageFloor
-- @param #AI_A2G_ENGAGE self -- @param #AI_A2G_ENGAGE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
self:AddTransition( { "Patrolling", "Engaging" }, "Refuel", "Refuelling" )
return self return self
end end
@ -389,17 +391,6 @@ function AI_A2G_ENGAGE:onafterAbort( AIGroup, From, Event, To )
end end
--- @param #AI_A2G_ENGAGE self
-- @param Wrapper.Group#GROUP DefenderGroup The GroupGroup managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_A2G_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, AttackSetUnit )
self:F( { DefenderGroup, From, Event, To, AttackSetUnit} )
end
--- @param #AI_A2G_ENGAGE self --- @param #AI_A2G_ENGAGE self
-- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM. -- @param Wrapper.Group#GROUP AIGroup The Group Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
@ -446,6 +437,8 @@ function AI_A2G_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, Attac
local DefenderGroupName = DefenderGroup:GetName() local DefenderGroupName = DefenderGroup:GetName()
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
local AttackCount = AttackSetUnit:Count() local AttackCount = AttackSetUnit:Count()
if AttackCount > 0 then if AttackCount > 0 then
@ -517,4 +510,5 @@ function AI_A2G_ENGAGE:onafterEngageRoute( DefenderGroup, From, Event, To, Attac
self:Return() self:Return()
self:__RTB( self.TaskDelay ) self:__RTB( self.TaskDelay )
end end
end end

View File

@ -316,8 +316,8 @@ function AI_A2G_PATROL.Resume( AIPatrol, Fsm )
AIPatrol:F( { "AI_A2G_PATROL.Resume:", AIPatrol:GetName() } ) AIPatrol:F( { "AI_A2G_PATROL.Resume:", AIPatrol:GetName() } )
if AIPatrol:IsAlive() then if AIPatrol:IsAlive() then
Fsm:__Reset( self.TaskDelay ) Fsm:__Reset( Fsm.TaskDelay )
Fsm:__PatrolRoute( self.TaskDelay ) Fsm:__PatrolRoute( Fsm.TaskDelay )
end end
end end

View File

@ -117,6 +117,8 @@ function AI_A2G_SEAD:onafterEngage( DefenderGroup, From, Event, To, AttackSetUni
local DefenderGroupName = DefenderGroup:GetName() local DefenderGroupName = DefenderGroup:GetName()
self.AttackSetUnit = AttackSetUnit -- Kept in memory in case of resume from refuel in air!
local AttackCount = AttackSetUnit:Count() local AttackCount = AttackSetUnit:Count()
if AttackCount > 0 then if AttackCount > 0 then
@ -206,3 +208,13 @@ function AI_A2G_SEAD:onafterEngage( DefenderGroup, From, Event, To, AttackSetUni
end end
end end
--- @param Wrapper.Group#GROUP AIEngage
function AI_A2G_SEAD.Resume( AIEngage, Fsm )
AIEngage:F( { "AI_A2G_SEAD.Resume:", AIEngage:GetName() } )
if AIEngage:IsAlive() then
Fsm:__Reset( Fsm.TaskDelay )
Fsm:__EngageRoute( Fsm.TaskDelay, Fsm.AttackSetUnit )
end
end

View File

@ -461,7 +461,7 @@ function AI_AIR:onafterStatus()
-- end -- end
if not self:Is( "Fuel" ) and not self:Is( "Home" ) then if not self:Is( "Fuel" ) and not self:Is( "Home" ) and not self:is( "Refuelling" )then
local Fuel = self.Controllable:GetFuelMin() local Fuel = self.Controllable:GetFuelMin()
@ -680,12 +680,14 @@ end
function AI_AIR:onafterRefuel( AIGroup, From, Event, To ) function AI_AIR:onafterRefuel( AIGroup, From, Event, To )
self:F( { AIGroup, From, Event, To } ) self:F( { AIGroup, From, Event, To } )
self:E( "Group " .. self.Controllable:GetName() .. " ... Refuelling! ( " .. self:GetState() .. " )" )
if AIGroup and AIGroup:IsAlive() then if AIGroup and AIGroup:IsAlive() then
local Tanker = GROUP:FindByName( self.TankerName ) local Tanker = GROUP:FindByName( self.TankerName )
if Tanker:IsAlive() and Tanker:IsAirPlane() then if Tanker:IsAlive() and Tanker:IsAirPlane() then
self:E( "Group " .. self.Controllable:GetName() .. " ... Refuelling! ( " .. self:GetState() .. "), at tanker " .. self.TankerName )
local RefuelRoute = {} local RefuelRoute = {}
--- Calculate the target route point. --- Calculate the target route point.