Skip to content

Commit e129df5

Browse files
authored
Merge branch 'master' into c3r341-global-necronomicon
2 parents 4a1c14f + 8a1e74a commit e129df5

File tree

20 files changed

+488
-3548
lines changed

20 files changed

+488
-3548
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
args: ['--fix=lf']
2121
- id: trailing-whitespace
2222
- repo: https://github.com/python-jsonschema/check-jsonschema
23-
rev: 0.29.3
23+
rev: 0.29.4
2424
hooks:
2525
- id: check-github-workflows
2626
- repo: https://github.com/Lucas-C/pre-commit-hooks

changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Template for new versions:
2828

2929
## New Tools
3030
- `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.
31+
- `immortal-cravings`: allow immortals to satisfy their cravings for food and drink
32+
- `justice`: various functions pertaining to the justice system, currently with a command to pardon a unit's prison sentence
3133

3234
## New Features
3335
- `force`: support the ``Wildlife`` event to allow additional wildlife to enter the map
@@ -38,6 +40,10 @@ Template for new versions:
3840
- `makeown`: halt any hostile jobs the unit may be engaged in, like kidnapping
3941
- `fix/loyaltycascade`: allow the fix to work on non-dwarven citizens
4042
- `control-panel`: fix setting numeric preferences from the commandline
43+
- `gui/quickfort`: fix build mode evluation rules to allow placement of various furniture and constructions on tiles with stair shapes or without orthagonal floor.
44+
- `emigration`: save-and-reload no longer resets the emigration cycle timeout, making gameplay more consistent
45+
- `geld`, `ungeld`: fix gelding/ungelding being undone for units who are historical figures when reloading a game
46+
- `rejuvenate`: fix error when specifying ``--age`` parameter
4147

4248
## Misc Improvements
4349
- `control-panel`: Add realistic-melting tweak to control-panel registry

docs/immortal-cravings.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
immortal-cravings
2+
=================
3+
4+
.. dfhack-tool::
5+
:summary: Allow immortals to satisfy their cravings for food and drink.
6+
:tags: fort gameplay
7+
8+
When enabled, this script watches your fort for units that have no physiological
9+
need to eat or drink but still have personality needs that can only be satisfied
10+
by eating or drinking (e.g. necromancers). This enables those units to help
11+
themselves to a drink or a meal when they crave one and are not otherwise
12+
occupied.
13+
14+
Usage
15+
-----
16+
17+
::
18+
19+
enable immortal-cravings

docs/justice.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
justice
2+
=======
3+
4+
.. dfhack-tool::
5+
:summary: Mess with the justice system.
6+
:tags: fort armok units
7+
8+
This tool allows control over aspects of the justice system, such as the
9+
ability to pardon criminals.
10+
11+
Usage
12+
-----
13+
14+
::
15+
justice [list]
16+
justice pardon [--unit <id>]
17+
18+
Pardon the selected unit or the one specified by unit id (if provided).
19+
Currently only applies to prison time and doesn't cancel beatings or
20+
hammerings.
21+
22+
Examples
23+
--------
24+
25+
``justice``
26+
List the convicts currently serving sentences.
27+
``justice pardon``
28+
Commutes the sentence of the currently selected convict.
29+
30+
Options
31+
-------
32+
33+
``-u``, ``--unit <id>``
34+
Specifies a specific unit instead of using a selected unit.

emigration.lua

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
--@module = true
22
--@enable = true
33

4+
local utils = require('utils')
5+
46
local GLOBAL_KEY = 'emigration' -- used for state change hooks and persistence
57

6-
enabled = enabled or false
8+
local function get_default_state()
9+
return {enabled=false, last_cycle_tick=0}
10+
end
11+
12+
state = state or get_default_state()
713

814
function isEnabled()
9-
return enabled
15+
return state.enabled
1016
end
1117

1218
local function persist_state()
13-
dfhack.persistent.saveSiteData(GLOBAL_KEY, {enabled=enabled})
19+
dfhack.persistent.saveSiteData(GLOBAL_KEY, state)
1420
end
1521

22+
local TICKS_PER_MONTH = 33600
23+
local TICKS_PER_YEAR = 12 * TICKS_PER_MONTH
24+
1625
function desireToStay(unit,method,civ_id)
1726
-- on a percentage scale
1827
local value = 100 - unit.status.current_soul.personality.stress / 5000
@@ -191,27 +200,36 @@ function checkmigrationnow()
191200
else
192201
for _, civ_id in pairs(merchant_civ_ids) do checkForDeserters('merchant', civ_id) end
193202
end
203+
204+
state.last_cycle_tick = dfhack.world.ReadCurrentTick() + TICKS_PER_YEAR * dfhack.world.ReadCurrentYear()
194205
end
195206

196207
local function event_loop()
197-
if enabled then
198-
checkmigrationnow()
199-
dfhack.timeout(1, 'months', event_loop)
208+
if state.enabled then
209+
local current_tick = dfhack.world.ReadCurrentTick() + TICKS_PER_YEAR * dfhack.world.ReadCurrentYear()
210+
if current_tick - state.last_cycle_tick < TICKS_PER_MONTH then
211+
local timeout_ticks = state.last_cycle_tick - current_tick + TICKS_PER_MONTH
212+
dfhack.timeout(timeout_ticks, 'ticks', event_loop)
213+
else
214+
checkmigrationnow()
215+
dfhack.timeout(1, 'months', event_loop)
216+
end
200217
end
201218
end
202219

203220
dfhack.onStateChange[GLOBAL_KEY] = function(sc)
204221
if sc == SC_MAP_UNLOADED then
205-
enabled = false
222+
state.enabled = false
206223
return
207224
end
208225

209226
if sc ~= SC_MAP_LOADED or df.global.gamemode ~= df.game_mode.DWARF then
210227
return
211228
end
212229

213-
local persisted_data = dfhack.persistent.getSiteData(GLOBAL_KEY, {enabled=false})
214-
enabled = persisted_data.enabled
230+
state = get_default_state()
231+
utils.assign(state, dfhack.persistent.getSiteData(GLOBAL_KEY, state))
232+
215233
event_loop()
216234
end
217235

@@ -230,11 +248,11 @@ if dfhack_flags and dfhack_flags.enable then
230248
end
231249

232250
if args[1] == "enable" then
233-
enabled = true
251+
state.enabled = true
234252
elseif args[1] == "disable" then
235-
enabled = false
253+
state.enabled = false
236254
else
237-
print('emigration is ' .. (enabled and 'enabled' or 'not enabled'))
255+
print('emigration is ' .. (state.enabled and 'enabled' or 'not enabled'))
238256
return
239257
end
240258

geld.lua

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
-- Gelds or ungelds animals
2-
-- Written by Josh Cooper(cppcooper) on 2019-12-10, last modified: 2020-02-23
3-
4-
utils = require('utils')
1+
local utils = require('utils')
52

63
local validArgs = utils.invert({
74
'unit',
85
'toggle',
96
'ungeld',
107
'help',
11-
'find',
128
})
139
local args = utils.processArgs({...}, validArgs)
14-
local help = [====[
15-
16-
geld
17-
====
18-
Geld allows the user to geld and ungeld animals.
19-
20-
Valid options:
21-
22-
``-unit <id>``: Gelds the unit with the specified ID.
23-
This is optional; if not specified, the selected unit is used instead.
24-
25-
``-ungeld``: Ungelds the specified unit instead (see also `ungeld`).
26-
27-
``-toggle``: Toggles the gelded status of the specified unit.
2810

29-
``-help``: Shows this help information
30-
31-
]====]
32-
33-
unit=nil
11+
local unit = nil
3412

3513
if args.help then
36-
print(help)
14+
print(dfhack.script_help())
3715
return
3816
end
3917

@@ -42,7 +20,7 @@ if args.unit then
4220
if id then
4321
unit = df.unit.find(id)
4422
else
45-
qerror("Invalid ID provided.")
23+
qerror("Invalid unit ID provided.")
4624
end
4725
else
4826
unit = dfhack.gui.getSelectedUnit()
@@ -53,55 +31,75 @@ if not unit then
5331
end
5432

5533
if unit.sex == df.pronoun_type.she then
56-
qerror("Cannot geld female animals")
57-
return
34+
qerror("Cannot geld female animals.")
5835
end
5936

60-
function FindBodyPart(unit,newstate)
61-
bfound = false
62-
for i,wound in ipairs(unit.body.wounds) do
63-
for j,part in ipairs(wound.parts) do
64-
if unit.body.wounds[i].parts[j].flags2.gelded ~= newstate then
65-
bfound = true
66-
if newstate ~= nil then
67-
unit.body.wounds[i].parts[j].flags2.gelded = newstate
68-
end
69-
end
37+
-- Find the geldable body part id, returns -1 on failure
38+
local function FindBodyPartId(unit)
39+
for i,part in ipairs(unit.body.body_plan.body_parts) do
40+
if part.flags.GELDABLE then
41+
return i
7042
end
7143
end
72-
return bfound
44+
return -1
7345
end
7446

75-
function AddParts(unit)
76-
for i,wound in ipairs(unit.body.wounds) do
77-
if wound.id == 1 and #wound.parts == 0 then
78-
utils.insert_or_update(unit.body.wounds[i].parts,{ new = true, body_part_id = 1 }, 'body_part_id')
79-
end
47+
-- Sets the gelded status of a unit, returns false on failure
48+
local function SetGelded(unit, state)
49+
-- Gelded status is set in a number of places:
50+
-- unit.flags3
51+
-- unit.body.wounds
52+
-- unit.body.components.body_part_status
53+
54+
local part_id = FindBodyPartId(unit)
55+
if part_id == -1 then
56+
print("Could not find a geldable body part.")
57+
return false
8058
end
81-
end
8259

83-
function Geld(unit)
84-
unit.flags3.gelded = true
85-
if not FindBodyPart(unit,true) then
86-
utils.insert_or_update(unit.body.wounds,{ new = true, id = unit.body.wound_next_id }, 'id')
60+
unit.flags3.gelded = state
61+
62+
if state then
63+
-- Create new wound
64+
local _,wound,_ = utils.insert_or_update(unit.body.wounds, { new = true, id = unit.body.wound_next_id }, 'id')
8765
unit.body.wound_next_id = unit.body.wound_next_id + 1
88-
AddParts(unit)
89-
if not FindBodyPart(unit,true) then
90-
error("could not find body part")
66+
local _,part,_ = utils.insert_or_update(wound.parts, { new = true, body_part_id = part_id}, 'body_part_id')
67+
part.flags2.gelded = true
68+
else
69+
-- Remove gelding from any existing wounds
70+
for _,wound in ipairs(unit.body.wounds) do
71+
for _,part in ipairs(wound.parts) do
72+
part.flags2.gelded = false
73+
end
74+
end
75+
end
76+
77+
if state then
78+
-- Set part status to gelded
79+
unit.body.components.body_part_status[part_id].gelded = true
80+
else
81+
-- Remove gelded status from all parts
82+
for _,part in ipairs(unit.body.components.body_part_status) do
83+
part.gelded = false
9184
end
9285
end
93-
print(string.format("unit %s gelded.",unit.id))
86+
return true
9487
end
9588

96-
function Ungeld(unit)
97-
unit.flags3.gelded = false
98-
FindBodyPart(unit,false)
99-
print(string.format("unit %s ungelded.",unit.id))
89+
local function Geld(unit)
90+
if SetGelded(unit, true) then
91+
print(string.format("Unit %s gelded.", unit.id))
92+
else
93+
print(string.format("Failed to geld unit %s.", unit.id))
94+
end
10095
end
10196

102-
if args.find then
103-
print(FindBodyPart(unit) and "found" or "not found")
104-
return
97+
local function Ungeld(unit)
98+
if SetGelded(unit, false) then
99+
print(string.format("Unit %s ungelded.", unit.id))
100+
else
101+
print(string.format("Failed to ungeld unit %s.", unit.id))
102+
end
105103
end
106104

107105
local oldstate = dfhack.units.isGelded(unit)
@@ -122,5 +120,5 @@ if newstate ~= oldstate then
122120
Ungeld(unit)
123121
end
124122
else
125-
qerror(string.format("unit %s is already %s", unit.id, oldstate and "gelded" or "ungelded"))
123+
qerror(string.format("Unit %s is already %s.", unit.id, oldstate and "gelded" or "ungelded"))
126124
end

gui/journal.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local gui = require 'gui'
55
local widgets = require 'gui.widgets'
66
local utils = require 'utils'
77
local json = require 'json'
8-
local text_editor = reqscript('internal/journal/text_editor')
98
local shifter = reqscript('internal/journal/shifter')
109
local table_of_contents = reqscript('internal/journal/table_of_contents')
1110

@@ -113,7 +112,7 @@ function JournalWindow:init()
113112
interior_b=true,
114113
frame_style_t=false,
115114
},
116-
text_editor.TextEditor{
115+
widgets.TextArea{
117116
view_id='journal_editor',
118117
frame={t=1, b=3, l=25, r=0},
119118
resize_min={w=30, h=10},

gui/manipulator.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,12 @@ function ManipulatorOverlay:init()
13411341
}
13421342
end
13431343

1344-
OVERLAY_WIDGETS = {
1345-
launcher=ManipulatorOverlay,
1346-
}
1344+
--
1345+
-- disable overlay widget while tool is still in dark launch mode
1346+
--
1347+
-- OVERLAY_WIDGETS = {
1348+
-- launcher=ManipulatorOverlay,
1349+
-- }
13471350

13481351
if dfhack_flags.module then return end
13491352

gui/notify.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ DwarfNotifyOverlay.ATTRS{
132132
}
133133

134134
local DWARFMODE_CONFLICTING_TOOLTIPS = utils.invert{
135-
df.main_hover_instruction.InfoUnits,
136-
df.main_hover_instruction.InfoJobs,
137-
df.main_hover_instruction.InfoPlaces,
138-
df.main_hover_instruction.InfoLabors,
139-
df.main_hover_instruction.InfoWorkOrders,
140-
df.main_hover_instruction.InfoNobles,
141-
df.main_hover_instruction.InfoObjects,
142-
df.main_hover_instruction.InfoJustice,
135+
df.main_hover_instruction.MAIN_OPEN_CREATURES,
136+
df.main_hover_instruction.MAIN_OPEN_TASKS,
137+
df.main_hover_instruction.MAIN_OPEN_PLACES,
138+
df.main_hover_instruction.MAIN_OPEN_LABOR,
139+
df.main_hover_instruction.MAIN_OPEN_WORK_ORDERS,
140+
df.main_hover_instruction.MAIN_OPEN_NOBLES,
141+
df.main_hover_instruction.MAIN_OPEN_OBJECTS,
142+
df.main_hover_instruction.MAIN_OPEN_JUSTICE,
143143
}
144144

145145
local mi = df.global.game.main_interface

0 commit comments

Comments
 (0)