Mood reading preliminary support

develop
simon 2010-04-26 13:23:57 +02:00
parent a60470ccd1
commit b59b552f93
5 changed files with 65 additions and 3 deletions

@ -260,10 +260,18 @@ namespace DFHack
uint32_t experience;
uint16_t rating;
};
struct t_material
{
int16_t typeA;
int16_t typeB;
int16_t typeC;
};
struct t_job
{
bool active;
uint8_t jobId;
uint32_t jobId;
uint8_t jobType;
uint32_t occupationPtr;
};
struct t_like
{
@ -284,6 +292,7 @@ namespace DFHack
uint32_t field_18;
};
// FIXME: define in Memory.xml instead?
#define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102
@ -371,6 +380,7 @@ namespace DFHack
bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
uint32_t GetDwarfRaceIndex ( void );
int32_t GetDwarfCivId ( void );
bool ReadJob(const t_creature * furball, vector<t_material> & mat);
private:
struct Private;
Private *d;

@ -89,6 +89,7 @@ Creatures::Creatures(APIPrivate* _d)
creatures.physical_offset = minfo->getOffset("creature_physical");
creatures.mood_offset = minfo->getOffset("creature_mood");
creatures.pickup_equipment_bit = minfo->getOffset("creature_pickup_equipment_bit");
creatures.current_job_offset = minfo->getOffset("creature_current_job");
// soul offsets
creatures.soul_skills_vector_offset = minfo->getOffset("soul_skills_vector");
creatures.soul_mental_offset = minfo->getOffset("soul_mental");
@ -157,6 +158,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
}
// non-SHM slow path
memory_info * minfo = d->d->offset_descriptor;
// read pointer from vector at position
uint32_t temp = d->p_cre->at (index);
@ -194,6 +196,19 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
// profession
furball.profession = p->readByte (temp + offs.profession_offset);
furball.current_job.occupationPtr = p->readDWord (temp + offs.current_job_offset);
if(furball.current_job.occupationPtr)
{
furball.current_job.active = true;
furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + minfo->getOffset("job_type") );
furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + minfo->getOffset("job_id") );
}
else
{
furball.current_job.active = false;;
}
// current job HACK: the job object isn't cleanly represented here
/*
uint32_t jobIdAddr = p->readDWord (temp + offs.creature_current_job_offset);
@ -342,3 +357,23 @@ bool Creatures::getCurrentCursorCreature(uint32_t & creature_index)
return true;
}
*/
bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
{
unsigned int i;
if(!d->Inited) return false;
if(!furball->current_job.active) return false;
Process * p = d->owner;
memory_info * minfo = d->d->offset_descriptor;
DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector"));
mat.resize(cmats.size());
for(i=0;i<cmats.size();i++)
{
printf("!");
mat[i].typeA = p->readWord(cmats[i] + minfo->getOffset("job_material_maintype"));
mat[i].typeB = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype1"));
mat[i].typeC = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype2"));
}
return true;
}

@ -53,6 +53,7 @@ typedef struct
uint32_t pickup_equipment_bit;
uint32_t soul_vector_offset;
uint32_t default_soul_offset;
uint32_t current_job_offset;
// soul offsets
uint32_t soul_skills_vector_offset;
// name offsets (needed for reading creature names)

@ -39,6 +39,7 @@ vector< vector <DFHack::t_itemType> > itemTypes;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
DFHack::Creatures * Creatures = NULL;
/*
likeType printLike40d(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,
@ -239,6 +240,18 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout <<"Male";
}
cout << endl;
if(creature.mood != -1)
{
cout << "mood: " << creature.mood << endl;
vector<DFHack::t_material> mat;
if(Creatures->ReadJob(&creature, mat))
{
for(unsigned int i = 0; i < mat.size(); i++)
printf("\t%.4x %.4x %.4x\n", mat[i].typeA, mat[i].typeB, mat[i].typeC);
}
}
/*
if(creature.pregnancy_timer > 0)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
@ -376,7 +389,7 @@ int main (int numargs, char ** args)
if(numargs == 2)
check = args[1];
DFHack::Creatures * Creatures = DF.getCreatures();
Creatures = DF.getCreatures();
DFHack::Materials * Materials = DF.getMaterials();
DFHack::Translation * Tran = DF.getTranslation();

@ -1420,12 +1420,15 @@ map_data_1b60_offset 0x1B9c
Job structure
=============
<Offset name="job_type">0x4</Offset> seems to be just like the old occupations
<Offset name="job_id">0x0</Offset> Incrementaly assigned
<Offset name="job_type">0x8</Offset> seems to be just like the old occupations
<Offset name="job_materials_vector">0xa4</Offset>
Job materials
=============
<Offset name="job_material_maintype">0x0</Offset> like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ...
<Offset name="job_material_sectype1">0x2</Offset> always -1
<Offset name="job_material_sectype2">0x2</Offset> subtype ?
Materials
=========