Merge branch 'master' of git://github.com/peterix/dfhack

develop
Simon Jackson 2010-06-18 01:18:00 +01:00
commit 0735c8b84a
71 changed files with 544 additions and 516 deletions

@ -712,7 +712,7 @@ string memory_info::getTraitName(const uint32_t traitIdx) const
throw Error::MissingMemoryDefinition("traitname", traitIdx); throw Error::MissingMemoryDefinition("traitname", traitIdx);
} }
std::vector< std::vector<std::string>> const& memory_info::getAllTraits() std::vector< std::vector<std::string> > const& memory_info::getAllTraits()
{ {
return d->traits; return d->traits;
} }

@ -74,7 +74,7 @@ namespace DFHack
std::string getTrait (const uint32_t, const uint32_t) const; std::string getTrait (const uint32_t, const uint32_t) const;
std::string getTraitName(const uint32_t) const; std::string getTraitName(const uint32_t) const;
std::string getLabor (const uint32_t); std::string getLabor (const uint32_t);
std::vector< std::vector<std::string>> const& getAllTraits(); std::vector< std::vector<std::string> > const& getAllTraits();
DFHack::t_level getLevelInfo(const uint32_t level) const; DFHack::t_level getLevelInfo(const uint32_t level) const;

@ -92,19 +92,19 @@ Creatures::Creatures(DFContextShared* _d)
creatures.mood_offset = minfo->getOffset("creature_mood"); creatures.mood_offset = minfo->getOffset("creature_mood");
creatures.mood_skill_offset = minfo->getOffset("creature_mood_skill"); creatures.mood_skill_offset = minfo->getOffset("creature_mood_skill");
creatures.pickup_equipment_bit = minfo->getOffset("creature_pickup_equipment_bit"); creatures.pickup_equipment_bit = minfo->getOffset("creature_pickup_equipment_bit");
creatures.current_job_offset = minfo->getOffset("creature_current_job"); creatures.current_job_offset = minfo->getOffset("creature_current_job");
// soul offsets // soul offsets
creatures.soul_skills_vector_offset = minfo->getOffset("soul_skills_vector"); creatures.soul_skills_vector_offset = minfo->getOffset("soul_skills_vector");
creatures.soul_mental_offset = minfo->getOffset("soul_mental"); creatures.soul_mental_offset = minfo->getOffset("soul_mental");
creatures.soul_traits_offset = minfo->getOffset("soul_traits"); creatures.soul_traits_offset = minfo->getOffset("soul_traits");
// appearance // appearance
creatures.appearance_vector_offset = minfo->getOffset("creature_appearance_vector"); creatures.appearance_vector_offset = minfo->getOffset("creature_appearance_vector");
//birth //birth
creatures.birth_year_offset = minfo->getOffset("creature_birth_year"); creatures.birth_year_offset = minfo->getOffset("creature_birth_year");
creatures.birth_time_offset = minfo->getOffset("creature_birth_time"); creatures.birth_time_offset = minfo->getOffset("creature_birth_time");
// name offsets for the creature module // name offsets for the creature module
creatures.name_firstname_offset = minfo->getOffset("name_firstname"); creatures.name_firstname_offset = minfo->getOffset("name_firstname");
creatures.name_nickname_offset = minfo->getOffset("name_nickname"); creatures.name_nickname_offset = minfo->getOffset("name_nickname");
@ -172,17 +172,17 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
*/ */
// non-SHM slow path // non-SHM slow path
memory_info * minfo = d->d->offset_descriptor; memory_info * minfo = d->d->offset_descriptor;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
furball.origin = temp; furball.origin = temp;
Creatures2010::creature_offsets &offs = d->creatures; Creatures2010::creature_offsets &offs = d->creatures;
//read creature from memory //read creature from memory
// name // name
d->d->readName(furball.name,temp + offs.name_offset); d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff // basic stuff
p->readDWord (temp + offs.happiness_offset, furball.happiness); p->readDWord (temp + offs.happiness_offset, furball.happiness);
p->readDWord (temp + offs.id_offset, furball.id); p->readDWord (temp + offs.id_offset, furball.id);
@ -193,24 +193,24 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
p->readWord (temp + offs.caste_offset, furball.caste); p->readWord (temp + offs.caste_offset, furball.caste);
p->readDWord (temp + offs.flags1_offset, furball.flags1.whole); p->readDWord (temp + offs.flags1_offset, furball.flags1.whole);
p->readDWord (temp + offs.flags2_offset, furball.flags2.whole); p->readDWord (temp + offs.flags2_offset, furball.flags2.whole);
// physical attributes // physical attributes
p->read(temp + offs.physical_offset, p->read(temp + offs.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES, sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&furball.strength); (uint8_t *)&furball.strength);
// mood stuff // mood stuff
furball.mood = (int16_t) p->readWord (temp + offs.mood_offset); furball.mood = (int16_t) p->readWord (temp + offs.mood_offset);
furball.mood_skill = p->readWord (temp + offs.mood_skill_offset); furball.mood_skill = p->readWord (temp + offs.mood_skill_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset); d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset);
// custom profession // custom profession
p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession)); p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession));
//fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset)); //fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset));
// labors // labors
p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors); p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
// profession // profession
furball.profession = p->readByte (temp + offs.profession_offset); furball.profession = p->readByte (temp + offs.profession_offset);
@ -268,20 +268,20 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
// a byte: this gives us 256 skills maximum. // a byte: this gives us 256 skills maximum.
furball.defaultSoul.skills[i].id = p->readByte (temp2); furball.defaultSoul.skills[i].id = p->readByte (temp2);
furball.defaultSoul.skills[i].rating = furball.defaultSoul.skills[i].rating =
p->readByte (temp2 + offsetof(t_skill, rating)); p->readByte (temp2 + offsetof(t_skill, rating));
furball.defaultSoul.skills[i].experience = furball.defaultSoul.skills[i].experience =
p->readWord (temp2 + offsetof(t_skill, experience)); p->readWord (temp2 + offsetof(t_skill, experience));
} }
// mental attributes are part of the soul // mental attributes are part of the soul
p->read(soul + offs.soul_mental_offset, p->read(soul + offs.soul_mental_offset,
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES, sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&furball.defaultSoul.analytical_ability); (uint8_t *)&furball.defaultSoul.analytical_ability);
// traits as well // traits as well
p->read(soul + offs.soul_traits_offset, p->read(soul + offs.soul_traits_offset,
sizeof (uint16_t) * NUM_CREATURE_TRAITS, sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &furball.defaultSoul.traits); (uint8_t *) &furball.defaultSoul.traits);
} }
DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset); DfVector <uint32_t> app(p, temp + offs.appearance_vector_offset);
@ -312,7 +312,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
{ {
if (!d->Started) if (!d->Started)
return -1; return -1;
Process *p = d->owner; Process *p = d->owner;
/* /*
if(d->creature_module) if(d->creature_module)
@ -359,130 +359,151 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]) bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS])
{ {
if(!d->Started) return false; if(!d->Started)
uint32_t temp = d->p_cre->at (index); {
Process * p = d->owner; return false;
}
p->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors); uint32_t temp = d->p_cre->at (index);
uint32_t pickup_equip; Process * p = d->owner;
p->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
pickup_equip |= 1u; p->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors);
p->writeDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip); uint32_t pickup_equip;
return true; p->readDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
pickup_equip |= 1u;
p->writeDWord(temp + d->creatures.pickup_equipment_bit, pickup_equip);
return true;
} }
bool Creatures::WriteHappiness(const uint32_t index, const uint32_t happinessValue) bool Creatures::WriteHappiness(const uint32_t index, const uint32_t happinessValue)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
uint32_t temp = d->p_cre->at (index); }
Process * p = d->owner; uint32_t temp = d->p_cre->at (index);
p->writeDWord (temp + d->creatures.happiness_offset, happinessValue); Process * p = d->owner;
return true; p->writeDWord (temp + d->creatures.happiness_offset, happinessValue);
return true;
} }
bool Creatures::WriteFlags(const uint32_t index, bool Creatures::WriteFlags(const uint32_t index,
const uint32_t flags1, const uint32_t flags1,
const uint32_t flags2) const uint32_t flags2)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
uint32_t temp = d->p_cre->at (index); }
Process * p = d->owner; uint32_t temp = d->p_cre->at (index);
p->writeDWord (temp + d->creatures.flags1_offset, flags1); Process * p = d->owner;
p->writeDWord (temp + d->creatures.flags2_offset, flags1); p->writeDWord (temp + d->creatures.flags1_offset, flags1);
return true; p->writeDWord (temp + d->creatures.flags2_offset, flags1);
return true;
} }
bool Creatures::WriteSkills(const uint32_t index, const t_soul &soul) bool Creatures::WriteSkills(const uint32_t index, const t_soul &soul)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
uint32_t temp = d->p_cre->at (index); }
Process * p = d->owner;
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset); uint32_t temp = d->p_cre->at (index);
Process * p = d->owner;
if(!souloff) uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
return false;
if(!souloff)
{
return false;
}
DfVector<uint32_t> skills(p, souloff + d->creatures.soul_skills_vector_offset); DfVector<uint32_t> skills(p, souloff + d->creatures.soul_skills_vector_offset);
for (uint32_t i=0; i<soul.numSkills; i++) for (uint32_t i=0; i<soul.numSkills; i++)
{ {
uint32_t temp2 = skills[i]; uint32_t temp2 = skills[i];
p->writeByte(temp2 + offsetof(t_skill, rating), soul.skills[i].rating); p->writeByte(temp2 + offsetof(t_skill, rating), soul.skills[i].rating);
p->writeWord(temp2 + offsetof(t_skill, experience), soul.skills[i].experience); p->writeWord(temp2 + offsetof(t_skill, experience), soul.skills[i].experience);
} }
return true; return true;
} }
bool Creatures::WriteAttributes(const uint32_t index, const t_creature &creature) bool Creatures::WriteAttributes(const uint32_t index, const t_creature &creature)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
}
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
Process * p = d->owner; Process * p = d->owner;
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset); uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
if(!souloff) if(!souloff)
return false; {
return false;
}
// physical attributes // physical attributes
p->write(temp + d->creatures.physical_offset, p->write(temp + d->creatures.physical_offset,
sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES, sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES,
(uint8_t *)&creature.strength); (uint8_t *)&creature.strength);
// mental attributes are part of the soul // mental attributes are part of the soul
p->write(souloff + d->creatures.soul_mental_offset, p->write(souloff + d->creatures.soul_mental_offset,
sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES, sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES,
(uint8_t *)&creature.defaultSoul.analytical_ability); (uint8_t *)&creature.defaultSoul.analytical_ability);
return true; return true;
} }
bool Creatures::WriteSex(const uint32_t index, const uint8_t sex) bool Creatures::WriteSex(const uint32_t index, const uint8_t sex)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
}
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
Process * p = d->owner; Process * p = d->owner;
p->writeByte (temp + d->creatures.sex_offset, sex); p->writeByte (temp + d->creatures.sex_offset, sex);
} }
bool Creatures::WriteTraits(const uint32_t index, const t_soul &soul) bool Creatures::WriteTraits(const uint32_t index, const t_soul &soul)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
}
uint32_t temp = d->p_cre->at (index);
Process * p = d->owner;
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset);
uint32_t temp = d->p_cre->at (index); if(!souloff)
Process * p = d->owner; {
uint32_t souloff = p->readDWord(temp + d->creatures.default_soul_offset); return false;
}
if(!souloff) p->write(souloff + d->creatures.soul_traits_offset,
return false; sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &soul.traits);
p->write(souloff + d->creatures.soul_traits_offset, return true;
sizeof (uint16_t) * NUM_CREATURE_TRAITS,
(uint8_t *) &soul.traits);
return true;
} }
bool Creatures::WriteMood(const uint32_t index, const uint16_t mood) bool Creatures::WriteMood(const uint32_t index, const uint16_t mood)
{ {
if(!d->Started) if(!d->Started)
return false; {
return false;
}
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
Process * p = d->owner; Process * p = d->owner;
p->writeWord(temp + d->creatures.mood_offset, mood); p->writeWord(temp + d->creatures.mood_offset, mood);
return true; return true;
} }
uint32_t Creatures::GetDwarfRaceIndex() uint32_t Creatures::GetDwarfRaceIndex()

@ -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,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,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 +1,14 @@
from .pydfapi import API import context
__all__ = [ "buildings",
"constructions",
"context",
"creatures",
"dftypes",
"flags",
"gui",
"items",
"maps",
"materials",
"position"
"vegetation" ]

@ -167,39 +167,4 @@ class Context(object):
if self._tran_obj is None: if self._tran_obj is None:
self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr)) self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr))
return self._tran_obj return self._tran_obj
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()

@ -1,25 +1,25 @@
# -*- coding: utf-8 -*- from ctypes import *
""" from pydfhack import libdfhack, ViewScreen
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): libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ]
"""
Enforce Suspend/Start class Gui(object):
""" def __init__(self, ptr):
if self.api.prepare(): self._gui_ptr = ptr
if not self.started:
self.started = self.Start() def start(self):
return self.started return libdfhack.Gui_Start(self._gui_ptr)
else:
return False 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 -*- from ctypes import *
""" from pydftypes import libdfhack
Python class for DF_Hack::Materials from util import *
"""
from ._pydfhack import _MaterialsManager _get_arg_types = [ c_void_p, _arr_create_func ]
from .mixins import NoStart
from .decorators import suspend libdfhack.Materials_getInorganic.argtypes = _get_arg_types
libdfhack.Materials_getOrganic.argtypes = _get_arg_types
class Materials(NoStart, _MaterialsManager): libdfhack.Materials_getTree.argtypes = _get_arg_types
api = None libdfhack.Materials_getPlant.argtypes = _get_arg_types
cls = _MaterialsManager libdfhack.Materials_getRace.argtypes = _get_arg_types
def __init__(self, api, *args, **kwds): #libdfhack.Materials_getRaceEx.argtypes = _get_arg_types
cls.__init__(self, args, kwds) libdfhack.Materials_getColor.argtypes = _get_arg_types
self.api = api libdfhack.Materials_getOther.argtypes = _get_arg_types
@suspend class Materials(object):
def Read_Wood_Materials(self, *args, **kw): def __init__(self, ptr):
return self.cls.Read_Wood_Materials(self, *args, **kw) self._mat_ptr = ptr
@suspend self.inorganic = None
def Read_Plant_Materials(self, *args, **kw): self.organic = None
return self.cls.Read_Plant_Materials(self, *args, **kw) self.tree = None
self.plant = None
@suspend self.race = None
def Read_Inorganic_Materials(self, *args, **kw): self.race_ex = None
return self.cls.Read_Inorganic_Materials(self, *args, **kw) self.color = None
self.other = None
@suspend
def Read_Descriptor_Colors(self, *args, **kw): def read_inorganic(self):
return self.cls.Read_Descriptor_Colors(self, *args, **kw) return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr)
@suspend def read_organic(self):
def Read_Creature_Types(self, *args, **kw): return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr)
return self.cls.Read_Creature_Types(self, *args, **kw)
def read_wood(self):
@suspend return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr)
def Read_Organic_Materials(self, *args, **kw):
return self.cls.Read_Organic_Materials(self, *args, **kw) def read_plant(self):
return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr)
@suspend
def Read_Creature_Types_Ex(self, *args, **kw): def read_creature_types(self):
return self.cls.Read_Creature_Types_Ex(self, *args, **kw) 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 -*- from ctypes import *
""" from pydftypes import libdfhack
Python class for DF_Hack::Position
""" class Position(object):
from ._pydfhack import _PositionManager def __init__(self, ptr):
from .blocks import Point, Block self._pos_ptr = ptr
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 self._vx, self._vy, self._vz = c_int(), c_int(), c_int()
def get_window_size(self): self._cx, self._cy, self._cz = c_int(), c_int(), c_int()
wsize = self.window_size self._ww, self._wh = c_int(), c_int()
return wsize
@suspend
def get_view_coords(self): def get_view_coords(self):
coords = self.view_coords if libdfhack.Position_getViewCoords(self._pos_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0:
return Point(*coords) return (self._vx.value, self._vy.value, self._vz.value)
else:
@suspend return (-1, -1, -1)
def get_cursor_tile(self):
point = self.get_cursor() def set_view_coords(self, v_coords):
if point: self._vx.value, self._vy.value, self._vz.value = v_coords
tile = self.api.maps.get_tile(point=point)
return tile 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: else:
return None return (-1, -1)

@ -1,18 +1,25 @@
# -*- coding: utf-8 -*- from ctypes import *
""" from pydftypes import libdfhack, Tree
Python class for DF_Hack::Vegetation
"""
from ._pydfhack import _VegetationManager
from .mixins import NeedsStart
from .decorators import suspend
class Vegetation(NeedsStart, _VegetationManager): class Vegetation(object):
api = None def __init__(self, ptr):
cls = _VegetationManager self._v_ptr = ptr
def __init__(self, api, *args, **kwds):
self.cls.__init__(self, args, kwds) def start(self):
self.api = api n = c_uint(0)
@suspend if libdfhack.Vegetation_Start(self._v_ptr, byref(n)) > 0:
def Read(self, *args, **kw): return int(n.value)
return self.cls.Read(self, *args, **kw) 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

@ -36,40 +36,68 @@ class holder
class address class address
{ {
public: public:
uint64_t addr_; uint64_t addr_;
unsigned int valid : 1; unsigned int valid : 1;
virtual void print(SegmentedFinder& sff) virtual void print(SegmentedFinder& sff)
{ {
cout << hex << "0x" << addr_ << endl; cout << hex << "0x" << addr_ << endl;
}; };
address(const uint64_t addr) address(const uint64_t addr)
{ {
addr_ = addr; addr_ = addr;
valid = false; valid = false;
} }
address & operator=(const uint64_t in) virtual address & operator=(const uint64_t in)
{ {
addr_ = in; addr_ = in;
valid = false; valid = false;
return *this; return *this;
} }
bool isValid(SegmentedFinder& sff) virtual bool isValid(SegmentedFinder& sff)
{
if(valid) return true;
if(sff.getSegmentForAddress(addr_))
{ {
if(valid) return true; valid = 1;
if(sff.getSegmentForAddress(addr_))
{
valid = 1;
}
} }
}
virtual bool equals (SegmentedFinder & sf, address & rhs)
{
return rhs.addr_ == addr_;
}
}; };
// pointer to a null-terminated byte string
class Cstr: public address class Cstr: public address
{ {
void print(SegmentedFinder & sf) void print(SegmentedFinder & sf)
{ {
cout << hex << "0x" << addr_ << ": \"" << sf.Translate<char>(addr_) << "\"" << endl; cout << hex << "0x" << addr_ << ": \"" << sf.Translate<char>(addr_) << "\"" << endl;
} }
bool equals(SegmentedFinder & sf,const char * rhs)
{
uint32_t addr2 = *(sf.Translate<uint32_t>(addr_));
return strcmp(sf.Translate<const char>(addr2), rhs) == 0;
}
template <class Predicate, class inType>
bool equalsP(SegmentedFinder & sf,inType rhs)
{
return Predicate(addr_, sf, rhs);
}
bool isValid(SegmentedFinder& sf)
{
if (address::isValid(sf))
{
// read the pointer
uint32_t addr2 = *(sf.Translate<uint32_t>(addr_));
// is it a real pointer? a pretty weak test, but whatever.
if(sf.getSegmentForAddress(addr2))
return true;
}
return false;
}
}; };
// STL STRING // STL STRING
#ifdef LINUX_BUILD #ifdef LINUX_BUILD
class STLstr: public address class STLstr: public address