Ejemplo n.º 1
0
    def updateOrder(self, conn, id, type, order_id, moreargs):
        """Not sure if this is the correct way, but it works"""
        args = [0, id, -1, type, 0, []]
        # Really stupid hack that makes me crazy, http post forms converts
        # everything into strings and I dont want to process the args seperatly
        # on the backend side.
        def recur_map(func, data):
            if hasattr(data, '__iter__'):
                return [recur_map(func, elem) for elem in data]
            else:
                try:
                    return func(data)
                except ValueError:
                    return data

        if moreargs:
            for arg in moreargs:
                args += recur_map(int, json.loads(arg))

        # Create the new order
        new = objects.Order(*args)
        new._dirty = True

        node = self.cache.orders[id][order_id]
        assert not node is None

        # Do some sanity checking
        d = self.cache.orders[id]
        assert node in d

        evt = self.cache.apply('orders', 'change', id, node, new)
        apply(conn, evt, self.cache)
        self.cache.save()
Ejemplo n.º 2
0
    def updateOrder(self, conn, id, type, order_id, moreargs):
        """Not sure if this is the correct way, but it works"""
        args = [0, id, -1, type, 0, []]

        # Really stupid hack that makes me crazy, http post forms converts
        # everything into strings and I dont want to process the args seperatly
        # on the backend side.
        def recur_map(func, data):
            if hasattr(data, '__iter__'):
                return [recur_map(func, elem) for elem in data]
            else:
                try:
                    return func(data)
                except ValueError:
                    return data

        if moreargs:
            for arg in moreargs:
                args += recur_map(int, json.loads(arg))

        # Create the new order
        new = objects.Order(*args)
        new._dirty = True

        node = self.cache.orders[id][order_id]
        assert not node is None

        # Do some sanity checking
        d = self.cache.orders[id]
        assert node in d

        evt = self.cache.apply('orders', 'change', id, node, new)
        apply(conn, evt, self.cache)
        self.cache.save()
Ejemplo n.º 3
0
 def sendOrder(self, conn, id, type, moreargs):
     print "Sending Orders ", type
     # sequence, id, slot, type, turns, resources
     args = [0, id, -1, type, 0, []]
     position = 0
     
     # get orderdesc so we can get default args for order type
     ordertype = objects.OrderDescs()[type]
     
     #create dummy order with dummy results
     args = insertDummyOrder(args, ordertype);
     order = ordertype(*args)
     order._dirty = True
     
     queue = self.cache.orders[id]
     
     #The Order number in terms of queue position
     position = len(queue)
     print "Send Order pos: ", position
     #Add order to back of queue
     node = queue.last
     if node != None and order != None:
         print "Printing sendorder args: ", args
         #make a new order
         evt = self.cache.apply("orders", "create after", id, node, order)
         apply(conn, evt, self.cache)
     
     return position, self.cache
Ejemplo n.º 4
0
 def removeOrder(self, conn, id, order_position):
     print "Remove order pos ", int(order_position)
     queue = self.cache.orders[int(id)]
     node = getOrderNodeByPosition(queue, int(order_position))
     if node != None:
         evt = self.cache.apply('orders', 'remove', id, nodes=[node])
         apply(conn, evt, self.cache)
         
     return self.cache
Ejemplo n.º 5
0
def endTurn(cache,rulesystem,connection):
    orders = rulesystem.findConstraint("order_move(int,int)")
    for order in orders:
        objid = int(order.args[0])
        destination = int(order.args[1])
        print "Moving %s to %s" % (objid,cache.objects[destination].pos)
        moveorder = findOrderDesc("Move")
        args = [0, objid, -1, moveorder.subtype, 0, [], destination]
        order = moveorder(*args)
        evt = cache.apply("orders","create after",objid,cache.orders[objid].head,order)
        tp.client.cache.apply(connection,evt,cache)
    orders = rulesystem.findConstraint("order_buildfleet(int,tuple,str)")
    for order in orders:
        objid = order.args[0]
        ships = list(order.args[1])
        name = order.args[2]
        print "Ordering fleet %s of %s" % (name,ships)
        buildorder = findOrderDesc("Build Fleet")
        args = [0, objid, -1, buildorder.subtype, 0, [], [[],ships], (len(name),name)]
        order = buildorder(*args)
        evt = cache.apply("orders","create after",objid,cache.orders[objid].head,order)
        tp.client.cache.apply(connection,evt,cache)
    orders = rulesystem.findConstraint("order_produce(int,tuple)")
    for order in orders:
        objid = order.args[0]
        toproduce = list(order.args[1])
        print "Producing %s" % toproduce
        order = findOrderDesc("Produce")
        args = [0, objid, -1, order.subtype, 0, [], [[],toproduce]]
        o = order(*args)
        evt = cache.apply("orders","create after",objid,cache.orders[objid].head,o)
        tp.client.cache.apply(connection,evt,cache)
    orders = rulesystem.findConstraint("order_colonise(int,tuple)")
    for order in orders:
        objid = order.args[0]
        target = order.args[1]
        print "Colonizing %s" % target
        order = findOrderDesc("Colonise")
        args = [0, objid, -1, order.subtype, 0, [], target]
        o = order(*args)
        evt = cache.apply("orders","create after",objid,cache.orders[objid].head,o)
        tp.client.cache.apply(connection,evt,cache)
Ejemplo n.º 6
0
def deleteAllMessages():
    """
    Deletes all messages.
    """
    global cache
    global connection

    for node in cache.messages[0]:
        if node == None:
            break
        evt = cache.apply("messages", "remove", 0, node, None)
        tp.client.cache.apply(connection, evt, cache)
Ejemplo n.º 7
0
 def updateOrder(self, conn, id, type, order_position, moreargs):
     """Not sure if this is the correct way, but it works"""
     args = [0, id, -1, type, 0, []]
     # Really stupid hack that makes me crazy, http post forms converts
     # everything into strings and I dont want to process the args seperatly
     # on the backend side.
     def recur_map(func, data):
         #print "Entering recur map", data
         if hasattr(data, '__iter__'):
             #print "hasiter attri"
             args = []
             for elem in data:
                 args.append(recur_map(func, elem))
             # [recur_map(func, elem) for elem in data]
             return args
         else:
             try:
                 return func(data)
             except ValueError:
                 return data
     
     moreargsProcessed = []
     if moreargs:
         for arg in moreargs:
             moreargsProcessed.append(recur_map(int, json.loads(arg)))
     
     # Create the new order
     ordertype = objects.OrderDescs()[type]
     
     args = applyArgNesting(args, moreargsProcessed, ordertype)
     order = ordertype(*args)
     order._dirty = True
     
     queue = self.cache.orders[int(id)]
     node = getOrderNodeByPosition(queue, int(order_position))
     if node != None and order != None:       
             evt = self.cache.apply("orders", "change", id, node, order)
             apply(conn, evt, self.cache)    
     
     return self.cache
Ejemplo n.º 8
0
def endTurn(cache,rulesystem,connection):
    orders = rulesystem.findConstraint("order_move(int,int,int)")
    for order in orders:
        start = int(order.args[0])
        destination = int(order.args[1])
        amount = int(order.args[2])
        logging.getLogger("daneel.mod-risk").debug("Moving %s troops from %s to %s" % (amount,start,destination))
        moveorder = findOrderDesc("Move")
        args = [0, start, -1, moveorder.subtype, 0, [], ([], [(destination, amount)])]
        order = moveorder(*args)
        orderqueueID = getOrderQueueList(cache,start)[0][1]
        evt = cache.apply("orders","create after",orderqueueID,cache.orders[orderqueueID].head,order)
        if connection != None:
            tp.client.cache.apply(connection,evt,cache)
    orders = rulesystem.findConstraint("order_reinforce(int,int)")
    for order in orders:
        objid = order.args[0]
        amount = order.args[1]
        logging.getLogger("daneel.mod-risk").debug("Reinforcing %s with %s troops" % (objid,amount))
        orderd = findOrderDesc("Reinforce")
        args = [0, objid, -1, orderd.subtype, 0, [], (amount, 0)]
        order = orderd(*args)
        orderqueueID = getOrderQueueList(cache,objid)[0][1]
        evt = cache.apply("orders","create after",orderqueueID,cache.orders[orderqueueID].head,order)
        if connection != None:
            tp.client.cache.apply(connection,evt,cache)
    orders = rulesystem.findConstraint("order_colonise(int,int)")
    planet = selectOwnedPlanet(cache)
    for order in orders:
        objid = order.args[0]
        amount = order.args[1]
        logging.getLogger("daneel.mod-risk").debug("Colonizing %s with %s troops" % (objid,amount))
        orderd = findOrderDesc("Colonize")
        args = [0, objid, -1, orderd.subtype, 0, [], ([], [(objid, amount)])]
        o = orderd(*args)
        orderqueueID = getOrderQueueList(cache,start)[0][1]
        evt = cache.apply("orders","create after",orderqueueID,cache.orders[orderqueueID].head,o)
        if connection != None:
            tp.client.cache.apply(connection,evt,cache)
Ejemplo n.º 9
0
def executeOrder(cache, connection, objectId, order):
    # get the queue for the object
    queueid = extra.objectutils.getOrderQueueList(cache, objectId)[0][1]
    queue = cache.orders[queueid]
    node = queue.first
    
    #check if there is no existing order
    if order != None and queue.first.CurrentOrder is None:
        # make a new order   
        evt = cache.apply("orders", "create after", queueid, node, order)
        tp.client.cache.apply(connection, evt, cache)
    #check if the existing order is the same as current order
    elif not checkIfOrdersSame(node.CurrentOrder, order):
        if order != None:
            #replace the current order with the new one
            evt = cache.apply("orders", "change", queueid, node, order)
            tp.client.cache.apply(connection, evt, cache)
        #delete order
        else:
            nodes = [x for x in queue]
            evt = cache.apply("orders", "remove", queueid, nodes=nodes)
            tp.client.cache.apply(connection, evt, cache)
Ejemplo n.º 10
0
    def sendOrder(self, conn, id, type, moreargs):
        # sequence, id, slot, type, turns, resources
        args = [0, id, -1, type, 0, []]

        # get orderdesc so we can get default args for order type
        orderdesc = objects.OrderDescs()[type]
        for name, type in orderdesc.names:
            args += defaults[type]

        # Create the new order
        new = objects.Order(*args)
        new._dirty = True

        # Insert order after
        node = self.cache.orders[id].last
        assert not node is None

        # Do some sanity checking
        d = self.cache.orders[id]
        assert node in d

        evt = self.cache.apply("orders", "create after", id, node, new)
        apply(conn, evt, self.cache)
        self.cache.save()
Ejemplo n.º 11
0
    def sendOrder(self, conn, id, type, moreargs):
        # sequence, id, slot, type, turns, resources
        args = [0, id, -1, type, 0, []]

        # get orderdesc so we can get default args for order type
        orderdesc = objects.OrderDescs()[type]
        for name, type in orderdesc.names:
            args += defaults[type]

        # Create the new order
        new = objects.Order(*args)
        new._dirty = True

        # Insert order after
        node = self.cache.orders[id].last
        assert not node is None

        # Do some sanity checking
        d = self.cache.orders[id]
        assert node in d

        evt = self.cache.apply("orders", "create after", id, node, new)
        apply(conn, evt, self.cache)
        self.cache.save()
Ejemplo n.º 12
0
 def removeOrder(self, conn, id, order_id):
     node = self.cache.orders[id][order_id]
     evt = self.cache.apply('orders', 'remove', id, nodes=[node])
     apply(conn, evt, self.cache)
     self.cache.save()
Ejemplo n.º 13
0
 def removeOrder(self, conn, id, order_id):
     node = self.cache.orders[id][order_id]
     evt = self.cache.apply('orders', 'remove', id, nodes=[node])
     apply(conn, evt, self.cache)
     self.cache.save()