first commit

develop
doomchild 2011-03-15 15:33:39 -05:00
parent fda4ad94cd
commit d28279894f
5 changed files with 176 additions and 0 deletions

@ -0,0 +1,53 @@
import time
from pydfhack import ContextManager
df_cm = ContextManager("Memory.xml")
df = None
def test_attach():
global df
if not df:
df = df_cm.get_single_context()
if not df.attach():
print "Unable to attach!"
return False
elif not df.detach():
print "Unabled to detach!"
return False
else:
return True
def suspend_test():
global df
if not df:
df = df_cm.get_single_context()
print "Testing suspend/resume"
df.attach()
t1 = time.time()
for i in xrange(1000):
df.suspend()
if i % 10 == 0:
print "%i%%" % (i / 10.0,)
df.resume()
t2 = time.time()
df.detach()
print "suspend test done in $0.9f seconds" % (t2 - t1)
if __name__ == "__main__":
if test_attach():
suspend_test()
print "Done. Press any key to continue"
raw_input()

@ -0,0 +1,20 @@
from context import Context, ContextManager
cm = ContextManager("Memory.xml")
df = cm.get_single_context()
df.attach()
pos = df.position
print "Hotkeys"
hotkeys = pos.read_hotkeys()
for key in hotkeys:
print "x: %d\ny: %d\tz: %d\ttext: %s" % (key.x, key.y, key.z, key.name)
df.detach()
print "Done. Press any key to continue"
raw_input()

@ -0,0 +1,24 @@
import sys
from pydfhack import ContextManager
df_cm = ContextManager("Memory.xml")
df = df_cm.get_single_context()
if not df.attach():
print "Unable to attach!"
print "Press any key to continue"
raw_input()
sys.exit(1)
pos = df.position
print "view coords: %s" % (pos.view_coords,)
print "cursor coords: %s" % (pos.cursor_coords,)
print "window size: %s" % (pos.window_size,)
if not df.detach():
print "Unable to detach!"
print "Done. Press any key to continue"
raw_input()

@ -0,0 +1,27 @@
from pydfhack import ContextManager, Maps
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()

@ -0,0 +1,52 @@
from context import Context, ContextManager
cm = ContextManager("Memory.xml")
df = cm.get_single_context()
df.attach()
pos = df.position
veg = df.vegetation
mps = df.maps
mat = df.materials
x, y, z = pos.get_cursor_coords()
num_veg = veg.start()
if x == -30000:
print "----==== Trees ====----"
for i in xrange(num_veg):
t = veg.read(i)
print "%d/%d/%d, %d:%d" % (t.x, t.y, t.z, t.type, t.material)
else:
#new method, gets the list of trees in a block. can show farm plants
if mps.start():
pos_tuple = (x, y, z)
trees = mps.read_vegetation(x / 16, y / 16, z)
if trees is not None:
for t in trees:
if (t.x, t.y, t.z) == pos_tuple:
print "----==== Tree at %d/%d/%d ====----" % pos_tuple
print str(t)
break
mps.finish()
#old method, get the tree from the global vegetation vector. can't show farm plants
for i in xrange(num_veg):
t = veg.read(i)
if (t.x, t.y, t.z) == pos_tuple:
print "----==== Tree at %d/%d/%d ====----" % pos_tuple
print str(t)
break
veg.finish()
df.detach()
print "Done. Press any key to continue"
raw_input()