develop
Petr Mrázek 2011-03-31 13:39:43 +02:00
commit 1e893295ce
5 changed files with 103 additions and 16 deletions

@ -76,6 +76,18 @@ class Context(object):
return libdfhack.Context_Attach(self._c_ptr) > 0
def detach(self):
self._mat_obj = None
self._map_obj = None
self._veg_obj = None
self._build_obj = None
self._con_obj = None
self._gui_obj = None
self._tran_obj = None
self._item_obj = None
self._creature_obj = None
self._world_obj = None
self._window_io_obj = None
return libdfhack.Context_Detach(self._c_ptr) > 0
def suspend(self):

@ -21,7 +21,8 @@ class DesignationStruct(Structure):
("liquid_static", c_uint, 1),
("feature_local", c_uint, 1),
("feature_global", c_uint, 1),
("liquid_character", c_uint, 2)]
("water_stagnant", c_uint, 1),
("water_salt", c_uint, 1)]
class DesignationFlags(Union):
_fields_ = [("whole", c_uint, 32),

@ -1,12 +1,12 @@
from ctypes import *
from dftypes import *
from util import _uintify, uint_ptr, check_pointer_cache
from util import _uintify, int_ptr, uint_ptr, check_pointer_cache
_MAX_DIM = 0x300
_MAX_DIM_SQR = _MAX_DIM * _MAX_DIM
libdfhack.Maps_getSize.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_getPosition.argtypes = [ c_void_p, uint_ptr, uint_ptr, uint_ptr ]
libdfhack.Maps_getPosition.argtypes = [ c_void_p, int_ptr, int_ptr, int_ptr ]
libdfhack.Maps_ReadTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
libdfhack.Maps_WriteTileTypes.argtypes = [ c_void_p, c_uint, c_uint, c_uint, POINTER(TileTypes40d) ]
@ -67,7 +67,7 @@ class Maps(object):
ux, uy, uz = _uintify(x, y, z)
if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, d) > 0:
if libdfhack.Maps_ReadDesignations(self._map_ptr, ux, uy, uz, byref(d)) > 0:
return d
else:
return None
@ -75,7 +75,7 @@ class Maps(object):
def write_designations(self, x, y, z, d):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, d) > 0
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, byref(d)) > 0
def read_temperatures(self, x, y, z):
t = Temperatures()
@ -102,10 +102,10 @@ class Maps(object):
else:
return None
def write_designations(self, x, y, z, o):
def write_occupancy(self, x, y, z, o):
ux, uy, uz = _uintify(x, y, z)
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, o) > 0
return libdfhack.Maps_WriteDesignations(self._map_ptr, ux, uy, uz, byref(o)) > 0
def read_dirty_bit(self, x, y, z):
bit = c_int(0)
@ -216,19 +216,19 @@ class Maps(object):
@property
def size(self):
x, y, z = (0, 0, 0)
x, y, z = (c_uint(0), c_uint(0), c_uint(0))
retval = libdfhack.Maps_getSize(self._map_ptr, byref(x), byref(y), byref(z))
return (x, y, z)
return (int(x.value), int(y.value), int(z.value))
@property
def position(self):
x, y, z = (0, 0, 0)
x, y, z = (c_int(0), c_int(0), c_int(0))
libdfhack.Maps_getPosition(self._map_ptr, byref(x), byref(y), byref(z))
return (x, y, z)
return (int(x.value), int(y.value), int(z.value))
class MapPoint(object):
__slots__ = ["_x", "_y", "_z", "_cmp_val"]

@ -1,5 +1,5 @@
from ctypes import *
from dftypes import GameModes
from dftypes import libdfhack, GameModes
from util import _uintify, uint_ptr
libdfhack.World_ReadGameMode.argtypes = [ c_void_p, POINTER(GameModes) ]
@ -17,6 +17,14 @@ class World(object):
def read_pause_state(self):
return libdfhack.World_ReadPauseState(self._world_ptr) > 0
def set_pause_state(self, pause_state):
p = c_byte(0)
if pause_state is not None and pause_state is not False:
p.value = 1
return libdfhack.World_SetPauseState(self._world_ptr, p) > 0
def read_current_tick(self):
tick = c_uint(0)

@ -1,27 +1,93 @@
from pydfhack import ContextManager, Maps
import time
from context import ContextManager
class HideBlock(object):
__slots__ = [ "x", "y", "z", "hiddens" ]
def __init__(self, *args, **kwargs):
self.x = 0
self.y = 0
self.z = 0
self.hiddens = [[0 for i in xrange(16)] for j in xrange(16)]
df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
df.attach()
m = df.maps()
m = df.maps
w = df.world
print "Pausing..."
w.start()
#this mimics the hack in the C++ reveal tool that attempts to ensure that DF isn't in the middle of
#a frame update
w.set_pause_state(True)
df.resume()
time.sleep(1)
df.suspend()
w.finish()
m.start()
print "Revealing, please wait..."
m_x, m_y, m_z = m.size
hide_blocks = []
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):
hb = HideBlock()
hb.x = x
hb.y = y
hb.z = z
d = m.read_designations(x, y, z)
for i in d:
for j in i:
for k_i, i in enumerate(d):
for k_j, j in enumerate(i):
hb.hiddens[k_i][k_j] = j.bits.hidden
j.bits.hidden = 0
hide_blocks.append(hb)
m.write_designations(x, y, z, d)
m.finish()
df.detach()
print "Map revealed. The game has been paused for you."
print "Unpausing can unleash the forces of hell!"
print "Press any key to unreveal."
print "Close to keep the map revealed !!FOREVER!!"
raw_input()
print "Unrevealing...please wait"
df.attach()
m = df.maps
m.start()
for h in hide_blocks:
d = m.read_designations(h.x, h.y, h.z)
for k_i, i in enumerate(h.hiddens):
for k_j, j in enumerate(i):
d[k_i][k_j].bits.hidden = j
m.write_designations(h.x, h.y, h.z, d)
m.finish()
print "Done. Press any key to continue"
raw_input()
df.detach()