Clean up aircraft allocation and procurement.

This also does improve the over-purchase problems, though I can't spot
the behavior change that's causing that. Presumably the old
implementation had a bug I can't spot and in rewriting it I solved the
problem...

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1582
This commit is contained in:
Dan Albert
2021-09-03 15:09:48 -07:00
parent 94fb0d8c66
commit ab2bb6814e
6 changed files with 76 additions and 132 deletions

View File

@@ -1,16 +1,20 @@
from typing import Optional
from __future__ import annotations
from typing import Optional, TYPE_CHECKING
from game.commander.aircraftallocator import AircraftAllocator
from game.commander.missionproposals import ProposedFlight
from game.dcs.aircrafttype import AircraftType
from game.squadrons.airwing import AirWing
from game.theater import MissionTarget, OffMapSpawn, ControlPoint
from game.utils import nautical_miles
from gen.ato import Package
from gen.flights.closestairfields import ClosestAirfields
from game.theater import MissionTarget, OffMapSpawn, ControlPoint
from gen.flights.flight import Flight
if TYPE_CHECKING:
from game.dcs.aircrafttype import AircraftType
from game.squadrons.airwing import AirWing
from gen.flights.closestairfields import ClosestAirfields
from .missionproposals import ProposedFlight
class PackageBuilder:
"""Builds a Package for the flights it receives."""
@@ -28,7 +32,7 @@ class PackageBuilder:
self.is_player = is_player
self.package_country = package_country
self.package = Package(location, auto_asap=asap)
self.allocator = AircraftAllocator(air_wing, closest_airfields, is_player)
self.air_wing = air_wing
self.start_type = start_type
def plan_flight(self, plan: ProposedFlight) -> bool:
@@ -39,11 +43,12 @@ class PackageBuilder:
caller should return any previously planned flights to the inventory
using release_planned_aircraft.
"""
assignment = self.allocator.find_squadron_for_flight(self.package.target, plan)
if assignment is None:
squadron = self.air_wing.best_squadron_for(
self.package.target, plan.task, plan.num_aircraft, this_turn=True
)
if squadron is None:
return False
airfield, squadron = assignment
start_type = airfield.required_aircraft_start_type
start_type = squadron.location.required_aircraft_start_type
if start_type is None:
start_type = self.start_type
@@ -54,7 +59,7 @@ class PackageBuilder:
plan.num_aircraft,
plan.task,
start_type,
divert=self.find_divert_field(squadron.aircraft, airfield),
divert=self.find_divert_field(squadron.aircraft, squadron.location),
)
self.package.add_flight(flight)
return True