develop
Petr Mrázek 2011-03-03 16:24:26 +01:00
commit 552180d430
9 changed files with 197 additions and 5 deletions

@ -104,6 +104,8 @@ 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 (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t) = NULL;
int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t) = NULL;
REG_MACRO(Byte, int8_t*, alloc_byte_buffer_callback)
REG_MACRO(Short, int16_t*, alloc_short_buffer_callback)
@ -208,10 +210,14 @@ void UnregisterNewCreatureTypeCallback()
REG_MACRO(Vein, t_vein*, alloc_vein_buffer_callback)
REG_MACRO(FrozenLiquidVein, t_frozenliquidvein*, alloc_frozenliquidvein_buffer_callback)
REG_MACRO(SpatterVein, t_spattervein*, alloc_spattervein_buffer_callback)
REG_MACRO(GrassVein, t_grassvein*, alloc_grassvein_buffer_callback)
REG_MACRO(WorldConstruction, t_worldconstruction*, alloc_worldconstruction_buffer_callback)
UNREG_MACRO(Vein, alloc_vein_buffer_callback)
UNREG_MACRO(FrozenLiquidVein, alloc_frozenliquidvein_buffer_callback)
UNREG_MACRO(SpatterVein, alloc_spattervein_buffer_callback)
UNREG_MACRO(GrassVein, alloc_grassvein_buffer_callback)
UNREG_MACRO(WorldConstruction, alloc_worldconstruction_buffer_callback)
int DFHack_isWallTerrain(int in)
{

@ -181,6 +181,8 @@ DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*,
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 (*alloc_grassvein_buffer_callback)(t_grassvein*, uint32_t);
DFHACK_EXPORT extern int (*alloc_worldconstruction_buffer_callback)(t_worldconstruction*, uint32_t);
DFHACK_EXPORT void RegisterEmptyCreatureTypeCallback(int (*funcptr)(c_creaturetype*));
DFHACK_EXPORT void RegisterNewCreatureTypeCallback(int (*funcptr)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t));
@ -189,6 +191,8 @@ DFHACK_EXPORT void RegisterCreatureTypeBufferCallback(int (*funcptr)(c_creaturet
DFHACK_EXPORT void RegisterVeinBufferCallback(int (*funcptr)(t_vein*, uint32_t));
DFHACK_EXPORT void RegisterFrozenLiquidVeinBufferCallback(int (*funcptr)(t_frozenliquidvein*, uint32_t));
DFHACK_EXPORT void RegisterSpatterVeinBufferCallback(int (*funcptr)(t_spattervein*, uint32_t));
DFHACK_EXPORT void RegisterGrassVeinBufferCallback(int (*funcptr)(t_grassvein*, uint32_t));
DFHACK_EXPORT void RegisterWorldConstructionBufferCallback(int (*funcptr)(t_worldconstruction*, uint32_t));
DFHACK_EXPORT void UnregisterEmptyCreatureTypeCallback();
DFHACK_EXPORT void UnregisterNewCreatureTypeCallback();
@ -197,6 +201,8 @@ HUNREG_MACRO(CreatureType)
HUNREG_MACRO(Vein)
HUNREG_MACRO(FrozenLiquidVein)
HUNREG_MACRO(SpatterVein)
HUNREG_MACRO(GrassVein)
HUNREG_MACRO(WorldConstruction)
DFHACK_EXPORT int DFHack_isWallTerrain(int in);
DFHACK_EXPORT int DFHack_isFloorTerrain(int in);

@ -76,6 +76,8 @@ DFHACK_EXPORT int Maps_ReadRegionOffsets(DFHackObject* maps, uint32_t x, uint32_
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);
DFHACK_EXPORT t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
DFHACK_EXPORT t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z);
#ifdef __cplusplus
}

@ -43,6 +43,8 @@ DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day);
DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather);
DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather);
DFHACK_EXPORT int World_ReadGameMode(DFHackObject* world);
#ifdef __cplusplus
}
#endif

@ -444,6 +444,68 @@ t_spattervein* Maps_ReadSpatterVeins(DFHackObject* maps, uint32_t x, uint32_t y,
return NULL;
}
t_grassvein* Maps_ReadGrassVeins(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_grassvein_buffer_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_grassvein> grass_veins;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, 0, 0, &grass_veins);
if(result)
{
t_grassvein* gs_buf = NULL;
if(grass_veins.size() > 0)
{
((*alloc_grassvein_buffer_callback)(gs_buf, grass_veins.size()));
copy(grass_veins.begin(), grass_veins.end(), gs_buf);
}
return gs_buf;
}
else
return NULL;
}
return NULL;
}
t_worldconstruction* Maps_ReadWorldConstructions(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z)
{
if(maps != NULL)
{
if(alloc_worldconstruction_buffer_callback == NULL)
return NULL;
vector<t_vein> veins;
vector<t_worldconstruction> constructions;
bool result = ((DFHack::Maps*)maps)->ReadVeins(x, y, z, &veins, 0, 0, 0, &constructions);
if(result)
{
t_worldconstruction* ct_buf = NULL;
if(constructions.size() > 0)
{
((*alloc_worldconstruction_buffer_callback)(ct_buf, constructions.size()));
copy(constructions.begin(), constructions.end(), ct_buf);
}
return ct_buf;
}
else
return NULL;
}
return NULL;
}
#ifdef __cplusplus
}
#endif

@ -113,7 +113,7 @@ int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather)
int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather)
{
if (world != NULL)
if(world != NULL)
{
((DFHack::World*)world)->SetCurrentWeather(weather);
return 1;
@ -122,6 +122,16 @@ int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather)
return -1;
}
int World_ReadGameMode(DFHackObject* world)
{
if(world != NULL)
{
return ((DFHack::World*)world)->ReadGameMode();
}
return -1;
}
#ifdef __cplusplus
}
#endif

@ -114,6 +114,38 @@ def _alloc_spattervein_buffer_callback(ptr, count):
_spattervein_functype = CFUNCTYPE(c_int, POINTER(SpatterVein), c_uint)
libdfhack.alloc_spatter_buffer_callback = _spattervein_functype(_alloc_spattervein_buffer_callback)
class GrassVein(Structure):
_fields_ = [("vtable", c_uint),
("material", c_uint),
("intensity", ((c_ubyte * 16) * 16)),
("address_of", c_uint)]
def _alloc_grassvein_buffer_callback(ptr, count):
allocated = _allocate_array(GrassVein, count)
ptr = addressof(allocated[0])
return 1
_grassvein_functype = CFUNCTYPE(c_int, POINTER(GrassVein), c_uint)
libdfhack.alloc_grassvein_buffer_callback = _grassvein_functype(_alloc_grassvein_buffer_callback)
class WorldConstruction(Structure):
_fields_ = [("vtable", c_uint),
("material", c_uint),
("assignment", c_ushort * 16),
("address_of", c_uint)]
def _alloc_worldconstruction_buffer_callback(ptr, count):
allocated = _allocate_array(WorldConstruction, count)
ptr = addressof(allocated[0])
return 1
_worldconstruction_functype = CFUNCTYPE(c_int, POINTER(WorldConstruction), c_uint)
libdfhack.alloc_worldconstruction_buffer_callback = _worldconstruction_functype(_alloc_worldconstructrion_buffer_callback)
class MapBlock40d(Structure):
_fields_ = [("tiletypes", TileTypes40d),
("designation", Designations40d),

@ -5,7 +5,9 @@ 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 ]
_default_argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_getSize.argtypes = _default_argtypes
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_ReadDesignations.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(Designations40d) ]
@ -15,9 +17,11 @@ 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_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_ReadStandardVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadFrozenVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadSpatterVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ]
libdfhack.Maps_ReadStandardVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadFrozenVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadSpatterVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadGrassVeins.argtypes = _default_argtypes
libdfhack.Maps_ReadWorldConstructions.argtypes = _default_argtypes
class Maps(object):
def __init__(self, ptr):
@ -169,6 +173,16 @@ class Maps(object):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadSpatterVeins(self._map_ptr, ux, uy, uz)
def read_grass_veins(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadGrassVeins(self._map_ptr, ux, uy, uz)
def read_world_constructions(self, x, y, z):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_ReadWorldConstructions(self._map_ptr, ux, uy, uz)
@property
def size(self):

@ -0,0 +1,58 @@
from ctypes import *
from util import _uintify, uint_ptr
class World(object):
def __init__(self, ptr):
self._world_ptr = ptr
def start(self):
return libdfhack.World_Start(self._world_ptr) > 0
def finish(self):
return libdfhack.World_Finish(self._world_ptr) > 0
def read_current_tick(self):
tick = c_uint(0)
if libdfhack.World_ReadCurrentTick(self._world_ptr, byref(tick)) > 0:
return int(tick)
else:
return -1
def read_current_year(self):
year = c_uint(0)
if libdfhack.World_ReadCurrentYear(self._world_ptr, byref(year)) > 0:
return int(year)
else:
return -1
def read_current_month(self):
month = c_uint(0)
if libdfhack.World_ReadCurrentMonth(self._world_ptr, byref(month)) > 0:
return int(month)
else:
return -1
def read_current_day(self):
day = c_uint(0)
if libdfhack.World_ReadCurrentDay(self._world_ptr, byref(day)) > 0:
return int(day)
else:
return -1
def read_current_weather(self):
weather = c_ubyte(0)
if libdfhack.World_ReadCurrentWeather(self._world_ptr, byref(weather)) > 0:
return int(weather)
else:
return -1
def write_current_weather(self, weather):
return libdfhack.World_WriteCurrentWeather(self._world_ptr, c_ubyte(weather))
def read_game_mode(self):
return int(libdfhack.World_ReadGameMode(self._world_ptr))