mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Cargo Dispatcher APC - Multiple Cargo Groups and Weight in APC
This commit is contained in:
@@ -96,7 +96,7 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius )
|
|||||||
self:AddTransition( "Loaded", "Deploy", "*" )
|
self:AddTransition( "Loaded", "Deploy", "*" )
|
||||||
|
|
||||||
self:AddTransition( "*", "Load", "Boarding" )
|
self:AddTransition( "*", "Load", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Board", "Boarding" )
|
self:AddTransition( { "Boarding", "Loaded" }, "Board", "Boarding" )
|
||||||
self:AddTransition( "Boarding", "Loaded", "Loaded" )
|
self:AddTransition( "Boarding", "Loaded", "Loaded" )
|
||||||
self:AddTransition( "Loaded", "Unload", "Unboarding" )
|
self:AddTransition( "Loaded", "Unload", "Unboarding" )
|
||||||
self:AddTransition( "Unboarding", "Unboard", "Unboarding" )
|
self:AddTransition( "Unboarding", "Unboard", "Unboarding" )
|
||||||
@@ -194,8 +194,20 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius )
|
|||||||
|
|
||||||
self:__Monitor( 1 )
|
self:__Monitor( 1 )
|
||||||
|
|
||||||
|
|
||||||
self:SetCarrier( APC )
|
self:SetCarrier( APC )
|
||||||
|
|
||||||
|
for _, APCUnit in pairs( APC:GetUnits() ) do
|
||||||
|
local Desc = APCUnit:GetDesc()
|
||||||
|
self:F({Desc=Desc})
|
||||||
|
-- local Box = CargoUnit:GetBoundingBox()
|
||||||
|
local VolumeUnit = ( Desc.box.max.x - Desc.box.min.x ) * ( Desc.box.max.y - Desc.box.min.y ) * ( Desc.box.max.z - Desc.box.min.z )
|
||||||
|
self:F({VolumeUnit=VolumeUnit})
|
||||||
|
local CargoBayWeightLimit = 1250
|
||||||
|
APCUnit:SetCargoBayWeightLimit( CargoBayWeightLimit )
|
||||||
|
self:F({CargoBayWeightLimit=CargoBayWeightLimit})
|
||||||
|
--Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
end
|
||||||
|
|
||||||
self.Transporting = false
|
self.Transporting = false
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
|
|
||||||
@@ -411,7 +423,6 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
self:F( { APC, From, Event, To } )
|
self:F( { APC, From, Event, To } )
|
||||||
|
|
||||||
local Boarding = false
|
local Boarding = false
|
||||||
self.BoardingCount = 0
|
|
||||||
|
|
||||||
if APC and APC:IsAlive() then
|
if APC and APC:IsAlive() then
|
||||||
self.APC_Cargo = {}
|
self.APC_Cargo = {}
|
||||||
@@ -427,11 +438,11 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
--Cargo:Ungroup()
|
--Cargo:Ungroup()
|
||||||
Cargo:Board( APCUnit, 25 )
|
Cargo:Board( APCUnit, 25 )
|
||||||
self:__Board( 1, Cargo )
|
self:__Board( 1, Cargo )
|
||||||
Boarding = true
|
|
||||||
|
|
||||||
-- 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
|
||||||
|
Boarding = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -458,7 +469,31 @@ function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo )
|
|||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo )
|
||||||
else
|
else
|
||||||
self:__Loaded( 1 )
|
for _, APCUnit in pairs( APC:GetUnits() ) do
|
||||||
|
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
||||||
|
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
||||||
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
|
if Cargo:IsUnLoaded() then
|
||||||
|
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
||||||
|
local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight()
|
||||||
|
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
|
||||||
|
Cargo:Board( APCUnit, 25 )
|
||||||
|
self:__Board( 10, Cargo )
|
||||||
|
-- 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.
|
||||||
|
self.APC_Cargo[APCUnit] = Cargo
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:__Loaded( 5, Cargo )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -471,7 +506,7 @@ end
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @return #boolean Cargo loaded.
|
-- @return #boolean Cargo loaded.
|
||||||
function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To )
|
function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To, Cargo )
|
||||||
self:F( { APC, From, Event, To } )
|
self:F( { APC, From, Event, To } )
|
||||||
|
|
||||||
local Loaded = true
|
local Loaded = true
|
||||||
@@ -484,7 +519,6 @@ function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To )
|
|||||||
Loaded = false
|
Loaded = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if Loaded == true then
|
if Loaded == true then
|
||||||
@@ -496,6 +530,9 @@ function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- On after Unload event.
|
--- On after Unload event.
|
||||||
-- @param #AI_CARGO_APC self
|
-- @param #AI_CARGO_APC self
|
||||||
-- @param Wrapper.Group#GROUP APC
|
-- @param Wrapper.Group#GROUP APC
|
||||||
@@ -512,6 +549,7 @@ function AI_CARGO_APC:onafterUnload( APC, From, Event, To, Deployed )
|
|||||||
APC:RouteStop()
|
APC:RouteStop()
|
||||||
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
||||||
Cargo:UnBoard()
|
Cargo:UnBoard()
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -534,6 +572,17 @@ function AI_CARGO_APC:onafterUnboard( APC, From, Event, To, Cargo, Deployed )
|
|||||||
if not Cargo:IsUnLoaded() then
|
if not Cargo:IsUnLoaded() then
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
else
|
else
|
||||||
|
for _, APCUnit in pairs( APC:GetUnits() ) do
|
||||||
|
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
||||||
|
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
||||||
|
if Cargo:IsLoaded() then
|
||||||
|
Cargo:UnBoard()
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
self:__Unloaded( 1, Cargo, Deployed )
|
self:__Unloaded( 1, Cargo, Deployed )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -559,22 +608,16 @@ function AI_CARGO_APC:onbeforeUnloaded( APC, From, Event, To, Cargo, Deployed )
|
|||||||
if APC and APC:IsAlive() then
|
if APC and APC:IsAlive() then
|
||||||
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
|
||||||
local CargoCheck = self.APC_Cargo[APCUnit]
|
local IsEmpty = APCUnit:IsCargoEmpty()
|
||||||
if CargoCheck then
|
self:I({ IsEmpty = IsEmpty })
|
||||||
self:F( { CargoCheck:GetName(), IsUnLoaded = CargoCheck:IsUnLoaded() } )
|
if not IsEmpty then
|
||||||
if CargoCheck:IsUnLoaded() == false then
|
AllUnloaded = false
|
||||||
AllUnloaded = false
|
break
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if AllUnloaded == true then
|
if AllUnloaded == true then
|
||||||
if Deployed == true then
|
if Deployed == true then
|
||||||
for APCUnit, Cargo in pairs( self.APC_Cargo ) do
|
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
|
||||||
Cargo:SetDeployed( true )
|
|
||||||
end
|
|
||||||
self.APC_Cargo = {}
|
self.APC_Cargo = {}
|
||||||
end
|
end
|
||||||
self:Guard()
|
self:Guard()
|
||||||
@@ -587,6 +630,21 @@ function AI_CARGO_APC:onbeforeUnloaded( APC, From, Event, To, Cargo, Deployed )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- On after Unloaded event.
|
||||||
|
-- @param #AI_CARGO_APC self
|
||||||
|
-- @param Wrapper.Group#GROUP APC
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param #string Cargo.Cargo#CARGO Cargo Cargo object.
|
||||||
|
-- @param #boolean Deployed Cargo is deployed.
|
||||||
|
-- @return #boolean All cargo unloaded.
|
||||||
|
function AI_CARGO_APC:onafterUnloaded( APC, From, Event, To, Cargo, Deployed )
|
||||||
|
self:F( { APC, From, Event, To, Cargo:GetName(), Deployed = Deployed } )
|
||||||
|
|
||||||
|
self.Transporting = false
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--- On after Follow event.
|
--- On after Follow event.
|
||||||
-- @param #AI_CARGO_APC self
|
-- @param #AI_CARGO_APC self
|
||||||
@@ -632,7 +690,6 @@ function AI_CARGO_APC._Deploy( APC, self )
|
|||||||
|
|
||||||
if APC:IsAlive() then
|
if APC:IsAlive() then
|
||||||
self:Unload( true )
|
self:Unload( true )
|
||||||
self.Transporting = false
|
|
||||||
self.Relocating = false
|
self.Relocating = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -416,6 +416,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
self:F( { Cargo = Cargo:GetName(), UnLoaded = Cargo:IsUnLoaded(), Deployed = Cargo:IsDeployed(), PickupCargo = self.PickupCargo[Carrier] ~= nil } )
|
self:F( { Cargo = Cargo:GetName(), UnLoaded = Cargo:IsUnLoaded(), Deployed = Cargo:IsDeployed(), PickupCargo = self.PickupCargo[Carrier] ~= nil } )
|
||||||
if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then
|
if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then
|
||||||
local CargoCoordinate = Cargo:GetCoordinate()
|
local CargoCoordinate = Cargo:GetCoordinate()
|
||||||
|
self:F({CargoCoordinate = CargoCoordinate })
|
||||||
local CoordinateFree = true
|
local CoordinateFree = true
|
||||||
for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do
|
for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do
|
||||||
if CarrierPickup:IsAlive() == true then
|
if CarrierPickup:IsAlive() == true then
|
||||||
@@ -427,6 +428,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
self.PickupCargo[CarrierPickup] = nil
|
self.PickupCargo[CarrierPickup] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self:F({CoordinateFree = CoordinateFree})
|
||||||
if CoordinateFree == true then
|
if CoordinateFree == true then
|
||||||
self.PickupCargo[Carrier] = CargoCoordinate
|
self.PickupCargo[Carrier] = CargoCoordinate
|
||||||
PickupCargo = Cargo
|
PickupCargo = Cargo
|
||||||
@@ -435,6 +437,8 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:F( { PickupCargo = PickupCargo} )
|
||||||
|
|
||||||
if PickupCargo then
|
if PickupCargo then
|
||||||
self.CarrierHome[Carrier] = nil
|
self.CarrierHome[Carrier] = nil
|
||||||
local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius )
|
local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius )
|
||||||
@@ -567,6 +571,7 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:F({Carrier=Carrier})
|
||||||
self.PickupCargo[Carrier] = nil
|
self.PickupCargo[Carrier] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ AI_CARGO_DISPATCHER_APC = {
|
|||||||
-- SetDeployZone = SET_ZONE:New():FilterPrefixes( "Deploy" ):FilterStart()
|
-- SetDeployZone = SET_ZONE:New():FilterPrefixes( "Deploy" ):FilterStart()
|
||||||
-- AICargoDispatcher = AI_CARGO_DISPATCHER_APC:New( SetAPC, SetCargo, SetDeployZone, 500 )
|
-- AICargoDispatcher = AI_CARGO_DISPATCHER_APC:New( SetAPC, SetCargo, SetDeployZone, 500 )
|
||||||
--
|
--
|
||||||
function AI_CARGO_DISPATCHER_APC:NewWithZones( SetAPC, SetCargo, SetDeployZone, CombatRadius )
|
function AI_CARGO_DISPATCHER_APC:New( SetAPC, SetCargo, SetDeployZone, CombatRadius )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, AI_CARGO_DISPATCHER:New( SetAPC, SetCargo, SetDeployZone ) ) -- #AI_CARGO_DISPATCHER_APC
|
local self = BASE:Inherit( self, AI_CARGO_DISPATCHER:NewWithZones( SetAPC, SetCargo, SetDeployZone ) ) -- #AI_CARGO_DISPATCHER_APC
|
||||||
|
|
||||||
self.CombatRadius = CombatRadius or 500
|
self.CombatRadius = CombatRadius or 500
|
||||||
|
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To)
|
|||||||
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() } )
|
||||||
if Cargo:IsUnLoaded() then
|
if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then
|
||||||
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
||||||
self:F( { "In radius", HelicopterUnit:GetName() } )
|
self:F( { "In radius", HelicopterUnit:GetName() } )
|
||||||
--Cargo:Ungroup()
|
--Cargo:Ungroup()
|
||||||
@@ -440,7 +440,6 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
|||||||
|
|
||||||
-- 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:Board( HelicopterUnit, 25 )
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo )
|
||||||
return
|
return
|
||||||
@@ -455,7 +454,7 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On before Loaded event. Check if cargo is loaded.
|
--- On after Loaded event. Check if cargo is loaded.
|
||||||
-- @param #AI_CARGO_HELICOPTER self
|
-- @param #AI_CARGO_HELICOPTER self
|
||||||
-- @param Wrapper.Group#GROUP Helicopter
|
-- @param Wrapper.Group#GROUP Helicopter
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
|
|||||||
@@ -779,7 +779,8 @@ do -- CARGO
|
|||||||
|
|
||||||
local Distance = 0
|
local Distance = 0
|
||||||
if self:IsUnLoaded() then
|
if self:IsUnLoaded() then
|
||||||
Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() )
|
local CargoCoordinate = self.CargoObject:GetCoordinate()
|
||||||
|
Distance = Coordinate:Get2DDistance( CargoCoordinate )
|
||||||
self:T( Distance )
|
self:T( Distance )
|
||||||
if Distance <= self.LoadRadius then
|
if Distance <= self.LoadRadius then
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -500,8 +500,6 @@ do -- CARGO_GROUP
|
|||||||
-- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup.
|
-- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup.
|
||||||
-- @return #nil There is no valid Cargo in the CargoGroup.
|
-- @return #nil There is no valid Cargo in the CargoGroup.
|
||||||
function CARGO_GROUP:GetCoordinate()
|
function CARGO_GROUP:GetCoordinate()
|
||||||
self:F()
|
|
||||||
|
|
||||||
local Cargo = self:GetFirstAlive() -- Cargo.Cargo#CARGO
|
local Cargo = self:GetFirstAlive() -- Cargo.Cargo#CARGO
|
||||||
|
|
||||||
if Cargo then
|
if Cargo then
|
||||||
@@ -635,12 +633,19 @@ do -- CARGO_GROUP
|
|||||||
|
|
||||||
if Cargo then
|
if Cargo then
|
||||||
local Distance = 0
|
local Distance = 0
|
||||||
|
local CargoCoordinate
|
||||||
if Cargo:IsLoaded() then
|
if Cargo:IsLoaded() then
|
||||||
Distance = Coordinate:Get2DDistance( Cargo.CargoCarrier:GetCoordinate() )
|
CargoCoordinate = Cargo.CargoCarrier:GetCoordinate()
|
||||||
else
|
else
|
||||||
Distance = Coordinate:Get2DDistance( Cargo.CargoObject:GetCoordinate() )
|
CargoCoordinate = Cargo.CargoObject:GetCoordinate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- if CargoCoordinate then
|
||||||
|
Distance = Coordinate:Get2DDistance( CargoCoordinate )
|
||||||
|
-- else
|
||||||
|
-- return false
|
||||||
|
-- end
|
||||||
|
|
||||||
self:F( { Distance = Distance, LoadRadius = self.LoadRadius } )
|
self:F( { Distance = Distance, LoadRadius = self.LoadRadius } )
|
||||||
if Distance <= self.LoadRadius then
|
if Distance <= self.LoadRadius then
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -879,7 +879,6 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user