diff --git a/changelog.txt b/changelog.txt index 99313d061e..7e90646dd7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/docs/pref-adjust.rst b/docs/pref-adjust.rst index a6794319eb..4a151cbb96 100644 --- a/docs/pref-adjust.rst +++ b/docs/pref-adjust.rst @@ -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 @@ -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 --------- diff --git a/pref-adjust.lua b/pref-adjust.lua index 067376a008..b06804f6cf 100644 --- a/pref-adjust.lua +++ b/pref-adjust.lua @@ -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, @@ -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 @@ -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 @@ -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 @@ -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