Selectable aircraft type in AutoCreateDialog

Resolves #165
This commit is contained in:
Raffson
2024-02-25 00:38:17 +01:00
parent b737f4e00c
commit e36e213b76
5 changed files with 103 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ from enum import Enum, auto
from typing import Optional
from game.ato.flighttype import FlightType
from game.dcs.aircrafttype import AircraftType
from game.theater import MissionTarget
@@ -33,6 +34,8 @@ class ProposedFlight:
#: field is None.
escort_type: Optional[EscortType] = field(default=None)
preferred_type: Optional[AircraftType] = field(default=None)
def __str__(self) -> str:
return f"{self.task} {self.num_aircraft} ship"

View File

@@ -49,7 +49,12 @@ class PackageBuilder:
pf = self.package.primary_flight
heli = pf.is_helo if pf else False
squadron = self.air_wing.best_squadron_for(
self.package.target, plan.task, plan.num_aircraft, heli, this_turn=True
self.package.target,
plan.task,
plan.num_aircraft,
heli,
this_turn=True,
preferred_type=plan.preferred_type,
)
if squadron is None:
return False

View File

@@ -51,6 +51,7 @@ class AirWing:
size: int,
heli: bool,
this_turn: bool,
preferred_type: Optional[AircraftType] = None,
) -> list[Squadron]:
airfield_cache = ObjectiveDistanceCache.get_closest_airfields(location)
best_aircraft = AircraftType.priority_list_for_task(task)
@@ -59,7 +60,13 @@ class AirWing:
if control_point.captured != self.player:
continue
capable_at_base = []
for squadron in control_point.squadrons:
squadrons = [
s
for s in control_point.squadrons
if not preferred_type
or s.aircraft.variant_id == preferred_type.variant_id
]
for squadron in squadrons:
if squadron.can_auto_assign_mission(
location, task, size, heli, this_turn
):
@@ -92,8 +99,11 @@ class AirWing:
size: int,
heli: bool,
this_turn: bool,
preferred_type: Optional[AircraftType] = None,
) -> Optional[Squadron]:
for squadron in self.best_squadrons_for(location, task, size, heli, this_turn):
for squadron in self.best_squadrons_for(
location, task, size, heli, this_turn, preferred_type
):
return squadron
return None