From 09d53f7d8c901a96e5566dd928626286dc44ab1c Mon Sep 17 00:00:00 2001 From: Thomas <72444570+Applevangelist@users.noreply.github.com> Date: Wed, 29 Jan 2025 13:24:04 +0100 Subject: [PATCH 1/8] Update CTLD.lua #CTLD - Added HelicopterLost Event --- Moose Development/Moose/Ops/CTLD.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index 5c83896a5..b5c7d9e19 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -1422,6 +1422,7 @@ function CTLD:New(Coalition, Prefixes, Alias) self:AddTransition("*", "CratesRepaired", "*") -- CTLD repair event. self:AddTransition("*", "CratesBuildStarted", "*") -- CTLD build event. self:AddTransition("*", "CratesRepairStarted", "*") -- CTLD repair event. + self:AddTransition("*", "HelicopterLost", "*") -- CTLD lost event. self:AddTransition("*", "Load", "*") -- CTLD load event. self:AddTransition("*", "Loaded", "*") -- CTLD load event. self:AddTransition("*", "Save", "*") -- CTLD save event. @@ -1831,6 +1832,24 @@ function CTLD:New(Coalition, Prefixes, Alias) -- @param #string To State. -- @param Wrapper.Group#GROUP Group Group Object. -- @param Wrapper.Unit#UNIT Unit Unit Object. + + --- FSM Function OnBeforeHelicopterLost. + -- @function [parent=#CTLD] OnBeforeHelicopterLost + -- @param #CTLD self + -- @param #string From State. + -- @param #string Event Trigger. + -- @param #string To State. + -- @param #string Unitname The name of the unit lost. + -- @param #table LostCargo Table of #CTLD_CARGO object which were aboard the helicopter/transportplane lost. Can be an empty table! + + --- FSM Function OnAfterHelicopterLost. + -- @function [parent=#CTLD] OnAfterHelicopterLost + -- @param #CTLD self + -- @param #string From State. + -- @param #string Event Trigger. + -- @param #string To State. + -- @param #string Unitname The name of the unit lost. + -- @param #table LostCargo Table of #CTLD_CARGO object which were aboard the helicopter/transportplane lost. Can be an empty table! --- FSM Function OnAfterLoad. -- @function [parent=#CTLD] OnAfterLoad @@ -1972,6 +1991,10 @@ function CTLD:_EventHandler(EventData) elseif event.id == EVENTS.PlayerLeaveUnit or event.id == EVENTS.UnitLost then -- remove from pilot table local unitname = event.IniUnitName or "none" + if self.CtldUnits[unitname] then + local lostcargo = UTILS.DeepCopy(self.Loaded_Cargo[unitname] or {}) + self:__HelicopterLost(1,unitname,lostcargo) + end self.CtldUnits[unitname] = nil self.Loaded_Cargo[unitname] = nil self.MenusDone[unitname] = nil From 4aacdc156736e10a79e323ab07467cc2d119a63b Mon Sep 17 00:00:00 2001 From: Shafik Date: Wed, 29 Jan 2025 14:43:43 +0200 Subject: [PATCH 2/8] [FIXED] attempt to index local 'CleanUpUnit' (a nil value) --- Moose Development/Moose/Functional/CleanUp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Functional/CleanUp.lua b/Moose Development/Moose/Functional/CleanUp.lua index 14616331f..5d975c3ca 100644 --- a/Moose Development/Moose/Functional/CleanUp.lua +++ b/Moose Development/Moose/Functional/CleanUp.lua @@ -384,7 +384,7 @@ function CLEANUP_AIRBASE.__:CleanUpSchedule() local CleanUpUnit = CleanUpListData.CleanUpUnit -- Wrapper.Unit#UNIT local CleanUpGroupName = CleanUpListData.CleanUpGroupName - if CleanUpUnit:IsAlive() ~= nil then + if CleanUpUnit and CleanUpUnit:IsAlive() ~= nil then if self:IsInAirbase( CleanUpUnit:GetVec2() ) then From 5ef9bb2acda3e323817cf3909eb6b8f87fec59ac Mon Sep 17 00:00:00 2001 From: Shafik Date: Wed, 29 Jan 2025 14:44:31 +0200 Subject: [PATCH 3/8] [FIXED] attempt to get length of local 'parking' (a nil value) --- Moose Development/Moose/Functional/Warehouse.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 3c812686d..29682074f 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -6047,7 +6047,7 @@ function WAREHOUSE:_SpawnAssetAircraft(alias, asset, request, parking, uncontrol else - if #parking<#template.units and not airstart then + if parking and #parking<#template.units and not airstart then local text=string.format("ERROR: Not enough parking! Free parking = %d < %d aircraft to be spawned.", #parking, #template.units) self:_DebugMessage(text) return nil From 99b93266ad466e417b0c0dbaff9ba791a042cbae Mon Sep 17 00:00:00 2001 From: Fedge <> Date: Wed, 29 Jan 2025 18:47:44 -0700 Subject: [PATCH 4/8] Fixes the AH-64D's FCR enum weapon definition. --- Moose Development/Moose/Utilities/Enums.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Utilities/Enums.lua b/Moose Development/Moose/Utilities/Enums.lua index 59df545e1..ffd2a7deb 100644 --- a/Moose Development/Moose/Utilities/Enums.lua +++ b/Moose Development/Moose/Utilities/Enums.lua @@ -1327,7 +1327,7 @@ ENUMS.Storage.weapons.OH58.Smk_Grenade_Violet = {4,5,9,490} ENUMS.Storage.weapons.OH58.Smk_Grenade_White = {4,5,9,492} ENUMS.Storage.weapons.OH58.Smk_Grenade_Yellow = {4,5,9,491} -- Apache -ENUMS.Storage.weapons.AH64D.AN_APG78 = {4,15,44,2138} +ENUMS.Storage.weapons.AH64D.AN_APG78 = {4,15,44,2114} ENUMS.Storage.weapons.AH64D.Internal_Aux_FuelTank = {1,3,43,1700} --- From 03c30f3ccef48b86e906f7224e7f8ffee24720c4 Mon Sep 17 00:00:00 2001 From: Fedge <> Date: Wed, 29 Jan 2025 18:48:34 -0700 Subject: [PATCH 5/8] Adds the 2 primary APKWS rockets as entries in the `ENUMS.Storage.weapons.missiles` table. I added them to `missiles`, rather than `nurs` because that's where they appear in the mission editor's storage window. --- Moose Development/Moose/Utilities/Enums.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Moose Development/Moose/Utilities/Enums.lua b/Moose Development/Moose/Utilities/Enums.lua index ffd2a7deb..a269fb972 100644 --- a/Moose Development/Moose/Utilities/Enums.lua +++ b/Moose Development/Moose/Utilities/Enums.lua @@ -1279,6 +1279,8 @@ ENUMS.Storage.weapons.nurs.S_5M = "weapons.nurs.S_5M" ENUMS.Storage.weapons.missiles.AGM_12A = "weapons.missiles.AGM_12A" ENUMS.Storage.weapons.droptanks.JAYHAWK_120_Fuel_Tank = "weapons.droptanks.JAYHAWK_120_Fuel_Tank" ENUMS.Storage.weapons.bombs.GBU_15_V_1_B = "weapons.bombs.GBU_15_V_1_B" +ENUMS.Storage.weapons.missiles.HYDRA_70_M151_APKWS = {4,4,8,292} +ENUMS.Storage.weapons.missiles.HYDRA_70_M282_APKWS = {4,4,8,293} -- dupes with typos ENUMS.Storage.weapons.bombs.BAP100 = "weapons.bombs.BAP_100" ENUMS.Storage.weapons.bombs.BLU3B_GROUP = "weapons.bombs.BLU-3B_GROUP" From 4b16e94eaf31d2c630988a3d0b3f78749d98725f Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 30 Jan 2025 13:19:11 +0100 Subject: [PATCH 6/8] #CTLD - Added function for the game designer to get an overview of stock and alive groups, if they want to manage the stock: `CTLD:_CountStockPlusInHeloPlusAliveGroups()` --- Moose Development/Moose/Ops/CTLD.lua | 165 +++++++++++++++++++++++++-- 1 file changed, 158 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index b5c7d9e19..62cbb8a25 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -56,6 +56,7 @@ do -- @field #string StaticType Individual type if set. -- @field #string StaticCategory Individual static category if set. -- @field #list<#string> TypeNames Table of unit types able to pick this cargo up. +-- @field #number Stock0 Initial stock, if any given. -- @extends Core.Base#BASE --- @@ -73,6 +74,7 @@ CTLD_CARGO = { HasBeenDropped = false, PerCrateMass = 0, Stock = nil, + Stock0 = nil, Mark = nil, DontShowInMenu = false, Location = nil, @@ -131,6 +133,7 @@ CTLD_CARGO = { self.HasBeenDropped = Dropped or false --#boolean self.PerCrateMass = PerCrateMass or 0 -- #number self.Stock = Stock or nil --#number + self.Stock0 = Stock or nil --#number self.Mark = nil self.Subcategory = Subcategory or "Other" self.DontShowInMenu = DontShowInMenu or false @@ -321,7 +324,7 @@ CTLD_CARGO = { --- Get Stock. -- @param #CTLD_CARGO self - -- @return #number Stock + -- @return #number Stock or -1 if unlimited. function CTLD_CARGO:GetStock() if self.Stock then return self.Stock @@ -330,6 +333,28 @@ CTLD_CARGO = { end end + --- Get Stock0. + -- @param #CTLD_CARGO self + -- @return #number Stock0 or -1 if unlimited. + function CTLD_CARGO:GetStock0() + if self.Stock0 then + return self.Stock0 + else + return -1 + end + end + + --- Get relative Stock. + -- @param #CTLD_CARGO self + -- @return #number Stock Percentage like 75, or -1 if unlimited. + function CTLD_CARGO:GetRelativeStock() + if self.Stock and self.Stock0 then + return math.floor((self.Stock/self.Stock0)*100) + else + return -1 + end + end + --- Add Stock. -- @param #CTLD_CARGO self -- @param #number Number to add, none if nil. @@ -986,6 +1011,14 @@ do -- function my_ctld:OnAfterCratesDropped(From, Event, To, Group, Unit, Cargotable) -- ... your code here ... -- end +-- +--- ## 3.6 OnAfterHelicopterLost +-- +-- This function is called when a player has deployed left a unit or crashed/died: +-- +-- function my_ctld:OnAfterHelicopterLost(From, Event, To, Unitname, Cargotable) +-- ... your code here ... +-- end -- -- ## 3.6 OnAfterCratesBuild, OnAfterCratesRepaired -- @@ -1355,7 +1388,7 @@ CTLD.UnitTypeCapabilities = { --- CTLD class version. -- @field #string version -CTLD.version="1.1.28" +CTLD.version="1.1.29" --- Instantiate a new CTLD. -- @param #CTLD self @@ -5313,6 +5346,119 @@ end self.EngineersInField = engtable return self end + + --- User - Count both the stock and groups in the field for available cargo types. Counts only limited cargo items and only troops and vehicle/FOB crates! + -- @param #CTLD self + -- @return #table Table A table of contents with numbers. + -- @usage + -- The index is the unique cargo name. + -- Each entry in the returned table contains a table with the following entries: + -- + -- { + -- Stock0 -- number of original stock when the cargo entry was created. + -- Stock -- number of currently available stock. + -- StockR -- relative number of available stock, e.g. 75 (percent). + -- Infield -- number of groups alive in the field of this kind. + -- Inhelo -- number of troops/crates in any helo alive. Can be with decimals < 1 if e.g. you have cargo that need 4 crates, but you have 2 loaded. + -- Sum -- sum is stock + infield + inhelo. + -- } + function CTLD:_CountStockPlusInHeloPlusAliveGroups() + local Troopstable = {} + -- generics + for _id,_cargo in pairs(self.Cargo_Crates) do + local generic = _cargo -- #CTLD_CARGO + local genname = generic:GetName() + if generic and generic:GetStock0() > 0 and not Troopstable[genname] then + Troopstable[genname] = { + Stock0 = generic:GetStock0(), + Stock = generic:GetStock(), + StockR = generic:GetRelativeStock(), + Infield = 0, + Inhelo = 0, + Sum = generic:GetStock(), + } + end + end + --- + for _id,_cargo in pairs(self.Cargo_Troops) do + local generic = _cargo -- #CTLD_CARGO + local genname = generic:GetName() + if generic and generic:GetStock0() > 0 and not Troopstable[genname] then + Troopstable[genname] = { + Stock0 = generic:GetStock0(), + Stock = generic:GetStock(), + StockR = generic:GetRelativeStock(), + Infield = 0, + Inhelo = 0, + Sum = generic:GetStock(), + } + end + end + -- Troops & Built Crates + for _index, _group in pairs (self.DroppedTroops) do + if _group and _group:IsAlive() then + self:T("Looking at ".._group:GetName() .. " in the field") + local generic = self:GetGenericCargoObjectFromGroupName(_group:GetName()) -- #CTLD_CARGO + if generic then + local genname = generic:GetName() + self:T("Found Generic "..genname .. " in the field. Adding.") + if generic:GetStock0() > 0 then -- don't count unlimited stock + if not Troopstable[genname] then + Troopstable[genname] = { + Stock0 = generic:GetStock0(), + Stock = generic:GetStock(), + StockR = generic:GetRelativeStock(), + Infield = 1, + Inhelo = 0, + Sum = generic:GetStock()+1, + } + else + Troopstable[genname].Infield = Troopstable[genname].Infield + 1 + Troopstable[genname].Sum = Troopstable[genname].Infield + Troopstable[genname].Stock + Troopstable[genname].Inhelo + end + end + else + self:E(self.lid.."Group without Cargo Generic: ".._group:GetName()) + end + end + end + -- Helos + for _unitname,_loaded in pairs(self.Loaded_Cargo) do + local _unit = UNIT:FindByName(_unitname) + if _unit and _unit:IsAlive() then + local unitname = _unit:GetName() + local loadedcargo = self.Loaded_Cargo[unitname].Cargo or {} + for _,_cgo in pairs (loadedcargo) do + local cargo = _cgo -- #CTLD_CARGO + local type = cargo.CargoType + local gname = cargo.Name + local gcargo = self:_FindCratesCargoObject(gname) or self:_FindTroopsCargoObject(gname) + self:T("Looking at ".. gname .. " in the helo - type = "..type) + if (type == CTLD_CARGO.Enum.TROOPS or type == CTLD_CARGO.Enum.ENGINEERS or type == CTLD_CARGO.Enum.VEHICLE or type == CTLD_CARGO.Enum.FOB) then + -- valid troops/engineers + if gcargo and gcargo:GetStock0() > 0 then -- don't count unlimited stock + self:T("Adding ".. gname .. " in the helo - type = "..type) + if (type == CTLD_CARGO.Enum.TROOPS or type == CTLD_CARGO.Enum.ENGINEERS) then + Troopstable[gname].Inhelo = Troopstable[gname].Inhelo + 1 + end + if (type == CTLD_CARGO.Enum.VEHICLE or type == CTLD_CARGO.Enum.FOB) then + -- maybe multiple crates of the same type + local counting = gcargo.CratesNeeded + local added = 1 + if counting > 1 then + added = added/counting + end + Troopstable[gname].Inhelo = Troopstable[gname].Inhelo + added + end + Troopstable[gname].Sum = Troopstable[gname].Infield + Troopstable[gname].Stock + Troopstable[gname].Inhelo + end + end + end + end + end + return Troopstable + end + --- User - function to add stock of a certain troops type -- @param #CTLD self @@ -5542,19 +5688,24 @@ end -- @return #CTLD_CARGO The cargo object or nil if not found function CTLD:GetGenericCargoObjectFromGroupName(GroupName) local Cargotype = nil + local template = GroupName + if string.find(template,"#") then + template = string.gsub(GroupName,"#(%d+)$","") + end + template = string.gsub(template,"-(%d+)$","") for k,v in pairs(self.Cargo_Troops) do local comparison = "" if type(v.Templates) == "string" then comparison = v.Templates else comparison = v.Templates[1] end - if comparison == GroupName then + if comparison == template then Cargotype = v break end end if not Cargotype then - for k,v in pairs(self.Cargo_Crates) do + for k,v in pairs(self.Cargo_Crates) do -- #number, #CTLD_CARGO local comparison = "" if type(v.Templates) == "string" then comparison = v.Templates else comparison = v.Templates[1] end - if comparison == GroupName then + if comparison == template and v.CargoType ~= CTLD_CARGO.Enum.REPAIR then Cargotype = v break end @@ -5679,7 +5830,7 @@ end if not match then self.CargoCounter = self.CargoCounter + 1 cargo.ID = self.CargoCounter - cargo.Stock = 1 + --cargo.Stock = 1 table.insert(self.Cargo_Troops,cargo) end @@ -5829,7 +5980,7 @@ end if not match then self.CargoCounter = self.CargoCounter + 1 cargo.ID = self.CargoCounter - cargo.Stock = 1 + --cargo.Stock = 1 table.insert(self.Cargo_Crates,cargo) end From 35348d9b81974022a142c47ac551f0d471ebb310 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 30 Jan 2025 18:32:25 +0100 Subject: [PATCH 7/8] #UTILS - Added UTILS.Weather for fog stuff --- Moose Development/Moose/Utilities/Utils.lua | 75 +++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index edf00b2f7..eeff81f26 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -4324,3 +4324,78 @@ end function UTILS.ScalarMult(vec, mult) return {x = vec.x*mult, y = vec.y*mult, z = vec.z*mult} end + +--- Utilities weather class for fog mainly. +-- @type UTILS.Weather +UTILS.Weather = {} + +--- Returns the current fog thickness in meters. Returns zero if fog is not present. +function UTILS.Weather.GetFogThickness() + return world.weather.getFogThickness() +end + +--- Sets the fog to the desired thickness in meters at sea level. +-- @param #number Thickness Thickness in meters. +-- Any fog animation will be discarded. +-- Valid range : 100 to 5000 meters +function UTILS.Weather.SetFogThickness(Thickness) + local value = Thickness + if value < 100 then value = 100 + elseif value > 5000 then value = 5000 end + return world.weather.setFogThickness(value) +end + +--- Removes the fog. +function UTILS.Weather.RemoveFog() + return world.weather.setFogThickness(0) +end + +--- Gets the maximum visibility distance of the current fog setting. +-- Returns 0 if no fog is present. +function UTILS.Weather.GetFogVisibilityDistanceMax() + return world.weather.getFogVisibilityDistance() +end + +--- Sets the maximum visibility at sea level in meters. +-- @param #number Thickness Thickness in meters. +-- Limit: 100 to 100000 +function UTILS.Weather.SetFogVisibilityDistance(Thickness) + local value = Thickness + if value < 100 then value = 100 + elseif value > 100000 then value = 100000 end + return world.weather.setFogVisibilityDistance(value) +end + +--- Uses data from the passed table to change the fog visibility and thickness over a desired timeframe. This allows for a gradual increase/decrease of fog values rather than abruptly applying the values. +-- Animation Key Format: {time, visibility, thickness} +-- @param #table AnimationKeys Table of AnimationKey tables +-- @usage +-- Time: in seconds 0 to infinity +-- Time is relative to when the function was called. Time value for each key must be larger than the previous key. If time is set to 0 then the fog will be applied to the corresponding visibility and thickness values at that key. Any time value greater than 0 will result in the current fog being inherited and changed to the first key. +-- Visibility: in meters 100 to 100000 +-- Thickness: in meters 100 to 5000 +-- The speed at which the visibility and thickness changes is based on the time between keys and the values that visibility and thickness are being set to. +-- +-- When the function is passed an empty table {} or nil the fog animation will be discarded and whatever the current thickness and visibility are set to will remain. +-- +-- The following will set the fog in the mission to disappear in 1 minute. +-- +-- UTILS.Weather.SetFogAnimation({ {60, 0, 0} }) +-- +-- The following will take 1 hour to get to the first fog setting, it will maintain that fog setting for another hour, then lightly removes the fog over the 2nd and 3rd hour, the completely removes the fog after 3 hours and 3 minutes from when the function was called. +-- +-- UTILS.Weather.SetFogAnimation({ +-- {3600, 10000, 3000}, -- one hour to get to that fog setting +-- {7200, 10000, 3000}, -- will maintain for 2 hours +-- {10800, 20000, 2000}, -- at 3 hours visibility will have been increased while thickness decreases slightly +-- {12600, 0, 0}, -- at 3:30 after the function was called the fog will be completely removed. +-- }) +-- +function UTILS.Weather.SetFogAnimation(AnimationKeys) + return world.weather.setFogAnimation(AnimationKeys) +end + +--- The fog animation will be discarded and whatever the current thickness and visibility are set to will remain +function UTILS.Weather.StopFogAnimation() + return world.weather.setFogAnimation({}) +end From d06e44d37b11b3bd6b8f5ac0b3db3c80744c20cd Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 30 Jan 2025 18:32:39 +0100 Subject: [PATCH 8/8] #CTLD small additions --- Moose Development/Moose/Ops/CTLD.lua | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index 62cbb8a25..180b2c2e6 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -5349,6 +5349,8 @@ end --- User - Count both the stock and groups in the field for available cargo types. Counts only limited cargo items and only troops and vehicle/FOB crates! -- @param #CTLD self + -- @param #boolean Restock If true, restock the cargo and troop items. + -- @param #number Threshold Percentage below which to restock, used in conjunction with Restock (must be true). Defaults to 75 (percent). -- @return #table Table A table of contents with numbers. -- @usage -- The index is the unique cargo name. @@ -5361,8 +5363,9 @@ end -- Infield -- number of groups alive in the field of this kind. -- Inhelo -- number of troops/crates in any helo alive. Can be with decimals < 1 if e.g. you have cargo that need 4 crates, but you have 2 loaded. -- Sum -- sum is stock + infield + inhelo. + -- GenericCargo -- this filed holds the generic CTLD_CARGO object which drives the available stock. Only populated if Restock is true. -- } - function CTLD:_CountStockPlusInHeloPlusAliveGroups() + function CTLD:_CountStockPlusInHeloPlusAliveGroups(Restock,Threshold) local Troopstable = {} -- generics for _id,_cargo in pairs(self.Cargo_Crates) do @@ -5377,6 +5380,9 @@ end Inhelo = 0, Sum = generic:GetStock(), } + if Restock == true then + Troopstable[genname].GenericCargo = generic + end end end --- @@ -5392,6 +5398,9 @@ end Inhelo = 0, Sum = generic:GetStock(), } + if Restock == true then + Troopstable[genname].GenericCargo = generic + end end end -- Troops & Built Crates @@ -5403,19 +5412,8 @@ end local genname = generic:GetName() self:T("Found Generic "..genname .. " in the field. Adding.") if generic:GetStock0() > 0 then -- don't count unlimited stock - if not Troopstable[genname] then - Troopstable[genname] = { - Stock0 = generic:GetStock0(), - Stock = generic:GetStock(), - StockR = generic:GetRelativeStock(), - Infield = 1, - Inhelo = 0, - Sum = generic:GetStock()+1, - } - else Troopstable[genname].Infield = Troopstable[genname].Infield + 1 Troopstable[genname].Sum = Troopstable[genname].Infield + Troopstable[genname].Stock + Troopstable[genname].Inhelo - end end else self:E(self.lid.."Group without Cargo Generic: ".._group:GetName()) @@ -5455,7 +5453,19 @@ end end end end + end + -- Restock? + if Restock == true then + local threshold = Threshold or 75 + for _name,_data in pairs(Troopstable) do + if _data.StockR and _data.StockR < threshold then + if _data.GenericCargo then + _data.GenericCargo:SetStock(_data.Stock0) -- refill to start level + end + end + end end + -- Return return Troopstable end @@ -5473,6 +5483,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:AddStock(number) + break end end return self @@ -5491,6 +5502,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:AddStock(number) + break end end return self @@ -5509,6 +5521,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:AddStock(number) + break end end return self @@ -5527,6 +5540,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:SetStock(number) + break end end return self @@ -5545,6 +5559,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:SetStock(number) + break end end return self @@ -5563,6 +5578,7 @@ end for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO if _troop.Name == name then _troop:SetStock(number) + break end end return self