Make the API a bit saner about the used data types and structures

develop
Petr Mrázek 2010-03-25 21:37:09 +01:00
parent 12ad14ada1
commit 822265443c
9 changed files with 163 additions and 109 deletions

@ -459,10 +459,10 @@ main(int argc, char *argv[])
TileMaterial tm = tileTypeTable[Block->tiletypes[x][y]].m; TileMaterial tm = tileTypeTable[Block->tiletypes[x][y]].m;
if( tc == WALL && tm == VEIN || tc == TREE_OK || tc == TREE_DEAD) if( tc == WALL && tm == VEIN || tc == TREE_OK || tc == TREE_DEAD)
{ {
Block->designaton[x][y].bits.dig = designation_default; Block->designation[x][y].bits.dig = designation_default;
} }
} }
DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) Block->designaton); DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation));
} }
// do a dump of the block data // do a dump of the block data
if(dump) if(dump)
@ -489,7 +489,7 @@ main(int argc, char *argv[])
{ {
int color = COLOR_BLACK; int color = COLOR_BLACK;
color = pickColor(Block->tiletypes[x][y]); color = pickColor(Block->tiletypes[x][y]);
if(!Block->designaton[x][y].bits.hidden) if(!Block->designation[x][y].bits.hidden)
/*{ /*{
puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color); puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color);
} }
@ -546,7 +546,7 @@ main(int argc, char *argv[])
{ {
if(tileTypeTable[blocks[1][1].tiletypes[k][j]].m != VEIN) if(tileTypeTable[blocks[1][1].tiletypes[k][j]].m != VEIN)
continue; continue;
if(blocks[1][1].designaton[k][j].bits.hidden) if(blocks[1][1].designation[k][j].bits.hidden)
continue; continue;
// and the bit array with a one-bit mask, check if the bit is set // and the bit array with a one-bit mask, check if the bit is set
bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k); bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k);

@ -107,18 +107,17 @@ IF(UNIX)
ENDIF(UNIX) ENDIF(UNIX)
# SWIG stuff # SWIG stuff
FIND_PACKAGE(SWIG) #FIND_PACKAGE(SWIG)
IF(SWIG_FOUND) #IF(SWIG_FOUND)
INCLUDE(${SWIG_USE_FILE}) #INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs) #FIND_PACKAGE(PythonLibs)
IF(PYTHONLIBS_FOUND) #IF(PYTHONLIBS_FOUND)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) #INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
SET(CMAKE_SWIG_FLAGS "-c++") #SET(CMAKE_SWIG_FLAGS "-c++")
SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES CPLUSPLUS ON) #SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES CPLUSPLUS ON)
# SET(CMAKE_DFHACK_SWIG_OUTDIR ${dfhack_SOURCE_DIR}/output CACHE PATH "Directory where Java wrapped libraries will be saved.") #SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES SWIG_FLAGS "-includeall")
# SET_SOURCE_FILES_PROPERTIES(pydfhack.i PROPERTIES SWIG_FLAGS "-includeall") #SWIG_ADD_MODULE(pydfhack python pydfhack.i)
SWIG_ADD_MODULE(pydfhack python pydfhack.i) #SWIG_LINK_LIBRARIES(pydfhack ${PYTHON_LIBRARIES} dfhack)
SWIG_LINK_LIBRARIES(pydfhack ${PYTHON_LIBRARIES} dfhack) #ENDIF(PYTHONLIBS_FOUND)
ENDIF(PYTHONLIBS_FOUND) #ENDIF(SWIG_FOUND)
ENDIF(SWIG_FOUND)

@ -348,7 +348,7 @@ bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
{ {
g_pProcess->read (addr + d->tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes); g_pProcess->read (addr + d->tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
g_pProcess->read (addr + d->occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy); g_pProcess->read (addr + d->occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy);
g_pProcess->read (addr + d->designation_offset, sizeof (buffer->designaton), (uint8_t *) buffer->designaton); g_pProcess->read (addr + d->designation_offset, sizeof (buffer->designation), (uint8_t *) buffer->designation);
g_pProcess->read (addr + d->biome_stuffs, sizeof (buffer->biome_indices), (uint8_t *) buffer->biome_indices); g_pProcess->read (addr + d->biome_stuffs, sizeof (buffer->biome_indices), (uint8_t *) buffer->biome_indices);
buffer->origin = addr; buffer->origin = addr;
uint32_t addr_of_struct = g_pProcess->readDWord(addr); uint32_t addr_of_struct = g_pProcess->readDWord(addr);
@ -361,7 +361,7 @@ bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer)
// 256 * sizeof(uint16_t) // 256 * sizeof(uint16_t)
bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer) bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -401,7 +401,7 @@ bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
// 256 * sizeof(uint32_t) // 256 * sizeof(uint32_t)
bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -414,7 +414,7 @@ bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer
// 256 * sizeof(uint32_t) // 256 * sizeof(uint32_t)
bool API::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) bool API::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -427,7 +427,7 @@ bool API::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
// 256 * sizeof(uint16_t) // 256 * sizeof(uint16_t)
bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer) bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -445,7 +445,7 @@ bool API::getCurrentCursorCreature(uint32_t & creature_index)
return true; return true;
} }
// 256 * sizeof(uint32_t) // 256 * sizeof(uint32_t)
bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -457,7 +457,7 @@ bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffe
} }
// 256 * sizeof(uint32_t) // 256 * sizeof(uint32_t)
bool API::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer) bool API::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
@ -471,12 +471,12 @@ bool API::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, uint32_t *buffer)
// FIXME: this is bad. determine the real size! // FIXME: this is bad. determine the real size!
//16 of them? IDK... there's probably just 7. Reading more doesn't cause errors as it's an array nested inside a block //16 of them? IDK... there's probably just 7. Reading more doesn't cause errors as it's an array nested inside a block
// 16 * sizeof(uint8_t) // 16 * sizeof(uint8_t)
bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, uint8_t *buffer) bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
{ {
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr) if (addr)
{ {
g_pProcess->read (addr + d->biome_stuffs, 16 * sizeof (uint8_t), buffer); g_pProcess->read (addr + d->biome_stuffs, 16 * sizeof (uint8_t), (uint8_t *) buffer);
return true; return true;
} }
return false; return false;

@ -46,32 +46,39 @@ namespace DFHack
public: public:
API(const std::string path_to_xml); API(const std::string path_to_xml);
~API(); ~API();
/*
* Basic control over DF's process state
*/
bool Attach(); bool Attach();
bool Detach(); bool Detach();
bool isAttached(); bool isAttached();
//true if paused, false if not /// stop DF from executing
bool ReadPauseState();
// read the DF menu view state (stock screen, unit screen, other screens
bool ReadViewScreen(t_viewscreen &);
// read the DF menu state (designation menu ect)
uint32_t ReadMenuState();
// stop DF from executing
bool Suspend(); bool Suspend();
// stop DF from executing, asynchronous, use with polling bool isSuspended();
/// stop DF from executing, asynchronous, use with polling
bool AsyncSuspend(); bool AsyncSuspend();
// resume DF
/// resume DF
bool Resume(); bool Resume();
/**
* Force resume /// forces resume on Windows. This can be a bad thing with multiple DF tools running!
* be careful with this one
*/
bool ForceResume(); bool ForceResume();
bool isSuspended();
/** /*
* Query the DF's GUI state
*/
///true if paused, false if not
bool ReadPauseState();
/// read the DF menu view state (stock screen, unit screen, other screens
bool ReadViewScreen(t_viewscreen &);
/// read the DF menu state (designation menu ect)
uint32_t ReadMenuState();
/*
* Matgloss. next four methods look very similar. I could use two and move the processing one level up... * Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later. * I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces * Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
@ -135,111 +142,148 @@ namespace DFHack
*/ */
uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz); uint32_t getBlockPtr (uint32_t blockx, uint32_t blocky, uint32_t blockz);
/// read the whole map block at block coords (see DFTypes.h for the block structure)
bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer); bool ReadBlock40d(uint32_t blockx, uint32_t blocky, uint32_t blockz, mapblock40d * buffer);
bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t) /// read/write block tile types
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t) bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, tiletypes40d *buffer);
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t) /// read/write block designations
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t) /// read/write block occupancies
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); // 256 * sizeof(uint32_t) bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
/// read/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit); bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit); bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);
/// read region offsets of a block /// read region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); // 16 * sizeof(uint8_t) bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, biome_indices40d *buffer);
/// read aggregated veins of a block /// read aggregated veins of a block
bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices); bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, std::vector <t_vein> & veins, std::vector <t_frozenliquidvein>& ices);
/** /*
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings * Constructions (costructed walls, floors, ramps, etc...)
*/ */
/// start reading constructions. numconstructions is an output - total constructions present
bool InitReadConstructions( uint32_t & numconstructions ); bool InitReadConstructions( uint32_t & numconstructions );
/// read a construiction at index
bool ReadConstruction(const int32_t index, t_construction & construction); bool ReadConstruction(const int32_t index, t_construction & construction);
/// cleanup after reading constructions
void FinishReadConstructions(); void FinishReadConstructions();
/*
* Buildings - also includes zones and stockpiles
*/
bool InitReadBuildings ( uint32_t & numbuildings ); bool InitReadBuildings ( uint32_t & numbuildings );
bool ReadBuilding(const int32_t index, t_building & building); bool ReadBuilding(const int32_t index, t_building & building);
void FinishReadBuildings(); void FinishReadBuildings();
/*
* Effects like mist, dragonfire or dust
*/
bool InitReadEffects ( uint32_t & numeffects ); bool InitReadEffects ( uint32_t & numeffects );
bool ReadEffect(const int32_t index, t_effect_df40d & effect); bool ReadEffect(const int32_t index, t_effect_df40d & effect);
bool WriteEffect(const int32_t index, const t_effect_df40d & effect); bool WriteEffect(const int32_t index, const t_effect_df40d & effect);
void FinishReadEffects(); void FinishReadEffects();
/*
* Trees and shrubs
*/
bool InitReadVegetation( uint32_t & numplants ); bool InitReadVegetation( uint32_t & numplants );
bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery); bool ReadVegetation(const int32_t index, t_tree_desc & shrubbery);
void FinishReadVegetation(); void FinishReadVegetation();
/*
* Creatures
*/
bool InitReadCreatures( uint32_t & numcreatures ); bool InitReadCreatures( uint32_t & numcreatures );
/// returns index of creature actually read or -1 if no creature can be found /**
* Read creatures in a box, starting with index. Returns -1 if no more creatures
* found. Call repeatedly do get all creatures in a specified box (uses tile coords)
*/
int32_t ReadCreatureInBox(const int32_t index, t_creature & furball, int32_t ReadCreatureInBox(const int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1, const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2); const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball); bool ReadCreature(const int32_t index, t_creature & furball);
void FinishReadCreatures(); void FinishReadCreatures();
/// read/write size bytes of raw data at offset. DANGEROUS, CAN SEGFAULT DF!
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target); void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source); void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
/// write labors of a creature (for Dwarf Therapist)
void WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
bool InitViewAndCursor(); /*
* Notes placed by the player
*/
/// start reading notes. numnotes is an output - total notes present
bool InitReadNotes( uint32_t & numnotes ); bool InitReadNotes( uint32_t & numnotes );
/// read note from the note vector at index
bool ReadNote(const int32_t index, t_note & note); bool ReadNote(const int32_t index, t_note & note);
/// free the note vector
void FinishReadNotes(); void FinishReadNotes();
/*
* Settlements
*/
bool InitReadSettlements( uint32_t & numsettlements ); bool InitReadSettlements( uint32_t & numsettlements );
bool ReadSettlement(const int32_t index, t_settlement & settlement); bool ReadSettlement(const int32_t index, t_settlement & settlement);
bool ReadCurrentSettlement(t_settlement & settlement); bool ReadCurrentSettlement(t_settlement & settlement);
void FinishReadSettlements(); void FinishReadSettlements();
/*
* Hotkeys (DF's zoom locations)
*/
bool InitReadHotkeys( ); bool InitReadHotkeys( );
bool ReadHotkeys(t_hotkey hotkeys[]); bool ReadHotkeys(t_hotkey hotkeys[]);
/*
* Cursor, and view coords
*/
bool InitViewAndCursor();
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z); bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
/// This returns false if there is nothing under the cursor, it puts the addresses in a vector if there is /// get the creature vector index of the creature currently under DF' cursor
bool getCurrentCursorCreature (uint32_t & creature_index); bool getCurrentCursorCreature (uint32_t & creature_index);
/*
* Window size in tiles
*/
bool InitViewSize(); bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height); bool getWindowSize(int32_t & width, int32_t & height);
/* unimplemented
bool setWindowSize(const int32_t & width, const int32_t & height);
*/
bool getItemIndexesInBox(std::vector<uint32_t> &indexes,
const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2);
/* /*
// FIXME: add a real creature class, move these * DF translation tables and name translation
string getLastName(const uint32_t &index, bool);
string getSquadName(const uint32_t &index, bool);
string getProfession(const uint32_t &index);
string getCurrentJob(const uint32_t &index);
vector<t_skill> getSkills(const uint32_t &index);
vector<t_trait> getTraits(const uint32_t &index);
vector<t_labor> getLabors(const uint32_t &index);
*/ */
bool InitReadNameTables (std::vector< std::vector<std::string> > & translations , std::vector< std::vector<std::string> > & foreign_languages); bool InitReadNameTables (std::vector< std::vector<std::string> > & translations , std::vector< std::vector<std::string> > & foreign_languages);
void FinishReadNameTables(); void FinishReadNameTables();
std::string TranslateName(const t_name & name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish=true); std::string TranslateName(const t_name & name,const std::vector< std::vector<std::string> > & translations ,const std::vector< std::vector<std::string> > & foreign_languages, bool inEnglish=true);
void WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
/*
* Item reading
*/
bool InitReadItems(uint32_t & numitems); bool InitReadItems(uint32_t & numitems);
bool getItemIndexesInBox(std::vector<uint32_t> &indexes,
const uint16_t x1, const uint16_t y1, const uint16_t z1,
const uint16_t x2, const uint16_t y2, const uint16_t z2);
bool ReadItem(const uint32_t index, t_item & item); bool ReadItem(const uint32_t index, t_item & item);
void FinishReadItems(); void FinishReadItems();
/*
* Get the other API parts for raw access
*/
memory_info *getMemoryInfo(); memory_info *getMemoryInfo();
Process * getProcess(); Process * getProcess();
DFWindow * getWindow(); DFWindow * getWindow();

@ -724,6 +724,12 @@ enum e_designation
designation_7 // whatever designation_7 // whatever
}; };
enum e_liquidtype
{
liquid_water,
liquid_magma
};
struct naked_designation struct naked_designation
{ {
unsigned int flow_size : 3; // how much liquid is here? unsigned int flow_size : 3; // how much liquid is here?
@ -753,7 +759,7 @@ struct naked_designation
* 0 = water * 0 = water
* 1 = magma * 1 = magma
*/ */
unsigned int liquid_type : 1; e_liquidtype liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf? unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile? unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
e_traffic traffic : 2; // needs enum e_traffic traffic : 2; // needs enum
@ -822,13 +828,18 @@ union t_occupancy
naked_occupancy_grouped unibits; naked_occupancy_grouped unibits;
}; };
typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16];
typedef uint8_t biome_indices40d [8];
typedef struct typedef struct
{ {
int16_t tiletypes [16][16]; tiletypes40d tiletypes;
DFHack::t_designation designaton [16][16]; designations40d designation;
DFHack::t_occupancy occupancy [16][16]; occupancies40d occupancy;
// really a '7', but I use 8 to make it neater :) // really a '7', but I use 8 to make it neater :)
uint8_t biome_indices [8]; biome_indices40d biome_indices;
uint32_t origin; // the address where it came from uint32_t origin; // the address where it came from
uint32_t dirty_dword; // bit 1 set means that the block is to be included in job checks uint32_t dirty_dword; // bit 1 set means that the block is to be included in job checks
} mapblock40d; } mapblock40d;

@ -13,7 +13,7 @@ int main (void)
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
DFHack::t_occupancy occupancies[256]; DFHack::occupancies40d occupancies;
DFHack::API DF ("Memory.xml"); DFHack::API DF ("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())
@ -34,14 +34,14 @@ int main (void)
if(DF.isValidBlock(x,y,z)) if(DF.isValidBlock(x,y,z))
{ {
// read block designations // read block designations
DF.ReadOccupancy(x,y,z, (uint32_t *) occupancies); DF.ReadOccupancy(x,y,z, &occupancies);
// change the hidden flag to 0 // change the hidden flag to 0
for (uint32_t i = 0; i < 256;i++) for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{ {
occupancies[i].unibits.splatter = 0; occupancies[i][j].unibits.splatter = 0;
} }
// write the designations back // write the designations back
DF.WriteOccupancy(x,y,z, (uint32_t *) occupancies); DF.WriteOccupancy(x,y,z, &occupancies);
} }
} }
} }

@ -136,8 +136,8 @@ int dig(DFHack::API& DF,
return 0; // max limit of 0, nothing to do return 0; // max limit of 0, nothing to do
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::t_designation designations[16][16]; DFHack::designations40d designations;
uint16_t tiles[16][16]; DFHack::tiletypes40d tiles;
DF.getSize(x_max,y_max,z_max); DF.getSize(x_max,y_max,z_max);
// every tile found, will later be sorted by distance to source // every tile found, will later be sorted by distance to source
@ -156,8 +156,8 @@ int dig(DFHack::API& DF,
if(DF.isValidBlock(x,y,z)) if(DF.isValidBlock(x,y,z))
{ {
// read block designations and tiletype // read block designations and tiletype
DF.ReadDesignations(x,y,z, (uint32_t *) designations); DF.ReadDesignations(x,y,z, &designations);
DF.ReadTileTypes(x,y,z, (uint16_t *) tiles); DF.ReadTileTypes(x,y,z, &tiles);
// search all tiles for dig targets: // search all tiles for dig targets:
// visible, not yet marked for dig and matching tile type // visible, not yet marked for dig and matching tile type
@ -210,9 +210,9 @@ int dig(DFHack::API& DF,
} }
// TODO this could probably be made much better, theres a big chance the trees are on the same grid // TODO this could probably be made much better, theres a big chance the trees are on the same grid
DF.ReadDesignations((*i).grid_x, (*i).grid_y, (*i).z, (uint32_t *) designations); DF.ReadDesignations((*i).grid_x, (*i).grid_y, (*i).z, &designations);
designations[(*i).local_x][(*i).local_y].bits.dig = DFHack::designation_default; designations[(*i).local_x][(*i).local_y].bits.dig = DFHack::designation_default;
DF.WriteDesignations((*i).grid_x, (*i).grid_y, (*i).z, (uint32_t *) designations); DF.WriteDesignations((*i).grid_x, (*i).grid_y, (*i).z, &designations);
// Mark as dirty so the jobs are properly picked up by the dwarves // Mark as dirty so the jobs are properly picked up by the dwarves
DF.WriteDirtyBit((*i).grid_x, (*i).grid_y, (*i).z, true); DF.WriteDirtyBit((*i).grid_x, (*i).grid_y, (*i).z, true);

@ -46,9 +46,9 @@ int main (int argc, const char* argv[])
showhidden = true; showhidden = true;
#endif #endif
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint16_t tiletypes[16][16]; DFHack::tiletypes40d tiletypes;
DFHack::t_designation designations[16][16]; DFHack::designations40d designations;
uint8_t regionoffsets[16]; DFHack::biome_indices40d regionoffsets;
map <int16_t, uint32_t> materials; map <int16_t, uint32_t> materials;
materials.clear(); materials.clear();
vector<DFHack::t_matgloss> stonetypes; vector<DFHack::t_matgloss> stonetypes;
@ -97,8 +97,8 @@ int main (int argc, const char* argv[])
continue; continue;
// read data // read data
DF.ReadTileTypes(x,y,z, (uint16_t *) tiletypes); DF.ReadTileTypes(x,y,z, &tiletypes);
DF.ReadDesignations(x,y,z, (uint32_t *) designations); DF.ReadDesignations(x,y,z, &designations);
memset(tempvein, -1, sizeof(tempvein)); memset(tempvein, -1, sizeof(tempvein));
veins.clear(); veins.clear();
@ -106,7 +106,7 @@ int main (int argc, const char* argv[])
if(showbaselayers) if(showbaselayers)
{ {
DF.ReadRegionOffsets(x,y,z, regionoffsets); DF.ReadRegionOffsets(x,y,z, &regionoffsets);
// get the layer materials // get the layer materials
for(uint32_t xx = 0;xx<16;xx++) for(uint32_t xx = 0;xx<16;xx++)
{ {

@ -11,7 +11,7 @@ using namespace std;
int main (void) int main (void)
{ {
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::t_designation designations[256]; DFHack::designations40d designations;
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())
@ -32,14 +32,14 @@ int main (void)
if(DF.isValidBlock(x,y,z)) if(DF.isValidBlock(x,y,z))
{ {
// read block designations // read block designations
DF.ReadDesignations(x,y,z, (uint32_t *) designations); DF.ReadDesignations(x,y,z, &designations);
// change the hidden flag to 0 // change the hidden flag to 0
for (uint32_t i = 0; i < 256;i++) for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
{ {
designations[i].bits.hidden = 0; designations[i][j].bits.hidden = 0;
} }
// write the designations back // write the designations back
DF.WriteDesignations(x,y,z, (uint32_t *) designations); DF.WriteDesignations(x,y,z, &designations);
} }
} }
} }