mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
- 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:
@@ -34,10 +34,10 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
|
|
||||||
self:SetStartState( "Unloaded" )
|
self:SetStartState( "Unloaded" )
|
||||||
|
|
||||||
self:AddTransition( "Unloaded", "Pickup", "*" )
|
self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" )
|
||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
|
|
||||||
self:AddTransition( "Unloaded", "Load", "Boarding" )
|
self:AddTransition( { "Unloaded", "Loaded" }, "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,6 +128,11 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet )
|
|||||||
-- Set carrier.
|
-- Set carrier.
|
||||||
self:SetCarrier( Airplane )
|
self:SetCarrier( Airplane )
|
||||||
|
|
||||||
|
Airplane:SetCargoBayWeightLimit( 5000 )
|
||||||
|
Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
|
||||||
|
self.Relocating = true
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -188,6 +193,7 @@ function AI_CARGO_AIRPLANE:SetCarrier( Airplane )
|
|||||||
|
|
||||||
|
|
||||||
function Airplane:OnEventEngineShutdown( EventData )
|
function Airplane:OnEventEngineShutdown( EventData )
|
||||||
|
AICargo.Relocating = false
|
||||||
AICargo:Landed( self.Airplane )
|
AICargo:Landed( self.Airplane )
|
||||||
end
|
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.
|
-- @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 )
|
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
|
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
self:F({_Cargo:GetName()})
|
self:F({_Cargo:GetName()})
|
||||||
local Cargo=_Cargo --Cargo.Cargo#CARGO
|
local Cargo=_Cargo --Cargo.Cargo#CARGO
|
||||||
local InRadius = Cargo:IsInLoadRadius( Coordinate )
|
local InRadius = Cargo:IsInLoadRadius( Coordinate )
|
||||||
if InRadius then
|
if InRadius then
|
||||||
self:__Board( 5 )
|
|
||||||
Cargo:Board( Airplane, 25 )
|
-- Is there a cargo still unloaded?
|
||||||
self.Cargo = Cargo
|
if Cargo:IsUnLoaded() == true then
|
||||||
break
|
|
||||||
|
self:__Board( 5, Cargo )
|
||||||
|
Cargo:Board( Airplane, 25 )
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -379,14 +389,16 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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
|
if Airplane and Airplane:IsAlive() then
|
||||||
self:F({ IsLoaded = self.Cargo:IsLoaded() } )
|
|
||||||
if not self.Cargo:IsLoaded() then
|
self:F({ IsLoaded = Cargo:IsLoaded() } )
|
||||||
self:__Board( 10 )
|
|
||||||
|
if not Cargo:IsLoaded() then
|
||||||
|
self:__Board( 10, Cargo )
|
||||||
else
|
else
|
||||||
self:__Loaded( 1 )
|
self:__Loaded( 1, Cargo )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -398,12 +410,46 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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")
|
env.info("FF troops loaded into cargo plane")
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
|
|
||||||
-- Check if another cargo can be loaded into the airplane.
|
-- 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
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -418,8 +464,11 @@ end
|
|||||||
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
self.Cargo:UnBoard()
|
local Cargos = Airplane:GetCargo()
|
||||||
self:__Unboard( 10 )
|
for CargoID, Cargo in pairs( Cargos ) do
|
||||||
|
Cargo:UnBoard()
|
||||||
|
self:__Unboard( 10, Cargo )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -430,13 +479,13 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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 Airplane and Airplane:IsAlive() then
|
||||||
if not self.Cargo:IsUnLoaded() then
|
if not Cargo:IsUnLoaded() then
|
||||||
self:__Unboard( 10 )
|
self:__Unboard( 10, Cargo )
|
||||||
else
|
else
|
||||||
self:__Unloaded( 1 )
|
self:__Unloaded( 1, Cargo )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -448,7 +497,7 @@ end
|
|||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @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
|
if Airplane and Airplane:IsAlive() then
|
||||||
self.Airplane = Airplane
|
self.Airplane = Airplane
|
||||||
|
|||||||
@@ -404,8 +404,8 @@ 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( { IsTransporting = AI_Cargo:IsTransporting() } )
|
self:I( { IsRelocating = AI_Cargo:IsRelocating() } )
|
||||||
if AI_Cargo:IsTransporting() == false then
|
if AI_Cargo:IsRelocating() == 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
|
||||||
|
|
||||||
@@ -560,9 +560,11 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo )
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.DeployAirbasesSet then
|
if self.DeployAirbasesSet then
|
||||||
|
|
||||||
local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase()
|
if self.AI_Cargo[Carrier]:IsTransporting() == true then
|
||||||
self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) )
|
local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase()
|
||||||
|
self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.PickupCargo[Carrier] = nil
|
self.PickupCargo[Carrier] = nil
|
||||||
|
|||||||
@@ -875,6 +875,13 @@ do -- CARGO
|
|||||||
return self.CargoObject:GetCoordinate()
|
return self.CargoObject:GetCoordinate()
|
||||||
end
|
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.
|
--- Set the weight of the cargo.
|
||||||
-- @param #CARGO self
|
-- @param #CARGO self
|
||||||
-- @param #number Weight The weight in kg.
|
-- @param #number Weight The weight in kg.
|
||||||
@@ -884,6 +891,22 @@ do -- CARGO
|
|||||||
return self
|
return self
|
||||||
end
|
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}.
|
--- Send a CC message to a @{Wrapper.Group}.
|
||||||
-- @param #CARGO self
|
-- @param #CARGO self
|
||||||
-- @param #string Message
|
-- @param #string Message
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ do -- CARGO_GROUP
|
|||||||
self:SetDeployed( false )
|
self:SetDeployed( false )
|
||||||
|
|
||||||
local WeightGroup = 0
|
local WeightGroup = 0
|
||||||
|
local VolumeGroup = 0
|
||||||
|
|
||||||
self.CargoGroup:Destroy()
|
self.CargoGroup:Destroy()
|
||||||
|
|
||||||
@@ -96,10 +97,7 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
-- And we register the spawned unit as part of the CargoSet.
|
-- And we register the spawned unit as part of the CargoSet.
|
||||||
local Unit = UNIT:Register( CargoUnitName )
|
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
|
end
|
||||||
|
|
||||||
-- Then we register the new group in the database
|
-- 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.
|
-- Now we spawn the new group based on the template created.
|
||||||
self.CargoObject = _DATABASE:Spawn( GroupTemplate )
|
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:SetWeight( WeightGroup )
|
||||||
self.CargoLimit = 10
|
self.CargoLimit = 10
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ end
|
|||||||
function IDENTIFIABLE:GetDesc()
|
function IDENTIFIABLE:GetDesc()
|
||||||
self:F2( self.IdentifiableName )
|
self:F2( self.IdentifiableName )
|
||||||
|
|
||||||
local DCSIdentifiable = self:GetDCSObject()
|
local DCSIdentifiable = self:GetDCSObject() -- DCS#Object
|
||||||
|
|
||||||
if DCSIdentifiable then
|
if DCSIdentifiable then
|
||||||
local IdentifiableDesc = DCSIdentifiable:getDesc()
|
local IdentifiableDesc = DCSIdentifiable:getDesc()
|
||||||
|
|||||||
@@ -868,6 +868,7 @@ do -- Cargo
|
|||||||
function POSITIONABLE:GetCargoBayFreeWeight()
|
function POSITIONABLE:GetCargoBayFreeWeight()
|
||||||
local CargoWeight = 0
|
local CargoWeight = 0
|
||||||
for CargoName, Cargo in pairs( self.__.Cargo ) do
|
for CargoName, Cargo in pairs( self.__.Cargo ) do
|
||||||
|
self:F( { Cargo = Cargo } )
|
||||||
CargoWeight = CargoWeight + Cargo:GetWeight()
|
CargoWeight = CargoWeight + Cargo:GetWeight()
|
||||||
end
|
end
|
||||||
return self.__.CargoBayWeightLimit - CargoWeight
|
return self.__.CargoBayWeightLimit - CargoWeight
|
||||||
@@ -883,7 +884,7 @@ do -- Cargo
|
|||||||
--- 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
|
||||||
function POSITIONABLE:GetCargoBayFreeWeightLimit( WeightLimit )
|
function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit )
|
||||||
self.__.CargoBayWeightLimit = WeightLimit
|
self.__.CargoBayWeightLimit = WeightLimit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user