Ejemplo n.º 1
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)
	def sendOrder(self, id, order, action="create after", node=None):
		"""Sends an order to the server.

		If node is None, append the order to the end of the queue.

		"""
		cache = self.getCache()
		network = self.parent.application.network
		queue = objectutils.getOrderQueueList(cache, id)
		if not node:
			node = cache.orders[queue[0][1]].last
		evt = cache.apply("orders", action, queue[0][1], node, order)
		self.parent.application.Post(evt, source=self)
    def sendOrder(self, id, order, action="create after", node=None):
        """Sends an order to the server.

		If node is None, append the order to the end of the queue.

		"""
        cache = self.getCache()
        network = self.parent.application.network
        queue = objectutils.getOrderQueueList(cache, id)
        if not node:
            node = cache.orders[queue[0][1]].last
        evt = cache.apply("orders", action, queue[0][1], node, order)
        self.parent.application.Post(evt, source=self)
Ejemplo n.º 4
0
	def updateOrdersWindow(self, id, cache):
		"""Update the order queue and available orders in the orders window

		Returns True if the window is updated successfully.

		"""
		wm = cegui.WindowManager.getSingleton()
		order_queue = wm.getWindow("Orders/OrderQueue")
		order_list = wm.getWindow("Orders/OrderList")
		order_queue.resetList()
		order_list.resetList()
		order_list.setText("")

		self.order_queue_items = []
		self.order_queue_list = []

		order_types = objectutils.getOrderTypes(cache, id)
		if len(order_types) <= 0:
			return False

		object = cache.objects[id]

		queuelist = cache.orders[objectutils.getOrderQueueList(cache, id)[0][1]]
		for o_node in queuelist:
			index = order_queue.addRow()
			order = o_node.CurrentOrder
			self.order_queue_list.append(o_node)
			item = cegui.ListboxTextItem(order._name)
			item.setAutoDeleted(False)
			item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush")
			self.order_queue_items.append(item)
			order_queue.setItem(item, 0, index) # col id, row id

			item = cegui.ListboxTextItem(str(order.turns))
			item.setAutoDeleted(False)
			order_queue.setItem(item, 1, index)
			self.order_queue_items.append(item)

		if len(order_types) > 0:
			self.orders = {}
			descs = OrderDescs()
			for order_type in order_types.popitem()[1]:
				if not descs.has_key(order_type):
					continue
				description = descs[order_type]
				item = cegui.ListboxTextItem(description._name)
				item.setAutoDeleted(False)
				self.orders[order_type] = item
				order_list.addItem(item)

		return True
Ejemplo n.º 5
0
	def update(self):
		"""Updates any lists in the arguments window upon receiving from the server"""
		#print "Updating list items"
		if self.id != None and self.order_subtype != None:
			cache = self.parent.getCache()
			queue_id = objectutils.getOrderQueueList(cache, self.id)[0][1]
			order = cache.orders[queue_id].last.CurrentOrder
			for triplet in self.arguments_pending_update:
				#print triplet
				arg_type = triplet[0]
				argument = triplet[1]
				attribute = triplet[2]

				if arg_type is ARG_LIST:
					if order is None:
						print "order is none"
						break
					update_list = getattr(order, attribute)[0]
					selection = argument.getChild("%s/Selection" % argument.name.c_str())
					print selection, selection.name, update_list
					self.update_list[argument.name.c_str()] = update_list

					selection.resetList()
					self.selection_list = {}

					for element in update_list:
						#print element[1]
						item = cegui.ListboxTextItem(element[1])
						item.setAutoDeleted(False)
						selection.addItem(item)
						if self.selection_list.has_key(element[1]):
							self.selection_list[element[1]].append(item)
						else:
							self.selection_list[element[1]] = [item]

			self.arguments_pending_update = []