def launch_mission(self): """Finishes planning and waits for mission completion.""" if not self.ato_has_clients() and not self.confirm_no_client_launch(): return negative_starts = self.negative_start_packages() if negative_starts: if not self.confirm_negative_start_time(negative_starts): return # TODO: Refactor this nonsense. game_event = None for event in self.game.events: if isinstance(event, FrontlineAttackEvent) and event.is_player_attacking: game_event = event if game_event is None: game_event = FrontlineAttackEvent( self.game, self.game.theater.controlpoints[0], self.game.theater.controlpoints[0], self.game.theater.controlpoints[0].position, self.game.player_name, self.game.enemy_name) game_event.is_awacs_enabled = True game_event.ca_slots = 1 game_event.departure_cp = self.game.theater.controlpoints[0] game_event.player_attacking({CAS: {}, CAP: {}}) game_event.depart_from = self.game.theater.controlpoints[0] self.game.initiate_event(game_event) waiting = QWaitingForMissionResultWindow(game_event, self.game) waiting.show()
def launch_mission(self): """Finishes planning and waits for mission completion.""" if not self.ato_has_clients() and not self.confirm_no_client_launch(): return if self.check_no_missing_pilots(): return negative_starts = self.negative_start_packages() if negative_starts: if not self.confirm_negative_start_time(negative_starts): return closest_cps = self.game.theater.closest_opposing_control_points() game_event = AirWarEvent( self.game, closest_cps[0], closest_cps[1], self.game.theater.controlpoints[0].position, self.game.player_faction.name, self.game.enemy_faction.name, ) unit_map = self.game.initiate_event(game_event) waiting = QWaitingForMissionResultWindow(game_event, self.game, unit_map) waiting.show()
def on_start(self): # TODO : refactor this nonsense self.gameEvent = None for event in self.game.events: if isinstance(event, FrontlineAttackEvent) and event.is_player_attacking: self.gameEvent = event if self.gameEvent is None: self.gameEvent = FrontlineAttackEvent( self.game, self.game.theater.controlpoints[0], self.game.theater.controlpoints[0], self.game.theater.controlpoints[0].position, self.game.player_name, self.game.enemy_name) #if self.awacs_checkbox.isChecked() == 1: # self.gameEvent.is_awacs_enabled = True # self.game.awacs_expense_commit() #else: # self.gameEvent.is_awacs_enabled = False self.gameEvent.is_awacs_enabled = True self.gameEvent.ca_slots = 1 self.gameEvent.departure_cp = self.game.theater.controlpoints[0] self.gameEvent.player_attacking({CAS: {}, CAP: {}}) self.gameEvent.depart_from = self.game.theater.controlpoints[0] self.game.initiate_event(self.gameEvent) waiting = QWaitingForMissionResultWindow(self.gameEvent, self.game) waiting.show() self.close()
def start(self): if self.awacs_checkbox.isChecked() == 1: self.gameEvent.is_awacs_enabled = True self.game.awacs_expense_commit() else: self.gameEvent.is_awacs_enabled = False ca_slot_entry_value = self.ca_slot_entry.value() try: ca_slots = int(ca_slot_entry_value and ca_slot_entry_value or "0") except: ca_slots = 0 self.gameEvent.ca_slots = ca_slots # Resolve Departure CP self.gameEvent.departure_cp = self.depart_from.itemData(self.depart_from.currentIndex()) flights = {k: {} for k in self.gameEvent.tasks} # type: db.TaskForceDict units_scramble_counts = {} # type: typing.Dict[typing.Type[UnitType], int] tasks_scramble_counts = {} # type: typing.Dict[typing.Type[Task], int] tasks_clients_counts = {} # type: typing.Dict[typing.Type[Task], int] def dampen_count(unit_type, count: int) -> int: nonlocal units_scramble_counts total_count = self.base.total_units_of_type(unit_type) total_scrambled = units_scramble_counts.get(unit_type, 0) dampened_value = count if count + total_scrambled < total_count else total_count - total_scrambled units_scramble_counts[unit_type] = units_scramble_counts.get(unit_type, 0) + dampened_value return dampened_value for task_type, dict in self.scramble_entries.items(): for unit_type, (count_entry, clients_entry) in dict.items(): try: count = int(count_entry.value()) except: count = 0 try: clients_count = int(clients_entry and clients_entry.value() or 0) except: clients_count = 0 dampened_count = dampen_count(unit_type, count) tasks_clients_counts[task_type] = tasks_clients_counts.get(task_type, 0) + clients_count tasks_scramble_counts[task_type] = tasks_scramble_counts.get(task_type, 0) + dampened_count flights[task_type][unit_type] = dampened_count, clients_count for task in self.gameEvent.ai_banned_tasks: if tasks_clients_counts.get(task, 0) == 0 and tasks_scramble_counts.get(task, 0) > 0: self.showErrorMessage("Need at least one player in flight {}".format(self.gameEvent.flight_name(task))) return for task in self.gameEvent.player_banned_tasks: if tasks_clients_counts.get(task, 0) != 0: self.showErrorMessage("Players are not allowed on flight {}".format(self.gameEvent.flight_name(task))) return if self.game.is_player_attack(self.gameEvent): if isinstance(self.gameEvent, FrontlineAttackEvent): if self.base.total_armor == 0: self.showErrorMessage("No ground vehicles available to attack!") return self.gameEvent.player_attacking(flights) else: if isinstance(self.gameEvent, FrontlineAttackEvent): if self.gameEvent.to_cp.base.total_armor == 0: self.showErrorMessage("No ground vehicles available to defend!") return self.gameEvent.player_defending(flights) self.game.initiate_event(self.gameEvent) waiting = QWaitingForMissionResultWindow(self.gameEvent, self.game) waiting.show() self.close()