creatures: read and write pregnancy counter

Also change creaturemanger to print out the ticks-until-birth for
pregnant creatures.
develop
Matthew Cline 2011-07-11 02:48:10 -07:00
parent 4d406524c0
commit 5c1526d6d9
5 changed files with 32 additions and 5 deletions

@ -64,6 +64,7 @@ DFHACK_EXPORT int Creatures_WriteMoodSkill(DFHackObject* cPtr, const uint32_t in
DFHACK_EXPORT int Creatures_WriteJob(DFHackObject* cPtr, const t_creature* furball, const t_material* mat, const uint32_t mat_count); DFHACK_EXPORT int Creatures_WriteJob(DFHackObject* cPtr, const t_creature* furball, const t_material* mat, const uint32_t mat_count);
DFHACK_EXPORT int Creatures_WritePos(DFHackObject* cPtr, const uint32_t index, const t_creature* creature); DFHACK_EXPORT int Creatures_WritePos(DFHackObject* cPtr, const uint32_t index, const t_creature* creature);
DFHACK_EXPORT int Creatures_WriteCiv(DFHackObject* cPtr, const uint32_t index, const int32_t civ); DFHACK_EXPORT int Creatures_WriteCiv(DFHackObject* cPtr, const uint32_t index, const int32_t civ);
DFHACK_EXPORT int Creatures_WritePregnancy(DFHackObject* cPtr, const uint32_t index, const uint32_t pregTimer);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -380,6 +380,7 @@ namespace DFHack
bool WriteJob(const t_creature * furball, std::vector<t_material> const& mat); bool WriteJob(const t_creature * furball, std::vector<t_material> const& mat);
bool WritePos(const uint32_t index, const t_creature &creature); bool WritePos(const uint32_t index, const t_creature &creature);
bool WriteCiv(const uint32_t index, const int32_t civ); bool WriteCiv(const uint32_t index, const int32_t civ);
bool WritePregnancy(const uint32_t index, const uint32_t pregTimer);
void CopyNameTo(t_creature &creature, uint32_t address); void CopyNameTo(t_creature &creature, uint32_t address);

@ -78,6 +78,8 @@ struct Creatures::Private
uint32_t artifact_name_offset; uint32_t artifact_name_offset;
uint32_t physical_offset; uint32_t physical_offset;
uint32_t mood_offset; uint32_t mood_offset;
uint32_t pregnancy_offset;
uint32_t pregnancy_ptr_offset;
uint32_t mood_skill_offset; uint32_t mood_skill_offset;
uint32_t pickup_equipment_bit; uint32_t pickup_equipment_bit;
uint32_t soul_vector_offset; uint32_t soul_vector_offset;
@ -171,8 +173,8 @@ Creatures::Creatures(DFContextShared* _d)
{ {
creatures.pickup_equipment_bit = OG_creature_ex->getOffset("pickup_equipment_bit"); creatures.pickup_equipment_bit = OG_creature_ex->getOffset("pickup_equipment_bit");
creatures.mood_offset = OG_creature_ex->getOffset("mood"); creatures.mood_offset = OG_creature_ex->getOffset("mood");
// pregnancy creatures.pregnancy_offset = OG_creature_ex->getOffset("pregnancy");
// pregnancy_ptr creatures.pregnancy_ptr_offset = OG_creature_ex->getOffset("pregnancy_ptr");
creatures.birth_year_offset = OG_creature_ex->getOffset("birth_year"); creatures.birth_year_offset = OG_creature_ex->getOffset("birth_year");
creatures.birth_time_offset = OG_creature_ex->getOffset("birth_time"); creatures.birth_time_offset = OG_creature_ex->getOffset("birth_time");
creatures.current_job_offset = OG_creature_ex->getOffset("current_job"); creatures.current_job_offset = OG_creature_ex->getOffset("current_job");
@ -312,10 +314,8 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
furball.birth_year = p->readDWord (addr_cr + offs.birth_year_offset ); furball.birth_year = p->readDWord (addr_cr + offs.birth_year_offset );
furball.birth_time = p->readDWord (addr_cr + offs.birth_time_offset ); furball.birth_time = p->readDWord (addr_cr + offs.birth_time_offset );
/*
* p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
*/
furball.pregnancy_timer = p->readDWord (addr_cr + offs.pregnancy_offset );
// appearance // appearance
DfVector <uint32_t> app(p, addr_cr + offs.appearance_vector_offset); DfVector <uint32_t> app(p, addr_cr + offs.appearance_vector_offset);
furball.nbcolors = app.size(); furball.nbcolors = app.size();
@ -652,6 +652,16 @@ bool Creatures::WriteCiv(const uint32_t index, const int32_t civ)
return true; return true;
} }
bool Creatures::WritePregnancy(const uint32_t index, const uint32_t pregTimer)
{
if(!d->Started) return false;
uint32_t temp = d->p_cre->at (index);
Process * p = d->owner;
p->writeDWord(temp + d->creatures.pregnancy_offset, pregTimer);
return true;
}
uint32_t Creatures::GetDwarfRaceIndex() uint32_t Creatures::GetDwarfRaceIndex()
{ {
if(!d->Inited) return 0; if(!d->Inited) return 0;

@ -320,6 +320,16 @@ int Creatures_WriteCiv(DFHackObject* cPtr, const uint32_t index, const int32_t c
return -1; return -1;
} }
int Creatures_WritePregnancy(DFHackObject* cPtr, const uint32_t index, const uint32_t pregTimer)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WritePregnancy(index, pregTimer);
}
return -1;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -518,6 +518,11 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in
cout << "(Labor " << i << ") " << setw(16) << laborname << endl; cout << "(Labor " << i << ") " << setw(16) << laborname << endl;
} }
} }
if (creature.pregnancy_timer > 0)
cout << "Pregnant: " << creature.pregnancy_timer << " ticks to "
<< "birth." << endl;
if (showallflags) if (showallflags)
{ {
DFHack::t_creaturflags1 f1 = creature.flags1; DFHack::t_creaturflags1 f1 = creature.flags1;