def change_map_flight_selection(self, index: QModelIndex) -> None: events = GameUpdateEvents() if not index.isValid(): events.deselect_flight() else: events.select_flight(self.package_model.flight_at_index(index)) EventStream.put_nowait(events)
def cancel_or_abort_flight(self, flight: Flight) -> None: if flight.state.cancelable: self.delete_flight(flight) EventStream.put_nowait(GameUpdateEvents().delete_flight(flight)) else: flight.abort() EventStream.put_nowait(GameUpdateEvents().update_flight(flight))
def cheat_capture(self) -> None: events = GameUpdateEvents() self.cp.capture(self.game_model.game, events, for_player=not self.cp.captured) # Reinitialized ground planners and the like. The ATO needs to be reset because # missions planned against the flipped base are no longer valid. self.game_model.game.initialize_turn(events) EventStream.put_nowait(events) GameUpdateSignal.get_instance().updateGame(self.game_model.game)
def run_in_thread(self) -> Iterator[None]: # This relies on undocumented behavior, but it is what the developer recommends: # https://github.com/encode/uvicorn/issues/742 thread = Thread(target=self.run) thread.start() try: while not self.started: time.sleep(1e-3) yield finally: self.should_exit = True EventStream.put_nowait(GameUpdateEvents().shut_down()) thread.join()
def update_game(self) -> None: events = GameUpdateEvents() events.update_tgo(self.ground_object) if any( package.target == self.ground_object for package in self.game.ato_for(player=False).packages ): # Replan if the tgo was a target of the redfor self.game.initialize_turn(events, for_red=True, for_blue=False) EventStream.put_nowait(events) GameUpdateSignal.get_instance().updateGame(self.game) # Refresh the dialog self.do_refresh_layout()
def cheat_alter_front_line(self, enemy_point: ControlPoint, advance: bool) -> None: amount = 0.2 if not advance: amount *= -1 self.cp.base.affect_strength(amount) enemy_point.base.affect_strength(-amount) front_line = self.cp.front_line_with(enemy_point) front_line.update_position() events = GameUpdateEvents().update_front_line(front_line) # Clear the ATO to replan missions affected by the front line. self.game.initialize_turn(events) EventStream.put_nowait(events) GameUpdateSignal.get_instance().updateGame(self.game)
def add_flight(self, flight: Flight) -> None: """Adds the new flight to the package.""" self.package_model.add_flight(flight) planner = FlightPlanBuilder(self.package_model.package, self.game.blue, self.game.theater) try: planner.populate_flight_plan(flight) self.package_model.update_tot() EventStream.put_nowait(GameUpdateEvents().new_flight(flight)) except PlanningError as ex: self.package_model.delete_flight(flight) logging.exception("Could not create flight") QMessageBox.critical(self, "Could not create flight", str(ex), QMessageBox.Ok) # noinspection PyUnresolvedReferences self.package_changed.emit()
def set_position( flight_id: UUID, waypoint_idx: int, position: LeafletPoint, game: Game = Depends(GameContext.require), ) -> None: from game.server import EventStream flight = game.db.flights.get(flight_id) if waypoint_idx == 0: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) waypoint = flight.flight_plan.waypoints[waypoint_idx - 1] waypoint.position = Point.from_latlng(LatLng(position.lat, position.lng), game.theater.terrain) package_model = (GameContext.get_model().ato_model_for( flight.blue).find_matching_package_model(flight.package)) if package_model is None: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail=f"Could not find PackageModel owning {flight}", ) package_model.update_tot() EventStream.put_nowait(GameUpdateEvents().update_flight(flight))
def cancel_or_abort_package(self, package: Package) -> None: with EventStream.event_context() as events: if all(f.state.cancelable for f in package.flights): events.delete_flights_in_package(package) self._delete_package(package) return package_model = self.find_matching_package_model(package) for flight in package.flights: if flight.state.cancelable: package_model.delete_flight(flight) events.delete_flight(flight) else: flight.abort() events.update_flight(flight)
def change_map_package_selection(self, index: QModelIndex) -> None: if not index.isValid(): EventStream.put_nowait(GameUpdateEvents().deselect_flight()) return package = self.ato_model.get_package_model(index) if package.rowCount() == 0: EventStream.put_nowait(GameUpdateEvents().deselect_flight()) else: EventStream.put_nowait(GameUpdateEvents().select_flight( package.flight_at_index(package.index(0))))
def on_packages_changed(self) -> None: if self.game is not None: self.game.compute_unculled_zones() EventStream.put_nowait(GameUpdateEvents().update_unculled_zones())
def on_close(self, _result) -> None: EventStream.put_nowait(GameUpdateEvents().update_flights_in_package( self.package_model.package))
def on_game_load(game: Game | None) -> None: EventStream.drain() EventStream.put_nowait(GameUpdateEvents().game_loaded(game))