def run(self, fleet_id, practice_id, formation): fleet_id = int(fleet_id) practice_id = int(practice_id) formation = int(formation) logger.info( 'Making the fleet {} go on the practice {} with formation {}' .format(fleet_id, practice_id, formation)) practice_list = self.objects.get('PracticeList') if not practice_list: logger.error('No practice list was found. Giving up.') return practice = practice_list.practices[practice_id - 1] if practice.result != kcsapi.Practice.RESULT_NEW: logger.error('Practice {} is already done.'.format(practice_id)) return expected_fleet_type = practice.fleet_type if not fleet.are_all_ships_available(self, fleet_id): return fleet_list = self.objects.get('FleetList') fleet_ = fleet_list.fleets[fleet_id - 1] yield self.do_manipulator(organizing.MarkReservedForUse, ship_ids=fleet_.ship_ids, reserved_for_use=True) yield self.screen.change_screen(screens.PORT_PRACTICE) yield self.screen.check_opponent(practice.id) # The oppoonent changed the fleet organization. The expected type # mismatches -- retry the process from the beginning. if practice.fleet_type != expected_fleet_type: yield self.screen.cancel() yield self.do_manipulator(organizing.MarkReservedForUse, ship_ids=fleet_.ship_ids, reserved_for_use=False) self.add_manipulator(HandlePractice, fleet_id, practice_id) return yield self.screen.try_practice() yield self.screen.select_fleet(fleet_id) yield self.screen.confirm_practice() if len(fleet_.ship_ids) >= 4: yield self.screen.select_formation(formation) yield self.do_manipulator(EngagePractice, formation=formation) yield self.do_manipulator(organizing.MarkReservedForUse, ship_ids=fleet_.ship_ids, reserved_for_use=False)
def run(self, fleet_id, mission_id): fleet_id = int(fleet_id) mission_id = int(mission_id) logger.info('Making the fleet {} go on the mission {}'.format( fleet_id, mission_id)) mission_list = self.objects['MissionList'] mission = mission_list.get_mission(mission_id) if not mission: raise Exception('Mission {} is unknown.') if not fleet.are_all_ships_available(self, fleet_id): return ship_list = self.objects['ShipList'] fleet_list = self.objects['FleetList'] ready = True ship_ids = fleet_list.fleets[fleet_id - 1].ship_ids for ship_id in ship_ids: ship = ship_list.ships[str(ship_id)] if not ship.resource_full: # Do not use unicode string in the exception message. It does # not work well with traceback.format_exception(). logger.error( u'Ship {} ({}) is not loading resources to its full ' u'capacity.'.format(ship.name, ship.id)) ready = False if not ready: yield self.do_manipulator(logistics.ChargeFleet(fleet_id=fleet_id)) yield self.do_manipulator(organizing.MarkReservedForUse, ship_ids=ship_ids, reserved_for_use=True) yield self.screen.change_screen(screens.PORT_MISSION) yield self.screen.select_maparea(mission.maparea) mission_index = mission_list.get_index_in_maparea(mission) yield self.screen.select_mission(mission_index) yield self.screen.confirm() yield self.screen.select_fleet(fleet_id) yield self.screen.finalize() yield self.do_manipulator(organizing.MarkReservedForUse, ship_ids=ship_ids, reserved_for_use=False)