moved the old Python/C stuff to python/deprecated
renamed "c api" to "pydfhack"develop
parent
b732e63673
commit
d58260740f
@ -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
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
@ -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
|
@ -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)]
|
@ -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)
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue