Merge branch 'master' of http://github.com/doomchild/dfhack
commit
d03cb827f3
@ -0,0 +1,43 @@
|
|||||||
|
import time
|
||||||
|
import math
|
||||||
|
import pydfapi
|
||||||
|
|
||||||
|
df = pydfapi.API("Memory.xml")
|
||||||
|
|
||||||
|
def test_attach():
|
||||||
|
if not df.Attach():
|
||||||
|
print "Unable to attach!"
|
||||||
|
return False
|
||||||
|
elif not df.Detach():
|
||||||
|
print "Unable to detach!"
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def suspend_test():
|
||||||
|
print "Testing suspend/resume"
|
||||||
|
|
||||||
|
df.Attach()
|
||||||
|
|
||||||
|
t1 = time.time()
|
||||||
|
|
||||||
|
for i in xrange(1000):
|
||||||
|
df.Suspend()
|
||||||
|
|
||||||
|
if i % 10 == 0:
|
||||||
|
print "%i%%" % (i / 10,)
|
||||||
|
|
||||||
|
df.Resume()
|
||||||
|
|
||||||
|
t2 = time.time()
|
||||||
|
|
||||||
|
df.Detach()
|
||||||
|
|
||||||
|
print "suspend tests 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,36 @@
|
|||||||
|
_splatter_dict = { 0 : "Rock",
|
||||||
|
1 : "Amber",
|
||||||
|
2 : "Coral",
|
||||||
|
3 : "Green Glass",
|
||||||
|
4 : "Clear Glass",
|
||||||
|
5 : "Crystal Glass",
|
||||||
|
6 : "Ice",
|
||||||
|
7 : "Coal",
|
||||||
|
8 : "Potash",
|
||||||
|
9 : "Ash",
|
||||||
|
10 : "Pearlash",
|
||||||
|
11 : "Lye",
|
||||||
|
12 : "Mud",
|
||||||
|
13 : "Vomit",
|
||||||
|
14 : "Salt",
|
||||||
|
15 : "Filth",
|
||||||
|
16 : "Frozen? Filth",
|
||||||
|
18 : "Grime",
|
||||||
|
0xF2 : "Very Specific Blood (references a named creature)" }
|
||||||
|
|
||||||
|
def get_splatter_type(mat1, mat2, creature_types):
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
if mat1 in _splatter_dict:
|
||||||
|
return _splatter_dict[mat1]
|
||||||
|
elif mat1 == 0x2A or mat1 == 0x2B:
|
||||||
|
splatter = StringIO()
|
||||||
|
|
||||||
|
if mat2 != -1:
|
||||||
|
splatter.write(creature_types[mat2]["id"] + " ")
|
||||||
|
|
||||||
|
splatter.write("Blood")
|
||||||
|
|
||||||
|
return splatter.getvalue()
|
||||||
|
else:
|
||||||
|
return "Unknown"
|
@ -0,0 +1,22 @@
|
|||||||
|
import sys
|
||||||
|
import pydfapi
|
||||||
|
|
||||||
|
df = pydfapi.API("Memory.xml")
|
||||||
|
|
||||||
|
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,8 @@
|
|||||||
|
import sys
|
||||||
|
from cStringIO import StringIO
|
||||||
|
import pydfapi
|
||||||
|
|
||||||
|
df = pydfapi.API("Memory.xml")
|
||||||
|
|
||||||
|
def print_settlement(settlement, english_words, foreign_words):
|
||||||
|
s = StringIO()
|
@ -0,0 +1,38 @@
|
|||||||
|
import pydfapi
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
df = pydfapi.API("Memory.xml")
|
||||||
|
|
||||||
|
if not df.Attach():
|
||||||
|
print "Unable to attach!"
|
||||||
|
return False
|
||||||
|
|
||||||
|
print "Attached, DF should be suspended now"
|
||||||
|
raw_input()
|
||||||
|
|
||||||
|
df.Resume()
|
||||||
|
|
||||||
|
print "Resumed, DF should be running"
|
||||||
|
raw_input()
|
||||||
|
|
||||||
|
df.Suspend()
|
||||||
|
|
||||||
|
print "Suspended, DF should be suspended now"
|
||||||
|
raw_input()
|
||||||
|
|
||||||
|
df.Resume()
|
||||||
|
|
||||||
|
print "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer"
|
||||||
|
raw_input()
|
||||||
|
|
||||||
|
df.Force_Resume()
|
||||||
|
|
||||||
|
print "ForceResumed. DF should be running."
|
||||||
|
raw_input()
|
||||||
|
|
||||||
|
if not df.Detach():
|
||||||
|
print "Can't detach from DF"
|
||||||
|
return False
|
||||||
|
|
||||||
|
print "Detached, DF should be running again"
|
||||||
|
raw_input()
|
@ -0,0 +1,66 @@
|
|||||||
|
import sys
|
||||||
|
from cStringIO import StringIO
|
||||||
|
import pydfapi
|
||||||
|
|
||||||
|
df = pydfapi.API("Memory.xml")
|
||||||
|
|
||||||
|
if not df.Attach():
|
||||||
|
print "Unable to attach!\nPress any key to continue"
|
||||||
|
raw_input()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
pos = df.position
|
||||||
|
veg = df.vegetation
|
||||||
|
mat = df.materials
|
||||||
|
|
||||||
|
organics = mat.Read_Organic_Materials()
|
||||||
|
|
||||||
|
x, y, z = pos.cursor_coords
|
||||||
|
|
||||||
|
num_vegs = veg.Start()
|
||||||
|
|
||||||
|
if x == -30000:
|
||||||
|
print "----==== Trees ====----"
|
||||||
|
|
||||||
|
for i in xrange(num_vegs):
|
||||||
|
tree = veg.Read(i)
|
||||||
|
|
||||||
|
t_x, t_y, t_z = tree["position"]
|
||||||
|
|
||||||
|
print "%f/%f/%f, %f:%f" % (t_x, t_y, t_z, tree["type"], tree["material"])
|
||||||
|
else:
|
||||||
|
print "----==== Tree at %i/%i/%i" % (x, y, z)
|
||||||
|
|
||||||
|
for i in xrange(num_vegs):
|
||||||
|
tree = veg.Read(i)
|
||||||
|
|
||||||
|
t_x, t_y, t_z = tree["position"]
|
||||||
|
t_type = tree["address"]
|
||||||
|
|
||||||
|
if t_x == x and t_y == y and t_z == z:
|
||||||
|
s = StringIO()
|
||||||
|
|
||||||
|
s.write("%f:%f = " % (tree["type"], tree["material"]))
|
||||||
|
|
||||||
|
if t_type in (1, 3):
|
||||||
|
s.write("near-water ")
|
||||||
|
|
||||||
|
s.write("%i " % (organics[tree["material"]]["id"]),)
|
||||||
|
|
||||||
|
if t_type in (0, 1):
|
||||||
|
s.write("tree\n")
|
||||||
|
elif t_type in (2, 3):
|
||||||
|
s.write("shrub\n")
|
||||||
|
|
||||||
|
print s.getvalue()
|
||||||
|
print "Address: 0x%x" % (tree["address"],)
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
veg.Finish()
|
||||||
|
|
||||||
|
if not df.Detach():
|
||||||
|
print "Unable to detach!"
|
||||||
|
|
||||||
|
print "Done. Press any key to continue"
|
||||||
|
raw_input()
|
@ -0,0 +1,21 @@
|
|||||||
|
from pydfhack import *
|
||||||
|
|
||||||
|
class API(_API):
|
||||||
|
def __init__(self, *args, **kwds):
|
||||||
|
_API.__init__(self, args, kwds)
|
||||||
|
|
||||||
|
self._map_mgr_type = Map
|
||||||
|
self._vegetation_mgr_type = Vegetation
|
||||||
|
self._gui_mgr_type = GUI
|
||||||
|
|
||||||
|
class Map(_MapManager):
|
||||||
|
def __init__(self, *args, **kwds):
|
||||||
|
_MapManager.__init__(self, args, kwds)
|
||||||
|
|
||||||
|
class Vegetation(_VegetationManager):
|
||||||
|
def __init__(self, *args, **kwds):
|
||||||
|
_VegetationManager.__init__(self, args, kwds)
|
||||||
|
|
||||||
|
class GUI(_GUIManager):
|
||||||
|
def __init__(self, *args, **kwds):
|
||||||
|
_GUIManager.__init__(self, args, kwds)
|
@ -1,16 +1,31 @@
|
|||||||
from collections import namedtuple
|
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")
|
Note = namedtuple("Note", "symbol, foreground, background, name, position")
|
||||||
Construction = namedtuple("Construction", "position, form, unk_8, mat_type, mat_idx, unk3, unk4, unk5, unk6, origin")
|
Construction = namedtuple("Construction", "position, form, unk_8, mat_type, mat_idx, unk3, unk4, unk5, unk6, origin")
|
||||||
Vein = namedtuple("Vein", "vtable, type, flags, address, assignment")
|
Vein = namedtuple("Vein", "vtable, type, flags, address, assignment")
|
||||||
FrozenLiquidVein = namedtuple("FrozenLiquidVein", "vtable, address, tiles")
|
FrozenLiquidVein = namedtuple("FrozenLiquidVein", "vtable, address, tiles")
|
||||||
SpatterVein = namedtuple("SpatterVein", "vtable, address, mat1, unk1, mat2, mat3, intensity")
|
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")
|
||||||
|
Matgloss = namedtuple("Matgloss", "id, fore, back, bright, name")
|
||||||
|
DescriptorColor = namedtuple("DescriptorColor", "id, r, v, b, name")
|
||||||
|
CreatureTypeEx = namedtuple("CreatureTypeEx", "rawname, castes, tile_character, tilecolor")
|
||||||
|
TileColor = namedtuple("TileColor", "fore, back, bright")
|
||||||
|
|
||||||
class Name(object):
|
class Name(object):
|
||||||
__slots__ = ["first_name", "nickname", "language", "has_name", "words", "parts_of_speech"]
|
__slots__ = ["first_name", "nickname", "language", "has_name", "words", "parts_of_speech"]
|
||||||
|
|
||||||
class Soul(object):
|
class Soul(object):
|
||||||
pass
|
def __init__(self, *args, **kwds):
|
||||||
|
if kwds:
|
||||||
|
for k, v in kwds.iteritems():
|
||||||
|
self.__dict__[k] = v
|
||||||
|
|
||||||
class MapBlock40d(object):
|
class MapBlock40d(object):
|
||||||
pass
|
pass
|
Loading…
Reference in New Issue