2009-10-23 04:54:24 -06:00
// Creature dump
# include <iostream>
2009-10-23 10:50:36 -06:00
# include <climits>
2009-10-23 04:54:24 -06:00
# include <integers.h>
# include <vector>
using namespace std ;
# include <DFTypes.h>
# include <DFHackAPI.h>
2009-11-13 20:46:56 -07:00
# include <DFMemInfo.h>
2009-10-23 04:54:24 -06:00
2009-10-23 10:50:36 -06:00
template < typename T >
void print_bits ( T val , std : : ostream & out )
{
T n_bits = sizeof ( val ) * CHAR_BIT ;
for ( unsigned i = 0 ; i < n_bits ; + + i ) {
out < < ! ! ( val & 1 ) < < " " ;
val > > = 1 ;
}
}
2009-12-31 19:14:41 -07:00
struct matGlosses
{
vector < DFHack : : t_matglossPlant > plantMat ;
vector < DFHack : : t_matgloss > woodMat ;
vector < DFHack : : t_matgloss > stoneMat ;
vector < DFHack : : t_matgloss > metalMat ;
vector < DFHack : : t_matgloss > creatureMat ;
} ;
enum likeType
{
FAIL = 0 ,
MATERIAL = 1 ,
ITEM = 2 ,
FOOD = 3
} ;
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,
//you can easily find good canidates for military duty for instance
//The ideal thing to do would be to call the df function directly with the desired likes, the df function modifies a string, so it should be possible to do...
if ( like . active ) {
if ( like . type = = 0 ) {
switch ( like . material . type )
{
case 0 :
cout < < mat . woodMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
case 1 :
cout < < mat . stoneMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
case 2 :
cout < < mat . metalMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
case 12 : // don't ask me why this has such a large jump, maybe this is not actually the matType for plants, but they all have this set to 12
cout < < mat . plantMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
case 32 :
cout < < mat . plantMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
case 121 :
cout < < mat . creatureMat [ like . material . index ] . name ;
return ( MATERIAL ) ;
default :
return ( FAIL ) ;
}
}
else if ( like . type = = 4 & & like . itemIndex ! = - 1 ) {
switch ( like . itemClass )
{
case 24 :
cout < < itemTypes [ 0 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 25 :
cout < < itemTypes [ 4 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 26 :
cout < < itemTypes [ 8 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 27 :
cout < < itemTypes [ 9 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 28 :
cout < < itemTypes [ 10 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 29 :
cout < < itemTypes [ 7 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 38 :
cout < < itemTypes [ 5 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 63 :
cout < < itemTypes [ 11 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 68 :
case 69 :
cout < < itemTypes [ 6 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
case 70 :
cout < < itemTypes [ 1 ] [ like . itemIndex ] . name ;
return ( ITEM ) ;
default :
// cout << like.itemClass << ":" << like.itemIndex;
return ( FAIL ) ;
}
}
else if ( like . material . type ! = - 1 ) { // && like.material.index == -1){
if ( like . type = = 2 ) {
switch ( like . itemClass )
{
case 52 :
case 53 :
case 58 :
cout < < mat . plantMat [ like . material . type ] . name ;
return ( FOOD ) ;
case 72 :
if ( like . material . type = ! 10 ) { // 10 is for milk stuff, which I don't know how to do
cout < < mat . plantMat [ like . material . index ] . extract_name ;
return ( FOOD ) ;
}
return ( FAIL ) ;
case 74 :
cout < < mat . plantMat [ like . material . index ] . drink_name ;
return ( FOOD ) ;
case 75 :
cout < < mat . plantMat [ like . material . index ] . food_name ;
return ( FOOD ) ;
case 47 :
case 48 :
cout < < mat . creatureMat [ like . material . type ] . name ;
return ( FOOD ) ;
default :
return ( FAIL ) ;
}
}
}
}
return ( FAIL ) ;
}
2009-10-23 10:50:36 -06:00
2009-10-23 04:54:24 -06:00
int main ( void )
{
2009-12-12 17:47:58 -07:00
vector < DFHack : : t_matgloss > creaturestypes ;
2009-12-31 19:14:41 -07:00
// t_matglossPlant test;
2009-11-10 20:37:28 -07:00
DFHack : : API DF ( " Memory.xml " ) ;
2009-10-23 04:54:24 -06:00
if ( ! DF . Attach ( ) )
{
cerr < < " DF not found " < < endl ;
return 1 ;
}
2009-12-31 19:14:41 -07:00
vector < string > buildingtypes ;
uint32_t numBuildings = DF . InitReadBuildings ( buildingtypes ) ;
//vector< vector <string> > all;
vector < vector < DFHack : : t_itemType > > itemTypes ;
DF . ReadItemTypes ( itemTypes ) ;
//DF.ReadAllMatgloss(all);
matGlosses mat ;
DF . ReadPlantMatgloss ( mat . plantMat ) ;
DF . ReadWoodMatgloss ( mat . woodMat ) ;
DF . ReadStoneMatgloss ( mat . stoneMat ) ;
DF . ReadMetalMatgloss ( mat . metalMat ) ;
DF . ReadCreatureMatgloss ( mat . creatureMat ) ;
2009-11-13 20:46:56 -07:00
DFHack : : memory_info mem = DF . getMemoryInfo ( ) ;
2009-10-23 04:54:24 -06:00
// get stone matgloss mapping
if ( ! DF . ReadCreatureMatgloss ( creaturestypes ) )
{
cerr < < " Can't get the creature types. " < < endl ;
return 1 ;
}
2009-12-12 12:52:30 -07:00
map < string , vector < string > > names ;
DF . InitReadNameTables ( names ) ;
2009-10-23 04:54:24 -06:00
uint32_t numCreatures = DF . InitReadCreatures ( ) ;
for ( uint32_t i = 0 ; i < numCreatures ; i + + )
{
2009-12-31 19:14:41 -07:00
DF . Suspend ( ) ;
2009-12-12 17:47:58 -07:00
DFHack : : t_creature temp ;
2009-10-23 04:54:24 -06:00
DF . ReadCreature ( i , temp ) ;
2009-12-31 19:14:41 -07:00
DF . ForceResume ( ) ;
if ( string ( creaturestypes [ temp . type ] . id ) = = " DWARF " ) {
2009-12-12 12:52:30 -07:00
cout < < " address: " < < temp . origin < < " creature type: " < < creaturestypes [ temp . type ] . id < < " , position: " < < temp . x < < " x " < < temp . y < < " y " < < temp . z < < " z " < < endl ;
2009-11-05 18:04:17 -07:00
bool addendl = false ;
2009-11-13 06:35:44 -07:00
if ( temp . first_name [ 0 ] )
2009-11-05 18:04:17 -07:00
{
cout < < " first name: " < < temp . first_name ;
addendl = true ;
}
2009-11-13 06:35:44 -07:00
if ( temp . nick_name [ 0 ] )
2009-11-05 18:04:17 -07:00
{
cout < < " , nick name: " < < temp . nick_name ;
addendl = true ;
}
2009-12-12 12:52:30 -07:00
string transName = DF . TranslateName ( temp . last_name , names , creaturestypes [ temp . type ] . id ) ;
if ( ! transName . empty ( ) ) {
cout < < " , trans name: " < < transName ;
addendl = true ;
}
//cout << ", generic name: " << DF.TranslateName(temp.last_name,names,"GENERIC");
2009-11-13 06:35:44 -07:00
/*
2009-11-07 14:05:10 -07:00
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 ;
}
2009-11-13 06:35:44 -07:00
*/
2009-12-31 19:14:41 -07:00
cout < < " , likes: " ;
for ( uint32_t i = 0 ; i < temp . numLikes ; i + + ) {
if ( printLike ( temp . likes [ i ] , mat , itemTypes ) )
cout < < " , " ;
}
2009-11-05 18:04:17 -07:00
if ( addendl )
{
cout < < endl ;
2009-11-07 14:05:10 -07:00
addendl = false ;
}
2009-11-13 20:46:56 -07:00
cout < < " profession: " < < mem . getProfession ( temp . profession ) < < " ( " < < ( int ) temp . profession < < " ) " ;
if ( temp . custom_profession [ 0 ] )
{
2009-11-07 14:05:10 -07:00
cout < < " , custom profession: " < < temp . custom_profession ;
2009-11-05 18:04:17 -07:00
}
2009-11-13 20:46:56 -07:00
if ( temp . current_job . active )
2009-11-07 14:05:10 -07:00
{
2009-11-13 20:46:56 -07:00
cout < < " , current job: " < < mem . getJob ( temp . current_job . jobId ) ;
2009-11-07 14:05:10 -07:00
}
2009-11-13 20:46:56 -07:00
cout < < endl ;
cout < < " happiness: " < < temp . happiness < < " , strength: " < < temp . strength < < " , agility: "
2009-11-09 16:18:20 -07:00
< < 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 ;
}
2009-11-13 20:46:56 -07:00
cout < < " , sex: " ;
2009-11-07 14:05:10 -07:00
if ( temp . sex = = 0 ) {
2009-11-13 20:46:56 -07:00
cout < < " Female " ;
2009-11-07 14:05:10 -07:00
}
else {
2009-11-13 20:46:56 -07:00
cout < < " Male " ;
2009-11-07 14:05:10 -07:00
}
cout < < endl ;
2009-11-13 06:35:44 -07:00
/*
2009-11-09 16:18:20 -07:00
//skills
for ( unsigned int i = 0 ; i < temp . skills . size ( ) ; i + + ) {
if ( i > 0 ) {
cout < < " , " ;
}
cout < < temp . skills [ i ] . name < < " : " < < temp . skills [ i ] . rating ;
}
2009-11-13 06:35:44 -07:00
*/
2009-10-23 20:32:57 -06:00
/*
* FLAGS 1
*/
2009-10-23 10:50:36 -06:00
cout < < " flags1: " ;
2009-10-23 20:32:57 -06:00
print_bits ( temp . flags1 . whole , cout ) ;
cout < < endl ;
if ( temp . flags1 . bits . dead )
{
cout < < " dead " ;
}
2009-10-29 08:06:05 -06:00
if ( temp . flags1 . bits . on_ground )
2009-10-23 20:32:57 -06:00
{
2009-10-29 08:06:05 -06:00
cout < < " on the ground, " ;
2009-10-23 20:32:57 -06:00
}
2009-10-29 08:06:05 -06:00
if ( temp . flags1 . bits . skeleton )
2009-10-23 20:32:57 -06:00
{
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
*/
2009-10-23 10:50:36 -06:00
cout < < endl < < " flags2: " ;
2009-10-23 20:32:57 -06:00
print_bits ( temp . flags2 . whole , cout ) ;
cout < < endl ;
2009-10-29 08:06:05 -06:00
if ( temp . flags2 . bits . killed )
2009-10-23 20:32:57 -06:00
{
2009-10-29 08:06:05 -06:00
cout < < " killed by kill function, " ;
2009-10-23 20:32:57 -06:00
}
2009-10-29 08:06:05 -06:00
if ( temp . flags2 . bits . resident )
2009-10-23 20:32:57 -06:00
{
2009-11-13 20:46:56 -07:00
cout < < " resident, " ;
2009-10-23 20:32:57 -06:00
}
2009-10-29 08:06:05 -06:00
if ( temp . flags2 . bits . gutted )
2009-10-23 20:32:57 -06:00
{
2009-11-13 20:46:56 -07:00
cout < < " gutted, " ;
2009-10-23 20:32:57 -06:00
}
if ( temp . flags2 . bits . slaughter )
{
2009-11-13 20:46:56 -07:00
cout < < " marked for slaughter, " ;
2009-10-23 20:32:57 -06:00
}
if ( temp . flags2 . bits . underworld )
{
2009-11-13 20:46:56 -07:00
cout < < " from the underworld, " ;
2009-10-23 20:32:57 -06:00
}
2009-10-23 10:50:36 -06:00
cout < < endl < < endl ;
2009-12-31 19:14:41 -07:00
}
}
2009-10-23 04:54:24 -06:00
DF . FinishReadCreatures ( ) ;
2009-10-31 12:09:13 -06:00
DF . Detach ( ) ;
2009-11-05 18:04:17 -07:00
# ifndef LINUX_BUILD
2009-10-30 03:01:14 -06:00
cout < < " Done. Press any key to continue " < < endl ;
cin . ignore ( ) ;
2009-11-05 18:04:17 -07:00
# endif
2009-10-23 04:54:24 -06:00
return 0 ;
2009-12-13 14:03:19 -07:00
}