mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OPSTRANSPORT
- Improved storage transport
This commit is contained in:
parent
655282a034
commit
e3b7a85956
@ -5458,10 +5458,10 @@ function OPSGROUP:onafterMissionExecute(From, Event, To, Mission)
|
|||||||
if self.isFlightgroup then
|
if self.isFlightgroup then
|
||||||
if Mission.prohibitABExecute == true then
|
if Mission.prohibitABExecute == true then
|
||||||
self:SetProhibitAfterburner()
|
self:SetProhibitAfterburner()
|
||||||
self:I("Set prohibit AB")
|
self:T(self.lid.."Set prohibit AB")
|
||||||
elseif Mission.prohibitABExecute == false then
|
elseif Mission.prohibitABExecute == false then
|
||||||
self:SetAllowAfterburner()
|
self:SetAllowAfterburner()
|
||||||
self:T2("Set allow AB")
|
self:T2(self.lid.."Set allow AB")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -8108,17 +8108,16 @@ function OPSGROUP:_CheckCargoTransport()
|
|||||||
-- Current pickup time.
|
-- Current pickup time.
|
||||||
local tloading=Time-self.Tloading
|
local tloading=Time-self.Tloading
|
||||||
|
|
||||||
--TODO: Check max loading time. If exceeded ==> abort transport.
|
--TODO: Check max loading time. If exceeded ==> abort transport. Time might depend on required cargos, because we need to give them time to arrive.
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:T(self.lid..string.format("Loading at %s [TZC UID=%d] for %s sec...", self.cargoTZC.PickupZone and self.cargoTZC.PickupZone:GetName() or "unknown", self.cargoTZC.uid, tloading))
|
self:T(self.lid..string.format("Loading at %s [TZC UID=%d] for %.1f sec...", self.cargoTZC.PickupZone and self.cargoTZC.PickupZone:GetName() or "unknown", self.cargoTZC.uid, tloading))
|
||||||
|
|
||||||
local boarding=false
|
local boarding=false
|
||||||
local gotcargo=false
|
local gotcargo=false
|
||||||
for _,_cargo in pairs(self.cargoTZC.Cargos) do
|
for _,_cargo in pairs(self.cargoTZC.Cargos) do
|
||||||
local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup
|
local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup
|
||||||
|
|
||||||
|
|
||||||
if cargo.type==OPSTRANSPORT.CargoType.OPSTRANPORT then
|
if cargo.type==OPSTRANSPORT.CargoType.OPSTRANPORT then
|
||||||
|
|
||||||
-- Check if anyone is still boarding.
|
-- Check if anyone is still boarding.
|
||||||
@ -8133,8 +8132,12 @@ function OPSGROUP:_CheckCargoTransport()
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
--TODO: load storage
|
-- Get cargo if it is in the cargo bay of any carrier element.
|
||||||
gotcargo=true
|
local mycargo=self:_GetMyCargoBayFromUID(cargo.uid)
|
||||||
|
|
||||||
|
if mycargo and mycargo.storageAmount>0 then
|
||||||
|
gotcargo=true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -8142,18 +8145,14 @@ function OPSGROUP:_CheckCargoTransport()
|
|||||||
|
|
||||||
-- Boarding finished ==> Transport cargo.
|
-- Boarding finished ==> Transport cargo.
|
||||||
if gotcargo and self.cargoTransport:_CheckRequiredCargos(self.cargoTZC, self) and not boarding then
|
if gotcargo and self.cargoTransport:_CheckRequiredCargos(self.cargoTZC, self) and not boarding then
|
||||||
self:T(self.lid.."Boarding finished ==> Loaded")
|
self:T(self.lid.."Boarding/loading finished ==> Loaded")
|
||||||
|
self.Tloading=nil
|
||||||
self:LoadingDone()
|
self:LoadingDone()
|
||||||
else
|
else
|
||||||
-- No cargo and no one is boarding ==> check again if we can make anyone board.
|
-- No cargo and no one is boarding ==> check again if we can make anyone board.
|
||||||
self:Loading()
|
self:Loading()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- No cargo and no one is boarding ==> check again if we can make anyone board.
|
|
||||||
if not gotcargo and not boarding then
|
|
||||||
--self:Loading()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif self:IsTransporting() then
|
elseif self:IsTransporting() then
|
||||||
|
|
||||||
-- Set time stamp.
|
-- Set time stamp.
|
||||||
@ -8195,11 +8194,14 @@ function OPSGROUP:_CheckCargoTransport()
|
|||||||
-- STORAGE
|
-- STORAGE
|
||||||
---
|
---
|
||||||
|
|
||||||
if cargo.delivered then
|
-- Get cargo if it is in the cargo bay of any carrier element.
|
||||||
|
local mycargo=self:_GetMyCargoBayFromUID(cargo.uid)
|
||||||
|
|
||||||
|
if mycargo and not cargo.delivered then
|
||||||
|
delivered=false
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -8595,8 +8597,6 @@ function OPSGROUP:_CheckDelivered(CargoTransport)
|
|||||||
done=false --Someone is not done!
|
done=false --Someone is not done!
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO: check if storage is delivered
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -9330,6 +9330,36 @@ function OPSGROUP:onafterPickup(From, Event, To)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- On after "Loading" event.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @param #table Cargos Table of cargos.
|
||||||
|
-- @return #table Table of sorted cargos.
|
||||||
|
function OPSGROUP:_SortCargo(Cargos)
|
||||||
|
|
||||||
|
-- Sort results table wrt descending weight.
|
||||||
|
local function _sort(a, b)
|
||||||
|
local cargoA=a --Ops.OpsGroup#OPSGROUP.CargoGroup
|
||||||
|
local cargoB=b --Ops.OpsGroup#OPSGROUP.CargoGroup
|
||||||
|
local weightA=0
|
||||||
|
local weightB=0
|
||||||
|
if cargoA.opsgroup then
|
||||||
|
weightA=cargoA.opsgroup:GetWeightTotal()
|
||||||
|
else
|
||||||
|
weightA=self:_GetWeightStorage(cargoA.storage)
|
||||||
|
end
|
||||||
|
if cargoB.opsgroup then
|
||||||
|
weightB=cargoB.opsgroup:GetWeightTotal()
|
||||||
|
else
|
||||||
|
weightB=self:_GetWeightStorage(cargoB.storage)
|
||||||
|
end
|
||||||
|
return weightA>weightB
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(Cargos, _sort)
|
||||||
|
|
||||||
|
return Cargos
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- On after "Loading" event.
|
--- On after "Loading" event.
|
||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
@ -9341,9 +9371,6 @@ function OPSGROUP:onafterLoading(From, Event, To)
|
|||||||
-- Set carrier status.
|
-- Set carrier status.
|
||||||
self:_NewCarrierStatus(OPSGROUP.CarrierStatus.LOADING)
|
self:_NewCarrierStatus(OPSGROUP.CarrierStatus.LOADING)
|
||||||
|
|
||||||
-- Loading time stamp.
|
|
||||||
self.Tloading=timer.getAbsTime()
|
|
||||||
|
|
||||||
-- Get valid cargos of the TZC.
|
-- Get valid cargos of the TZC.
|
||||||
local cargos={}
|
local cargos={}
|
||||||
for _,_cargo in pairs(self.cargoTZC.Cargos) do
|
for _,_cargo in pairs(self.cargoTZC.Cargos) do
|
||||||
@ -9379,12 +9406,7 @@ function OPSGROUP:onafterLoading(From, Event, To)
|
|||||||
|
|
||||||
local isAvail=true
|
local isAvail=true
|
||||||
if cargo.type==OPSTRANSPORT.CargoType.STORAGE then
|
if cargo.type==OPSTRANSPORT.CargoType.STORAGE then
|
||||||
local nAvail=0
|
local nAvail=cargo.storage.storageFrom:GetAmount(cargo.storage.cargoType)
|
||||||
if type(cargo.storage.cargoType)=="number" then
|
|
||||||
nAvail=cargo.storage.storageFrom:GetLiquidAmount(cargo.storage.cargoType)
|
|
||||||
else
|
|
||||||
nAvail=cargo.storage.storageFrom:GetItemAmount(cargo.storage.cargoType)
|
|
||||||
end
|
|
||||||
if nAvail>0 then
|
if nAvail>0 then
|
||||||
isAvail=true
|
isAvail=true
|
||||||
else
|
else
|
||||||
@ -9407,25 +9429,8 @@ function OPSGROUP:onafterLoading(From, Event, To)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sort results table wrt descending weight.
|
-- Sort cargos.
|
||||||
local function _sort(a, b)
|
self:_SortCargo(cargos)
|
||||||
local cargoA=a --Ops.OpsGroup#OPSGROUP.CargoGroup
|
|
||||||
local cargoB=b --Ops.OpsGroup#OPSGROUP.CargoGroup
|
|
||||||
local weightA=0
|
|
||||||
local weightB=0
|
|
||||||
if cargoA.opsgroup then
|
|
||||||
weightA=cargoA.opsgroup:GetWeightTotal()
|
|
||||||
else
|
|
||||||
weightA=self:_GetWeightStorage(cargoA.storage)
|
|
||||||
end
|
|
||||||
if cargoB.opsgroup then
|
|
||||||
weightB=cargoB.opsgroup:GetWeightTotal()
|
|
||||||
else
|
|
||||||
weightB=self:_GetWeightStorage(cargoB.storage)
|
|
||||||
end
|
|
||||||
return weightA>weightB
|
|
||||||
end
|
|
||||||
table.sort(cargos, _sort)
|
|
||||||
|
|
||||||
-- Loop over all cargos.
|
-- Loop over all cargos.
|
||||||
for _,_cargo in pairs(cargos) do
|
for _,_cargo in pairs(cargos) do
|
||||||
@ -9452,9 +9457,16 @@ function OPSGROUP:onafterLoading(From, Event, To)
|
|||||||
|
|
||||||
-- Get weight of cargo that needs to be transported.
|
-- Get weight of cargo that needs to be transported.
|
||||||
weight=self:_GetWeightStorage(cargo.storage, false)
|
weight=self:_GetWeightStorage(cargo.storage, false)
|
||||||
|
|
||||||
|
-- Get amount that the warehouse currently has.
|
||||||
|
local Amount=cargo.storage.storageFrom:GetAmount(cargo.storage.cargoType)
|
||||||
|
local Weight=Amount*cargo.storage.cargoWeight
|
||||||
|
|
||||||
|
-- Make sure, we do not take more than the warehouse can provide.
|
||||||
|
weight=math.min(weight, Weight)
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:T(self.lid..string.format("Loading storage weight=%d kg!", weight))
|
self:T(self.lid..string.format("Loading storage weight=%d kg (warehouse has %d kg)!", weight, Weight))
|
||||||
|
|
||||||
-- Loop over all elements of the carrier group.
|
-- Loop over all elements of the carrier group.
|
||||||
for _,_element in pairs(self.elements) do
|
for _,_element in pairs(self.elements) do
|
||||||
@ -9465,37 +9477,34 @@ function OPSGROUP:onafterLoading(From, Event, To)
|
|||||||
|
|
||||||
-- Min of weight or bay.
|
-- Min of weight or bay.
|
||||||
local w=math.min(weight, free)
|
local w=math.min(weight, free)
|
||||||
|
|
||||||
|
-- Check that weight is >0 and also greater that at least one item. We cannot transport half a missile.
|
||||||
|
if w>=cargo.storage.cargoWeight then
|
||||||
|
|
||||||
-- Calculate item amount.
|
-- Calculate item amount.
|
||||||
local amount=w/cargo.storage.cargoWeight
|
local amount=math.floor(w/cargo.storage.cargoWeight)
|
||||||
|
|
||||||
--TODO: Check the amount that the warehouse currently has!
|
-- Remove items from warehouse.
|
||||||
-- We dont want to remove more than what is actually there.
|
cargo.storage.storageFrom:RemoveAmount(cargo.storage.cargoType, amount)
|
||||||
-- Also needs a check if it is unlimited.
|
|
||||||
|
-- Add amount to loaded cargo.
|
||||||
-- Remove items from warehouse.
|
cargo.storage.cargoLoaded=cargo.storage.cargoLoaded+amount
|
||||||
if type(cargo.storage.cargoType)=="number" then
|
|
||||||
cargo.storage.storageFrom:RemoveLiquid(cargo.storage.cargoType, amount)
|
-- Add cargo to cargo by of element.
|
||||||
else
|
self:_AddCargobayStorage(element, cargo.uid, cargo.storage.cargoType, amount, cargo.storage.cargoWeight)
|
||||||
cargo.storage.storageFrom:RemoveItem(cargo.storage.cargoType, amount)
|
|
||||||
end
|
-- Reduce weight for the next element (if any).
|
||||||
|
weight=weight-amount*cargo.storage.cargoWeight
|
||||||
-- Add amount to loaded cargo.
|
|
||||||
cargo.storage.cargoLoaded=cargo.storage.cargoLoaded+amount
|
-- Debug info.
|
||||||
|
local text=string.format("Element %s: loaded amount=%d (weight=%d) ==> left=%d kg", element.name, amount, amount*cargo.storage.cargoWeight, weight)
|
||||||
-- Add cargo to cargo by of element.
|
self:T(self.lid..text)
|
||||||
self:_AddCargobayStorage(element, cargo.uid, cargo.storage.cargoType, amount, cargo.storage.cargoWeight)
|
|
||||||
|
-- If no cargo left, break the loop.
|
||||||
-- Reduce weight for the next element (if any).
|
if weight<=0 then
|
||||||
weight=weight-w
|
break
|
||||||
|
end
|
||||||
-- Debug info.
|
|
||||||
local text=string.format("Element %s: amount=%d, weight=%d, left=%d", element.name, amount, w, weight)
|
|
||||||
self:T2(self.lid..text)
|
|
||||||
|
|
||||||
-- If no cargo left, break the loop.
|
|
||||||
if weight<=0 then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -9992,11 +10001,7 @@ function OPSGROUP:onafterUnloading(From, Event, To)
|
|||||||
|
|
||||||
if mycargo then
|
if mycargo then
|
||||||
-- Add cargo to warehouse storage.
|
-- Add cargo to warehouse storage.
|
||||||
if type(mycargo.storageType)=="number" then
|
cargo.storage.storageTo:AddAmount(mycargo.storageType, mycargo.storageAmount)
|
||||||
cargo.storage.storageTo:AddLiquid(mycargo.storageType, mycargo.storageAmount)
|
|
||||||
else
|
|
||||||
cargo.storage.storageTo:AddItem(mycargo.storageType, mycargo.storageAmount)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Add amount to delivered.
|
-- Add amount to delivered.
|
||||||
cargo.storage.cargoDelivered=cargo.storage.cargoDelivered+mycargo.storageAmount
|
cargo.storage.cargoDelivered=cargo.storage.cargoDelivered+mycargo.storageAmount
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
-- * Supports ground, naval and airborne (airplanes and helicopters) units as carriers
|
-- * Supports ground, naval and airborne (airplanes and helicopters) units as carriers
|
||||||
-- * Use combined forces (ground, naval, air) to transport the troops
|
-- * Use combined forces (ground, naval, air) to transport the troops
|
||||||
-- * Additional FSM events to hook into and customize your mission design
|
-- * Additional FSM events to hook into and customize your mission design
|
||||||
|
-- * Transport of warehouse storage (fuel, weapons and equipment)
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
@ -602,6 +603,8 @@ end
|
|||||||
|
|
||||||
--- Add cargo warehouse storage to be transported. This adds items such as fuel, weapons and other equipment, which is to be transported
|
--- Add cargo warehouse storage to be transported. This adds items such as fuel, weapons and other equipment, which is to be transported
|
||||||
-- from one DCS warehouse to another.
|
-- from one DCS warehouse to another.
|
||||||
|
-- For weapons and equipment, the weight per item has to be specified explicitly as these cannot be retrieved by the DCS API. For liquids the
|
||||||
|
-- default value of 1 kg per item should be used as the amount of liquid is already given in kg.
|
||||||
-- @param #OPSTRANSPORT self
|
-- @param #OPSTRANSPORT self
|
||||||
-- @param Wrapper.Storage#STORAGE StorageFrom Storage from.
|
-- @param Wrapper.Storage#STORAGE StorageFrom Storage from.
|
||||||
-- @param Wrapper.Storage#STORAGE StorageTo Storage to.
|
-- @param Wrapper.Storage#STORAGE StorageTo Storage to.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user