From df41612c437185e5f256f5345fe7205a5125149c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 12 Jan 2025 03:47:43 -0800 Subject: [PATCH] use new translation module and fix a number of encoding bugs along the way --- armoks-blessing.lua | 2 +- brainwash.lua | 2 +- caravan.lua | 15 ++------ deathcause.lua | 20 +++++----- devel/kill-hf.lua | 28 +------------- devel/unit-path.lua | 2 +- diplomacy.lua | 8 ++-- do-job-now.lua | 19 ++-------- elevate-mental.lua | 14 +------ elevate-physical.lua | 12 +----- embark-anyone.lua | 2 +- emigration.lua | 2 +- exportlegends.lua | 28 +++++++------- fix/corrupt-equipment.lua | 2 +- fix/loyaltycascade.lua | 4 +- fix/stuck-merchants.lua | 29 ++------------ fix/stuck-worship.lua | 6 +-- fixnaked.lua | 2 +- gaydar.lua | 2 +- gui/advfort.lua | 2 +- gui/companion-order.lua | 2 +- gui/family-affairs.lua | 3 +- gui/gm-editor.lua | 2 +- gui/masspit.lua | 20 ++++++---- gui/rename.lua | 13 ++++--- gui/room-list.lua | 2 +- gui/sitemap.lua | 6 +-- gui/unit-info-viewer.lua | 2 +- gui/workshop-job.lua | 2 +- internal/advtools/convo.lua | 4 +- internal/confirm/specs.lua | 2 +- internal/exportlegends/racefilter.lua | 2 +- internal/gm-unit/editor_civilization.lua | 2 +- linger.lua | 6 +-- list-agreements.lua | 4 +- make-legendary.lua | 2 +- markdown.lua | 2 +- modtools/extra-gamelog.lua | 6 +-- modtools/set-belief.lua | 2 +- modtools/set-need.lua | 2 +- modtools/set-personality.lua | 2 +- necronomicon.lua | 4 +- pref-adjust.lua | 8 ++-- prefchange.lua | 48 ++++++++++++------------ set-orientation.lua | 2 +- superdwarf.lua | 7 +--- troubleshoot-item.lua | 12 +----- uniform-unstick.lua | 2 +- unretire-anyone.lua | 4 +- warn-stranded.lua | 2 +- 50 files changed, 135 insertions(+), 243 deletions(-) diff --git a/armoks-blessing.lua b/armoks-blessing.lua index 9a64c5bc96..e34cc9992e 100644 --- a/armoks-blessing.lua +++ b/armoks-blessing.lua @@ -233,7 +233,7 @@ end -- --------------------------------------------------------------------------- function adjust_all_dwarves(skillname) for _,v in ipairs(dfhack.units.getCitizens()) do - print("Adjusting "..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(v)))) + print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(v))) brainwash_unit(v) elevate_attributes(v) rejuvenate.rejuvenate(v, true) diff --git a/brainwash.lua b/brainwash.lua index 12776de283..1cbdc29355 100644 --- a/brainwash.lua +++ b/brainwash.lua @@ -27,7 +27,7 @@ function brainwash_unit(profile) return end - unit_name=dfhack.TranslateName(dfhack.units.getVisibleName(unit)) + unit_name = dfhack.df2console(dfhack.units.getReadableName(unit)) print("Previous personality values for "..unit_name) printall(unit.status.current_soul.personality.traits) diff --git a/caravan.lua b/caravan.lua index 2d3a0cfb79..0dd2cf6d89 100644 --- a/caravan.lua +++ b/caravan.lua @@ -62,7 +62,7 @@ function commands.list() print(dfhack.df2console(('%d: %s caravan from %s'):format( id, df.creature_raw.find(df.historical_entity.find(car.entity).race).name[2], -- adjective - dfhack.TranslateName(df.historical_entity.find(car.entity).name) + dfhack.translation.translateName(df.historical_entity.find(car.entity).name) ))) print(' ' .. (df.caravan_state.T_trade_state[car.trade_state] or ('Unknown state: ' .. car.trade_state))) print((' %d day(s) remaining'):format(math.floor(car.time_remaining / 120))) @@ -126,15 +126,6 @@ local function isDisconnectedPackAnimal(unit) end end -local function getPrintableUnitName(unit) - local visible_name = dfhack.units.getVisibleName(unit) - local profession_name = dfhack.units.getProfessionName(unit) - if visible_name.has_name then - return ('%s (%s)'):format(dfhack.TranslateName(visible_name), profession_name) - end - return profession_name -- for unnamed animals -end - local function rejoin_pack_animals() print('Reconnecting disconnected pack animals...') local found = false @@ -142,8 +133,8 @@ local function rejoin_pack_animals() if unit.flags1.merchant and isDisconnectedPackAnimal(unit) then local dragger = unit.following print((' %s <-> %s'):format( - dfhack.df2console(getPrintableUnitName(unit)), - dfhack.df2console(getPrintableUnitName(dragger)) + dfhack.df2console(dfhack.units.getReadableName(unit)), + dfhack.df2console(dfhack.units.getReadableName(dragger)) )) unit.relationship_ids[ df.unit_relationship_type.Dragger ] = dragger.id dragger.relationship_ids[ df.unit_relationship_type.Draggee ] = unit.id diff --git a/deathcause.lua b/deathcause.lua index 9b0d4fad61..16e05d5f5a 100644 --- a/deathcause.lua +++ b/deathcause.lua @@ -25,13 +25,11 @@ function getDeathStringFromCause(cause) end function displayDeathUnit(unit) - local str = ("The %s"):format(getRaceNameSingular(unit.race)) - if unit.name.has_name then - str = str .. (" %s"):format(dfhack.TranslateName(unit.name)) - end + local str = unit.name.has_name and '' or 'The ' + str = str .. dfhack.units.getReadableName(unit) if not dfhack.units.isDead(unit) then - print(str .. " is not dead yet!") + print(dfhack.df2console(str) .. " is not dead yet!") return end @@ -46,13 +44,13 @@ function displayDeathUnit(unit) if killer then str = str .. (", killed by the %s"):format(getRaceNameSingular(killer.race)) if killer.name.has_name then - str = str .. (" %s"):format(dfhack.TranslateName(killer.name)) + str = str .. (" %s"):format(dfhack.translation.translateName(dfhack.units.getVisibleName(killer))) end end end end - print(str .. '.') + print(dfhack.df2console(str) .. '.') end -- returns the item description if the item still exists; otherwise @@ -68,7 +66,7 @@ end function displayDeathEventHistFigUnit(histfig_unit, event) local str = ("The %s %s %s in year %d"):format( getRaceNameSingular(histfig_unit.race), - dfhack.TranslateName(histfig_unit.name), + dfhack.translation.translateName(dfhack.units.getVisibleName(histfig_unit)), getDeathStringFromCause(event.death_cause), event.year ) @@ -77,7 +75,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event) if slayer_histfig then str = str .. (", killed by the %s %s"):format( getRaceNameSingular(slayer_histfig.race), - dfhack.TranslateName(slayer_histfig.name) + dfhack.translation.translateName(dfhack.units.getVisiblename(slayer_histfig)) ) end @@ -89,7 +87,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event) end end - print(str .. '.') + print(dfhack.df2console(str) .. '.') end -- Returns the death event for the given histfig or nil if not found @@ -111,7 +109,7 @@ function displayDeathHistFig(histfig) end if not dfhack.units.isDead(histfig_unit) then - print(("%s is not dead yet!"):format(dfhack.TranslateName(histfig_unit.name))) + print(("%s is not dead yet!"):format(dfhack.df2console(dfhack.units.getReadableName(histfig_unit)))) else local death_event = getDeathEventForHistFig(histfig.id) displayDeathEventHistFigUnit(histfig_unit, death_event) diff --git a/devel/kill-hf.lua b/devel/kill-hf.lua index e2cf5f7215..63b8083988 100644 --- a/devel/kill-hf.lua +++ b/devel/kill-hf.lua @@ -1,31 +1,5 @@ -- Kills the specified historical figure ---[====[ - -devel/kill-hf -============= - -Kills the specified historical figure, even if off-site, or terminates a -pregnancy. Useful for working around :bug:`11549`. - -Usage:: - - devel/kill-hf [-p|--pregnancy] [-n|--dry-run] HISTFIG_ID - -Arguments: - -``histfig_id``: - the ID of the historical figure to target - -``-p``, ``--pregnancy``: - if specified, and if the historical figure is pregnant, terminate the - pregnancy instead of killing the historical figure - -``-n``, ``--dry-run``: - if specified, only print the name of the historical figure - -]====] - local target_hf = -1 local target_pregnancy = false local dry_run = false @@ -44,7 +18,7 @@ end local hf = df.historical_figure.find(target_hf) or qerror('histfig not found: ' .. target_hf) -local hf_name = dfhack.df2console(dfhack.TranslateName(hf.name)) +local hf_name = dfhack.df2console(dfhack.translation.translateName(hf.name)) local hf_desc = ('%i: %s (%s)'):format(target_hf, hf_name, dfhack.units.getRaceNameById(hf.race)) if dry_run then diff --git a/devel/unit-path.lua b/devel/unit-path.lua index 459ff92159..6f5e34d58e 100644 --- a/devel/unit-path.lua +++ b/devel/unit-path.lua @@ -127,7 +127,7 @@ function UnitPathUI:onRenderBody(dc) dc:seek(2,3):pen(COLOR_BLUE):string(prof) if name and name.has_name then - dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.TranslateName(name)) + dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.translation.translateName(name)) end local cursor = guidm.getCursorPos() diff --git a/diplomacy.lua b/diplomacy.lua index 7baee75ab6..7b44efa4cf 100644 --- a/diplomacy.lua +++ b/diplomacy.lua @@ -25,10 +25,10 @@ function get_civ_list() end end table.insert(civ_list, { - cur_civ_id, - rel_str, - matched, - dfhack.TranslateName(cur_civ.name, true) + cur_civ_id, + rel_str, + matched, + dfhack.translation.translateName(cur_civ.name, true) }) end end diff --git a/do-job-now.lua b/do-job-now.lua index 4e83970c8f..3ef9585a9b 100644 --- a/do-job-now.lua +++ b/do-job-now.lua @@ -6,16 +6,6 @@ local function print_help() print(dfhack.script_help()) end -local function getUnitName(unit) - local language_name = dfhack.units.getVisibleName(unit) - if language_name.has_name then - return dfhack.df2console(dfhack.TranslateName( language_name )) - end - - -- animals - return dfhack.units.getProfessionName(unit) -end - local function doJobNow(job) local job_str = dfhack.job.getName(job) if not job.flags.do_now then @@ -30,7 +20,7 @@ local function doJobNow(job) end local unit = dfhack.job.getWorker(job) if unit then - print("... by " .. getUnitName(unit) ) + print("... by " .. dfhack.df2console(dfhack.units.getReadableName(unit))) end end @@ -64,7 +54,6 @@ end local function doUnitJobNow(unit) if dfhack.units.isCitizen(unit) then - --print('This will attempt to make a job of ' .. getUnitName(unit) .. ' a top priority') local t_job = unit.job if t_job then local job = t_job.current_job @@ -73,10 +62,8 @@ local function doUnitJobNow(unit) return end end - print("Couldn't find any job for " .. getUnitName(unit) ) + print("Couldn't find any job for " .. dfhack.df2console(dfhack.units.getReadableName(unit))) else - --print('This will attempt to make a job with ' .. getUnitName(unit) .. ' a top priority') - local needle = unit.id for _link, job in utils.listpairs(df.global.world.jobs.list) do if #job.general_refs > 0 then @@ -92,7 +79,7 @@ local function doUnitJobNow(unit) end end - print("Couldn't find any job involving " .. getUnitName(unit) ) + print("Couldn't find any job involving " .. dfhack.df2console(dfhack.units.getReadableName(unit))) end end diff --git a/elevate-mental.lua b/elevate-mental.lua index c484a22635..cd067a60eb 100644 --- a/elevate-mental.lua +++ b/elevate-mental.lua @@ -1,14 +1,4 @@ -- Elevate all the mental attributes of a unit --- by vjek -local help = [====[ - -elevate-mental -============== -Set all mental attributes of the selected dwarf to the maximum possible, or -any number numbers between 0 and 5000 passed as an argument: -``elevate-mental 100`` for example would make the dwarf very stupid indeed. - -]====] function ElevateMentalAttributes(value) local unit=dfhack.gui.getSelectedUnit() @@ -17,7 +7,7 @@ function ElevateMentalAttributes(value) return end --print name of dwarf - print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit))) --walk through available attributes, adjust current to max if unit.status.current_soul then for k,v in pairs(unit.status.current_soul.mental_attrs) do @@ -42,7 +32,7 @@ if opt ~= nil then ElevateMentalAttributes(opt) end if opt <0 or opt >5000 then - print(help) + print(dfhack.script_help()) print('\n\nInvalid number!') end end diff --git a/elevate-physical.lua b/elevate-physical.lua index bf8e97c458..6a6aeffdb4 100644 --- a/elevate-physical.lua +++ b/elevate-physical.lua @@ -1,14 +1,4 @@ -- Elevate all the physical attributes of a unit --- by vjek ---[====[ - -elevate-physical -================ -Set all physical attributes of the selected dwarf to the maximum possible, or -any number numbers between 0 and 5000 passed as an argument. Higher is -usually better, but an ineffective hammerer can be useful too... - -]====] function ElevatePhysicalAttributes(value) local unit=dfhack.gui.getSelectedUnit() @@ -17,7 +7,7 @@ function ElevatePhysicalAttributes(value) return end --print name of dwarf - print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit))) --walk through available attributes, adjust current to max if unit.body then for k,v in pairs(unit.body.physical_attrs) do diff --git a/embark-anyone.lua b/embark-anyone.lua index 0f6fc61ad2..10772e46e1 100644 --- a/embark-anyone.lua +++ b/embark-anyone.lua @@ -68,7 +68,7 @@ function embarkAnyone() -- Find the civ's name, or come up with one if civ.name.has_name then - label = dfhack.TranslateName(civ.name, true) .. "\n" + label = dfhack.translation.translateName(civ.name, true) .. "\n" else label = "Unnamed " .. dfhack.units.getRaceReadableNameById(civ.race) .. diff --git a/emigration.lua b/emigration.lua index 1d1dea305e..ea494a7e36 100644 --- a/emigration.lua +++ b/emigration.lua @@ -34,7 +34,7 @@ end function desert(u,method,civ) u.following = nil - local line = dfhack.TranslateName(dfhack.units.getVisibleName(u)) .. " has " + local line = dfhack.units.getReadableName(u) .. " has " if method == 'merchant' then line = line.."joined the merchants" u.flags1.merchant = true diff --git a/exportlegends.lua b/exportlegends.lua index db5e12ffb1..e4c5eedea4 100644 --- a/exportlegends.lua +++ b/exportlegends.lua @@ -136,8 +136,8 @@ local function export_more_legends_xml() file:write("\n") file:write("\n") - file:write(""..escape_xml(dfhack.df2utf(dfhack.TranslateName(world.world_data.name))).."\n") - file:write(""..escape_xml(dfhack.df2utf(dfhack.TranslateName(world.world_data.name,1))).."\n") + file:write(""..escape_xml(dfhack.df2utf(dfhack.translation.translateName(world.world_data.name))).."\n") + file:write(""..escape_xml(dfhack.df2utf(dfhack.translation.translateName(world.world_data.name,1))).."\n") local chunks = {} @@ -145,7 +145,7 @@ local function export_more_legends_xml() for landmassK, landmassV in progress_ipairs(vector, 'landmasses') do file:write("\t\n") file:write("\t\t"..landmassV.index.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(landmassV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(landmassV.name,1))).."\n") file:write("\t\t"..landmassV.min_x..","..landmassV.min_y.."\n") file:write("\t\t"..landmassV.max_x..","..landmassV.max_y.."\n") file:write("\t\n") @@ -156,7 +156,7 @@ local function export_more_legends_xml() for mountainK, mountainV in progress_ipairs(vector, 'mountains') do file:write("\t\n") file:write("\t\t"..mountainK.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(mountainV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(mountainV.name,1))).."\n") file:write("\t\t"..mountainV.pos.x..","..mountainV.pos.y.."\n") file:write("\t\t"..mountainV.height.."\n") if mountainV.flags.is_volcano then @@ -205,7 +205,7 @@ local function export_more_legends_xml() table.insert(chunks, make_chunk('rivers', world.world_data.rivers, function(vector) for riverK, riverV in progress_ipairs(vector, 'rivers') do file:write("\t\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(riverV.name, 1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(riverV.name, 1))).."\n") file:write("\t\t") for pathK, pathV in progress_ipairs(riverV.path.x, 'river section', true) do file:write(pathV..","..riverV.path.y[pathK]..",") @@ -249,8 +249,8 @@ local function export_more_legends_xml() file:write("\t\t\t\t"..buildingV.id.."\n") file:write("\t\t\t\t"..df_enums.abstract_building_type[buildingV:getType()]:lower().."\n") if table_containskey(buildingV,"name") then - file:write("\t\t\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(buildingV.name, 1))).."\n") - file:write("\t\t\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(buildingV.name))).."\n") + file:write("\t\t\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(buildingV.name, 1))).."\n") + file:write("\t\t\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(buildingV.name))).."\n") end if df.abstract_building_templest:is_instance(buildingV) then file:write("\t\t\t\t"..buildingV.deity_type.."\n") @@ -280,7 +280,7 @@ local function export_more_legends_xml() for wcK, wcV in progress_ipairs(vector, 'constructions') do file:write("\t\n") file:write("\t\t"..wcV.id.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(wcV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(wcV.name,1))).."\n") file:write("\t\t"..(df_enums.world_construction_type[wcV:getType()]):lower().."\n") file:write("\t\t") for xK, xVal in ipairs(wcV.square_pos.x) do @@ -338,7 +338,7 @@ local function export_more_legends_xml() for idK, idV in progress_ipairs(vector, 'identities') do file:write("\t\n") file:write("\t\t"..idV.id.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(idV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(idV.name,1))).."\n") local id_tag = df.identity_type.attrs[idV.type].id_tag if id_tag then file:write("\t\t<"..id_tag..">"..idV[id_tag].."\n") @@ -446,7 +446,7 @@ local function export_more_legends_xml() for occasionK, occasionV in pairs(entityV.occasion_info.occasions) do file:write("\t\t\n") file:write("\t\t\t"..occasionV.id.."\n") - file:write("\t\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(occasionV.name,1))).."\n") + file:write("\t\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(occasionV.name,1))).."\n") file:write("\t\t\t"..occasionV.purpose_id.."\n") for scheduleK, scheduleV in pairs(occasionV.schedule) do file:write("\t\t\t\n") @@ -760,7 +760,7 @@ local function export_more_legends_xml() else dfhack.printerr ("Unknown df.identity_type value encountered:"..tostring (identity.type)..". Please report to DFHack team.") end - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(identity.name))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(identity.name))).."\n") local craw = df.creature_raw.find(identity.race) if craw then file:write("\t\t"..(craw.creature_id):lower().."\n") @@ -967,7 +967,7 @@ local function export_more_legends_xml() for formK, formV in progress_ipairs(vector, 'poetic forms') do file:write("\t\n") file:write("\t\t"..formV.id.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(formV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(formV.name,1))).."\n") file:write("\t\n") end end)) @@ -976,7 +976,7 @@ local function export_more_legends_xml() for formK, formV in progress_ipairs(vector, 'musical forms') do file:write("\t\n") file:write("\t\t"..formV.id.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(formV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(formV.name,1))).."\n") file:write("\t\n") end end)) @@ -985,7 +985,7 @@ local function export_more_legends_xml() for formK, formV in progress_ipairs(vector, 'dance forms') do file:write("\t\n") file:write("\t\t"..formV.id.."\n") - file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.TranslateName(formV.name,1))).."\n") + file:write("\t\t"..escape_xml(dfhack.df2utf(dfhack.translation.translateName(formV.name,1))).."\n") file:write("\t\n") end end)) diff --git a/fix/corrupt-equipment.lua b/fix/corrupt-equipment.lua index e509b8d9ec..a11723ee06 100644 --- a/fix/corrupt-equipment.lua +++ b/fix/corrupt-equipment.lua @@ -85,7 +85,7 @@ function fix_equipment () for i, squad in ipairs (df.global.world.squads.all) do if squad.entity_id == df.global.plotinfo.group_id then - local squad_name = dfhack.TranslateName(squad.name, true) + local squad_name = dfhack.translation.translateName(squad.name, true) if squad.alias ~= "" then squad_name = squad.alias end diff --git a/fix/loyaltycascade.lua b/fix/loyaltycascade.lua index b6ae0515ef..768fbdfcf2 100644 --- a/fix/loyaltycascade.lua +++ b/fix/loyaltycascade.lua @@ -51,7 +51,7 @@ local function fixUnit(unit) -- If the unit is a former member of your civilization, as well as now an -- enemy of it, we make it become a member again. if former_civ_index and enemy_civ_index then - local civ_name = dfhack.TranslateName(df.historical_entity.find(df.global.plotinfo.civ_id).name) + local civ_name = dfhack.translation.translateName(df.historical_entity.find(df.global.plotinfo.civ_id).name) convertUnit(unit, df.global.plotinfo.civ_id, former_civ_index, enemy_civ_index) @@ -62,7 +62,7 @@ local function fixUnit(unit) end if former_group_index and enemy_group_index then - local group_name = dfhack.TranslateName(df.historical_entity.find(df.global.plotinfo.group_id).name) + local group_name = dfhack.translation.translateName(df.historical_entity.find(df.global.plotinfo.group_id).name) convertUnit(unit, df.global.plotinfo.group_id, former_group_index, enemy_group_index) diff --git a/fix/stuck-merchants.lua b/fix/stuck-merchants.lua index ceddc205e1..fa9b5b77c0 100644 --- a/fix/stuck-merchants.lua +++ b/fix/stuck-merchants.lua @@ -1,26 +1,7 @@ --- Dismisses stuck merchants that haven't entered the map yet --- Based on "dismissmerchants" by PatrikLundell: --- http://www.bay12forums.com/smf/index.php?topic=159297.msg7257447#msg7257447 - -local help = [====[ - -fix/stuck-merchants -=================== - -Dismisses merchants that haven't entered the map yet. This can fix :bug:`9593`. -This script should probably not be run if any merchants are on the map, so using -it with `repeat` is not recommended. - -Run ``fix/stuck-merchants -n`` or ``fix/stuck-merchants --dry-run`` to list all -merchants that would be dismissed but make no changes. - -]====] - - function getEntityName(u) local civ = df.historical_entity.find(u.civ_id) if not civ then return 'unknown civ' end - return dfhack.TranslateName(civ.name) + return dfhack.translation.translateName(civ.name) end function getEntityRace(u) @@ -38,7 +19,7 @@ function dismissMerchants(args) local dry_run = false for _, arg in pairs(args) do if args[1]:match('-h') or args[1]:match('help') then - print(help) + print(dfhack.script_help()) return elseif args[1]:match('-n') or args[1]:match('dry') then dry_run = true @@ -49,7 +30,7 @@ function dismissMerchants(args) print(('%s unit %d: %s (%s), civ %d (%s, %s)'):format( dry_run and 'Would remove' or 'Removing', u.id, - dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(u))), + dfhack.df2console(dfhack.units.getReadableName(u)), df.creature_raw.find(u.race).name[0], u.civ_id, dfhack.df2console(getEntityName(u)), @@ -62,6 +43,4 @@ function dismissMerchants(args) end end -if not dfhack_flags.module then - dismissMerchants{...} -end +dismissMerchants{...} diff --git a/fix/stuck-worship.lua b/fix/stuck-worship.lua index 2d48809141..d21df82717 100644 --- a/fix/stuck-worship.lua +++ b/fix/stuck-worship.lua @@ -87,10 +87,6 @@ local function get_prayer_targets(unit) end end -local function unit_name(unit) - return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))) -end - local count = 0 for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do local prayer_targets = get_prayer_targets(unit) @@ -101,7 +97,7 @@ for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do if shuffle_prayer_needs(needs, prayer_targets) then count = count + 1 if verbose then - print('Shuffled prayer target for '..unit_name(unit)) + print('Shuffled prayer target for '..dfhack.df2console(dfhack.units.getReadableName(unit))) end end ::next_unit:: diff --git a/fixnaked.lua b/fixnaked.lua index 916d8f5ad3..02dbc794f3 100644 --- a/fixnaked.lua +++ b/fixnaked.lua @@ -29,7 +29,7 @@ for fnUnitCount,fnUnit in ipairs(dfhack.units.getCitizens()) do end if fixed then total_fixed = total_fixed + 1 - print(total_fixed, total_removed, dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit))) + print(total_fixed, total_removed, dfhack.df2console(dfhack.units.getReadableName(fnUnit))) end end end diff --git a/gaydar.lua b/gaydar.lua index 3981fd21e9..5dfb5a1828 100644 --- a/gaydar.lua +++ b/gaydar.lua @@ -77,7 +77,7 @@ end local function nameOrSpeciesAndNumber(unit) if unit.name.has_name then - return dfhack.TranslateName(dfhack.units.getVisibleName(unit))..' '..getSexString(unit.sex),true + return dfhack.translation.translateName(dfhack.units.getVisibleName(unit))..' '..getSexString(unit.sex),true else return 'Unit #'..unit.id..' ('..df.creature_raw.find(unit.race).caste[unit.caste].caste_name[0]..' '..getSexString(unit.sex)..')',false end diff --git a/gui/advfort.lua b/gui/advfort.lua index 7f17afb8fe..125bed7ba8 100644 --- a/gui/advfort.lua +++ b/gui/advfort.lua @@ -1197,7 +1197,7 @@ function usetool:update_site() local site_label=self.subviews.siteLabel --as:wid.Label if site then - site_label:itemById("site").text=dfhack.TranslateName(site.name) + site_label:itemById("site").text=dfhack.translation.translateName(site.name) else if settings.safe then site_label:itemById("site").text="" diff --git a/gui/companion-order.lua b/gui/companion-order.lua index 9659c79785..71bc644c22 100644 --- a/gui/companion-order.lua +++ b/gui/companion-order.lua @@ -494,7 +494,7 @@ function CompanionUi:onRenderBody( dc) else dc:pen(COLOR_GREY) end - dc:newline(1):string(string.char(k+char_a)..". "):string(dfhack.TranslateName(v.name)); + dc:newline(1):string(string.char(k+char_a)..". "):string(dfhack.translation.translateName(v.name)); end dc:pen(COLOR_GREY) local w,h=self:getWindowSize() diff --git a/gui/family-affairs.lua b/gui/family-affairs.lua index c0a64447b5..d67c9c0c0f 100644 --- a/gui/family-affairs.lua +++ b/gui/family-affairs.lua @@ -145,7 +145,8 @@ local function set_spouse(unit1, unit2, accept_fn) add_hf_link(df.histfig_hf_link_spousest, unit1.hist_figure_id, unit2.hist_figure_id) add_hf_link(df.histfig_hf_link_spousest, unit2.hist_figure_id, unit1.hist_figure_id) dfhack.gui.showAutoAnnouncement(df.announcement_type.MARRIAGE, xyz2pos(dfhack.units.getPosition(unit1)), - ('%s and %s have married!'):format(dfhack.TranslateName(unit1.name), dfhack.TranslateName(unit2.name)), + ('%s and %s have married!'):format(dfhack.translation.translateName(unit1.name), + dfhack.translation.translateName(unit2.name)), COLOR_LIGHTMAGENTA) accept_fn() end diff --git a/gui/gm-editor.lua b/gui/gm-editor.lua index 6d37f96c5f..6902875b69 100644 --- a/gui/gm-editor.lua +++ b/gui/gm-editor.lua @@ -636,7 +636,7 @@ function GmEditorUi:getStringValue(trg, field) elseif df.coord2d:is_instance(f) then text=('(%d, %d) %s'):format(f.x, f.y, text) elseif df.language_name:is_instance(f) then - text=('%s (%s) %s'):format(dfhack.TranslateName(f, false), dfhack.TranslateName(f, true), text) + text=('%s (%s) %s'):format(dfhack.translation.translateName(f, false), dfhack.translation.translateName(f, true), text) end end local enum = f._type diff --git a/gui/masspit.lua b/gui/masspit.lua index cc83ee847e..e46712819a 100644 --- a/gui/masspit.lua +++ b/gui/masspit.lua @@ -73,16 +73,16 @@ function Masspit:showStockpiles() for _, zone in pairs(df.global.world.buildings.other.STOCKPILE) do if (#zone.settings.animals.enabled > 0) then if #getCagedUnits(zone) > 0 then - local zone_name = zone.name.length and dfhack.TranslateName(zone.name) or "Animal stockpile #" .. zone.stockpile_number + local zone_name = #zone.name > 0 and zone.name or ("Animal stockpile #" .. zone.stockpile_number) local zone_position = df.coord:new() zone_position.x = zone.centerx zone_position.y = zone.centery zone_position.z = zone.z table.insert(choices, { - text = ([[%s: %s x:%s y:%s]]):format(zone.id, zone_name, zone.centerx, zone.centery), + text = zone_name, zone_position = zone_position, - zone_id = zone.id + zone_id = zone.id, }) end end @@ -97,6 +97,10 @@ function Masspit:showStockpiles() end end +local function getElevation() + return df.global.world.map.region_z + df.global.window_z - 100 +end + function Masspit:showPondPits() self.subviews.pages:setSelected('pits') @@ -104,14 +108,14 @@ function Masspit:showPondPits() for _, zone in pairs(df.global.world.buildings.other.ACTIVITY_ZONE) do if (zone.type == df.civzone_type.Pond) then - local zone_name = zone.name.length and dfhack.TranslateName(zone.name) or "Unnamed pit/pond" + local zone_name = #zone.name > 0 and zone.name or ("Unnamed pit/pond on elevation "..getElevation()) local zone_position = df.coord:new() zone_position.x = zone.centerx zone_position.y = zone.centery zone_position.z = zone.z table.insert(choices, { - text = ([[%s: %s x:%s y:%s]]):format(zone.id, zone_name, zone.centerx, zone.centery), + text = zone_name, zone_position = zone_position, zone_id = zone.id }) @@ -161,7 +165,7 @@ function Masspit:setPit(_, choice) for _, unit_id in pairs(self.caged_units) do local unit = df.unit.find(unit_id) - local unit_name = unit.name.has_name and dfhack.TranslateName(unit.name) or dfhack.units.getRaceNameById(unit.race) + local unit_name = dfhack.units.getReadableName(unit) -- Prevents duplicate units in assignments, which can cause crashes. local duplicate = false @@ -171,7 +175,7 @@ function Masspit:setPit(_, choice) end end - table.insert(choices, { text = ([[%s: %s %s]]):format(unit.id, unit_name, duplicate and "(ALREADY ASSIGNED)" or "") }) + table.insert(choices, { text = ([[%s: %s%s]]):format(unit.id, unit_name, duplicate and " (ALREADY ASSIGNED)" or "") }) if not duplicate then unit.general_refs:insert("#", { new = df.general_ref_building_civzone_assignedst, building_id=self.pit.id }) @@ -220,7 +224,7 @@ function MasspitScreen:onDismiss() view = nil end -if not dfhack.isMapLoaded() then +if not dfhack.world.isFortressMode() or not dfhack.isMapLoaded() then qerror('This script requires a fortress map to be loaded') end diff --git a/gui/rename.lua b/gui/rename.lua index 362ba2f3c4..8f4cfe3c6d 100644 --- a/gui/rename.lua +++ b/gui/rename.lua @@ -65,7 +65,8 @@ local function get_world_target() local sync_targets = { function() df.global.world.cur_savegame.world_header.world_name = - ('%s, "%s"'):format(dfhack.TranslateName(target), dfhack.TranslateName(target, true)) + ('%s, "%s"'):format(dfhack.translation.translateName(target), + dfhack.translation.translateName(target, true)) end } return target, sync_targets @@ -93,7 +94,7 @@ local function select_location(site, cb) local desc, pen = sitemap.get_location_desc(loc) table.insert(choices, { text={ - dfhack.TranslateName(loc.name, true), + dfhack.translation.translateName(loc.name, true), ' (', {text=desc, pen=pen}, ')', @@ -312,11 +313,11 @@ function Rename:init(info) -- }, widgets.Label{ frame={t=2}, - text={{pen=COLOR_YELLOW, text=function() return pad_text(dfhack.TranslateName(self.target), self.frame_body.width) end}}, + text={{pen=COLOR_YELLOW, text=function() return pad_text(dfhack.translation.translateName(self.target), self.frame_body.width) end}}, }, widgets.Label{ frame={t=3}, - text={{pen=COLOR_LIGHTCYAN, text=function() return pad_text(('"%s"'):format(dfhack.TranslateName(self.target, true)), self.frame_body.width) end}}, + text={{pen=COLOR_LIGHTCYAN, text=function() return pad_text(('"%s"'):format(dfhack.translation.translateName(self.target, true)), self.frame_body.width) end}}, }, widgets.CycleHotkeyLabel{ view_id='language', @@ -621,8 +622,8 @@ function Rename:randomize_component_word(comp) end function Rename:generate_random_name() - print('TODO: call dfhack.GenerateName API once it exists') - -- dfhack.GenerateName(self.target) + print('TODO: call dfhack.translation.generateName API once it exists') + -- dfhack.translation.generateName(self.target) -- for _, sync_target in ipairs(self.sync_targets) do -- if type(sync_target) == 'function' then -- sync_target() diff --git a/gui/room-list.lua b/gui/room-list.lua index 00de972a10..4a9a50e93d 100644 --- a/gui/room-list.lua +++ b/gui/room-list.lua @@ -120,7 +120,7 @@ function drawUnitName(dc, unit) local vname = dfhack.units.getVisibleName(unit) if vname and vname.has_name then - dc:string(dfhack.TranslateName(vname)..', ') + dc:string(dfhack.translation.translateName(vname)..', ') end dc:string(dfhack.units.getProfessionName(unit)) else diff --git a/gui/sitemap.lua b/gui/sitemap.lua index ec7ffff7d1..1f779bfc9c 100644 --- a/gui/sitemap.lua +++ b/gui/sitemap.lua @@ -38,7 +38,7 @@ function get_location_desc(loc) local entity = is_deity and df.historical_figure.find(id) or df.historical_entity.find(id) local desc = 'Temple' if not entity then return desc, COLOR_YELLOW end - local name = dfhack.TranslateName(entity.name, true) + local name = dfhack.translation.translateName(entity.name, true) if #name > 0 then desc = ('%s to %s'):format(desc, name) end @@ -50,7 +50,7 @@ end local function get_location_label(loc, zones) local tokens = {} - table.insert(tokens, dfhack.TranslateName(loc.name, true)) + table.insert(tokens, dfhack.translation.translateName(loc.name, true)) local desc, pen = get_location_desc(loc) if desc then table.insert(tokens, ' (') @@ -106,7 +106,7 @@ end local function get_affiliation(unit) local he = df.historical_entity.find(unit.civ_id) if not he then return 'Unknown affiliation' end - local et_name = dfhack.TranslateName(he.name, true) + local et_name = dfhack.translation.translateName(he.name, true) local et_type = df.historical_entity_type[he.type]:gsub('(%l)(%u)', '%1 %2') return ('%s%s %s'):format(#et_name > 0 and et_name or 'Unknown', #et_name > 0 and ',' or '', et_type) end diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index ed677453a9..d6c817e69b 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -180,7 +180,7 @@ local function get_name_chunk(unit) end local function get_translated_name_chunk(unit) - local tname = dfhack.TranslateName(dfhack.units.getVisibleName(unit), true) + local tname = dfhack.translation.translateName(dfhack.units.getVisibleName(unit), true) if #tname == 0 then return '' end return ('"%s"'):format(tname) end diff --git a/gui/workshop-job.lua b/gui/workshop-job.lua index 5c368f8ba8..b071ee1142 100644 --- a/gui/workshop-job.lua +++ b/gui/workshop-job.lua @@ -75,7 +75,7 @@ function JobDetails:init(args) if self.job.flags.suspend then status = { text = 'Suspended', pen = COLOR_RED } elseif worker then - status = { text = dfhack.TranslateName(dfhack.units.getVisibleName(worker)), pen = COLOR_GREEN } + status = { text = dfhack.units.getReadableName(worker), pen = COLOR_GREEN } end self:addviews{ diff --git a/internal/advtools/convo.lua b/internal/advtools/convo.lua index 96ed0f015b..d8b9b06a37 100644 --- a/internal/advtools/convo.lua +++ b/internal/advtools/convo.lua @@ -77,11 +77,11 @@ local function new_choice(choice_type, title, keywords) end local function addWhereaboutsChoice(race, name, target_id, heard_of) - local title = "Ask for the whereabouts of the " .. race .. " " .. dfhack.TranslateName(name, true) + local title = "Ask for the whereabouts of the " .. race .. " " .. dfhack.translation.translateName(name, true) if heard_of then title = title .. " (Heard of)" end - local choice = new_choice(df.talk_choice_type.AskWhereabouts, title, dfhack.TranslateName(name):split()) + local choice = new_choice(df.talk_choice_type.AskWhereabouts, title, dfhack.translation.translateName(name):split()) -- insert before the last choice, which is usually "back" adventure.conversation.conv_choice_info:insert(#adventure.conversation.conv_choice_info-1, choice) choice.choice.invocation_target_hfid = target_id diff --git a/internal/confirm/specs.lua b/internal/confirm/specs.lua index b5e356bf72..3fb9ed13c4 100644 --- a/internal/confirm/specs.lua +++ b/internal/confirm/specs.lua @@ -424,7 +424,7 @@ ConfirmSpec{ selected_pos = scroll_pos + (y - first_portrait_rect.y1) // 3 end local unit = dfhack.gui.getWidget(scroll_rows, selected_pos, 0).u - selected_convict_name = dfhack.TranslateName(dfhack.units.getVisibleName(unit)) + selected_convict_name = dfhack.translation.translateName(dfhack.units.getVisibleName(unit)) if selected_convict_name == '' then selected_convict_name = 'this creature' end diff --git a/internal/exportlegends/racefilter.lua b/internal/exportlegends/racefilter.lua index 52524a9b71..7270396c23 100644 --- a/internal/exportlegends/racefilter.lua +++ b/internal/exportlegends/racefilter.lua @@ -89,7 +89,7 @@ local function do_filter(scr, filter_str, full_refresh) hfid_to_race[hfid] = hf and hf.race or -1 hfid_to_name[hfid] = hf and dfhack.toSearchNormalized( - ('%s %s'):format(dfhack.TranslateName(hf.name, false), dfhack.TranslateName(hf.name, true))) or '' + ('%s %s'):format(dfhack.translation.translateName(hf.name, false), dfhack.translation.translateName(hf.name, true))) or '' end if cur_race >= 0 and hfid_to_race[hfid] ~= cur_race then scr.histfigs_filtered:erase(idx) diff --git a/internal/gm-unit/editor_civilization.lua b/internal/gm-unit/editor_civilization.lua index c062814156..b1c6c0572a 100644 --- a/internal/gm-unit/editor_civilization.lua +++ b/internal/gm-unit/editor_civilization.lua @@ -66,7 +66,7 @@ function civ_name(id,format_name,format_no_name,name_other,name_invalid) return name_invalid or "" end end - local t={NAME=dfhack.TranslateName(civ.name),ENGLISH=dfhack.TranslateName(civ.name,true),ID=civ.id} --TODO race?, maybe something from raws? + local t={NAME=dfhack.translation.translateName(civ.name),ENGLISH=dfhack.translation.translateName(civ.name,true),ID=civ.id} --TODO race?, maybe something from raws? if t.NAME=="" then return string.gsub(format_no_name or " ($ID)", "%$(%w+)", t) end diff --git a/linger.lua b/linger.lua index 2207c48d1c..1e618827fc 100644 --- a/linger.lua +++ b/linger.lua @@ -32,11 +32,7 @@ end if not slayer then qerror("Killer not found!") elseif slayer.flags2.killed then - local slayerName = "" - if slayer.name.has_name then - slayerName = ", " .. dfhack.TranslateName(slayer.name) .. "," - end - qerror("Your slayer" .. slayerName .. " is dead!") + qerror("Your slayer, " .. dfhack.df2console(dfhack.units.getReadableName(slayer)) .. " is dead!") end bodyswap.swapAdvUnit(slayer) diff --git a/list-agreements.lua b/list-agreements.lua index 7666c4c39f..55c53a7860 100644 --- a/list-agreements.lua +++ b/list-agreements.lua @@ -66,7 +66,7 @@ end function get_agr_party_name(agr) --assume party 0 is guild/order, 1 is local government as siteid = playerfortid local party_id = agr.parties[0].entity_ids[0] - local party_name = dfhack.TranslateName(df.global.world.entities.all[party_id].name, true) + local party_name = dfhack.translation.translateName(df.global.world.entities.all[party_id].name, true) if not party_name then party_name = 'An Unknown Entity or Group' end @@ -77,7 +77,7 @@ function get_deity_name(agr) local religion_id = agr.details[0].data.Location.deity_data.Religion local deities = df.global.world.entities.all[religion_id].relations.deities if #deities == 0 then return 'An Unknown Deity' end - return dfhack.TranslateName(df.global.world.history.figures[deities[0]].name,true) + return dfhack.translation.translateName(df.global.world.history.figures[deities[0]].name,true) end --get resolution status, and string diff --git a/make-legendary.lua b/make-legendary.lua index ca1edf9529..2098ad0ba2 100644 --- a/make-legendary.lua +++ b/make-legendary.lua @@ -3,7 +3,7 @@ local utils = require('utils') function getName(unit) - return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + return dfhack.df2console(dfhack.units.getReadableName(unit)) end function legendize(unit, skill_idx) diff --git a/markdown.lua b/markdown.lua index a914e55bb3..61da34c464 100644 --- a/markdown.lua +++ b/markdown.lua @@ -6,7 +6,7 @@ local gui = require('gui') local argparse = require('argparse') -- Get world name for default filename -local worldName = dfhack.df2utf(dfhack.TranslateName(df.global.world.world_data.name)):gsub(" ", "_") +local worldName = dfhack.df2utf(dfhack.translation.translateName(df.global.world.world_data.name)):gsub(" ", "_") local help, overwrite, filenameArg = false, false, nil local positionals = argparse.processArgsGetopt({ ... }, { diff --git a/modtools/extra-gamelog.lua b/modtools/extra-gamelog.lua index 343b5ef34a..8b9538513c 100644 --- a/modtools/extra-gamelog.lua +++ b/modtools/extra-gamelog.lua @@ -35,7 +35,7 @@ function log_on_load(op) local fort_ent = df.global.plotinfo.main.fortress_entity local civ_ent = df.historical_entity.find(df.global.plotinfo.civ_id) local function fullname(item) - return dfhack.TranslateName(item.name)..' ('..dfhack.TranslateName(item.name ,true)..')' + return dfhack.translation.translateName(item.name)..' ('..dfhack.translation.translateName(item.name ,true)..')' end msg('Loaded '..df.global.world.cur_savegame.save_dir..', '..fullname(df.global.world.world_data).. ' at coordinates ('..site.pos.x..','..site.pos.y..')') @@ -71,7 +71,7 @@ function log_nobles() if expedition_leader == nil then msg("Expedition leader position is now vacant.") else - msg(dfhack.TranslateName(dfhack.units.getVisibleName(expedition_leader)).." became expedition leader.") + msg(dfhack.translation.translateName(dfhack.units.getVisibleName(expedition_leader)).." became expedition leader.") end end @@ -79,7 +79,7 @@ function log_nobles() if mayor == nil then msg("Mayor position is now vacant.") else - msg(dfhack.TranslateName(dfhack.units.getVisibleName(mayor)).." became mayor.") + msg(dfhack.translation.translateName(dfhack.units.getVisibleName(mayor)).." became mayor.") end end old_mayor = mayor diff --git a/modtools/set-belief.lua b/modtools/set-belief.lua index b0b3019218..c46b2adafc 100644 --- a/modtools/set-belief.lua +++ b/modtools/set-belief.lua @@ -263,7 +263,7 @@ end -- Print unit's beliefs into the dfhack console. Cultural beliefs are marked with a * function printUnitBeliefs(unit) - print("Beliefs for " .. dfhack.TranslateName(unit.name) .. ":") + print("Beliefs for " .. dfhack.df2console(dfhack.units.getReadableName(unit)) .. ":") for id, name in ipairs(df.value_type) do if name ~= 'NONE' then local strength = getUnitBelief(unit, id) diff --git a/modtools/set-need.lua b/modtools/set-need.lua index 8698d8744b..fd235e28a7 100644 --- a/modtools/set-need.lua +++ b/modtools/set-need.lua @@ -455,7 +455,7 @@ end -- Print unit's needs, levels, and focus into dfhack console function printUnitNeeds(unit) - print("Needs for " .. dfhack.TranslateName(unit.name) .. ":") + print("Needs for " .. dfhack.df2console(dfhack.units.getReadableName(unit)) .. ":") for index, needInstance in ipairs(unit.status.current_soul.personality.needs) do local name = df.need_type[needInstance.id] local level = needInstance.need_level diff --git a/modtools/set-personality.lua b/modtools/set-personality.lua index 29c966e25c..9b1b421a70 100644 --- a/modtools/set-personality.lua +++ b/modtools/set-personality.lua @@ -243,7 +243,7 @@ function randomTraitValue() end function printUnitTraits(unit) - print("Traits of " .. dfhack.TranslateName(unit.name) .. ":") + print("Traits of " .. dfhack.df2console(dfhack.units.getReadableName(unit)) .. ":") for id, name in ipairs(df.personality_facet_type) do if name ~= 'NONE' then local baseValue = getUnitTraitBase(unit, id) diff --git a/necronomicon.lua b/necronomicon.lua index 47d7c374ac..4914b85a60 100644 --- a/necronomicon.lua +++ b/necronomicon.lua @@ -60,7 +60,7 @@ function necronomicon(include_slabs) for _, item in ipairs(df.global.world.items.other.SLAB) do if check_slab_secrets(item) then local artifact = get_item_artifact(item) - local name = dfhack.TranslateName(artifact.name) + local name = dfhack.translation.translateName(artifact.name) print(" " .. dfhack.df2console(name)) end end @@ -87,7 +87,7 @@ function necronomicon_world(include_slabs) print() for _,rec in ipairs(df.global.world.artifacts.all) do if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then - print(dfhack.df2console(dfhack.TranslateName(rec.name))) + print(dfhack.df2console(dfhack.translation.translateName(rec.name))) end end print() diff --git a/pref-adjust.lua b/pref-adjust.lua index a783c97094..067376a008 100644 --- a/pref-adjust.lua +++ b/pref-adjust.lua @@ -236,7 +236,7 @@ function build_all_lists(printflag) list_of_poems_string = "" vec=df.global.world.poetic_forms.all for k=0,#vec-1 do - name=dfhack.TranslateName(vec[k].name,true) + name=dfhack.translation.translateName(vec[k].name,true) list_of_poems[name]=k list_of_poems_string=list_of_poems_string..k..":"..name.."," end @@ -248,7 +248,7 @@ function build_all_lists(printflag) list_of_music_string = "" vec=df.global.world.musical_forms.all for k=0,#vec-1 do - name=dfhack.TranslateName(vec[k].name,true) + name=dfhack.translation.translateName(vec[k].name,true) list_of_music[name]=k list_of_music_string=list_of_music_string..k..":"..name.."," end @@ -260,7 +260,7 @@ function build_all_lists(printflag) list_of_dances_string = "" vec=df.global.world.dance_forms.all for k=0,#vec-1 do - name=dfhack.TranslateName(vec[k].name,true) + name=dfhack.translation.translateName(vec[k].name,true) list_of_dances[name]=k list_of_dances_string=list_of_dances_string..k..":"..name.."," end @@ -270,7 +270,7 @@ function build_all_lists(printflag) end -- end func build_all_lists -- --------------------------------------------------------------------------- function unit_name_to_console(unit) - return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + return dfhack.df2console(dfhack.units.getReadableName(unit)) end diff --git a/prefchange.lua b/prefchange.lua index 826d1670bd..81b3f10915 100644 --- a/prefchange.lua +++ b/prefchange.lua @@ -18,7 +18,7 @@ function axeplate() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- axes and breastplates utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -29,7 +29,7 @@ function axeplate() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -44,7 +44,7 @@ function hammershirt() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- hammers and mail shirts utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 2 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -55,7 +55,7 @@ function hammershirt() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -70,7 +70,7 @@ function swordboot() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- short swords and high boots utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 3 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -81,7 +81,7 @@ function swordboot() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -96,7 +96,7 @@ function spearboot() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- spears and high boots utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 4 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -107,7 +107,7 @@ function spearboot() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -122,7 +122,7 @@ function maceshield() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- maces and shields utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 5 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -133,7 +133,7 @@ function maceshield() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -148,7 +148,7 @@ function xbowhelm() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- crossbows and helms utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 6 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -159,7 +159,7 @@ function xbowhelm() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -174,7 +174,7 @@ function pickglove() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- picks and gauntlets utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 7 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -185,7 +185,7 @@ function pickglove() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -200,7 +200,7 @@ function longglove() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- long swords and gauntlets, skipped bows and whatnot utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 13 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -211,7 +211,7 @@ function longglove() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -226,7 +226,7 @@ function daggerpants() local pss_counter=31415926 local prefcount = #(unit.status.current_soul.preferences) - print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("Before, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") -- daggers and greaves, skipped the weapons which are too large for most dwarves utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = 16 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') @@ -237,7 +237,7 @@ function daggerpants() utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') prefcount = #(unit.status.current_soul.preferences) - print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + print ("After, unit "..dfhack.df2console(dfhack.units.getReadableName(unit)).." has "..prefcount.." preferences") end -- --------------------------------------------------------------------------- @@ -274,16 +274,16 @@ function clear_all(v) end -- --------------------------------------------------------------------------- function printpref_all_dwarves() - for _,v in ipairs(dfhack.units.getCitizens()) do - print("Showing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - print_all(v) + for _,unit in ipairs(dfhack.units.getCitizens()) do + print("Showing Preferences for "..dfhack.df2console(dfhack.units.getReadableName(unit))) + print_all(unit) end end -- --------------------------------------------------------------------------- function clearpref_all_dwarves() - for _,v in ipairs(dfhack.units.getCitizens()) do - print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - clear_all(v) + for _,unit in ipairs(dfhack.units.getCitizens()) do + print("Clearing Preferences for "..dfhack.df2console(dfhack.units.getReadableName(unit))) + clear_all(unit) end end -- --------------------------------------------------------------------------- diff --git a/set-orientation.lua b/set-orientation.lua index 6b821b8fcf..f1b1233cd5 100644 --- a/set-orientation.lua +++ b/set-orientation.lua @@ -214,7 +214,7 @@ function main(...) -- View if args.view then - print("Orientation of " .. dfhack.TranslateName(unit.name) .. ":") + print("Orientation of " .. dfhack.df2console(dfhack.units.getReadableName(unit)) .. ":") print("Male: " .. getInterestString(getInterest(unit, "male"))) print("Female: " .. getInterestString(getInterest(unit, "female"))) return diff --git a/superdwarf.lua b/superdwarf.lua index 16f3cacffb..d3dd754ce0 100644 --- a/superdwarf.lua +++ b/superdwarf.lua @@ -21,12 +21,7 @@ local function getUnit(obj) end local function getName(unit) - local name = dfhack.TranslateName(unit.name) - -- Animals will have a profession name if they aren't named - if name == '' then - name = dfhack.units.getProfessionName(unit) - end - return name + return dfhack.df2console(dfhack.units.getReadableName(unit)) end local function onTimer() diff --git a/troubleshoot-item.lua b/troubleshoot-item.lua index a509407048..db7167b558 100644 --- a/troubleshoot-item.lua +++ b/troubleshoot-item.lua @@ -1,13 +1,4 @@ --- troubleshoot-item.lua --@ module = true ---[====[ - -troubleshoot-item -================= -Print various properties of the selected item. Sometimes useful for -troubleshooting issues such as why dwarves won't pick up a certain item. - -]====] local function coord_to_str(coord) local out = {} @@ -45,8 +36,7 @@ function troubleshoot_item(item, out) if unit_holder.unit_id then local unit = df.unit.find(unit_holder.unit_id) if unit then - local unit_details = string.format("%s - %s", dfhack.TranslateName(dfhack.units.getVisibleName(unit)), dfhack.units.getProfessionName(unit)) - out('Held by unit: ' .. unit_details) + out('Held by unit: ' .. dfhack.units.getReadableName(unit)) else warn('Could not find unit with unit_id: ' .. unit_holder.unit_id) end diff --git a/uniform-unstick.lua b/uniform-unstick.lua index e77663242e..be3a4ad858 100644 --- a/uniform-unstick.lua +++ b/uniform-unstick.lua @@ -106,7 +106,7 @@ end -- Will figure out which items need to be moved to the floor, returns an item_id:item map local function process(unit, args, need_newline) local silent = args.all -- Don't print details if we're iterating through all dwarves - local unit_name = dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + local unit_name = dfhack.df2console(dfhack.units.getReadableName(unit)) if not silent then need_newline = print_line("Processing unit " .. unit_name, need_newline) diff --git a/unretire-anyone.lua b/unretire-anyone.lua index 0e79fccaba..be2a50c1a0 100644 --- a/unretire-anyone.lua +++ b/unretire-anyone.lua @@ -70,8 +70,8 @@ function showNemesisPrompt(advSetUpScreen) end if histFig.name.has_name then name = name .. - '\n' .. dfhack.TranslateName(histFig.name) .. - '\n"' .. dfhack.TranslateName(histFig.name, true) .. '"' + '\n' .. dfhack.translation.translateName(histFig.name) .. + '\n"' .. dfhack.translation.translateName(histFig.name, true) .. '"' else name = name .. '\nUnnamed' diff --git a/warn-stranded.lua b/warn-stranded.lua index 239c4b335d..d916057d05 100644 --- a/warn-stranded.lua +++ b/warn-stranded.lua @@ -132,7 +132,7 @@ end local function getUnitDescription(unit) return ('[%s] %s %s'):format( dfhack.units.getProfessionName(unit), - dfhack.TranslateName(dfhack.units.getVisibleName(unit)), + dfhack.translation.translateName(dfhack.units.getVisibleName(unit)), getSexString(unit.sex)) end