Convert flight creator to pilot roster.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1143
This commit is contained in:
Dan Albert
2021-06-02 01:48:39 -07:00
parent 8edb952800
commit 558502d8ea
9 changed files with 147 additions and 71 deletions

View File

@@ -144,7 +144,7 @@ class Event:
def _commit_pilot_experience(ato: AirTaskingOrder) -> None:
for package in ato.packages:
for flight in package.flights:
for idx, pilot in enumerate(flight.pilots):
for idx, pilot in enumerate(flight.roster.pilots):
if pilot is None:
logging.error(
f"Cannot award experience to pilot #{idx} of {flight} "

View File

@@ -13,7 +13,6 @@ from typing import (
List,
TYPE_CHECKING,
Optional,
Iterable,
Iterator,
Sequence,
)
@@ -142,8 +141,12 @@ class Squadron:
def return_pilot(self, pilot: Pilot) -> None:
self.available_pilots.append(pilot)
def return_pilots(self, pilots: Iterable[Pilot]) -> None:
self.available_pilots.extend(pilots)
def return_pilots(self, pilots: Sequence[Pilot]) -> None:
# Return in reverse so that returning two pilots and then getting two more
# results in the same ordering. This happens commonly when resetting rosters in
# the UI, when we clear the roster because the UI is updating, then end up
# repopulating the same size flight from the same squadron.
self.available_pilots.extend(reversed(pilots))
def enlist_new_pilots(self, count: int) -> None:
new_pilots = [Pilot(self.faker.name()) for _ in range(count)]

View File

@@ -62,7 +62,7 @@ class UnitMap:
self.airlifts: Dict[str, AirliftUnit] = {}
def add_aircraft(self, group: FlyingGroup, flight: Flight) -> None:
for pilot, unit in zip(flight.pilots, group.units):
for pilot, unit in zip(flight.roster.pilots, group.units):
# The actual name is a String (the pydcs translatable string), which
# doesn't define __eq__.
name = str(unit.name)