def initialise(self): """ Initialise the database with anything needed for this game. The ruleset should do things like, - Create any components in the databases - Create any resources in the databases - etc This should not add anything to the players universe. Use the populate command for that. This command takes no arguments, so it should not do anything which needs information from the user. """ dbconn.use(self.game) trans = dbconn.begin() try: Event.new('gameadded', self.game) trans.commit() except: trans.rollback() raise
def turn(self): """ generate a turn for this ruleset For simple rulesets (and some reasonably complicated ones), this default method works. This method performs orders and actions in the order dictated via the orderOfOrders attribute. The program treats actions and orders almost identically. For example, If orderOfOrders contained, [MoveAction, Nop, (Clean, 'fleetsonly')] The move action would be applied first. Then all NOp orders would be performed. Then the Clean action would be applied with the argument ('fleetsonly') """ # Create a turn processing lock dbconn.use(self.game) lock = Lock.new('processing') # Connect to the database trans = dbconn.begin() try: # FIXME: This won't work as if a move then colonise order occurs, # and the move order completed the colonise order won't be # performed. It also removes the ability for dummy orders to be # removed. # # Get all the orders d = OrderGet() print d for action in self.orderOfOrders: if type(action) == TupleType: action, args = action[0], action[1:] else: args = tuple() name = str(action.__name__) if "orders" in name: green("%s - Starting with" % name, args) if d.has_key(name): for order in d[name]: order.do(*args) else: print "No orders of that type avaliable.." green("%s - Finished" % name) elif "actions" in name: blue("%s - Starting with" % name, args) __import__(name, globals(), locals(), ["do"]).do(Object(0), *args) blue("%s - Finished" % name) sys.stdout.write("\n") # Reparent the universe # Create a EOT event Event.new('endofturn', self.game) trans.commit() except: dbconn.rollback() raise