mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Mission planning on a per-control point basis lacked the context it needed to make good decisions, and the ability to make larger missions that pulled aircraft from multiple airfields. The per-CP planners have been replaced in favor of a global planner per coalition. The planner generates a list of potential missions in order of priority and then allocates aircraft to the proposed flights until no missions remain. Mission planning behavior has changed: * CAP flights will now only be generated for airfields within a predefined threat range of an enemy airfield. * CAS, SEAD, and strike missions get escorts. Strike missions get a SEAD flight. * CAS, SEAD, and strike missions will not be planned unless they have an escort available. * Missions may originate from multiple airfields. There's more to do: * The range limitations imposed on the mission planner should take aircraft range limitations into account. * Air superiority aircraft like the F-15 should be preferred for CAP over multi-role aircraft like the F/A-18 since otherwise we run the risk of running out of ground attack capable aircraft even though there are still unused aircraft. * Mission priorities may need tuning. * Target areas could be analyzed for potential threats, allowing escort flights to be optional or omitted if there is no threat to defend against. For example, late game a SEAD flight for a strike mission probably is not necessary. * SAM threat should be judged by how close the extent of the SAM's range is to friendly locations, not the distance to the site itself. An SA-10 30 nm away is more threatening than an SA-6 25 nm away. * Much of the planning behavior should be factored out into the coalition's doctrine. But as-is this is an improvement over the existing behavior, so those things can be follow ups. The potential regression in behavior here is that we're no longer planning multiple cycles of missions. Each objective will get one CAP. I think this fits better with the turn cycle of the game, as a CAP flight should be able to remain on station for the duration of the turn (especially with refueling). Note that this does break save compatibility as the old planner was a part of the game object, and since that class is now gone it can't be unpickled.
107 lines
3.8 KiB
Python
107 lines
3.8 KiB
Python
import logging
|
|
from typing import Optional
|
|
|
|
from PySide2.QtCore import Qt, Signal
|
|
from PySide2.QtWidgets import (
|
|
QDialog,
|
|
QPushButton,
|
|
QVBoxLayout,
|
|
)
|
|
from dcs.planes import PlaneType
|
|
|
|
from game import Game
|
|
from gen.ato import Package
|
|
from gen.flights.flightplan import FlightPlanBuilder
|
|
from gen.flights.flight import Flight, FlightType
|
|
from qt_ui.uiconstants import EVENT_ICONS
|
|
from qt_ui.widgets.QFlightSizeSpinner import QFlightSizeSpinner
|
|
from qt_ui.widgets.QLabeledWidget import QLabeledWidget
|
|
from qt_ui.widgets.combos.QAircraftTypeSelector import QAircraftTypeSelector
|
|
from qt_ui.widgets.combos.QFlightTypeComboBox import QFlightTypeComboBox
|
|
from qt_ui.widgets.combos.QOriginAirfieldSelector import QOriginAirfieldSelector
|
|
from theater import ControlPoint, FrontLine, TheaterGroundObject
|
|
|
|
|
|
class QFlightCreator(QDialog):
|
|
created = Signal(Flight)
|
|
|
|
def __init__(self, game: Game, package: Package) -> None:
|
|
super().__init__()
|
|
|
|
self.game = game
|
|
self.package = package
|
|
|
|
self.planner = FlightPlanBuilder(self.game, is_player=True)
|
|
|
|
self.setWindowTitle("Create flight")
|
|
self.setWindowIcon(EVENT_ICONS["strike"])
|
|
|
|
layout = QVBoxLayout()
|
|
|
|
self.task_selector = QFlightTypeComboBox(
|
|
self.game.theater, self.package.target
|
|
)
|
|
self.task_selector.setCurrentIndex(0)
|
|
layout.addLayout(QLabeledWidget("Task:", self.task_selector))
|
|
|
|
self.aircraft_selector = QAircraftTypeSelector(
|
|
self.game.aircraft_inventory.available_types_for_player
|
|
)
|
|
self.aircraft_selector.setCurrentIndex(0)
|
|
self.aircraft_selector.currentIndexChanged.connect(
|
|
self.on_aircraft_changed)
|
|
layout.addLayout(QLabeledWidget("Aircraft:", self.aircraft_selector))
|
|
|
|
self.airfield_selector = QOriginAirfieldSelector(
|
|
self.game.aircraft_inventory,
|
|
[cp for cp in game.theater.controlpoints if cp.captured],
|
|
self.aircraft_selector.currentData()
|
|
)
|
|
layout.addLayout(QLabeledWidget("Airfield:", self.airfield_selector))
|
|
|
|
self.flight_size_spinner = QFlightSizeSpinner()
|
|
layout.addLayout(QLabeledWidget("Count:", self.flight_size_spinner))
|
|
|
|
layout.addStretch()
|
|
|
|
self.create_button = QPushButton("Create")
|
|
self.create_button.clicked.connect(self.create_flight)
|
|
layout.addWidget(self.create_button, alignment=Qt.AlignRight)
|
|
|
|
self.setLayout(layout)
|
|
|
|
def verify_form(self) -> Optional[str]:
|
|
aircraft: PlaneType = self.aircraft_selector.currentData()
|
|
origin: ControlPoint = self.airfield_selector.currentData()
|
|
size: int = self.flight_size_spinner.value()
|
|
if not origin.captured:
|
|
return f"{origin.name} is not owned by your coalition."
|
|
available = origin.base.aircraft.get(aircraft, 0)
|
|
if not available:
|
|
return f"{origin.name} has no {aircraft.id} available."
|
|
if size > available:
|
|
return f"{origin.name} has only {available} {aircraft.id} available."
|
|
return None
|
|
|
|
def create_flight(self) -> None:
|
|
error = self.verify_form()
|
|
if error is not None:
|
|
self.error_box("Could not create flight", error)
|
|
return
|
|
|
|
task = self.task_selector.currentData()
|
|
aircraft = self.aircraft_selector.currentData()
|
|
origin = self.airfield_selector.currentData()
|
|
size = self.flight_size_spinner.value()
|
|
|
|
flight = Flight(aircraft, size, origin, task)
|
|
self.planner.populate_flight_plan(flight, self.package.target)
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
self.created.emit(flight)
|
|
self.close()
|
|
|
|
def on_aircraft_changed(self, index: int) -> None:
|
|
new_aircraft = self.aircraft_selector.itemData(index)
|
|
self.airfield_selector.change_aircraft(new_aircraft)
|