- remove assets from warehouse if they are removed from cohort
This commit is contained in:
Frank
2025-11-09 16:21:38 +01:00
parent 1267a64fcb
commit ea60795e84
4 changed files with 36 additions and 23 deletions
+1
View File
@@ -79,6 +79,7 @@
do -- FSM
--- FSM class
-- @type FSM
-- @field #string ClassName Name of the class.
-- @field Core.Scheduler#SCHEDULER CallScheduler Call scheduler.
@@ -8596,6 +8596,8 @@ function WAREHOUSE:_DeleteStockItem(stockitem)
local item=self.stock[i] --#WAREHOUSE.Assetitem
if item.uid==stockitem.uid then
table.remove(self.stock,i)
-- remove also from warehouse DB
_WAREHOUSEDB.Assets[stockitem.uid]=nil
break
end
end
+28 -18
View File
@@ -629,32 +629,42 @@ end
--- Remove assets from pool. Not that assets must not be spawned or already reserved or requested.
-- @param #COHORT self
-- @param #number N Number of assets to be removed. Default 1.
-- @param #number Delay Delay in seconds before assets are removed.
-- @return #COHORT self
function COHORT:RemoveAssets(N)
function COHORT:RemoveAssets(N, Delay)
self:T2(self.lid..string.format("Remove %d assets of Cohort", N))
N=N or 1
local n=0
for i=#self.assets,1,-1 do
local asset=self.assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if Delay and Delay>0 then
-- Delayed call
self:ScheduleOnce(Delay, COHORT.RemoveAssets, self, N, 0)
else
self:T2(self.lid..string.format("Checking removing asset %s", asset.spawngroupname))
if not (asset.requested or asset.spawned or asset.isReserved) then
self:T2(self.lid..string.format("Removing asset %s", asset.spawngroupname))
table.remove(self.assets, i)
n=n+1
else
self:T2(self.lid..string.format("Could NOT Remove asset %s", asset.spawngroupname))
N=N or 1
local n=0
for i=#self.assets,1,-1 do
local asset=self.assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
self:T2(self.lid..string.format("Checking removing asset %s", asset.spawngroupname))
if not (asset.requested or asset.spawned or asset.isReserved) then
self:T2(self.lid..string.format("Removing asset %s", asset.spawngroupname))
-- Remove from warehouse and warehouse DB
asset.legion:_DeleteStockItem(asset)
table.remove(self.assets, i)
n=n+1
else
self:T2(self.lid..string.format("Could NOT Remove asset %s", asset.spawngroupname))
end
if n>=N then
break
end
end
if n>=N then
break
end
self:T(self.lid..string.format("Removed %d/%d assets. New asset count=%d", n, N, #self.assets))
end
self:T(self.lid..string.format("Removed %d/%d assets. New asset count=%d", n, N, #self.assets))
return self
end
+5 -5
View File
@@ -13466,10 +13466,10 @@ function OPSGROUP:GetAmmoUnit(unit, display)
local ammotable=unit:GetAmmo()
if ammotable then
local weapons=#ammotable
--self:I(ammotable)
--self:I(ammotable)
--UTILS.PrintTableToLog(ammotable)
-- Loop over all weapons.
for w=1,weapons do
@@ -13477,9 +13477,9 @@ function OPSGROUP:GetAmmoUnit(unit, display)
-- Number of current weapon.
local Nammo=ammotable[w]["count"]
-- Range in meters. Seems only to exist for missiles (not shells).
local rmin=ammotable[w]["desc"]["rangeMin"] or 0
local rmax=ammotable[w]["desc"]["rangeMaxAltMin"] or 0
-- Range in meters. Seems only to exist for missiles (not shells).
local rmin=ammotable[w]["desc"]["rangeMin"] or 0
local rmax=ammotable[w]["desc"]["rangeMaxAltMin"] or 0
-- Type name of current weapon.
local Tammo=ammotable[w]["desc"]["typeName"]