Add an option to prefer primary tasked aircraft.

We're still using mostly the same aircraft selection as we have before
we added squadrons: the closest aircraft is the best choice.

This adds an option to obey the primary task set by the campaign
designer (can be overridden by players), even if the squadron is farther
away than one that is capable of it as a secondary task.

I don't expect this option to live very long. I'm making it optional for
now to give people a chance to test it, but it'll either replace the old
selection strategy or will be removed.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1892.
This commit is contained in:
Dan Albert
2023-05-04 22:34:23 -07:00
committed by Raffson
parent e95a6bf759
commit f719e1cfe7
8 changed files with 116 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
from __future__ import annotations
from PySide6.QtWidgets import QComboBox
from game.ato import FlightType
from game.dcs.aircrafttype import AircraftType
from game.squadrons import Squadron
class PrimaryTaskSelector(QComboBox):
def __init__(self, aircraft: AircraftType | None) -> None:
super().__init__()
self.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
self.set_aircraft(aircraft)
@staticmethod
def for_squadron(squadron: Squadron) -> PrimaryTaskSelector:
selector = PrimaryTaskSelector(squadron.aircraft)
selector.setCurrentText(squadron.primary_task.value)
return selector
def set_aircraft(self, aircraft: AircraftType | None) -> None:
self.clear()
if aircraft is None:
self.addItem("Select aircraft type first", None)
self.setEnabled(False)
self.update()
return
self.setEnabled(True)
for task in aircraft.iter_task_capabilities():
self.addItem(task.value, task)
self.model().sort(0)
self.setEnabled(True)
self.update()
@property
def selected_task(self) -> FlightType | None:
return self.currentData()