From 35348d9b81974022a142c47ac551f0d471ebb310 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 30 Jan 2025 18:32:25 +0100 Subject: [PATCH 1/4] #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 2/4] #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 From 74520b13599571523b966a8c2070cfd0bd09a5d1 Mon Sep 17 00:00:00 2001 From: Shafik Date: Fri, 31 Jan 2025 10:30:18 +0200 Subject: [PATCH 3/4] [FIXED] attempt to index a nil value (`AWACS:_CheckAwacsStatus` -> `OPSGROUP:GetCallsignName` -> `GROUP:IsPlayer`) --- Moose Development/Moose/Wrapper/Group.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index aedf6412d..e72822977 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -757,7 +757,11 @@ end -- @param #GROUP self -- @return #boolean If true, group is associated with a client or player slot. function GROUP:IsPlayer() - return self:GetUnit(1):IsPlayer() + local unit = self:GetUnit(1) + if unit then + return unit:IsPlayer() + end + return false end --- Returns the UNIT wrapper object with number UnitNumber. If it doesn't exist, tries to return the next available unit. From f0fe1b431df2a23a4d8bef6fa7dbf403658279da Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 31 Jan 2025 14:26:28 +0100 Subject: [PATCH 4/4] #SPAWN - Add optional waiting time to InitRepeatOnLanding --- Moose Development/Moose/Core/Spawn.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 89ff4d9fa..42b8bab38 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -1278,6 +1278,7 @@ end --- Respawn group after landing. -- @param #SPAWN self +-- @param #number WaitingTime Wait this many seconds before despawning the alive group after landing. Defaults to 3 . -- @return #SPAWN self -- @usage -- @@ -1285,15 +1286,16 @@ end -- -- Re-SPAWN the Group(s) after each landing and Engine Shut-Down automatically. -- SpawnRU_SU34 = SPAWN:New( 'Su-34' ) -- :InitRandomizeRoute( 1, 1, 3000 ) --- :InitRepeatOnLanding() +-- :InitRepeatOnLanding(20) -- :Spawn() -- -function SPAWN:InitRepeatOnLanding() +function SPAWN:InitRepeatOnLanding(WaitingTime) --self:F( { self.SpawnTemplatePrefix } ) self:InitRepeat() self.RepeatOnEngineShutDown = false self.RepeatOnLanding = true + self.RepeatOnLandingTime = (WaitingTime and WaitingTime > 3) and WaitingTime or 3 return self end @@ -4064,7 +4066,7 @@ function SPAWN:_OnLand( EventData ) -- self:ReSpawn( SpawnGroupIndex ) -- Delay respawn by three seconds due to DCS 2.5.4.26368 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076 -- Bug was initially only for engine shutdown event but after ED "fixed" it, it now happens on landing events. - SCHEDULER:New( nil, self.ReSpawn, { self, SpawnGroupIndex }, 3 ) + SCHEDULER:New( nil, self.ReSpawn, { self, SpawnGroupIndex }, self.RepeatOnLandingTime or 3 ) end end end