mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Got the airplanes finally to load together ...
This commit is contained in:
parent
7f9f9b33fd
commit
74e9599df9
@ -37,7 +37,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" )
|
self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" )
|
||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
|
|
||||||
self:AddTransition( { "Unloaded", "Loaded" }, "Load", "Boarding" )
|
self:AddTransition( { "Unloaded", "Boarding" }, "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" )
|
||||||
@ -128,8 +128,13 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
-- Set carrier.
|
-- Set carrier.
|
||||||
self:SetCarrier( Airplane )
|
self:SetCarrier( Airplane )
|
||||||
|
|
||||||
Airplane:SetCargoBayWeightLimit( 5000 )
|
local Desc = Airplane:GetUnit(1):GetDesc()
|
||||||
Airplane:SetCargoBayVolumeLimit( 15 )
|
|
||||||
|
self:F({Desc=Desc})
|
||||||
|
|
||||||
|
|
||||||
|
Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
||||||
|
--Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
|
||||||
self.Relocating = true
|
self.Relocating = true
|
||||||
|
|
||||||
@ -344,8 +349,7 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp
|
|||||||
-- Set destination airbase for next :Route() command.
|
-- Set destination airbase for next :Route() command.
|
||||||
self.Airbase = Airbase
|
self.Airbase = Airbase
|
||||||
|
|
||||||
-- Unclear?!
|
self.Transporting = true
|
||||||
self.Transporting = false
|
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -398,6 +402,38 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo )
|
|||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo )
|
||||||
else
|
else
|
||||||
|
-- Check if another cargo can be loaded into the airplane.
|
||||||
|
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
|
|
||||||
|
self:F({_Cargo:GetName()})
|
||||||
|
local Cargo =_Cargo --Cargo.Cargo#CARGO
|
||||||
|
|
||||||
|
-- Is there a cargo still unloaded?
|
||||||
|
if Cargo:IsUnLoaded() == true then
|
||||||
|
|
||||||
|
-- Only when the cargo is within load radius.
|
||||||
|
local InRadius = Cargo:IsInLoadRadius( Airplane:GetCoordinate() )
|
||||||
|
if InRadius then
|
||||||
|
|
||||||
|
local CargoBayFreeWeight = Airplane:GetCargoBayFreeWeight()
|
||||||
|
--local CargoBayFreeVolume = Airplane:GetCargoBayFreeVolume()
|
||||||
|
|
||||||
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
--local CargoVolume = Cargo:GetVolume()
|
||||||
|
|
||||||
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
|
|
||||||
|
-- ok, board.
|
||||||
|
self:__Load( 5, Airplane:GetCoordinate() )
|
||||||
|
|
||||||
|
-- And start the boarding loop for the AI_CARGO_AIRPLANE object until the cargo is boarded.
|
||||||
|
--Cargo:Board( Airplane, 25 )
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
self:__Loaded( 1, Cargo )
|
self:__Loaded( 1, Cargo )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -415,41 +451,8 @@ 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" } )
|
||||||
-- Check if another cargo can be loaded into the airplane.
|
self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle!
|
||||||
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
|
|
||||||
|
|
||||||
self:F({_Cargo:GetName()})
|
|
||||||
local Cargo =_Cargo --Cargo.Cargo#CARGO
|
|
||||||
|
|
||||||
-- Is there a cargo still unloaded?
|
|
||||||
if Cargo:IsUnLoaded() == true then
|
|
||||||
|
|
||||||
-- Only when the cargo is within load radius.
|
|
||||||
local InRadius = Cargo:IsInLoadRadius( Airplane:GetCoordinate() )
|
|
||||||
if InRadius then
|
|
||||||
|
|
||||||
local CargoBayFreeWeight = Airplane:GetCargoBayFreeWeight()
|
|
||||||
local CargoBayFreeVolume = Airplane:GetCargoBayFreeVolume()
|
|
||||||
|
|
||||||
local CargoWeight = Cargo:GetWeight()
|
|
||||||
local CargoVolume = Cargo:GetVolume()
|
|
||||||
|
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
|
||||||
if CargoBayFreeWeight > CargoWeight and CargoBayFreeVolume > CargoVolume then
|
|
||||||
|
|
||||||
-- ok, board.
|
|
||||||
self:__Load( 5, Airplane:GetCoordinate() )
|
|
||||||
|
|
||||||
-- And start the boarding loop for the AI_CARGO_AIRPLANE object until the cargo is boarded.
|
|
||||||
--Cargo:Board( Airplane, 25 )
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
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!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -405,7 +405,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
-- 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() } )
|
||||||
if AI_Cargo:IsRelocating() == 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
|
||||||
|
|
||||||
|
|||||||
@ -1020,13 +1020,27 @@ do -- CARGO_REPRESENTABLE
|
|||||||
-- @param #CARGO_REPRESENTABLE self
|
-- @param #CARGO_REPRESENTABLE self
|
||||||
-- @param #string Type
|
-- @param #string Type
|
||||||
-- @param #string Name
|
-- @param #string Name
|
||||||
-- @param #number Weight
|
|
||||||
-- @param #number LoadRadius (optional)
|
-- @param #number LoadRadius (optional)
|
||||||
-- @param #number NearRadius (optional)
|
-- @param #number NearRadius (optional)
|
||||||
-- @return #CARGO_REPRESENTABLE
|
-- @return #CARGO_REPRESENTABLE
|
||||||
function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, Weight, LoadRadius, NearRadius )
|
function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, LoadRadius, NearRadius )
|
||||||
local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE
|
local self = BASE:Inherit( self, CARGO:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE
|
||||||
self:F( { Type, Name, Weight, LoadRadius, NearRadius } )
|
self:F( { Type, Name, LoadRadius, NearRadius } )
|
||||||
|
|
||||||
|
local Desc = CargoObject:GetDesc()
|
||||||
|
self:I( { Desc = Desc } )
|
||||||
|
local Weight = math.random( 80, 120 )
|
||||||
|
if Desc then
|
||||||
|
Weight = Desc.massEmpty
|
||||||
|
end
|
||||||
|
|
||||||
|
self:SetWeight( Weight )
|
||||||
|
|
||||||
|
-- local Box = CargoUnit:GetBoundingBox()
|
||||||
|
-- local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z )
|
||||||
|
-- self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } )
|
||||||
|
--self:SetVolume( VolumeUnit )
|
||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@ -107,32 +107,19 @@ do -- CARGO_GROUP
|
|||||||
self.CargoObject = _DATABASE:Spawn( GroupTemplate )
|
self.CargoObject = _DATABASE:Spawn( GroupTemplate )
|
||||||
|
|
||||||
for CargoUnitID, CargoUnit in pairs( self.CargoObject:GetUnits() ) do
|
for CargoUnitID, CargoUnit in pairs( self.CargoObject:GetUnits() ) do
|
||||||
local Desc = CargoUnit:GetDesc()
|
|
||||||
self:I( { Desc = Desc } )
|
|
||||||
local WeightUnit = math.random( 80, 120 )
|
|
||||||
if Desc then
|
|
||||||
WeightUnit = Desc.massEmpty
|
|
||||||
end
|
|
||||||
|
|
||||||
local Box = CargoUnit:GetBoundingBox()
|
|
||||||
local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z )
|
|
||||||
self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } )
|
|
||||||
|
|
||||||
|
|
||||||
local CargoUnitName = CargoUnit:GetName()
|
local CargoUnitName = CargoUnit:GetName()
|
||||||
|
|
||||||
local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, 0, LoadRadius, NearRadius )
|
local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, LoadRadius, NearRadius )
|
||||||
Cargo:SetWeight( WeightUnit )
|
|
||||||
Cargo:SetVolume( VolumeUnit )
|
|
||||||
self.CargoSet:Add( CargoUnitName, Cargo )
|
self.CargoSet:Add( CargoUnitName, Cargo )
|
||||||
|
|
||||||
WeightGroup = WeightGroup + WeightUnit
|
WeightGroup = WeightGroup + Cargo:GetWeight()
|
||||||
VolumeGroup = VolumeGroup + VolumeUnit
|
--VolumeGroup = VolumeGroup + VolumeUnit
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:SetWeight( WeightGroup )
|
self:SetWeight( WeightGroup )
|
||||||
self.CargoLimit = 10
|
|
||||||
|
|
||||||
self:T( { "Weight Cargo", WeightGroup } )
|
self:T( { "Weight Cargo", WeightGroup } )
|
||||||
|
|
||||||
|
|||||||
@ -42,9 +42,9 @@ do -- CARGO_UNIT
|
|||||||
-- @param #number LoadRadius (optional)
|
-- @param #number LoadRadius (optional)
|
||||||
-- @param #number NearRadius (optional)
|
-- @param #number NearRadius (optional)
|
||||||
-- @return #CARGO_UNIT
|
-- @return #CARGO_UNIT
|
||||||
function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius )
|
function CARGO_UNIT:New( CargoUnit, Type, Name, LoadRadius, NearRadius )
|
||||||
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
|
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
|
||||||
self:I( { Type, Name, Weight, LoadRadius, NearRadius } )
|
self:I( { Type, Name, LoadRadius, NearRadius } )
|
||||||
|
|
||||||
self:T( CargoUnit )
|
self:T( CargoUnit )
|
||||||
self.CargoObject = CargoUnit
|
self.CargoObject = CargoUnit
|
||||||
|
|||||||
@ -851,17 +851,17 @@ do -- Cargo
|
|||||||
return ItemCount
|
return ItemCount
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get Cargo Bay Free Volume in m3.
|
-- --- Get Cargo Bay Free Volume in m3.
|
||||||
-- @param #POSITIONABLE self
|
-- -- @param #POSITIONABLE self
|
||||||
-- @return #number CargoBayFreeVolume
|
-- -- @return #number CargoBayFreeVolume
|
||||||
function POSITIONABLE:GetCargoBayFreeVolume()
|
-- function POSITIONABLE:GetCargoBayFreeVolume()
|
||||||
local CargoVolume = 0
|
-- local CargoVolume = 0
|
||||||
for CargoName, Cargo in pairs( self.__.Cargo ) do
|
-- for CargoName, Cargo in pairs( self.__.Cargo ) do
|
||||||
CargoVolume = CargoVolume + Cargo:GetVolume()
|
-- CargoVolume = CargoVolume + Cargo:GetVolume()
|
||||||
end
|
-- end
|
||||||
return self.__.CargoBayVolumeLimit - CargoVolume
|
-- return self.__.CargoBayVolumeLimit - CargoVolume
|
||||||
end
|
-- end
|
||||||
|
--
|
||||||
--- Get Cargo Bay Free Weight in kg.
|
--- Get Cargo Bay Free Weight in kg.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @return #number CargoBayFreeWeight
|
-- @return #number CargoBayFreeWeight
|
||||||
@ -874,13 +874,13 @@ do -- Cargo
|
|||||||
return self.__.CargoBayWeightLimit - CargoWeight
|
return self.__.CargoBayWeightLimit - CargoWeight
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get Cargo Bay Volume Limit in m3.
|
-- --- Get Cargo Bay Volume Limit in m3.
|
||||||
-- @param #POSITIONABLE self
|
-- -- @param #POSITIONABLE self
|
||||||
-- @param #number VolumeLimit
|
-- -- @param #number VolumeLimit
|
||||||
function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit )
|
-- function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit )
|
||||||
self.__.CargoBayVolumeLimit = VolumeLimit
|
-- self.__.CargoBayVolumeLimit = VolumeLimit
|
||||||
end
|
-- end
|
||||||
|
|
||||||
--- Get Cargo Bay Weight Limit in kg.
|
--- Get Cargo Bay Weight Limit in kg.
|
||||||
-- @param #POSITIONABLE self
|
-- @param #POSITIONABLE self
|
||||||
-- @param #number WeightLimit
|
-- @param #number WeightLimit
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user