From 30819dad720d99c17277f149557e4fab90e7ed13 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 22 Feb 2024 09:00:54 +0100 Subject: [PATCH 1/2] Catch for invalid STN/SADL octals --- Moose Development/Moose/Core/Database.lua | 16 ++++++++++++---- Moose Development/Moose/Core/Spawn.lua | 12 ++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 8ffedba7b..47884fae0 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -1037,13 +1037,21 @@ function DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, Category if UnitTemplate.AddPropAircraft then if UnitTemplate.AddPropAircraft.STN_L16 then local stn = UTILS.OctalToDecimal(UnitTemplate.AddPropAircraft.STN_L16) - self.STNS[stn] = UnitTemplate.name - self:I("Register STN "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name) + if stn == nil or stn < 1 then + self:E("WARNING: Invalid STN "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name) + else + self.STNS[stn] = UnitTemplate.name + self:I("Register STN "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name) + end end if UnitTemplate.AddPropAircraft.SADL_TN then local sadl = UTILS.OctalToDecimal(UnitTemplate.AddPropAircraft.SADL_TN) - self.SADL[sadl] = UnitTemplate.name - self:I("Register SADL "..tostring(UnitTemplate.AddPropAircraft.SADL_TN).." for ".. UnitTemplate.name) + if sadl == nil or sadl < 1 then + self:E("WARNING: Invalid SADL "..tostring(UnitTemplate.AddPropAircraft.STN_L16).." for ".. UnitTemplate.name) + else + self.SADL[sadl] = UnitTemplate.name + self:I("Register SADL "..tostring(UnitTemplate.AddPropAircraft.SADL_TN).." for ".. UnitTemplate.name) + end end end diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 97d30dfe5..5de09ed58 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -782,12 +782,16 @@ end --- [Airplane - F15/16/18/AWACS/B1B/Tanker only] Set the STN Link16 starting number of the Group; each unit of the spawned group will have a consecutive STN set. -- @param #SPAWN self --- @param #number Octal The octal number (digits 1..7, max 5 digits, i.e. 77777) to set the STN to. Every STN needs to be unique! +-- @param #number Octal The octal number (digits 1..7, max 5 digits, i.e. 1..77777) to set the STN to. Every STN needs to be unique! -- @return #SPAWN self function SPAWN:InitSTN(Octal) self:F( { Octal = Octal } ) self.SpawnInitSTN = Octal or 77777 local num = UTILS.OctalToDecimal(Octal) + if num == nil or num < 1 then + self:E("WARNING - STN "..tostring(Octal).." is not valid!") + return self + end if _DATABASE.STNS[num] ~= nil then self:E("WARNING - STN already assigned: "..tostring(Octal).." is used for ".._DATABASE.STNS[Octal]) end @@ -796,12 +800,16 @@ end --- [Airplane - A10-C II only] Set the SADL TN starting number of the Group; each unit of the spawned group will have a consecutive SADL set. -- @param #SPAWN self --- @param #number Octal The octal number (digits 1..7, max 4 digits, i.e. 7777) to set the SADL to. Every SADL needs to be unique! +-- @param #number Octal The octal number (digits 1..7, max 4 digits, i.e. 1..7777) to set the SADL to. Every SADL needs to be unique! -- @return #SPAWN self function SPAWN:InitSADL(Octal) self:F( { Octal = Octal } ) self.SpawnInitSADL = Octal or 7777 local num = UTILS.OctalToDecimal(Octal) + if num == nil or num < 1 then + self:E("WARNING - SADL "..tostring(Octal).." is not valid!") + return self + end if _DATABASE.SADL[num] ~= nil then self:E("WARNING - SADL already assigned: "..tostring(Octal).." is used for ".._DATABASE.SADL[Octal]) end From 2ce9f26e26d96061ed49917ff8bae24352da4056 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 22 Feb 2024 09:19:22 +0100 Subject: [PATCH 2/2] Docu --- Moose Development/Moose/Core/Spawn.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 5de09ed58..705da5929 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -199,6 +199,11 @@ -- -- * @{#SPAWN.InitRepeat}() or @{#SPAWN.InitRepeatOnLanding}(): This method is used to re-spawn automatically the same group after it has landed. -- * @{#SPAWN.InitRepeatOnEngineShutDown}(): This method is used to re-spawn automatically the same group after it has landed and it shuts down the engines at the ramp. +-- +-- ### Link-16 Datalink STN and SADL IDs (limited at the moment to F15/16/18/AWACS/Tanker/B1B, but not the F15E for clients, SADL A10CII only) +-- +-- *{#SPAWN.InitSTN}(): Set the STN of the first unit in the group. All other units will have consecutive STNs, provided they have not been used yet. +-- *{#SPAWN.InitSADL}(): Set the SADL of the first unit in the group. All other units will have consecutive SADLs, provided they have not been used yet. -- -- ## SPAWN **Spawn** methods --