diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 28a71989f..75f3f2873 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -37,7 +37,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" ) self:AddTransition( "Loaded", "Deploy", "*" ) - self:AddTransition( { "Unloaded", "Loaded" }, "Load", "Boarding" ) + self:AddTransition( { "Unloaded", "Boarding" }, "Load", "Boarding" ) self:AddTransition( "Boarding", "Board", "Boarding" ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) @@ -128,8 +128,13 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- Set carrier. self:SetCarrier( Airplane ) - Airplane:SetCargoBayWeightLimit( 5000 ) - Airplane:SetCargoBayVolumeLimit( 15 ) + local Desc = Airplane:GetUnit(1):GetDesc() + + self:F({Desc=Desc}) + + + Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) + --Airplane:SetCargoBayVolumeLimit( 15 ) 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. self.Airbase = Airbase - -- Unclear?! - self.Transporting = false + self.Transporting = true self.Relocating = false end @@ -398,6 +402,38 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo ) if not Cargo:IsLoaded() then self:__Board( 10, Cargo ) 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 ) end end @@ -415,41 +451,8 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To, Cargo ) env.info("FF troops loaded into cargo plane") if Airplane and Airplane:IsAlive() then - - -- 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 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! + 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 diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 9a5082f52..c7a0ea4b9 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -405,7 +405,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() -- Check if this Carrier need to go and Pickup something... -- So, if the cargo bay is not full yet with cargo to be loaded ... 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 -- now find the first cargo that is Unloaded diff --git a/Moose Development/Moose/Cargo/Cargo.lua b/Moose Development/Moose/Cargo/Cargo.lua index e0b6f4d4a..50cade298 100644 --- a/Moose Development/Moose/Cargo/Cargo.lua +++ b/Moose Development/Moose/Cargo/Cargo.lua @@ -1020,13 +1020,27 @@ do -- CARGO_REPRESENTABLE -- @param #CARGO_REPRESENTABLE self -- @param #string Type -- @param #string Name - -- @param #number Weight -- @param #number LoadRadius (optional) -- @param #number NearRadius (optional) -- @return #CARGO_REPRESENTABLE - function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, Weight, LoadRadius, NearRadius ) - local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE - self:F( { Type, Name, Weight, LoadRadius, NearRadius } ) + function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, LoadRadius, NearRadius ) + local self = BASE:Inherit( self, CARGO:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE + 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 end diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index b7c78a713..72a3430cf 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -107,32 +107,19 @@ do -- CARGO_GROUP self.CargoObject = _DATABASE:Spawn( GroupTemplate ) 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 Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, 0, LoadRadius, NearRadius ) - Cargo:SetWeight( WeightUnit ) - Cargo:SetVolume( VolumeUnit ) + local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, LoadRadius, NearRadius ) self.CargoSet:Add( CargoUnitName, Cargo ) - WeightGroup = WeightGroup + WeightUnit - VolumeGroup = VolumeGroup + VolumeUnit + WeightGroup = WeightGroup + Cargo:GetWeight() + --VolumeGroup = VolumeGroup + VolumeUnit end self:SetWeight( WeightGroup ) - self.CargoLimit = 10 self:T( { "Weight Cargo", WeightGroup } ) diff --git a/Moose Development/Moose/Cargo/CargoUnit.lua b/Moose Development/Moose/Cargo/CargoUnit.lua index c7992256c..90eceeda9 100644 --- a/Moose Development/Moose/Cargo/CargoUnit.lua +++ b/Moose Development/Moose/Cargo/CargoUnit.lua @@ -42,9 +42,9 @@ do -- CARGO_UNIT -- @param #number LoadRadius (optional) -- @param #number NearRadius (optional) -- @return #CARGO_UNIT - function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) - local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_UNIT - self:I( { 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, LoadRadius, NearRadius ) ) -- #CARGO_UNIT + self:I( { Type, Name, LoadRadius, NearRadius } ) self:T( CargoUnit ) self.CargoObject = CargoUnit diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 44fa06d52..1de5c21fe 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -851,17 +851,17 @@ do -- Cargo return ItemCount end - --- Get Cargo Bay Free Volume in m3. - -- @param #POSITIONABLE self - -- @return #number CargoBayFreeVolume - function POSITIONABLE:GetCargoBayFreeVolume() - local CargoVolume = 0 - for CargoName, Cargo in pairs( self.__.Cargo ) do - CargoVolume = CargoVolume + Cargo:GetVolume() - end - return self.__.CargoBayVolumeLimit - CargoVolume - end - +-- --- Get Cargo Bay Free Volume in m3. +-- -- @param #POSITIONABLE self +-- -- @return #number CargoBayFreeVolume +-- function POSITIONABLE:GetCargoBayFreeVolume() +-- local CargoVolume = 0 +-- for CargoName, Cargo in pairs( self.__.Cargo ) do +-- CargoVolume = CargoVolume + Cargo:GetVolume() +-- end +-- return self.__.CargoBayVolumeLimit - CargoVolume +-- end +-- --- Get Cargo Bay Free Weight in kg. -- @param #POSITIONABLE self -- @return #number CargoBayFreeWeight @@ -874,13 +874,13 @@ do -- Cargo return self.__.CargoBayWeightLimit - CargoWeight end - --- Get Cargo Bay Volume Limit in m3. - -- @param #POSITIONABLE self - -- @param #number VolumeLimit - function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit ) - self.__.CargoBayVolumeLimit = VolumeLimit - end - +-- --- Get Cargo Bay Volume Limit in m3. +-- -- @param #POSITIONABLE self +-- -- @param #number VolumeLimit +-- function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit ) +-- self.__.CargoBayVolumeLimit = VolumeLimit +-- end + --- Get Cargo Bay Weight Limit in kg. -- @param #POSITIONABLE self -- @param #number WeightLimit