Fix cases where pilots were not returned.

https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
Dan Albert 2021-05-26 18:49:19 -07:00
parent 5277beede3
commit 8b8e018521
7 changed files with 15 additions and 1 deletions

View File

@ -387,6 +387,8 @@ class Game:
# Update statistics
self.game_stats.update(self)
self.blue_air_wing.reset()
self.red_air_wing.reset()
self.aircraft_inventory.reset()
for cp in self.theater.controlpoints:
self.aircraft_inventory.set_from_control_point(cp)

View File

@ -78,7 +78,7 @@ class Squadron:
self.available_pilots.extend(new_pilots)
def return_all_pilots(self) -> None:
self.available_pilots = self.pilots
self.available_pilots = list(self.pilots)
@property
def faker(self) -> Faker:
@ -152,6 +152,10 @@ class AirWing:
def squadron_at_index(self, index: int) -> Squadron:
return list(self.iter_squadrons())[index]
def reset(self) -> None:
for squadron in self.iter_squadrons():
squadron.return_all_pilots()
@property
def size(self) -> int:
return sum(len(s) for s in self.squadrons.values())

View File

@ -529,6 +529,7 @@ class PendingTransfers:
flight = transport.flight
flight.package.remove_flight(flight)
self.game.aircraft_inventory.return_from_flight(flight)
flight.clear_roster()
@cancel_transport.register
def _cancel_transport_convoy(

View File

@ -257,6 +257,7 @@ class PackageBuilder:
flights = list(self.package.flights)
for flight in flights:
self.global_inventory.return_from_flight(flight)
flight.clear_roster()
self.package.remove_flight(flight)

View File

@ -284,6 +284,9 @@ class Flight:
def missing_pilots(self) -> int:
return len([p for p in self.pilots if p is None])
def clear_roster(self) -> None:
self.squadron.return_pilots([p for p in self.pilots if p is not None])
def __repr__(self):
name = db.unit_type_name(self.unit_type)
if self.custom_name:

View File

@ -167,6 +167,7 @@ class PackageModel(QAbstractListModel):
if flight.cargo is not None:
flight.cargo.transport = None
self.game_model.game.aircraft_inventory.return_from_flight(flight)
flight.clear_roster()
self.package.remove_flight(flight)
self.endRemoveRows()
self.update_tot()
@ -259,6 +260,7 @@ class AtoModel(QAbstractListModel):
self.ato.remove_package(package)
for flight in package.flights:
self.game.aircraft_inventory.return_from_flight(flight)
flight.clear_roster()
if flight.cargo is not None:
flight.cargo.transport = None
self.endRemoveRows()

View File

@ -239,6 +239,7 @@ class QNewPackageDialog(QPackageDialog):
super().on_cancel()
for flight in self.package_model.package.flights:
self.game.aircraft_inventory.return_from_flight(flight)
flight.clear_roster()
class QEditPackageDialog(QPackageDialog):