Add "Instant Squadron Transfer" cheat option

Resolves #14
This commit is contained in:
Raffson
2022-12-26 01:27:52 +01:00
parent 5c06e74659
commit 00ab0c4be2
7 changed files with 42 additions and 4 deletions

View File

@@ -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)