mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-21 11:02:45 +00:00
AI helicopter dispatcher working to load multiple infantry groups !
This commit is contained in:
@@ -129,10 +129,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
self:SetCarrier( Airplane )
|
self:SetCarrier( Airplane )
|
||||||
|
|
||||||
local Desc = Airplane:GetUnit(1):GetDesc()
|
local Desc = Airplane:GetUnit(1):GetDesc()
|
||||||
|
|
||||||
self:F({Desc=Desc})
|
self:F({Desc=Desc})
|
||||||
|
|
||||||
|
|
||||||
Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
||||||
--Airplane:SetCargoBayVolumeLimit( 15 )
|
--Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
|
||||||
@@ -251,12 +248,15 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To )
|
|||||||
env.info("FF load airplane "..Airplane:GetName())
|
env.info("FF load airplane "..Airplane:GetName())
|
||||||
self:Load( Airplane:GetCoordinate() )
|
self:Load( Airplane:GetCoordinate() )
|
||||||
self.RoutePickup = false
|
self.RoutePickup = false
|
||||||
|
self.Relocating = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Aircraft was send to this airbase to deploy troops. Initiate unloading.
|
-- Aircraft was send to this airbase to deploy troops. Initiate unloading.
|
||||||
if self.RouteDeploy == true then
|
if self.RouteDeploy == true then
|
||||||
self:Unload()
|
self:Unload()
|
||||||
self.RouteDeploy = false
|
self.RouteDeploy = false
|
||||||
|
self.Transporting = false
|
||||||
|
self.Relocating = false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -451,10 +451,9 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To, Cargo )
|
|||||||
env.info("FF troops loaded into cargo plane")
|
env.info("FF troops loaded into cargo plane")
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
self:F( { "Transporting" } )
|
self:F( { "Transporting" } )
|
||||||
self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle!
|
self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle!
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
-- The Pickup sequence ...
|
-- The Pickup sequence ...
|
||||||
-- Check if this Carrier need to go and Pickup something...
|
-- Check if this Carrier need to go and Pickup something...
|
||||||
-- So, if the cargo bay is not full yet with cargo to be loaded ...
|
-- So, if the cargo bay is not full yet with cargo to be loaded ...
|
||||||
self:I( { IsRelocating = AI_Cargo:IsRelocating() } )
|
self:I( { IsRelocating = AI_Cargo:IsRelocating(), IsTransporting = AI_Cargo:IsTransporting() } )
|
||||||
if AI_Cargo:IsRelocating() == false and AI_Cargo:IsTransporting() == false then
|
if AI_Cargo:IsRelocating() == false and AI_Cargo:IsTransporting() == false then
|
||||||
-- ok, so there is a free Carrier
|
-- ok, so there is a free Carrier
|
||||||
-- now find the first cargo that is Unloaded
|
-- now find the first cargo that is Unloaded
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet )
|
|||||||
self:AddTransition( "Unloaded", "Pickup", "*" )
|
self:AddTransition( "Unloaded", "Pickup", "*" )
|
||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
|
|
||||||
self:AddTransition( "Unloaded", "Load", "Boarding" )
|
self:AddTransition( { "Unloaded", "Loading" }, "Load", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Board", "Boarding" )
|
self:AddTransition( "Boarding", "Board", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Loaded", "Loaded" )
|
self:AddTransition( "Boarding", "Loaded", "Loaded" )
|
||||||
self:AddTransition( "Loaded", "Unload", "Unboarding" )
|
self:AddTransition( "Loaded", "Unload", "Unboarding" )
|
||||||
@@ -144,6 +144,16 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet )
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
|
local Desc = HelicopterUnit:GetDesc()
|
||||||
|
self:F({Desc=Desc})
|
||||||
|
HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
||||||
|
--Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
end
|
||||||
|
|
||||||
|
self.Relocating = false
|
||||||
|
self.Transporting = false
|
||||||
|
|
||||||
self:SetCarrier( Helicopter )
|
self:SetCarrier( Helicopter )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@@ -380,7 +390,6 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To)
|
|||||||
self.BoardingCount = 0
|
self.BoardingCount = 0
|
||||||
|
|
||||||
if Helicopter and Helicopter:IsAlive() then
|
if Helicopter and Helicopter:IsAlive() then
|
||||||
self.Helicopter_Cargo = {}
|
|
||||||
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
||||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
@@ -393,10 +402,6 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To)
|
|||||||
Cargo:Board( HelicopterUnit, 25 )
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
self:__Board( 1, Cargo )
|
self:__Board( 1, Cargo )
|
||||||
Boarding = true
|
Boarding = true
|
||||||
|
|
||||||
-- So now this APCUnit has Cargo that is being loaded.
|
|
||||||
-- This will be used further in the logic to follow and to check cargo status.
|
|
||||||
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -424,7 +429,27 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
|||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo )
|
||||||
else
|
else
|
||||||
self:__Loaded( 1, Cargo )
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
|
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
||||||
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
|
if Cargo:IsUnLoaded() then
|
||||||
|
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
||||||
|
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
||||||
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
|
|
||||||
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
|
self:__Board( 10, Cargo )
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:__Loaded( 1, Cargo ) -- Will only be executed when no more cargo is boarded.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -438,24 +463,12 @@ end
|
|||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
||||||
-- @return #boolean Cargo is loaded.
|
-- @return #boolean Cargo is loaded.
|
||||||
function AI_CARGO_HELICOPTER:onbeforeLoaded( Helicopter, From, Event, To, Cargo )
|
function AI_CARGO_HELICOPTER:onafterLoaded( Helicopter, From, Event, To, Cargo )
|
||||||
self:F( { Helicopter, From, Event, To, Cargo } )
|
self:F( { Helicopter, From, Event, To, Cargo } )
|
||||||
|
|
||||||
local Loaded = true
|
|
||||||
|
|
||||||
if Helicopter and Helicopter:IsAlive() then
|
if Helicopter and Helicopter:IsAlive() then
|
||||||
for HelicopterUnit, Cargo in pairs( self.Helicopter_Cargo ) do
|
self.Transporting = true
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
|
||||||
self:F( { IsLoaded = Cargo:IsLoaded(), IsDestroyed = Cargo:IsDestroyed() } )
|
|
||||||
if not Cargo:IsLoaded() and not Cargo:IsDestroyed() then
|
|
||||||
Loaded = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Loaded
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -471,9 +484,11 @@ function AI_CARGO_HELICOPTER:onafterUnload( Helicopter, From, Event, To, Deploye
|
|||||||
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
||||||
for _, Cargo in pairs( HelicopterUnit:GetCargo() ) do
|
for _, Cargo in pairs( HelicopterUnit:GetCargo() ) do
|
||||||
Cargo:UnBoard()
|
if Cargo:IsLoaded() then
|
||||||
Cargo:SetDeployed( true )
|
Cargo:UnBoard()
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
Cargo:SetDeployed( true )
|
||||||
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -495,6 +510,17 @@ function AI_CARGO_HELICOPTER:onafterUnboard( Helicopter, From, Event, To, Cargo,
|
|||||||
if not Cargo:IsUnLoaded() then
|
if not Cargo:IsUnLoaded() then
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
else
|
else
|
||||||
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
|
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
||||||
|
for _, Cargo in pairs( HelicopterUnit:GetCargo() ) do
|
||||||
|
if Cargo:IsLoaded() then
|
||||||
|
Cargo:UnBoard()
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
self:__Unloaded( 1, Cargo, Deployed )
|
self:__Unloaded( 1, Cargo, Deployed )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -519,21 +545,16 @@ function AI_CARGO_HELICOPTER:onbeforeUnloaded( Helicopter, From, Event, To, Carg
|
|||||||
|
|
||||||
if Helicopter and Helicopter:IsAlive() then
|
if Helicopter and Helicopter:IsAlive() then
|
||||||
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
||||||
local CargoCheck = self.Helicopter_Cargo[HelicopterUnit] -- Cargo.Cargo#CARGO
|
local IsEmpty = HelicopterUnit:IsCargoEmpty()
|
||||||
if CargoCheck then
|
self:I({ IsEmpty = IsEmpty })
|
||||||
self:F( { CargoCheck:GetName(), IsUnLoaded = CargoCheck:IsUnLoaded() } )
|
if not IsEmpty then
|
||||||
if CargoCheck:IsUnLoaded() == false then
|
|
||||||
AllUnloaded = false
|
AllUnloaded = false
|
||||||
break
|
break
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if AllUnloaded == true then
|
if AllUnloaded == true then
|
||||||
if Deployed == true then
|
if Deployed == true then
|
||||||
for HelicopterUnit, Cargo in pairs( self.Helicopter_Cargo ) do
|
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
|
||||||
end
|
|
||||||
self.Helicopter_Cargo = {}
|
self.Helicopter_Cargo = {}
|
||||||
end
|
end
|
||||||
self.Helicopter = Helicopter
|
self.Helicopter = Helicopter
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ do -- CARGO_GROUP
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Then we register the new group in the database
|
-- Then we register the new group in the database
|
||||||
GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID )
|
self.CargoGroup = GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID )
|
||||||
|
|
||||||
-- Now we spawn the new group based on the template created.
|
-- Now we spawn the new group based on the template created.
|
||||||
self.CargoObject = _DATABASE:Spawn( GroupTemplate )
|
self.CargoObject = _DATABASE:Spawn( GroupTemplate )
|
||||||
|
|||||||
@@ -840,6 +840,17 @@ do -- Cargo
|
|||||||
self.__.Cargo = {}
|
self.__.Cargo = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Is cargo bay empty.
|
||||||
|
-- @param #POSITIONABLE self
|
||||||
|
function POSITIONABLE:IsCargoEmpty()
|
||||||
|
local IsEmpty = true
|
||||||
|
for _, Cargo in pairs( self.__.Cargo ) do
|
||||||
|
IsEmpty = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
return IsEmpty
|
||||||
|
end
|
||||||
|
|
||||||
--- Get cargo item count.
|
--- Get cargo item count.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @return Core.Cargo#CARGO Cargo
|
-- @return Core.Cargo#CARGO Cargo
|
||||||
|
|||||||
Reference in New Issue
Block a user