diff --git a/dfhack/include/modules/Creatures_C.h b/dfhack/include/modules/Creatures_C.h new file mode 100644 index 000000000..e216c2a0f --- /dev/null +++ b/dfhack/include/modules/Creatures_C.h @@ -0,0 +1,60 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#ifndef CREATURES_C_API +#define CREATURES_C_API + +#include "Export.h" +#include "integers.h" +#include "DFTypes.h" +#include "modules/Materials.h" +#include "modules/Creatures.h" +#include "DFHackAPI_C.h" + +using namespace DFHack; + +#ifdef __cplusplus +extern "C" { +#endif + +DFHACK_EXPORT int Creatures_Start(DFHackObject* cPtr, uint32_t* numCreatures); +DFHACK_EXPORT int Creatures_Finish(DFHackObject* cPtr); + +DFHACK_EXPORT int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, const int32_t index, t_creature* furball, + const uint16_t x1, const uint16_t y1, const uint16_t z1, + const uint16_t x2, const uint16_t y2, const uint16_t z2); + +DFHACK_EXPORT int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball); +DFHACK_EXPORT int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]); + +DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr); +DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr); + +DFHACK_EXPORT int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int)); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dfhack/include/modules/Materials_C.h b/dfhack/include/modules/Materials_C.h index 321a728ec..2e7765fdc 100644 --- a/dfhack/include/modules/Materials_C.h +++ b/dfhack/include/modules/Materials_C.h @@ -59,14 +59,20 @@ DFHACK_EXPORT int Materials_getRaceExSize(DFHackObject* mat); DFHACK_EXPORT int Materials_getColorSize(DFHackObject* mat); DFHACK_EXPORT int Materials_getOtherSize(DFHackObject* mat); -DFHACK_EXPORT int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)); -DFHACK_EXPORT int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)( int)); -DFHACK_EXPORT int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)); -DFHACK_EXPORT int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)); -DFHACK_EXPORT int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)); +DFHACK_EXPORT int Materials_getInorganic(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)); +DFHACK_EXPORT int Materials_getOrganic(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)( int)); +DFHACK_EXPORT int Materials_getTree(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)); +DFHACK_EXPORT int Materials_getPlant(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)); +DFHACK_EXPORT int Materials_getRace(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)); + +/*doomchild: + I haven't done getRaceEx yet, because I'm not sure about the best way to make the t_creaturetype struct + accessible from C. +*/ // DFHACK_EXPORT int Materials_getRaceEx(DFHackObject* mat, t_creaturetype* (*t_creaturetype_buffer_create)(int)); -DFHACK_EXPORT int Materials_getColor(DFHackObject* mat, void* (*t_descriptor_color_buffer_create)(int)); -DFHACK_EXPORT int Materials_getOther(DFHackObject* mat, void* (*t_matglossOther_buffer_create)(int)); + +DFHACK_EXPORT int Materials_getColor(DFHackObject* mat, t_descriptor_color* (*t_descriptor_color_buffer_create)(int)); +DFHACK_EXPORT int Materials_getOther(DFHackObject* mat, t_matglossOther* (*t_matglossOther_buffer_create)(int)); #ifdef __cplusplus } diff --git a/dfhack/modules/Creatures_C.cpp b/dfhack/modules/Creatures_C.cpp new file mode 100644 index 000000000..9b0624da3 --- /dev/null +++ b/dfhack/modules/Creatures_C.cpp @@ -0,0 +1,143 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "Export.h" +#include "integers.h" +#include +#include +#include + +using namespace std; + +#include "DFTypes.h" +#include "modules/Materials.h" +#include "modules/Creatures.h" +#include "modules/Creatures_C.h" +#include "DFHackAPI_C.h" + +using namespace DFHack; + +#ifdef __cplusplus +extern "C" { +#endif + +int Creatures_Start(DFHackObject* cPtr, uint32_t* numCreatures) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->Start(*numCreatures); + } + + return -1; +} + +int Creatures_Finish(DFHackObject* cPtr) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->Finish(); + } + + return -1; +} + +int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, const int32_t index, t_creature* furball, const uint16_t x1, const uint16_t y1, const uint16_t z1, const uint16_t x2, const uint16_t y2, const uint16_t z2) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->ReadCreatureInBox(index, *furball, x1, y1, z1, x2, y2, z2); + } + + return -1; +} + +int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature* furball) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->ReadCreature(index, *furball); + } + + return -1; +} + +int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->WriteLabors(index, labors); + } + + return -1; +} + +uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->GetDwarfRaceIndex(); + } + + return 0; +} + +int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr) +{ + if(cPtr != NULL) + { + return ((DFHack::Creatures*)cPtr)->GetDwarfCivId(); + } + + return -1; +} + +int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int)) +{ + if(cPtr != NULL) + { + std::vector mat; + + if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat)) + { + t_material* buf = (*t_material_buffer_create)(mat.size()); + + if(buf != NULL) + { + copy(mat.begin(), mat.end(), buf); + + return 1; + } + else + return -1; + } + else + return 0; + } + + return -1; +} + +#ifdef __cplusplus +} +#endif diff --git a/dfhack/modules/Materials_C.cpp b/dfhack/modules/Materials_C.cpp index db8754390..1400e3d1a 100644 --- a/dfhack/modules/Materials_C.cpp +++ b/dfhack/modules/Materials_C.cpp @@ -223,7 +223,7 @@ int Materials_getOtherSize(DFHackObject* mat) //vector getters -int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getInorganic(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)) { if(mat != NULL) { @@ -231,7 +231,7 @@ int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)( if(materials->inorganic.size() > 0) { - t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->inorganic.size())); + t_matgloss* buf = ((*t_matgloss_buffer_create)(materials->inorganic.size())); if(buf != NULL) { @@ -249,7 +249,7 @@ int Materials_getInorganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)( return -1; } -int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getOrganic(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)) { if(mat != NULL) { @@ -257,7 +257,7 @@ int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(in if(materials->organic.size() > 0) { - t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->organic.size())); + t_matgloss* buf = ((*t_matgloss_buffer_create)(materials->organic.size())); if(buf != NULL) { @@ -275,7 +275,7 @@ int Materials_getOrganic(DFHackObject* mat, void* (*t_matgloss_buffer_create)(in return -1; } -int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getTree(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)) { if(mat != NULL) { @@ -283,7 +283,7 @@ int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) if(materials->tree.size() > 0) { - t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->tree.size())); + t_matgloss* buf = ((*t_matgloss_buffer_create)(materials->tree.size())); if(buf != NULL) { @@ -301,7 +301,7 @@ int Materials_getTree(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) return -1; } -int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getPlant(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)) { if(mat != NULL) { @@ -309,7 +309,7 @@ int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int) if(materials->plant.size() > 0) { - t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->plant.size())); + t_matgloss* buf = ((*t_matgloss_buffer_create)(materials->plant.size())); if(buf != NULL) { @@ -327,7 +327,7 @@ int Materials_getPlant(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int) return -1; } -int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getRace(DFHackObject* mat, t_matgloss* (*t_matgloss_buffer_create)(int)) { if(mat != NULL) { @@ -335,7 +335,7 @@ int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) if(materials->race.size() > 0) { - t_matgloss* buf = (t_matgloss*)((*t_matgloss_buffer_create)(materials->race.size())); + t_matgloss* buf = ((*t_matgloss_buffer_create)(materials->race.size())); if(buf != NULL) { @@ -355,7 +355,7 @@ int Materials_getRace(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) //race_ex getter goes here... -int Materials_getColor(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getColor(DFHackObject* mat, t_descriptor_color* (*t_descriptor_color_buffer_create)(int)) { if(mat != NULL) { @@ -363,7 +363,7 @@ int Materials_getColor(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int) if(materials->color.size() > 0) { - t_descriptor_color* buf = (t_descriptor_color*)((*t_matgloss_buffer_create)(materials->color.size())); + t_descriptor_color* buf = ((*t_descriptor_color_buffer_create)(materials->color.size())); if(buf != NULL) { @@ -381,7 +381,7 @@ int Materials_getColor(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int) return -1; } -int Materials_getOther(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int)) +int Materials_getOther(DFHackObject* mat, t_matglossOther* (*t_matglossOther_buffer_create)(int)) { if(mat != NULL) { @@ -389,7 +389,7 @@ int Materials_getOther(DFHackObject* mat, void* (*t_matgloss_buffer_create)(int) if(materials->other.size() > 0) { - t_matglossOther* buf = (t_matglossOther*)((*t_matgloss_buffer_create)(materials->other.size())); + t_matglossOther* buf = ((*t_matglossOther_buffer_create)(materials->other.size())); if(buf != NULL) {