develop
Petr Mrázek 2011-03-14 22:06:25 +01:00
commit 2ea6a3d84a
9 changed files with 275 additions and 59 deletions

@ -82,12 +82,14 @@ int (*alloc_matgloss_buffer_callback)(t_matgloss**, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t) = NULL; int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t) = NULL;
int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t) = NULL; int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t) = NULL;
int (*alloc_t_feature_buffer_callback)(t_feature**, uint32_t) = NULL; int (*alloc_feature_buffer_callback)(t_feature**, uint32_t) = NULL;
int (*alloc_t_hotkey_buffer_callback)(t_hotkey**, uint32_t) = NULL; int (*alloc_hotkey_buffer_callback)(t_hotkey**, uint32_t) = NULL;
int (*alloc_t_screen_buffer_callback)(t_screen**, uint32_t) = NULL; int (*alloc_screen_buffer_callback)(t_screen**, uint32_t) = NULL;
int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t) = NULL; int (*alloc_tree_buffer_callback)(t_tree**, uint32_t) = NULL;
int (*alloc_t_material_buffer_callback)(t_material**, uint32_t) = NULL;
int (*alloc_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t) = NULL;
int (*alloc_material_buffer_callback)(t_material**, uint32_t) = NULL;
int (*alloc_creaturetype_buffer_callback)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t) = NULL; int (*alloc_creaturetype_buffer_callback)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t) = NULL;
@ -97,6 +99,8 @@ int (*alloc_spattervein_buffer_callback)(t_spattervein**, uint32_t) = NULL;
int (*alloc_grassvein_buffer_callback)(t_grassvein**, uint32_t) = NULL; int (*alloc_grassvein_buffer_callback)(t_grassvein**, uint32_t) = NULL;
int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction**, uint32_t) = NULL; int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction**, uint32_t) = NULL;
int (*alloc_featuremap_buffer_callback)(c_featuremap_node**, uint32_t*, uint32_t) = NULL;
//int (*alloc_bodypart_buffer_callback)(t_bodypart**, uint32_t) = NULL; //int (*alloc_bodypart_buffer_callback)(t_bodypart**, uint32_t) = NULL;
REG_MACRO(Byte, int8_t**, alloc_byte_buffer_callback) REG_MACRO(Byte, int8_t**, alloc_byte_buffer_callback)
REG_MACRO(Short, int16_t**, alloc_short_buffer_callback) REG_MACRO(Short, int16_t**, alloc_short_buffer_callback)
@ -108,11 +112,12 @@ REG_MACRO(Char, char**, alloc_char_buffer_callback)
REG_MACRO(Matgloss, t_matgloss**, alloc_matgloss_buffer_callback) REG_MACRO(Matgloss, t_matgloss**, alloc_matgloss_buffer_callback)
REG_MACRO(DescriptorColor, t_descriptor_color**, alloc_descriptor_buffer_callback) REG_MACRO(DescriptorColor, t_descriptor_color**, alloc_descriptor_buffer_callback)
REG_MACRO(MatglossOther, t_matglossOther**, alloc_matgloss_other_buffer_callback) REG_MACRO(MatglossOther, t_matglossOther**, alloc_matgloss_other_buffer_callback)
REG_MACRO(Feature, t_feature**, alloc_t_feature_buffer_callback) REG_MACRO(Feature, t_feature**, alloc_feature_buffer_callback)
REG_MACRO(Hotkey, t_hotkey**, alloc_t_hotkey_buffer_callback) REG_MACRO(Hotkey, t_hotkey**, alloc_hotkey_buffer_callback)
REG_MACRO(Screen, t_screen**, alloc_t_screen_buffer_callback) REG_MACRO(Screen, t_screen**, alloc_screen_buffer_callback)
REG_MACRO(CustomWorkshop, t_customWorkshop**, alloc_t_customWorkshop_buffer_callback) REG_MACRO(Tree, t_tree**, alloc_tree_buffer_callback)
REG_MACRO(Material, t_material**, alloc_t_material_buffer_callback) REG_MACRO(CustomWorkshop, t_customWorkshop**, alloc_customWorkshop_buffer_callback)
REG_MACRO(Material, t_material**, alloc_material_buffer_callback)
UNREG_MACRO(Byte, alloc_byte_buffer_callback) UNREG_MACRO(Byte, alloc_byte_buffer_callback)
UNREG_MACRO(Short, alloc_short_buffer_callback) UNREG_MACRO(Short, alloc_short_buffer_callback)
@ -124,11 +129,12 @@ UNREG_MACRO(Char, alloc_char_buffer_callback)
UNREG_MACRO(Matgloss, alloc_matgloss_buffer_callback) UNREG_MACRO(Matgloss, alloc_matgloss_buffer_callback)
UNREG_MACRO(DescriptorColor, alloc_descriptor_buffer_callback) UNREG_MACRO(DescriptorColor, alloc_descriptor_buffer_callback)
UNREG_MACRO(MatglossOther, alloc_matgloss_other_buffer_callback) UNREG_MACRO(MatglossOther, alloc_matgloss_other_buffer_callback)
UNREG_MACRO(Feature, alloc_t_feature_buffer_callback) UNREG_MACRO(Feature, alloc_feature_buffer_callback)
UNREG_MACRO(Hotkey, alloc_t_hotkey_buffer_callback) UNREG_MACRO(Hotkey, alloc_hotkey_buffer_callback)
UNREG_MACRO(Screen, alloc_t_screen_buffer_callback) UNREG_MACRO(Screen, alloc_screen_buffer_callback)
UNREG_MACRO(CustomWorkshop, alloc_t_customWorkshop_buffer_callback) UNREG_MACRO(Tree, alloc_tree_buffer_callback)
UNREG_MACRO(Material, alloc_t_material_buffer_callback) UNREG_MACRO(CustomWorkshop, alloc_customWorkshop_buffer_callback)
UNREG_MACRO(Material, alloc_material_buffer_callback)
void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t)) void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturetype**, c_creaturetype_descriptor*, uint32_t))
{ {
@ -149,6 +155,13 @@ UNREG_MACRO(SpatterVein, alloc_spattervein_buffer_callback)
UNREG_MACRO(GrassVein, alloc_grassvein_buffer_callback) UNREG_MACRO(GrassVein, alloc_grassvein_buffer_callback)
UNREG_MACRO(WorldConstruction, alloc_worldconstruction_buffer_callback) UNREG_MACRO(WorldConstruction, alloc_worldconstruction_buffer_callback)
void RegisterFeatureMapBufferCallback(int (*funcptr)(c_featuremap_node**, uint32_t*, uint32_t))
{
alloc_featuremap_buffer_callback = funcptr;
}
UNREG_MACRO(FeatureMap, alloc_featuremap_buffer_callback)
int DFHack_isWallTerrain(int in) int DFHack_isWallTerrain(int in)
{ {
return DFHack::isWallTerrain(in); return DFHack::isWallTerrain(in);

@ -55,9 +55,11 @@ DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss**, uint32_
DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t); DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color**, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t); DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_feature_buffer_callback)(t_feature**, uint32_t); DFHACK_EXPORT extern int (*alloc_feature_buffer_callback)(t_feature**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_hotkey_buffer_callback)(t_hotkey**, uint32_t); DFHACK_EXPORT extern int (*alloc_hotkey_buffer_callback)(t_hotkey**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_screen_buffer_callback)(t_screen**, uint32_t); DFHACK_EXPORT extern int (*alloc_screen_buffer_callback)(t_screen**, uint32_t);
DFHACK_EXPORT extern int (*alloc_tree_buffer_callback)(t_tree**, uint32_t);
DFHACK_EXPORT void RegisterByteBufferCallback(int (*funcptr)(int8_t**, uint32_t)); DFHACK_EXPORT void RegisterByteBufferCallback(int (*funcptr)(int8_t**, uint32_t));
DFHACK_EXPORT void RegisterShortBufferCallback(int (*funcptr)(int16_t**, uint32_t)); DFHACK_EXPORT void RegisterShortBufferCallback(int (*funcptr)(int16_t**, uint32_t));
@ -77,6 +79,8 @@ DFHACK_EXPORT void RegisterFeatureBufferCallback(int (*funcptr)(t_feature**, uin
DFHACK_EXPORT void RegisterHotkeyBufferCallback(int (*funcptr)(t_hotkey**, uint32_t)); DFHACK_EXPORT void RegisterHotkeyBufferCallback(int (*funcptr)(t_hotkey**, uint32_t));
DFHACK_EXPORT void RegisterScreenBufferCallback(int (*funcptr)(t_screen**, uint32_t)); DFHACK_EXPORT void RegisterScreenBufferCallback(int (*funcptr)(t_screen**, uint32_t));
DFHACK_EXPORT void RegisterTreeBufferCallback(int (*funcptr)(t_tree**, uint32_t));
HUNREG_MACRO(Byte) HUNREG_MACRO(Byte)
HUNREG_MACRO(Short) HUNREG_MACRO(Short)
HUNREG_MACRO(Int) HUNREG_MACRO(Int)
@ -94,14 +98,16 @@ HUNREG_MACRO(Feature)
HUNREG_MACRO(Hotkey) HUNREG_MACRO(Hotkey)
HUNREG_MACRO(Screen) HUNREG_MACRO(Screen)
HUNREG_MACRO(Tree)
struct t_customWorkshop struct t_customWorkshop
{ {
uint32_t index; uint32_t index;
char name[256]; char name[256];
}; };
DFHACK_EXPORT extern int (*alloc_t_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t); DFHACK_EXPORT extern int (*alloc_customWorkshop_buffer_callback)(t_customWorkshop**, uint32_t);
DFHACK_EXPORT extern int (*alloc_t_material_buffer_callback)(t_material**, uint32_t); DFHACK_EXPORT extern int (*alloc_material_buffer_callback)(t_material**, uint32_t);
DFHACK_EXPORT void RegisterCustomWorkshopBufferCallback(int (*funcptr)(t_customWorkshop**, uint32_t)); DFHACK_EXPORT void RegisterCustomWorkshopBufferCallback(int (*funcptr)(t_customWorkshop**, uint32_t));
DFHACK_EXPORT void RegisterMaterialBufferCallback(int (*funcptr)(t_material**, uint32_t)); DFHACK_EXPORT void RegisterMaterialBufferCallback(int (*funcptr)(t_material**, uint32_t));
@ -213,6 +219,37 @@ HUNREG_MACRO(SpatterVein)
HUNREG_MACRO(GrassVein) HUNREG_MACRO(GrassVein)
HUNREG_MACRO(WorldConstruction) HUNREG_MACRO(WorldConstruction)
struct c_mapcoord
{
union
{
struct
{
uint16_t x;
uint16_t y;
uint32_t z;
};
struct
{
uint16_t x;
uint16_t y;
} dim;
uint64_t comparate;
};
};
struct c_featuremap_node
{
c_mapcoord coordinate;
t_feature* features;
uint32_t feature_length;
};
DFHACK_EXPORT extern int (*alloc_featuremap_buffer_callback)(c_featuremap_node**, uint32_t*, uint32_t);
DFHACK_EXPORT void RegisterFeatureMapBufferCallback(int (*funcptr)(c_featuremap_node**, uint32_t*, uint32_t));
DFHACK_EXPORT int DFHack_isWallTerrain(int in); DFHACK_EXPORT int DFHack_isWallTerrain(int in);
DFHACK_EXPORT int DFHack_isFloorTerrain(int in); DFHACK_EXPORT int DFHack_isFloorTerrain(int in);
DFHACK_EXPORT int DFHack_isRampTerrain(int in); DFHACK_EXPORT int DFHack_isRampTerrain(int in);

@ -39,6 +39,7 @@ DFHACK_EXPORT int Maps_Finish(DFHackObject* maps);
DFHACK_EXPORT uint16_t* Maps_ReadGeology(DFHackObject* maps); DFHACK_EXPORT uint16_t* Maps_ReadGeology(DFHackObject* maps);
DFHACK_EXPORT t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps); DFHACK_EXPORT t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps);
DFHACK_EXPORT c_featuremap_node* Maps_ReadLocalFeatures(DFHackObject* maps);
DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z); DFHACK_EXPORT void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z);
DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
@ -90,6 +91,8 @@ typedef struct
DFHACK_EXPORT int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, c_allveins* vein_struct); DFHACK_EXPORT int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, c_allveins* vein_struct);
DFHACK_EXPORT t_tree* Maps_ReadVegetation(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -81,7 +81,7 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr)
if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes)) if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes))
return NULL; return NULL;
(*alloc_t_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size()); (*alloc_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size());
if(cw_Ptr == NULL) if(cw_Ptr == NULL)
return NULL; return NULL;

@ -86,7 +86,7 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball)
t_material* buf = NULL; t_material* buf = NULL;
(*alloc_t_material_buffer_callback)(&buf, mat.size()); (*alloc_material_buffer_callback)(&buf, mat.size());
if(buf != NULL) if(buf != NULL)
{ {

@ -24,6 +24,7 @@ distribution.
#include "dfhack/DFPragma.h" #include "dfhack/DFPragma.h"
#include <vector> #include <vector>
#include <map>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
@ -74,7 +75,7 @@ uint16_t* Maps_ReadGeology(DFHackObject* maps)
} }
} }
(*alloc_ushort_buffer_callback)(buf, geoLength); ((*alloc_ushort_buffer_callback)(buf, geoLength));
if(buf != NULL) if(buf != NULL)
{ {
@ -110,7 +111,7 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
t_feature** buf = NULL; t_feature** buf = NULL;
(*alloc_t_feature_buffer_callback)(buf, featureVec.size()); ((*alloc_feature_buffer_callback)(buf, featureVec.size()));
if(buf != NULL) if(buf != NULL)
{ {
@ -128,6 +129,54 @@ t_feature* Maps_ReadGlobalFeatures(DFHackObject* maps)
return NULL; return NULL;
} }
c_featuremap_node* Maps_ReadLocalFeatures(DFHackObject* maps)
{
if(maps != NULL)
{
std::map <DFCoord, std::vector<t_feature *> > local_features;
std::map <DFCoord, std::vector<t_feature *> >::iterator iterate;
uint32_t i;
if(((DFHack::Maps*)maps)->ReadLocalFeatures(local_features))
{
if(local_features.empty() == true)
return NULL;
c_featuremap_node* featuremap;
uint32_t* featuremap_size = (uint32_t*)calloc(local_features.size(), sizeof(uint32_t));
for(i = 0, iterate = local_features.begin(); iterate != local_features.end(); i++, iterate++)
featuremap_size[i] = (*iterate).second.size();
((*alloc_featuremap_buffer_callback)(&featuremap, featuremap_size, local_features.size()));
free(featuremap_size);
if(featuremap == NULL)
return NULL;
for(i = 0, iterate = local_features.begin(); iterate != local_features.end(); i++, iterate++)
{
uint32_t j;
featuremap[i].coordinate.comparate = (*iterate).first.comparate;
for(j = 0; j < (*iterate).second.size(); j++)
featuremap[i].features[j] = *((*iterate).second[j]);
//copy((*iterate).second.begin(), (*iterate).second.end(), featuremap[i].features);
featuremap[i].feature_length = (*iterate).second.size();
}
return featuremap;
}
else
return NULL;
}
return NULL;
}
void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z)
{ {
if(maps != NULL) if(maps != NULL)
@ -615,6 +664,34 @@ int Maps_ReadAllVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, c_
return -1; return -1;
} }
t_tree* Maps_ReadVegetation(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps == NULL)
return NULL;
else
{
std::vector<t_tree> plants;
bool result = ((DFHack::Maps*)maps)->ReadVegetation(x, y, z, &plants);
t_tree* buf = NULL;
if(!result || plants.size() <= 0)
return NULL;
else
{
((*alloc_tree_buffer_callback)(&buf, plants.size()));
if(buf == NULL)
return NULL;
copy(plants.begin(), plants.end(), buf);
return buf;
}
}
return NULL;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -104,7 +104,7 @@ t_hotkey* Position_ReadHotkeys(DFHackObject* pos)
{ {
t_hotkey* buf = NULL; t_hotkey* buf = NULL;
(*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); (*alloc_hotkey_buffer_callback)(&buf, NUM_HOTKEYS);
if(buf != NULL) if(buf != NULL)
{ {
@ -146,7 +146,7 @@ t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t heig
{ {
t_screen* buf = NULL; t_screen* buf = NULL;
(*alloc_t_screen_buffer_callback)(&buf, width * height); (*alloc_screen_buffer_callback)(&buf, width * height);
if(buf == NULL) if(buf == NULL)
return NULL; return NULL;

@ -49,13 +49,19 @@ class Position2D(Structure):
_fields_ = [("x", c_ushort), _fields_ = [("x", c_ushort),
("y", c_ushort)] ("y", c_ushort)]
class Position3d(Structure):
_fields_ = [("x", c_ushort),
("y", c_ushort),
("z", c_uint)]
class PlaneCoord(Union): class PlaneCoord(Union):
_fields_ = [("xy", c_uint), _fields_ = [("xyz", Position3D),
("dim", Position2D)] ("dim", Position2D),
("comparate", c_ulong)]
def __cmp__(self, other): def __cmp__(self, other):
if isinstance(other, PlaneCoord): if isinstance(other, PlaneCoord):
return self.xy - other.xy return self.comparate - other.comparate
else: else:
raise TypeError("argument must be of type %s" % type(self)) raise TypeError("argument must be of type %s" % type(self))
@ -66,6 +72,35 @@ class Feature(Structure):
("discovered", c_byte), ("discovered", c_byte),
("origin", c_uint)] ("origin", c_uint)]
class FeatureMapNode(Structure):
_fields_ = [("coordinate", PlaneCoord),
("features", POINTER(Feature)),
("feature_length", c_uint)]
def _alloc_featuremap_buffer_callback(ptr, fmap_list, count):
arr_list = []
arr = (FeatureMapNode * count)()
for i, v in enumerate(arr):
f_count = int(fmap_list[i])
f_arr = (Feature * f_count)()
f_p = cast(f_arr, POINTER(Feature))
v.features = f_p
arr_list.extend((f_arr, f_p))
p = cast(arr, POINTER(FeatureMapNode))
ptr[0] = p
pointer_dict[addressof(arr)] = (ptr, arr, p, arr_list)
return 1
_alloc_featuremap_buffer_functype = CFUNCTYPE(c_int, POINTER(POINTER(FeatureMapNode)), uint_ptr, c_uint)
_alloc_featuremap_buffer_func = _alloc_featuremap_buffer_functype(_alloc_featuremap_buffer_callback)
_register_callback("alloc_featuremap_buffer_callback", _alloc_featuremap_buffer_func)
class Vein(Structure): class Vein(Structure):
_fields_ = [("vtable", c_uint), _fields_ = [("vtable", c_uint),
("type", c_int), ("type", c_int),
@ -188,7 +223,7 @@ class DescriptorColor(Structure):
def _alloc_descriptor_buffer_callback(ptr, count): def _alloc_descriptor_buffer_callback(ptr, count):
return util._allocate_array(ptr, DescriptorColor, count) return util._allocate_array(ptr, DescriptorColor, count)
_descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint) _descriptor_functype = CFUNCTYPE(c_int, POINTER(POINTER(DescriptorColor)), c_uint)
_descriptor_func = _descriptor_functype(_alloc_descriptor_buffer_callback) _descriptor_func = _descriptor_functype(_alloc_descriptor_buffer_callback)
_register_callback("alloc_descriptor_buffer_callback", _descriptor_func) _register_callback("alloc_descriptor_buffer_callback", _descriptor_func)
@ -205,10 +240,10 @@ class MatglossPlant(Structure):
class MatglossOther(Structure): class MatglossOther(Structure):
_fields_ = [("rawname", c_char * 128)] _fields_ = [("rawname", c_char * 128)]
def _alloc_matgloss_other_buffer_callback(count): def _alloc_matgloss_other_buffer_callback(ptr, count):
return util._allocate_array(ptr, MatglossOther, count) return util._allocate_array(ptr, MatglossOther, count)
_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint) _matgloss_other_functype = CFUNCTYPE(c_int, POINTER(POINTER(MatglossOther)), c_uint)
_matgloss_other_func = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback) _matgloss_other_func = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback)
_register_callback("alloc_matgloss_other_buffer_callback", _matgloss_other_func) _register_callback("alloc_matgloss_other_buffer_callback", _matgloss_other_func)
@ -227,12 +262,12 @@ class CustomWorkshop(Structure):
_fields_ = [("index", c_uint), _fields_ = [("index", c_uint),
("name", c_char * 256)] ("name", c_char * 256)]
def _alloc_custom_workshop_buffer_callback(count): def _alloc_custom_workshop_buffer_callback(ptr, count):
return util._allocate_array(ptr, CustomWorkshop, count) return util._allocate_array(ptr, CustomWorkshop, count)
_custom_workshop_functype = CFUNCTYPE(c_int, POINTER(CustomWorkshop), c_uint) _custom_workshop_functype = CFUNCTYPE(c_int, POINTER(POINTER(CustomWorkshop)), c_uint)
_custom_workshop_func = _custom_workshop_functype(_alloc_custom_workshop_buffer_callback) _custom_workshop_func = _custom_workshop_functype(_alloc_custom_workshop_buffer_callback)
_register_callback("alloc_t_customWorkshop_buffer_callback", _custom_workshop_func) _register_callback("alloc_customWorkshop_buffer_callback", _custom_workshop_func)
class Construction(Structure): class Construction(Structure):
_fields_ = [("x", c_ushort), _fields_ = [("x", c_ushort),
@ -256,6 +291,26 @@ class Tree(Structure):
("z", c_ushort), ("z", c_ushort),
("address", c_uint)] ("address", c_uint)]
def __str__(self):
water = ""
tree_type = "tree"
if self.type == 1 or self.type == 3:
water = "near-water"
if self.type == 2 or self.type == 3:
tree_type = "shrub"
s = "%d:%d = %s %s\nAddress: 0x%x\n" % (self.type, self.material, water, tree_type, self.address)
return s
def _alloc_tree_buffer_callback(ptr, count):
return util._allocate_array(ptr, Tree, count)
_alloc_tree_buffer_functype = CFUNCTYPE(c_int, POINTER(POINTER(Tree)), c_uint)
_alloc_tree_buffer_func = _alloc_tree_buffer_functype(_alloc_tree_buffer_callback)
_register_callback("alloc_tree_buffer_callback", _alloc_tree_buffer_func)
class Material(Structure): class Material(Structure):
_fields_ = [("itemType", c_short), _fields_ = [("itemType", c_short),
("subType", c_short), ("subType", c_short),
@ -263,12 +318,12 @@ class Material(Structure):
("index", c_int), ("index", c_int),
("flags", c_uint)] ("flags", c_uint)]
def _alloc_material_buffer_callback(count): def _alloc_material_buffer_callback(ptr, count):
return util._allocate_array(ptr, Material, count) return util._allocate_array(ptr, Material, count)
_material_functype = CFUNCTYPE(c_int, POINTER(Material), c_uint) _material_functype = CFUNCTYPE(c_int, POINTER(POINTER(Material)), c_uint)
_material_func = _material_functype(_alloc_material_buffer_callback) _material_func = _material_functype(_alloc_material_buffer_callback)
_register_callback("alloc_t_material_buffer_callback", _material_func) _register_callback("alloc_material_buffer_callback", _material_func)
class Skill(Structure): class Skill(Structure):
_fields_ = [("id", c_uint), _fields_ = [("id", c_uint),
@ -513,7 +568,6 @@ def _alloc_creaturetype_buffer(ptr, descriptors, count):
p = cast(c_arr, _creaturetype_ptr) p = cast(c_arr, _creaturetype_ptr)
ptr[0] = p ptr[0] = p
print ""
pointer_dict[addressof(c_arr)] = (ptr, c_arr, p, arr_list) pointer_dict[addressof(c_arr)] = (ptr, c_arr, p, arr_list)

@ -17,17 +17,21 @@ libdfhack.Maps_WriteTemperatures.argtypes = [ c_void_p, c_uint, c_uint, c_uint,
libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ]
libdfhack.Maps_WriteOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ] libdfhack.Maps_WriteOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Occupancies40d) ]
libdfhack.Maps_ReadRegionOffsets.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(BiomeIndices40d) ] libdfhack.Maps_ReadRegionOffsets.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(BiomeIndices40d) ]
libdfhack.Maps_ReadVegetation.argtypes = _default_argtypes
libdfhack.Maps_ReadVegetation.restype = c_void_p
libdfhack.Maps_ReadStandardVeins.argtypes = _default_argtypes libdfhack.Maps_ReadStandardVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadFrozenVeins.argtypes = _default_argtypes libdfhack.Maps_ReadFrozenVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadSpatterVeins.argtypes = _default_argtypes libdfhack.Maps_ReadSpatterVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadGrassVeins.argtypes = _default_argtypes libdfhack.Maps_ReadGrassVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadWorldConstructions.argtypes = _default_argtypes libdfhack.Maps_ReadWorldConstructions.argtypes = _default_argtypes
libdfhack.Maps_ReadStandardVeins.restype = POINTER(Vein) libdfhack.Maps_ReadStandardVeins.restype = c_void_p
libdfhack.Maps_ReadFrozenVeins.restype = POINTER(FrozenLiquidVein) libdfhack.Maps_ReadFrozenVeins.restype = c_void_p
libdfhack.Maps_ReadSpatterVeins.restype = POINTER(SpatterVein) libdfhack.Maps_ReadSpatterVeins.restype = c_void_p
libdfhack.Maps_ReadGrassVeins.restype = POINTER(GrassVein) libdfhack.Maps_ReadGrassVeins.restype = c_void_p
libdfhack.Maps_ReadWorldConstructions.restype = POINTER(WorldConstruction) libdfhack.Maps_ReadWorldConstructions.restype = c_void_p
class Maps(object): class Maps(object):
def __init__(self, ptr): def __init__(self, ptr):
@ -171,9 +175,9 @@ class Maps(object):
veins_ptr = libdfhack.Maps_ReadStandardVeins(self._map_ptr, ux, uy, uz) veins_ptr = libdfhack.Maps_ReadStandardVeins(self._map_ptr, ux, uy, uz)
veins = None veins = None
if id(veins_ptr) in dftypes.pointer_dict: if veins_ptr in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1] veins = [i for i in dftypes.pointer_dict[veins_ptr][1]]
del dftypes.pointer_dict[id(veins_ptr)] del dftypes.pointer_dict[veins_ptr]
return veins return veins
@ -183,9 +187,9 @@ class Maps(object):
veins_ptr = libdfhack.Maps_ReadFrozenVeins(self._map_ptr, ux, uy, uz) veins_ptr = libdfhack.Maps_ReadFrozenVeins(self._map_ptr, ux, uy, uz)
veins = None veins = None
if id(veins_ptr) in dftypes.pointer_dict: if veins_ptr in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1] veins = [i for i in dftypes.pointer_dict[veins_ptr][1]]
del dftypes.pointer_dict[id(veins_ptr)] del dftypes.pointer_dict[veins_ptr]
return veins return veins
@ -195,9 +199,9 @@ class Maps(object):
veins_ptr = libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz) veins_ptr = libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz)
veins = None veins = None
if id(veins_ptr) in dftypes.pointer_dict: if veins_ptr in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1] veins = [i for i in dftypes.pointer_dict[veins_ptr][1]]
del dftypes.pointer_dict[id(veins_ptr)] del dftypes.pointer_dict[veins_ptr]
return veins return veins
@ -207,9 +211,9 @@ class Maps(object):
veins_ptr = libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz) veins_ptr = libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz)
veins = None veins = None
if id(veins_ptr) in dftypes.pointer_dict: if veins_ptr in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1] veins = [i for i in dftypes.pointer_dict[veins_ptr][1]]
del dftypes.pointer_dict[id(veins_ptr)] del dftypes.pointer_dict[veins_ptr]
return veins return veins
@ -219,12 +223,40 @@ class Maps(object):
veins_ptr = libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz) veins_ptr = libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz)
veins = None veins = None
if id(veins_ptr) in dftypes.pointer_dict: if veins_ptr in dftypes.pointer_dict:
veins = dftypes.pointer_dict[id(veins_ptr)][1] veins = [i for i in dftypes.pointer_dict[veins_ptr][1]]
del dftypes.pointer_dict[id(veins_ptr)] del dftypes.pointer_dict[veins_ptr]
return veins return veins
def read_vegetation(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
veg_ptr = libdfhack.Maps_ReadVegetation(self._map_ptr, ux, uy, uz)
veg = None
if veg_ptr in dftypes.pointer_dict:
veg = [i for i in dftypes.pointer_dict[veg_ptr][1]]
del dftypes.pointer_dict[veg_ptr]
def read_local_features(self):
f = libdfhack.Maps_ReadLocalFeatures(self._map_ptr)
feature_dict = {}
f_arr = None
if f in dftypes.pointer_dict:
f_arr = dftypes.pointer_dict[f][1]
del dftypes.pointer_dict[f]
if f_arr is not None:
for node in f_arr:
c = node.coordinate.xyz
coord = MapPoint(c.x, c.y, c.z)
f_list = [node.features[i] for i in xrange(node.feature_length)]
feature_dict[coord] = f_list
return feature_dict
@property @property
def size(self): def size(self):
x = c_uint() x = c_uint()