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.
This commit is contained in:
Raffson 2023-05-01 16:06:20 +02:00
parent 31cfc333c7
commit b4b19d3ad5
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
5 changed files with 16 additions and 3 deletions

View File

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

View File

@ -56,12 +56,14 @@ 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
if claim_inv:
self.squadron.claim_inventory(count)
if roster is None:
self.roster = FlightRoster(self.squadron, initial_size=count)

View File

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

View File

@ -180,6 +180,7 @@ class AircraftGenerator:
FlightType.BARCAP,
StartType.COLD,
divert=None,
claim_inv=False,
)
flight.state = Completed(flight, self.game.settings)

View File

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