Merge branch 'master' of git://github.com/peterix/dfhack

develop
Simon Jackson 2010-07-15 12:58:25 +01:00
commit 9bafefbd80
6 changed files with 212 additions and 1 deletions

@ -67,6 +67,40 @@ int (*alloc_empty_creaturetype_callback)(c_creaturetype*) = NULL;
int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL; int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL; int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL;
int (*alloc_vein_buffer_callback)(t_vein*, uint32_t) = NULL;
int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t) = NULL;
int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t) = NULL;
int DFHack_isWallTerrain(int in)
{
return DFHack::isWallTerrain(in);
}
int DFHack_isFloorTerrain(int in)
{
return DFHack::isFloorTerrain(in);
}
int DFHack_isRampTerrain(int in)
{
return DFHack::isRampTerrain(in);
}
int DFHack_isStairTerrain(int in)
{
return DFHack::isStairTerrain(in);
}
int DFHack_isOpenTerrain(int in)
{
return DFHack::isOpenTerrain(in);
}
int DFHack_getVegetationType(int in)
{
return DFHack::getVegetationType(in);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -27,6 +27,7 @@ distribution.
#include "DFHack_C.h" #include "DFHack_C.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -100,6 +101,17 @@ DFHACK_EXPORT extern int (*alloc_empty_creaturetype_callback)(c_creaturetype*);
DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t); DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t); DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t);
DFHACK_EXPORT extern int (*alloc_vein_buffer_callback)(t_vein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_frozenliquidvein_buffer_callback)(t_frozenliquidvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_spattervein_buffer_callback)(t_spattervein*, uint32_t);
DFHACK_EXPORT extern int DFHack_isWallTerrain(int in);
DFHACK_EXPORT extern int DFHack_isFloorTerrain(int in);
DFHACK_EXPORT extern int DFHack_isRampTerrain(int in);
DFHACK_EXPORT extern int DFHack_isStairTerrain(int in);
DFHACK_EXPORT extern int DFHack_isOpenTerrain(int in);
DFHACK_EXPORT extern int DFHack_getVegetationType(int in);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -69,6 +69,10 @@ DFHACK_EXPORT int Maps_WriteBlockFlags(DFHackObject* maps, uint32_t x, uint32_t
DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, biome_indices40d* buffer); DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z, biome_indices40d* buffer);
DFHACK_EXPORT t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -22,6 +22,12 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
#include <vector>
#include <algorithm>
using namespace std;
#include "dfhack-c/DFTypes_C.h"
#include "dfhack-c/modules/Maps_C.h" #include "dfhack-c/modules/Maps_C.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -268,6 +274,98 @@ int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t
return -1; return -1;
} }
t_vein* Maps_ReadStandardVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_vein_buffer_callback == NULL)
return NULL;
vector<t_vein> veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins);
if(result)
{
t_vein* v_buf = NULL;
if(veins.size() > 0)
{
((*alloc_vein_buffer_callback)(v_buf, veins.size()));
copy(veins.begin(), veins.end(), v_buf);
}
return v_buf;
}
else
return NULL;
}
return NULL;
}
t_frozenliquidvein* Maps_ReadFrozenVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_frozenliquidvein_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_frozenliquidvein> frozen_veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, &frozen_veins);
if(result)
{
t_frozenliquidvein* fv_buf = NULL;
if(frozen_veins.size() > 0)
{
((*alloc_frozenliquidvein_buffer_callback)(fv_buf, frozen_veins.size()));
copy(frozen_veins.begin(), frozen_veins.end(), fv_buf);
}
return fv_buf;
}
else
return NULL;
}
return NULL;
}
t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_spattervein_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_spattervein> spatter_veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, 0, &spatter_veins);
if(result)
{
t_spattervein* sv_buf = NULL;
if(spatter_veins.size() > 0)
{
((*alloc_spattervein_buffer_callback)(sv_buf, spatter_veins.size()));
copy(spatter_veins.begin(), spatter_veins.end(), sv_buf);
}
return sv_buf;
}
else
return NULL;
}
return NULL;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -4,7 +4,7 @@ import util
libdfhack.Buildings_GetCustomWorkshopType.argtypes = [ c_void_p, POINTER(CustomWorkshop) ] libdfhack.Buildings_GetCustomWorkshopType.argtypes = [ c_void_p, POINTER(CustomWorkshop) ]
def Buildings(object): class Buildings(object):
def __init__(self, ptr): def __init__(self, ptr):
self._b_ptr = ptr self._b_ptr = ptr

@ -2,6 +2,9 @@ from ctypes import *
from pydftypes import * from pydftypes import *
from util import _uintify, uint_ptr from util import _uintify, uint_ptr
_MAX_DIM = 0x300
_MAX_DIM_SQR = _MAX_DIM * _MAX_DIM
libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ] libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ] libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
@ -161,3 +164,63 @@ class Maps(object):
return (int(x.value), int(y.value), int(z.value)) return (int(x.value), int(y.value), int(z.value))
else: else:
return (-1, -1, -1) return (-1, -1, -1)
class MapPoint(object):
__slots__ = ["_x", "_y", "_z", "_cmp_val"]
def __init__(self, x = 0, y = 0, z = 0):
self._x, self._y, self._z = x, y, z
self._cmp_val = self._get_cmp_value()
def _val_set(self, which, val):
if which == 0:
self._x = val
elif which == 1:
self._y = val
elif which == 2:
self._z = val
self._cmp_val = self._get_cmp_value()
x = property(fget = lambda self: self._x, fset = lambda self, v: self._val_set(0, v))
y = property(fget = lambda self: self._y, fset = lambda self, v: self._val_set(1, v))
z = property(fget = lambda self: self._z, fset = lambda self, v: self._val_set(2, v))
def _get_cmp_value(self):
return (self.z * _MAX_DIM_SQR) + (self.y * _MAX_DIM) + self.x
#comparison operators
def __eq__(self, other):
return self.x == other.x and self.y == other.y and self.z == other.z
def __ne__(self, other):
return not self == other
def __lt__(self, other):
return self._cmp_val < other._cmp_val
def __le__(self, other):
return self < other or self == other
def __gt__(self, other):
return self._cmp_val > other._cmp_val
def __ge__(self, other):
return self > other or self == other
#arithmetic operators
def __add__(self, num):
return MapPoint(self.x, self.y, self.z + num)
def __sub__(self, num):
return MapPoint(self.x, self.y, self.z - num)
def __div__(self, num):
return MapPoint(self.x / num, self.y / num, self.z)
def __mul__(self, num):
return MapPoint(self.x * num, self.y * num, self.z)
def __mod__(self, num):
return MapPoint(self.x % num, self.y % num, self.z)