From d58260740f6d993c06aeb412f62fa71b5fe08ce0 Mon Sep 17 00:00:00 2001 From: doomchild Date: Thu, 17 Jun 2010 15:29:29 -0500 Subject: [PATCH 1/3] moved the old Python/C stuff to python/deprecated renamed "c api" to "pydfhack" --- library/python/c api/gui.py | 25 -- library/python/c api/materials.py | 141 -------- library/python/c api/position.py | 43 --- library/python/c api/pydftypes.py | 315 ---------------- library/python/c api/vegetation.py | 25 -- .../python/{ => deprecated}/CMakeLists.txt | 0 library/python/{ => deprecated}/DF_API.cpp | 0 .../python/{ => deprecated}/DF_Buildings.cpp | 0 .../{ => deprecated}/DF_Constructions.cpp | 0 .../{ => deprecated}/DF_CreatureManager.cpp | 0 .../{ => deprecated}/DF_CreatureType.cpp | 0 library/python/{ => deprecated}/DF_GUI.cpp | 0 .../python/{ => deprecated}/DF_Helpers.cpp | 0 .../python/{ => deprecated}/DF_Imports.cpp | 0 library/python/{ => deprecated}/DF_Maps.cpp | 0 .../python/{ => deprecated}/DF_Material.cpp | 0 .../python/{ => deprecated}/DF_MemInfo.cpp | 0 .../python/{ => deprecated}/DF_Position.cpp | 0 .../python/{ => deprecated}/DF_Translate.cpp | 0 .../python/{ => deprecated}/DF_Vegetation.cpp | 0 library/python/{ => deprecated}/build-linux | 0 library/python/{ => deprecated}/build.bat | 0 .../{ => deprecated}/dfhack_api_ctypes.py | 0 .../{ => deprecated}/examples/attachtest.py | 0 .../{ => deprecated}/examples/miscutils.py | 0 .../{ => deprecated}/examples/position.py | 0 .../examples/settlementdump.py | 0 .../{ => deprecated}/examples/suspendtest.py | 0 .../{ => deprecated}/examples/treedump.py | 0 library/python/{ => deprecated}/ez_setup.py | 0 library/python/{ => deprecated}/linsetup.py | 0 library/python/{ => deprecated}/pydfhack.cpp | 0 .../{ => deprecated}/pydfhack/__init__.py | 0 .../{ => deprecated}/pydfhack/blocks.py | 0 .../{ => deprecated}/pydfhack/construction.py | 0 .../{ => deprecated}/pydfhack/creature.py | 0 .../{ => deprecated}/pydfhack/decorators.py | 0 library/python/deprecated/pydfhack/gui.py | 25 ++ .../python/{ => deprecated}/pydfhack/map.py | 0 .../python/deprecated/pydfhack/materials.py | 42 +++ .../{ => deprecated}/pydfhack/meminfo.py | 0 .../{ => deprecated}/pydfhack/mixins.py | 0 .../python/deprecated/pydfhack/position.py | 42 +++ .../{ => deprecated}/pydfhack/pydfapi.py | 0 .../pydfhack}/pydfhackflags.py | 27 +- .../python/deprecated/pydfhack/pydftypes.py | 50 +++ .../{ => deprecated}/pydfhack/translation.py | 0 .../python/deprecated/pydfhack/vegetation.py | 18 + library/python/{ => deprecated}/setup.py | 0 library/python/{ => deprecated}/test.py | 0 .../python/{ => deprecated}/tools/shell.py | 0 .../python/{ => deprecated}/tools/trees.py | 0 .../python/{c api => pydfhack}/buildings.py | 0 .../{c api => pydfhack}/constructions.py | 0 library/python/{c api => pydfhack}/context.py | 0 .../python/{c api => pydfhack}/creatures.py | 0 .../{c api => pydfhack}/dfhack_api_ctypes.py | 0 library/python/{c api => pydfhack}/enum.py | 0 library/python/pydfhack/gui.py | 46 +-- library/python/{c api => pydfhack}/items.py | 0 library/python/{c api => pydfhack}/maps.py | 0 library/python/pydfhack/materials.py | 183 +++++++--- library/python/pydfhack/position.py | 77 ++-- library/python/pydfhack/pydfhackflags.py | 27 +- library/python/pydfhack/pydftypes.py | 335 ++++++++++++++++-- library/python/{c api => pydfhack}/util.py | 0 library/python/pydfhack/vegetation.py | 39 +- 67 files changed, 730 insertions(+), 730 deletions(-) delete mode 100644 library/python/c api/gui.py delete mode 100644 library/python/c api/materials.py delete mode 100644 library/python/c api/position.py delete mode 100644 library/python/c api/pydftypes.py delete mode 100644 library/python/c api/vegetation.py rename library/python/{ => deprecated}/CMakeLists.txt (100%) rename library/python/{ => deprecated}/DF_API.cpp (100%) rename library/python/{ => deprecated}/DF_Buildings.cpp (100%) rename library/python/{ => deprecated}/DF_Constructions.cpp (100%) rename library/python/{ => deprecated}/DF_CreatureManager.cpp (100%) rename library/python/{ => deprecated}/DF_CreatureType.cpp (100%) rename library/python/{ => deprecated}/DF_GUI.cpp (100%) rename library/python/{ => deprecated}/DF_Helpers.cpp (100%) rename library/python/{ => deprecated}/DF_Imports.cpp (100%) rename library/python/{ => deprecated}/DF_Maps.cpp (100%) rename library/python/{ => deprecated}/DF_Material.cpp (100%) rename library/python/{ => deprecated}/DF_MemInfo.cpp (100%) rename library/python/{ => deprecated}/DF_Position.cpp (100%) rename library/python/{ => deprecated}/DF_Translate.cpp (100%) rename library/python/{ => deprecated}/DF_Vegetation.cpp (100%) rename library/python/{ => deprecated}/build-linux (100%) rename library/python/{ => deprecated}/build.bat (100%) rename library/python/{ => deprecated}/dfhack_api_ctypes.py (100%) rename library/python/{ => deprecated}/examples/attachtest.py (100%) rename library/python/{ => deprecated}/examples/miscutils.py (100%) rename library/python/{ => deprecated}/examples/position.py (100%) rename library/python/{ => deprecated}/examples/settlementdump.py (100%) rename library/python/{ => deprecated}/examples/suspendtest.py (100%) rename library/python/{ => deprecated}/examples/treedump.py (100%) rename library/python/{ => deprecated}/ez_setup.py (100%) rename library/python/{ => deprecated}/linsetup.py (100%) rename library/python/{ => deprecated}/pydfhack.cpp (100%) rename library/python/{ => deprecated}/pydfhack/__init__.py (100%) rename library/python/{ => deprecated}/pydfhack/blocks.py (100%) rename library/python/{ => deprecated}/pydfhack/construction.py (100%) rename library/python/{ => deprecated}/pydfhack/creature.py (100%) rename library/python/{ => deprecated}/pydfhack/decorators.py (100%) create mode 100644 library/python/deprecated/pydfhack/gui.py rename library/python/{ => deprecated}/pydfhack/map.py (100%) create mode 100644 library/python/deprecated/pydfhack/materials.py rename library/python/{ => deprecated}/pydfhack/meminfo.py (100%) rename library/python/{ => deprecated}/pydfhack/mixins.py (100%) create mode 100644 library/python/deprecated/pydfhack/position.py rename library/python/{ => deprecated}/pydfhack/pydfapi.py (100%) rename library/python/{c api => deprecated/pydfhack}/pydfhackflags.py (91%) create mode 100644 library/python/deprecated/pydfhack/pydftypes.py rename library/python/{ => deprecated}/pydfhack/translation.py (100%) create mode 100644 library/python/deprecated/pydfhack/vegetation.py rename library/python/{ => deprecated}/setup.py (100%) rename library/python/{ => deprecated}/test.py (100%) rename library/python/{ => deprecated}/tools/shell.py (100%) rename library/python/{ => deprecated}/tools/trees.py (100%) rename library/python/{c api => pydfhack}/buildings.py (100%) rename library/python/{c api => pydfhack}/constructions.py (100%) rename library/python/{c api => pydfhack}/context.py (100%) rename library/python/{c api => pydfhack}/creatures.py (100%) rename library/python/{c api => pydfhack}/dfhack_api_ctypes.py (100%) rename library/python/{c api => pydfhack}/enum.py (100%) rename library/python/{c api => pydfhack}/items.py (100%) rename library/python/{c api => pydfhack}/maps.py (100%) rename library/python/{c api => pydfhack}/util.py (100%) diff --git a/library/python/c api/gui.py b/library/python/c api/gui.py deleted file mode 100644 index 09a7c5c94..000000000 --- a/library/python/c api/gui.py +++ /dev/null @@ -1,25 +0,0 @@ -from ctypes import * -from pydfhack import libdfhack, ViewScreen - -libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ] - -class Gui(object): - def __init__(self, ptr): - self._gui_ptr = ptr - - def start(self): - return libdfhack.Gui_Start(self._gui_ptr) - - def finish(self): - return libdfhack.Gui_Finish(self._gui_ptr) - - def read_pause_state(self): - return libdfhack.Gui_ReadPauseState(self._pos_ptr) > 0 - - def read_view_screen(self): - s = ViewScreen() - - if libdfhack.Gui_ReadViewScreen(self._gui_ptr, byref(s)) > 0: - return s - else: - return None diff --git a/library/python/c api/materials.py b/library/python/c api/materials.py deleted file mode 100644 index 04d82fddb..000000000 --- a/library/python/c api/materials.py +++ /dev/null @@ -1,141 +0,0 @@ -from ctypes import * -from pydftypes import libdfhack -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): - def __init__(self, ptr): - self._mat_ptr = ptr - - self.inorganic = None - self.organic = None - self.tree = None - self.plant = None - self.race = None - self.race_ex = None - self.color = None - self.other = None - - def read_inorganic(self): - return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) - - def read_organic(self): - return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) - - def read_wood(self): - return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) - - def read_plant(self): - return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) - - def read_creature_types(self): - return libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) - - def read_creature_types_ex(self): - return libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) - - def read_descriptor_colors(self): - return libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) - - def read_others(self): - return libdfhack.Materials_ReadOthers(self._mat_ptr) - - def read_all(self): - libdfhack.Materials_ReadAllMaterials(self._mat_ptr) - - def get_description(self, material): - return libdfhack.Materials_getDescription(self._mat_ptr, byref(material)) - - def update_inorganic_cache(self): - def update_callback(count): - allocated = _allocate_array(Matgloss, count) - - self.inorganic = allocated[0] - - 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] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getOrganic(self._mat_ptr, callback) - - def update_tree_cache(self): - def update_callback(count): - allocated = _allocate_array(Matgloss, count) - - self.tree = allocated[0] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getTree(self._mat_ptr, callback) - - def update_plant_cache(self): - def update_callback(count): - allocated = _allocate_array(Matgloss, count) - - self.plant = allocated[0] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getPlant(self._mat_ptr, callback) - - def update_race_cache(self): - def update_callback(count): - allocated = _allocate_array(Matgloss, count) - - self.race = allocated[0] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getRace(self._mat_ptr, callback) - - def update_color_cache(self): - def update_callback(count): - allocated = _allocate_array(DescriptorColor, count) - - self.color = allocated[0] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getColor(self._mat_ptr, callback) - - def update_other_cache(self): - def update_callback(count): - allocated = _allocate_array(MatglossOther, count) - - self.other = allocated[0] - - return allocated[1] - - callback = _arr_create_func(update_callback) - - return libdfhack.Materials_getOther(self._mat_ptr, callback) diff --git a/library/python/c api/position.py b/library/python/c api/position.py deleted file mode 100644 index ffa758150..000000000 --- a/library/python/c api/position.py +++ /dev/null @@ -1,43 +0,0 @@ -from ctypes import * -from pydftypes import libdfhack - -class Position(object): - def __init__(self, ptr): - self._pos_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 get_view_coords(self): - if libdfhack.Position_getViewCoords(self._pos_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0: - return (self._vx.value, self._vy.value, self._vz.value) - else: - return (-1, -1, -1) - - def set_view_coords(self, v_coords): - self._vx.value, self._vy.value, self._vz.value = v_coords - - libdfhack.Position_setViewCoords(self._pos_ptr, self._vx, self._vy, self._vz) - - view_coords = property(get_view_coords, set_view_coords) - - def get_cursor_coords(self): - if libdfhack.Position_getCursorCoords(self._pos_ptr, byref(self._cx), byref(self._cy), byref(self._cz)) > 0: - return (self._cx.value, self._cy.value, self._cz.value) - else: - return (-1, -1, -1) - - def set_cursor_coords(self, c_coords): - self._cx.value, self._cy.value, self_cz.value = c_coords - - libdfhack.Position_setCursorCoords(self._pos_ptr, self._cx, self._cy, self._cz) - - cursor_coords = property(get_cursor_coords, set_cursor_coords) - - @property - def window_size(self): - if libdfhack.Position_getWindowSize(self._pos_ptr, byref(self._ww), byref(self._wh)) > 0: - return (self._ww.value, self._wh.value) - else: - return (-1, -1) diff --git a/library/python/c api/pydftypes.py b/library/python/c api/pydftypes.py deleted file mode 100644 index 376d99238..000000000 --- a/library/python/c api/pydftypes.py +++ /dev/null @@ -1,315 +0,0 @@ -from ctypes import * -from pydfhackflags import * -from enum import * -from util import * - -libdfhack = cdll.libdfhack - -libdfhack.alloc_byte_buffer_callback = alloc_byte_buffer -libdfhack.alloc_ubyte_buffer_callback = alloc_ubyte_buffer -libdfhack.alloc_short_buffer_callback = alloc_short_buffer -libdfhack.alloc_ushort_buffer_callback = alloc_ushort_buffer -libdfhack.alloc_int_buffer_callback = alloc_int_buffer -libdfhack.alloc_uint_buffer_callback = alloc_uint_buffer -libdfhack.alloc_char_buffer_callback = alloc_char_buffer - -int_ptr = POINTER(c_int) -uint_ptr = POINTER(c_uint) - -_arr_create_func = CFUNCTYPE(c_void_p, c_int) - -TileTypes40d = ((c_int * 16) * 16) -BiomeIndices40d = c_ubyte * 16 -Temperatures = ((c_ushort * 16) * 16) -Designations40d = ((DesignationFlags * 16) * 16) -Occupancies40d = ((OccupancyFlags * 16) * 16) - -class Position2D(Structure): - _fields_ = [("x", c_ushort), - ("y", c_ushort)] - -class PlaneCoord(Union): - _fields_ = [("xy", c_uint), - ("dim", Position2D)] - - def __cmp__(self, other): - if isinstance(other, PlaneCoord): - return self.xy - other.xy - else: - raise TypeError("argument must be of type %s" % type(self)) - -class Feature(Structure): - _fields_ = [("type", FeatureType), - ("main_material", c_short), - ("sub_material", c_short), - ("discovered", c_byte), - ("origin", c_uint)] - -class Vein(Structure): - _fields_ = [("vtable", c_uint), - ("type", c_int), - ("assignment", c_short * 16), - ("flags", c_uint), - ("address_of", c_uint)] - -class FrozenLiquidVein(Structure): - _fields_ = [("vtable", c_uint), - ("tiles", TileTypes40d), - ("address_of", c_uint)] - -class SpatterVein(Structure): - _fields_ = [("vtable", c_uint), - ("mat1", c_ushort), - ("unk1", c_ushort), - ("mat2", c_uint), - ("mat3", c_ushort), - ("intensity", ((c_ubyte * 16) * 16)), - ("address_of", c_uint)] - -class MapBlock40d(Structure): - _fields_ = [("tiletypes", TileTypes40d), - ("designation", Designations40d), - ("occupancy", Occupancies40d), - ("biome_indices", BiomeIndices40d), - ("origin", c_uint), - ("blockflags", BlockFlags), - ("global_feature", c_short), - ("local_feature", c_short)] - - -class ViewScreen(Structure): - _fields_ = [("type", c_int)] - -class Matgloss(Structure): - _fields_ = [("id", c_char * 128), - ("fore", c_byte), - ("back", c_byte), - ("bright", c_byte), - ("name", c_char * 128)] - -def _alloc_matgloss_buffer_callback(ptr, count): - allocated = _allocate_array(Matgloss, count) - - ptr = addressof(allocated[0]) - - return 1 - -_matgloss_functype = CFUNCTYPE(c_int, POINTER(Matgloss), c_uint) -libdfhack.alloc_matgloss_buffer_callback = _matgloss_functype(_alloc_matgloss_buffer_callback) - -class MatglossPair(Structure): - _fields_ = [("type", c_short), - ("index", c_int)] - -class DescriptorColor(Structure): - _fields_ = [("id", c_char * 128), - ("r", c_float), - ("v", c_float), - ("b", c_float), - ("name", c_char * 128)] - -def _alloc_descriptor_buffer_callback(ptr, count): - allocated = _allocate_array(DescriptorColor, count) - - ptr = addressof(allocated[0]) - - return 1 - -_descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint) -libdfhack.alloc_descriptor_buffer_callback = _descriptor_functype(_alloc_descriptor_buffer_callback) - -class MatglossOther(Structure): - _fields_ = [("rawname", c_char * 128)] - -def _alloc_matgloss_other_buffer_callback(count): - allocated = _allocate_array(MatglossOther, count) - - ptr = addressof(allocated[0]) - - return 1 - -_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint) -libdfhack.alloc_matgloss_other_buffer_callback = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback) - -class Building(Structure): - _fields_ = [("origin", c_uint), - ("vtable", c_uint), - ("x1", c_uint), - ("y1", c_uint), - ("x2", c_uint), - ("y2", c_uint), - ("z", c_uint), - ("material", MatglossPair), - ("type", c_uint)] - -class CustomWorkshop(Structure): - _fields_ = [("index", c_uint), - ("name", c_char * 256)] - -class Construction(Structure): - _fields_ = [("x", c_ushort), - ("y", c_ushort), - ("z", c_ushort), - ("form", c_ushort), - ("unk_8", c_ushort), - ("mat_type", c_ushort), - ("mat_idx", c_ushort), - ("unk3", c_ushort), - ("unk4", c_ushort), - ("unk5", c_ushort), - ("unk6", c_uint), - ("origin", c_uint)] - -class Tree(Structure): - _fields_ = [("type", c_ushort), - ("material", c_ushort), - ("x", c_ushort), - ("y", c_ushort), - ("z", c_ushort), - ("address", c_uint)] - -class Material(Structure): - _fields_ = [("itemType", c_short), - ("subType", c_short), - ("subIndex", c_short), - ("index", c_int), - ("flags", c_uint)] - -class Skill(Structure): - _fields_ = [("id", c_ushort), - ("experience", c_uint), - ("rating", c_ushort)] - -class Job(Structure): - _fields_ = [("active", c_byte), - ("jobId", c_uint), - ("jobType", c_ubyte), - ("occupationPtr", c_uint)] - -class Like(Structure): - _fields_ = [("type", c_short), - ("itemClass", c_short), - ("itemIndex", c_short), - ("material", MatglossPair), - ("active", c_byte)] - -class Attribute(Structure): - _fields_ = [("level", c_uint), - ("field_4", c_uint), - ("field_8", c_uint), - ("field_C", c_uint), - ("leveldiff", c_uint), - ("field_14", c_uint), - ("field_18", c_uint)] - -class Name(Structure): - _fields_ = [("first_name", (c_char * 128)), - ("nickname", (c_char * 128)), - ("words", (c_int * 7)), - ("parts_of_speech", (c_ushort * 7)), - ("language", c_uint), - ("has_name", c_byte)] - -class Note(Structure): - _fields_ = [("symbol", c_char), - ("foreground", c_ushort), - ("background", c_ushort), - ("name", (c_char * 128)), - ("x", c_ushort), - ("y", c_ushort), - ("z", c_ushort)] - -class Settlement(Structure): - _fields_ = [("origin", c_uint), - ("name", Name), - ("world_x", c_short), - ("world_y", c_short), - ("local_x1", c_short), - ("local_x2", c_short), - ("local_y1", c_short), - ("local_y2", c_short)] - -_NUM_CREATURE_TRAITS = 30 -_NUM_CREATURE_LABORS = 102 - -class Soul(Structure): - _fields_ = [("numSkills", c_ubyte), - ("skills", (Skill * 256)), - ("traits", (c_ushort * _NUM_CREATURE_TRAITS)), - ("analytical_ability", Attribute), - ("focus", Attribute), - ("willpower", Attribute), - ("creativity", Attribute), - ("intuition", Attribute), - ("patience", Attribute), - ("memory", Attribute), - ("linguistic_ability", Attribute), - ("spatial_sense", Attribute), - ("musicality", Attribute), - ("kinesthetic_sense", Attribute), - ("empathy", Attribute), - ("social_awareness", Attribute)] - -_MAX_COLORS = 15 - -class Creature(Structure): - _fields_ = [("origin", c_uint), - ("x", c_ushort), - ("y", c_ushort), - ("z", c_ushort), - ("race", c_uint), - ("civ", c_int), - ("flags1", CreatureFlags1), - ("flags2", CreatureFlags2), - ("name", Name), - ("mood", c_short), - ("mood_skill", c_short), - ("artifact_name", Name), - ("profession", c_ubyte), - ("custom_profession", (c_char * 128)), - ("labors", (c_ubyte * _NUM_CREATURE_LABORS)), - ("current_job", Job), - ("happiness", c_uint), - ("id", c_uint), - ("strength", Attribute), - ("agility", Attribute), - ("toughness", Attribute), - ("endurance", Attribute), - ("recuperation", Attribute), - ("disease_resistance", Attribute), - ("squad_leader_id", c_int), - ("sex", c_ubyte), - ("caste", c_ushort), - ("pregnancy_timer", c_uint), - ("has_default_soul", c_byte), - ("defaultSoul", Soul), - ("nbcolors", c_uint), - ("color", (c_uint * _MAX_COLORS))] - -class CreatureExtract(Structure): - _fields_ = [("rawname", (c_char * 128))] - -class BodyPart(Structure): - _fields_ = [("id", (c_char * 128)), - ("category", (c_char * 128)), - ("single", (c_char * 128)), - ("plural", (c_char * 128))] - -class ColorModifier(Structure): - _fields_ = [("part", (c_char * 128)), - ("colorlist", POINTER(c_uint)), - ("colorlistLength", c_uint)] - - def __init__(self): - self.part[0] = '\0' - self.colorlistLength = 0 - -ColorModifierPtr = POINTER(ColorModifier) - -def _alloc_empty_colormodifier_callback(ptr): - ptr = ColorModifierPtr(ColorModifier()) - - return 1 - -_empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr) -libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback) diff --git a/library/python/c api/vegetation.py b/library/python/c api/vegetation.py deleted file mode 100644 index 0c22d26b5..000000000 --- a/library/python/c api/vegetation.py +++ /dev/null @@ -1,25 +0,0 @@ -from ctypes import * -from pydftypes import libdfhack, Tree - -class Vegetation(object): - def __init__(self, ptr): - self._v_ptr = ptr - - def start(self): - n = c_uint(0) - - if libdfhack.Vegetation_Start(self._v_ptr, byref(n)) > 0: - return int(n.value) - else: - return -1 - - def finish(self): - return libdfhack.Vegetation_Finish(self._v_ptr) > 0 - - def read(self, index): - t = Tree() - - if libdfhack.Vegetation_Read(self._v_ptr, c_uint(index), byref(t)) > 0: - return t - else: - return None diff --git a/library/python/CMakeLists.txt b/library/python/deprecated/CMakeLists.txt similarity index 100% rename from library/python/CMakeLists.txt rename to library/python/deprecated/CMakeLists.txt diff --git a/library/python/DF_API.cpp b/library/python/deprecated/DF_API.cpp similarity index 100% rename from library/python/DF_API.cpp rename to library/python/deprecated/DF_API.cpp diff --git a/library/python/DF_Buildings.cpp b/library/python/deprecated/DF_Buildings.cpp similarity index 100% rename from library/python/DF_Buildings.cpp rename to library/python/deprecated/DF_Buildings.cpp diff --git a/library/python/DF_Constructions.cpp b/library/python/deprecated/DF_Constructions.cpp similarity index 100% rename from library/python/DF_Constructions.cpp rename to library/python/deprecated/DF_Constructions.cpp diff --git a/library/python/DF_CreatureManager.cpp b/library/python/deprecated/DF_CreatureManager.cpp similarity index 100% rename from library/python/DF_CreatureManager.cpp rename to library/python/deprecated/DF_CreatureManager.cpp diff --git a/library/python/DF_CreatureType.cpp b/library/python/deprecated/DF_CreatureType.cpp similarity index 100% rename from library/python/DF_CreatureType.cpp rename to library/python/deprecated/DF_CreatureType.cpp diff --git a/library/python/DF_GUI.cpp b/library/python/deprecated/DF_GUI.cpp similarity index 100% rename from library/python/DF_GUI.cpp rename to library/python/deprecated/DF_GUI.cpp diff --git a/library/python/DF_Helpers.cpp b/library/python/deprecated/DF_Helpers.cpp similarity index 100% rename from library/python/DF_Helpers.cpp rename to library/python/deprecated/DF_Helpers.cpp diff --git a/library/python/DF_Imports.cpp b/library/python/deprecated/DF_Imports.cpp similarity index 100% rename from library/python/DF_Imports.cpp rename to library/python/deprecated/DF_Imports.cpp diff --git a/library/python/DF_Maps.cpp b/library/python/deprecated/DF_Maps.cpp similarity index 100% rename from library/python/DF_Maps.cpp rename to library/python/deprecated/DF_Maps.cpp diff --git a/library/python/DF_Material.cpp b/library/python/deprecated/DF_Material.cpp similarity index 100% rename from library/python/DF_Material.cpp rename to library/python/deprecated/DF_Material.cpp diff --git a/library/python/DF_MemInfo.cpp b/library/python/deprecated/DF_MemInfo.cpp similarity index 100% rename from library/python/DF_MemInfo.cpp rename to library/python/deprecated/DF_MemInfo.cpp diff --git a/library/python/DF_Position.cpp b/library/python/deprecated/DF_Position.cpp similarity index 100% rename from library/python/DF_Position.cpp rename to library/python/deprecated/DF_Position.cpp diff --git a/library/python/DF_Translate.cpp b/library/python/deprecated/DF_Translate.cpp similarity index 100% rename from library/python/DF_Translate.cpp rename to library/python/deprecated/DF_Translate.cpp diff --git a/library/python/DF_Vegetation.cpp b/library/python/deprecated/DF_Vegetation.cpp similarity index 100% rename from library/python/DF_Vegetation.cpp rename to library/python/deprecated/DF_Vegetation.cpp diff --git a/library/python/build-linux b/library/python/deprecated/build-linux similarity index 100% rename from library/python/build-linux rename to library/python/deprecated/build-linux diff --git a/library/python/build.bat b/library/python/deprecated/build.bat similarity index 100% rename from library/python/build.bat rename to library/python/deprecated/build.bat diff --git a/library/python/dfhack_api_ctypes.py b/library/python/deprecated/dfhack_api_ctypes.py similarity index 100% rename from library/python/dfhack_api_ctypes.py rename to library/python/deprecated/dfhack_api_ctypes.py diff --git a/library/python/examples/attachtest.py b/library/python/deprecated/examples/attachtest.py similarity index 100% rename from library/python/examples/attachtest.py rename to library/python/deprecated/examples/attachtest.py diff --git a/library/python/examples/miscutils.py b/library/python/deprecated/examples/miscutils.py similarity index 100% rename from library/python/examples/miscutils.py rename to library/python/deprecated/examples/miscutils.py diff --git a/library/python/examples/position.py b/library/python/deprecated/examples/position.py similarity index 100% rename from library/python/examples/position.py rename to library/python/deprecated/examples/position.py diff --git a/library/python/examples/settlementdump.py b/library/python/deprecated/examples/settlementdump.py similarity index 100% rename from library/python/examples/settlementdump.py rename to library/python/deprecated/examples/settlementdump.py diff --git a/library/python/examples/suspendtest.py b/library/python/deprecated/examples/suspendtest.py similarity index 100% rename from library/python/examples/suspendtest.py rename to library/python/deprecated/examples/suspendtest.py diff --git a/library/python/examples/treedump.py b/library/python/deprecated/examples/treedump.py similarity index 100% rename from library/python/examples/treedump.py rename to library/python/deprecated/examples/treedump.py diff --git a/library/python/ez_setup.py b/library/python/deprecated/ez_setup.py similarity index 100% rename from library/python/ez_setup.py rename to library/python/deprecated/ez_setup.py diff --git a/library/python/linsetup.py b/library/python/deprecated/linsetup.py similarity index 100% rename from library/python/linsetup.py rename to library/python/deprecated/linsetup.py diff --git a/library/python/pydfhack.cpp b/library/python/deprecated/pydfhack.cpp similarity index 100% rename from library/python/pydfhack.cpp rename to library/python/deprecated/pydfhack.cpp diff --git a/library/python/pydfhack/__init__.py b/library/python/deprecated/pydfhack/__init__.py similarity index 100% rename from library/python/pydfhack/__init__.py rename to library/python/deprecated/pydfhack/__init__.py diff --git a/library/python/pydfhack/blocks.py b/library/python/deprecated/pydfhack/blocks.py similarity index 100% rename from library/python/pydfhack/blocks.py rename to library/python/deprecated/pydfhack/blocks.py diff --git a/library/python/pydfhack/construction.py b/library/python/deprecated/pydfhack/construction.py similarity index 100% rename from library/python/pydfhack/construction.py rename to library/python/deprecated/pydfhack/construction.py diff --git a/library/python/pydfhack/creature.py b/library/python/deprecated/pydfhack/creature.py similarity index 100% rename from library/python/pydfhack/creature.py rename to library/python/deprecated/pydfhack/creature.py diff --git a/library/python/pydfhack/decorators.py b/library/python/deprecated/pydfhack/decorators.py similarity index 100% rename from library/python/pydfhack/decorators.py rename to library/python/deprecated/pydfhack/decorators.py diff --git a/library/python/deprecated/pydfhack/gui.py b/library/python/deprecated/pydfhack/gui.py new file mode 100644 index 000000000..07192f67c --- /dev/null +++ b/library/python/deprecated/pydfhack/gui.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Python class for DF_Hack::GUI +""" +from ._pydfhack import _GUIManager +class GUI(_GUIManager): + api = None + started = False + def __init__(self, api, *args, **kwds): + _GUIManager.__init__(self, args, kwds) + self.api = api + + def prepare(self): + """ + Enforce Suspend/Start + """ + if self.api.prepare(): + if not self.started: + self.started = self.Start() + return self.started + else: + return False + + + diff --git a/library/python/pydfhack/map.py b/library/python/deprecated/pydfhack/map.py similarity index 100% rename from library/python/pydfhack/map.py rename to library/python/deprecated/pydfhack/map.py diff --git a/library/python/deprecated/pydfhack/materials.py b/library/python/deprecated/pydfhack/materials.py new file mode 100644 index 000000000..13e02c682 --- /dev/null +++ b/library/python/deprecated/pydfhack/materials.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +""" +Python class for DF_Hack::Materials +""" +from ._pydfhack import _MaterialsManager +from .mixins import NoStart +from .decorators import suspend + +class Materials(NoStart, _MaterialsManager): + api = None + cls = _MaterialsManager + def __init__(self, api, *args, **kwds): + cls.__init__(self, args, kwds) + self.api = api + + @suspend + def Read_Wood_Materials(self, *args, **kw): + return self.cls.Read_Wood_Materials(self, *args, **kw) + + @suspend + def Read_Plant_Materials(self, *args, **kw): + return self.cls.Read_Plant_Materials(self, *args, **kw) + + @suspend + def Read_Inorganic_Materials(self, *args, **kw): + return self.cls.Read_Inorganic_Materials(self, *args, **kw) + + @suspend + def Read_Descriptor_Colors(self, *args, **kw): + return self.cls.Read_Descriptor_Colors(self, *args, **kw) + + @suspend + def Read_Creature_Types(self, *args, **kw): + return self.cls.Read_Creature_Types(self, *args, **kw) + + @suspend + def Read_Organic_Materials(self, *args, **kw): + return self.cls.Read_Organic_Materials(self, *args, **kw) + + @suspend + def Read_Creature_Types_Ex(self, *args, **kw): + return self.cls.Read_Creature_Types_Ex(self, *args, **kw) diff --git a/library/python/pydfhack/meminfo.py b/library/python/deprecated/pydfhack/meminfo.py similarity index 100% rename from library/python/pydfhack/meminfo.py rename to library/python/deprecated/pydfhack/meminfo.py diff --git a/library/python/pydfhack/mixins.py b/library/python/deprecated/pydfhack/mixins.py similarity index 100% rename from library/python/pydfhack/mixins.py rename to library/python/deprecated/pydfhack/mixins.py diff --git a/library/python/deprecated/pydfhack/position.py b/library/python/deprecated/pydfhack/position.py new file mode 100644 index 000000000..7956ea812 --- /dev/null +++ b/library/python/deprecated/pydfhack/position.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +""" +Python class for DF_Hack::Position +""" +from ._pydfhack import _PositionManager +from .blocks import Point, Block +from .mixins import NoStart +from .decorators import suspend + +class Position(NoStart, _PositionManager): + api = None + cls = _PositionManager + def __init__(self, api, *args, **kwds): + self.cls.__init__(self, args, kwds) + self.api = api + + @suspend + def get_cursor(self): + coords = self.cursor_coords + if coords: + return Point(*coords) + else: + return None + + @suspend + def get_window_size(self): + wsize = self.window_size + return wsize + + @suspend + def get_view_coords(self): + coords = self.view_coords + return Point(*coords) + + @suspend + def get_cursor_tile(self): + point = self.get_cursor() + if point: + tile = self.api.maps.get_tile(point=point) + return tile + else: + return None diff --git a/library/python/pydfhack/pydfapi.py b/library/python/deprecated/pydfhack/pydfapi.py similarity index 100% rename from library/python/pydfhack/pydfapi.py rename to library/python/deprecated/pydfhack/pydfapi.py diff --git a/library/python/c api/pydfhackflags.py b/library/python/deprecated/pydfhack/pydfhackflags.py similarity index 91% rename from library/python/c api/pydfhackflags.py rename to library/python/deprecated/pydfhack/pydfhackflags.py index 645bba659..f8c15bef7 100644 --- a/library/python/c api/pydfhackflags.py +++ b/library/python/deprecated/pydfhack/pydfhackflags.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- from ctypes import Structure, Union, c_uint -from enum import * class DesignationStruct(Structure): _fields_ = [("flow_size", c_uint, 3), ("pile", c_uint, 1), - ("dig", DesignationType, 3), + ("dig", c_uint, 3), ("smooth", c_uint, 2), ("hidden", c_uint, 1), ("geolayer_index", c_uint, 4), @@ -182,16 +181,30 @@ class ItemFlags(Union): def __int__(self): return self.whole +dig_types = { "no" : 0, + "default" : 1, + "ud_stair" : 2, + "channel" : 3, + "ramp" : 4, + "d_stair" : 5, + "u_stair" : 6, + "whatever" : 7 } + +traffic_types = { "normal" : 0, + "low" : 1, + "high" : 2, + "restricted" : 3 } + class BlockFlagStruct(Structure): _fields_ = [("designated", c_uint, 1), - ("unk_1", c_uint, 1), - ("liquid_1", c_uint, 1), - ("liquid_2", c_uint, 1), - ("unk_2", c_uint, 28)] + ("unk_1", c_uint, 1), + ("liquid_1", c_uint, 1), + ("liquid_2", c_uint, 1), + ("unk_2", c_uint, 28)] class BlockFlags(Union): _fields_ = [("whole", c_uint, 32), - ("bits", BlockFlagStruct)] + ("bits", BlockFlagStruct)] def __init__(self, inital = 0): self.whole = initial diff --git a/library/python/deprecated/pydfhack/pydftypes.py b/library/python/deprecated/pydfhack/pydftypes.py new file mode 100644 index 000000000..eadef49c4 --- /dev/null +++ b/library/python/deprecated/pydfhack/pydftypes.py @@ -0,0 +1,50 @@ +from ctypes import * +from collections import namedtuple + +Position2D = namedtuple("Position2D", "x, y") +Position3D = namedtuple("Position3D", "x, y, z") +Rectangle = namedtuple("Rectangle", "x1, y1, x2, y2") +Note = namedtuple("Note", "symbol, foreground, background, name, position") +Construction = namedtuple("Construction", "position, form, unk_8, mat_type, mat_idx, unk3, unk4, unk5, unk6, origin") +Vein = namedtuple("Vein", "vtable, type, flags, address, assignment") +FrozenLiquidVein = namedtuple("FrozenLiquidVein", "vtable, address, tiles") +SpatterVein = namedtuple("SpatterVein", "vtable, address, mat1, unk1, mat2, mat3, intensity") +Settlement = namedtuple("Settlement", "origin, name, world_pos, local_pos") +Attribute = namedtuple("Attribute", "level, field_4, field_8, field_C, leveldiff, field_14, field_18"); +Skill = namedtuple("Skill", "id, experience, rating") +Tree = namedtuple("Tree", "type, material, position, address") +CreatureCaste = namedtuple("CreatureCaste", "rawname, singular, plural, adjective") +CreatureTypeEx = namedtuple("CreatureTypeEx", "rawname, castes, tile_character, tilecolor") +TileColor = namedtuple("TileColor", "fore, back, bright") +Name = namedtuple("Name", "first_name, nickname, language, has_name, words, parts_of_speech") + +char_array = c_char * 128 + +class Soul(object): + def __init__(self, *args, **kwds): + if kwds: + for k, v in kwds.iteritems(): + self.__dict__[k] = v + +class MapBlock40d(object): + pass + +class ViewScreen(Structure): + _fields_ = [("type", c_int)] + +class Matgloss(Structure): + _fields_ = [("id", char_array), + ("fore", c_byte), + ("back", c_byte), + ("bright", c_byte), + ("name", char_array)] + +class Descriptor_Color(Structure): + _fields_ = [("id", char_array), + ("r", c_float), + ("v", c_float), + ("b", c_float), + ("name", char_array)] + +class MatglossOther(Structure): + _fields_ = [("rawname", char_array)] diff --git a/library/python/pydfhack/translation.py b/library/python/deprecated/pydfhack/translation.py similarity index 100% rename from library/python/pydfhack/translation.py rename to library/python/deprecated/pydfhack/translation.py diff --git a/library/python/deprecated/pydfhack/vegetation.py b/library/python/deprecated/pydfhack/vegetation.py new file mode 100644 index 000000000..ce1262a13 --- /dev/null +++ b/library/python/deprecated/pydfhack/vegetation.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +""" +Python class for DF_Hack::Vegetation +""" +from ._pydfhack import _VegetationManager +from .mixins import NeedsStart +from .decorators import suspend + +class Vegetation(NeedsStart, _VegetationManager): + api = None + cls = _VegetationManager + def __init__(self, api, *args, **kwds): + self.cls.__init__(self, args, kwds) + self.api = api + + @suspend + def Read(self, *args, **kw): + return self.cls.Read(self, *args, **kw) diff --git a/library/python/setup.py b/library/python/deprecated/setup.py similarity index 100% rename from library/python/setup.py rename to library/python/deprecated/setup.py diff --git a/library/python/test.py b/library/python/deprecated/test.py similarity index 100% rename from library/python/test.py rename to library/python/deprecated/test.py diff --git a/library/python/tools/shell.py b/library/python/deprecated/tools/shell.py similarity index 100% rename from library/python/tools/shell.py rename to library/python/deprecated/tools/shell.py diff --git a/library/python/tools/trees.py b/library/python/deprecated/tools/trees.py similarity index 100% rename from library/python/tools/trees.py rename to library/python/deprecated/tools/trees.py diff --git a/library/python/c api/buildings.py b/library/python/pydfhack/buildings.py similarity index 100% rename from library/python/c api/buildings.py rename to library/python/pydfhack/buildings.py diff --git a/library/python/c api/constructions.py b/library/python/pydfhack/constructions.py similarity index 100% rename from library/python/c api/constructions.py rename to library/python/pydfhack/constructions.py diff --git a/library/python/c api/context.py b/library/python/pydfhack/context.py similarity index 100% rename from library/python/c api/context.py rename to library/python/pydfhack/context.py diff --git a/library/python/c api/creatures.py b/library/python/pydfhack/creatures.py similarity index 100% rename from library/python/c api/creatures.py rename to library/python/pydfhack/creatures.py diff --git a/library/python/c api/dfhack_api_ctypes.py b/library/python/pydfhack/dfhack_api_ctypes.py similarity index 100% rename from library/python/c api/dfhack_api_ctypes.py rename to library/python/pydfhack/dfhack_api_ctypes.py diff --git a/library/python/c api/enum.py b/library/python/pydfhack/enum.py similarity index 100% rename from library/python/c api/enum.py rename to library/python/pydfhack/enum.py diff --git a/library/python/pydfhack/gui.py b/library/python/pydfhack/gui.py index 07192f67c..09a7c5c94 100644 --- a/library/python/pydfhack/gui.py +++ b/library/python/pydfhack/gui.py @@ -1,25 +1,25 @@ -# -*- coding: utf-8 -*- -""" -Python class for DF_Hack::GUI -""" -from ._pydfhack import _GUIManager -class GUI(_GUIManager): - api = None - started = False - def __init__(self, api, *args, **kwds): - _GUIManager.__init__(self, args, kwds) - self.api = api +from ctypes import * +from pydfhack import libdfhack, ViewScreen - def prepare(self): - """ - Enforce Suspend/Start - """ - if self.api.prepare(): - if not self.started: - self.started = self.Start() - return self.started - else: - return False - - +libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ] + +class Gui(object): + def __init__(self, ptr): + self._gui_ptr = ptr + + def start(self): + return libdfhack.Gui_Start(self._gui_ptr) + + def finish(self): + return libdfhack.Gui_Finish(self._gui_ptr) + def read_pause_state(self): + return libdfhack.Gui_ReadPauseState(self._pos_ptr) > 0 + + def read_view_screen(self): + s = ViewScreen() + + if libdfhack.Gui_ReadViewScreen(self._gui_ptr, byref(s)) > 0: + return s + else: + return None diff --git a/library/python/c api/items.py b/library/python/pydfhack/items.py similarity index 100% rename from library/python/c api/items.py rename to library/python/pydfhack/items.py diff --git a/library/python/c api/maps.py b/library/python/pydfhack/maps.py similarity index 100% rename from library/python/c api/maps.py rename to library/python/pydfhack/maps.py diff --git a/library/python/pydfhack/materials.py b/library/python/pydfhack/materials.py index 13e02c682..04d82fddb 100644 --- a/library/python/pydfhack/materials.py +++ b/library/python/pydfhack/materials.py @@ -1,42 +1,141 @@ -# -*- coding: utf-8 -*- -""" -Python class for DF_Hack::Materials -""" -from ._pydfhack import _MaterialsManager -from .mixins import NoStart -from .decorators import suspend - -class Materials(NoStart, _MaterialsManager): - api = None - cls = _MaterialsManager - def __init__(self, api, *args, **kwds): - cls.__init__(self, args, kwds) - self.api = api - - @suspend - def Read_Wood_Materials(self, *args, **kw): - return self.cls.Read_Wood_Materials(self, *args, **kw) - - @suspend - def Read_Plant_Materials(self, *args, **kw): - return self.cls.Read_Plant_Materials(self, *args, **kw) - - @suspend - def Read_Inorganic_Materials(self, *args, **kw): - return self.cls.Read_Inorganic_Materials(self, *args, **kw) - - @suspend - def Read_Descriptor_Colors(self, *args, **kw): - return self.cls.Read_Descriptor_Colors(self, *args, **kw) - - @suspend - def Read_Creature_Types(self, *args, **kw): - return self.cls.Read_Creature_Types(self, *args, **kw) - - @suspend - def Read_Organic_Materials(self, *args, **kw): - return self.cls.Read_Organic_Materials(self, *args, **kw) - - @suspend - def Read_Creature_Types_Ex(self, *args, **kw): - return self.cls.Read_Creature_Types_Ex(self, *args, **kw) +from ctypes import * +from pydftypes import libdfhack +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): + def __init__(self, ptr): + self._mat_ptr = ptr + + self.inorganic = None + self.organic = None + self.tree = None + self.plant = None + self.race = None + self.race_ex = None + self.color = None + self.other = None + + def read_inorganic(self): + return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) + + def read_organic(self): + return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) + + def read_wood(self): + return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) + + def read_plant(self): + return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) + + def read_creature_types(self): + return libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) + + def read_creature_types_ex(self): + return libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) + + def read_descriptor_colors(self): + return libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) + + def read_others(self): + return libdfhack.Materials_ReadOthers(self._mat_ptr) + + def read_all(self): + libdfhack.Materials_ReadAllMaterials(self._mat_ptr) + + def get_description(self, material): + return libdfhack.Materials_getDescription(self._mat_ptr, byref(material)) + + def update_inorganic_cache(self): + def update_callback(count): + allocated = _allocate_array(Matgloss, count) + + self.inorganic = allocated[0] + + 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] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getOrganic(self._mat_ptr, callback) + + def update_tree_cache(self): + def update_callback(count): + allocated = _allocate_array(Matgloss, count) + + self.tree = allocated[0] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getTree(self._mat_ptr, callback) + + def update_plant_cache(self): + def update_callback(count): + allocated = _allocate_array(Matgloss, count) + + self.plant = allocated[0] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getPlant(self._mat_ptr, callback) + + def update_race_cache(self): + def update_callback(count): + allocated = _allocate_array(Matgloss, count) + + self.race = allocated[0] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getRace(self._mat_ptr, callback) + + def update_color_cache(self): + def update_callback(count): + allocated = _allocate_array(DescriptorColor, count) + + self.color = allocated[0] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getColor(self._mat_ptr, callback) + + def update_other_cache(self): + def update_callback(count): + allocated = _allocate_array(MatglossOther, count) + + self.other = allocated[0] + + return allocated[1] + + callback = _arr_create_func(update_callback) + + return libdfhack.Materials_getOther(self._mat_ptr, callback) diff --git a/library/python/pydfhack/position.py b/library/python/pydfhack/position.py index 7956ea812..ffa758150 100644 --- a/library/python/pydfhack/position.py +++ b/library/python/pydfhack/position.py @@ -1,42 +1,43 @@ -# -*- coding: utf-8 -*- -""" -Python class for DF_Hack::Position -""" -from ._pydfhack import _PositionManager -from .blocks import Point, Block -from .mixins import NoStart -from .decorators import suspend - -class Position(NoStart, _PositionManager): - api = None - cls = _PositionManager - def __init__(self, api, *args, **kwds): - self.cls.__init__(self, args, kwds) - self.api = api - - @suspend - def get_cursor(self): - coords = self.cursor_coords - if coords: - return Point(*coords) - else: - return None +from ctypes import * +from pydftypes import libdfhack + +class Position(object): + def __init__(self, ptr): + self._pos_ptr = ptr - @suspend - def get_window_size(self): - wsize = self.window_size - return wsize + 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() - @suspend def get_view_coords(self): - coords = self.view_coords - return Point(*coords) - - @suspend - def get_cursor_tile(self): - point = self.get_cursor() - if point: - tile = self.api.maps.get_tile(point=point) - return tile + if libdfhack.Position_getViewCoords(self._pos_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0: + return (self._vx.value, self._vy.value, self._vz.value) + else: + return (-1, -1, -1) + + def set_view_coords(self, v_coords): + self._vx.value, self._vy.value, self._vz.value = v_coords + + libdfhack.Position_setViewCoords(self._pos_ptr, self._vx, self._vy, self._vz) + + view_coords = property(get_view_coords, set_view_coords) + + def get_cursor_coords(self): + if libdfhack.Position_getCursorCoords(self._pos_ptr, byref(self._cx), byref(self._cy), byref(self._cz)) > 0: + return (self._cx.value, self._cy.value, self._cz.value) + else: + return (-1, -1, -1) + + def set_cursor_coords(self, c_coords): + self._cx.value, self._cy.value, self_cz.value = c_coords + + libdfhack.Position_setCursorCoords(self._pos_ptr, self._cx, self._cy, self._cz) + + cursor_coords = property(get_cursor_coords, set_cursor_coords) + + @property + def window_size(self): + if libdfhack.Position_getWindowSize(self._pos_ptr, byref(self._ww), byref(self._wh)) > 0: + return (self._ww.value, self._wh.value) else: - return None + return (-1, -1) diff --git a/library/python/pydfhack/pydfhackflags.py b/library/python/pydfhack/pydfhackflags.py index f8c15bef7..645bba659 100644 --- a/library/python/pydfhack/pydfhackflags.py +++ b/library/python/pydfhack/pydfhackflags.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from ctypes import Structure, Union, c_uint +from enum import * class DesignationStruct(Structure): _fields_ = [("flow_size", c_uint, 3), ("pile", c_uint, 1), - ("dig", c_uint, 3), + ("dig", DesignationType, 3), ("smooth", c_uint, 2), ("hidden", c_uint, 1), ("geolayer_index", c_uint, 4), @@ -181,30 +182,16 @@ class ItemFlags(Union): def __int__(self): return self.whole -dig_types = { "no" : 0, - "default" : 1, - "ud_stair" : 2, - "channel" : 3, - "ramp" : 4, - "d_stair" : 5, - "u_stair" : 6, - "whatever" : 7 } - -traffic_types = { "normal" : 0, - "low" : 1, - "high" : 2, - "restricted" : 3 } - class BlockFlagStruct(Structure): _fields_ = [("designated", c_uint, 1), - ("unk_1", c_uint, 1), - ("liquid_1", c_uint, 1), - ("liquid_2", c_uint, 1), - ("unk_2", c_uint, 28)] + ("unk_1", c_uint, 1), + ("liquid_1", c_uint, 1), + ("liquid_2", c_uint, 1), + ("unk_2", c_uint, 28)] class BlockFlags(Union): _fields_ = [("whole", c_uint, 32), - ("bits", BlockFlagStruct)] + ("bits", BlockFlagStruct)] def __init__(self, inital = 0): self.whole = initial diff --git a/library/python/pydfhack/pydftypes.py b/library/python/pydfhack/pydftypes.py index eadef49c4..376d99238 100644 --- a/library/python/pydfhack/pydftypes.py +++ b/library/python/pydfhack/pydftypes.py @@ -1,50 +1,315 @@ from ctypes import * -from collections import namedtuple - -Position2D = namedtuple("Position2D", "x, y") -Position3D = namedtuple("Position3D", "x, y, z") -Rectangle = namedtuple("Rectangle", "x1, y1, x2, y2") -Note = namedtuple("Note", "symbol, foreground, background, name, position") -Construction = namedtuple("Construction", "position, form, unk_8, mat_type, mat_idx, unk3, unk4, unk5, unk6, origin") -Vein = namedtuple("Vein", "vtable, type, flags, address, assignment") -FrozenLiquidVein = namedtuple("FrozenLiquidVein", "vtable, address, tiles") -SpatterVein = namedtuple("SpatterVein", "vtable, address, mat1, unk1, mat2, mat3, intensity") -Settlement = namedtuple("Settlement", "origin, name, world_pos, local_pos") -Attribute = namedtuple("Attribute", "level, field_4, field_8, field_C, leveldiff, field_14, field_18"); -Skill = namedtuple("Skill", "id, experience, rating") -Tree = namedtuple("Tree", "type, material, position, address") -CreatureCaste = namedtuple("CreatureCaste", "rawname, singular, plural, adjective") -CreatureTypeEx = namedtuple("CreatureTypeEx", "rawname, castes, tile_character, tilecolor") -TileColor = namedtuple("TileColor", "fore, back, bright") -Name = namedtuple("Name", "first_name, nickname, language, has_name, words, parts_of_speech") - -char_array = c_char * 128 - -class Soul(object): - def __init__(self, *args, **kwds): - if kwds: - for k, v in kwds.iteritems(): - self.__dict__[k] = v - -class MapBlock40d(object): - pass +from pydfhackflags import * +from enum import * +from util import * + +libdfhack = cdll.libdfhack + +libdfhack.alloc_byte_buffer_callback = alloc_byte_buffer +libdfhack.alloc_ubyte_buffer_callback = alloc_ubyte_buffer +libdfhack.alloc_short_buffer_callback = alloc_short_buffer +libdfhack.alloc_ushort_buffer_callback = alloc_ushort_buffer +libdfhack.alloc_int_buffer_callback = alloc_int_buffer +libdfhack.alloc_uint_buffer_callback = alloc_uint_buffer +libdfhack.alloc_char_buffer_callback = alloc_char_buffer + +int_ptr = POINTER(c_int) +uint_ptr = POINTER(c_uint) + +_arr_create_func = CFUNCTYPE(c_void_p, c_int) + +TileTypes40d = ((c_int * 16) * 16) +BiomeIndices40d = c_ubyte * 16 +Temperatures = ((c_ushort * 16) * 16) +Designations40d = ((DesignationFlags * 16) * 16) +Occupancies40d = ((OccupancyFlags * 16) * 16) + +class Position2D(Structure): + _fields_ = [("x", c_ushort), + ("y", c_ushort)] + +class PlaneCoord(Union): + _fields_ = [("xy", c_uint), + ("dim", Position2D)] + + def __cmp__(self, other): + if isinstance(other, PlaneCoord): + return self.xy - other.xy + else: + raise TypeError("argument must be of type %s" % type(self)) + +class Feature(Structure): + _fields_ = [("type", FeatureType), + ("main_material", c_short), + ("sub_material", c_short), + ("discovered", c_byte), + ("origin", c_uint)] + +class Vein(Structure): + _fields_ = [("vtable", c_uint), + ("type", c_int), + ("assignment", c_short * 16), + ("flags", c_uint), + ("address_of", c_uint)] + +class FrozenLiquidVein(Structure): + _fields_ = [("vtable", c_uint), + ("tiles", TileTypes40d), + ("address_of", c_uint)] + +class SpatterVein(Structure): + _fields_ = [("vtable", c_uint), + ("mat1", c_ushort), + ("unk1", c_ushort), + ("mat2", c_uint), + ("mat3", c_ushort), + ("intensity", ((c_ubyte * 16) * 16)), + ("address_of", c_uint)] + +class MapBlock40d(Structure): + _fields_ = [("tiletypes", TileTypes40d), + ("designation", Designations40d), + ("occupancy", Occupancies40d), + ("biome_indices", BiomeIndices40d), + ("origin", c_uint), + ("blockflags", BlockFlags), + ("global_feature", c_short), + ("local_feature", c_short)] + class ViewScreen(Structure): _fields_ = [("type", c_int)] class Matgloss(Structure): - _fields_ = [("id", char_array), + _fields_ = [("id", c_char * 128), ("fore", c_byte), ("back", c_byte), ("bright", c_byte), - ("name", char_array)] + ("name", c_char * 128)] -class Descriptor_Color(Structure): - _fields_ = [("id", char_array), +def _alloc_matgloss_buffer_callback(ptr, count): + allocated = _allocate_array(Matgloss, count) + + ptr = addressof(allocated[0]) + + return 1 + +_matgloss_functype = CFUNCTYPE(c_int, POINTER(Matgloss), c_uint) +libdfhack.alloc_matgloss_buffer_callback = _matgloss_functype(_alloc_matgloss_buffer_callback) + +class MatglossPair(Structure): + _fields_ = [("type", c_short), + ("index", c_int)] + +class DescriptorColor(Structure): + _fields_ = [("id", c_char * 128), ("r", c_float), ("v", c_float), ("b", c_float), - ("name", char_array)] + ("name", c_char * 128)] + +def _alloc_descriptor_buffer_callback(ptr, count): + allocated = _allocate_array(DescriptorColor, count) + + ptr = addressof(allocated[0]) + + return 1 + +_descriptor_functype = CFUNCTYPE(c_int, POINTER(DescriptorColor), c_uint) +libdfhack.alloc_descriptor_buffer_callback = _descriptor_functype(_alloc_descriptor_buffer_callback) class MatglossOther(Structure): - _fields_ = [("rawname", char_array)] + _fields_ = [("rawname", c_char * 128)] + +def _alloc_matgloss_other_buffer_callback(count): + allocated = _allocate_array(MatglossOther, count) + + ptr = addressof(allocated[0]) + + return 1 + +_matgloss_other_functype = CFUNCTYPE(c_int, POINTER(MatglossOther), c_uint) +libdfhack.alloc_matgloss_other_buffer_callback = _matgloss_other_functype(_alloc_matgloss_other_buffer_callback) + +class Building(Structure): + _fields_ = [("origin", c_uint), + ("vtable", c_uint), + ("x1", c_uint), + ("y1", c_uint), + ("x2", c_uint), + ("y2", c_uint), + ("z", c_uint), + ("material", MatglossPair), + ("type", c_uint)] + +class CustomWorkshop(Structure): + _fields_ = [("index", c_uint), + ("name", c_char * 256)] + +class Construction(Structure): + _fields_ = [("x", c_ushort), + ("y", c_ushort), + ("z", c_ushort), + ("form", c_ushort), + ("unk_8", c_ushort), + ("mat_type", c_ushort), + ("mat_idx", c_ushort), + ("unk3", c_ushort), + ("unk4", c_ushort), + ("unk5", c_ushort), + ("unk6", c_uint), + ("origin", c_uint)] + +class Tree(Structure): + _fields_ = [("type", c_ushort), + ("material", c_ushort), + ("x", c_ushort), + ("y", c_ushort), + ("z", c_ushort), + ("address", c_uint)] + +class Material(Structure): + _fields_ = [("itemType", c_short), + ("subType", c_short), + ("subIndex", c_short), + ("index", c_int), + ("flags", c_uint)] + +class Skill(Structure): + _fields_ = [("id", c_ushort), + ("experience", c_uint), + ("rating", c_ushort)] + +class Job(Structure): + _fields_ = [("active", c_byte), + ("jobId", c_uint), + ("jobType", c_ubyte), + ("occupationPtr", c_uint)] + +class Like(Structure): + _fields_ = [("type", c_short), + ("itemClass", c_short), + ("itemIndex", c_short), + ("material", MatglossPair), + ("active", c_byte)] + +class Attribute(Structure): + _fields_ = [("level", c_uint), + ("field_4", c_uint), + ("field_8", c_uint), + ("field_C", c_uint), + ("leveldiff", c_uint), + ("field_14", c_uint), + ("field_18", c_uint)] + +class Name(Structure): + _fields_ = [("first_name", (c_char * 128)), + ("nickname", (c_char * 128)), + ("words", (c_int * 7)), + ("parts_of_speech", (c_ushort * 7)), + ("language", c_uint), + ("has_name", c_byte)] + +class Note(Structure): + _fields_ = [("symbol", c_char), + ("foreground", c_ushort), + ("background", c_ushort), + ("name", (c_char * 128)), + ("x", c_ushort), + ("y", c_ushort), + ("z", c_ushort)] + +class Settlement(Structure): + _fields_ = [("origin", c_uint), + ("name", Name), + ("world_x", c_short), + ("world_y", c_short), + ("local_x1", c_short), + ("local_x2", c_short), + ("local_y1", c_short), + ("local_y2", c_short)] + +_NUM_CREATURE_TRAITS = 30 +_NUM_CREATURE_LABORS = 102 + +class Soul(Structure): + _fields_ = [("numSkills", c_ubyte), + ("skills", (Skill * 256)), + ("traits", (c_ushort * _NUM_CREATURE_TRAITS)), + ("analytical_ability", Attribute), + ("focus", Attribute), + ("willpower", Attribute), + ("creativity", Attribute), + ("intuition", Attribute), + ("patience", Attribute), + ("memory", Attribute), + ("linguistic_ability", Attribute), + ("spatial_sense", Attribute), + ("musicality", Attribute), + ("kinesthetic_sense", Attribute), + ("empathy", Attribute), + ("social_awareness", Attribute)] + +_MAX_COLORS = 15 + +class Creature(Structure): + _fields_ = [("origin", c_uint), + ("x", c_ushort), + ("y", c_ushort), + ("z", c_ushort), + ("race", c_uint), + ("civ", c_int), + ("flags1", CreatureFlags1), + ("flags2", CreatureFlags2), + ("name", Name), + ("mood", c_short), + ("mood_skill", c_short), + ("artifact_name", Name), + ("profession", c_ubyte), + ("custom_profession", (c_char * 128)), + ("labors", (c_ubyte * _NUM_CREATURE_LABORS)), + ("current_job", Job), + ("happiness", c_uint), + ("id", c_uint), + ("strength", Attribute), + ("agility", Attribute), + ("toughness", Attribute), + ("endurance", Attribute), + ("recuperation", Attribute), + ("disease_resistance", Attribute), + ("squad_leader_id", c_int), + ("sex", c_ubyte), + ("caste", c_ushort), + ("pregnancy_timer", c_uint), + ("has_default_soul", c_byte), + ("defaultSoul", Soul), + ("nbcolors", c_uint), + ("color", (c_uint * _MAX_COLORS))] + +class CreatureExtract(Structure): + _fields_ = [("rawname", (c_char * 128))] + +class BodyPart(Structure): + _fields_ = [("id", (c_char * 128)), + ("category", (c_char * 128)), + ("single", (c_char * 128)), + ("plural", (c_char * 128))] + +class ColorModifier(Structure): + _fields_ = [("part", (c_char * 128)), + ("colorlist", POINTER(c_uint)), + ("colorlistLength", c_uint)] + + def __init__(self): + self.part[0] = '\0' + self.colorlistLength = 0 + +ColorModifierPtr = POINTER(ColorModifier) + +def _alloc_empty_colormodifier_callback(ptr): + ptr = ColorModifierPtr(ColorModifier()) + + return 1 + +_empty_colormodifier_functype = CFUNCTYPE(c_int, ColorModifierPtr) +libdfhack.alloc_empty_colormodifier_callback = _empty_colormodifier_functype(_alloc_empty_colormodifier_callback) diff --git a/library/python/c api/util.py b/library/python/pydfhack/util.py similarity index 100% rename from library/python/c api/util.py rename to library/python/pydfhack/util.py diff --git a/library/python/pydfhack/vegetation.py b/library/python/pydfhack/vegetation.py index ce1262a13..0c22d26b5 100644 --- a/library/python/pydfhack/vegetation.py +++ b/library/python/pydfhack/vegetation.py @@ -1,18 +1,25 @@ -# -*- coding: utf-8 -*- -""" -Python class for DF_Hack::Vegetation -""" -from ._pydfhack import _VegetationManager -from .mixins import NeedsStart -from .decorators import suspend +from ctypes import * +from pydftypes import libdfhack, Tree -class Vegetation(NeedsStart, _VegetationManager): - api = None - cls = _VegetationManager - def __init__(self, api, *args, **kwds): - self.cls.__init__(self, args, kwds) - self.api = api +class Vegetation(object): + def __init__(self, ptr): + self._v_ptr = ptr + + def start(self): + n = c_uint(0) - @suspend - def Read(self, *args, **kw): - return self.cls.Read(self, *args, **kw) + if libdfhack.Vegetation_Start(self._v_ptr, byref(n)) > 0: + return int(n.value) + else: + return -1 + + def finish(self): + return libdfhack.Vegetation_Finish(self._v_ptr) > 0 + + def read(self, index): + t = Tree() + + if libdfhack.Vegetation_Read(self._v_ptr, c_uint(index), byref(t)) > 0: + return t + else: + return None From fa8238af0886063ad596cdcfa90825e739b47e98 Mon Sep 17 00:00:00 2001 From: doomchild Date: Thu, 17 Jun 2010 15:38:48 -0500 Subject: [PATCH 2/3] removed reveal and force_suspend to examples --- library/python/pydfhack/context.py | 37 +----------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/library/python/pydfhack/context.py b/library/python/pydfhack/context.py index eed236b09..0afc2cf25 100644 --- a/library/python/pydfhack/context.py +++ b/library/python/pydfhack/context.py @@ -167,39 +167,4 @@ class Context(object): if self._tran_obj is None: self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr)) - return self._tran_obj - -def reveal(): - df_cm = ContextManager("Memory.xml") - df = df_cm.get_single_context() - - df.attach() - - m = df.maps - - m.start() - - m_x, m_y, m_z = m.size - - for x in xrange(m_x): - for y in xrange(m_y): - for z in xrange(m_z): - if m.is_valid_block(x, y, z): - d = m.read_designations(x, y, z) - - for i in d: - for j in i: - j.bits.hidden = 0 - - m.write_designations(x, y, z, d) - - m.finish() - df.detach() - -def resume(): - df_cm = ContextManager("Memory.xml") - df = df_cm.get_single_context() - - df.attach() - df.force_resume() - df.detach() + return self._tran_obj \ No newline at end of file From 5b71ac7dae0c622a843a116cd58590dccf9d2d17 Mon Sep 17 00:00:00 2001 From: doomchild Date: Thu, 17 Jun 2010 16:26:53 -0500 Subject: [PATCH 3/3] add __init__ file renamed flags and types --- library/python/pydfhack/__init__.py | 14 ++++++++++++++ .../python/pydfhack/{pydftypes.py => dftypes.py} | 0 .../python/pydfhack/{pydfhackflags.py => flags.py} | 0 3 files changed, 14 insertions(+) create mode 100644 library/python/pydfhack/__init__.py rename library/python/pydfhack/{pydftypes.py => dftypes.py} (100%) rename library/python/pydfhack/{pydfhackflags.py => flags.py} (100%) diff --git a/library/python/pydfhack/__init__.py b/library/python/pydfhack/__init__.py new file mode 100644 index 000000000..99cf04305 --- /dev/null +++ b/library/python/pydfhack/__init__.py @@ -0,0 +1,14 @@ +import context + +__all__ = [ "buildings", + "constructions", + "context", + "creatures", + "dftypes", + "flags", + "gui", + "items", + "maps", + "materials", + "position" + "vegetation" ] \ No newline at end of file diff --git a/library/python/pydfhack/pydftypes.py b/library/python/pydfhack/dftypes.py similarity index 100% rename from library/python/pydfhack/pydftypes.py rename to library/python/pydfhack/dftypes.py diff --git a/library/python/pydfhack/pydfhackflags.py b/library/python/pydfhack/flags.py similarity index 100% rename from library/python/pydfhack/pydfhackflags.py rename to library/python/pydfhack/flags.py