Further cleanup for name stuff; fixing examples that I broke and handling settlements. Also added mood, so that it can be determined whether or not the dwarf's artifact was created.

develop
Zhentar 2010-03-07 20:01:30 -06:00
parent 65bf8f69fd
commit 052dd53c03
7 changed files with 1759 additions and 1735 deletions

@ -169,8 +169,9 @@ int main (void)
return 1;
}
map<string, vector<string> > names;
if(!DF.InitReadNameTables(names))
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))
{
cerr << "Can't get name tables" << endl;
return 1;
@ -189,17 +190,17 @@ int main (void)
{
cout << "address: " << temp.origin << " creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
bool addendl = false;
if(temp.first_name[0])
if(temp.name.first_name[0])
{
cout << "first name: " << temp.first_name;
cout << "first name: " << temp.name.first_name;
addendl = true;
}
if(temp.nick_name[0])
if(temp.name.nickname[0])
{
cout << ", nick name: " << temp.nick_name;
cout << ", nick name: " << temp.name.nickname;
addendl = true;
}
string transName = DF.TranslateName(temp.last_name,names,creaturestypes[temp.type].id);
string transName = DF.TranslateName(temp.name,englishWords,foreignWords,false);
if(!transName.empty())
{
cout << ", trans name: " << transName;

@ -50,8 +50,9 @@ int main (void)
cerr << "DF not found" << endl;
return 1;
}
map< string, vector<string> > names;
if(!DF.InitReadNameTables(names))
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))
{
cerr << "Could not get Names" << endl;
return 1;
@ -61,7 +62,7 @@ int main (void)
cout << "\nSelect Name to search or q to Quit" << endl;
getline (cin, input);
while(input != "q"){
for( map< string, vector<string> >::iterator it = names.begin();it != names.end(); it++){
/*for( map< string, vector<string> >::iterator it = names.begin();it != names.end(); it++){
for(uint32_t i = 0; i < it->second.size(); i++){
uint32_t found = tolower(input).find(tolower(it->second[i]));
if(found != string::npos){
@ -70,7 +71,7 @@ int main (void)
cout << it->first << " " << it->second[i] << " " << groupBy2(value.str()) << endl;
}
}
}
}*/
DF.Resume();
getline(cin,input);
}

@ -23,7 +23,8 @@ void print_bits ( T val, std::ostream& out )
val >>= 1;
}
}
map<string, vector<string> > names;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
uint32_t numCreatures;
vector<DFHack::t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF)
@ -37,15 +38,15 @@ void printDwarves(DFHack::API & DF)
if (type == "DWARF" && !temp.flags1.bits.dead && !temp.flags2.bits.killed)
{
cout << i << ":";
if (temp.nick_name[0])
if (temp.name.nickname[0])
{
cout << temp.nick_name;
cout << temp.name.nickname;
}
else
{
cout << temp.first_name;
cout << temp.name.first_name;
}
string transName = DF.TranslateName(temp.last_name,names,creaturestypes[temp.type].id);
string transName = DF.TranslateName(temp.name,englishWords,foreignWords, false);
cout << " " << temp.custom_profession; //transName;
if (dwarfCounter%3 != 2)
{
@ -109,7 +110,7 @@ bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string &
if (input == "n")
{
commandString = "pzyn";
eraseAmount = string(toChange.nick_name).length();
eraseAmount = string(toChange.name.nickname).length();
changeType = true;
isName = true;
}
@ -153,7 +154,7 @@ bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, b
int tryCount = 0;
if (isName)
{
while (testCre.nick_name != changeValue && tryCount <50)
while (testCre.name.nickname != changeValue && tryCount <50)
{
DF.Resume();
w->TypeSpecial(DFHack::WAIT,1,100);
@ -324,7 +325,7 @@ int main (void)
return 1;
}
DF.InitReadNameTables(names);
DF.InitReadNameTables(englishWords,foreignWords);
DF.InitReadCreatures(numCreatures);
DF.InitViewAndCursor();
DFHack::Process * p = DF.getProcess();

@ -9,10 +9,11 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const map<string, vector<string> > &names)
void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords)
{
string genericName = DF.TranslateName(settlement.name,2,names,"GENERIC");
string dwarfName = DF.TranslateName(settlement.name,2,names,"DWARF");
string genericName = DF.TranslateName(settlement.name,englishWords,foreignWords,true);
string dwarfName = DF.TranslateName(settlement.name,englishWords,foreignWords,false);
cout << dwarfName << " " << genericName << " " << "world x: " << settlement.world_x << " world y: " << settlement.world_y
<< " local_x: " << settlement.local_x1 << " local_y: " << settlement.local_y1 << " size: " << settlement.local_x2 - settlement.local_x1 << " by " << settlement.local_y2 - settlement.local_y1 << "\n";
}
@ -32,22 +33,23 @@ int main (int argc,const char* argv[])
cerr << "Could not read Settlements" << endl;
return 1;
}
map<string, vector<string> > names;
if(!DF.InitReadNameTables(names))
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))
{
cerr << "Can't get name tables" << endl;
return 1;
}
cout << "Settlements\n";
for(uint32_t i =0;i<numSettlements;i++){
/*for(uint32_t i =0;i<numSettlements;i++){
DFHack::t_settlement temp;
DF.ReadSettlement(i,temp);
printSettlement(DF,temp,names);
}
printSettlement(DF,temp,englishWords,foreignWords);
}*/
// MSVC claims this is causing the heap to be corrupted, I think it is because the currentSettlement vector only has 1 item in it
cout << "Current Settlement\n";
DF.ReadCurrentSettlement(current);
printSettlement(DF,current,names);
if(DF.ReadCurrentSettlement(current))
printSettlement(DF,current,englishWords,foreignWords);
DF.FinishReadNameTables();
DF.FinishReadSettlements();

@ -36,6 +36,9 @@ public:
, pm (NULL), p (NULL), offset_descriptor (NULL)
, p_cons (NULL), p_bld (NULL), p_veg (NULL)
{}
void readName(t_name & name, uint32_t address);
uint32_t * block;
uint32_t x_block_count, y_block_count, z_block_count;
uint32_t regionX, regionY, regionZ;
@ -61,12 +64,15 @@ public:
uint32_t view_screen_offset;
uint32_t current_menu_state_offset;
uint32_t name_firstname_offset;
uint32_t name_nickname_offset;
uint32_t name_words_offset;
uint32_t creature_pos_offset;
uint32_t creature_type_offset;
uint32_t creature_flags1_offset;
uint32_t creature_flags2_offset;
uint32_t creature_name_offset;
uint32_t creature_custom_profession_offset;
uint32_t creature_profession_offset;
uint32_t creature_sex_offset;
@ -85,6 +91,7 @@ public:
uint32_t creature_traits_offset;
uint32_t creature_likes_offset;
uint32_t creature_artifact_name_offset;
uint32_t creature_mood_offset;
uint32_t item_material_offset;
@ -869,6 +876,9 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
try
{
memory_info * minfo = d->offset_descriptor;
d->name_firstname_offset = minfo->getOffset("name_firstname");
d->name_nickname_offset = minfo->getOffset("name_nickname");
d->name_words_offset = minfo->getOffset("name_words");
int creatures = d->offset_descriptor->getAddress ("creatures");
d->creature_pos_offset = minfo->getOffset ("creature_position");
d->creature_type_offset = minfo->getOffset ("creature_race");
@ -893,6 +903,7 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
d->creature_traits_offset = minfo->getOffset ("creature_traits");
d->creature_likes_offset = minfo->getOffset("creature_likes");
d->creature_artifact_name_offset = minfo->getOffset("creature_artifact_name");
d->creature_mood_offset = minfo->getOffset("creature_mood");
d->p_cre = new DfVector (d->p->readVector (creatures, 4));
//InitReadNameTables();
@ -974,7 +985,7 @@ bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_settlements->at (index);
settlement.origin = temp;
g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name);
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
@ -987,7 +998,7 @@ bool API::ReadCurrentSettlement(t_settlement & settlement)
uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0);
settlement.origin = temp;
g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name);
d->readName(settlement.name, temp + d->settlement_name_offset);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true;
@ -1101,11 +1112,11 @@ bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
return true;
}
void readName(t_name & name, uint32_t address)
void API::Private::readName(t_name & name, uint32_t address)
{
g_pProcess->readSTLString(address, name.first_name, 128);
g_pProcess->readSTLString(address + sizeof(string), name.nickname, 128);
g_pProcess->read(address + 2 * sizeof(string),48, (uint8_t *) name.words);
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128);
g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128);
g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words);
}
bool API::ReadCreature (const int32_t index, t_creature & furball)
@ -1120,14 +1131,12 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
g_pProcess->readDWord (temp + d->creature_flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + d->creature_flags2_offset, furball.flags2.whole);
// names
readName(furball.name,temp + d->creature_name_offset);
readName(furball.squad_name, temp + d->creature_squad_name_offset);
readName(furball.artifact_name, temp + d->creature_artifact_name_offset);
d->readName(furball.name,temp + d->creature_name_offset);
d->readName(furball.squad_name, temp + d->creature_squad_name_offset);
d->readName(furball.artifact_name, temp + d->creature_artifact_name_offset);
// custom profession
fill_char_buf (furball.custom_profession, d->p->readSTLString (temp + d->creature_custom_profession_offset));
// labors
g_pProcess->read (temp + d->creature_labors_offset, NUM_CREATURE_LABORS, furball.labors);
// traits
@ -1168,6 +1177,9 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}
g_pProcess->readWord (temp + d->creature_mood_offset, furball.mood);
g_pProcess->readDWord (temp + d->creature_happiness_offset, furball.happiness);
g_pProcess->readDWord (temp + d->creature_id_offset, furball.id);
g_pProcess->readDWord (temp + d->creature_agility_offset, furball.agility);

@ -543,6 +543,7 @@ struct t_creature
uint8_t numLikes;
t_like likes[32];
t_job current_job;
uint16_t mood;
uint32_t happiness;
uint32_t id;
uint32_t agility;
@ -797,7 +798,7 @@ struct t_hotkey
struct t_settlement
{
uint32_t origin;
int32_t name[2];
t_name name;
int16_t world_x;
int16_t world_y;
int16_t local_x1;

@ -730,12 +730,18 @@
<Address name="language_vector">0x01534240</Address>
<Offset name="word_table">0x54</Offset>
<!-- name struct -->
<Offset name="name_firstname">0x0</Offset>
<Offset name="name_nickname">0x1C</Offset>
<Offset name="name_words">0x38</Offset>
<!-- creature offsets -->
<Offset name="creature_flags1">0xFC</Offset>
<Offset name="creature_flags2">0x100</Offset>
<Offset name="creature_sex">0x10A</Offset>
<Offset name="creature_id">0x10C</Offset>
<Offset name="creature_squad_name">0x198</Offset>
<Offset name="creature_mood">0x238</Offset>
<Offset name="creature_squad_leader_id">0x268</Offset>
<Offset name="creature_money">0x2F8</Offset>
<Offset name="creature_current_job">0x314</Offset>
@ -821,7 +827,7 @@
<Address name="settlement_current">0x01533CC0</Address>
<Address name="settlements">0x01533BF4</Address>
<Offset name="settlement_name">0x38</Offset>
<Offset name="settlement_name">0x0</Offset>
<Offset name="settlement_world_xy">0x7a</Offset>
<Offset name="settlement_local_xy">0x100</Offset>