Skip to content

Commit 6d5340f

Browse files
committed
Merge remote-tracking branch 'origin/master' into autocheese
2 parents 44b5547 + 1a58e45 commit 6d5340f

File tree

8 files changed

+163
-216
lines changed

8 files changed

+163
-216
lines changed

assign-preferences.lua

Lines changed: 53 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,12 @@
11
-- Change the preferences of a unit.
22
--@ module = true
33

4-
local help = [====[
5-
6-
assign-preferences
7-
==================
8-
A script to change the preferences of a unit.
9-
10-
Preferences are classified into 12 types. The first 9 are:
11-
12-
* like material;
13-
* like creature;
14-
* like food;
15-
* hate creature;
16-
* like item;
17-
* like plant;
18-
* like tree;
19-
* like colour;
20-
* like shape.
21-
22-
These can be changed using this script.
23-
24-
The remaining three are not currently managed by this script,
25-
and are: like poetic form, like musical form, like dance form.
26-
27-
To produce the correct description in the "thoughts and preferences"
28-
page, you must specify the particular type of preference. For
29-
each type, a description is provided in the section below.
30-
31-
You will need to know the token of the object you want your dwarf to like.
32-
You can find them in the wiki, otherwise in the folder "/raw/objects/" under
33-
the main DF directory you will find all the raws defined in the game.
34-
35-
For more information:
36-
https://dwarffortresswiki.org/index.php/DF2014:Preferences
37-
38-
Usage:
39-
40-
``-help``:
41-
print the help page.
42-
43-
``-unit <UNIT_ID>``:
44-
set the target unit ID. If not present, the
45-
currently selected unit will be the target.
46-
47-
``-likematerial [ <TOKEN> <TOKEN> <...> ]``:
48-
usually a type of stone, a type of metal and a type
49-
of gem, plus it can also be a type of wood, a type of
50-
glass, a type of leather, a type of horn, a type of
51-
pearl, a type of ivory, a decoration material - coral
52-
or amber, a type of bone, a type of shell, a type
53-
of silk, a type of yarn, or a type of plant cloth.
54-
Write the full tokens.
55-
There must be a space before and after each square
56-
bracket.
57-
58-
``-likecreature [ <TOKEN> <TOKEN> <...> ]``:
59-
one or more creatures liked by the unit. You can
60-
just list the species: the creature token will be
61-
something similar to ``CREATURE:SPARROW:SKIN``,
62-
so the name of the species will be ``SPARROW``. Nothing
63-
will stop you to write the full token, if you want: the
64-
script will just ignore the first and the last parts.
65-
There must be a space before and after each square
66-
bracket.
67-
68-
``-likefood [ <TOKEN> <TOKEN> <...> ]``:
69-
usually a type of alcohol, plus it can be a type of
70-
meat, a type of fish, a type of cheese, a type of edible
71-
plant, a cookable plant/creature extract, a cookable
72-
mill powder, a cookable plant seed or a cookable plant
73-
leaf. Write the full tokens.
74-
There must be a space before and after each square
75-
bracket.
76-
77-
``-hatecreature [ <TOKEN> <TOKEN> <...> ]``:
78-
works the same way as ``-likecreature``, but this time
79-
it's one or more creatures that the unit detests. They
80-
should be a type of ``HATEABLE`` vermin which isn't already
81-
explicitly liked, but no check is performed about this.
82-
Like before, you can just list the creature species.
83-
There must be a space before and after each square
84-
bracket.
85-
86-
``-likeitem [ <TOKEN> <TOKEN> <...> ]``:
87-
a kind of weapon, a kind of ammo, a kind of piece of
88-
armor, a piece of clothing (including backpacks or
89-
quivers), a type of furniture (doors, floodgates, beds,
90-
chairs, windows, cages, barrels, tables, coffins,
91-
statues, boxes, armor stands, weapon racks, cabinets,
92-
bins, hatch covers, grates, querns, millstones, traction
93-
benches, or slabs), a kind of craft (figurines, amulets,
94-
scepters, crowns, rings, earrings, bracelets, or large
95-
gems), or a kind of miscellaneous item (catapult parts,
96-
ballista parts, a type of siege ammo, a trap component,
97-
coins, anvils, totems, chains, flasks, goblets,
98-
buckets, animal traps, an instrument, a toy, splints,
99-
crutches, or a tool). The item tokens can be found here:
100-
https://dwarffortresswiki.org/index.php/DF2014:Item_token
101-
If you want to specify an item subtype, look into the files
102-
listed under the column "Subtype" of the wiki page (they are
103-
in the "/raw/ojects/" folder), then specify the items using
104-
the full tokens found in those files (see examples below).
105-
There must be a space before and after each square
106-
bracket.
107-
108-
``-likeplant [ <TOKEN> <TOKEN> <...> ]``:
109-
works in a similar way as ``-likecreature``, this time
110-
with plants. You can just List the plant species (the
111-
middle part of the token).
112-
There must be a space before and after each square
113-
bracket.
114-
115-
``-liketree [ <TOKEN> <TOKEN> <...> ]``:
116-
works exactly as ``-likeplant``. I think this
117-
preference type is here for backward compatibility (?).
118-
You can still use it, however. As before,
119-
you can just list the tree (plant) species.
120-
There must be a space before and after each square
121-
bracket.
122-
123-
``-likecolor [ <TOKEN> <TOKEN> <...> ]``:
124-
you can find the color tokens here:
125-
https://dwarffortresswiki.org/index.php/DF2014:Color#Color_tokens
126-
or inside the "descriptor_color_standard.txt" file
127-
(in the "/raw/ojects/" folder). You can use the full token or
128-
just the color name.
129-
There must be a space before and after each square
130-
bracket.
131-
132-
``-likeshape [ <TOKEN> <TOKEN> <...> ]``:
133-
I couldn't find a list of shape tokens in the wiki, but you
134-
can find them inside the "descriptor_shape_standard.txt"
135-
file (in the "/raw/ojects/" folder). You can
136-
use the full token or just the shape name.
137-
There must be a space before and after each square
138-
bracket.
139-
140-
``-reset``:
141-
clear all preferences. If the script is called
142-
with both this option and one or more preferences,
143-
first all the unit preferences will be cleared
144-
and then the listed preferences will be added.
145-
146-
Examples:
147-
148-
* "likes alabaster and willow wood"::
149-
150-
assign-preferences -reset -likematerial [ INORGANIC:ALABASTER PLANT:WILLOW:WOOD ]
151-
152-
* "likes sparrows for their ..."::
153-
154-
assign-preferences -reset -likecreature SPARROW
155-
156-
* "prefers to consume dwarven wine and olives"::
157-
158-
assign-preferences -reset -likefood [ PLANT:MUSHROOM_HELMET_PLUMP:DRINK PLANT:OLIVE:FRUIT ]
159-
160-
* "absolutely detests jumping spiders::
161-
162-
assign-preferences -reset -hatecreature SPIDER_JUMPING
163-
164-
* "likes logs and battle axes"::
165-
166-
assign-preferences -reset -likeitem [ WOOD ITEM_WEAPON:ITEM_WEAPON_AXE_BATTLE ]
167-
168-
* "likes straberry plants for their ..."::
169-
170-
assign-preferences -reset -likeplant BERRIES_STRAW
171-
172-
* "likes oaks for their ..."::
173-
174-
assign-preferences -reset -liketree OAK
175-
176-
* "likes the color aqua"::
177-
178-
assign-preferences -reset -likecolor AQUA
179-
180-
* "likes stars"::
181-
182-
assign-preferences -reset -likeshape STAR
183-
184-
]====]
185-
1864
local utils = require("utils")
1875

1886
local valid_args = utils.invert({
1897
'help',
1908
'unit',
9+
'show',
19110
'likematerial',
19211
'likecreature',
19312
'likefood',
@@ -207,6 +26,38 @@ local function print_yellow(text)
20726
dfhack.color(-1)
20827
end
20928

29+
local function format_preference(pref, index)
30+
print(string.format("Preference #%d:", index))
31+
32+
local pref_type = df.unit_preference.T_type[pref.type]
33+
local description = ""
34+
if pref_type == "LikeMaterial" then
35+
description = "Likes material: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
36+
elseif pref_type == "LikeFood" then
37+
description = "Likes food: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
38+
elseif pref_type == "LikeItem" then
39+
description = "Likes item type: " .. tostring(pref.item_type)
40+
elseif pref_type == "LikePlant" then
41+
description = "Likes plant: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
42+
elseif pref_type == "HateCreature" then
43+
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.creature_id].creature_id
44+
elseif pref_type == "LikeColor" then
45+
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.color_id].id
46+
elseif pref_type == "LikeShape" then
47+
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.shape_id].id
48+
elseif pref_type == "LikePoeticForm" then
49+
description = "Likes poetic form: " .. dfhack.translation.translateName(df.global.world.poetic_forms.all[pref.poetic_form_id].name, true)
50+
elseif pref_type == "LikeMusicalForm" then
51+
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.musical_form_id].name, true)
52+
elseif pref_type == "LikeDanceForm" then
53+
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.dance_form_id].name, true)
54+
else
55+
description = "Unknown preference type: " .. tostring(pref.type)
56+
end
57+
58+
print(description)
59+
end
60+
21061
-- initialise random number generator
21162
local rng = dfhack.random.new()
21263

@@ -624,12 +475,25 @@ function assign(preferences, unit, reset)
624475
end
625476
end
626477

478+
-- ----------------------------------------------- SHOW PREF UTILITY ------------------------------------------------ --
479+
local function showPreferences(unit)
480+
assert(not unit or type(unit) == "number" or df.unit:is_instance(unit))
481+
unit = unit or dfhack.gui.getSelectedUnit(true)
482+
if not unit then
483+
qerror("No unit found.")
484+
end
485+
486+
for i, pref in ipairs(unit.status.current_soul.preferences) do
487+
format_preference(pref, i)
488+
end
489+
end
490+
627491
-- ------------------------------------------------------ MAIN ------------------------------------------------------ --
628492
local function main(...)
629493
local args = utils.processArgs({ ... }, valid_args)
630494

631495
if args.help then
632-
print(help)
496+
print(dfhack.script_help())
633497
return
634498
end
635499

@@ -646,9 +510,15 @@ local function main(...)
646510
reset = true
647511
end
648512

513+
if args.show then
514+
showPreferences(unit)
515+
return
516+
end
517+
649518
-- parse preferences
650519
args.unit = nil -- remove from args table
651520
args.reset = nil -- remove from args table
521+
args.show = nil -- remove from args table
652522
local preferences = {}
653523
utils.assign(preferences, args)
654524

changelog.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ Template for new versions:
3333
## New Features
3434

3535
## Fixes
36-
- `deathcause`: fix error when retrieving the name of a historical figure
3736

3837
## Misc Improvements
38+
- `assign-preferences`: new ``--show`` option to display the preferences of the selected unit
39+
- `pref-adjust`: new ``show`` command to display the preferences of the selected unit
40+
- `hide-tutorials`: if enabled, also hide tutorial popups for adventure mode
41+
- `hide-tutorials`: new ``reset`` command that will re-enable popups in the current game
3942

4043
## Removed
4144

45+
# 51.02-r1
46+
47+
## Fixes
48+
- `deathcause`: fix error when retrieving the name of a historical figure
49+
4250
# 50.15-r2
4351

4452
## New Tools

docs/assign-preferences.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ assign-preferences
22
==================
33

44
.. dfhack-tool::
5-
:summary: Adjust a unit's preferences.
5+
:summary: View or adjust a unit's preferences.
66
:tags: fort armok units
77

88
You will need to know the token of the object you want your dwarf to like.
@@ -71,6 +71,8 @@ brackets can be omitted.
7171
``--unit <id>``
7272
The target unit ID. If not present, the currently selected unit will be the
7373
target.
74+
``--show``
75+
Print the list of current likes/dislikes for the selected unit
7476
``--likematerial [ <token> [<token> ...] ]``
7577
This is usually set to three tokens: a type of stone, a type of metal, and a
7678
type of gem. It can also be a type of wood, glass, leather, horn, pearl,

docs/hide-tutorials.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ hide-tutorials
33

44
.. dfhack-tool::
55
:summary: Hide new fort tutorial popups.
6-
:tags: fort interface
6+
:tags: adventure fort interface
77

88
If you've played the game before and don't need to see the tutorial popups that
99
show up on every new fort, ``hide-tutorials`` can hide them for you. You can
1010
enable this tool as a system service in the "Services" tab of
11-
`gui/control-panel` so it takes effect for all new or loaded forts.
11+
`gui/control-panel` so it takes effect for all forts and adventures.
1212

1313
Specifically, this tool hides:
1414

1515
- The popup displayed when creating a new world
1616
- The "Do you want to start a tutorial embark" popup
1717
- Popups displayed the first time you open the labor, burrows, justice, and
1818
other similar screens in a new fort
19+
- Popups displayed when you perform certain actions for the first time in an
20+
adventure
1921

2022
Note that only unsolicited tutorial popups are hidden. If you directly request
2123
a tutorial page from the help, then it will still function normally.
@@ -27,6 +29,10 @@ Usage
2729

2830
enable hide-tutorials
2931
hide-tutorials
32+
hide-tutorials reset
3033

31-
If you haven't enabled the tool, but you run the command while a fort is
32-
loaded, all future popups for the loaded fort will be hidden.
34+
If you haven't enabled the tool, but you run the command while a fort or
35+
adventure is loaded, all future popups for the loaded game will be hidden.
36+
37+
If you run the command with the ``reset`` option, all popups will be re-enabled
38+
as if they had never been seen or dismissed.

docs/pref-adjust.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pref-adjust
22
===========
33

44
.. dfhack-tool::
5-
:summary: Set the preferences of a dwarf to an ideal.
5+
:summary: See the preferences of a dwarf or set them to a designated profile.
66
:tags: fort armok units
77

88
This tool replaces a dwarf's preferences with an "ideal" set which is easy to
@@ -16,19 +16,21 @@ satisfy::
1616
Usage
1717
-----
1818

19+
``pref-adjust list``
20+
List all types of preferences. No changes will be made to any units.
21+
``pref-adjust show``
22+
Show the preferences of the selected unit.
1923
``pref-adjust all|goth_all|clear_all``
20-
Changes/clears preferences for all dwarves.
24+
Changes/clears preferences for all citizens.
2125
``pref-adjust one|goth|clear``
2226
Changes/clears preferences for the currently selected dwarf.
23-
``pref-adjust list``
24-
List all types of preferences. No changes will be made to any dwarves.
2527

2628

2729
Examples
2830
--------
2931

3032
``pref-adjust all``
31-
Change preferences for all dwarves to an ideal.
33+
Change preferences for all citizens to an ideal.
3234

3335
Goth mode
3436
---------

gui/manipulator.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ function Spreadsheet:init()
653653
data_fn=curry(toggle_sorted_vec_data, wd.assigned_units),
654654
toggle_fn=function(unit_id, prev_val)
655655
toggle_sorted_vec(wd.assigned_units, unit_id, prev_val)
656-
-- TODO: poke DF to actually apply the work details to units
656+
local unit = df.unit.find(unit_id)
657+
if unit then dfhack.units.setAutomaticProfessions(unit) end
657658
end,
658659
}
659660
}

0 commit comments

Comments
 (0)