From bdb0ebd8eab2c1c7e8109de60204cdd8bcd0f042 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 1 Mar 2011 14:37:34 -0600 Subject: [PATCH] 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