Update Translation::TranslateName to include the first name, plus have it follow the init setting for nickname display (in Dwarf mode)

develop
Quietust 2012-01-27 21:36:01 -06:00
parent 331be2c821
commit 116e5d60be
3 changed files with 56 additions and 20 deletions

@ -38,11 +38,14 @@ using namespace std;
using namespace DFHack; using namespace DFHack;
using namespace DFHack::Simple; using namespace DFHack::Simple;
using namespace df::enums;
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/d_init.h"
using df::global::world; using df::global::world;
using df::global::d_init;
bool Translation::IsValid () bool Translation::IsValid ()
{ {
@ -82,22 +85,53 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
{ {
string out; string out;
if(!inEnglish) string word = name->first_name;
word[0] = toupper(word[0]);
out.append(word);
if (!name->nickname.empty())
{
word = "`" + name->nickname + "'";
switch (d_init ? d_init->nickname_dwarf : d_init_nickname::CENTRALIZE)
{
case d_init_nickname::REPLACE_ALL:
out = word;
return out;
case d_init_nickname::REPLACE_FIRST:
out = "";
break;
case d_init_nickname::CENTRALIZE:
break;
}
if (out.length() > 0)
out.append(" ");
out.append(word);
}
if (!inEnglish)
{ {
if (name->words[0] >= 0 || name->words[1] >= 0) if (name->words[0] >= 0 || name->words[1] >= 0)
{ {
word.clear();
if (name->words[0] >= 0) if (name->words[0] >= 0)
out.append(*world->raws.language.translations[name->language]->words[name->words[0]]); word.append(*world->raws.language.translations[name->language]->words[name->words[0]]);
if (name->words[1] >= 0) if (name->words[1] >= 0)
out.append(*world->raws.language.translations[name->language]->words[name->words[1]]); word.append(*world->raws.language.translations[name->language]->words[name->words[1]]);
out[0] = toupper(out[0]);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
if (name->words[5] >= 0) if (name->words[5] >= 0)
{ {
string word; word.clear();
for (int i = 2; i <= 5; i++) for (int i = 2; i <= 5; i++)
if (name->words[i] >= 0) if (name->words[i] >= 0)
word.append(*world->raws.language.translations[name->language]->words[name->words[i]]); word.append(*world->raws.language.translations[name->language]->words[name->words[i]]);
word[0] = toupper(word[0]); word[0] = toupper(word[0]);
if (out.length() > 0) if (out.length() > 0)
out.append(" "); out.append(" ");
@ -105,7 +139,9 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
} }
if (name->words[6] >= 0) if (name->words[6] >= 0)
{ {
string word = *world->raws.language.translations[name->language]->words[name->words[6]]; word.clear();
word.append(*world->raws.language.translations[name->language]->words[name->words[6]]);
word[0] = toupper(word[0]); word[0] = toupper(word[0]);
if (out.length() > 0) if (out.length() > 0)
@ -117,11 +153,17 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
{ {
if (name->words[0] >= 0 || name->words[1] >= 0) if (name->words[0] >= 0 || name->words[1] >= 0)
{ {
word.clear();
if (name->words[0] >= 0) if (name->words[0] >= 0)
out.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]); word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]);
if (name->words[1] >= 0) if (name->words[1] >= 0)
out.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]); word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]);
out[0] = toupper(out[0]);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
if (name->words[5] >= 0) if (name->words[5] >= 0)
{ {
@ -133,7 +175,7 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
{ {
if (name->words[i] >= 0) if (name->words[i] >= 0)
{ {
string word = world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value]; word = world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value];
word[0] = toupper(word[0]); word[0] = toupper(word[0]);
out.append(" " + word); out.append(" " + word);
} }
@ -146,10 +188,11 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
else else
out.append("Of"); out.append("Of");
string word = world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]; word = world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value];
word[0] = toupper(word[0]); word[0] = toupper(word[0]);
out.append(" " + word); out.append(" " + word);
} }
} }
return out; return out;
} }

@ -184,14 +184,7 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
std::string info; std::string info;
if (owner) if (owner)
{ c->con.print(", owner %s", Translation::TranslateName(&owner->name,false).c_str());
info = owner->name.first_name;
if (!owner->name.nickname.empty())
info += std::string(" '") + owner->name.nickname + "'";
info += " ";
info += Translation::TranslateName(&owner->name,false);
c->con.print(", owner %s", info.c_str());
}
if (!dry_run) if (!dry_run)
{ {

@ -61,7 +61,7 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
c->con.printerr("Dwarf with strange mood does not have a mood type!\n"); c->con.printerr("Dwarf with strange mood does not have a mood type!\n");
continue; continue;
} }
c->con.print("%s %s is currently ", unit->name.first_name.c_str(), Translation::TranslateName(&unit->name, false).c_str()); c->con.print("%s is currently ", Translation::TranslateName(&unit->name, false).c_str());
switch (unit->mood) switch (unit->mood)
{ {
case mood_type::Macabre: case mood_type::Macabre: