mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Merge branch 'develop' into FF/Develop
This commit is contained in:
commit
0ebbbde6c3
@ -419,16 +419,21 @@ 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
|
||||||
for _, Cargo in pairs( self.CargoSet:GetSet() ) do
|
|
||||||
|
self.APC_Cargo_Weight[APCUnit] = APCUnit:GetCargoBayFreeWeight()
|
||||||
|
|
||||||
|
--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
|
||||||
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 = APCUnit:GetCargoBayFreeWeight()
|
local CargoBayFreeWeight = self.APC_Cargo_Weight[APCUnit]
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
@ -438,11 +443,12 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To )
|
|||||||
APC:RouteStop()
|
APC:RouteStop()
|
||||||
--Cargo:Ungroup()
|
--Cargo:Ungroup()
|
||||||
Cargo:Board( APCUnit, 25 )
|
Cargo:Board( APCUnit, 25 )
|
||||||
self:__Board( 1, Cargo )
|
self:__Board( 1, 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
|
||||||
Boarding = true
|
Boarding = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -462,22 +468,21 @@ 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.
|
||||||
-- @param #string Cargo.Cargo#CARGO Cargo Cargo object.
|
-- @param Cargo.Cargo#CARGO Cargo Cargo object.
|
||||||
function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo )
|
-- @param Wrapper.Unit#UNIT APCUnit
|
||||||
self:F( { APC, From, Event, To, Cargo } )
|
function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo, APCUnit )
|
||||||
|
self:F( { APC, From, Event, To, Cargo, APCUnit:GetName() } )
|
||||||
|
|
||||||
if APC and APC:IsAlive() then
|
if APC and APC:IsAlive() then
|
||||||
self:F({ IsLoaded = Cargo:IsLoaded(), Cargo:GetName(), APC:GetName() } )
|
self:F({ IsLoaded = Cargo:IsLoaded(), Cargo:GetName(), APC:GetName() } )
|
||||||
if not Cargo:IsLoaded() then
|
if not Cargo:IsLoaded() then
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo, APCUnit )
|
||||||
else
|
else
|
||||||
for _, APCUnit in pairs( APC:GetUnits() ) do
|
for _, Cargo in UTILS.spairs( self.CargoSet:GetSet(), function( t, a, b ) return t[a]:GetWeight() > t[b]:GetWeight() end ) do
|
||||||
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
|
||||||
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( APCUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
||||||
local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight()
|
local CargoBayFreeWeight = self.APC_Cargo_Weight[APCUnit]
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
@ -485,16 +490,16 @@ function AI_CARGO_APC:onafterBoard( APC, 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( APCUnit, 25 )
|
Cargo:Board( APCUnit, 25 )
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, 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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
self:__Loaded( 5, Cargo )
|
self:__Loaded( 5, Cargo )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -552,6 +557,7 @@ function AI_CARGO_APC:onafterUnload( APC, From, Event, To, Deployed )
|
|||||||
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
||||||
if Cargo:IsLoaded() then
|
if Cargo:IsLoaded() then
|
||||||
Cargo:UnBoard()
|
Cargo:UnBoard()
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -580,6 +586,7 @@ function AI_CARGO_APC:onafterUnboard( APC, From, Event, To, Cargo, Deployed )
|
|||||||
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
||||||
if Cargo:IsLoaded() then
|
if Cargo:IsLoaded() then
|
||||||
Cargo:UnBoard()
|
Cargo:UnBoard()
|
||||||
|
Cargo:SetDeployed( true )
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -604,7 +611,6 @@ function AI_CARGO_APC:onbeforeUnloaded( APC, From, Event, To, Cargo, Deployed )
|
|||||||
self:F( { APC, From, Event, To, Cargo:GetName(), Deployed = Deployed } )
|
self:F( { APC, From, Event, To, Cargo:GetName(), Deployed = Deployed } )
|
||||||
|
|
||||||
local AllUnloaded = true
|
local AllUnloaded = true
|
||||||
Cargo:SetDeployed( true )
|
|
||||||
|
|
||||||
--Cargo:Regroup()
|
--Cargo:Regroup()
|
||||||
|
|
||||||
|
|||||||
@ -420,7 +420,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
|
||||||
@ -437,12 +437,26 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if CoordinateFree == true then
|
if CoordinateFree == true then
|
||||||
|
-- Check if this cargo can be picked-up by at least one carrier unit of AI_Cargo.
|
||||||
|
local LargestLoadCapacity = 0
|
||||||
|
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
|
self.PickupCargo[Carrier] = CargoCoordinate
|
||||||
PickupCargo = Cargo
|
PickupCargo = Cargo
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if PickupCargo then
|
if PickupCargo then
|
||||||
self.CarrierHome[Carrier] = nil
|
self.CarrierHome[Carrier] = nil
|
||||||
|
|||||||
@ -2089,6 +2089,8 @@ do -- Route methods
|
|||||||
local dist=ToCoordinate:Get2DDistance(PathOnRoad[#PathOnRoad-1])
|
local dist=ToCoordinate:Get2DDistance(PathOnRoad[#PathOnRoad-1])
|
||||||
if dist>10 then
|
if dist>10 then
|
||||||
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
|
||||||
|
table.insert(route, ToCoordinate:GetRandomCoordinateInRadius(10,5):WaypointGround(5, OffRoadFormation))
|
||||||
|
table.insert(route, ToCoordinate:GetRandomCoordinateInRadius(10,5):WaypointGround(5, OffRoadFormation))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user