- Have added cargo bay limits based on volume and weight.

- AI Cargo Dispatcher works with cargo bay limits for carrier. (i still need to add options to set the parameters for this).
- Carriers load now multiple cargo.
- Added weight and volume attached to cargo objects for units. I reworked the respawning of cargo units, so that these volumes and weights are collected from the unit Descriptor properties!
- There are still bugs, which I need to resolve, but it is going in the right direction.
This commit is contained in:
FlightControl 2018-08-11 11:33:43 +02:00
parent a14c2ef589
commit 7f9f9b33fd
6 changed files with 129 additions and 31 deletions

View File

@ -34,10 +34,10 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
self:SetStartState( "Unloaded" )
self:AddTransition( "Unloaded", "Pickup", "*" )
self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" )
self:AddTransition( "Loaded", "Deploy", "*" )
self:AddTransition( "Unloaded", "Load", "Boarding" )
self:AddTransition( { "Unloaded", "Loaded" }, "Load", "Boarding" )
self:AddTransition( "Boarding", "Board", "Boarding" )
self:AddTransition( "Boarding", "Loaded", "Loaded" )
self:AddTransition( "Loaded", "Unload", "Unboarding" )
@ -128,6 +128,11 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
-- Set carrier.
self:SetCarrier( Airplane )
Airplane:SetCargoBayWeightLimit( 5000 )
Airplane:SetCargoBayVolumeLimit( 15 )
self.Relocating = true
return self
end
@ -188,6 +193,7 @@ function AI_CARGO_AIRPLANE:SetCarrier( Airplane )
function Airplane:OnEventEngineShutdown( EventData )
AICargo.Relocating = false
AICargo:Landed( self.Airplane )
end
@ -355,17 +361,21 @@ end
-- @param Wrapper.Point#COORDINATE Coordinate Place where the cargo is guided to if it is inside the load radius.
function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate )
if Airplane and Airplane:IsAlive()~=nil then
if Airplane and Airplane:IsAlive() ~= nil then
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
self:F({_Cargo:GetName()})
local Cargo=_Cargo --Cargo.Cargo#CARGO
local InRadius = Cargo:IsInLoadRadius( Coordinate )
if InRadius then
self:__Board( 5 )
Cargo:Board( Airplane, 25 )
self.Cargo = Cargo
break
-- Is there a cargo still unloaded?
if Cargo:IsUnLoaded() == true then
self:__Board( 5, Cargo )
Cargo:Board( Airplane, 25 )
break
end
end
end
@ -379,14 +389,16 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To )
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo )
if Airplane and Airplane:IsAlive() then
self:F({ IsLoaded = self.Cargo:IsLoaded() } )
if not self.Cargo:IsLoaded() then
self:__Board( 10 )
self:F({ IsLoaded = Cargo:IsLoaded() } )
if not Cargo:IsLoaded() then
self:__Board( 10, Cargo )
else
self:__Loaded( 1 )
self:__Loaded( 1, Cargo )
end
end
@ -398,12 +410,46 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To )
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!
end
end
@ -418,8 +464,11 @@ end
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
if Airplane and Airplane:IsAlive() then
self.Cargo:UnBoard()
self:__Unboard( 10 )
local Cargos = Airplane:GetCargo()
for CargoID, Cargo in pairs( Cargos ) do
Cargo:UnBoard()
self:__Unboard( 10, Cargo )
end
end
end
@ -430,13 +479,13 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To )
function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To, Cargo )
if Airplane and Airplane:IsAlive() then
if not self.Cargo:IsUnLoaded() then
self:__Unboard( 10 )
if not Cargo:IsUnLoaded() then
self:__Unboard( 10, Cargo )
else
self:__Unloaded( 1 )
self:__Unloaded( 1, Cargo )
end
end
@ -448,7 +497,7 @@ end
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To )
function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To, Cargo )
if Airplane and Airplane:IsAlive() then
self.Airplane = Airplane

View File

@ -404,8 +404,8 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
-- The Pickup sequence ...
-- 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( { IsTransporting = AI_Cargo:IsTransporting() } )
if AI_Cargo:IsTransporting() == false then
self:I( { IsRelocating = AI_Cargo:IsRelocating() } )
if AI_Cargo:IsRelocating() == false then
-- ok, so there is a free Carrier
-- now find the first cargo that is Unloaded
@ -560,9 +560,11 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo )
end
if self.DeployAirbasesSet then
local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase()
self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) )
if self.AI_Cargo[Carrier]:IsTransporting() == true then
local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase()
self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) )
end
end
self.PickupCargo[Carrier] = nil

View File

@ -875,6 +875,13 @@ do -- CARGO
return self.CargoObject:GetCoordinate()
end
--- Get the weight of the cargo.
-- @param #CARGO self
-- @return #number Weight The weight in kg.
function CARGO:GetWeight()
return self.Weight
end
--- Set the weight of the cargo.
-- @param #CARGO self
-- @param #number Weight The weight in kg.
@ -884,6 +891,22 @@ do -- CARGO
return self
end
--- Get the volume of the cargo.
-- @param #CARGO self
-- @return #number Volume The volume in kg.
function CARGO:GetVolume()
return self.Volume
end
--- Set the volume of the cargo.
-- @param #CARGO self
-- @param #number Volume The volume in kg.
-- @return #CARGO
function CARGO:SetVolume( Volume )
self.Volume = Volume
return self
end
--- Send a CC message to a @{Wrapper.Group}.
-- @param #CARGO self
-- @param #string Message

View File

@ -73,6 +73,7 @@ do -- CARGO_GROUP
self:SetDeployed( false )
local WeightGroup = 0
local VolumeGroup = 0
self.CargoGroup:Destroy()
@ -96,10 +97,7 @@ do -- CARGO_GROUP
-- And we register the spawned unit as part of the CargoSet.
local Unit = UNIT:Register( CargoUnitName )
--local WeightUnit = Unit:GetDesc().massEmpty
--WeightGroup = WeightGroup + WeightUnit
local CargoUnit = CARGO_UNIT:New( Unit, Type, CargoUnitName, 10, LoadRadius, NearRadius )
self.CargoSet:Add( CargoUnitName, CargoUnit )
end
-- Then we register the new group in the database
@ -107,6 +105,31 @@ do -- CARGO_GROUP
-- Now we spawn the new group based on the template created.
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 )
self.CargoSet:Add( CargoUnitName, Cargo )
WeightGroup = WeightGroup + WeightUnit
VolumeGroup = VolumeGroup + VolumeUnit
end
self:SetWeight( WeightGroup )
self.CargoLimit = 10

View File

@ -216,7 +216,7 @@ end
function IDENTIFIABLE:GetDesc()
self:F2( self.IdentifiableName )
local DCSIdentifiable = self:GetDCSObject()
local DCSIdentifiable = self:GetDCSObject() -- DCS#Object
if DCSIdentifiable then
local IdentifiableDesc = DCSIdentifiable:getDesc()

View File

@ -868,6 +868,7 @@ do -- Cargo
function POSITIONABLE:GetCargoBayFreeWeight()
local CargoWeight = 0
for CargoName, Cargo in pairs( self.__.Cargo ) do
self:F( { Cargo = Cargo } )
CargoWeight = CargoWeight + Cargo:GetWeight()
end
return self.__.CargoBayWeightLimit - CargoWeight
@ -883,7 +884,7 @@ do -- Cargo
--- Get Cargo Bay Weight Limit in kg.
-- @param #POSITIONABLE self
-- @param #number WeightLimit
function POSITIONABLE:GetCargoBayFreeWeightLimit( WeightLimit )
function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit )
self.__.CargoBayWeightLimit = WeightLimit
end