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
5 changed files with 16 additions and 3 deletions

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)