Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to commute the prison sentence of a convicted criminal #1200

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

master-spike
Copy link
Contributor

@master-spike master-spike commented Jun 20, 2024

@myk002
Copy link
Member

myk002 commented Jun 21, 2024

commute-sentence isn't quite as discoverable as I'd like it to be. Could we instead call it justice? The initial functionality here could be invoked as justice pardon, and the overall syntax would be:

justice <command> [<options>]

with just the one command (pardon) for now. it should at least take a -u, --unit option to allow specific unit ids to be specified, and if no id is specified then it defaults to the selected unit.

@master-spike master-spike force-pushed the commute_sentence branch 3 times, most recently from d1081ea to 7b85a77 Compare June 21, 2024 22:24
docs/justice.rst Outdated
=======

.. dfhack-tool::
:summary: Commands related to the justice system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:summary: Commands related to the justice system
:summary: Commands related to the justice system.

docs/justice.rst Outdated
This tool allows control over aspects of the justice system, such as the
ability to pardon criminals.

usage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
usage
Usage

docs/justice.rst Outdated
::
justice pardon [--unit <id>]

Pardon the selected unit or the one specified by unit id if provided. Currently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Pardon the selected unit or the one specified by unit id if provided. Currently
Pardon the selected unit or the one specified by unit id (if provided). Currently

docs/justice.rst Outdated
only applies to prison time and doesn't cancel beatings or hammerings.


options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options
Options

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if unit then pardon_unit(unit) end
pardon_unit(unit)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need this check because unit can still be nil if a unit wasn't found by either of the methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a unit was not found in either of the if branches above, then qerror will throw

justice.lua Outdated
Comment on lines 38 to 40
end

qerror(("Unrecognised command: %s"):format(command))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end
qerror(("Unrecognised command: %s"):format(command))
elseif not command then
qerror('missing command')
else
qerror(("Unrecognised command: %s"):format(command))
end

Copy link
Member

@myk002 myk002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a line to the changelog under New tools

@master-spike
Copy link
Contributor Author

pre-commit.ci autofix

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a unit was not found in either of the if branches above, then qerror will throw

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not unit then qerror(("No unit with id %i"):format(unit_id)) end
if not unit then qerror(("No unit with id %d"):format(unit_id)) end

if command == "pardon" then
command_pardon(unit_id)
elseif not command then
qerror('Missing command')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qerror('Missing command')
print(dfhack.script_help())

@myk002
Copy link
Member

myk002 commented Nov 28, 2024

github doesn't seem to be able to merge this for some reason, so I'll do some git magic in #1341

myk002 added a commit that referenced this pull request Nov 28, 2024
@myk002 myk002 merged commit dbce375 into DFHack:master Nov 28, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Command to commute the prison sentence of convicted criminals
2 participants