modify the renamer and creature dump to output the new current cursor creature code

develop
belal 2010-03-12 09:21:45 -05:00
parent ed386d3fd3
commit 791ac8dd75
4 changed files with 177 additions and 155 deletions

@ -36,6 +36,12 @@ enum likeType
FOOD = 3 FOOD = 3
}; };
vector<DFHack::t_matgloss> creaturestypes;
matGlosses mat;
vector< vector <DFHack::t_itemType> > itemTypes;
map<string, vector<string> > names;
DFHack::memory_info *mem;
likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vector <DFHack::t_itemType> > & itemTypes) likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vector <DFHack::t_itemType> > & itemTypes)
{ // The function in DF which prints out the likes is a monster, it is a huge switch statement with tons of options and calls a ton of other functions as well, { // The function in DF which prints out the likes is a monster, it is a huge switch statement with tons of options and calls a ton of other functions as well,
//so I am not going to try and put all the possibilites here, only the low hanging fruit, with stones and metals, as well as items, //so I am not going to try and put all the possibilites here, only the low hanging fruit, with stones and metals, as well as items,
@ -141,85 +147,43 @@ likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vec
} }
int main (void) void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{ {
vector<DFHack::t_matgloss> creaturestypes; if(string(creaturestypes[creature.type].id) == "DWARF")
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{ {
cerr << "DF not found" << endl; cout << "address: " << creature.origin << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
return 1;
}
vector< vector <DFHack::t_itemType> > itemTypes;
DF.ReadItemTypes(itemTypes);
matGlosses mat;
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);
DF.ReadStoneMatgloss(mat.stoneMat);
DF.ReadMetalMatgloss(mat.metalMat);
DF.ReadCreatureMatgloss(mat.creatureMat);
DFHack::memory_info *mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
}
map<string, vector<string> > names;
if(!DF.InitReadNameTables(names))
{
cerr << "Can't get name tables" << endl;
return 1;
}
uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures))
{
cerr << "Can't get creatures" << endl;
return 1;
}
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i, temp);
if(string(creaturestypes[temp.type].id) == "DWARF")
{
cout << "address: " << temp.origin << " creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
bool addendl = false; bool addendl = false;
if(temp.first_name[0]) if(creature.first_name[0])
{ {
cout << "first name: " << temp.first_name; cout << "first name: " << creature.first_name;
addendl = true; addendl = true;
} }
if(temp.nick_name[0]) if(creature.nick_name[0])
{ {
cout << ", nick name: " << temp.nick_name; cout << ", nick name: " << creature.nick_name;
addendl = true; addendl = true;
} }
string transName = DF.TranslateName(temp.last_name,names,creaturestypes[temp.type].id); string transName = DF.TranslateName(creature.last_name,names,creaturestypes[creature.type].id);
if(!transName.empty()) if(!transName.empty())
{ {
cout << ", trans name: " << transName; cout << ", trans name: " << transName;
addendl=true; addendl=true;
} }
//cout << ", generic name: " << DF.TranslateName(temp.last_name,names,"GENERIC"); //cout << ", generic name: " << DF.TranslateName(creature.last_name,names,"GENERIC");
/* /*
if(!temp.trans_name.empty()){ if(!creature.trans_name.empty()){
cout << ", trans name: " << temp.trans_name; cout << ", trans name: " << creature.trans_name;
addendl =true; addendl =true;
} }
if(!temp.generic_name.empty()){ if(!creature.generic_name.empty()){
cout << ", generic name: " << temp.generic_name; cout << ", generic name: " << creature.generic_name;
addendl=true; addendl=true;
} }
*/ */
cout << ", likes: "; cout << ", likes: ";
for(uint32_t i = 0;i<temp.numLikes; i++) for(uint32_t i = 0;i<creature.numLikes; i++)
{ {
if(printLike(temp.likes[i],mat,itemTypes)) if(printLike(creature.likes[i],mat,itemTypes))
{ {
cout << ", "; cout << ", ";
} }
@ -229,24 +193,24 @@ int main (void)
cout << endl; cout << endl;
addendl = false; addendl = false;
} }
cout << "profession: " << mem->getProfession(temp.profession) << "(" << (int) temp.profession << ")"; cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")";
if(temp.custom_profession[0]) if(creature.custom_profession[0])
{ {
cout << ", custom profession: " << temp.custom_profession; cout << ", custom profession: " << creature.custom_profession;
} }
if(temp.current_job.active) if(creature.current_job.active)
{ {
cout << ", current job: " << mem->getJob(temp.current_job.jobId); cout << ", current job: " << mem->getJob(creature.current_job.jobId);
} }
cout << endl; cout << endl;
cout << "happiness: " << temp.happiness << ", strength: " << temp.strength << ", agility: " cout << "happiness: " << creature.happiness << ", strength: " << creature.strength << ", agility: "
<< temp.agility << ", toughness: " << temp.toughness << ", money: " << temp.money << ", id: " << temp.id; << creature.agility << ", toughness: " << creature.toughness << ", money: " << creature.money << ", id: " << creature.id;
if(temp.squad_leader_id != -1) if(creature.squad_leader_id != -1)
{ {
cout << ", squad_leader_id: " << temp.squad_leader_id; cout << ", squad_leader_id: " << creature.squad_leader_id;
} }
cout << ", sex: "; cout << ", sex: ";
if(temp.sex == 0) if(creature.sex == 0)
{ {
cout << "Female"; cout << "Female";
} }
@ -257,44 +221,44 @@ int main (void)
cout << endl; cout << endl;
/* /*
//skills //skills
for(unsigned int i = 0; i < temp.skills.size();i++){ for(unsigned int i = 0; i < creature.skills.size();i++){
if(i > 0){ if(i > 0){
cout << ", "; cout << ", ";
} }
cout << temp.skills[i].name << ": " << temp.skills[i].rating; cout << creature.skills[i].name << ": " << creature.skills[i].rating;
} }
*/ */
/* /*
* FLAGS 1 * FLAGS 1
*/ */
cout << "flags1: "; cout << "flags1: ";
print_bits(temp.flags1.whole, cout); print_bits(creature.flags1.whole, cout);
cout << endl; cout << endl;
if(temp.flags1.bits.dead) if(creature.flags1.bits.dead)
{ {
cout << "dead "; cout << "dead ";
} }
if(temp.flags1.bits.on_ground) if(creature.flags1.bits.on_ground)
{ {
cout << "on the ground, "; cout << "on the ground, ";
} }
if(temp.flags1.bits.skeleton) if(creature.flags1.bits.skeleton)
{ {
cout << "skeletal "; cout << "skeletal ";
} }
if(temp.flags1.bits.zombie) if(creature.flags1.bits.zombie)
{ {
cout << "zombie "; cout << "zombie ";
} }
if(temp.flags1.bits.tame) if(creature.flags1.bits.tame)
{ {
cout << "tame "; cout << "tame ";
} }
if(temp.flags1.bits.royal_guard) if(creature.flags1.bits.royal_guard)
{ {
cout << "royal_guard "; cout << "royal_guard ";
} }
if(temp.flags1.bits.fortress_guard) if(creature.flags1.bits.fortress_guard)
{ {
cout << "fortress_guard "; cout << "fortress_guard ";
} }
@ -302,31 +266,85 @@ int main (void)
* FLAGS 2 * FLAGS 2
*/ */
cout << endl << "flags2: "; cout << endl << "flags2: ";
print_bits(temp.flags2.whole, cout); print_bits(creature.flags2.whole, cout);
cout << endl; cout << endl;
if(temp.flags2.bits.killed) if(creature.flags2.bits.killed)
{ {
cout << "killed by kill function, "; cout << "killed by kill function, ";
} }
if(temp.flags2.bits.resident) if(creature.flags2.bits.resident)
{ {
cout << "resident, "; cout << "resident, ";
} }
if(temp.flags2.bits.gutted) if(creature.flags2.bits.gutted)
{ {
cout << "gutted, "; cout << "gutted, ";
} }
if(temp.flags2.bits.slaughter) if(creature.flags2.bits.slaughter)
{ {
cout << "marked for slaughter, "; cout << "marked for slaughter, ";
} }
if(temp.flags2.bits.underworld) if(creature.flags2.bits.underworld)
{ {
cout << "from the underworld, "; cout << "from the underworld, ";
} }
cout << endl << endl; cout << endl << endl;
} }
}
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
DF.ReadItemTypes(itemTypes);
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);
DF.ReadStoneMatgloss(mat.stoneMat);
DF.ReadMetalMatgloss(mat.metalMat);
DF.ReadCreatureMatgloss(mat.creatureMat);
mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
}
if(!DF.InitReadNameTables(names))
{
cerr << "Can't get name tables" << endl;
return 1;
}
uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures))
{
cerr << "Can't get creatures" << endl;
return 1;
} }
DF.InitViewAndCursor();
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
printCreature(DF,temp);
}
uint32_t currentIdx;
DFHack::t_creature currentCreature;
DF.getCurrentCursorCreature(currentIdx);
cout << "current creature" << endl;
DF.ReadCreature(currentIdx, currentCreature);
printCreature(DF,currentCreature);
DF.FinishReadCreatures(); DF.FinishReadCreatures();
DF.Detach(); DF.Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD

@ -364,16 +364,18 @@ start:
{ {
DF.Suspend(); DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z); DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
vector<uint32_t> underCursor; uint32_t underCursor;
while (!DF.getCurrentCursorCreatures(underCursor)) DF.getCurrentCursorCreature(underCursor);
while (underCursor != toChangeNum)
{ {
DF.Resume(); DF.Resume();
w->TypeSpecial(DFHack::WAIT,1,100); w->TypeStr("v",100);
DF.Suspend(); DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z); DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
DF.ReadCreature(toChangeNum,toChange); DF.ReadCreature(toChangeNum,toChange);
DF.getCurrentCursorCreature(underCursor);
} }
//CurrentCursorCreatures gives the creatures in the order that you see them with the 'k' cursor. /*//CurrentCursorCreatures gives the creatures in the order that you see them with the 'k' cursor.
//The 'v' cursor displays them in the order of last, then first,second,third and so on //The 'v' cursor displays them in the order of last, then first,second,third and so on
//Pretty weird, but it works //Pretty weird, but it works
//The only place that seems to display which creature is currently selected is on the stack, whose location is likely not static, so not usable //The only place that seems to display which creature is currently selected is on the stack, whose location is likely not static, so not usable
@ -388,7 +390,7 @@ start:
break; break;
} }
} }
} }*/
DF.Resume(); DF.Resume();
w->TypeStr(commandString.c_str()); w->TypeStr(commandString.c_str());
if (waitTillScreenState(DF,"viewscreen_customize_unit")) if (waitTillScreenState(DF,"viewscreen_customize_unit"))

@ -331,7 +331,7 @@ bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
return false; return false;
} }
bool API::getCurrentCursorCreature (uint32_t & creature_index) bool API::getCurrentCursorCreature(uint32_t & creature_index)
{ {
if(!d->cursorWindowInited) return false; if(!d->cursorWindowInited) return false;
creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset); creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset);

@ -199,7 +199,9 @@ namespace DFHack
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z); bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
bool API::getCurrentCursorCreature (uint32_t & creature_index); /// This returns false if there is nothing under the cursor, it puts the addresses in a vector if there is
bool getCurrentCursorCreature (uint32_t & creature_index);
bool InitViewSize(); bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height); bool getWindowSize(int32_t & width, int32_t & height);