mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Finish Cargo/Optimization_Dispatcher
This commit is contained in:
@@ -420,7 +420,8 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
self.APC_Cargo = {}
|
self.APC_Cargo = {}
|
||||||
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
|
||||||
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
|
||||||
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
local Cargo = Cargo -- Cargo.Cargo#CARGO
|
||||||
self:F( { IsUnLoaded = Cargo:IsUnLoaded(), IsDeployed = Cargo:IsDeployed(), Cargo:GetName(), APC:GetName() } )
|
self:F( { IsUnLoaded = Cargo:IsUnLoaded(), IsDeployed = Cargo:IsDeployed(), Cargo:GetName(), APC:GetName() } )
|
||||||
if Cargo:IsUnLoaded() then -- and not Cargo:IsDeployed() then
|
if Cargo:IsUnLoaded() then -- and not Cargo:IsDeployed() then
|
||||||
@@ -472,7 +473,7 @@ function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo )
|
|||||||
else
|
else
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
|
|
||||||
local PickupCargo = nil
|
local PickupCargo = nil
|
||||||
|
|
||||||
for CargoName, Cargo in pairs( self.SetCargo:GetSet() ) do
|
for CargoName, Cargo in UTILS.spairs( self.SetCargo: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
|
||||||
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
|
||||||
@@ -428,9 +428,23 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if CoordinateFree == true then
|
if CoordinateFree == true then
|
||||||
self.PickupCargo[Carrier] = CargoCoordinate
|
-- Check if this cargo can be picked-up by at least one carrier unit of AI_Cargo.
|
||||||
PickupCargo = Cargo
|
local LargestLoadCapacity = 0
|
||||||
break
|
for _, Carrier in pairs( Carrier:GetUnits() ) do
|
||||||
|
local LoadCapacity = Carrier:GetCargoBayFreeWeight()
|
||||||
|
if LargestLoadCapacity < LoadCapacity then
|
||||||
|
LargestLoadCapacity = LoadCapacity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- So if there is aa carrier that has the required load capacity to load the total weight of the cargo, dispatch the carrier.
|
||||||
|
-- Otherwise break and go to the next carrier.
|
||||||
|
-- This will skip cargo which is too large to be able to be loaded by carriers
|
||||||
|
-- and will secure an efficient dispatching scheme.
|
||||||
|
if LargestLoadCapacity >= Cargo:GetWeight() then
|
||||||
|
self.PickupCargo[Carrier] = CargoCoordinate
|
||||||
|
PickupCargo = Cargo
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user