def moveTo(self, source, destination): """Orders a fleet to move to a destination source - ID of the fleet to move destination - ID of the destination object """ object = self.objects[source] if object.subtype is FLEET: target = self.objects[destination] descs = OrderDescs() order_types = objectutils.getOrderTypes(self.getCache(), source) for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue descclass = descs[order_type] if descclass._name in ['Move', 'Move To', 'Intercept']: orderargs = [0, source, -1, descclass.subtype, 0, []] for prop in descclass.properties: if isinstance(prop, parameters.OrderParamAbsSpaceCoords): pos = [x for x in tp_helpers.getAbsPosition(target)] orderargs.append([pos]) if isinstance(prop, parameters.OrderParamObject): orderargs.append(destination) order = objects.Order(*orderargs) order._dirty = True self.sendOrder(source, order) self.starmap.connectObjects(source, destination) break
def moveTo(self, source, destination): """Orders a fleet to move to a destination source - ID of the fleet to move destination - ID of the destination object """ object = self.objects[source] if object.subtype is FLEET: target = self.objects[destination] descs = OrderDescs() order_types = objectutils.getOrderTypes(self.getCache(), source) for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue descclass = descs[order_type] if descclass._name in ['Move', 'Move To', 'Intercept']: orderargs = [0, source, -1, descclass.subtype, 0, []] for prop in descclass.properties: if isinstance(prop, parameters.OrderParamAbsSpaceCoords): pos = [ x for x in tp_helpers.getAbsPosition(target) ] orderargs.append([pos]) if isinstance(prop, parameters.OrderParamObject): orderargs.append(destination) order = objects.Order(*orderargs) order._dirty = True self.sendOrder(source, order) self.starmap.connectObjects(source, destination) break
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
def showOrder(self, evt=None, index=None): """Show the arguments for a selected order evt is used if the method is a callback from CEGUI index is used to indicate which of the available orders to show Either evt or index will be used only, the other parameter can be None """ if evt: index = int(evt.window.name.c_str()[17:]) if index == None: print "no valid index" return None id = self.parent.getIDFromMovable(self.parent.current_object) cache = self.parent.getCache() object = cache.objects[id] descs = OrderDescs() orders = [] for order_type in objectutils.getOrderTypes(cache, id).popitem()[1]: if not descs.has_key(order_type): continue orders.append(descs[order_type]) order_description = orders[index] self.arguments = [] orderargs = [0, id, -1, order_description.subtype, 0, []] for prop in order_description.properties: orderargs += self.defaults[type(prop)] order = order_description(*orderargs) # need to send an empty order to get allowable choices e.g. production self.parent.sendOrder(id, order) for prop in order_description.properties: print "adding argument", prop self.arguments_window.addArgument(prop.name, ARG_PARAM_MAP[type(prop)]) self.arguments_window.show(order_description._name) self.arguments_window.setCurrentOrder(id, order_description.subtype) self.update_order = order self.update_id = id
def openOrdersMenu(self): """Open the radial menu which shows available orders""" if not self.current_object: return id = self.getIDFromMovable(self.current_object) object = self.objects[id] order_types = objectutils.getOrderTypes(self.getCache(), id) if len(order_types) > 0: self.orders_menu.entity = self.current_object if self.orders_menu.toggle(): descs = OrderDescs() for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue description = descs[order_type] #print description self.orders_menu.add(description._name, self.orders_window, "showOrder") else: self.orders_window.hideArguments()