Skip to content

Commit d4a10bd

Browse files
authored
Merge pull request #1375 from TolMera/pref-adjust/createNewFunctionGetPreferences
Feat: Add "show" to pref-adjust
2 parents 34012d6 + 1af1663 commit d4a10bd

File tree

3 files changed

+59
-17
lines changed

3 files changed

+59
-17
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Template for new versions:
3333
## Fixes
3434

3535
## Misc Improvements
36+
- `pref-assign`: updated to allow users to run `pref-assign show` to get a list of units current preferences
3637

3738
## Removed
3839

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
---------

pref-adjust.lua

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pss_counter = pss_counter or 31415926
66

77
-- ---------------------------------------------------------------------------
88
function insert_preference(unit, preftype, val1)
9-
109
if preftype == df.unit_preference.T_type.LikeMaterial then
1110
utils.insert_or_update(unit.status.current_soul.preferences, {
1211
new = true,
@@ -269,6 +268,51 @@ function build_all_lists(printflag)
269268
end
270269
end -- end func build_all_lists
271270
-- ---------------------------------------------------------------------------
271+
function get_preferences(unit)
272+
if not unit then
273+
print("No unit selected!")
274+
return
275+
end
276+
277+
local preferences = unit.status.current_soul.preferences
278+
if #preferences == 0 then
279+
print("Unit " .. unit_name_to_console(unit) .. " has no preferences.")
280+
return
281+
end
282+
283+
print("Preferences for " .. unit_name_to_console(unit) .. ":")
284+
for _, pref in ipairs(preferences) do
285+
local pref_type = df.unit_preference.T_type[pref.type]
286+
local description = ""
287+
288+
if pref_type == "LikeMaterial" then
289+
description = "Likes material: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
290+
elseif pref_type == "LikeFood" then
291+
description = "Likes food: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
292+
elseif pref_type == "LikeItem" then
293+
description = "Likes item type: " .. tostring(pref.item_type)
294+
elseif pref_type == "LikePlant" then
295+
description = "Likes plant: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
296+
elseif pref_type == "HateCreature" then
297+
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.creature_id].creature_id
298+
elseif pref_type == "LikeColor" then
299+
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.color_id].id
300+
elseif pref_type == "LikeShape" then
301+
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.shape_id].id
302+
elseif pref_type == "LikePoeticForm" then
303+
description = "Likes poetic form: " .. dfhack.translation.translateName(df.global.world.poetic_forms.all[pref.poetic_form_id].name, true)
304+
elseif pref_type == "LikeMusicalForm" then
305+
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.musical_form_id].name, true)
306+
elseif pref_type == "LikeDanceForm" then
307+
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.dance_form_id].name, true)
308+
else
309+
description = "Unknown preference type: " .. tostring(pref.type)
310+
end
311+
312+
print(description)
313+
end
314+
end -- end function: get_preferences
315+
-- ---------------------------------------------------------------------------
272316
function unit_name_to_console(unit)
273317
return dfhack.df2console(dfhack.units.getReadableName(unit))
274318
end
@@ -282,7 +326,7 @@ build_all_lists(false)
282326
local opt = ({...})[1]
283327

284328
function handle_one(profile)
285-
local unit = dfhack.gui.getSelectedUnit()
329+
local unit = dfhack.gui.getSelectedUnit(true)
286330
if unit == nil then
287331
print ("No unit available! Aborting with extreme prejudice.")
288332
return
@@ -299,7 +343,7 @@ end
299343
if opt == "list" then
300344
build_all_lists(true)
301345
elseif opt == "clear" then
302-
local unit = dfhack.gui.getSelectedUnit()
346+
local unit = dfhack.gui.getSelectedUnit(true)
303347
if unit==nil then
304348
print ("No unit available! Aborting with extreme prejudice.")
305349
return
@@ -317,16 +361,11 @@ elseif opt == "all" then
317361
handle_all("IDEAL")
318362
elseif opt == "goth_all" then
319363
handle_all("GOTH")
364+
elseif opt == "show" then
365+
local unit = dfhack.gui.getSelectedUnit(true)
366+
get_preferences(unit)
320367
else
321-
print ("Sets preferences of one dwarf, or of all dwarves, using profiles.")
322-
print ("Valid options:")
323-
print ("list -- show available preference type lists")
324-
print ("clear -- clear preferences of selected unit")
325-
print ("clear_all -- clear preferences of all units")
326-
print ("goth -- alter current dwarf preferences to Goth")
327-
print ("goth_all -- alter all dwarf preferences to Goth")
328-
print ("one -- alter current dwarf preferences to Ideal")
329-
print ("all -- alter all dwarf preferences to Ideal")
368+
print(dfhack.script_help())
330369
if opt and opt ~= "help" then
331370
qerror("Unrecognized option: " .. opt)
332371
end

0 commit comments

Comments
 (0)