@ -25,68 +25,47 @@ distribution.
# include "DFCommonInternal.h"
# include "DFCommonInternal.h"
# include "../private/APIPrivate.h"
# include "../private/APIPrivate.h"
# define SHMCREATURESHDR ((Creatures ::shm_creature_hdr *)d->shm_start)
# define SHMCREATURESHDR ((Creatures 2010 ::shm_creature_hdr *)d->shm_start)
using namespace DFHack ;
using namespace DFHack ;
/*
bool API : : InitReadCreatures ( uint32_t & numcreatures )
bool API : : InitReadCreatures ( uint32_t & numcreatures )
{
{
if ( ! d - > InitReadNames ( ) ) return false ;
if ( ! d - > InitReadNames ( ) ) return false ;
try
try
{
{
memory_info * minfo = d - > offset_descriptor ;
memory_info * minfo = d - > offset_descriptor ;
Creatures : : creature_offsets & off = d - > creatures ;
Creatures 2010 : : creature_offsets & off = d - > creatures ;
off . creature_vector = minfo - > getAddress ( " creature s " ) ;
off . creature_vector = minfo - > getAddress ( " creature _vector " ) ;
off . creature_pos_offset = minfo - > getOffset ( " creature_position " ) ;
off . creature_pos_offset = minfo - > getOffset ( " creature_position " ) ;
off . creature_type_offset = minfo - > getOffset ( " creature_race " ) ;
off . creature_profession_offset = minfo - > getOffset ( " creature_profession " ) ;
off . creature_race_offset = minfo - > getOffset ( " creature_race " ) ;
off . creature_flags1_offset = minfo - > getOffset ( " creature_flags1 " ) ;
off . creature_flags1_offset = minfo - > getOffset ( " creature_flags1 " ) ;
off . creature_flags2_offset = minfo - > getOffset ( " creature_flags2 " ) ;
off . creature_flags2_offset = minfo - > getOffset ( " creature_flags2 " ) ;
off . creature_name_offset = minfo - > getOffset ( " creature_name " ) ;
off . creature_name_offset = minfo - > getOffset ( " creature_name " ) ;
off . creature_custom_profession_offset = minfo - > getOffset ( " creature_custom_profession " ) ;
off . creature_profession_offset = minfo - > getOffset ( " creature_profession " ) ;
off . creature_sex_offset = minfo - > getOffset ( " creature_sex " ) ;
off . creature_sex_offset = minfo - > getOffset ( " creature_sex " ) ;
off . creature_id_offset = minfo - > getOffset ( " creature_id " ) ;
off . creature_id_offset = minfo - > getOffset ( " creature_id " ) ;
off . creature_squad_name_offset = minfo - > getOffset ( " creature_squad_name " ) ;
off . creature_squad_leader_id_offset = minfo - > getOffset ( " creature_squad_leader_id " ) ;
off . creature_money_offset = minfo - > getOffset ( " creature_money " ) ;
off . creature_current_job_offset = minfo - > getOffset ( " creature_current_job " ) ;
off . creature_current_job_id_offset = minfo - > getOffset ( " current_job_id " ) ;
off . creature_strength_offset = minfo - > getOffset ( " creature_strength " ) ;
off . creature_agility_offset = minfo - > getOffset ( " creature_agility " ) ;
off . creature_toughness_offset = minfo - > getOffset ( " creature_toughness " ) ;
off . creature_skills_offset = minfo - > getOffset ( " creature_skills " ) ;
off . creature_labors_offset = minfo - > getOffset ( " creature_labors " ) ;
off . creature_labors_offset = minfo - > getOffset ( " creature_labors " ) ;
off . creature_happiness_offset = minfo - > getOffset ( " creature_happiness " ) ;
off . creature_happiness_offset = minfo - > getOffset ( " creature_happiness " ) ;
off . creature_traits_offset = minfo - > getOffset ( " creature_traits " ) ;
off . creature_likes_offset = minfo - > getOffset ( " creature_likes " ) ;
off . creature_artifact_name_offset = minfo - > getOffset ( " creature_artifact_name " ) ;
off . creature_artifact_name_offset = minfo - > getOffset ( " creature_artifact_name " ) ;
off . creature_mood_offset = minfo - > getOffset ( " creature_mood " ) ;
off . creature_pregnancy_offset = minfo - > getOffset ( " creature_pregnancy " ) ;
off . creature_blood_max_offset = minfo - > getOffset ( " creature_blood_max " ) ;
off . creature_blood_current_offset = minfo - > getOffset ( " creature_blood_current " ) ;
off . creature_bleed_offset = minfo - > getOffset ( " creature_bleed " ) ;
// name offsets for the creature module
// name offsets for the creature module
off . name_firstname_offset = minfo - > getOffset ( " name_firstname " ) ;
off . name_firstname_offset = minfo - > getOffset ( " name_firstname " ) ;
off . name_nickname_offset = minfo - > getOffset ( " name_nickname " ) ;
off . name_nickname_offset = minfo - > getOffset ( " name_nickname " ) ;
off . name_words_offset = minfo - > getOffset ( " name_words " ) ;
off . name_words_offset = minfo - > getOffset ( " name_words " ) ;
// HACK: vector correction. No longer relevant.
off . vector_correct = 0 ;
d - > p_cre = new DfVector ( d - > p , off . creature_vector , 4 ) ;
d - > p_cre = new DfVector ( d - > p , off . creature_vector , 4 ) ;
d - > creaturesInited = true ;
d - > creaturesInited = true ;
numcreatures = d - > p_cre - > getSize ( ) ;
numcreatures = d - > p_cre - > getSize ( ) ;
// --> SHM initialization (if possible) <--
// --> SHM initialization (if possible) <--
g_pProcess - > getModuleIndex ( " Creatures 40d " , 1 , d - > creature_module ) ;
g_pProcess - > getModuleIndex ( " Creatures 2010 " , 1 , d - > creature_module ) ;
if ( d - > creature_module )
if ( d - > creature_module )
{
{
// supply the module with offsets so it can work with them
// supply the module with offsets so it can work with them
memcpy ( SHMDATA ( Creatures : : creature_offsets ) , & d - > creatures , sizeof ( Creatures : : creature_offsets ) ) ;
memcpy ( SHMDATA ( Creatures 2010 : : creature_offsets ) , & d - > creatures , sizeof ( Creatures 2010 : : creature_offsets ) ) ;
const uint32_t cmd = Creatures : : CREATURE_INIT + ( d - > creature_module < < 16 ) ;
const uint32_t cmd = Creatures 2010 : : CREATURE_INIT + ( d - > creature_module < < 16 ) ;
g_pProcess - > SetAndWait ( cmd ) ;
g_pProcess - > SetAndWait ( cmd ) ;
}
}
return true ;
return true ;
@ -106,7 +85,7 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
{
{
// supply the module with offsets so it can work with them
// supply the module with offsets so it can work with them
SHMCREATURESHDR - > index = index ;
SHMCREATURESHDR - > index = index ;
const uint32_t cmd = Creatures : : CREATURE_AT_INDEX + ( d - > creature_module < < 16 ) ;
const uint32_t cmd = Creatures 2010 : : CREATURE_AT_INDEX + ( d - > creature_module < < 16 ) ;
g_pProcess - > SetAndWait ( cmd ) ;
g_pProcess - > SetAndWait ( cmd ) ;
memcpy ( & furball , SHMDATA ( t_creature ) , sizeof ( t_creature ) ) ;
memcpy ( & furball , SHMDATA ( t_creature ) , sizeof ( t_creature ) ) ;
// cerr << "creature read from SHM!" << endl;
// cerr << "creature read from SHM!" << endl;
@ -115,24 +94,25 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
// read pointer from vector at position
// read pointer from vector at position
uint32_t temp = * ( uint32_t * ) d - > p_cre - > at ( index ) ;
uint32_t temp = * ( uint32_t * ) d - > p_cre - > at ( index ) ;
furball . origin = temp ;
furball . origin = temp ;
Creatures : : creature_offsets & offs = d - > creatures ;
Creatures 2010 : : creature_offsets & offs = d - > creatures ;
//read creature from memory
//read creature from memory
g_pProcess - > read ( temp + offs . creature_pos_offset , 3 * sizeof ( uint16_t ) , ( uint8_t * ) & ( furball . x ) ) ; // xyz really
g_pProcess - > read ( temp + offs . creature_pos_offset , 3 * sizeof ( uint16_t ) , ( uint8_t * ) & ( furball . x ) ) ; // xyz really
g_pProcess - > readDWord ( temp + offs . creature_ typ e_offset, furball . type ) ;
g_pProcess - > readDWord ( temp + offs . creature_ rac e_offset, furball . type ) ;
g_pProcess - > readDWord ( temp + offs . creature_flags1_offset , furball . flags1 . whole ) ;
g_pProcess - > readDWord ( temp + offs . creature_flags1_offset , furball . flags1 . whole ) ;
g_pProcess - > readDWord ( temp + offs . creature_flags2_offset , furball . flags2 . whole ) ;
g_pProcess - > readDWord ( temp + offs . creature_flags2_offset , furball . flags2 . whole ) ;
// names
// names
d - > readName ( furball . name , temp + offs . creature_name_offset ) ;
d - > readName ( furball . name , temp + offs . creature_name_offset ) ;
d - > readName ( furball . squad_name , temp + offs . creature_squad_name_offset ) ;
//d->readName(furball.squad_name, temp + offs.creature_squad_name_offset);
d - > readName ( furball . artifact_name , temp + offs . creature_artifact_name_offset ) ;
d - > readName ( furball . artifact_name , temp + offs . creature_artifact_name_offset ) ;
// custom profession
// custom profession
fill_char_buf ( furball . custom_profession , d - > p - > readSTLString ( temp + offs . creature_custom_profession_offset ) ) ;
//fill_char_buf (furball.custom_profession, d->p->readSTLString (temp + offs.creature_custom_profession_offset));
// labors
// labors
g_pProcess - > read ( temp + offs . creature_labors_offset , NUM_CREATURE_LABORS , furball . labors ) ;
g_pProcess - > read ( temp + offs . creature_labors_offset , NUM_CREATURE_LABORS , furball . labors ) ;
// traits
// traits
g_pProcess - > read ( temp + offs . creature_traits_offset , sizeof ( uint16_t ) * NUM_CREATURE_TRAITS , ( uint8_t * ) & furball . traits ) ;
//g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
// learned skills
// learned skills
/*
DfVector skills ( d - > p , temp + offs . creature_skills_offset , 4 ) ;
DfVector skills ( d - > p , temp + offs . creature_skills_offset , 4 ) ;
furball . numSkills = skills . getSize ( ) ;
furball . numSkills = skills . getSize ( ) ;
for ( uint32_t i = 0 ; i < furball . numSkills ; i + + )
for ( uint32_t i = 0 ; i < furball . numSkills ; i + + )
@ -144,9 +124,11 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
furball . skills [ i ] . rating = g_pProcess - > readByte ( temp2 + 4 ) ;
furball . skills [ i ] . rating = g_pProcess - > readByte ( temp2 + 4 ) ;
furball . skills [ i ] . experience = g_pProcess - > readWord ( temp2 + 8 ) ;
furball . skills [ i ] . experience = g_pProcess - > readWord ( temp2 + 8 ) ;
}
}
*/
// profession
// profession
furball . profession = g_pProcess - > readByte ( temp + offs . creature_profession_offset ) ;
furball . profession = g_pProcess - > readByte ( temp + offs . creature_profession_offset ) ;
// current job HACK: the job object isn't cleanly represented here
// current job HACK: the job object isn't cleanly represented here
/*
uint32_t jobIdAddr = g_pProcess - > readDWord ( temp + offs . creature_current_job_offset ) ;
uint32_t jobIdAddr = g_pProcess - > readDWord ( temp + offs . creature_current_job_offset ) ;
if ( jobIdAddr )
if ( jobIdAddr )
@ -158,8 +140,9 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
{
{
furball . current_job . active = false ;
furball . current_job . active = false ;
}
}
*/
//likes
//likes
/*
DfVector likes ( d - > p , temp + offs . creature_likes_offset , 4 ) ;
DfVector likes ( d - > p , temp + offs . creature_likes_offset , 4 ) ;
furball . numLikes = likes . getSize ( ) ;
furball . numLikes = likes . getSize ( ) ;
for ( uint32_t i = 0 ; i < furball . numLikes ; i + + )
for ( uint32_t i = 0 ; i < furball . numLikes ; i + + )
@ -169,38 +152,50 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
}
}
furball . mood = ( int16_t ) g_pProcess - > readWord ( temp + offs . creature_mood_offset ) ;
furball . mood = ( int16_t ) g_pProcess - > readWord ( temp + offs . creature_mood_offset ) ;
*/
g_pProcess - > readDWord ( temp + offs . creature_happiness_offset , furball . happiness ) ;
g_pProcess - > readDWord ( temp + offs . creature_happiness_offset , furball . happiness ) ;
g_pProcess - > readDWord ( temp + offs . creature_id_offset , furball . id ) ;
g_pProcess - > readDWord ( temp + offs . creature_id_offset , furball . id ) ;
/*
g_pProcess - > readDWord ( temp + offs . creature_agility_offset , furball . agility ) ;
g_pProcess - > readDWord ( temp + offs . creature_agility_offset , furball . agility ) ;
g_pProcess - > readDWord ( temp + offs . creature_strength_offset , furball . strength ) ;
g_pProcess - > readDWord ( temp + offs . creature_strength_offset , furball . strength ) ;
g_pProcess - > readDWord ( temp + offs . creature_toughness_offset , furball . toughness ) ;
g_pProcess - > readDWord ( temp + offs . creature_toughness_offset , furball . toughness ) ;
g_pProcess - > readDWord ( temp + offs . creature_money_offset , furball . money ) ;
g_pProcess - > readDWord ( temp + offs . creature_money_offset , furball . money ) ;
furball . squad_leader_id = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_squad_leader_id_offset ) ;
furball . squad_leader_id = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_squad_leader_id_offset ) ;
*/
g_pProcess - > readByte ( temp + offs . creature_sex_offset , furball . sex ) ;
g_pProcess - > readByte ( temp + offs . creature_sex_offset , furball . sex ) ;
/*
g_pProcess - > readDWord ( temp + offs . creature_pregnancy_offset , furball . pregnancy_timer ) ;
g_pProcess - > readDWord ( temp + offs . creature_pregnancy_offset , furball . pregnancy_timer ) ;
furball . blood_max = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_blood_max_offset ) ;
furball . blood_max = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_blood_max_offset ) ;
furball . blood_current = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_blood_current_offset ) ;
furball . blood_current = ( int32_t ) g_pProcess - > readDWord ( temp + offs . creature_blood_current_offset ) ;
g_pProcess - > readDWord ( temp + offs . creature_bleed_offset , furball . bleed_rate ) ;
g_pProcess - > readDWord ( temp + offs . creature_bleed_offset , furball . bleed_rate ) ;
*/
return true ;
return true ;
}
}
/*
bool API : : WriteLabors ( const uint32_t index , uint8_t labors [ NUM_CREATURE_LABORS ] )
bool API : : WriteLabors ( const uint32_t index , uint8_t labors [ NUM_CREATURE_LABORS ] )
{
{
if ( ! d - > creaturesInited ) return false ;
if ( ! d - > creaturesInited ) return false ;
uint32_t temp = * ( uint32_t * ) d - > p_cre - > at ( index ) ;
uint32_t temp = * ( uint32_t * ) d - > p_cre - > at ( index ) ;
WriteRaw ( temp + d - > creatures . creature_labors_offset , NUM_CREATURE_LABORS , labors ) ;
WriteRaw ( temp + d - > creatures . creature_labors_offset , NUM_CREATURE_LABORS , labors ) ;
}
}
*/
/*
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 ) ;
return true ;
return true ;
}
}
*/
*/
void API : : FinishReadCreatures ( )
{
if ( d - > p_cre )
{
delete d - > p_cre ;
d - > p_cre = 0 ;
}
d - > creaturesInited = false ;
//FinishReadNameTables();
}