mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Updates on cargo handling of core engine.
This commit is contained in:
parent
42b04dedaa
commit
d4d05f4693
@ -418,11 +418,11 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
|
|
||||||
if APC and APC:IsAlive() then
|
if APC and APC:IsAlive() then
|
||||||
self.APC_Cargo = {}
|
self.APC_Cargo = {}
|
||||||
self.APC_Cargo_Weight = {}
|
|
||||||
for _, APCUnit in pairs( APC:GetUnits() ) do
|
for _, APCUnit in pairs( APC:GetUnits() ) do
|
||||||
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
||||||
|
|
||||||
self.APC_Cargo_Weight[APCUnit] = APCUnit:GetCargoBayFreeWeight()
|
local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight()
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
|
|
||||||
--for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
--for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
for _, Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
for _, Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
||||||
@ -432,10 +432,7 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
||||||
self:F( { "In radius", APCUnit:GetName() } )
|
self:F( { "In radius", APCUnit:GetName() } )
|
||||||
|
|
||||||
local CargoBayFreeWeight = self.APC_Cargo_Weight[APCUnit]
|
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
|
||||||
|
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
@ -447,7 +444,6 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
-- So now this APCUnit has Cargo that is being loaded.
|
-- 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.
|
-- This will be used further in the logic to follow and to check cargo status.
|
||||||
self.APC_Cargo[APCUnit] = Cargo
|
self.APC_Cargo[APCUnit] = Cargo
|
||||||
self.APC_Cargo_Weight[APCUnit] = self.APC_Cargo_Weight[APCUnit] - CargoWeight
|
|
||||||
Boarding = true
|
Boarding = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -477,14 +473,13 @@ function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo, APCUnit )
|
|||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo, APCUnit )
|
self:__Board( 10, Cargo, APCUnit )
|
||||||
else
|
else
|
||||||
|
local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight()
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
for _, Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
for _, Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
if Cargo:IsUnLoaded() then
|
if Cargo:IsUnLoaded() then
|
||||||
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
||||||
local CargoBayFreeWeight = self.APC_Cargo_Weight[APCUnit]
|
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
|
||||||
|
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
@ -493,7 +488,6 @@ function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo, APCUnit )
|
|||||||
-- So now this APCUnit has Cargo that is being loaded.
|
-- 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.
|
-- This will be used further in the logic to follow and to check cargo status.
|
||||||
self.APC_Cargo[APCUnit] = Cargo
|
self.APC_Cargo[APCUnit] = Cargo
|
||||||
self.APC_Cargo_Weight[APCUnit] = self.APC_Cargo_Weight[APCUnit] - CargoWeight
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -355,35 +355,44 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On after Load event. Checks if cargo is inside the load radius and if so starts the boarding process.
|
--- On before Load event. Checks if cargo is inside the load radius and if so starts the boarding process.
|
||||||
-- @param #AI_CARGO_AIRPLANE self
|
-- @param #AI_CARGO_AIRPLANE self
|
||||||
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
-- @param Wrapper.Group#GROUP Airplane Transport plane.
|
||||||
-- @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.
|
||||||
-- @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:onbeforeLoad( Airplane, From, Event, To, Coordinate )
|
||||||
|
|
||||||
|
|
||||||
|
local Boarding = false
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() ~= nil then
|
if Airplane and Airplane:IsAlive() ~= nil then
|
||||||
|
|
||||||
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
|
for _, AirplaneUnit in pairs( Airplane:GetUnits() ) do
|
||||||
self:F({_Cargo:GetName()})
|
local AirplaneUnit = AirplaneUnit -- Wrapper.Unit#UNIT
|
||||||
local Cargo=_Cargo --Cargo.Cargo#CARGO
|
for _,_Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
local InRadius = Cargo:IsInLoadRadius( Coordinate )
|
self:F({_Cargo:GetName()})
|
||||||
if InRadius then
|
local Cargo=_Cargo --Cargo.Cargo#CARGO
|
||||||
|
local InRadius = Cargo:IsInLoadRadius( Coordinate )
|
||||||
-- Is there a cargo still unloaded?
|
if InRadius then
|
||||||
if Cargo:IsUnLoaded() == true then
|
|
||||||
|
-- Is there a cargo still unloaded?
|
||||||
self:__Board( 5, Cargo )
|
if Cargo:IsUnLoaded() == true then
|
||||||
Cargo:Board( Airplane, 25 )
|
|
||||||
break
|
Cargo:Board( AirplaneUnit, 25 )
|
||||||
|
self:__Board( 5, Cargo, AirplaneUnit )
|
||||||
|
Boarding = true
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return Boarding
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after Board event. Cargo is inside the load radius and boarding is performed.
|
--- On after Board event. Cargo is inside the load radius and boarding is performed.
|
||||||
@ -392,17 +401,22 @@ 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, Cargo )
|
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
||||||
|
-- @param Wrapper.Unit#UNIT AirplaneUnit
|
||||||
|
function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo, AirplaneUnit )
|
||||||
|
|
||||||
if Airplane and Airplane:IsAlive() then
|
if Airplane and Airplane:IsAlive() then
|
||||||
|
|
||||||
self:F({ IsLoaded = Cargo:IsLoaded() } )
|
self:F({ IsLoaded = Cargo:IsLoaded() } )
|
||||||
|
|
||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo, AirplaneUnit )
|
||||||
else
|
else
|
||||||
|
local CargoBayFreeWeight = AirplaneUnit:GetCargoBayFreeWeight()
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
|
|
||||||
-- 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
|
for _,_Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
||||||
|
|
||||||
self:F({_Cargo:GetName()})
|
self:F({_Cargo:GetName()})
|
||||||
local Cargo =_Cargo --Cargo.Cargo#CARGO
|
local Cargo =_Cargo --Cargo.Cargo#CARGO
|
||||||
@ -465,18 +479,20 @@ 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
|
||||||
local Cargos = Airplane:GetCargo()
|
for _, AirplaneUnit in pairs( Airplane:GetUnits() ) do
|
||||||
for CargoID, Cargo in pairs( Cargos ) do
|
local Cargos = AirplaneUnit:GetCargo()
|
||||||
|
for CargoID, Cargo in pairs( Cargos ) do
|
||||||
local Angle = 180
|
|
||||||
local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees.
|
local Angle = 180
|
||||||
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees.
|
||||||
self:T( { CargoCarrierHeading, CargoDeployHeading } )
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading )
|
self:T( { CargoCarrierHeading, CargoDeployHeading } )
|
||||||
|
local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading )
|
||||||
Cargo:UnBoard( CargoDeployCoordinate )
|
|
||||||
Cargo:SetDeployed( true )
|
Cargo:UnBoard( CargoDeployCoordinate )
|
||||||
self:__Unboard( 10, Cargo )
|
Cargo:SetDeployed( true )
|
||||||
|
self:__Unboard( 10, Cargo )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -496,22 +512,24 @@ function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To, Cargo )
|
|||||||
if not Cargo:IsUnLoaded() then
|
if not Cargo:IsUnLoaded() then
|
||||||
self:__Unboard( 10, Cargo )
|
self:__Unboard( 10, Cargo )
|
||||||
else
|
else
|
||||||
local Cargos = Airplane:GetCargo()
|
for _, AirplaneUnit in pairs( Airplane:GetUnits() ) do
|
||||||
for CargoID, Cargo in pairs( Cargos ) do
|
local Cargos = AirplaneUnit:GetCargo()
|
||||||
if Cargo:IsLoaded() then
|
for CargoID, Cargo in pairs( Cargos ) do
|
||||||
local Angle = 180
|
if Cargo:IsLoaded() then
|
||||||
local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees.
|
local Angle = 180
|
||||||
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees.
|
||||||
self:T( { CargoCarrierHeading, CargoDeployHeading } )
|
local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle )
|
||||||
local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading )
|
self:T( { CargoCarrierHeading, CargoDeployHeading } )
|
||||||
Cargo:UnBoard( CargoDeployCoordinate )
|
local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading )
|
||||||
Cargo:SetDeployed( true )
|
Cargo:UnBoard( CargoDeployCoordinate )
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
self:__Unboard( 10, Cargo )
|
|
||||||
return
|
self:__Unboard( 10, Cargo )
|
||||||
end
|
return
|
||||||
end
|
end
|
||||||
self:__Unloaded( 1, Cargo )
|
end
|
||||||
|
self:__Unloaded( 1, Cargo )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -390,6 +390,9 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To)
|
|||||||
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 HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
||||||
|
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
|
|
||||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
self:F( { IsUnLoaded = Cargo:IsUnLoaded() } )
|
self:F( { IsUnLoaded = Cargo:IsUnLoaded() } )
|
||||||
@ -397,17 +400,14 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To)
|
|||||||
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
||||||
self:F( { "In radius", HelicopterUnit:GetName() } )
|
self:F( { "In radius", HelicopterUnit:GetName() } )
|
||||||
|
|
||||||
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
|
||||||
|
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
|
|
||||||
--Cargo:Ungroup()
|
--Cargo:Ungroup()
|
||||||
Cargo:Board( HelicopterUnit, 25 )
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
self:__Board( 1, Cargo )
|
self:__Board( 1, Cargo, HelicopterUnit )
|
||||||
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
||||||
Boarding = true
|
Boarding = true
|
||||||
break
|
break
|
||||||
@ -430,32 +430,29 @@ end
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
||||||
function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
-- @param Wrapper.Unit#UNIT HelicopterUnit
|
||||||
self:F( { Helicopter, From, Event, To, Cargo } )
|
function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo, HelicopterUnit )
|
||||||
|
self:F( { Helicopter, From, Event, To, Cargo, HelicopterUnit } )
|
||||||
|
|
||||||
if Helicopter and Helicopter:IsAlive() then
|
if Helicopter and Helicopter:IsAlive() then
|
||||||
self:F({ IsLoaded = Cargo:IsLoaded() } )
|
self:F({ IsLoaded = Cargo:IsLoaded() } )
|
||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo, HelicopterUnit )
|
||||||
else
|
else
|
||||||
for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do
|
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
||||||
local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
if Cargo:IsUnLoaded() then
|
if Cargo:IsUnLoaded() then
|
||||||
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
||||||
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
local CargoWeight = Cargo:GetWeight()
|
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
self:__Board( 10, Cargo, HelicopterUnit )
|
||||||
Cargo:Board( HelicopterUnit, 25 )
|
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
||||||
self:__Board( 10, Cargo )
|
return
|
||||||
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user