develop
Petr Mrázek 2011-03-06 23:57:22 +01:00
commit bbbea3d023
9 changed files with 269 additions and 125 deletions

@ -236,16 +236,6 @@ DFHackObject* Context_getProcess(DFHackObject* context)
return NULL; return NULL;
} }
DFHackObject* Context_getWindow(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWindowIO();
}
return NULL;
}
DFHackObject* Context_getCreatures(DFHackObject* context) DFHackObject* Context_getCreatures(DFHackObject* context)
{ {
if(context != NULL) if(context != NULL)
@ -346,6 +336,26 @@ DFHackObject* Context_getItems(DFHackObject* context)
return NULL; return NULL;
} }
DFHackObject* Context_getWorld(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWorld();
}
return NULL;
}
DFHackObject* Context_getWindowIO(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWindowIO();
}
return NULL;
}
void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target) void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target)
{ {
if(context != NULL) if(context != NULL)

@ -133,7 +133,6 @@ DFHACK_EXPORT int Context_AsyncSuspend(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMemoryInfo(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getMemoryInfo(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getProcess(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getProcess(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWindow(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getCreatures(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getCreatures(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMaps(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getMaps(DFHackObject* context);
@ -145,6 +144,8 @@ DFHACK_EXPORT DFHackObject* Context_getVegetation(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getBuildings(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getBuildings(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getConstructions(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getConstructions(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getItems(DFHackObject* context); DFHACK_EXPORT DFHackObject* Context_getItems(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWorld(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWindowIO(DFHackObject* context);
//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc //these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc
DFHACK_EXPORT void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target); DFHACK_EXPORT void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target);

@ -32,9 +32,9 @@ distribution.
extern "C" { extern "C" {
#endif #endif
DFHACK_EXPORT int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift); DFHACK_EXPORT int WindowIO_TypeStr(DFHackObject* window, const char* input, uint32_t delay, int8_t useShift);
DFHACK_EXPORT int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay); DFHACK_EXPORT int WindowIO_TypeSpecial(DFHackObject* window, t_special command, uint32_t count, uint32_t delay);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -234,6 +234,9 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
if(buf != NULL) if(buf != NULL)
@ -258,6 +261,9 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
if(buf != NULL) if(buf != NULL)
@ -282,6 +288,9 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
if(buf != NULL) if(buf != NULL)
@ -306,6 +315,9 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
if(buf != NULL) if(buf != NULL)
@ -330,6 +342,9 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
{ {
t_matgloss* buf = NULL; t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size())); ((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
if(buf != NULL) if(buf != NULL)
@ -356,6 +371,9 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
{ {
c_creaturetype* buf = NULL; c_creaturetype* buf = NULL;
if(alloc_creaturetype_buffer_callback == NULL)
return NULL;
((*alloc_creaturetype_buffer_callback)(buf, matSize)); ((*alloc_creaturetype_buffer_callback)(buf, matSize));
if(buf != NULL) if(buf != NULL)

@ -40,18 +40,23 @@ using namespace DFHack;
extern "C" { extern "C" {
#endif #endif
int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift) int WindowIO_TypeStr(DFHackObject* window, const char* input, uint32_t delay, int8_t useShift)
{ {
if(window != NULL) if(window != NULL)
{ {
((DFHack::WindowIO*)window)->TypeStr(input, delay, useShift); bool shifting = false;
if(useShift > 0)
shifting = true;
((DFHack::WindowIO*)window)->TypeStr(input, delay, shifting);
return 1; return 1;
} }
return -1; return -1;
} }
int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay) int WindowIO_TypeSpecial(DFHackObject* window, t_special command, uint32_t count, uint32_t delay)
{ {
if(window != NULL) if(window != NULL)
{ {

@ -11,7 +11,6 @@ libdfhack.Context_Free.argtypes = [ c_void_p ]
libdfhack.Context_getMemoryInfo.restype = c_void_p libdfhack.Context_getMemoryInfo.restype = c_void_p
libdfhack.Context_getProcess.restype = c_void_p libdfhack.Context_getProcess.restype = c_void_p
libdfhack.Context_getWindow.restype = c_void_p
libdfhack.Context_getCreatures.restype = c_void_p libdfhack.Context_getCreatures.restype = c_void_p
libdfhack.Context_getMaps.restype = c_void_p libdfhack.Context_getMaps.restype = c_void_p
@ -23,6 +22,8 @@ libdfhack.Context_getVegetation.restype = c_void_p
libdfhack.Context_getBuildings.restype = c_void_p libdfhack.Context_getBuildings.restype = c_void_p
libdfhack.Context_getConstructions.restype = c_void_p libdfhack.Context_getConstructions.restype = c_void_p
libdfhack.Context_getItems.restype = c_void_p libdfhack.Context_getItems.restype = c_void_p
libdfhack.Context_getWorld.restype = c_void_p
libdfhack.Context_getWindowIO.restype = c_void_p
class ContextManager(object): class ContextManager(object):
def __init__(self, memory_path): def __init__(self, memory_path):
@ -67,6 +68,8 @@ class Context(object):
self._tran_obj = None self._tran_obj = None
self._item_obj = None self._item_obj = None
self._creature_obj = None self._creature_obj = None
self._world_obj = None
self._window_io_obj = None
def __del__(self): def __del__(self):
libdfhack.Context_Free(self._c_ptr) libdfhack.Context_Free(self._c_ptr)
@ -168,3 +171,19 @@ class Context(object):
self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr)) self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr))
return self._tran_obj return self._tran_obj
@property
def world(self):
import world
if self._world_obj is None:
self._world_obj = world.World(libdfhack.Context_getWorld(self._c_ptr))
return self._world_obj
@property
def window_io(self):
import window_io
if self._window_io_obj is None:
self._window_io_obj = window_io.WindowIO(libdfhack.Context_getWindowIO(self._c_ptr))
return self._window_io_obj

@ -95,3 +95,62 @@ LiquidType = C_EnumerationType("LiquidType",
(c_uint,), (c_uint,),
{"Water" : 0, {"Water" : 0,
"Magma" : 1}) "Magma" : 1})
#this list must stay in the same order as the one in dfhack/library/include/dfhack/modules/WindowIO.h!
_keys = ["ENTER",
"SPACE",
"BACK_SPACE",
"TAB",
"CAPS_LOCK",
"LEFT_SHIFT",
"RIGHT_SHIFT",
"LEFT_CONTROL",
"RIGHT_CONTROL",
"ALT",
"WAIT",
"ESCAPE",
"UP",
"DOWN",
"LEFT",
"RIGHT",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"PAGE_UP",
"PAGE_DOWN",
"INSERT",
"DFK_DELETE",
"HOME",
"END",
"KEYPAD_DIVIDE",
"KEYPAD_MULTIPLY",
"KEYPAD_SUBTRACT",
"KEYPAD_ADD,"
"KEYPAD_ENTER",
"KEYPAD_0",
"KEYPAD_1",
"KEYPAD_2",
"KEYPAD_3",
"KEYPAD_4",
"KEYPAD_5",
"KEYPAD_6",
"KEYPAD_7",
"KEYPAD_8",
"KEYPAD_9",
"KEYPAD_DECIMAL_POINT",
"NUM_SPECIALS"]
_key_dict = dict([(k, i) for i, k in enumerate(_keys)])
KeyType = C_EnumerationType("KeyType",
(c_uint,),
_key_dict)

@ -2,17 +2,6 @@ from ctypes import *
from dftypes import libdfhack from dftypes import libdfhack
from util import * from util import *
_get_arg_types = [ c_void_p, _arr_create_func ]
libdfhack.Materials_getInorganic.argtypes = _get_arg_types
libdfhack.Materials_getOrganic.argtypes = _get_arg_types
libdfhack.Materials_getTree.argtypes = _get_arg_types
libdfhack.Materials_getPlant.argtypes = _get_arg_types
libdfhack.Materials_getRace.argtypes = _get_arg_types
#libdfhack.Materials_getRaceEx.argtypes = _get_arg_types
libdfhack.Materials_getColor.argtypes = _get_arg_types
libdfhack.Materials_getOther.argtypes = _get_arg_types
class Materials(object): class Materials(object):
def __init__(self, ptr): def __init__(self, ptr):
self._mat_ptr = ptr self._mat_ptr = ptr
@ -26,116 +15,134 @@ class Materials(object):
self.color = None self.color = None
self.other = None self.other = None
def read_inorganic(self): def _get_inorganic(self):
return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) self.inorganic = libdfhack.Materials_getInorganic(self._mat_ptr)
def _get_organic(self):
def read_organic(self): self.organic = libdfhack.Materials_getOrganic(self._mat_ptr)
return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) def _get_tree(self):
self.tree = libdfhack.Materials_getTree(self._mat_ptr)
def read_wood(self): def _get_plant(self):
return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) self.plant = libdfhack.Materials_getPlant(self._mat_ptr)
def _get_race(self):
def read_plant(self): self.race = libdfhack.Materials_getRace(self._mat_ptr)
return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) def _get_race_ex(self):
self.race_ex = libdfhack.Materials_getRaceEx(self._mat_ptr)
def read_creature_types(self): def _get_color(self):
return libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) self.color = libdfhack.Materials_getColor(self._mat_ptr)
def _get_other(self):
def read_creature_types_ex(self): self.other = libdfhack.Materials_getOther(self._mat_ptr)
return libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr)
def _get_all(self):
def read_descriptor_colors(self): self._get_inorganic()
return libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) self._get_organic()
self._get_tree()
def read_others(self): self._get_plant()
return libdfhack.Materials_ReadOthers(self._mat_ptr) self._get_race()
self._get_race_ex()
def read_all(self): self._get_color()
libdfhack.Materials_ReadAllMaterials(self._mat_ptr) self._get_other()
def _clear_all(self):
def get_description(self, material): self.inorganic = None
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material)) self.organic = None
self.tree = None
def update_inorganic_cache(self): self.plant = None
def update_callback(count): self.race = None
allocated = _allocate_array(Matgloss, count) self.race_ex = None
self.color = None
self.inorganic = allocated[0] self.other = None
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getInorganic(self._mat_ptr, callback)
def update_organic_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.organic = allocated[0] def read_inorganic(self):
result = libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) > 0
return allocated[1] if result == True:
self._get_inorganic()
else:
self.inorganic = None
callback = _arr_create_func(update_callback) return result
return libdfhack.Materials_getOrganic(self._mat_ptr, callback) def read_organic(self):
result = libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) > 0
def update_tree_cache(self): if result == True:
def update_callback(count): self._get_organic()
allocated = _allocate_array(Matgloss, count) else:
self.organic = None
self.tree = allocated[0] return result
return allocated[1] def read_tree(self):
result = libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) > 0
callback = _arr_create_func(update_callback) if result == True:
self._get_tree()
else:
self.tree = None
return libdfhack.Materials_getTree(self._mat_ptr, callback) return result
def update_plant_cache(self): def read_plant(self):
def update_callback(count): result = libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) > 0
allocated = _allocate_array(Matgloss, count)
self.plant = allocated[0] if result == True:
self._get_plant()
else:
self.plant = None
return allocated[1] return result
callback = _arr_create_func(update_callback) def read_creature_types(self):
result = libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) > 0
return libdfhack.Materials_getPlant(self._mat_ptr, callback) if result == True:
self._get_race()
else:
self.race = None
def update_race_cache(self): return result
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.race = allocated[0] def read_creature_types_ex(self):
result = libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) > 0
return allocated[1] if result == True:
self._get_race_ex()
else:
self.race_ex = None
callback = _arr_create_func(update_callback) return result
return libdfhack.Materials_getRace(self._mat_ptr, callback) def read_descriptor_colors(self):
result = libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) > 0
def update_color_cache(self): if result == True:
def update_callback(count): self._get_color()
allocated = _allocate_array(DescriptorColor, count) else:
self.color = None
self.color = allocated[0] return result
return allocated[1] def read_others(self):
result = libdfhack.Materials_ReadOthers(self._mat_ptr) > 0
callback = _arr_create_func(update_callback) if result == True:
self._get_other()
else:
self.other = None
return libdfhack.Materials_getColor(self._mat_ptr, callback) return result
def update_other_cache(self): def read_all(self):
def update_callback(count): result = libdfhack.Materials_ReadAllMaterials(self._mat_ptr) > 0
allocated = _allocate_array(MatglossOther, count)
self.other = allocated[0] if result == True:
self._get_all()
else:
self._clear_all()
return allocated[1] return result
callback = _arr_create_func(update_callback) def get_type(self, material):
return libdfhack.Materials_getType(self._mat_ptr, byref(material))
return libdfhack.Materials_getOther(self._mat_ptr, callback) def get_description(self, material):
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material))

@ -0,0 +1,25 @@
from ctypes import *
libdfhack.WindowIO_TypeStr.argtypes = [ c_void_p, c_char_p, c_uint, c_byte ]
libdfhack.WindowIO_TypeSpecial.argtypes = [ c_void_p, c_uint, c_uint, c_uint, c_uint ]
class WindowIO(object):
def __init__(self, ptr):
self._window_io_ptr = ptr
def type_str(self, s, delay = 0, use_shift = False):
c_shift = c_byte(0)
c_delay = c_int(delay)
c_s = c_char_p(s)
if use_shift is True:
c_shift = c_byte(1)
return libdfhack.WindowIO_TypeStr(self._window_io_ptr, c_s, c_delay, c_shift) > 0
def type_special(self, command, count = 1, delay = 0):
c_command = c_uint(command)
c_count = c_uint(count)
c_delay = c_uint(delay)
return libdfhack.WindwIO_TypeSpecial(self._window_io_ptr, c_command, c_count, c_delay) > 0