def equipment_test(self): eqp = rpg.equipment eqp.define_set("Humanoid", ["Head", "Left Hand", "Right Hand", "Quiver"]) eqp.define_slot("Quiver", ["Projectile"], 0.0) eqp.define_slot("Left Hand", ["Weapon"], 0.0) eqp.define_slot("Right Hand", ["Shield"], 0.5) eqp.define_slot("Head", ["Helmet"], 0.2) print "Saving ..." file = base.diskio(base.diskio.GZ_FILE) eqp.put_state(file) file.put_record(self.Data) print "Loading ..." file = base.diskio(base.diskio.GZ_FILE) file.get_record(self.Data) eqp.get_state(file) print "Humanoid Inventory:", eqp.get_set_modifier("Humanoid") inv = eqp.create_inventory("Humanoid") slt = inv.first() while slt != None: print "*", slt.id(), ":", eqp.get_modifier(slt.id()) slt = inv.next()
def eventtest(self): filename = sys.path[0] + "/data/eventtest.data" # -- add data directory to python search path sys.path.insert(0, "data") fty = event.factory() svd = 0 # -- first event ev1 = event.time_event("0m30s") ev1.set_repeat("30s", 6) lst = fty.add(ev1) lst.connect_callback("time_events", "event_script", "callback_1", ("#1", 1)) # -- second event ev2 = event.time_event("1m05s") ev2.set_repeat("30s", 4) lst = fty.add(ev2) lst.connect_callback("time_events", "event_script", "callback_2") # -- run for 3:20 gametime minutes while event.date.time() < 200: # -- save factory to disk if event.date.time() == 100 and svd == 0: print " Saving state" record = base.diskio(base.diskio.GZ_FILE) fty.put_state(record) record.put_record(filename) svd = 1 base.Timer.update() event.date.update() # -- resume with saved state print " Returning to previously saved state" fty.clear() # -- need absolute filename for loading or file has to sit in # Adonthell's search path record = base.diskio(base.diskio.GZ_FILE) record.get_record(filename) success = fty.get_state(record) if success == 1: print "OK" else:
def eventtest (self): filename = sys.path[0] + "/data/eventtest.data" # -- add data directory to python search path sys.path.insert (0, "data") fty = event.factory () svd = 0 # -- first event ev1 = event.time_event ("0m30s") ev1.set_repeat ("30s", 6) lst = fty.add (ev1) lst.connect_callback ("time_events", "event_script", "callback_1", ("#1", 1)) # -- second event ev2 = event.time_event ("1m05s") ev2.set_repeat ("30s", 4) lst = fty.add (ev2) lst.connect_callback ("time_events", "event_script", "callback_2") # -- run for 3:20 gametime minutes while event.date.time () < 200: # -- save factory to disk if event.date.time () == 100 and svd == 0: print " Saving state" record = base.diskio (base.diskio.GZ_FILE) fty.put_state (record) record.put_record (filename) svd = 1 base.Timer.update () event.date.update () # -- resume with saved state print " Returning to previously saved state" fty.clear () # -- need absolute filename for loading or file has to sit in # Adonthell's search path record = base.diskio (base.diskio.GZ_FILE) record.get_record (filename) success = fty.get_state (record) if success == 1: print "OK" else:
def run(self): # -- check that we've got a file to report on if len(sys.argv) != 2: print "usage: python filereport.py <filename>" return # -- get filename filename = sys.argv[1] # -- open file of detected type record = base.diskio(self.file_type(filename)) # -- load contents of file record.get_record(filename) print "Checksum =", hex(record.checksum()) print "Byteorder =", chr(record.byte_order()) print "Contents:" print "" print "Field Type Len Value" print "---------- -------- ----- ------------------------------" # -- print contents recursively to stdout self.print_record(record, 0) print "========== ======== ===== =============================="
def run (self): # -- check that we've got a file to report on if len (sys.argv) != 2: print "usage: python filereport.py <filename>" return # -- get filename filename = sys.argv[1] # -- open file of detected type record = base.diskio (self.file_type (filename)) # -- load contents of file record.get_record (filename) print "Checksum =", hex (record.checksum()) print "Byteorder =", chr (record.byte_order()) print "Contents:" print "" print "Field Type Len Value" print "---------- -------- ----- ------------------------------" # -- print contents recursively to stdout self.print_record (record, 0) print "========== ======== ===== =============================="
def test_cube_io (self): """Test saving and loading of a cube""" # -- create cube cube = world.cube3 (100, 100, 40) # -- save cube record = base.diskio (base.diskio.XML_FILE) cube.put_state (record) record.put_record ("cube.xml") # -- load cube record.get_record ("cube.xml") cube.get_state (record); return cube
def __init__ (self): self.GzWriter = base.diskio (base.diskio.GZ_FILE) self.XmlWriter = base.diskio (base.diskio.XML_FILE)
def inventory_test (self): Torches = [] Inventories = [] # -- create some mutable items print "Creating torches ...", while len (Torches) < 7: Torches.append (rpg.item (1)) Torches[-1].get_state (self.path + "small_torch.item") print len(Torches), # -- create immutable items print "done\nCreating coins ...", Coin = rpg.item (0) Coin.get_state (self.path + "coin.item") rpg.item_storage.add (Coin) # -- create some inventories print "done\nCreating inventories ...", Inventories.append (rpg.inventory (5, 1)) Inventories.append (rpg.inventory (5, 1)) Inventories.append (rpg.inventory (0, 0)) # -- populate inventories print "done\nPopulating inventories ...", Inventories[0].add (Coin, 3500) Inventories[0].add (Torches[0]) Inventories[1].add (Torches[1]) Inventories[1].add (Torches[2]) Inventories[1].add (Coin, 2100) Inventories[1].add (Torches[3]) Inventories[1].add (Torches[4]) Inventories[2].add (Coin, 2100) Inventories[2].add (Torches[5]) Inventories[2].add (Torches[6]) # -- actual tests print "done" self.print_inventories (Inventories) print "Saving ..." out = base.diskio (base.diskio.GZ_FILE) for i in Inventories: i.put_state (out) out.put_record ("/tmp/itemtest.tmp") print "Cleaning up ..." Inventories = [] Inventories.append (rpg.inventory ()) Inventories.append (rpg.inventory ()) Inventories.append (rpg.inventory ()) print "Loading ..." rin = base.diskio (base.diskio.GZ_FILE) rin.get_record ("/tmp/itemtest.tmp") for i in Inventories: i.get_state (rin) self.print_inventories (Inventories) print "Moving some stuff around ..." self.move (Inventories[2], Inventories[0], 5, 2) self.move (Inventories[2], Inventories[0], 1, 55) self.move (Inventories[2], Inventories[2], 5, 100) self.move (Inventories[0], Inventories[0], 5, 4) self.print_inventories([Inventories[0], Inventories[2]]) print "Saving ..." out = base.diskio (base.diskio.GZ_FILE) for i in Inventories: i.put_state (out) out.put_record ("/tmp/itemtest.tmp") print "Cleaning up ..." Inventories = [] Inventories.append (rpg.inventory ()) Inventories.append (rpg.inventory ()) Inventories.append (rpg.inventory ()) print "Loading ..." rin = base.diskio (base.diskio.GZ_FILE) rin.get_record ("/tmp/itemtest.tmp") for i in Inventories: i.get_state (rin) self.print_inventories (Inventories) print "Moving some stuff around ..." self.move (Inventories[2], Inventories[1], 1, 1000) self.print_inventories ([Inventories[1], Inventories[2]]) # -- cleanup rpg.item_storage.cleanup ()
def inventory_test(self): Torches = [] Inventories = [] # -- create some mutable items print "Creating torches ...", while len(Torches) < 7: Torches.append(rpg.item(1)) Torches[-1].get_state(self.path + "small_torch.item") print len(Torches), # -- create immutable items print "done\nCreating coins ...", Coin = rpg.item(0) Coin.get_state(self.path + "coin.item") rpg.item_storage.add(Coin) # -- create some inventories print "done\nCreating inventories ...", Inventories.append(rpg.inventory(5, 1)) Inventories.append(rpg.inventory(5, 1)) Inventories.append(rpg.inventory(0, 0)) # -- populate inventories print "done\nPopulating inventories ...", Inventories[0].add(Coin, 3500) Inventories[0].add(Torches[0]) Inventories[1].add(Torches[1]) Inventories[1].add(Torches[2]) Inventories[1].add(Coin, 2100) Inventories[1].add(Torches[3]) Inventories[1].add(Torches[4]) Inventories[2].add(Coin, 2100) Inventories[2].add(Torches[5]) Inventories[2].add(Torches[6]) # -- actual tests print "done" self.print_inventories(Inventories) print "Saving ..." out = base.diskio(base.diskio.GZ_FILE) for i in Inventories: i.put_state(out) out.put_record("/tmp/itemtest.tmp") print "Cleaning up ..." Inventories = [] Inventories.append(rpg.inventory()) Inventories.append(rpg.inventory()) Inventories.append(rpg.inventory()) print "Loading ..." rin = base.diskio(base.diskio.GZ_FILE) rin.get_record("/tmp/itemtest.tmp") for i in Inventories: i.get_state(rin) self.print_inventories(Inventories) print "Moving some stuff around ..." self.move(Inventories[2], Inventories[0], 5, 2) self.move(Inventories[2], Inventories[0], 1, 55) self.move(Inventories[2], Inventories[2], 5, 100) self.move(Inventories[0], Inventories[0], 5, 4) self.print_inventories([Inventories[0], Inventories[2]]) print "Saving ..." out = base.diskio(base.diskio.GZ_FILE) for i in Inventories: i.put_state(out) out.put_record("/tmp/itemtest.tmp") print "Cleaning up ..." Inventories = [] Inventories.append(rpg.inventory()) Inventories.append(rpg.inventory()) Inventories.append(rpg.inventory()) print "Loading ..." rin = base.diskio(base.diskio.GZ_FILE) rin.get_record("/tmp/itemtest.tmp") for i in Inventories: i.get_state(rin) self.print_inventories(Inventories) print "Moving some stuff around ..." self.move(Inventories[2], Inventories[1], 1, 1000) self.print_inventories([Inventories[1], Inventories[2]]) # -- cleanup rpg.item_storage.cleanup()
def __init__(self): self.GzWriter = base.diskio(base.diskio.GZ_FILE) self.XmlWriter = base.diskio(base.diskio.XML_FILE)