From cee5d176b980cf6dccfb4410c6afe284d31e9b82 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 09:23:53 -0500 Subject: [PATCH 01/12] changed Construction field type "mat_idx" to c_uint (to match t_construction struct layout) --- dfhack-python/dftypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dfhack-python/dftypes.py b/dfhack-python/dftypes.py index 20b035478..39af610e8 100644 --- a/dfhack-python/dftypes.py +++ b/dfhack-python/dftypes.py @@ -276,7 +276,7 @@ class Construction(Structure): ("form", c_ushort), ("unk_8", c_ushort), ("mat_type", c_ushort), - ("mat_idx", c_ushort), + ("mat_idx", c_uint), ("unk3", c_ushort), ("unk4", c_ushort), ("unk5", c_ushort), From e34831a354450f009ca53af4762f936d96193b4a Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 09:46:59 -0500 Subject: [PATCH 02/12] added getters/setters for cursor/view coords, window size, and screen tiles added ReadHotkeys --- library/include/dfhack-c/modules/Gui_C.h | 12 ++ library/modules/Gui_C.cpp | 214 +++++++++++------------ 2 files changed, 118 insertions(+), 108 deletions(-) diff --git a/library/include/dfhack-c/modules/Gui_C.h b/library/include/dfhack-c/modules/Gui_C.h index a1be816a4..f10f23b4c 100644 --- a/library/include/dfhack-c/modules/Gui_C.h +++ b/library/include/dfhack-c/modules/Gui_C.h @@ -36,6 +36,18 @@ extern "C" { DFHACK_EXPORT int Gui_Start(DFHackObject* gui); DFHACK_EXPORT int Gui_Finish(DFHackObject* gui); +DFHACK_EXPORT int Gui_getViewCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Gui_setViewCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z); + +DFHACK_EXPORT int Gui_getCursorCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Gui_setCursorCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z); + +DFHACK_EXPORT t_hotkey* Gui_ReadHotkeys(DFHackObject* gui); + +DFHACK_EXPORT int Gui_getWindowSize(DFHackObject* gui, int32_t* width, int32_t* height); + +DFHACK_EXPORT t_screen* Gui_getScreenTiles(DFHackObject* gui, int32_t width, int32_t height); + DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen); DFHACK_EXPORT int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState); diff --git a/library/modules/Gui_C.cpp b/library/modules/Gui_C.cpp index 218d16d94..5566e2eb6 100644 --- a/library/modules/Gui_C.cpp +++ b/library/modules/Gui_C.cpp @@ -48,126 +48,103 @@ int Gui_Finish(DFHackObject* gui) return -1; } -int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) +int Gui_getViewCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z) { if(gui != NULL) { - return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); + int32_t tx, ty, tz; + + if(((DFHack::Gui*)gui)->getViewCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; } return -1; } -int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState) +int Gui_setViewCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z) { if(gui != NULL) { - *menuState = ((DFHack::Gui*)gui)->ReadMenuState(); - - return 1; + if(((DFHack::Gui*)gui)->setViewCoords(x, y, z)) + return 1; + else + return 0; } return -1; } -int Gui_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) -{ - if(pos != NULL) - { - int32_t tx, ty, tz; - - if(((DFHack::Gui*)pos)->getViewCoords(tx, ty, tz)) - { - *x = tx; - *y = ty; - *z = tz; - - return 1; - } - else - return 0; - } - - return -1; -} - -int Gui_setViewCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) -{ - if(pos != NULL) - { - if(((DFHack::Gui*)pos)->setViewCoords(x, y, z)) - return 1; - else - return 0; - } - - return -1; -} - - -int Gui_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) +int Gui_getCursorCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z) { - if(pos != NULL) - { - int32_t tx, ty, tz; - - if(((DFHack::Gui*)pos)->getCursorCoords(tx, ty, tz)) - { - *x = tx; - *y = ty; - *z = tz; - - return 1; - } - else - return 0; - } - - return -1; + if(gui != NULL) + { + int32_t tx, ty, tz; + + if(((DFHack::Gui*)gui)->getCursorCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; + } + + return -1; } -int Gui_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) +int Gui_setCursorCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z) { - if(pos != NULL) - { - if(((DFHack::Gui*)pos)->setCursorCoords(x, y, z)) - return 1; - else - return 0; - } - - return -1; + if(gui != NULL) + { + if(((DFHack::Gui*)gui)->setCursorCoords(x, y, z)) + return 1; + else + return 0; + } + + return -1; } -t_hotkey* Gui_ReadHotkeys(DFHackObject* pos) +t_hotkey* Gui_ReadHotkeys(DFHackObject* gui) { - if(pos != NULL) - { - t_hotkey* buf = NULL; - - (*alloc_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); - - if(buf != NULL) - { - if(((DFHack::Gui*)pos)->ReadHotkeys(buf)) - return buf; - else - return NULL; - } - else - return NULL; - } - - return NULL; + if(gui != NULL) + { + t_hotkey* buf; + + (*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); + + if(buf != NULL) + { + if(((DFHack::Gui*)gui)->ReadHotkeys(buf)) + return buf; + else + return NULL; + } + else + return NULL; + } + + return NULL; } -int Gui_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) +int Gui_getWindowSize(DFHackObject* gui, int32_t* width, int32_t* height) { - if(pos != NULL) + if(gui != NULL) { int32_t tw, th; - if(((DFHack::Gui*)pos)->getWindowSize(tw, th)) + if(((DFHack::Gui*)gui)->getWindowSize(tw, th)) { *width = tw; *height = th; @@ -181,26 +158,47 @@ int Gui_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) return -1; } -t_screen* Gui_getScreenTiles(DFHackObject* pos, int32_t width, int32_t height) +t_screen* Gui_getScreenTiles(DFHackObject* gui, int32_t width, int32_t height) { - if(pos != NULL) - { - t_screen* buf = NULL; - - (*alloc_screen_buffer_callback)(&buf, width * height); - - if(buf == NULL) - return NULL; - - if(((DFHack::Gui*)pos)->getScreenTiles(width, height, buf)) - return buf; - else - return NULL; - } - - return NULL; + if(gui != NULL) + { + t_screen* buf; + + (*alloc_t_screen_buffer_callback)(&buf, width * height); + + if(buf == NULL) + return NULL; + + if(((DFHack::Gui*)gui)->getScreenTiles(width, height, buf)) + return buf; + else + return NULL; + } + + return NULL; } +int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) +{ + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); + } + + return -1; +} + +int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState) +{ + if(gui != NULL) + { + *menuState = ((DFHack::Gui*)gui)->ReadMenuState(); + + return 1; + } + + return -1; +} #ifdef __cplusplus } From c18167224b16b4833485840046cf0916812affdf Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:04:19 -0500 Subject: [PATCH 03/12] updated to match C API --- dfhack-python/gui.py | 64 +++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/dfhack-python/gui.py b/dfhack-python/gui.py index 8d71ff6a5..2a050d782 100644 --- a/dfhack-python/gui.py +++ b/dfhack-python/gui.py @@ -1,22 +1,31 @@ -from ctypes import * -from pydfhack import libdfhack, ViewScreen +from ctypes import c_void_p, c_int, c_uint, byref +from dftypes import libdfhack, ViewScreen, Hotkey +from util import check_pointer_cache + +libdfhack.Gui_getViewCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ] +libdfhack.Gui_setViewCoords.argtypes = [ c_void_p, c_int, c_int, c_int ] + +libdfhack.Gui_getCursorCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ] +libdfhack.Gui_setCursorCoords.argtypes = [ c_void_p, c_int, c_int, c_int ] + +libdfhack.Gui_getWindowSize.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int) ] -libdfhack.Gui_ReadHotkeys.restype = c_void_p libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ] +libdfhack.Gui_ReadHotkeys.restype = c_void_p + +libdfhack.Gui_getScreenTiles.argtypes = [ c_void_p, c_int, c_int ] +libdfhack.Gui_getScreenTiles.restype = c_void_p + class Gui(object): def __init__(self, ptr): self._gui_ptr = ptr - self._vx, self._vy, self._vz = c_int(), c_int(), c_int() - self._cx, self._cy, self._cz = c_int(), c_int(), c_int() - self._ww, self._wh = c_int(), c_int() - def start(self): - return libdfhack.Gui_Start(self._gui_ptr) + return libdfhack.Gui_Start(self._gui_ptr) > 0 def finish(self): - return libdfhack.Gui_Finish(self._gui_ptr) + return libdfhack.Gui_Finish(self._gui_ptr) > 0 def read_view_screen(self): s = ViewScreen() @@ -27,37 +36,38 @@ class Gui(object): return None def get_view_coords(self): - if libdfhack.Gui_getViewCoords(self._gui_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0: - return (self._vx.value, self._vy.value, self._vz.value) + x, y, z = (0, 0, 0) + + if libdfhack.Gui_getViewCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0: + return (x, y, z) else: return (-1, -1, -1) - def set_view_coords(self, v_coords): - self._vx.value, self._vy.value, self._vz.value = v_coords - - libdfhack.Gui_setViewCoords(self._gui_ptr, self._vx, self._vy, self._vz) - - view_coords = property(get_view_coords, set_view_coords) + def set_view_coords(self, x, y, z): + libdfhack.Gui_setViewCoords(self._gui_ptr, x, y, z) def get_cursor_coords(self): - if libdfhack.Gui_getCursorCoords(self._gui_ptr, byref(self._cx), byref(self._cy), byref(self._cz)) > 0: - return (self._cx.value, self._cy.value, self._cz.value) + x, y, z = (0, 0, 0) + + if libdfhack.Gui_getCursorCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0: + return (x, y, z) else: return (-1, -1, -1) - def set_cursor_coords(self, c_coords): - self._cx.value, self._cy.value, self_cz.value = c_coords - - libdfhack.Gui_setCursorCoords(self._gui_ptr, self._cx, self._cy, self._cz) - - cursor_coords = property(get_cursor_coords, set_cursor_coords) + def set_cursor_coords(self, x, y, z): + libdfhack.Gui_setCursorCoords(self._gui_ptr, x, y, z) def read_hotkeys(self): return check_pointer_cache(libdfhack.Gui_ReadHotkeys(self._gui_ptr)) + + def get_screen_tiles(self, width, height): + return check_pointer_cache(libdfhack.Gui_getScreenTiles(self._gui_ptr, width, height)) @property def window_size(self): - if libdfhack.Gui_getWindowSize(self._gui_ptr, byref(self._ww), byref(self._wh)) > 0: - return (self._ww.value, self._wh.value) + width, height = (0, 0) + + if libdfhack.Gui_getWindowSize(self._gui_ptr, byref(width), byref(height)) > 0: + return (width, height) else: return (-1, -1) From ea54dc645cc0c921496a1fee9ccf7b7a5026ff81 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:07:50 -0500 Subject: [PATCH 04/12] removed references to position module, which no longer exists --- dfhack-python/context.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/dfhack-python/context.py b/dfhack-python/context.py index a09e1ea17..66c9eda29 100644 --- a/dfhack-python/context.py +++ b/dfhack-python/context.py @@ -15,7 +15,6 @@ libdfhack.Context_getProcess.restype = c_void_p libdfhack.Context_getCreatures.restype = c_void_p libdfhack.Context_getMaps.restype = c_void_p libdfhack.Context_getGui.restype = c_void_p -libdfhack.Context_getPosition.restype = c_void_p libdfhack.Context_getMaterials.restype = c_void_p libdfhack.Context_getTranslation.restype = c_void_p libdfhack.Context_getVegetation.restype = c_void_p @@ -58,7 +57,6 @@ class Context(object): def __init__(self, ptr): self._c_ptr = ptr - self._pos_obj = None self._mat_obj = None self._map_obj = None self._veg_obj = None @@ -100,14 +98,6 @@ class Context(object): def is_suspended(self): return libdfhack.Context_isSuspended(self._c_ptr) > 0 - @property - def position(self): - import position - if self._pos_obj is None: - self._pos_obj = position.Position(libdfhack.Context_getPosition(self._c_ptr)) - - return self._pos_obj - @property def materials(self): import materials @@ -186,4 +176,9 @@ class Context(object): 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 \ No newline at end of file + return self._window_io_obj + +cm = ContextManager("Memory.xml") +df = cm.get_single_context() +df.attach() +w = df.window_io \ No newline at end of file From 3e335c4b7bcab6e120478e3345cfb5f0d2c784dd Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:08:08 -0500 Subject: [PATCH 05/12] switched from position to gui (since position no longer exists) --- tools/python/hotkeynotedump.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/python/hotkeynotedump.py b/tools/python/hotkeynotedump.py index edfdfb2f9..77cd0b811 100644 --- a/tools/python/hotkeynotedump.py +++ b/tools/python/hotkeynotedump.py @@ -5,11 +5,11 @@ df = cm.get_single_context() df.attach() -pos = df.position +gui = df.gui print "Hotkeys" -hotkeys = pos.read_hotkeys() +hotkeys = gui.read_hotkeys() for key in hotkeys: print "x: %d\ny: %d\tz: %d\ttext: %s" % (key.x, key.y, key.z, key.name) From e9cda85e9b1a9bed91c1c38de055d0ab801fe33f Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:09:34 -0500 Subject: [PATCH 06/12] no need to import everything in dftypes --- dfhack-python/constructions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dfhack-python/constructions.py b/dfhack-python/constructions.py index fea93ee0b..f822a54fa 100644 --- a/dfhack-python/constructions.py +++ b/dfhack-python/constructions.py @@ -1,5 +1,5 @@ -from ctypes import * -from dftypes import * +from ctypes import c_uint, byref +from dftypes import libdfhack, Construction class Constructions(object): def __init__(self, ptr): From df29be13687b0444c22e12053daadadd15c3aac6 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:10:30 -0500 Subject: [PATCH 07/12] removed some testing stuff --- dfhack-python/context.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dfhack-python/context.py b/dfhack-python/context.py index 66c9eda29..92f5ccec8 100644 --- a/dfhack-python/context.py +++ b/dfhack-python/context.py @@ -176,9 +176,4 @@ class Context(object): 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 - -cm = ContextManager("Memory.xml") -df = cm.get_single_context() -df.attach() -w = df.window_io \ No newline at end of file + return self._window_io_obj \ No newline at end of file From cf59b7802d59d63abd4cfb39d21994ba0e9264eb Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:22:56 -0500 Subject: [PATCH 08/12] added getPosition --- library/include/dfhack-c/modules/Maps_C.h | 2 ++ library/modules/Maps_C.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/library/include/dfhack-c/modules/Maps_C.h b/library/include/dfhack-c/modules/Maps_C.h index 9ad717103..7e759083b 100644 --- a/library/include/dfhack-c/modules/Maps_C.h +++ b/library/include/dfhack-c/modules/Maps_C.h @@ -42,6 +42,8 @@ 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_getPosition(DFHackObject* maps, int32_t* x, int32_t* y, int32_t* z); + DFHACK_EXPORT int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); DFHACK_EXPORT uint32_t Maps_getBlockPtr(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z); diff --git a/library/modules/Maps_C.cpp b/library/modules/Maps_C.cpp index 67e4ed355..81a216531 100644 --- a/library/modules/Maps_C.cpp +++ b/library/modules/Maps_C.cpp @@ -185,6 +185,14 @@ void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) } } +void Maps_getPosition(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) +{ + if(maps != NULL) + { + ((DFHack::Maps*)maps)->getPosition(*x, *y, *z); + } +} + int Maps_isValidBlock(DFHackObject* maps, uint32_t x, uint32_t y, uint32_t z) { if(maps != NULL) From f1bb4a46616e3c189f0a683d93abfcf11c074f57 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:37:31 -0500 Subject: [PATCH 09/12] argument types were wrong for vein readers added world position getter --- dfhack-python/maps.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/dfhack-python/maps.py b/dfhack-python/maps.py index f7ed0c1f0..a6a4d8a27 100644 --- a/dfhack-python/maps.py +++ b/dfhack-python/maps.py @@ -5,9 +5,9 @@ from util import _uintify, uint_ptr, check_pointer_cache _MAX_DIM = 0x300 _MAX_DIM_SQR = _MAX_DIM * _MAX_DIM -_default_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_getPosition.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) ] @@ -18,14 +18,13 @@ libdfhack.Maps_ReadOccupancy.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POIN 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_ReadVegetation.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] libdfhack.Maps_ReadVegetation.restype = c_void_p -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 +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_ReadGrassVeins.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] +libdfhack.Maps_ReadWorldConstructions.argtypes = [ c_void_p, c_uint, c_uint, c_uint ] libdfhack.Maps_ReadStandardVeins.restype = c_void_p libdfhack.Maps_ReadFrozenVeins.restype = c_void_p @@ -217,16 +216,19 @@ class Maps(object): @property def size(self): - x = c_uint() - y = c_uint() - z = c_uint() + x, y, z = (0, 0, 0) retval = libdfhack.Maps_getSize(self._map_ptr, byref(x), byref(y), byref(z)) - if retval > 0: - return (int(x.value), int(y.value), int(z.value)) - else: - return (-1, -1, -1) + return (x, y, z) + + @property + def position(self): + x, y, z = (0, 0, 0) + + libdfhack.Maps_getPosition(self._map_ptr, byref(x), byref(y), byref(z)) + + return (x, y, z) class MapPoint(object): __slots__ = ["_x", "_y", "_z", "_cmp_val"] From d0cd969ed2ed2127926c4a2ec683cc0bbc7cd282 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:38:29 -0500 Subject: [PATCH 10/12] got everything up to the point that it matches what's in the C++ version of the position tool --- tools/python/position.py | 53 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/tools/python/position.py b/tools/python/position.py index fa8547fe2..122440589 100644 --- a/tools/python/position.py +++ b/tools/python/position.py @@ -13,9 +13,56 @@ if not df.attach(): gui = df.gui -print "view coords: %s" % (gui.view_coords,) -print "cursor coords: %s" % (gui.cursor_coords,) -print "window size: %s" % (gui.window_size,) +if gui is not None: + maps = df.maps + world = df.world + + have_maps = maps.start() + world.start() + + gm = world.read_game_mode() + + if gm is not None: + print gm + + date_tuple = (world.read_current_year(), world.read_current_month(), world.read_current_day(), world.read_current_tick()) + + print "Year: %d Month: %d Day: %d Tick: %d" % date_tuple + + v_coords = gui.get_view_coords() + c_coords = gui.get_cursor_coords() + w_coords = (-1, -1, -1) + world_pos_string = "" + + if have_maps is True: + w_coords = maps.getPosition() + + x = (v_coords[0] + w_coords[0]) * 48 + y = (v_coords[1] + w_coords[1]) * 48 + z = (v_coords[2] + w_coords[2]) + + world_pos_string = " world: %d/%d/%d" % (x, y, z) + + print "Map world offset: %d/%d/%d embark squares" % w_coords + + if v_coords != (-1, -1, -1): + print "view coords: %d/%d/%d" % v_coords + + if have_maps is True: + print world_pos_string + + if c_coords != (-1, -1, -1): + print "cursor coords: %d/%d/%d" % c_coords + + if have_maps is True: + print world_pos_string + + window_size = gui.get_window_size() + + if window_size != (-1, -1): + print "window size : %d %d" % window_size +else: + print "cursor and window parameters are unsupported on your version of DF" if not df.detach(): print "Unable to detach!" From 4c55f544644d6fb56483c6f225c47ea5d6c31125 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:41:45 -0500 Subject: [PATCH 11/12] spelled a couple of allocator names wrong --- library/modules/Gui_C.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/modules/Gui_C.cpp b/library/modules/Gui_C.cpp index 5566e2eb6..8c6ed777b 100644 --- a/library/modules/Gui_C.cpp +++ b/library/modules/Gui_C.cpp @@ -122,7 +122,7 @@ t_hotkey* Gui_ReadHotkeys(DFHackObject* gui) { t_hotkey* buf; - (*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); + (*alloc_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); if(buf != NULL) { @@ -164,7 +164,7 @@ t_screen* Gui_getScreenTiles(DFHackObject* gui, int32_t width, int32_t height) { t_screen* buf; - (*alloc_t_screen_buffer_callback)(&buf, width * height); + (*alloc_screen_buffer_callback)(&buf, width * height); if(buf == NULL) return NULL; From 1bf6a2ea71c6b069a9e53b5f956144c7449a1408 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 29 Mar 2011 10:42:04 -0500 Subject: [PATCH 12/12] generally, function signatures are supposed to match between header and implementation file... --- library/modules/Maps_C.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/Maps_C.cpp b/library/modules/Maps_C.cpp index 81a216531..7d17e5c78 100644 --- a/library/modules/Maps_C.cpp +++ b/library/modules/Maps_C.cpp @@ -185,7 +185,7 @@ void Maps_getSize(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) } } -void Maps_getPosition(DFHackObject* maps, uint32_t* x, uint32_t* y, uint32_t* z) +void Maps_getPosition(DFHackObject* maps, int32_t* x, int32_t* y, int32_t* z) { if(maps != NULL) {