Merge branch 'version_compatiblity' of git://github.com/belal/dfhack

develop
Petr Mrázek 2010-03-14 20:15:54 +01:00
commit 34a2f238b0
6 changed files with 852 additions and 677 deletions

@ -35,6 +35,13 @@ enum likeType
ITEM = 2,
FOOD = 3
};
vector<DFHack::t_matgloss> creaturestypes;
matGlosses mat;
vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
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,
@ -141,9 +148,162 @@ likeType printLike(DFHack::t_like like, const matGlosses & mat,const vector< vec
}
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
if(string(creaturestypes[creature.type].id) == "DWARF")
{
cout << "address: " << creature.origin << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false;
if(creature.name.first_name[0])
{
cout << "first name: " << creature.name.first_name;
addendl = true;
}
if(creature.name.nickname[0])
{
cout << ", nick name: " << creature.name.nickname;
addendl = true;
}
string transName = DF.TranslateName(creature.name,englishWords,foreignWords,false);
if(!transName.empty())
{
cout << ", trans name: " << transName;
addendl=true;
}
//cout << ", generic name: " << DF.TranslateName(creature.last_name,names,"GENERIC");
/*
if(!creature.trans_name.empty()){
cout << ", trans name: " << creature.trans_name;
addendl =true;
}
if(!creature.generic_name.empty()){
cout << ", generic name: " << creature.generic_name;
addendl=true;
}
*/
cout << ", likes: ";
for(uint32_t i = 0;i<creature.numLikes; i++)
{
if(printLike(creature.likes[i],mat,itemTypes))
{
cout << ", ";
}
}
if(addendl)
{
cout << endl;
addendl = false;
}
cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")";
if(creature.custom_profession[0])
{
cout << ", custom profession: " << creature.custom_profession;
}
if(creature.current_job.active)
{
cout << ", current job: " << mem->getJob(creature.current_job.jobId);
}
cout << endl;
cout << "happiness: " << creature.happiness << ", strength: " << creature.strength << ", agility: "
<< creature.agility << ", toughness: " << creature.toughness << ", money: " << creature.money << ", id: " << creature.id;
if(creature.squad_leader_id != -1)
{
cout << ", squad_leader_id: " << creature.squad_leader_id;
}
if(creature.mood != -1){
cout << ", mood: " << creature.mood << " ";
}
cout << ", sex: ";
if(creature.sex == 0)
{
cout << "Female";
}
else
{
cout <<"Male";
}
cout << endl;
/*
//skills
for(unsigned int i = 0; i < creature.skills.size();i++){
if(i > 0){
cout << ", ";
}
cout << creature.skills[i].name << ": " << creature.skills[i].rating;
}
*/
/*
* FLAGS 1
*/
cout << "flags1: ";
print_bits(creature.flags1.whole, cout);
cout << endl;
if(creature.flags1.bits.dead)
{
cout << "dead ";
}
if(creature.flags1.bits.on_ground)
{
cout << "on the ground, ";
}
if(creature.flags1.bits.skeleton)
{
cout << "skeletal ";
}
if(creature.flags1.bits.zombie)
{
cout << "zombie ";
}
if(creature.flags1.bits.tame)
{
cout << "tame ";
}
if(creature.flags1.bits.royal_guard)
{
cout << "royal_guard ";
}
if(creature.flags1.bits.fortress_guard)
{
cout << "fortress_guard ";
}
/*
* FLAGS 2
*/
cout << endl << "flags2: ";
print_bits(creature.flags2.whole, cout);
cout << endl;
if(creature.flags2.bits.killed)
{
cout << "killed by kill function, ";
}
if(creature.flags2.bits.resident)
{
cout << "resident, ";
}
if(creature.flags2.bits.gutted)
{
cout << "gutted, ";
}
if(creature.flags2.bits.slaughter)
{
cout << "marked for slaughter, ";
}
if(creature.flags2.bits.underworld)
{
cout << "from the underworld, ";
}
cout << endl;
if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) ){
string artifact_name = DF.TranslateName(creature.artifact_name,englishWords,foreignWords,false);
cout << "artifact: " << artifact_name << endl;
}
}
cout << endl;
}
int main (void)
{
vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{
@ -151,17 +311,17 @@ int main (void)
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();
mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
@ -169,8 +329,6 @@ int main (void)
return 1;
}
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))
{
cerr << "Can't get name tables" << endl;
@ -182,152 +340,21 @@ int main (void)
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);
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;
if(temp.name.first_name[0])
{
cout << "first name: " << temp.name.first_name;
addendl = true;
}
if(temp.name.nickname[0])
{
cout << ", nick name: " << temp.name.nickname;
addendl = true;
}
string transName = DF.TranslateName(temp.name,englishWords,foreignWords,false);
if(!transName.empty())
{
cout << ", trans name: " << transName;
addendl=true;
}
//cout << ", generic name: " << DF.TranslateName(temp.last_name,names,"GENERIC");
/*
if(!temp.trans_name.empty()){
cout << ", trans name: " << temp.trans_name;
addendl =true;
}
if(!temp.generic_name.empty()){
cout << ", generic name: " << temp.generic_name;
addendl=true;
}
*/
cout << ", likes: ";
for(uint32_t i = 0;i<temp.numLikes; i++)
{
if(printLike(temp.likes[i],mat,itemTypes))
{
cout << ", ";
}
}
if(addendl)
{
cout << endl;
addendl = false;
}
cout << "profession: " << mem->getProfession(temp.profession) << "(" << (int) temp.profession << ")";
if(temp.custom_profession[0])
{
cout << ", custom profession: " << temp.custom_profession;
}
if(temp.current_job.active)
{
cout << ", current job: " << mem->getJob(temp.current_job.jobId);
}
cout << endl;
cout << "happiness: " << temp.happiness << ", strength: " << temp.strength << ", agility: "
<< temp.agility << ", toughness: " << temp.toughness << ", money: " << temp.money << ", id: " << temp.id;
if(temp.squad_leader_id != -1)
{
cout << ", squad_leader_id: " << temp.squad_leader_id;
}
cout << ", sex: ";
if(temp.sex == 0)
{
cout << "Female";
}
else
{
cout <<"Male";
}
cout << endl;
/*
//skills
for(unsigned int i = 0; i < temp.skills.size();i++){
if(i > 0){
cout << ", ";
}
cout << temp.skills[i].name << ": " << temp.skills[i].rating;
}
*/
/*
* FLAGS 1
*/
cout << "flags1: ";
print_bits(temp.flags1.whole, cout);
cout << endl;
if(temp.flags1.bits.dead)
{
cout << "dead ";
}
if(temp.flags1.bits.on_ground)
{
cout << "on the ground, ";
}
if(temp.flags1.bits.skeleton)
{
cout << "skeletal ";
}
if(temp.flags1.bits.zombie)
{
cout << "zombie ";
}
if(temp.flags1.bits.tame)
{
cout << "tame ";
}
if(temp.flags1.bits.royal_guard)
{
cout << "royal_guard ";
}
if(temp.flags1.bits.fortress_guard)
{
cout << "fortress_guard ";
}
/*
* FLAGS 2
*/
cout << endl << "flags2: ";
print_bits(temp.flags2.whole, cout);
cout << endl;
if(temp.flags2.bits.killed)
{
cout << "killed by kill function, ";
}
if(temp.flags2.bits.resident)
{
cout << "resident, ";
}
if(temp.flags2.bits.gutted)
{
cout << "gutted, ";
}
if(temp.flags2.bits.slaughter)
{
cout << "marked for slaughter, ";
}
if(temp.flags2.bits.underworld)
{
cout << "from the underworld, ";
}
cout << endl << endl;
}
DF.ReadCreature(i,temp);
cout << "index " << i << " ";
printCreature(DF,temp);
}
uint32_t currentIdx;
DFHack::t_creature currentCreature;
DF.getCurrentCursorCreature(currentIdx);
cout << "current creature at index " << currentIdx << endl;
DF.ReadCreature(currentIdx, currentCreature);
printCreature(DF,currentCreature);
DF.FinishReadCreatures();
DF.Detach();
#ifndef LINUX_BUILD

@ -366,16 +366,18 @@ start:
{
DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
vector<uint32_t> underCursor;
while (!DF.getCurrentCursorCreatures(underCursor))
uint32_t underCursor;
DF.getCurrentCursorCreature(underCursor);
while (underCursor != toChangeNum)
{
DF.Resume();
w->TypeSpecial(DFHack::WAIT,1,100);
w->TypeStr("v",100);
DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
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
//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
@ -390,7 +392,7 @@ start:
break;
}
}
}
}*/
DF.Resume();
w->TypeStr(commandString.c_str());
if (waitTillScreenState(DF,"viewscreen_customize_unit"))

@ -431,23 +431,12 @@ bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer)
return false;
}
bool API::getCurrentCursorCreatures (vector<uint32_t> &addresses)
bool API::getCurrentCursorCreature(uint32_t & creature_index)
{
if(d->cursorWindowInited) return false;
DfVector creUnderCursor = d->p->readVector (d->current_cursor_creature_offset, 4);
if (creUnderCursor.getSize() == 0)
{
return false;
}
addresses.clear();
for (uint32_t i = 0;i < creUnderCursor.getSize();i++)
{
uint32_t temp = * (uint32_t *) creUnderCursor.at (i);
addresses.push_back (temp);
}
if(!d->cursorWindowInited) return false;
creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset);
return true;
}
// 256 * sizeof(uint32_t)
bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
{
@ -1258,7 +1247,7 @@ 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);
furball.mood = (int16_t) g_pProcess->readWord (temp + d->creature_mood_offset);
g_pProcess->readDWord (temp + d->creature_happiness_offset, furball.happiness);

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

@ -545,7 +545,7 @@ struct t_creature
uint8_t numLikes;
t_like likes[32];
t_job current_job;
uint16_t mood;
int16_t mood;
uint32_t happiness;
uint32_t id;
uint32_t agility;

File diff suppressed because it is too large Load Diff