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

Feat: Add "show" to pref-adjust #1375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Template for new versions:
## Fixes

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

## Removed

Expand Down
12 changes: 7 additions & 5 deletions docs/pref-adjust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pref-adjust
===========

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

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

``pref-adjust list``
List all types of preferences. No changes will be made to any units.
``pref-adjust show``
Show the preferences of the selected unit.
``pref-adjust all|goth_all|clear_all``
Changes/clears preferences for all dwarves.
Changes/clears preferences for all citizens.
``pref-adjust one|goth|clear``
Changes/clears preferences for the currently selected dwarf.
``pref-adjust list``
List all types of preferences. No changes will be made to any dwarves.


Examples
--------

``pref-adjust all``
Change preferences for all dwarves to an ideal.
Change preferences for all citizens to an ideal.

Goth mode
---------
Expand Down
63 changes: 51 additions & 12 deletions pref-adjust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pss_counter = pss_counter or 31415926

-- ---------------------------------------------------------------------------
function insert_preference(unit, preftype, val1)

if preftype == df.unit_preference.T_type.LikeMaterial then
utils.insert_or_update(unit.status.current_soul.preferences, {
new = true,
Expand Down Expand Up @@ -269,6 +268,51 @@ function build_all_lists(printflag)
end
end -- end func build_all_lists
-- ---------------------------------------------------------------------------
function get_preferences(unit)
if not unit then
print("No unit selected!")
return
end

local preferences = unit.status.current_soul.preferences
if #preferences == 0 then
print("Unit " .. unit_name_to_console(unit) .. " has no preferences.")
return
end

print("Preferences for " .. unit_name_to_console(unit) .. ":")
for _, pref in ipairs(preferences) do
local pref_type = df.unit_preference.T_type[pref.type]
local description = ""

if pref_type == "LikeMaterial" then
description = "Likes material: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
elseif pref_type == "LikeFood" then
description = "Likes food: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
elseif pref_type == "LikeItem" then
description = "Likes item type: " .. tostring(pref.item_type)
elseif pref_type == "LikePlant" then
description = "Likes plant: " .. dfhack.matinfo.getToken(pref.mattype, pref.matindex)
elseif pref_type == "HateCreature" then
description = "Hates creature: " .. df.global.world.raws.creatures.all[pref.creature_id].creature_id
elseif pref_type == "LikeColor" then
description = "Likes color: " .. df.global.world.raws.descriptors.colors[pref.color_id].id
elseif pref_type == "LikeShape" then
description = "Likes shape: " .. df.global.world.raws.descriptors.shapes[pref.shape_id].id
elseif pref_type == "LikePoeticForm" then
description = "Likes poetic form: " .. dfhack.translation.translateName(df.global.world.poetic_forms.all[pref.poetic_form_id].name, true)
elseif pref_type == "LikeMusicalForm" then
description = "Likes musical form: " .. dfhack.translation.translateName(df.global.world.musical_forms.all[pref.musical_form_id].name, true)
elseif pref_type == "LikeDanceForm" then
description = "Likes dance form: " .. dfhack.translation.translateName(df.global.world.dance_forms.all[pref.dance_form_id].name, true)
else
description = "Unknown preference type: " .. tostring(pref.type)
end

print(description)
end
end -- end function: get_preferences
-- ---------------------------------------------------------------------------
function unit_name_to_console(unit)
return dfhack.df2console(dfhack.units.getReadableName(unit))
end
Expand All @@ -282,7 +326,7 @@ build_all_lists(false)
local opt = ({...})[1]

function handle_one(profile)
local unit = dfhack.gui.getSelectedUnit()
local unit = dfhack.gui.getSelectedUnit(true)
if unit == nil then
print ("No unit available! Aborting with extreme prejudice.")
return
Expand All @@ -299,7 +343,7 @@ end
if opt == "list" then
build_all_lists(true)
elseif opt == "clear" then
local unit = dfhack.gui.getSelectedUnit()
local unit = dfhack.gui.getSelectedUnit(true)
if unit==nil then
print ("No unit available! Aborting with extreme prejudice.")
return
Expand All @@ -317,16 +361,11 @@ elseif opt == "all" then
handle_all("IDEAL")
elseif opt == "goth_all" then
handle_all("GOTH")
elseif opt == "show" then
local unit = dfhack.gui.getSelectedUnit(true)
get_preferences(unit)
else
print ("Sets preferences of one dwarf, or of all dwarves, using profiles.")
print ("Valid options:")
print ("list -- show available preference type lists")
print ("clear -- clear preferences of selected unit")
print ("clear_all -- clear preferences of all units")
print ("goth -- alter current dwarf preferences to Goth")
print ("goth_all -- alter all dwarf preferences to Goth")
print ("one -- alter current dwarf preferences to Ideal")
print ("all -- alter all dwarf preferences to Ideal")
print(dfhack.script_help())
if opt and opt ~= "help" then
qerror("Unrecognized option: " .. opt)
end
Expand Down
Loading