From 59707f53461c81fdc9021712eb40450b20628fba Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 10:51:16 -0600 Subject: [PATCH 1/6] inexplicable modifications that need to be committed before I can merge... --- build/build-MinGW32-release-trace.bat | 10 +- build/build-MinGW32-release.bat | 8 +- build/generate-MSVC-2010.bat | 6 +- tools/supported/probe.cpp | 336 +++++++++++++------------- 4 files changed, 180 insertions(+), 180 deletions(-) diff --git a/build/build-MinGW32-release-trace.bat b/build/build-MinGW32-release-trace.bat index ca7df86d3..f75da5ff8 100644 --- a/build/build-MinGW32-release-trace.bat +++ b/build/build-MinGW32-release-trace.bat @@ -1,6 +1,6 @@ -mkdir build-real -cd build-real -cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release --trace > trace-stdout.txt 2> trace-stderr.txt -mingw32-make 2> log.txt -pause +mkdir build-real +cd build-real +cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release --trace > trace-stdout.txt 2> trace-stderr.txt +mingw32-make 2> log.txt +pause dir file.xxx \ No newline at end of file diff --git a/build/build-MinGW32-release.bat b/build/build-MinGW32-release.bat index 18e5bcab4..dd0dc6b88 100644 --- a/build/build-MinGW32-release.bat +++ b/build/build-MinGW32-release.bat @@ -1,5 +1,5 @@ -mkdir build-real -cd build-real -cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release -mingw32-make 2> log.txt +mkdir build-real +cd build-real +cmake ..\.. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release +mingw32-make 2> log.txt pause \ No newline at end of file diff --git a/build/generate-MSVC-2010.bat b/build/generate-MSVC-2010.bat index 50828f7ea..588051bc6 100644 --- a/build/generate-MSVC-2010.bat +++ b/build/generate-MSVC-2010.bat @@ -1,4 +1,4 @@ -mkdir build-real -cd build-real -cmake ..\.. -G"Visual Studio 10" +mkdir build-real +cd build-real +cmake ..\.. -G"Visual Studio 10" pause \ No newline at end of file diff --git a/tools/supported/probe.cpp b/tools/supported/probe.cpp index 9d8549e5b..eb4ec284c 100644 --- a/tools/supported/probe.cpp +++ b/tools/supported/probe.cpp @@ -1,168 +1,168 @@ -// Just show some position data - -#include -#include -#include -#include -#include -#include -#include - -#define DFHACK_WANT_MISCUTILS 1 -#define DFHACK_WANT_TILETYPES 1 -#include - -using namespace DFHack; -int main (int numargs, const char ** args) -{ - DFHack::ContextManager DFMgr("Memory.xml"); - DFHack::Context *DF = DFMgr.getSingleContext(); - - BEGIN_PROBE: - try - { - DF->Attach(); - } - catch (std::exception& e) - { - std::cerr << e.what() << std::endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - - - DFHack::Position *Pos = DF->getPosition(); - DFHack::VersionInfo* mem = DF->getMemoryInfo(); - DFHack::Maps *Maps = DF->getMaps(); - DFHack::Process * p = DF->getProcess(); - OffsetGroup *mapsg = mem->getGroup("Maps"); - OffsetGroup *mapblockg = mapsg->getGroup("block"); - OffsetGroup *localfeatg = mapsg->getGroup("features")->getGroup("local"); - - uint32_t region_x_offset = mapsg->getAddress("region_x"); - uint32_t region_y_offset = mapsg->getAddress("region_y"); - uint32_t region_z_offset = mapsg->getAddress("region_z"); - - uint32_t designatus = mapblockg->getOffset("designation"); - uint32_t block_feature1 = mapblockg->getOffset("feature_local"); - uint32_t block_feature2 = mapblockg->getOffset("feature_global"); - - uint32_t feature1_start_ptr = localfeatg->getAddress("start_ptr"); - int32_t regionX, regionY, regionZ; - - // read position of the region inside DF world - p->readDWord (region_x_offset, (uint32_t &)regionX); - p->readDWord (region_y_offset, (uint32_t &)regionY); - p->readDWord (region_z_offset, (uint32_t &)regionZ); - - Maps->Start(); - - vector global_features; - std::map > local_features; - Maps->ReadLocalFeatures(local_features); - Maps->ReadGlobalFeatures(global_features); - - int32_t cursorX, cursorY, cursorZ; - Pos->getCursorCoords(cursorX,cursorY,cursorZ); - if(cursorX != -30000) - { - uint32_t blockX = cursorX / 16; - uint32_t tileX = cursorX % 16; - uint32_t blockY = cursorY / 16; - uint32_t tileY = cursorY % 16; - t_temperatures tmpb1, tmpb2; - mapblock40d block; - if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block)) - { - Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2); - printf("block addr: 0x%x\n", block.origin); - int16_t tiletype = block.tiletypes[tileX][tileY]; - naked_designation &des = block.designation[tileX][tileY].bits; - uint32_t &desw = block.designation[tileX][tileY].whole; - print_bits(block.designation[tileX][tileY].whole,std::cout); - std::cout << endl; - print_bits(block.occupancy[tileX][tileY].whole,std::cout); - std::cout << endl; - - // tiletype - std::cout <<"tiletype: " << tiletype; - if(tileTypeTable[tiletype].name) - std::cout << " = " << tileTypeTable[tiletype].name << std::endl; - - printf("%-10s: %4d %s\n","Class",tileTypeTable[tiletype].c,TileClassString[ tileTypeTable[tiletype].c ] , 0); - printf("%-10s: %4d %s\n","Material",tileTypeTable[tiletype].c,TileMaterialString[ tileTypeTable[tiletype].m ] , 0); - printf("%-10s: %4d %s\n","Special",tileTypeTable[tiletype].c,TileSpecialString[ tileTypeTable[tiletype].s ] , 0); - printf("%-10s: %4d\n","Variant",tileTypeTable[tiletype].v , 0); - printf("%-10s: %s\n","Direction",tileTypeTable[tiletype].d.getStr() , 0); - - - std::cout << std::endl; - std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl; - std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl; - - // biome, geolayer - std::cout << "biome: " << des.biome << std::endl; - std::cout << "geolayer: " << des.geolayer_index << std::endl; - - // liquids - if(des.flow_size) - { - if(des.liquid_type == DFHack::liquid_magma) - std::cout <<"magma: "; - else std::cout <<"water: "; - std::cout << des.flow_size << std::endl; - } - if(des.flow_forbid) - std::cout << "flow forbid" << std::endl; - if(des.pile) - std::cout << "stockpile?" << std::endl; - if(des.rained) - std::cout << "rained?" << std::endl; - if(des.smooth) - std::cout << "smooth?" << std::endl; - uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation); - printf("designation offset: 0x%x\n", designato); - - #define PRINT_FLAG( X ) printf("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) ) - PRINT_FLAG( hidden ); - PRINT_FLAG( light ); - PRINT_FLAG( skyview ); - PRINT_FLAG( subterranean ); - PRINT_FLAG( water_table ); - //PRINT_FLAG( rained ); - - planecoord pc; - pc.dim.x=blockX; pc.dim.y=blockY; - - PRINT_FLAG( feature_local ); - if( des.feature_local ) - { - printf("%-16s %4d (%2d) %s\n", "", - block.local_feature, - local_features[pc][block.local_feature]->type, - sa_feature[local_features[pc][block.local_feature]->type] - ); - } - - PRINT_FLAG( feature_global ); - if( des.feature_global ){ - printf("%-16s %4d (%2d) %s\n", "", - block.global_feature, - global_features[block.global_feature].type, - sa_feature[global_features[block.global_feature].type] - ); - } - #undef PRINT_FLAG - std::cout << std::endl; - } - } - DF->Detach(); - #ifndef LINUX_BUILD - std::cout << "Press any key to refresh..." << std::endl; - cin.ignore(); - goto BEGIN_PROBE; - #endif - return 0; -} +// Just show some position data + +#include +#include +#include +#include +#include +#include +#include + +#define DFHACK_WANT_MISCUTILS 1 +#define DFHACK_WANT_TILETYPES 1 +#include + +using namespace DFHack; +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); + + BEGIN_PROBE: + try + { + DF->Attach(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + + DFHack::Position *Pos = DF->getPosition(); + DFHack::VersionInfo* mem = DF->getMemoryInfo(); + DFHack::Maps *Maps = DF->getMaps(); + DFHack::Process * p = DF->getProcess(); + OffsetGroup *mapsg = mem->getGroup("Maps"); + OffsetGroup *mapblockg = mapsg->getGroup("block"); + OffsetGroup *localfeatg = mapsg->getGroup("features")->getGroup("local"); + + uint32_t region_x_offset = mapsg->getAddress("region_x"); + uint32_t region_y_offset = mapsg->getAddress("region_y"); + uint32_t region_z_offset = mapsg->getAddress("region_z"); + + uint32_t designatus = mapblockg->getOffset("designation"); + uint32_t block_feature1 = mapblockg->getOffset("feature_local"); + uint32_t block_feature2 = mapblockg->getOffset("feature_global"); + + uint32_t feature1_start_ptr = localfeatg->getAddress("start_ptr"); + int32_t regionX, regionY, regionZ; + + // read position of the region inside DF world + p->readDWord (region_x_offset, (uint32_t &)regionX); + p->readDWord (region_y_offset, (uint32_t &)regionY); + p->readDWord (region_z_offset, (uint32_t &)regionZ); + + Maps->Start(); + + vector global_features; + std::map > local_features; + Maps->ReadLocalFeatures(local_features); + Maps->ReadGlobalFeatures(global_features); + + int32_t cursorX, cursorY, cursorZ; + Pos->getCursorCoords(cursorX,cursorY,cursorZ); + if(cursorX != -30000) + { + uint32_t blockX = cursorX / 16; + uint32_t tileX = cursorX % 16; + uint32_t blockY = cursorY / 16; + uint32_t tileY = cursorY % 16; + t_temperatures tmpb1, tmpb2; + mapblock40d block; + if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block)) + { + Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2); + printf("block addr: 0x%x\n", block.origin); + int16_t tiletype = block.tiletypes[tileX][tileY]; + naked_designation &des = block.designation[tileX][tileY].bits; + uint32_t &desw = block.designation[tileX][tileY].whole; + print_bits(block.designation[tileX][tileY].whole,std::cout); + std::cout << endl; + print_bits(block.occupancy[tileX][tileY].whole,std::cout); + std::cout << endl; + + // tiletype + std::cout <<"tiletype: " << tiletype; + if(tileTypeTable[tiletype].name) + std::cout << " = " << tileTypeTable[tiletype].name << std::endl; + + printf("%-10s: %4d %s\n","Class",tileTypeTable[tiletype].c,TileClassString[ tileTypeTable[tiletype].c ] , 0); + printf("%-10s: %4d %s\n","Material",tileTypeTable[tiletype].c,TileMaterialString[ tileTypeTable[tiletype].m ] , 0); + printf("%-10s: %4d %s\n","Special",tileTypeTable[tiletype].c,TileSpecialString[ tileTypeTable[tiletype].s ] , 0); + printf("%-10s: %4d\n","Variant",tileTypeTable[tiletype].v , 0); + printf("%-10s: %s\n","Direction",tileTypeTable[tiletype].d.getStr() , 0); + + + std::cout << std::endl; + std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl; + std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl; + + // biome, geolayer + std::cout << "biome: " << des.biome << std::endl; + std::cout << "geolayer: " << des.geolayer_index << std::endl; + + // liquids + if(des.flow_size) + { + if(des.liquid_type == DFHack::liquid_magma) + std::cout <<"magma: "; + else std::cout <<"water: "; + std::cout << des.flow_size << std::endl; + } + if(des.flow_forbid) + std::cout << "flow forbid" << std::endl; + if(des.pile) + std::cout << "stockpile?" << std::endl; + if(des.rained) + std::cout << "rained?" << std::endl; + if(des.smooth) + std::cout << "smooth?" << std::endl; + uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation); + printf("designation offset: 0x%x\n", designato); + + #define PRINT_FLAG( X ) printf("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) ) + PRINT_FLAG( hidden ); + PRINT_FLAG( light ); + PRINT_FLAG( skyview ); + PRINT_FLAG( subterranean ); + PRINT_FLAG( water_table ); + //PRINT_FLAG( rained ); + + planecoord pc; + pc.dim.x=blockX; pc.dim.y=blockY; + + PRINT_FLAG( feature_local ); + if( des.feature_local ) + { + printf("%-16s %4d (%2d) %s\n", "", + block.local_feature, + local_features[pc][block.local_feature]->type, + sa_feature[local_features[pc][block.local_feature]->type] + ); + } + + PRINT_FLAG( feature_global ); + if( des.feature_global ){ + printf("%-16s %4d (%2d) %s\n", "", + block.global_feature, + global_features[block.global_feature].type, + sa_feature[global_features[block.global_feature].type] + ); + } + #undef PRINT_FLAG + std::cout << std::endl; + } + } + DF->Detach(); + #ifndef LINUX_BUILD + std::cout << "Press any key to refresh..." << std::endl; + cin.ignore(); + goto BEGIN_PROBE; + #endif + return 0; +} From bdb0ebd8eab2c1c7e8109de60204cdd8bcd0f042 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:37:34 -0600 Subject: [PATCH 2/6] added grass vein and world construction readers --- library/DFTypes_C.cpp | 6 +++ library/include/dfhack-c/DFTypes_C.h | 6 +++ library/include/dfhack-c/modules/Maps_C.h | 2 + library/modules/Maps_C.cpp | 62 +++++++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/library/DFTypes_C.cpp b/library/DFTypes_C.cpp index 7543e4b6c..4bd1a676b 100644 --- a/library/DFTypes_C.cpp +++ b/library/DFTypes_C.cpp @@ -104,6 +104,8 @@ int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL; int (*alloc_vein_buffer_callback)(t_vein*, uint32_t) = NULL; int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t) = NULL; int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t) = NULL; +int (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t) = NULL; +int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t) = NULL; REG_MACRO(Byte, int8_t*, alloc_byte_buffer_callback) REG_MACRO(Short, int16_t*, alloc_short_buffer_callback) @@ -208,10 +210,14 @@ void UnregisterNewCreatureTypeCallback() REG_MACRO(Vein, t_vein*, alloc_vein_buffer_callback) REG_MACRO(FrozenLiquidVein, t_frozenliquidvein*, alloc_frozenliquidvein_buffer_callback) REG_MACRO(SpatterVein, t_spattervein*, alloc_spattervein_buffer_callback) +REG_MACRO(GrassVein, t_grassvein*, alloc_grassvein_buffer_callback) +REG_MACRO(WorldConstruction, t_worldconstruction*, alloc_worldconstruction_buffer_callback) UNREG_MACRO(Vein, alloc_vein_buffer_callback) UNREG_MACRO(FrozenLiquidVein, alloc_frozenliquidvein_buffer_callback) UNREG_MACRO(SpatterVein, alloc_spattervein_buffer_callback) +UNREG_MACRO(GrassVein, alloc_grassvein_buffer_callback) +UNREG_MACRO(WorldConstruction, alloc_worldconstruction_buffer_callback) int DFHack_isWallTerrain(int in) { diff --git a/library/include/dfhack-c/DFTypes_C.h b/library/include/dfhack-c/DFTypes_C.h index 772a0be04..f0c3dcb4c 100644 --- a/library/include/dfhack-c/DFTypes_C.h +++ b/library/include/dfhack-c/DFTypes_C.h @@ -181,6 +181,8 @@ DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein*, uint32_t); DFHACK_EXPORT extern int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t); DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t); +DFHACK_EXPORT extern int (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t); +DFHACK_EXPORT extern int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t); DFHACK_EXPORT void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*)); DFHACK_EXPORT void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t)); @@ -189,6 +191,8 @@ DFHACK_EXPORT void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturet DFHACK_EXPORT void RegisterVeinBufferCallback(int (*funcptr)(t_vein*, uint32_t)); DFHACK_EXPORT void RegisterFrozenLiquidVeinBufferCallback(int (*funcptr)(t_frozenliquidvein*, uint32_t)); DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervein*, uint32_t)); +DFHACK_EXPORT void RegisterGrassVeinBufferCallback(int (*funcptr)(t_grassvein*, uint32_t)); +DFHACK_EXPORT void RegisterWorldConstructionBufferCallback(int (*funcptr)(t_worldconstruction*, uint32_t)); DFHACK_EXPORT void UnregisterEmptyCreatureTypeCallback(); DFHACK_EXPORT void UnregisterNewCreatureTypeCallback(); @@ -197,6 +201,8 @@ HUNREG_MACRO(CreatureType) HUNREG_MACRO(Vein) HUNREG_MACRO(FrozenLiquidVein) HUNREG_MACRO(SpatterVein) +HUNREG_MACRO(GrassVein) +HUNREG_MACRO(WorldConstruction) DFHACK_EXPORT int DFHack_isWallTerrain(int in); DFHACK_EXPORT int DFHack_isFloorTerrain(int in); diff --git a/library/include/dfhack-c/modules/Maps_C.h b/library/include/dfhack-c/modules/Maps_C.h index 3199fc3af..088e530f6 100644 --- a/library/include/dfhack-c/modules/Maps_C.h +++ b/library/include/dfhack-c/modules/Maps_C.h @@ -76,6 +76,8 @@ DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_ DFHACK_EXPORT t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); DFHACK_EXPORT t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); DFHACK_EXPORT t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); +DFHACK_EXPORT t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); +DFHACK_EXPORT t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); #ifdef __cplusplus } diff --git a/library/modules/Maps_C.cpp b/library/modules/Maps_C.cpp index 58e9bb76c..b1ded2dcc 100644 --- a/library/modules/Maps_C.cpp +++ b/library/modules/Maps_C.cpp @@ -444,6 +444,68 @@ t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, return NULL; } +t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) +{ + if(maps != NULL) + { + if(alloc_grassvein_buffer_callback == NULL) + return NULL; + + vector veins; + vector grass_veins; + bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, 0, 0, &grass_veins); + + if(result) + { + t_grassvein* gs_buf = NULL; + + if(grass_veins.size() > 0) + { + ((*alloc_grassvein_buffer_callback)(gs_buf, grass_veins.size())); + + copy(grass_veins.begin(), grass_veins.end(), gs_buf); + } + + return gs_buf; + } + else + return NULL; + } + + return NULL; +} + +t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) +{ + if(maps != NULL) + { + if(alloc_worldconstruction_buffer_callback == NULL) + return NULL; + + vector veins; + vector constructions; + bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, 0, 0, 0, &constructions); + + if(result) + { + t_worldconstruction* ct_buf = NULL; + + if(constructions.size() > 0) + { + ((*alloc_worldconstruction_buffer_callback)(ct_buf, constructions.size())); + + copy(constructions.begin(), constructions.end(), ct_buf); + } + + return ct_buf; + } + else + return NULL; + } + + return NULL; +} + #ifdef __cplusplus } #endif From 0b777449059348238b4b434fb2fd4e66695df5f8 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:38:45 -0600 Subject: [PATCH 3/6] added game mode reader --- library/include/dfhack-c/modules/World_C.h | 2 ++ library/modules/World_C.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/include/dfhack-c/modules/World_C.h b/library/include/dfhack-c/modules/World_C.h index c4348b5e9..a16068d49 100644 --- a/library/include/dfhack-c/modules/World_C.h +++ b/library/include/dfhack-c/modules/World_C.h @@ -43,6 +43,8 @@ DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day); DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather); DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather); +DFHACK_EXPORT int World_ReadGameMode(DFHackObject* world); + #ifdef __cplusplus } #endif diff --git a/library/modules/World_C.cpp b/library/modules/World_C.cpp index 6aa0b320f..aa92a0359 100644 --- a/library/modules/World_C.cpp +++ b/library/modules/World_C.cpp @@ -113,7 +113,7 @@ int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather) int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather) { - if (world != NULL) + if(world != NULL) { ((DFHack::World*)world)->SetCurrentWeather(weather); return 1; @@ -122,6 +122,16 @@ int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather) return -1; } +int World_ReadGameMode(DFHackObject* world) +{ + if(world != NULL) + { + return ((DFHack::World*)world)->ReadGameMode(); + } + + return -1; +} + #ifdef __cplusplus } #endif From 06ae98c9dd82dd79ee2fcaa5b84af24128c41cd2 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:39:18 -0600 Subject: [PATCH 4/6] first commit --- library/python/pydfhack/world.py | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 library/python/pydfhack/world.py diff --git a/library/python/pydfhack/world.py b/library/python/pydfhack/world.py new file mode 100644 index 000000000..29e6fd15a --- /dev/null +++ b/library/python/pydfhack/world.py @@ -0,0 +1,58 @@ +from ctypes import * +from util import _uintify, uint_ptr + +class World(object): + def __init__(self, ptr): + self._world_ptr = ptr + + def start(self): + return libdfhack.World_Start(self._world_ptr) > 0 + + def finish(self): + return libdfhack.World_Finish(self._world_ptr) > 0 + + def read_current_tick(self): + tick = c_uint(0) + + if libdfhack.World_ReadCurrentTick(self._world_ptr, byref(tick)) > 0: + return int(tick) + else: + return -1 + + def read_current_year(self): + year = c_uint(0) + + if libdfhack.World_ReadCurrentYear(self._world_ptr, byref(year)) > 0: + return int(year) + else: + return -1 + + def read_current_month(self): + month = c_uint(0) + + if libdfhack.World_ReadCurrentMonth(self._world_ptr, byref(month)) > 0: + return int(month) + else: + return -1 + + def read_current_day(self): + day = c_uint(0) + + if libdfhack.World_ReadCurrentDay(self._world_ptr, byref(day)) > 0: + return int(day) + else: + return -1 + + def read_current_weather(self): + weather = c_ubyte(0) + + if libdfhack.World_ReadCurrentWeather(self._world_ptr, byref(weather)) > 0: + return int(weather) + else: + return -1 + + def write_current_weather(self, weather): + return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather)) + + def read_game_mode(self): + return int(libdfhack.World_ReadGameMode(self._world_ptr)) \ No newline at end of file From 42670c798b96124fa13618205e2bd819dec88f6e Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:39:33 -0600 Subject: [PATCH 5/6] added grass vein and world construction types --- library/python/pydfhack/dftypes.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/library/python/pydfhack/dftypes.py b/library/python/pydfhack/dftypes.py index 86332ace4..7eae67932 100644 --- a/library/python/pydfhack/dftypes.py +++ b/library/python/pydfhack/dftypes.py @@ -114,6 +114,38 @@ def _alloc_spattervein_buffer_callback(ptr, count): _spattervein_functype = CFUNCTYPE(c_int, POINTER(SpatterVein), c_uint) libdfhack.alloc_spatter_buffer_callback = _spattervein_functype(_alloc_spattervein_buffer_callback) +class GrassVein(Structure): + _fields_ = [("vtable", c_uint), + ("material", c_uint), + ("intensity", ((c_ubyte * 16) * 16)), + ("address_of", c_uint)] + +def _alloc_grassvein_buffer_callback(ptr, count): + allocated = _allocate_array(GrassVein, count) + + ptr = addressof(allocated[0]) + + return 1 + +_grassvein_functype = CFUNCTYPE(c_int, POINTER(GrassVein), c_uint) +libdfhack.alloc_grassvein_buffer_callback = _grassvein_functype(_alloc_grassvein_buffer_callback) + +class WorldConstruction(Structure): + _fields_ = [("vtable", c_uint), + ("material", c_uint), + ("assignment", c_ushort * 16), + ("address_of", c_uint)] + +def _alloc_worldconstruction_buffer_callback(ptr, count): + allocated = _allocate_array(WorldConstruction, count) + + ptr = addressof(allocated[0]) + + return 1 + +_worldconstruction_functype = CFUNCTYPE(c_int, POINTER(WorldConstruction), c_uint) +libdfhack.alloc_worldconstruction_buffer_callback = _worldconstruction_functype(_alloc_worldconstructrion_buffer_callback) + class MapBlock40d(Structure): _fields_ = [("tiletypes", TileTypes40d), ("designation", Designations40d), From f56cad1265192d8bf62f53972b405e1c5b22c664 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:39:56 -0600 Subject: [PATCH 6/6] added grass vein and world construction readers --- library/python/pydfhack/maps.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/library/python/pydfhack/maps.py b/library/python/pydfhack/maps.py index f92b75598..ea2175b6a 100644 --- a/library/python/pydfhack/maps.py +++ b/library/python/pydfhack/maps.py @@ -5,7 +5,9 @@ from util import _uintify, uint_ptr _MAX_DIM = 0x300 _MAX_DIM_SQR = _MAX_DIM * _MAX_DIM -libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ] +_default_argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ] + +libdfhack.Maps_getSize.argtypes = _default_argtypes libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] libdfhack.Maps_ReadDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ] @@ -15,9 +17,11 @@ libdfhack.Maps_WriteTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint, libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] libdfhack.Maps_WriteOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] libdfhack.Maps_ReadRegionOffsets.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(BiomeIndices40d) ] -libdfhack.Maps_ReadStandardVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] -libdfhack.Maps_ReadFrozenVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] -libdfhack.Maps_ReadSpatterVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] +libdfhack.Maps_ReadStandardVeins.argtypes = _default_argtypes +libdfhack.Maps_ReadFrozenVeins.argtypes = _default_argtypes +libdfhack.Maps_ReadSpatterVeins.argtypes = _default_argtypes +libdfhack.Maps_ReadGrassVeins.argtypes = _default_argtypes +libdfhack.Maps_ReadWorldConstructions.argtypes = _default_argtypes class Maps(object): def __init__(self, ptr): @@ -169,6 +173,16 @@ class Maps(object): ux, uy, uz = _uintify(x, y, z) return libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz) + + def read_grass_veins(self, x, y, z): + ux, uy, uz = _uintify(x, y, z) + + return libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz) + + def read_world_constructions(self, x, y, z): + ux, uy, uz = _uintify(x, y, z) + + return libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz) @property def size(self):