@ -36,6 +36,13 @@ enum likeType
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,
//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,86 +148,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 ;
DFHack : : API DF ( " Memory.xml " ) ;
if ( ! DF . Attach ( ) )
{
cerr < < " DF not found " < < 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 ) )
if ( string ( creaturestypes [ creature . type ] . id ) = = " DWARF " )
{
cerr < < " Can't get the creature types. " < < endl ;
return 1 ;
}
vector < vector < string > > englishWords ;
vector < vector < string > > foreignWords ;
if ( ! DF . InitReadNameTables ( englishWords , foreignWords ) )
{
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 ;
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 ( temp . name . first_name [ 0 ] )
if ( creature . name . first_name [ 0 ] )
{
cout < < " first name: " < < temp . name . first_name ;
cout < < " first name: " < < creature . name . first_name ;
addendl = true ;
}
if ( temp . name . nickname [ 0 ] )
if ( creature . name . nickname [ 0 ] )
{
cout < < " , nick name: " < < temp . name . nickname ;
cout < < " , nick name: " < < creature . name . nickname ;
addendl = true ;
}
string transName = DF . TranslateName ( temp . name , englishWords , foreignWords , false ) ;
string transName = DF . TranslateName ( creature . name , englishWords , foreignWords , false ) ;
if ( ! transName . empty ( ) )
{
cout < < " , trans name: " < < transName ;
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 ( ) ) {
cout < < " , trans name: " < < temp . trans_name ;
if ( ! creature . trans_name . empty ( ) ) {
cout < < " , trans name: " < < creature . trans_name ;
addendl = true ;
}
if ( ! temp . generic_name . empty ( ) ) {
cout < < " , generic name: " < < temp . generic_name ;
if ( ! crea tur e. generic_name . empty ( ) ) {
cout < < " , generic name: " < < crea tur e. generic_name ;
addendl = true ;
}
*/
cout < < " , likes: " ;
for ( uint32_t i = 0 ; i < temp . numLikes ; i + + )
for ( uint32_t i = 0 ; i < crea tur e. numLikes ; i + + )
{
if ( printLike ( temp . likes [ i ] , mat , itemTypes ) )
if ( printLike ( crea tur e. likes [ i ] , mat , itemTypes ) )
{
cout < < " , " ;
}
@ -230,24 +194,27 @@ int main (void)
cout < < endl ;
addendl = false ;
}
cout < < " profession: " < < mem - > getProfession ( temp . profession ) < < " ( " < < ( int ) temp . profession < < " ) " ;
if ( temp . custom_profession [ 0 ] )
cout < < " profession: " < < mem - > getProfession ( crea tur e. profession ) < < " ( " < < ( int ) crea tur e. profession < < " ) " ;
if ( crea tur e. custom_profession [ 0 ] )
{
cout < < " , custom profession: " < < temp . custom_profession ;
cout < < " , custom profession: " < < crea tur e. custom_profession ;
}
if ( temp . current_job . active )
if ( crea tur e. current_job . active )
{
cout < < " , current job: " < < mem - > getJob ( temp . current_job . jobId ) ;
cout < < " , current job: " < < mem - > getJob ( crea tur e. 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 < < " happiness: " < < crea tur e. happiness < < " , strength: " < < crea tur e. strength < < " , agility: "
< < crea tur e. agility < < " , toughness: " < < crea tur e. toughness < < " , money: " < < crea tur e. money < < " , id: " < < crea tur e. id ;
if ( crea tur e. squad_leader_id ! = - 1 )
{
cout < < " , squad_leader_id: " < < temp . squad_leader_id ;
cout < < " , squad_leader_id: " < < creature . squad_leader_id ;
}
if ( creature . mood ! = - 1 ) {
cout < < " , mood: " < < creature . mood < < " " ;
}
cout < < " , sex: " ;
if ( temp . sex = = 0 )
if ( crea tur e. sex = = 0 )
{
cout < < " Female " ;
}
@ -258,44 +225,44 @@ int main (void)
cout < < endl ;
/*
//skills
for ( unsigned int i = 0 ; i < temp . skills . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < crea tur e. skills . size ( ) ; i + + ) {
if ( i > 0 ) {
cout < < " , " ;
}
cout < < temp . skills [ i ] . name < < " : " < < temp . skills [ i ] . rating ;
cout < < crea tur e. skills [ i ] . name < < " : " < < crea tur e. skills [ i ] . rating ;
}
*/
/*
* FLAGS 1
*/
cout < < " flags1: " ;
print_bits ( temp . flags1 . whole , cout ) ;
print_bits ( crea tur e. flags1 . whole , cout ) ;
cout < < endl ;
if ( temp . flags1 . bits . dead )
if ( crea tur e. flags1 . bits . dead )
{
cout < < " dead " ;
}
if ( temp . flags1 . bits . on_ground )
if ( crea tur e. flags1 . bits . on_ground )
{
cout < < " on the ground, " ;
}
if ( temp . flags1 . bits . skeleton )
if ( crea tur e. flags1 . bits . skeleton )
{
cout < < " skeletal " ;
}
if ( temp . flags1 . bits . zombie )
if ( crea tur e. flags1 . bits . zombie )
{
cout < < " zombie " ;
}
if ( temp . flags1 . bits . tame )
if ( crea tur e. flags1 . bits . tame )
{
cout < < " tame " ;
}
if ( temp . flags1 . bits . royal_guard )
if ( crea tur e. flags1 . bits . royal_guard )
{
cout < < " royal_guard " ;
}
if ( temp . flags1 . bits . fortress_guard )
if ( crea tur e. flags1 . bits . fortress_guard )
{
cout < < " fortress_guard " ;
}
@ -303,31 +270,91 @@ int main (void)
* FLAGS 2
*/
cout < < endl < < " flags2: " ;
print_bits ( temp . flags2 . whole , cout ) ;
print_bits ( crea tur e. flags2 . whole , cout ) ;
cout < < endl ;
if ( temp . flags2 . bits . killed )
if ( crea tur e. flags2 . bits . killed )
{
cout < < " killed by kill function, " ;
}
if ( temp . flags2 . bits . resident )
if ( crea tur e. flags2 . bits . resident )
{
cout < < " resident, " ;
}
if ( temp . flags2 . bits . gutted )
if ( crea tur e. flags2 . bits . gutted )
{
cout < < " gutted, " ;
}
if ( temp . flags2 . bits . slaughter )
if ( crea tur e. flags2 . bits . slaughter )
{
cout < < " marked for slaughter, " ;
}
if ( temp . flags2 . bits . underworld )
if ( crea tur e. flags2 . bits . underworld )
{
cout < < " from the underworld, " ;
}
cout < < endl < < endl ;
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 )
{
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 ( englishWords , foreignWords ) )
{
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 ) ;
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