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
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
warranty. In no event will the authors be held liable for any
@ -47,7 +47,8 @@ distribution.
#endif
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
// The C interface for vector management
@ -172,6 +173,20 @@ DFHACKAPI bool DFHackAPI_ReadPlantMatgloss(DFHackAPIHandle self, DFHackAPIVector
return retn;
}
DFHACKAPI bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output)
{
vector<t_matgloss> result;
uint32_t i;
bool retn = self->ReadCreatureMatgloss (result);
output->type = DFHackAPIVectorTypeC_Matgloss;
output->length = result.size();
output->data = new t_matgloss[output->length];
for (i = 0; i < output->length; i++)
( (t_matgloss *) output->data) [i] = result[i];
return retn;
}
DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign)
{
vector< vector<uint16_t> > result;
@ -323,6 +338,21 @@ 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
}
#endif

@ -1,6 +1,6 @@
/*
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
warranty. In no event will the authors be held liable for any
@ -49,7 +49,8 @@ distribution.
using namespace std;
#endif
typedef enum DFHackAPIVectorTypeC {
typedef enum DFHackAPIVectorTypeC
{
DFHackAPIVectorTypeC_Normal, // array of struct's
DFHackAPIVectorTypeC_Matgloss, // array of t_matgloss's
DFHackAPIVectorTypeC_Uint16, // array of uint16_t's
@ -59,7 +60,8 @@ typedef enum DFHackAPIVectorTypeC {
DFHackAPIVectorTypeC_DWord = 0xffffffff // Unused
} DFHackAPIVectorTypeC;
typedef struct DFHackAPIVectorC {
typedef struct DFHackAPIVectorC
{
void *data;
uint32_t length;
DFHackAPIVectorTypeC type;
@ -73,7 +75,8 @@ typedef char bool;
#endif
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif // __cplusplus
// The C interface for vector management
@ -91,6 +94,7 @@ DFHACKAPI bool DFHackAPI_ReadStoneMatgloss(DFHackAPIHandle self, DFHackAPIVector
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_ReadCreatureMatgloss (DFHackAPIHandle self, DFHackAPIVectorC *output);
DFHACKAPI bool DFHackAPI_ReadGeology (DFHackAPIHandle self, DFHackAPIVectorC *assign);
@ -126,6 +130,10 @@ DFHACKAPI uint32_t DFHackAPI_InitReadVegetation(DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadVegetation (DFHackAPIHandle self, const uint32_t *index, t_tree_desc * shrubbery);
DFHACKAPI void DFHackAPI_FinishReadVegetation (DFHackAPIHandle self);
DFHACKAPI uint32_t DFHackAPI_InitReadCreatures (DFHackAPIHandle self);
DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball);
DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self);
#ifdef __cplusplus
}
#endif // __cplusplus
@ -176,6 +184,17 @@ inline bool DFHackAPI_ReadPlantMatgloss(DFHackAPIHandle self, vector<t_matgloss>
return result;
}
inline bool DFHackAPI_ReadCreatureMatgloss (DFHackAPIHandle self, vector<t_matgloss> & output)
{
DFHackAPIVectorC vector;
bool result = DFHackAPI_ReadCreatureMatgloss (self, &vector);
uint32_t i;
for (i = 0; i < vector.length; i++)
output.push_back ( ( (t_matgloss *) vector.data) [i]);
DFHackAPIVector_free (&vector);
return result;
}
inline bool DFHackAPI_ReadGeology (DFHackAPIHandle self, vector< vector<uint16_t> > &assign)
{
DFHackAPIVectorC vec;
@ -278,7 +297,10 @@ public:
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)
// returns an array of 9 vectors of indices into stone matgloss
@ -434,6 +456,23 @@ public:
{
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

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