How to rename a Dwarf

dwarf-fortress

I can add, change and remove the nick names of my Dwarves (or any other playable and currently played race) easily; that's one of the functions of the unit screen. This visually replaces the first name of the Dwarf in this list and a few other places, but their actual first name stays and is being used in places like combat reports and so on.

I'd like to be able to rename the Dwarf in question instead, both first and last name (the last name so that I can have children inherit the last names of their parents, as strange as it may sound to a real Dwarf). I couldn't find anything in the game itself and the most commonly used DF admin tool – Dwarf Therapist – only allows changing in the nick name.

Is there a way to do it? Ideally in-game, but using external programs is fine too, especially if I don't have to shut down the game to do so.

Best Answer

It looks like it can be possible with DFusion (which is a part of newer DFHack releases), though nobody - as far as I could find - created such a program so far.

Technical details

Specifically, the "units" (Dwarves, but also any other "living" entity on the map) have the following fields:

  • name.first_name - First name; std::string (max length 27 characters in the memory dump, but likely more than 16 will produce errors), can be freely changed. This is the one used for "v" unit info, the unit screen and a few other places.
  • name.nickname - Nick name; std::string, same as above.
  • name.language - Language of the family name and other (heroic) additional names; index into the df.global.world.raws.language.translations table
  • name.words[7] - Word parts for the family name and heroic additional names; 32-bit integer values, indices into the df.global.world.raws.language.translations[languagename].words array. If -1, this part is missing. According to Dwarf Therapist source code:
    • Index 0 + 1 is used for the original family name (2 parts, stuck together).
    • Index 2 + 5 is used for the heroic surname (again 2 parts).
    • Index 6 is used for the additional heroic surname (1 part only).
    • Indices 3 and 4 are unused.
  • hist_figure_id - Index into the df.global.world.history.figures array, which includes the full name record duplicated - all the above fields. This is used for the detail view of the Dwarf (v-target the Dwarf-z or u-pick the Dwarf from the list-v displays).

There's also a hist_figure_id2 field, but I'm not sure what it is for; possibly to store the ID of vampire as opposed to their cover identity.

One important caveat of it all is: Surnames can only be constructed out of existing words in a language. On the other hand, they don't have to be constructed of the language of the character's race.

Example

As an example on how to use it, assume you want to set some Dwarves nicknames, then transfer them all(!) to their first names. Start up Dwarf Fortress with DFHack enabled, load your game and add nicknames as you wish. Then change to the DFHack command line window and type ...

lua

... to start DFusion-extended lua interpreter. In there, copy & paste the following small program:

figs=df.global.world.history.figures
units=df.global.world.units.active
for _,v in ipairs(units) do
  if v.race == df.global.ui.race_id and v.name.nickname and v.name.nickname ~= "" then
    v.name.first_name = v.name.nickname
    for _2,f in ipairs(figs) do
      if v.hist_figure_id  == f.id then
        f.name.first_name = v.name.nickname
      end
    end
    v.name.nickname = ""
  end
end

... and done.

enter image description here