From 782ea3da1654d3fb8c998087a83a383ed26c7e5c Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Thu, 20 Jun 2024 18:18:16 +0100 Subject: [PATCH 1/4] added script commute-sentence to commute the prison sentence of a selected unit --- commute-sentence.lua | 19 +++++++++++++++++++ docs/commute-sentence.rst | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 commute-sentence.lua create mode 100644 docs/commute-sentence.rst diff --git a/commute-sentence.lua b/commute-sentence.lua new file mode 100644 index 0000000000..8e2a15cb93 --- /dev/null +++ b/commute-sentence.lua @@ -0,0 +1,19 @@ +local utils = require('utils') +local argparse = require('argparse') + +local function commute_sentence(unit) + for _,punishment in ipairs(df.global.plotinfo.punishments) do + if punishment.criminal == unit.id then + punishment.prison_counter = 0 + return + end + end + qerror('Unit is not currently serving a sentence!') +end + +unit = dfhack.gui.getSelectedUnit(true) +if not unit then + qerror('No unit selected!') +else + commute_sentence(unit) +end diff --git a/docs/commute-sentence.rst b/docs/commute-sentence.rst new file mode 100644 index 0000000000..f2f36bbaa1 --- /dev/null +++ b/docs/commute-sentence.rst @@ -0,0 +1,16 @@ +commute-sentence +================ + +.. dfhack-tool:: + :summary: Commute the prison sentences of convicted criminals. + :tags: fort armok units + +If a unit is currently serving out their sentence but you want them released +for whatever reason, this tool can commute their sentence. Just select the unit +and run the command. + +usage +----- + +:: + commute-sentence From 613c3ecaef2a0909b7273aa686b42d3e558b076e Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 21 Jun 2024 23:17:56 +0100 Subject: [PATCH 2/4] changed commute-sentence to justice with command option pardon --- commute-sentence.lua | 19 ------------------- docs/commute-sentence.rst | 16 ---------------- docs/justice.rst | 25 ++++++++++++++++++++++++ justice.lua | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 35 deletions(-) delete mode 100644 commute-sentence.lua delete mode 100644 docs/commute-sentence.rst create mode 100644 docs/justice.rst create mode 100644 justice.lua diff --git a/commute-sentence.lua b/commute-sentence.lua deleted file mode 100644 index 8e2a15cb93..0000000000 --- a/commute-sentence.lua +++ /dev/null @@ -1,19 +0,0 @@ -local utils = require('utils') -local argparse = require('argparse') - -local function commute_sentence(unit) - for _,punishment in ipairs(df.global.plotinfo.punishments) do - if punishment.criminal == unit.id then - punishment.prison_counter = 0 - return - end - end - qerror('Unit is not currently serving a sentence!') -end - -unit = dfhack.gui.getSelectedUnit(true) -if not unit then - qerror('No unit selected!') -else - commute_sentence(unit) -end diff --git a/docs/commute-sentence.rst b/docs/commute-sentence.rst deleted file mode 100644 index f2f36bbaa1..0000000000 --- a/docs/commute-sentence.rst +++ /dev/null @@ -1,16 +0,0 @@ -commute-sentence -================ - -.. dfhack-tool:: - :summary: Commute the prison sentences of convicted criminals. - :tags: fort armok units - -If a unit is currently serving out their sentence but you want them released -for whatever reason, this tool can commute their sentence. Just select the unit -and run the command. - -usage ------ - -:: - commute-sentence diff --git a/docs/justice.rst b/docs/justice.rst new file mode 100644 index 0000000000..4334f5057b --- /dev/null +++ b/docs/justice.rst @@ -0,0 +1,25 @@ +justice +======= + +.. dfhack-tool:: + :summary: Commands related to the justice system + :tags: fort armok units + +This tool allows control over aspects of the justice system, such as the +ability to pardon criminals. + +usage +----- + +:: + justice pardon [--unit ] + +Pardon the selected unit or the one specified by unit id if provided. Currently +only applies to prison time and doesn't cancel beatings or hammerings. + + +options +------- + +``-u``, ``--unit `` + Specifies the unit id of the target of the command. diff --git a/justice.lua b/justice.lua new file mode 100644 index 0000000000..f86b4fbed4 --- /dev/null +++ b/justice.lua @@ -0,0 +1,40 @@ + +local argparse = require('argparse') + +local function pardon_unit(unit) + for _,punishment in ipairs(df.global.plotinfo.punishments) do + if punishment.criminal == unit.id then + punishment.prison_counter = 0 + return + end + end + qerror('Unit is not currently serving a sentence!') +end + +local function command_pardon(unit_id) + local unit = nil + if not unit_id then + unit = dfhack.gui.getSelectedUnit() + if not unit then qerror("No unit selected!") end + else + unit = df.unit.find(unit_id) + if not unit then qerror(("No unit with id %i"):format(unit_id)) end + end + if unit then pardon_unit(unit) end +end + +local unit_id = nil + +local args = {...} + +local positionals = argparse.processArgsGetopt(args, + {'u', 'unit', hasArg=true, handler=function(optarg) unit_id = optarg end} +) + +local command = positionals[1] + +if command == "pardon" then + command_pardon(unit_id) +end + +qerror(("Unrecognised command: %s"):format(command)) From 622b7118772a5cdadb1990eba88d402e0233cd6a Mon Sep 17 00:00:00 2001 From: master-spike Date: Mon, 28 Oct 2024 00:27:58 +0000 Subject: [PATCH 3/4] `justice` - line added to changelog for introduction of this script --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 384f2560ad..e95538a05c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -29,6 +29,7 @@ Template for new versions: ## New Tools - `fix/wildlife`: prevent wildlife from getting stuck when trying to exit the map. This fix needs to be enabled manually in `gui/control-panel` on the Bug Fixes tab since not all players want this bug to be fixed. - `immortal-cravings`: allow immortals to satisfy their cravings for food and drink +- `justice`: various functions pertaining to the justice system, currently with a command to pardon a unit's prison sentence. ## New Features - `force`: support the ``Wildlife`` event to allow additional wildlife to enter the map From 7d7baca9332d15936ed7a0a05e68edd97f5252b3 Mon Sep 17 00:00:00 2001 From: master-spike Date: Mon, 28 Oct 2024 00:40:59 +0000 Subject: [PATCH 4/4] justice: implement code review suggestions --- docs/justice.rst | 11 ++++++----- justice.lua | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/justice.rst b/docs/justice.rst index 4334f5057b..e5ff93cbcb 100644 --- a/docs/justice.rst +++ b/docs/justice.rst @@ -2,23 +2,24 @@ justice ======= .. dfhack-tool:: - :summary: Commands related to the justice system + :summary: Commands related to the justice system. :tags: fort armok units This tool allows control over aspects of the justice system, such as the ability to pardon criminals. -usage +Usage ----- :: justice pardon [--unit ] -Pardon the selected unit or the one specified by unit id if provided. Currently -only applies to prison time and doesn't cancel beatings or hammerings. +Pardon the selected unit or the one specified by unit id (if provided). +Currently only applies to prison time and doesn't cancel beatings or +hammerings. -options +Options ------- ``-u``, ``--unit `` diff --git a/justice.lua b/justice.lua index f86b4fbed4..5071f24458 100644 --- a/justice.lua +++ b/justice.lua @@ -35,6 +35,8 @@ local command = positionals[1] if command == "pardon" then command_pardon(unit_id) +elseif not command then + qerror('Missing command') +else + qerror(("Unrecognised command: %s"):format(command)) end - -qerror(("Unrecognised command: %s"):format(command))