Get rid of df_name

develop
Quietust 2012-01-21 13:12:40 -06:00
parent 8052305c2e
commit 7b2835e2a9
7 changed files with 25 additions and 30 deletions

@ -42,17 +42,6 @@ namespace DFHack
uint8_t data[SIZE];
};
struct df_name
{
std::string first_name;
std::string nick_name;
int32_t words[7];
int16_t parts_of_speech[7];
int32_t language;
int16_t unknown;
int16_t has_name;
};
// DF effects, by darius from the bay12 forum
enum EFFECT_TYPE
{

@ -33,6 +33,9 @@ distribution.
#include "Export.h"
#include "Module.h"
#include "Types.h"
#include "DataDefs.h"
#include "df/language_name.h"
namespace DFHack
{
@ -67,10 +70,10 @@ namespace DFHack
// names, used by a few other modules.
bool InitReadNames();
bool readName(t_name & name, df_name * address);
bool copyName(df_name * address, df_name * target);
bool readName(t_name & name, df::language_name * address);
bool copyName(df::language_name * address, df::language_name * target);
// translate a name using the loaded dictionaries
std::string TranslateName(const DFHack::df_name * name, bool inEnglish = true);
std::string TranslateName(const df::language_name * name, bool inEnglish = true);
private:
struct Private;

@ -259,7 +259,7 @@ namespace DFHack
uint32_t GetDwarfRaceIndex ( void );
int32_t GetDwarfCivId ( void );
void CopyNameTo(df::unit *creature, df_name * target);
void CopyNameTo(df::unit *creature, df::language_name * target);
bool RemoveOwnedItemByIdx(const uint32_t index, int32_t id);
bool RemoveOwnedItemByPtr(df::unit * unit, int32_t id);

@ -33,6 +33,8 @@ distribution.
#include "Export.h"
#include "Module.h"
#include "Types.h"
#include "DataDefs.h"
#include "df/language_name.h"
namespace DFHack
{
/**
@ -45,7 +47,7 @@ namespace DFHack
#pragma pack(push, 2)
struct df_plant
{
df_name name;
df::language_name name;
union
{
uint16_t type;

@ -36,6 +36,7 @@ using namespace std;
#include "Types.h"
#include "ModuleFactory.h"
#include "Core.h"
using namespace DFHack;
Module* DFHack::createTranslation()
@ -167,7 +168,7 @@ bool Translation::InitReadNames()
return true;
}
bool Translation::readName(t_name & name, df_name * source)
bool Translation::readName(t_name & name, df::language_name * source)
{
Core & c = Core::getInstance();
Process * p = c.p;
@ -180,7 +181,7 @@ bool Translation::readName(t_name & name, df_name * source)
if(!InitReadNames()) return false;
}
strncpy(name.first_name,source->first_name.c_str(),127);
strncpy(name.nickname,source->nick_name.c_str(),127);
strncpy(name.nickname,source->nickname.c_str(),127);
memcpy(&name.parts_of_speech, &source->parts_of_speech, sizeof (source->parts_of_speech));
memcpy(&name.words, &source->words, sizeof (source->words));
name.language = source->language;
@ -188,7 +189,7 @@ bool Translation::readName(t_name & name, df_name * source)
return true;
}
bool Translation::copyName(df_name * source, df_name * target)
bool Translation::copyName(df::language_name * source, df::language_name * target)
{
if (source == target)
return true;
@ -196,7 +197,7 @@ bool Translation::copyName(df_name * source, df_name * target)
Process * p = c.p;
target->first_name = source->first_name;
target->nick_name = source->nick_name;
target->nickname = source->nickname;
target->has_name = source->has_name;
target->language = source->language;
memcpy(&target->parts_of_speech, &source->parts_of_speech, sizeof (source->parts_of_speech));
@ -205,7 +206,7 @@ bool Translation::copyName(df_name * source, df_name * target)
return true;
}
string Translation::TranslateName(const df_name * name, bool inEnglish)
string Translation::TranslateName(const df::language_name * name, bool inEnglish)
{
string out;
assert (d->Started);
@ -242,8 +243,8 @@ string Translation::TranslateName(const df_name * name, bool inEnglish)
{
if(name->words[0] >=0 || name->words[1] >=0)
{
if(name->words[0]>=0) out.append(d->dicts.translations[name->parts_of_speech[0]+1][name->words[0]]);
if(name->words[1]>=0) out.append(d->dicts.translations[name->parts_of_speech[1]+1][name->words[1]]);
if(name->words[0]>=0) out.append(d->dicts.translations[name->parts_of_speech[0].value+1][name->words[0]]);
if(name->words[1]>=0) out.append(d->dicts.translations[name->parts_of_speech[1].value+1][name->words[1]]);
out[0] = toupper(out[0]);
}
if(name->words[5] >=0)
@ -257,7 +258,7 @@ string Translation::TranslateName(const df_name * name, bool inEnglish)
{
if(name->words[i]>=0)
{
word = d->dicts.translations[name->parts_of_speech[i]+1][name->words[i]];
word = d->dicts.translations[name->parts_of_speech[i].value+1][name->words[i]];
word[0] = toupper(word[0]);
out.append(" " + word);
}
@ -270,7 +271,7 @@ string Translation::TranslateName(const df_name * name, bool inEnglish)
else
out.append("Of");
string word;
word.append(d->dicts.translations[name->parts_of_speech[6]+1][name->words[6]]);
word.append(d->dicts.translations[name->parts_of_speech[6].value+1][name->words[6]]);
word[0] = toupper(word[0]);
out.append(" " + word);
}

@ -157,7 +157,7 @@ void Units::CopyCreature(df::unit * source, t_unit & furball)
//read creature from memory
// name
d->trans->readName(furball.name,(df_name *)&source->name);
d->trans->readName(furball.name, &source->name);
// basic stuff
furball.id = source->id;
@ -183,7 +183,7 @@ void Units::CopyCreature(df::unit * source, t_unit & furball)
// mood stuff
furball.mood = source->mood;
furball.mood_skill = source->job.unk_2f8; // FIXME: really? More like currently used skill anyway.
d->trans->readName(furball.artifact_name, (df_name *)&source->status.artifact_name);
d->trans->readName(furball.artifact_name, &source->status.artifact_name);
// labors
memcpy(&furball.labors, &source->status.labors, sizeof(furball.labors));
@ -571,8 +571,8 @@ bool Units::RemoveOwnedItemByPtr(df::unit * temp, int32_t id)
return true;
}
void Units::CopyNameTo(df::unit * creature, df_name * target)
void Units::CopyNameTo(df::unit * creature, df::language_name * target)
{
d->trans->copyName((df_name *)&creature->name, target);
d->trans->copyName(&creature->name, target);
}

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