2009-10-23 04:54:24 -06:00
// Creature dump
# include <iostream>
2009-10-23 10:50:36 -06:00
# include <climits>
2010-04-26 09:33:17 -06:00
# include <string.h>
2009-10-23 04:54:24 -06:00
# include <vector>
2010-06-04 16:02:02 -06:00
# include <stdio.h>
2009-10-23 04:54:24 -06:00
using namespace std ;
2010-06-04 16:02:02 -06:00
# define DFHACK_WANT_MISCUTILS
2010-05-25 22:48:23 -06:00
# include <DFHack.h>
2009-10-23 04:54:24 -06:00
2009-12-31 19:14:41 -07:00
enum likeType
{
FAIL = 0 ,
MATERIAL = 1 ,
ITEM = 2 ,
FOOD = 3
} ;
2010-03-12 07:21:45 -07:00
2010-04-28 10:09:32 -06:00
DFHack : : Materials * Materials ;
2010-08-20 06:10:05 -06:00
DFHack : : VersionInfo * mem ;
2010-03-13 07:09:14 -07:00
vector < vector < string > > englishWords ;
vector < vector < string > > foreignWords ;
2010-04-26 05:23:57 -06:00
DFHack : : Creatures * Creatures = NULL ;
2010-05-12 07:39:22 -06:00
uint32_t current_year ;
uint32_t current_tick ;
2010-04-04 04:29:56 -06:00
/*
likeType printLike40d ( DFHack : : t_like like , const matGlosses & mat , const vector < vector < DFHack : : t_itemType > > & itemTypes )
2009-12-31 19:14:41 -07:00
{ // 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 ) ;
}
2010-04-04 04:29:56 -06:00
*/
2009-10-23 10:50:36 -06:00
2010-05-23 15:06:10 -06:00
void printCreature ( DFHack : : Context * DF , const DFHack : : t_creature & creature )
2010-03-12 07:21:45 -07:00
{
2010-05-12 07:39:22 -06:00
uint32_t dayoflife ;
2010-04-28 10:09:32 -06:00
cout < < " address: " < < hex < < creature . origin < < dec < < " creature type: " < < Materials - > raceEx [ creature . race ] . rawname
< < " [ " < < Materials - > raceEx [ creature . race ] . tile_character
< < " , " < < Materials - > raceEx [ creature . race ] . tilecolor . fore
< < " , " < < Materials - > raceEx [ creature . race ] . tilecolor . back
< < " , " < < Materials - > raceEx [ creature . race ] . tilecolor . bright
2010-04-19 03:23:11 -06:00
< < " ] "
< < " , position: " < < creature . x < < " x " < < creature . y < < " y " < < creature . z < < " z " < < endl ;
2010-03-12 07:21:45 -07:00
bool addendl = false ;
2010-03-13 07:09:14 -07:00
if ( creature . name . first_name [ 0 ] )
2010-03-12 07:21:45 -07:00
{
2010-03-13 07:09:14 -07:00
cout < < " first name: " < < creature . name . first_name ;
2010-03-12 07:21:45 -07:00
addendl = true ;
}
2010-03-13 07:09:14 -07:00
if ( creature . name . nickname [ 0 ] )
2010-03-12 07:21:45 -07:00
{
2010-03-13 07:09:14 -07:00
cout < < " , nick name: " < < creature . name . nickname ;
2010-03-12 07:21:45 -07:00
addendl = true ;
}
2010-04-06 17:17:03 -06:00
2010-05-23 15:06:10 -06:00
DFHack : : Translation * Tran = DF - > getTranslation ( ) ;
2010-08-20 06:10:05 -06:00
DFHack : : VersionInfo * mem = DF - > getMemoryInfo ( ) ;
2010-04-06 17:17:03 -06:00
string transName = Tran - > TranslateName ( creature . name , false ) ;
2010-03-12 07:21:45 -07:00
if ( ! transName . empty ( ) )
{
cout < < " , trans name: " < < transName ;
addendl = true ;
}
2010-04-13 15:21:31 -06:00
transName = Tran - > TranslateName ( creature . name , true ) ;
if ( ! transName . empty ( ) )
{
cout < < " , last name: " < < transName ;
addendl = true ;
}
2010-06-23 16:34:35 -06:00
if ( creature . civ )
{
cout < < " civilization: " < < creature . civ ;
addendl = true ;
}
2010-04-06 17:17:03 -06:00
2010-04-04 04:29:56 -06:00
/*
2010-03-12 07:21:45 -07:00
cout < < " , likes: " ;
for ( uint32_t i = 0 ; i < creature . numLikes ; i + + )
{
if ( printLike ( creature . likes [ i ] , mat , itemTypes ) )
{
cout < < " , " ;
}
2010-04-04 04:29:56 -06:00
}
*/
2010-03-12 07:21:45 -07:00
if ( addendl )
{
cout < < endl ;
addendl = false ;
}
2010-04-04 04:43:11 -06:00
cout < < " profession: " < < mem - > getProfession ( creature . profession ) < < " ( " < < ( int ) creature . profession < < " ) " ;
2010-04-06 17:17:03 -06:00
2010-03-12 07:21:45 -07:00
if ( creature . custom_profession [ 0 ] )
{
cout < < " , custom profession: " < < creature . custom_profession ;
}
2010-04-06 17:17:03 -06:00
/*
2010-03-12 07:21:45 -07:00
if ( creature . current_job . active )
{
cout < < " , current job: " < < mem - > getJob ( creature . current_job . jobId ) ;
}
2010-04-04 04:29:56 -06:00
*/
2010-03-12 07:21:45 -07:00
cout < < endl ;
2010-05-12 07:39:22 -06:00
dayoflife = creature . birth_year * 12 * 28 + creature . birth_time / 1200 ;
cout < < " Born on the year " < < creature . birth_year < < " , month " < < ( creature . birth_time / 1200 / 28 ) < < " , day " < < ( ( creature . birth_time / 1200 ) % 28 + 1 ) < < " , " < < dayoflife < < " days lived. " < < endl ;
2010-05-05 06:08:18 -06:00
cout < < " Appearance : " ;
for ( unsigned int i = 0 ; i < creature . nbcolors ; i + + )
{
cout < < Materials - > raceEx [ creature . race ] . castes [ creature . caste ] . ColorModifier [ i ] . part < < " " ;
uint32_t color = Materials - > raceEx [ creature . race ] . castes [ creature . caste ] . ColorModifier [ i ] . colorlist [ creature . color [ i ] ] ;
if ( color < Materials - > color . size ( ) )
cout < < Materials - > color [ color ] . name < < " [ "
< < ( unsigned int ) ( Materials - > color [ color ] . r * 255 ) < < " : "
< < ( unsigned int ) ( Materials - > color [ color ] . v * 255 ) < < " : "
< < ( unsigned int ) ( Materials - > color [ color ] . b * 255 ) < < " ] " ;
else
cout < < Materials - > alldesc [ color ] . id ;
2010-05-12 07:39:22 -06:00
if ( Materials - > raceEx [ creature . race ] . castes [ creature . caste ] . ColorModifier [ i ] . startdate > 0 )
{
if ( ( Materials - > raceEx [ creature . race ] . castes [ creature . caste ] . ColorModifier [ i ] . startdate < = dayoflife ) & &
( Materials - > raceEx [ creature . race ] . castes [ creature . caste ] . ColorModifier [ i ] . enddate > dayoflife ) )
cout < < " [active] " ;
else
cout < < " [inactive] " ;
}
2010-05-05 06:08:18 -06:00
cout < < " - " ;
}
cout < < endl ;
2010-04-08 18:14:47 -06:00
cout < < " happiness: " < < creature . happiness
< < " , strength: " < < creature . strength . level
< < " , agility: " < < creature . agility . level
< < " , toughness: " < < creature . toughness . level
< < " , endurance: " < < creature . endurance . level
< < " , recuperation: " < < creature . recuperation . level
< < " , disease resistance: " < < creature . disease_resistance . level
//<< ", money: " << creature.money
< < " , id: " < < creature . id ;
2010-04-04 04:29:56 -06:00
/*
2010-03-12 07:21:45 -07:00
if ( creature . squad_leader_id ! = - 1 )
{
cout < < " , squad_leader_id: " < < creature . squad_leader_id ;
}
2010-03-14 11:21:26 -06:00
if ( creature . mood ! = - 1 ) {
cout < < " , mood: " < < creature . mood < < " " ;
2010-04-04 04:29:56 -06:00
} */
2010-03-12 07:21:45 -07:00
cout < < " , sex: " ;
if ( creature . sex = = 0 )
{
cout < < " Female " ;
}
else
{
cout < < " Male " ;
}
cout < < endl ;
2010-04-26 05:23:57 -06:00
2010-04-28 10:09:32 -06:00
if ( ( creature . mood ! = - 1 ) & & ( creature . mood < 5 ) )
2010-04-27 12:18:46 -06:00
{
cout < < " mood: " < < creature . mood < < " , skill: " < < mem - > getSkill ( creature . mood_skill ) < < endl ;
vector < DFHack : : t_material > mymat ;
if ( Creatures - > ReadJob ( & creature , mymat ) )
{
for ( unsigned int i = 0 ; i < mymat . size ( ) ; i + + )
{
2010-05-02 02:35:23 -06:00
printf ( " \t %s(%d) \t %d %d %d - %.8x \n " , Materials - > getDescription ( mymat [ i ] ) . c_str ( ) , mymat [ i ] . itemType , mymat [ i ] . subType , mymat [ i ] . subIndex , mymat [ i ] . index , mymat [ i ] . flags ) ;
2010-04-27 12:18:46 -06:00
}
}
}
2010-04-26 05:23:57 -06:00
2010-08-30 22:52:03 -06:00
//std::vector<uint32_t> inventory;
// FIXME: TOO BAD...
/*
2010-08-28 14:47:38 -06:00
if ( Creatures - > ReadInventoryPtr ( creature . origin , inventory ) )
{
DFHack : : Items * Items = DF - > getItems ( ) ;
printf ( " \t Inventory: \n " ) ;
for ( unsigned int i = 0 ; i < inventory . size ( ) ; i + + )
{
printf ( " \t \t %s \n " , Items - > getItemDescription ( inventory [ i ] , Materials ) . c_str ( ) ) ;
}
}
2010-08-30 22:52:03 -06:00
*/
2010-08-17 07:21:54 -06:00
2010-04-04 04:29:56 -06:00
/*
2010-03-26 06:01:46 -06:00
if ( creature . pregnancy_timer > 0 )
cout < < " gives birth in " < < creature . pregnancy_timer / 1200 < < " days. " ;
cout < < " Blood: " < < creature . blood_current < < " / " < < creature . blood_max < < " bleeding: " < < creature . bleed_rate ;
2010-04-04 04:29:56 -06:00
*/
2010-03-26 06:01:46 -06:00
cout < < endl ;
2010-03-21 14:47:24 -06:00
2010-04-12 19:11:26 -06:00
if ( creature . has_default_soul )
2010-04-06 18:46:46 -06:00
{
2010-04-12 19:11:26 -06:00
//skills
cout < < " Skills " < < endl ;
for ( unsigned int i = 0 ; i < creature . defaultSoul . numSkills ; i + + )
2010-04-06 18:46:46 -06:00
{
2010-04-12 19:11:26 -06:00
if ( i > 0 )
{
cout < < " , " ;
}
cout < < mem - > getSkill ( creature . defaultSoul . skills [ i ] . id ) < < " : " < < creature . defaultSoul . skills [ i ] . rating ;
2010-03-12 07:21:45 -07:00
}
2010-04-12 19:11:26 -06:00
cout < < endl ;
cout < < " Traits " < < endl ;
for ( uint32_t i = 0 ; i < 30 ; i + + )
2010-04-06 19:38:22 -06:00
{
2010-04-12 19:11:26 -06:00
string trait = mem - > getTrait ( i , creature . defaultSoul . traits [ i ] ) ;
if ( ! trait . empty ( ) ) cout < < trait < < " , " ;
2010-04-06 19:38:22 -06:00
}
2010-04-12 19:11:26 -06:00
cout < < endl ;
// labors
cout < < " Labors " < < endl ;
for ( unsigned int i = 0 ; i < NUM_CREATURE_LABORS ; i + + )
2010-04-06 19:38:22 -06:00
{
2010-04-12 19:11:26 -06:00
if ( ! creature . labors [ i ] )
continue ;
string laborname ;
try
{
laborname = mem - > getLabor ( i ) ;
}
catch ( exception & )
{
break ;
}
cout < < laborname < < " , " ;
2010-04-06 19:38:22 -06:00
}
2010-04-12 19:11:26 -06:00
cout < < endl ;
2010-04-11 16:48:25 -06:00
}
2010-03-12 07:21:45 -07:00
/*
* FLAGS 1
*/
cout < < " flags1: " ;
print_bits ( creature . flags1 . whole , cout ) ;
cout < < endl ;
if ( creature . flags1 . bits . dead )
{
cout < < " dead " ;
}
if ( creature . flags1 . bits . on_ground )
{
cout < < " on the ground, " ;
}
if ( creature . flags1 . bits . skeleton )
{
cout < < " skeletal " ;
}
if ( creature . flags1 . bits . zombie )
{
cout < < " zombie " ;
}
if ( creature . flags1 . bits . tame )
{
cout < < " tame " ;
}
if ( creature . flags1 . bits . royal_guard )
{
cout < < " royal_guard " ;
}
if ( creature . flags1 . bits . fortress_guard )
{
cout < < " fortress_guard " ;
}
/*
* FLAGS 2
*/
cout < < endl < < " flags2: " ;
print_bits ( creature . flags2 . whole , cout ) ;
cout < < endl ;
if ( creature . flags2 . bits . killed )
{
cout < < " killed by kill function, " ;
}
if ( creature . flags2 . bits . resident )
{
cout < < " resident, " ;
}
if ( creature . flags2 . bits . gutted )
{
cout < < " gutted, " ;
}
if ( creature . flags2 . bits . slaughter )
{
cout < < " marked for slaughter, " ;
}
if ( creature . flags2 . bits . underworld )
{
cout < < " from the underworld, " ;
}
2010-03-14 11:21:26 -06:00
cout < < endl ;
2010-04-12 23:36:16 -06:00
2010-04-04 04:29:56 -06:00
if ( creature . flags1 . bits . had_mood & & ( creature . mood = = - 1 | | creature . mood = = 8 ) )
{
2010-04-12 23:36:16 -06:00
string artifact_name = Tran - > TranslateName ( creature . artifact_name , false ) ;
2010-03-14 11:21:26 -06:00
cout < < " artifact: " < < artifact_name < < endl ;
2010-04-12 23:36:16 -06:00
}
2010-05-05 06:08:18 -06:00
2010-03-14 11:21:26 -06:00
cout < < endl ;
2010-03-12 07:21:45 -07:00
}
2010-04-15 05:04:58 -06:00
int main ( int numargs , char * * args )
2009-10-23 04:54:24 -06:00
{
2010-05-12 07:39:22 -06:00
DFHack : : World * World ;
2010-05-23 15:06:10 -06:00
DFHack : : ContextManager DFMgr ( " Memory.xml " ) ;
DFHack : : Context * DF ;
2010-03-26 06:01:46 -06:00
try
{
2010-05-23 15:06:10 -06:00
DF = DFMgr . getSingleContext ( ) ;
DF - > Attach ( ) ;
2010-03-26 06:01:46 -06:00
}
catch ( exception & e )
2009-10-23 04:54:24 -06:00
{
2010-03-26 06:01:46 -06:00
cerr < < e . what ( ) < < endl ;
# ifndef LINUX_BUILD
cin . ignore ( ) ;
# endif
2009-10-23 04:54:24 -06:00
return 1 ;
}
2010-04-15 05:04:58 -06:00
string check = " " ;
if ( numargs = = 2 )
check = args [ 1 ] ;
2010-02-11 14:08:39 -07:00
2010-05-23 15:06:10 -06:00
Creatures = DF - > getCreatures ( ) ;
Materials = DF - > getMaterials ( ) ;
World = DF - > getWorld ( ) ;
2010-05-12 07:39:22 -06:00
current_year = World - > ReadCurrentYear ( ) ;
current_tick = World - > ReadCurrentTick ( ) ;
2010-05-23 15:06:10 -06:00
DFHack : : Translation * Tran = DF - > getTranslation ( ) ;
2010-04-04 16:48:19 -06:00
2010-03-26 06:38:49 -06:00
uint32_t numCreatures ;
2010-04-04 16:48:19 -06:00
if ( ! Creatures - > Start ( numCreatures ) )
2010-03-26 06:38:49 -06:00
{
cerr < < " Can't get creatures " < < endl ;
# ifndef LINUX_BUILD
cin . ignore ( ) ;
# endif
return 1 ;
}
if ( ! numCreatures )
{
cerr < < " No creatures to print " < < endl ;
# ifndef LINUX_BUILD
cin . ignore ( ) ;
# endif
return 1 ;
}
2010-04-12 21:46:26 -06:00
2010-05-23 15:06:10 -06:00
mem = DF - > getMemoryInfo ( ) ;
2010-09-02 19:01:37 -06:00
Materials - > ReadInorganicMaterials ( ) ;
Materials - > ReadOrganicMaterials ( ) ;
Materials - > ReadWoodMaterials ( ) ;
Materials - > ReadPlantMaterials ( ) ;
Materials - > ReadCreatureTypes ( ) ;
Materials - > ReadCreatureTypesEx ( ) ;
Materials - > ReadDescriptorColors ( ) ;
2010-04-06 17:17:03 -06:00
if ( ! Tran - > Start ( ) )
2010-02-11 14:08:39 -07:00
{
cerr < < " Can't get name tables " < < endl ;
return 1 ;
}
2010-04-12 19:11:26 -06:00
vector < uint32_t > addrs ;
2010-04-04 04:29:56 -06:00
//DF.InitViewAndCursor();
2009-10-23 04:54:24 -06:00
for ( uint32_t i = 0 ; i < numCreatures ; i + + )
{
2010-08-17 07:21:54 -06:00
printf ( " %d/%d \n " , i , numCreatures ) ;
2009-12-12 17:47:58 -07:00
DFHack : : t_creature temp ;
2010-04-04 16:48:19 -06:00
Creatures - > ReadCreature ( i , temp ) ;
2010-04-28 10:09:32 -06:00
if ( check . empty ( ) | | string ( Materials - > raceEx [ temp . race ] . rawname ) = = check )
2010-03-29 18:26:52 -06:00
{
cout < < " index " < < i < < " " ;
2010-04-12 19:11:26 -06:00
2010-03-29 18:26:52 -06:00
printCreature ( DF , temp ) ;
2010-04-12 19:11:26 -06:00
addrs . push_back ( temp . origin ) ;
2010-03-29 18:26:52 -06:00
}
2010-08-17 07:21:54 -06:00
printf ( " ! \n " ) ;
2009-12-31 19:30:35 -07:00
}
2010-04-27 12:18:46 -06:00
if ( addrs . size ( ) < = 10 )
{
interleave_hex ( DF , addrs , 200 ) ;
}
2010-04-04 04:29:56 -06:00
/*
2010-03-12 07:21:45 -07:00
uint32_t currentIdx ;
DFHack : : t_creature currentCreature ;
DF . getCurrentCursorCreature ( currentIdx ) ;
2010-03-14 11:21:26 -06:00
cout < < " current creature at index " < < currentIdx < < endl ;
2010-03-12 07:21:45 -07:00
DF . ReadCreature ( currentIdx , currentCreature ) ;
printCreature ( DF , currentCreature ) ;
2010-04-04 04:29:56 -06:00
*/
2010-08-17 07:21:54 -06:00
2010-04-04 16:48:19 -06:00
Creatures - > Finish ( ) ;
2010-05-23 15:06:10 -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
}