|
1 |
| - |
2 | 1 | local argparse = require('argparse')
|
3 | 2 |
|
| 3 | +local TICKS_PER_SEASON_TICK = 10 |
| 4 | +local TICKS_PER_DAY = 1200 |
| 5 | + |
| 6 | +local function list_convicts() |
| 7 | + local found = false |
| 8 | + for _,punishment in ipairs(df.global.plotinfo.punishments) do |
| 9 | + local unit = df.unit.find(punishment.criminal) |
| 10 | + if unit and punishment.prison_counter > 0 then |
| 11 | + found = true |
| 12 | + local days = math.ceil((punishment.prison_counter * TICKS_PER_SEASON_TICK) / TICKS_PER_DAY) |
| 13 | + print(('%s (id: %d): serving a sentence of %d day(s)'):format( |
| 14 | + dfhack.units.getReadableName(unit), unit.id, days)) |
| 15 | + end |
| 16 | + end |
| 17 | + if not found then |
| 18 | + print('No criminals currently serving sentences.') |
| 19 | + end |
| 20 | +end |
| 21 | + |
4 | 22 | local function pardon_unit(unit)
|
5 | 23 | for _,punishment in ipairs(df.global.plotinfo.punishments) do
|
6 | 24 | if punishment.criminal == unit.id then
|
|
14 | 32 | local function command_pardon(unit_id)
|
15 | 33 | local unit = nil
|
16 | 34 | if not unit_id then
|
17 |
| - unit = dfhack.gui.getSelectedUnit() |
18 |
| - if not unit then qerror("No unit selected!") end |
| 35 | + unit = dfhack.gui.getSelectedUnit(true) |
| 36 | + if not unit then qerror('No unit selected!') end |
19 | 37 | else
|
20 | 38 | unit = df.unit.find(unit_id)
|
21 |
| - if not unit then qerror(("No unit with id %i"):format(unit_id)) end |
| 39 | + if not unit then qerror(('No unit with id %d'):format(unit_id)) end |
22 | 40 | end
|
23 |
| - if unit then pardon_unit(unit) end |
| 41 | + pardon_unit(unit) |
24 | 42 | end
|
25 | 43 |
|
26 | 44 | local unit_id = nil
|
27 | 45 |
|
28 |
| -local args = {...} |
29 |
| - |
30 |
| -local positionals = argparse.processArgsGetopt(args, |
31 |
| - {'u', 'unit', hasArg=true, handler=function(optarg) unit_id = optarg end} |
| 46 | +local positionals = argparse.processArgsGetopt({...}, |
| 47 | + { |
| 48 | + {'u', 'unit', hasArg=true, |
| 49 | + handler=function(optarg) unit_id = argparse.nonnegativeInt(optarg, 'unit') end}, |
| 50 | + } |
32 | 51 | )
|
33 | 52 |
|
34 | 53 | local command = positionals[1]
|
35 | 54 |
|
36 |
| -if command == "pardon" then |
| 55 | +if command == 'pardon' then |
37 | 56 | command_pardon(unit_id)
|
38 |
| -elseif not command then |
39 |
| - qerror('Missing command') |
| 57 | +elseif not command or command == 'list' then |
| 58 | + list_convicts() |
40 | 59 | else
|
41 |
| - qerror(("Unrecognised command: %s"):format(command)) |
| 60 | + qerror(('Unrecognised command: %s'):format(command)) |
42 | 61 | end
|
0 commit comments