added updated Write functions

develop
doomchild 2010-08-18 15:46:06 -05:00
parent 2889b01357
commit f2696dadca
2 changed files with 157 additions and 50 deletions

@ -43,12 +43,23 @@ DFHACK_EXPORT int32_t Creatures_ReadCreatureInBox(DFHackObject* cPtr, const int3
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 t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball);
DFHACK_EXPORT uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr);
DFHACK_EXPORT int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr);
DFHACK_EXPORT t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball);
DFHACK_EXPORT int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
DFHACK_EXPORT int Creatures_WriteHappiness(DFHackObject* cPtr, const uint32_t index, const uint32_t happiness_value);
DFHACK_EXPORT int Creatures_WriteFlags(DFHackObject* cPtr, const uint32_t index, const uint32_t flags1, const uint32_t flags2);
DFHACK_EXPORT int Creatures_WriteSkills(DFHackObject* cPtr, const uint32_t index, const t_soul* soul);
DFHACK_EXPORT int Creatures_WriteAttributes(DFHackObject* cPtr, const uint32_t index, const t_creature* creature);
DFHACK_EXPORT int Creatures_WriteSex(DFHackObject* cPtr, const uint32_t index, const uint8_t sex);
DFHACK_EXPORT int Creatures_WriteTraits(DFHackObject* cPtr, const uint32_t index, const t_soul* soul);
DFHACK_EXPORT int Creatures_WriteMood(DFHackObject* cPtr, const uint32_t index, const uint16_t mood);
DFHACK_EXPORT int Creatures_WriteMoodSkill(DFHackObject* cPtr, const uint32_t index, const uint16_t moodSkill);
DFHACK_EXPORT int Creatures_WriteJob(DFHackObject* cPtr, const t_creature* furball, const t_material* mat, const uint32_t mat_count);
DFHACK_EXPORT int Creatures_WritePos(DFHackObject* cPtr, const uint32_t index, const t_creature* creature);
DFHACK_EXPORT int Creatures_WriteCiv(DFHackObject* cPtr, const uint32_t index, const int32_t civ);
#ifdef __cplusplus
}

@ -24,6 +24,11 @@ distribution.
#include "dfhack-c/modules/Creatures_C.h"
#include <vector>
#include <algorithm>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
@ -68,14 +73,32 @@ int Creatures_ReadCreature(DFHackObject* cPtr, const int32_t index, t_creature*
return -1;
}
int Creatures_WriteLabors(DFHackObject* cPtr, const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteLabors(index, labors);
std::vector<t_material> mat;
if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat))
{
t_material* buf;
(*alloc_t_material_buffer_callback)(buf, mat.size());
if(buf != NULL)
{
copy(mat.begin(), mat.end(), buf);
return buf;
}
else
return NULL;
}
else
return NULL;
}
return -1;
return NULL;
}
uint32_t Creatures_GetDwarfRaceIndex(DFHackObject* cPtr)
@ -98,58 +121,131 @@ int32_t Creatures_GetDwarfCivId(DFHackObject* cPtr)
return -1;
}
// int Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball, t_material* (*t_material_buffer_create)(int))
// {
// if(cPtr != NULL)
// {
// std::vector<t_material> mat;
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;
}
int Creatures_WriteHappiness(DFHackObject* cPtr, const uint32_t index, const uint32_t happiness_value)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteHappiness(index, happiness_value);
}
// if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat))
// {
// t_material* buf = (*t_material_buffer_create)(mat.size());
return -1;
}
// if(buf != NULL)
// {
// copy(mat.begin(), mat.end(), buf);
int Creatures_WriteFlags(DFHackObject* cPtr, const uint32_t index, const uint32_t flags1, const uint32_t flags2)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteFlags(index, flags1, flags2);
}
// return 1;
// }
// else
// return -1;
// }
// else
// return 0;
// }
return -1;
}
int Creatures_WriteSkills(DFHackObject* cPtr, const uint32_t index, const t_soul* soul)
{
if(cPtr != NULL && soul != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteSkills(index, *soul);
}
// return -1;
// }
return -1;
}
t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
int Creatures_WriteAttributes(DFHackObject* cPtr, const uint32_t index, const t_creature* creature)
{
if(cPtr != NULL && creature != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteAttributes(index, *creature);
}
return -1;
}
int Creatures_WriteSex(DFHackObject* cPtr, const uint32_t index, const uint8_t sex)
{
if(cPtr != NULL)
{
std::vector<t_material> mat;
return ((DFHack::Creatures*)cPtr)->WriteSex(index, sex);
}
if(((DFHack::Creatures*)cPtr)->ReadJob(furball, mat))
return -1;
}
int Creatures_WriteTraits(DFHackObject* cPtr, const uint32_t index, const t_soul* soul)
{
if(cPtr != NULL && soul != NULL)
{
t_material* buf;
return ((DFHack::Creatures*)cPtr)->WriteTraits(index, *soul);
}
(*alloc_t_material_buffer_callback)(buf, mat.size());
return -1;
}
if(buf != NULL)
int Creatures_WriteMood(DFHackObject* cPtr, const uint32_t index, const uint16_t mood)
{
if(cPtr != NULL)
{
copy(mat.begin(), mat.end(), buf);
return ((DFHack::Creatures*)cPtr)->WriteMood(index, mood);
}
return buf;
return -1;
}
int Creatures_WriteMoodSkill(DFHackObject* cPtr, const uint32_t index, const uint16_t moodSkill)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteMoodSkill(index, moodSkill);
}
else
return NULL;
return -1;
}
int Creatures_WriteJob(DFHackObject* cPtr, const t_creature* furball, const t_material* mat, const uint32_t mat_count)
{
if(cPtr != NULL && furball != NULL && mat != NULL)
{
if(mat_count == 0)
return 0;
std::vector<t_material> mat_vec;
copy(mat, mat + mat_count, mat_vec.begin());
return ((DFHack::Creatures*)cPtr)->WriteJob(furball, mat_vec);
}
else
return NULL;
return -1;
}
int Creatures_WritePos(DFHackObject* cPtr, const uint32_t index, const t_creature* creature)
{
if(cPtr != NULL && creature != NULL)
{
return ((DFHack::Creatures*)cPtr)->WritePos(index, *creature);
}
return NULL;
return -1;
}
int Creatures_WriteCiv(DFHackObject* cPtr, const uint32_t index, const int32_t civ)
{
if(cPtr != NULL)
{
return ((DFHack::Creatures*)cPtr)->WriteCiv(index, civ);
}
return -1;
}
#ifdef __cplusplus