update to the C API

develop
Petr Mrázek 2009-10-23 14:00:15 +00:00
parent dab8d37c03
commit e637488cbd
3 changed files with 621 additions and 545 deletions

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -31,297 +31,327 @@ distribution.
#include "DFHackAPIc.h" #include "DFHackAPIc.h"
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
# ifndef secure_strcpy # ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy((dst), (buf)) # define secure_strcpy(dst, size, buf) strcpy((dst), (buf))
# endif # endif
#else #else
# if defined(_MSC_VER) && _MSC_VER >= 1400 # if defined(_MSC_VER) && _MSC_VER >= 1400
# ifndef secure_strcpy # ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy_s((dst), (size), (buf)) # define secure_strcpy(dst, size, buf) strcpy_s((dst), (size), (buf))
# endif # endif
# else # else
# ifndef secure_strcpy # ifndef secure_strcpy
# define secure_strcpy(dst, size, buf) strcpy((dst), (buf)) # define secure_strcpy(dst, size, buf) strcpy((dst), (buf))
# endif # endif
# endif # endif
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
// The C interface for vector management // The C interface for vector management
DFHACKAPI void DFHackAPIVector_free(DFHackAPIVectorC *vector) DFHACKAPI void DFHackAPIVector_free (DFHackAPIVectorC *vector)
{ {
uint32_t i; uint32_t i;
switch (vector->type) switch (vector->type)
{ {
case DFHackAPIVectorTypeC_Normal: case DFHackAPIVectorTypeC_Normal:
delete [] (vector->data); delete [] (vector->data);
break; break;
case DFHackAPIVectorTypeC_Matgloss: case DFHackAPIVectorTypeC_Matgloss:
delete [] ((t_matgloss *)vector->data); delete [] ( (t_matgloss *) vector->data);
break; break;
case DFHackAPIVectorTypeC_Uint16: case DFHackAPIVectorTypeC_Uint16:
delete [] ((uint16_t *)vector->data); delete [] ( (uint16_t *) vector->data);
break; break;
case DFHackAPIVectorTypeC_Vein: case DFHackAPIVectorTypeC_Vein:
delete [] ((t_vein *)vector->data); delete [] ( (t_vein *) vector->data);
break; break;
case DFHackAPIVectorTypeC_String: case DFHackAPIVectorTypeC_String:
for (i = 0; i < vector->length; i++) for (i = 0; i < vector->length; i++)
delete [] ((char **)vector->data)[i]; delete [] ( (char **) vector->data) [i];
delete [] ((char **)vector->data); delete [] ( (char **) vector->data);
break; break;
case DFHackAPIVectorTypeC_Recursive: case DFHackAPIVectorTypeC_Recursive:
for (i = 0; i < vector->length; i++) for (i = 0; i < vector->length; i++)
DFHackAPIVector_free(&((DFHackAPIVectorC *) vector->data)[i]); DFHackAPIVector_free (& ( (DFHackAPIVectorC *) vector->data) [i]);
delete [] ((DFHackAPIVectorC *)vector->data); delete [] ( (DFHackAPIVectorC *) vector->data);
break; break;
} }
vector->type = DFHackAPIVectorTypeC_Normal; vector->type = DFHackAPIVectorTypeC_Normal;
vector->length = 0; vector->length = 0;
vector->data = 0; vector->data = 0;
} }
// The C interface to DFHackAPI (for multiple language support) // The C interface to DFHackAPI (for multiple language support)
DFHACKAPI DFHackAPIHandle CreateDFHackAPI(const char *path_to_xml) DFHACKAPI DFHackAPIHandle CreateDFHackAPI (const char *path_to_xml)
{ {
return new DFHackAPIImpl(path_to_xml); return new DFHackAPIImpl (path_to_xml);
} }
DFHACKAPI void DestroyDFHackAPI(DFHackAPIHandle self) DFHACKAPI void DestroyDFHackAPI (DFHackAPIHandle self)
{ {
if (self != NULL) if (self != NULL)
delete self; delete self;
} }
DFHACKAPI bool DFHackAPI_Attach(DFHackAPIHandle self) DFHACKAPI bool DFHackAPI_Attach (DFHackAPIHandle self)
{ {
return self->Attach(); return self->Attach();
} }
DFHACKAPI bool DFHackAPI_Detach(DFHackAPIHandle self) DFHACKAPI bool DFHackAPI_Detach (DFHackAPIHandle self)
{ {
return self->Detach(); return self->Detach();
} }
DFHACKAPI bool DFHackAPI_isAttached(DFHackAPIHandle self) DFHACKAPI bool DFHackAPI_isAttached (DFHackAPIHandle self)
{ {
return self->isAttached(); return self->isAttached();
} }
DFHACKAPI bool DFHackAPI_ReadStoneMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output) DFHACKAPI bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{ {
vector<t_matgloss> result; vector<t_matgloss> result;
uint32_t i; uint32_t i;
bool retn = self->ReadStoneMatgloss(result); bool retn = self->ReadStoneMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss; output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size(); output->length = result.size();
output->data = new t_matgloss[output->length]; output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++) for (i = 0; i < output->length; i++)
((t_matgloss *)output->data)[i] = result[i]; ( (t_matgloss *) output->data) [i] = result[i];
return retn; return retn;
} }
DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output) DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{ {
vector<t_matgloss> result; vector<t_matgloss> result;
uint32_t i; uint32_t i;
bool retn = self->ReadWoodMatgloss (result); bool retn = self->ReadWoodMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss; output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size(); output->length = result.size();
output->data = new t_matgloss[output->length]; output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++) for (i = 0; i < output->length; i++)
((t_matgloss *)output->data)[i] = result[i]; ( (t_matgloss *) output->data) [i] = result[i];
return retn; return retn;
} }
DFHACKAPI bool DFHackAPI_ReadMetalMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output) DFHACKAPI bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{ {
vector<t_matgloss> result; vector<t_matgloss> result;
uint32_t i; uint32_t i;
bool retn = self->ReadMetalMatgloss(result); bool retn = self->ReadMetalMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss; output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size(); output->length = result.size();
output->data = new t_matgloss[output->length]; output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++) for (i = 0; i < output->length; i++)
((t_matgloss *)output->data)[i] = result[i]; ( (t_matgloss *) output->data) [i] = result[i];
return retn; return retn;
} }
DFHACKAPI bool DFHackAPI_ReadPlantMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output) DFHACKAPI bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{ {
vector<t_matgloss> result; vector<t_matgloss> result;
uint32_t i; uint32_t i;
bool retn = self->ReadPlantMatgloss(result); bool retn = self->ReadPlantMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss; output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size(); output->length = result.size();
output->data = new t_matgloss[output->length]; output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++) for (i = 0; i < output->length; i++)
((t_matgloss *)output->data)[i] = result[i]; ( (t_matgloss *) output->data) [i] = result[i];
return retn; return retn;
} }
DFHACKAPI bool DFHackAPI_ReadGeology(DFHackAPIHandle self, DFHackAPIVectorC *assign) DFHACKAPI bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{ {
vector< vector<uint16_t> > result; vector<t_matgloss> result;
uint32_t i, j; uint32_t i;
bool retn = self->ReadGeology(result); bool retn = self->ReadCreatureMatgloss (result);
assign->type = DFHackAPIVectorTypeC_Recursive; output->type = DFHackAPIVectorTypeC_Matgloss;
assign->length = result.size(); output->length = result.size();
assign->data = new DFHackAPIVectorC[assign->length]; output->data = new t_matgloss[output->length];
for (i = 0; i < assign->length; i++) for (i = 0; i < output->length; i++)
{ ( (t_matgloss *) output->data) [i] = result[i];
DFHackAPIVectorC &current = ((DFHackAPIVectorC *) assign->data)[i];
current.type = DFHackAPIVectorTypeC_Uint16; return retn;
current.length = result[i].size(); }
current.data = new uint16_t[current.length]; DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign)
for (j = 0; j < current.length; j++) {
((uint16_t *)current.data)[j] = result[i][j]; vector< vector<uint16_t> > result;
} uint32_t i, j;
bool retn = self->ReadGeology (result);
return retn;
} assign->type = DFHackAPIVectorTypeC_Recursive;
assign->length = result.size();
DFHACKAPI bool DFHackAPI_InitMap(DFHackAPIHandle self) assign->data = new DFHackAPIVectorC[assign->length];
{ for (i = 0; i < assign->length; i++)
return self->InitMap(); {
} DFHackAPIVectorC &current = ( (DFHackAPIVectorC *) assign->data) [i];
current.type = DFHackAPIVectorTypeC_Uint16;
DFHACKAPI bool DFHackAPI_DestroyMap(DFHackAPIHandle self) current.length = result[i].size();
{ current.data = new uint16_t[current.length];
return self->DestroyMap(); for (j = 0; j < current.length; j++)
} ( (uint16_t *) current.data) [j] = result[i][j];
}
DFHACKAPI void DFHackAPI_getSize(DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z)
{ return retn;
return self->getSize(*x, *y, *z); }
}
DFHACKAPI bool DFHackAPI_InitMap (DFHackAPIHandle self)
DFHACKAPI bool DFHackAPI_isValidBlock(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz) {
{ return self->InitMap();
return self->isValidBlock(blockx, blocky, blockz); }
}
DFHACKAPI bool DFHackAPI_DestroyMap (DFHackAPIHandle self)
DFHACKAPI bool DFHackAPI_ReadTileTypes(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) {
{ return self->DestroyMap();
return self->ReadTileTypes(blockx, blocky, blockz, buffer); }
}
DFHACKAPI void DFHackAPI_getSize (DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z)
DFHACKAPI bool DFHackAPI_WriteTileTypes(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) {
{ return self->getSize (*x, *y, *z);
return self->WriteTileTypes(blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_isValidBlock (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz)
DFHACKAPI bool DFHackAPI_ReadDesignations(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) {
{ return self->isValidBlock (blockx, blocky, blockz);
return self->ReadDesignations (blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_ReadTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer)
DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) {
{ return self->ReadTileTypes (blockx, blocky, blockz, buffer);
return self->WriteDesignations (blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_WriteTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer)
DFHACKAPI bool DFHackAPI_ReadOccupancy(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) {
{ return self->WriteTileTypes (blockx, blocky, blockz, buffer);
return self->ReadOccupancy(blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_ReadDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
DFHACKAPI bool DFHackAPI_WriteOccupancy(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) {
{ return self->ReadDesignations (blockx, blocky, blockz, buffer);
return self->WriteOccupancy(blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
DFHACKAPI bool DFHackAPI_ReadRegionOffsets(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) {
{ return self->WriteDesignations (blockx, blocky, blockz, buffer);
return self->ReadRegionOffsets(blockx, blocky, blockz, buffer); }
}
DFHACKAPI bool DFHackAPI_ReadOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
DFHACKAPI bool DFHackAPI_ReadVeins(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins) {
{ return self->ReadOccupancy (blockx, blocky, blockz, buffer);
vector<t_vein> result; }
uint32_t i;
bool retn = self->ReadVeins(blockx, blocky, blockz, result); DFHACKAPI bool DFHackAPI_WriteOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{
veins->type = DFHackAPIVectorTypeC_Vein; return self->WriteOccupancy (blockx, blocky, blockz, buffer);
veins->length = result.size(); }
veins->data = new t_vein[veins->length];
for (i = 0; i < veins->length; i++) DFHACKAPI bool DFHackAPI_ReadRegionOffsets (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer)
((t_vein *)veins->data)[i] = result[i]; {
return self->ReadRegionOffsets (blockx, blocky, blockz, buffer);
return retn; }
}
DFHACKAPI bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins)
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions(DFHackAPIHandle self) {
{ vector<t_vein> result;
return self->InitReadConstructions(); uint32_t i;
} bool retn = self->ReadVeins (blockx, blocky, blockz, result);
DFHACKAPI bool DFHackAPI_ReadConstruction(DFHackAPIHandle self, const uint32_t *index, t_construction * construction) veins->type = DFHackAPIVectorTypeC_Vein;
{ veins->length = result.size();
return self->ReadConstruction(*index, *construction); veins->data = new t_vein[veins->length];
} for (i = 0; i < veins->length; i++)
( (t_vein *) veins->data) [i] = result[i];
DFHACKAPI void DFHackAPI_FinishReadConstructions(DFHackAPIHandle self)
{ return retn;
self->FinishReadConstructions(); }
}
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions (DFHackAPIHandle self)
DFHACKAPI uint32_t DFHackAPI_InitReadBuildings(DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes) {
{ return self->InitReadConstructions();
vector<string> result; }
uint32_t i;
uint32_t retn = self->InitReadBuildings(result); DFHACKAPI bool DFHackAPI_ReadConstruction (DFHackAPIHandle self, const uint32_t *index, t_construction * construction)
{
v_buildingtypes->type = DFHackAPIVectorTypeC_String; return self->ReadConstruction (*index, *construction);
v_buildingtypes->length = result.size(); }
v_buildingtypes->data = new char *[v_buildingtypes->length];
for (i = 0; i < v_buildingtypes->length; i++) DFHACKAPI void DFHackAPI_FinishReadConstructions (DFHackAPIHandle self)
{ {
char *str = new char[result[i].size() + 1]; self->FinishReadConstructions();
secure_strcpy(str, result[i].size() + 1, result[i].c_str()); }
((char **)v_buildingtypes->data)[i] = str;
} DFHACKAPI uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes)
{
return retn; vector<string> result;
} uint32_t i;
uint32_t retn = self->InitReadBuildings (result);
DFHACKAPI bool DFHackAPI_ReadBuilding(DFHackAPIHandle self, const uint32_t *index, t_building * building)
{ v_buildingtypes->type = DFHackAPIVectorTypeC_String;
return self->ReadBuilding(*index, *building); v_buildingtypes->length = result.size();
} v_buildingtypes->data = new char *[v_buildingtypes->length];
for (i = 0; i < v_buildingtypes->length; i++)
DFHACKAPI void DFHackAPI_FinishReadBuildings(DFHackAPIHandle self) {
{ char *str = new char[result[i].size() + 1];
self->FinishReadBuildings(); secure_strcpy (str, result[i].size() + 1, result[i].c_str());
} ( (char **) v_buildingtypes->data) [i] = str;
}
DFHACKAPI uint32_t DFHackAPI_InitReadVegetation(DFHackAPIHandle self)
{ return retn;
return self->InitReadVegetation(); }
}
DFHACKAPI bool DFHackAPI_ReadBuilding (DFHackAPIHandle self, const uint32_t *index, t_building * building)
DFHACKAPI bool DFHackAPI_ReadVegetation(DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery) {
{ return self->ReadBuilding (*index, *building);
return self->ReadVegetation(*index, *shrubbery); }
}
DFHACKAPI void DFHackAPI_FinishReadBuildings (DFHackAPIHandle self)
DFHACKAPI void DFHackAPI_FinishReadVegetation(DFHackAPIHandle self) {
{ self->FinishReadBuildings();
self->FinishReadVegetation(); }
}
DFHACKAPI uint32_t DFHackAPI_InitReadVegetation (DFHackAPIHandle self)
{
return self->InitReadVegetation();
}
DFHACKAPI bool DFHackAPI_ReadVegetation (DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery)
{
return self->ReadVegetation (*index, *shrubbery);
}
DFHACKAPI void DFHackAPI_FinishReadVegetation (DFHackAPIHandle self)
{
self->FinishReadVegetation();
}
DFHACKAPI uint32_t DFHackAPI_InitReadCreatures (DFHackAPIHandle self)
{
return self->InitReadCreatures();
}
DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball)
{
return self->ReadCreature (*index, *furball);
}
DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self)
{
self->FinishReadCreatures();
}
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/dfhack www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,43 +26,45 @@ distribution.
#define SIMPLEAPIC_H_INCLUDED #define SIMPLEAPIC_H_INCLUDED
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
# ifndef DFHACKAPI # ifndef DFHACKAPI
# define DFHACKAPI extern "C" # define DFHACKAPI extern "C"
# endif # endif
#else #else
# ifdef BUILD_DFHACK_LIB # ifdef BUILD_DFHACK_LIB
# ifndef DFHACKAPI # ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllexport) # define DFHACKAPI extern "C" __declspec(dllexport)
# endif # endif
# else # else
# ifndef DFHACKAPI # ifndef DFHACKAPI
# define DFHACKAPI extern "C" __declspec(dllimport) # define DFHACKAPI extern "C" __declspec(dllimport)
# endif # endif
# endif # endif
#endif #endif
#include <integers.h> #include <integers.h>
#ifdef __cplusplus #ifdef __cplusplus
# include <vector> # include <vector>
# include <string> # include <string>
using namespace std; using namespace std;
#endif #endif
typedef enum DFHackAPIVectorTypeC { typedef enum DFHackAPIVectorTypeC
DFHackAPIVectorTypeC_Normal, // array of struct's {
DFHackAPIVectorTypeC_Matgloss, // array of t_matgloss's DFHackAPIVectorTypeC_Normal, // array of struct's
DFHackAPIVectorTypeC_Uint16, // array of uint16_t's DFHackAPIVectorTypeC_Matgloss, // array of t_matgloss's
DFHackAPIVectorTypeC_Vein, // array of t_vein's DFHackAPIVectorTypeC_Uint16, // array of uint16_t's
DFHackAPIVectorTypeC_String, // array of const char *'s DFHackAPIVectorTypeC_Vein, // array of t_vein's
DFHackAPIVectorTypeC_Recursive, // array of DFHackAPIVectorC struct's DFHackAPIVectorTypeC_String, // array of const char *'s
DFHackAPIVectorTypeC_DWord = 0xffffffff // Unused DFHackAPIVectorTypeC_Recursive, // array of DFHackAPIVectorC struct's
DFHackAPIVectorTypeC_DWord = 0xffffffff // Unused
} DFHackAPIVectorTypeC; } DFHackAPIVectorTypeC;
typedef struct DFHackAPIVectorC { typedef struct DFHackAPIVectorC
void *data; {
uint32_t length; void *data;
DFHackAPIVectorTypeC type; uint32_t length;
DFHackAPIVectorTypeC type;
} DFHackAPIVector; } DFHackAPIVector;
#ifdef __cplusplus #ifdef __cplusplus
@ -73,58 +75,64 @@ typedef char bool;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif // __cplusplus #endif // __cplusplus
// The C interface for vector management // The C interface for vector management
DFHACKAPI void DFHackAPIVector_free(DFHackAPIVectorC *vector); DFHACKAPI void DFHackAPIVector_free (DFHackAPIVectorC *vector);
// The C interface to DFHackAPI (for multiple language support) // The C interface to DFHackAPI (for multiple language support)
DFHACKAPI DFHackAPIHandle CreateDFHackAPI(const char *path_to_xml); DFHACKAPI DFHackAPIHandle CreateDFHackAPI (const char *path_to_xml);
DFHACKAPI void DestroyDFHackAPI(DFHackAPIHandle self); DFHACKAPI void DestroyDFHackAPI (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_Attach (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_Detach (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_isAttached (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_Attach(DFHackAPIHandle self); DFHACKAPI bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_Detach(DFHackAPIHandle self); DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_isAttached(DFHackAPIHandle self); DFHACKAPI bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadStoneMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output); DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign);
DFHACKAPI bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadMetalMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadPlantMatgloss(DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadGeology(DFHackAPIHandle self, DFHackAPIVectorC *assign); DFHACKAPI bool DFHackAPI_InitMap (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_DestroyMap (DFHackAPIHandle self);
DFHACKAPI void DFHackAPI_getSize (DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACKAPI bool DFHackAPI_InitMap(DFHackAPIHandle self); DFHACKAPI bool DFHackAPI_isValidBlock (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz);
DFHACKAPI bool DFHackAPI_DestroyMap(DFHackAPIHandle self);
DFHACKAPI void DFHackAPI_getSize(DFHackAPIHandle self, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACKAPI bool DFHackAPI_isValidBlock(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz); DFHACKAPI bool DFHackAPI_ReadTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer);
DFHACKAPI bool DFHackAPI_WriteTileTypes (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer);
DFHACKAPI bool DFHackAPI_ReadTileTypes(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); DFHACKAPI bool DFHackAPI_ReadDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_WriteTileTypes(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_ReadDesignations(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); DFHACKAPI bool DFHackAPI_ReadOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_WriteDesignations (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); DFHACKAPI bool DFHackAPI_WriteOccupancy (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_ReadOccupancy(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer); DFHACKAPI bool DFHackAPI_ReadRegionOffsets (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer);
DFHACKAPI bool DFHackAPI_WriteOccupancy(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer);
DFHACKAPI bool DFHackAPI_ReadRegionOffsets(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer); DFHACKAPI bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins);
DFHACKAPI bool DFHackAPI_ReadVeins(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, DFHackAPIVectorC * veins);
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadConstruction (DFHackAPIHandle self, const uint32_t *index, t_construction * construction);
DFHACKAPI void DFHackAPI_FinishReadConstructions (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadConstructions(DFHackAPIHandle self); DFHACKAPI uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes);
DFHACKAPI bool DFHackAPI_ReadConstruction(DFHackAPIHandle self, const uint32_t *index, t_construction * construction); DFHACKAPI bool DFHackAPI_ReadBuilding (DFHackAPIHandle self, const uint32_t *index, t_building * building);
DFHACKAPI void DFHackAPI_FinishReadConstructions(DFHackAPIHandle self); DFHACKAPI void DFHackAPI_FinishReadBuildings (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadBuildings(DFHackAPIHandle self, DFHackAPIVectorC *v_buildingtypes); DFHACKAPI uint32_t DFHackAPI_InitReadVegetation (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadBuilding(DFHackAPIHandle self, const uint32_t *index, t_building * building); DFHACKAPI bool DFHackAPI_ReadVegetation (DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery);
DFHACKAPI void DFHackAPI_FinishReadBuildings(DFHackAPIHandle self); DFHACKAPI void DFHackAPI_FinishReadVegetation (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadVegetation(DFHackAPIHandle self); DFHACKAPI uint32_t DFHackAPI_InitReadCreatures (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadVegetation(DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery); DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball);
DFHACKAPI void DFHackAPI_FinishReadVegetation(DFHackAPIHandle self); DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self);
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -132,88 +140,99 @@ DFHACKAPI void DFHackAPI_FinishReadVegetation(DFHackAPIHandle self);
// C++ wrappers for C API that use vectors // C++ wrappers for C API that use vectors
#ifdef __cplusplus #ifdef __cplusplus
inline bool DFHackAPI_ReadStoneMatgloss(DFHackAPIHandle self, vector<t_matgloss> & output) inline bool DFHackAPI_ReadStoneMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadStoneMatgloss(self, &vector); bool result = DFHackAPI_ReadStoneMatgloss (self, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vector.length; i++)
output.push_back(((t_matgloss *) vector.data)[i]); output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free(&vector); DFHackAPIVector_free (&vector);
return result; return result;
} }
inline bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output) inline bool DFHackAPI_ReadWoodMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadWoodMatgloss (self, &vector); bool result = DFHackAPI_ReadWoodMatgloss (self, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vector.length; i++)
output.push_back(((t_matgloss *) vector.data)[i]); output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free(&vector); DFHackAPIVector_free (&vector);
return result; return result;
} }
inline bool DFHackAPI_ReadMetalMatgloss(DFHackAPIHandle self, vector<t_matgloss> & output) inline bool DFHackAPI_ReadMetalMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadMetalMatgloss(self, &vector); bool result = DFHackAPI_ReadMetalMatgloss (self, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vector.length; i++)
output.push_back(((t_matgloss *) vector.data)[i]); output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free(&vector); DFHackAPIVector_free (&vector);
return result; return result;
} }
inline bool DFHackAPI_ReadPlantMatgloss(DFHackAPIHandle self, vector<t_matgloss> & output) inline bool DFHackAPI_ReadPlantMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadPlantMatgloss(self, &vector); bool result = DFHackAPI_ReadPlantMatgloss (self, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vector.length; i++)
output.push_back(((t_matgloss *) vector.data)[i]); output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free(&vector); DFHackAPIVector_free (&vector);
return result; return result;
} }
inline bool DFHackAPI_ReadGeology(DFHackAPIHandle self, vector< vector<uint16_t> > &assign) inline bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{ {
DFHackAPIVectorC vec; DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadGeology(self, &vec); bool result = DFHackAPI_ReadCreatureMatgloss (self, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vec.length; i++) for (i = 0; i < vector.length; i++)
{ output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVectorC &current = ((DFHackAPIVectorC *) vec.data)[i]; DFHackAPIVector_free (&vector);
vector<uint16_t> fill; return result;
uint32_t j;
for (j = 0; j < current.length; j++)
fill.push_back(((uint16_t *) current.data)[j]);
assign.push_back(fill);
}
DFHackAPIVector_free(&vec);
return result;
} }
inline bool DFHackAPI_ReadVeins(DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins) inline bool DFHackAPI_ReadGeology (DFHackAPIHandle self, vector< vector<uint16_t> > &assign)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vec;
bool result = DFHackAPI_ReadVeins(self, blockx, blocky, blockz, &vector); bool result = DFHackAPI_ReadGeology (self, &vec);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vec.length; i++)
veins.push_back(((t_vein *) vector.data)[i]); {
DFHackAPIVector_free(&vector); DFHackAPIVectorC &current = ( (DFHackAPIVectorC *) vec.data) [i];
return result; vector<uint16_t> fill;
uint32_t j;
for (j = 0; j < current.length; j++)
fill.push_back ( ( (uint16_t *) current.data) [j]);
assign.push_back (fill);
}
DFHackAPIVector_free (&vec);
return result;
} }
inline uint32_t DFHackAPI_InitReadBuildings(DFHackAPIHandle self, vector <string> &v_buildingtypes) inline bool DFHackAPI_ReadVeins (DFHackAPIHandle self, uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins)
{ {
DFHackAPIVectorC vector; DFHackAPIVectorC vector;
uint32_t result = DFHackAPI_InitReadBuildings(self, &vector); bool result = DFHackAPI_ReadVeins (self, blockx, blocky, blockz, &vector);
uint32_t i; uint32_t i;
for (i = 0; i < vector.length; i++) for (i = 0; i < vector.length; i++)
v_buildingtypes.push_back(((const char **) vector.data)[i]); veins.push_back ( ( (t_vein *) vector.data) [i]);
DFHackAPIVector_free(&vector); DFHackAPIVector_free (&vector);
return result; return result;
}
inline uint32_t DFHackAPI_InitReadBuildings (DFHackAPIHandle self, vector <string> &v_buildingtypes)
{
DFHackAPIVectorC vector;
uint32_t result = DFHackAPI_InitReadBuildings (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
v_buildingtypes.push_back ( ( (const char **) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
} }
#endif // __cplusplus #endif // __cplusplus
@ -221,64 +240,67 @@ inline uint32_t DFHackAPI_InitReadBuildings(DFHackAPIHandle self, vector <string
#ifdef __cplusplus #ifdef __cplusplus
class CDFHackAPI class CDFHackAPI
{ {
DFHackAPIHandle handle; DFHackAPIHandle handle;
public: public:
CDFHackAPI(const string &path_to_xml) CDFHackAPI (const string &path_to_xml)
: handle(CreateDFHackAPI(path_to_xml.c_str())) : handle (CreateDFHackAPI (path_to_xml.c_str()))
{ {
if (handle == NULL) if (handle == NULL)
{ {
// TODO: handle failure // TODO: handle failure
} }
} }
inline ~CDFHackAPI() inline ~CDFHackAPI()
{ {
DestroyDFHackAPI(handle); DestroyDFHackAPI (handle);
handle = NULL; handle = NULL;
} }
inline bool Attach() inline bool Attach()
{ {
return DFHackAPI_Attach(handle); return DFHackAPI_Attach (handle);
} }
inline bool Detach() inline bool Detach()
{ {
return DFHackAPI_Detach(handle); return DFHackAPI_Detach (handle);
} }
inline bool isAttached() inline bool isAttached()
{ {
return DFHackAPI_isAttached(handle); return DFHackAPI_isAttached (handle);
} }
/** /**
* Matgloss. next four methods look very similar. I could use two and move the processing one level up... * Matgloss. next four methods look very similar. I could use two and move the processing one level up...
* I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later. * I'll keep it like this, even with the code duplication as it will hopefully get more features and separate data types later.
* Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces * Yay for nebulous plans for a rock survey tool that tracks how much of which metal could be smelted from available resorces
*/ */
inline bool ReadStoneMatgloss(vector<t_matgloss> & output) inline bool ReadStoneMatgloss (vector<t_matgloss> & output)
{ {
return DFHackAPI_ReadStoneMatgloss(handle, output); return DFHackAPI_ReadStoneMatgloss (handle, output);
} }
inline bool ReadWoodMatgloss (vector<t_matgloss> & output) inline bool ReadWoodMatgloss (vector<t_matgloss> & output)
{ {
return DFHackAPI_ReadWoodMatgloss(handle, output); return DFHackAPI_ReadWoodMatgloss (handle, output);
} }
inline bool ReadMetalMatgloss(vector<t_matgloss> & output) inline bool ReadMetalMatgloss (vector<t_matgloss> & output)
{ {
return DFHackAPI_ReadMetalMatgloss(handle, output); return DFHackAPI_ReadMetalMatgloss (handle, output);
} }
inline bool ReadPlantMatgloss(vector<t_matgloss> & output) inline bool ReadPlantMatgloss (vector<t_matgloss> & output)
{ {
return DFHackAPI_ReadPlantMatgloss(handle, output); return DFHackAPI_ReadPlantMatgloss (handle, output);
} }
// FIXME: add creatures for all the creature products inline bool ReadCreatureMatgloss (vector<t_matgloss> & output)
{
return DFHackAPI_ReadCreatureMatgloss (handle, output);
}
// read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client) // read region surroundings, get their vectors of geolayers so we can do translation (or just hand the translation table to the client)
// returns an array of 9 vectors of indices into stone matgloss // returns an array of 9 vectors of indices into stone matgloss
@ -311,129 +333,146 @@ public:
} }
} }
*/ */
inline bool ReadGeology( vector < vector <uint16_t> >& assign ) inline bool ReadGeology (vector < vector <uint16_t> >& assign)
{ {
return DFHackAPI_ReadGeology(handle, assign); return DFHackAPI_ReadGeology (handle, assign);
} }
/* /*
* BLOCK DATA * BLOCK DATA
*/ */
/// allocate and read pointers to map blocks /// allocate and read pointers to map blocks
inline bool InitMap() inline bool InitMap()
{ {
return DFHackAPI_InitMap(handle); return DFHackAPI_InitMap (handle);
} }
/// destroy the mapblock cache /// destroy the mapblock cache
inline bool DestroyMap() inline bool DestroyMap()
{ {
return DFHackAPI_DestroyMap(handle); return DFHackAPI_DestroyMap (handle);
} }
/// get size of the map in tiles /// get size of the map in tiles
inline void getSize(uint32_t& x, uint32_t& y, uint32_t& z) inline void getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{ {
DFHackAPI_getSize(handle, &x, &y, &z); DFHackAPI_getSize (handle, &x, &y, &z);
} }
/** /**
* Return false/0 on failure, buffer allocated by client app, 256 items long * Return false/0 on failure, buffer allocated by client app, 256 items long
*/ */
inline bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz) inline bool isValidBlock (uint32_t blockx, uint32_t blocky, uint32_t blockz)
{ {
return DFHackAPI_isValidBlock(handle, blockx, blocky, blockz); return DFHackAPI_isValidBlock (handle, blockx, blocky, blockz);
} }
inline bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t) inline bool ReadTileTypes (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t)
{ {
return DFHackAPI_ReadTileTypes(handle, blockx, blocky, blockz, buffer); return DFHackAPI_ReadTileTypes (handle, blockx, blocky, blockz, buffer);
} }
inline bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t) inline bool WriteTileTypes (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer) // 256 * sizeof(uint16_t)
{ {
return DFHackAPI_WriteTileTypes(handle, blockx, blocky, blockz, buffer); return DFHackAPI_WriteTileTypes (handle, blockx, blocky, blockz, buffer);
} }
inline bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t) inline bool ReadDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{ {
return DFHackAPI_ReadDesignations(handle, blockx, blocky, blockz, buffer); return DFHackAPI_ReadDesignations (handle, blockx, blocky, blockz, buffer);
} }
inline bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) inline bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer)
{ {
return DFHackAPI_WriteDesignations(handle, blockx, blocky, blockz, buffer); return DFHackAPI_WriteDesignations (handle, blockx, blocky, blockz, buffer);
} }
inline bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t) inline bool ReadOccupancy (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{ {
return DFHackAPI_ReadOccupancy(handle, blockx, blocky, blockz, buffer); return DFHackAPI_ReadOccupancy (handle, blockx, blocky, blockz, buffer);
} }
inline bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t) inline bool WriteOccupancy (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint32_t *buffer) // 256 * sizeof(uint32_t)
{ {
return DFHackAPI_WriteOccupancy(handle, blockx, blocky, blockz, buffer); return DFHackAPI_WriteOccupancy (handle, blockx, blocky, blockz, buffer);
} }
/// read region offsets of a block /// read region offsets of a block
inline bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) // 16 * sizeof(uint8_t) inline bool ReadRegionOffsets (uint32_t blockx, uint32_t blocky, uint32_t blockz, uint8_t *buffer) // 16 * sizeof(uint8_t)
{ {
return DFHackAPI_ReadRegionOffsets(handle, blockx, blocky, blockz, buffer); return DFHackAPI_ReadRegionOffsets (handle, blockx, blocky, blockz, buffer);
} }
/// read aggregated veins of a block /// read aggregated veins of a block
inline bool ReadVeins(uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins) inline bool ReadVeins (uint32_t blockx, uint32_t blocky, uint32_t blockz, vector <t_vein> & veins)
{ {
return DFHackAPI_ReadVeins(handle, blockx, blocky, blockz, veins); return DFHackAPI_ReadVeins (handle, blockx, blocky, blockz, veins);
} }
/** /**
* Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings * Buildings, constructions, plants, all pretty straighforward. InitReadBuildings returns all the building types as a mapping between a numeric values and strings
*/ */
inline uint32_t InitReadConstructions() inline uint32_t InitReadConstructions()
{ {
return DFHackAPI_InitReadConstructions(handle); return DFHackAPI_InitReadConstructions (handle);
} }
inline bool ReadConstruction(const uint32_t &index, t_construction & construction) inline bool ReadConstruction (const uint32_t &index, t_construction & construction)
{ {
return DFHackAPI_ReadConstruction(handle, &index, & construction); return DFHackAPI_ReadConstruction (handle, &index, & construction);
} }
inline void FinishReadConstructions() inline void FinishReadConstructions()
{ {
DFHackAPI_FinishReadConstructions(handle); DFHackAPI_FinishReadConstructions (handle);
} }
inline uint32_t InitReadBuildings(vector <string> &v_buildingtypes) inline uint32_t InitReadBuildings (vector <string> &v_buildingtypes)
{ {
return DFHackAPI_InitReadBuildings(handle, v_buildingtypes); return DFHackAPI_InitReadBuildings (handle, v_buildingtypes);
} }
inline bool ReadBuilding(const uint32_t &index, t_building & building) inline bool ReadBuilding (const uint32_t &index, t_building & building)
{ {
return DFHackAPI_ReadBuilding(handle, &index, &building); return DFHackAPI_ReadBuilding (handle, &index, &building);
} }
inline void FinishReadBuildings() inline void FinishReadBuildings()
{ {
DFHackAPI_FinishReadBuildings(handle); DFHackAPI_FinishReadBuildings (handle);
} }
inline uint32_t InitReadVegetation() inline uint32_t InitReadVegetation()
{ {
return DFHackAPI_InitReadVegetation(handle); return DFHackAPI_InitReadVegetation (handle);
} }
inline bool ReadVegetation(const uint32_t &index, t_tree_desc & shrubbery) inline bool ReadVegetation (const uint32_t &index, t_tree_desc & shrubbery)
{ {
return DFHackAPI_ReadVegetation(handle, &index, &shrubbery); return DFHackAPI_ReadVegetation (handle, &index, &shrubbery);
} }
inline void FinishReadVegetation() inline void FinishReadVegetation()
{ {
DFHackAPI_FinishReadVegetation(handle); DFHackAPI_FinishReadVegetation (handle);
} }
inline uint32_t InitReadCreatures()
{
return DFHackAPI_InitReadCreatures (handle);
}
inline bool ReadCreature (const uint32_t &index, t_creature & furball)
{
return DFHackAPI_ReadCreature (handle, &index, &furball);
}
inline void FinishReadCreatures()
{
DFHackAPI_FinishReadCreatures (handle);
}
}; };
#endif // __cplusplus #endif // __cplusplus

@ -87,7 +87,10 @@
<!-- creature offsets --> <!-- creature offsets -->
<Offset name="creature_position">0x94</Offset> <Offset name="creature_position">0x94</Offset>
<Offset name="creature_profession">0x88</Offset>
<Offset name="creature_type">0x8C</Offset> <Offset name="creature_type">0x8C</Offset>
<Offset name="creature_flags1">0xE4</Offset>
<Offset name="creature_flags2">0xE8</Offset>
<!-- tree and shrub offsets --> <!-- tree and shrub offsets -->
<Offset name="tree_desc_offset">0x70</Offset> <Offset name="tree_desc_offset">0x70</Offset>
@ -217,6 +220,10 @@
<Address name="vegetation">0x014F4B4C</Address> <Address name="vegetation">0x014F4B4C</Address>
<Address name="creatures">0x014edfcc</Address> <Address name="creatures">0x014edfcc</Address>
<!-- creature offsets -->
<Offset name="creature_flags1">0xFC</Offset>
<Offset name="creature_flags2">0x100</Offset>
<!-- tree and shrub offsets --> <!-- tree and shrub offsets -->
<Offset name="tree_desc_offset">0x70</Offset> <Offset name="tree_desc_offset">0x70</Offset>