@@ -6,7 +6,6 @@ pss_counter = pss_counter or 31415926
66
77-- ---------------------------------------------------------------------------
88function 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
270269end -- 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+ -- ---------------------------------------------------------------------------
272316function unit_name_to_console (unit )
273317 return dfhack .df2console (dfhack .units .getReadableName (unit ))
274318end
@@ -282,7 +326,7 @@ build_all_lists(false)
282326local opt = ({... })[1 ]
283327
284328function 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
299343if opt == " list" then
300344 build_all_lists (true )
301345elseif 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" )
318362elseif opt == " goth_all" then
319363 handle_all (" GOTH" )
364+ elseif opt == " show" then
365+ local unit = dfhack .gui .getSelectedUnit (true )
366+ get_preferences (unit )
320367else
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