From 00ab0c4be220dc8b168ad2d5eb7dea1fb865c710 Mon Sep 17 00:00:00 2001 From: Raffson Date: Mon, 26 Dec 2022 01:27:52 +0100 Subject: [PATCH] Add "Instant Squadron Transfer" cheat option Resolves #14 --- changelog.md | 1 + game/ato/flight.py | 4 ++++ game/migrator.py | 1 - game/settings/settings.py | 1 + qt_ui/main.py | 1 + qt_ui/windows/SquadronDialog.py | 23 ++++++++++++++++++++--- qt_ui/windows/settings/QSettingsWindow.py | 15 +++++++++++++++ 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 0331f686..4bd9a398 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## Features/Improvements * **[Mission Generation]** Given a CAS flight was planned, delay ground force attack until first CAS flight is on station * **[Mission Generation]** Add option to switch ATFLIR to LITENING automatically for ground based F-18C flights +* **[Cheat Menu]** Option to instantly transfer squadrons across bases. ## Fixes * **[UI]** Removed deprecated options diff --git a/game/ato/flight.py b/game/ato/flight.py index ee8625b5..089ab5ec 100644 --- a/game/ato/flight.py +++ b/game/ato/flight.py @@ -264,4 +264,8 @@ class Flight(SidcDescribable): results.kill_pilot(self, pilot) def recreate_flight_plan(self) -> None: + from game.sim.gameupdateevents import GameUpdateEvents + from game.server import EventStream + self._flight_plan_builder.regenerate() + EventStream.put_nowait(GameUpdateEvents().update_flight(self)) diff --git a/game/migrator.py b/game/migrator.py index 186499fe..8f4efc0d 100644 --- a/game/migrator.py +++ b/game/migrator.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING from game.ato.packagewaypoints import PackageWaypoints from game.data.doctrine import MODERN_DOCTRINE, COLDWAR_DOCTRINE, WWII_DOCTRINE -from game.utils import knots, feet, nautical_miles if TYPE_CHECKING: from game import Game diff --git a/game/settings/settings.py b/game/settings/settings.py index 9b6fede1..33f8dd88 100644 --- a/game/settings/settings.py +++ b/game/settings/settings.py @@ -509,6 +509,7 @@ class Settings: show_red_ato: bool = False enable_frontline_cheats: bool = False enable_base_capture_cheat: bool = False + enable_transfer_cheat: bool = False # LUA Plugins system plugins: Dict[str, bool] = field(default_factory=dict) diff --git a/qt_ui/main.py b/qt_ui/main.py index f8d33fd3..2e05fccd 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -304,6 +304,7 @@ def create_game( automate_aircraft_reinforcements=auto_procurement, enable_frontline_cheats=cheats, enable_base_capture_cheat=cheats, + enable_transfer_cheat=cheats, restrict_weapons_by_date=restrict_weapons_by_date, ), GeneratorSettings( diff --git a/qt_ui/windows/SquadronDialog.py b/qt_ui/windows/SquadronDialog.py index 4465097a..50137d20 100644 --- a/qt_ui/windows/SquadronDialog.py +++ b/qt_ui/windows/SquadronDialog.py @@ -14,7 +14,9 @@ from PySide2.QtWidgets import ( QVBoxLayout, ) +from game.ato.flightplans.custom import CustomFlightPlan from game.ato.flighttype import FlightType +from game.ato.flightwaypointtype import FlightWaypointType from game.squadrons import Pilot, Squadron from game.theater import ConflictTheater, ControlPoint from qt_ui.delegates import TwoColumnRowDelegate @@ -96,7 +98,8 @@ class SquadronDestinationComboBox(QComboBox): room = squadron.location.unclaimed_parking() self.addItem( - f"Remain at {squadron.location} (room for {room} more aircraft)", None + f"Remain at {squadron.location} (room for {room} more aircraft)", + squadron.location, ) selected_index: Optional[int] = None for idx, destination in enumerate(sorted(self.iter_destinations(), key=str), 1): @@ -117,7 +120,7 @@ class SquadronDestinationComboBox(QComboBox): def iter_destinations(self) -> Iterator[ControlPoint]: size = self.squadron.expected_size_next_turn for control_point in self.theater.control_points_for(self.squadron.player): - if control_point == self: + if control_point == self.squadron.location: continue if not control_point.can_operate(self.squadron.aircraft): continue @@ -188,11 +191,25 @@ class SquadronDialog(QDialog): def squadron(self) -> Squadron: return self.squadron_model.squadron + def _instant_relocate(self, destination: ControlPoint) -> None: + self.squadron.relocate_to(destination) + for _, f in self.squadron.flight_db.objects.items(): + if f.squadron == self.squadron: + if isinstance(f.flight_plan, CustomFlightPlan): + for wpt in f.flight_plan.waypoints: + if wpt.waypoint_type == FlightWaypointType.LANDING_POINT: + wpt.control_point = destination + wpt.position = wpt.control_point.position + break + f.recreate_flight_plan() + def on_destination_changed(self, index: int) -> None: with report_errors("Could not change squadron destination", self): destination = self.transfer_destination.itemData(index) - if destination is None: + if destination is self.squadron.location: self.squadron.cancel_relocation() + elif self.ato_model.game.settings.enable_transfer_cheat: + self._instant_relocate(destination) else: self.squadron.plan_relocation(destination) self.ato_model.replace_from_game(player=True) diff --git a/qt_ui/windows/settings/QSettingsWindow.py b/qt_ui/windows/settings/QSettingsWindow.py index c8897d0a..b313c86f 100644 --- a/qt_ui/windows/settings/QSettingsWindow.py +++ b/qt_ui/windows/settings/QSettingsWindow.py @@ -60,6 +60,10 @@ class CheatSettingsBox(QGroupBox): ) self.base_capture_cheat_checkbox.toggled.connect(apply_settings) + self.transfer_cheat_checkbox = QCheckBox() + self.transfer_cheat_checkbox.setChecked(game.settings.enable_transfer_cheat) + self.transfer_cheat_checkbox.toggled.connect(apply_settings) + self.red_ato = QLabeledWidget("Show Red ATO:", self.red_ato_checkbox) self.main_layout.addLayout(self.red_ato) self.frontline_cheat = QLabeledWidget( @@ -70,6 +74,10 @@ class CheatSettingsBox(QGroupBox): "Enable Base Capture Cheat:", self.base_capture_cheat_checkbox ) self.main_layout.addLayout(self.base_capture_cheat) + self.transfer_cheat = QLabeledWidget( + "Enable Instant Squadron Transfer Cheat:", self.transfer_cheat_checkbox + ) + self.main_layout.addLayout(self.transfer_cheat) @property def show_red_ato(self) -> bool: @@ -83,6 +91,10 @@ class CheatSettingsBox(QGroupBox): def show_base_capture_cheat(self) -> bool: return self.base_capture_cheat_checkbox.isChecked() + @property + def show_transfer_cheat(self) -> bool: + return self.transfer_cheat_checkbox.isChecked() + class AutoSettingsLayout(QGridLayout): def __init__( @@ -360,6 +372,9 @@ class QSettingsWindow(QDialog): self.game.settings.enable_base_capture_cheat = ( self.cheat_options.show_base_capture_cheat ) + self.game.settings.enable_transfer_cheat = ( + self.cheat_options.show_transfer_cheat + ) events = GameUpdateEvents() self.game.compute_unculled_zones(events)