From b4b19d3ad5b1c18872de35f8cfeaff34f44db6f3 Mon Sep 17 00:00:00 2001 From: Raffson Date: Mon, 1 May 2023 16:06:20 +0200 Subject: [PATCH] Avoid claiming unused aircraft Probably the final Fix #97 Unused aircraft (assigned upon takeoff) would get claimed but since it's not possible to delete those flights after aborting, these flights wouldn't get released anymore. This should fix that issue, including a migrator change to correct the number of claimed aircraft per squadron. --- changelog.md | 1 + game/ato/flight.py | 4 +++- game/migrator.py | 11 +++++++++++ game/missiongenerator/aircraft/aircraftgenerator.py | 1 + qt_ui/windows/QWaitingForMissionResultWindow.py | 2 -- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index f9e5dbfa..6bb31469 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ ## Fixes * **[New Game Wizard]** Settings would not persist when going back to a previous page. +* **[Mission Generation]** Unused aircraft are no longer claimed, fixing a bug where these aircraft would no longer be available after aborting the mission. # Retribution v1.1.1 (hotfix) diff --git a/game/ato/flight.py b/game/ato/flight.py index 44042788..956d4cae 100644 --- a/game/ato/flight.py +++ b/game/ato/flight.py @@ -56,13 +56,15 @@ class Flight(SidcDescribable, RadioFrequencyContainer, TacanContainer): frequency: Optional[RadioFrequency] = None, channel: Optional[TacanChannel] = None, callsign: Optional[str] = None, + claim_inv: bool = True, ) -> None: self.id = uuid.uuid4() self.package = package self.country = country self.coalition = squadron.coalition self.squadron = squadron - self.squadron.claim_inventory(count) + if claim_inv: + self.squadron.claim_inventory(count) if roster is None: self.roster = FlightRoster(self.squadron, initial_size=count) else: diff --git a/game/migrator.py b/game/migrator.py index c58eca94..5f20ed0f 100644 --- a/game/migrator.py +++ b/game/migrator.py @@ -25,6 +25,7 @@ class Migrator: self._update_package_attributes() self._update_control_points() self._update_flights() + self._release_untasked_flights() def _update_doctrine(self) -> None: doctrines = [ @@ -77,3 +78,13 @@ class Migrator: try_set_attr(f, "tacan") try_set_attr(f, "tcn_name") try_set_attr(f, "fuel", f.unit_type.max_fuel) + + def _release_untasked_flights(self) -> None: + for cp in self.game.theater.controlpoints: + for s in cp.squadrons: + claimed = s.owned_aircraft - s.untasked_aircraft + count = 0 + for f in s.flight_db.objects.values(): + if f.squadron == s: + count += f.count + s.claim_inventory(count - claimed) diff --git a/game/missiongenerator/aircraft/aircraftgenerator.py b/game/missiongenerator/aircraft/aircraftgenerator.py index 9cccbd7f..93fd8f7f 100644 --- a/game/missiongenerator/aircraft/aircraftgenerator.py +++ b/game/missiongenerator/aircraft/aircraftgenerator.py @@ -180,6 +180,7 @@ class AircraftGenerator: FlightType.BARCAP, StartType.COLD, divert=None, + claim_inv=False, ) flight.state = Completed(flight, self.game.settings) diff --git a/qt_ui/windows/QWaitingForMissionResultWindow.py b/qt_ui/windows/QWaitingForMissionResultWindow.py index 628c6ac7..0397dc29 100644 --- a/qt_ui/windows/QWaitingForMissionResultWindow.py +++ b/qt_ui/windows/QWaitingForMissionResultWindow.py @@ -1,7 +1,6 @@ from __future__ import annotations import logging -import os from pathlib import Path from typing import Optional @@ -23,7 +22,6 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape from game import Game from game.debriefing import Debriefing -from game.persistency import base_path from game.profiling import logged_duration from qt_ui.simcontroller import SimController from qt_ui.windows.GameUpdateSignal import GameUpdateSignal