Stagger package start times.

Avoids crowding the taxiways, and adds some life to the end of the
mission.

Later on, this will happen more naturally because we can delay
takeoffs to align with the package's DTOT.
This commit is contained in:
Dan Albert 2020-10-06 21:48:13 -07:00
parent 944748a0ac
commit e537396fec
3 changed files with 38 additions and 0 deletions

View File

@ -40,6 +40,8 @@ class Package:
#: The set of flights in the package. #: The set of flights in the package.
flights: List[Flight] = field(default_factory=list) flights: List[Flight] = field(default_factory=list)
delay: int = field(default=0)
join_point: Optional[Point] = field(default=None, init=False, hash=False) join_point: Optional[Point] = field(default=None, init=False, hash=False)
split_point: Optional[Point] = field(default=None, init=False, hash=False) split_point: Optional[Point] = field(default=None, init=False, hash=False)
ingress_point: Optional[Point] = field(default=None, init=False, hash=False) ingress_point: Optional[Point] = field(default=None, init=False, hash=False)

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
import random
import operator import operator
from dataclasses import dataclass from dataclasses import dataclass
from typing import Iterator, List, Optional, Set, TYPE_CHECKING, Tuple, Type from typing import Iterator, List, Optional, Set, TYPE_CHECKING, Tuple, Type
@ -384,6 +385,9 @@ class CoalitionMissionPlanner:
MAX_SEAD_RANGE = nm_to_meter(150) MAX_SEAD_RANGE = nm_to_meter(150)
MAX_STRIKE_RANGE = nm_to_meter(150) MAX_STRIKE_RANGE = nm_to_meter(150)
NON_CAP_MIN_DELAY = 1
NON_CAP_MAX_DELAY = 5
def __init__(self, game: Game, is_player: bool) -> None: def __init__(self, game: Game, is_player: bool) -> None:
self.game = game self.game = game
self.is_player = is_player self.is_player = is_player
@ -430,6 +434,8 @@ class CoalitionMissionPlanner:
for proposed_mission in self.propose_missions(): for proposed_mission in self.propose_missions():
self.plan_mission(proposed_mission) self.plan_mission(proposed_mission)
self.stagger_missions()
for cp in self.objective_finder.friendly_control_points(): for cp in self.objective_finder.friendly_control_points():
inventory = self.game.aircraft_inventory.for_control_point(cp) inventory = self.game.aircraft_inventory.for_control_point(cp)
for aircraft, available in inventory.all_aircraft: for aircraft, available in inventory.all_aircraft:
@ -467,6 +473,34 @@ class CoalitionMissionPlanner:
flight_plan_builder.populate_flight_plan(flight) flight_plan_builder.populate_flight_plan(flight)
self.ato.add_package(package) self.ato.add_package(package)
def stagger_missions(self) -> None:
def start_time_generator(count: int, earliest: int, latest: int,
margin: int) -> Iterator[int]:
interval = latest // count
for time in range(earliest, latest, interval):
error = random.randint(-margin, margin)
yield max(0, time + error)
dca_types = (
FlightType.BARCAP,
FlightType.CAP,
FlightType.INTERCEPTION,
)
non_dca_packages = [p for p in self.ato.packages if
p.primary_task not in dca_types]
start_time = start_time_generator(
count=len(non_dca_packages),
earliest=5,
latest=90,
margin=5
)
for package in non_dca_packages:
package.delay = next(start_time)
for flight in package.flights:
flight.scheduled_in = package.delay
def message(self, title, text) -> None: def message(self, title, text) -> None:
"""Emits a planning message to the player. """Emits a planning message to the player.

View File

@ -27,6 +27,7 @@ class QFlightCreator(QDialog):
super().__init__() super().__init__()
self.game = game self.game = game
self.package = package
self.setWindowTitle("Create flight") self.setWindowTitle("Create flight")
self.setWindowIcon(EVENT_ICONS["strike"]) self.setWindowIcon(EVENT_ICONS["strike"])
@ -90,6 +91,7 @@ class QFlightCreator(QDialog):
size = self.flight_size_spinner.value() size = self.flight_size_spinner.value()
flight = Flight(aircraft, size, origin, task) flight = Flight(aircraft, size, origin, task)
flight.scheduled_in = self.package.delay
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
self.created.emit(flight) self.created.emit(flight)