diff --git a/changelog/snippets/features.7132.md b/changelog/snippets/features.7132.md new file mode 100644 index 0000000000..1cd04e7672 --- /dev/null +++ b/changelog/snippets/features.7132.md @@ -0,0 +1,3 @@ +- (#7132) Gorton's birthday present + +When playing full share, when you self destruct a selection with one or more ACUs in it you will self destruct only the ACUs instead. diff --git a/changelog/snippets/sections/graphics.7095.md b/changelog/snippets/graphics.7095.md similarity index 100% rename from changelog/snippets/sections/graphics.7095.md rename to changelog/snippets/graphics.7095.md diff --git a/lua/SimCallbacks.lua b/lua/SimCallbacks.lua index 63d984c647..34169119f5 100644 --- a/lua/SimCallbacks.lua +++ b/lua/SimCallbacks.lua @@ -179,7 +179,34 @@ Callbacks.UpdateMarker = SimPing.UpdateMarker Callbacks.FactionSelection = ScenarioFramework.OnFactionSelect -Callbacks.ToggleSelfDestruct = import("/lua/selfdestruct.lua").ToggleSelfDestruct +---@param data ToggleSelfDestructData +---@param units Unit[] +Callbacks.ToggleSelfDestruct = function(data, units) + -- prevent malformed input + if (not units) or (table.getn(units) == 0) then + return + end + + -- prevent abuse + if (not data) or (not data.owner) or (not OkayToMessWithArmy(data.owner)) then + return + end + + -- moderation rule: if you self destruct with one or more ACUs in the selection when playing full + -- share, then you only self destruct the ACUs. This does not make it impossible to abuse, but it + -- does introduce a simple guardrail. + if ScenarioInfo.Options.Share == "FullShare" then + local commandUnits = EntityCategoryFilterDown(categories.COMMAND, SecureUnits(units)) + if table.getn(commandUnits) > 0 then + import("/lua/selfdestruct.lua").ToggleSelfDestruct(data, commandUnits) + return + end + end + + -- otherwise just pass it through as usual + import("/lua/selfdestruct.lua").ToggleSelfDestruct(data, units) +end + Callbacks.MarkerOnScreen = import("/lua/simcameramarkers.lua").MarkerOnScreen diff --git a/lua/selfdestruct.lua b/lua/selfdestruct.lua index e7681efcb2..a2bd229732 100644 --- a/lua/selfdestruct.lua +++ b/lua/selfdestruct.lua @@ -5,6 +5,10 @@ local CancelCountdown = CancelCountdown local ForkThread = ForkThread local KillThread = KillThread +---@class ToggleSelfDestructData +---@field owner number +---@field noDelay boolean + -- prevent magic numbers local countdownDuration = 5 @@ -20,7 +24,7 @@ local function SelfDestructThread(unit) end --- Toggles the destruction of the units ----@param data { owner: number, noDelay: boolean } +---@param data ToggleSelfDestructData ---@param units? Unit[] function ToggleSelfDestruct(data, units)