From 92a05ca74a44b56c7c7c2cc1ea5c72821be13400 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sun, 19 Jan 2025 18:22:21 +0100 Subject: [PATCH] #CTLD - If troops or vehicles have a stock set, you can only inject as many as there are in stock. Specifically, when using persistence, the load function will restrict to inject more objects than are in stock, each inject draws on the stock. --- Moose Development/Moose/Ops/CTLD.lua | 46 ++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index 26295b17a..bfb47f706 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -1352,7 +1352,7 @@ CTLD.UnitTypeCapabilities = { --- CTLD class version. -- @field #string version -CTLD.version="1.1.23" +CTLD.version="1.1.24" --- Instantiate a new CTLD. -- @param #CTLD self @@ -5512,14 +5512,18 @@ end local match = false local cgotbl = self.Cargo_Troops local name = cargo:GetName() + local CargoObject + local CargoName for _,_cgo in pairs (cgotbl) do local cname = _cgo:GetName() if name == cname then match = true + CargoObject = _cgo + CargoName = cname break end end - return match + return match, CargoObject, CargoName end local function Cruncher(group,typename,anzahl) @@ -5565,11 +5569,24 @@ end end end - if not IsTroopsMatch(cargo) then + local match,CargoObject,CargoName = IsTroopsMatch(cargo) + + if not match then self.CargoCounter = self.CargoCounter + 1 cargo.ID = self.CargoCounter cargo.Stock = 1 - table.insert(self.Cargo_Troops,cargo) + table.insert(self.Cargo_Crates,cargo) + end + + if match and CargoObject then + local stock = CargoObject:GetStock() + if stock ~= -1 and stock ~= nil and stock == 0 then + -- stock empty + self:T(self.lid.."Stock of "..CargoName.." is empty. Cannot inject.") + return + else + CargoObject:RemoveStock(1) + end end local type = cargo:GetType() -- #CTLD_CARGO.Enum @@ -5637,14 +5654,18 @@ end local match = false local cgotbl = self.Cargo_Crates local name = cargo:GetName() + local CargoObject + local CargoName for _,_cgo in pairs (cgotbl) do local cname = _cgo:GetName() if name == cname then match = true + CargoObject = _cgo + CargoName = cname break end end - return match + return match,CargoObject,CargoName end local function Cruncher(group,typename,anzahl) @@ -5690,13 +5711,26 @@ end end end - if not IsVehicMatch(cargo) then + local match,CargoObject,CargoName = IsVehicMatch(cargo) + + if not match then self.CargoCounter = self.CargoCounter + 1 cargo.ID = self.CargoCounter cargo.Stock = 1 table.insert(self.Cargo_Crates,cargo) end + if match and CargoObject then + local stock = CargoObject:GetStock() + if stock ~= -1 and stock ~= nil and stock == 0 then + -- stock empty + self:T(self.lid.."Stock of "..CargoName.." is empty. Cannot inject.") + return + else + CargoObject:RemoveStock(1) + end + end + local type = cargo:GetType() -- #CTLD_CARGO.Enum if (type == CTLD_CARGO.Enum.VEHICLE or type == CTLD_CARGO.Enum.FOB) then -- unload