diff --git a/gen/aircraft.py b/gen/aircraft.py index fa233d2e..bcbd0be1 100644 --- a/gen/aircraft.py +++ b/gen/aircraft.py @@ -751,6 +751,16 @@ class AircraftConflictGenerator: new_level = min(current_level + increase, len(levels) - 1) return levels[new_level] + def set_skill(self, unit: FlyingUnit, pilot: Optional[Pilot], blue: bool) -> None: + if pilot is None or not pilot.player: + unit.skill = self.skill_level_for(unit, pilot, blue) + return + + if self.use_client: + unit.set_client() + else: + unit.set_player() + def _setup_group( self, group: FlyingGroup, @@ -777,29 +787,17 @@ class AircraftConflictGenerator: for unit_instance in group.units: unit_instance.livery_id = livery - num_clients = min(len(group.units), flight.client_count) - for idx in range(0, num_clients): - unit = group.units[idx] - if self.use_client: - unit.set_client() - else: - unit.set_player() - + for unit, pilot in zip(group.units, flight.pilots): + player = pilot is not None and pilot.player + self.set_skill(unit, pilot, blue=flight.departure.captured) # Do not generate player group with late activation. - if group.late_activation: + if player and group.late_activation: group.late_activation = False # Set up F-14 Client to have pre-stored alignment if unit_type is F_14B: unit.set_property(F_14B.Properties.INSAlignmentStored.id, True) - for idx in range(num_clients, len(group.units)): - unit = group.units[idx] - pilot = flight.pilots[idx] - unit.skill = self.skill_level_for( - unit, pilot, blue=flight.departure.captured - ) - group.points[0].tasks.append( OptReactOnThreat(OptReactOnThreat.Values.EvadeFire) ) diff --git a/gen/flights/flight.py b/gen/flights/flight.py index 53a4b16f..7270d329 100644 --- a/gen/flights/flight.py +++ b/gen/flights/flight.py @@ -228,7 +228,6 @@ class Flight: self.loadout = Loadout.default_for(self) self.start_type = start_type self.use_custom_loadout = False - self.client_count = 0 self.custom_name = custom_name # Only used by transport missions. @@ -247,6 +246,10 @@ class Flight: def count(self) -> int: return len(self.pilots) + @property + def client_count(self) -> int: + return len([p for p in self.pilots if p is not None and p.player]) + @property def unit_type(self) -> Type[FlyingType]: return self.squadron.aircraft diff --git a/qt_ui/windows/mission/flight/settings/QFlightSlotEditor.py b/qt_ui/windows/mission/flight/settings/QFlightSlotEditor.py index c96b05b5..0223c06f 100644 --- a/qt_ui/windows/mission/flight/settings/QFlightSlotEditor.py +++ b/qt_ui/windows/mission/flight/settings/QFlightSlotEditor.py @@ -4,6 +4,7 @@ from PySide2.QtCore import Signal, QModelIndex from PySide2.QtWidgets import QLabel, QGroupBox, QSpinBox, QGridLayout, QComboBox from game import Game +from game.squadrons import Pilot from gen.flights.flight import Flight from qt_ui.models import PackageModel @@ -18,6 +19,12 @@ class PilotSelector(QComboBox): self.rebuild(initial_build=True) + @staticmethod + def text_for(pilot: Pilot) -> str: + if pilot.player: + return f"{pilot.name} (player)" + return pilot.name + def _do_rebuild(self) -> None: self.clear() if self.pilot_index >= self.flight.count: @@ -31,12 +38,13 @@ class PilotSelector(QComboBox): current_pilot = self.flight.pilots[self.pilot_index] if current_pilot is not None: choices.append(current_pilot) - for pilot in sorted(choices, key=lambda p: p.name): - self.addItem(pilot.name, pilot) + # Put players first, otherwise alphabetically. + for pilot in sorted(choices, key=lambda p: (not p.player, p.name)): + self.addItem(self.text_for(pilot), pilot) if current_pilot is None: self.setCurrentText("Unassigned") return - self.setCurrentText(current_pilot.name) + self.setCurrentText(self.text_for(current_pilot)) self.currentIndexChanged.connect(self.replace_pilot) def rebuild(self, initial_build: bool = False) -> None: @@ -90,29 +98,15 @@ class QFlightSlotEditor(QGroupBox): self.aircraft_count_spinner.setValue(flight.count) self.aircraft_count_spinner.valueChanged.connect(self._changed_aircraft_count) - self.client_count = QLabel("Client slots count:") - self.client_count_spinner = QSpinBox() - self.client_count_spinner.setMinimum(0) - self.client_count_spinner.setMaximum(max_count) - self.client_count_spinner.setValue(flight.client_count) - self.client_count_spinner.valueChanged.connect(self._changed_client_count) - - if not self.flight.unit_type.flyable: - self.client_count_spinner.setValue(0) - self.client_count_spinner.setEnabled(False) - layout.addWidget(self.aircraft_count, 0, 0) layout.addWidget(self.aircraft_count_spinner, 0, 1) - layout.addWidget(self.client_count, 1, 0) - layout.addWidget(self.client_count_spinner, 1, 1) + layout.addWidget(QLabel("Squadron:"), 1, 0) + layout.addWidget(QLabel(self.flight.squadron.name), 1, 1) - layout.addWidget(QLabel("Squadron:"), 2, 0) - layout.addWidget(QLabel(self.flight.squadron.name), 2, 1) - - layout.addWidget(QLabel("Assigned pilots:"), 3, 0) + layout.addWidget(QLabel("Assigned pilots:"), 2, 0) self.pilot_selectors = [] - for pilot_idx, row in enumerate(range(3, 7)): + for pilot_idx, row in enumerate(range(2, 6)): selector = PilotSelector(self.flight, pilot_idx) selector.available_pilots_changed.connect(self.reset_pilot_selectors) self.pilot_selectors.append(selector) @@ -143,15 +137,4 @@ class QFlightSlotEditor(QGroupBox): return self.flight.resize(new_count) - self._cap_client_count() self.reset_pilot_selectors() - - def _changed_client_count(self): - self.flight.client_count = int(self.client_count_spinner.value()) - self._cap_client_count() - self.package_model.update_tot() - - def _cap_client_count(self): - if self.flight.client_count > self.flight.count: - self.flight.client_count = self.flight.count - self.client_count_spinner.setValue(self.flight.client_count)