From 78a12876d5686a80e8547774de5504fe6eacd809 Mon Sep 17 00:00:00 2001 From: doomchild Date: Thu, 16 Sep 2010 13:04:09 -0500 Subject: [PATCH] added ReadInventoryIdx and ReadInventoryPtr wrappers --- .../include/dfhack-c/modules/Creatures_C.h | 3 + library/modules/Creatures_C.cpp | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/library/include/dfhack-c/modules/Creatures_C.h b/library/include/dfhack-c/modules/Creatures_C.h index 16c357e58..34d145bde 100644 --- a/library/include/dfhack-c/modules/Creatures_C.h +++ b/library/include/dfhack-c/modules/Creatures_C.h @@ -45,6 +45,9 @@ DFHACK_EXPORT int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, const int3 DFHACK_EXPORT int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball); DFHACK_EXPORT t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball); +DFHACK_EXPORT uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index); +DFHACK_EXPORT uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index); + DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr); DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr); diff --git a/library/modules/Creatures_C.cpp b/library/modules/Creatures_C.cpp index 1370258b2..a9b3f9191 100644 --- a/library/modules/Creatures_C.cpp +++ b/library/modules/Creatures_C.cpp @@ -104,6 +104,64 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball) return NULL; } +uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index) +{ + if(cPtr != NULL) + { + std::vector item; + + if(((DFHack::Creatures*)cPtr)->ReadInventoryIdx(index, item)) + { + if(item.size() <= 0) + return NULL; + + uint32_t* buf; + + (*alloc_uint_buffer_callback)(buf, item.size()); + + if(buf != NULL) + { + copy(item.begin(), item.end(), buf); + + return buf; + } + else + return NULL; + } + } + + return NULL; +} + +uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index) +{ + if(cPtr != NULL) + { + std::vector item; + + if(((DFHack::Creatures*)cPtr)->ReadInventoryPtr(index, item)) + { + if(item.size() <= 0) + return NULL; + + uint32_t* buf; + + (*alloc_uint_buffer_callback)(buf, item.size()); + + if(buf != NULL) + { + copy(item.begin(), item.end(), buf); + + return buf; + } + else + return NULL; + } + } + + return NULL; +} + uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr) { if(cPtr != NULL)