Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
Applevangelist 2025-01-30 18:33:06 +01:00
commit fe0edeb011
2 changed files with 103 additions and 12 deletions

View File

@ -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! --- 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 #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. -- @return #table Table A table of contents with numbers.
-- @usage -- @usage
-- The index is the unique cargo name. -- The index is the unique cargo name.
@ -5361,8 +5363,9 @@ end
-- Infield -- number of groups alive in the field of this kind. -- 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. -- 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. -- 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 = {} local Troopstable = {}
-- generics -- generics
for _id,_cargo in pairs(self.Cargo_Crates) do for _id,_cargo in pairs(self.Cargo_Crates) do
@ -5377,6 +5380,9 @@ end
Inhelo = 0, Inhelo = 0,
Sum = generic:GetStock(), Sum = generic:GetStock(),
} }
if Restock == true then
Troopstable[genname].GenericCargo = generic
end
end end
end end
--- ---
@ -5392,6 +5398,9 @@ end
Inhelo = 0, Inhelo = 0,
Sum = generic:GetStock(), Sum = generic:GetStock(),
} }
if Restock == true then
Troopstable[genname].GenericCargo = generic
end
end end
end end
-- Troops & Built Crates -- Troops & Built Crates
@ -5403,20 +5412,9 @@ end
local genname = generic:GetName() local genname = generic:GetName()
self:T("Found Generic "..genname .. " in the field. Adding.") self:T("Found Generic "..genname .. " in the field. Adding.")
if generic:GetStock0() > 0 then -- don't count unlimited stock 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].Infield = Troopstable[genname].Infield + 1
Troopstable[genname].Sum = Troopstable[genname].Infield + Troopstable[genname].Stock + Troopstable[genname].Inhelo Troopstable[genname].Sum = Troopstable[genname].Infield + Troopstable[genname].Stock + Troopstable[genname].Inhelo
end end
end
else else
self:E(self.lid.."Group without Cargo Generic: ".._group:GetName()) self:E(self.lid.."Group without Cargo Generic: ".._group:GetName())
end end
@ -5456,6 +5454,18 @@ end
end 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 return Troopstable
end end
@ -5473,6 +5483,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:AddStock(number) _troop:AddStock(number)
break
end end
end end
return self return self
@ -5491,6 +5502,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:AddStock(number) _troop:AddStock(number)
break
end end
end end
return self return self
@ -5509,6 +5521,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:AddStock(number) _troop:AddStock(number)
break
end end
end end
return self return self
@ -5527,6 +5540,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:SetStock(number) _troop:SetStock(number)
break
end end
end end
return self return self
@ -5545,6 +5559,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:SetStock(number) _troop:SetStock(number)
break
end end
end end
return self return self
@ -5563,6 +5578,7 @@ end
for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO for _id,_troop in pairs (gentroops) do -- #number, #CTLD_CARGO
if _troop.Name == name then if _troop.Name == name then
_troop:SetStock(number) _troop:SetStock(number)
break
end end
end end
return self return self

View File

@ -4324,3 +4324,78 @@ end
function UTILS.ScalarMult(vec, mult) function UTILS.ScalarMult(vec, mult)
return {x = vec.x*mult, y = vec.y*mult, z = vec.z*mult} return {x = vec.x*mult, y = vec.y*mult, z = vec.z*mult}
end 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