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.
flights: List[Flight] = field(default_factory=list)
delay: int = field(default=0)
join_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)

View File

@ -1,6 +1,7 @@
from __future__ import annotations
import logging
import random
import operator
from dataclasses import dataclass
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_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:
self.game = game
self.is_player = is_player
@ -430,6 +434,8 @@ class CoalitionMissionPlanner:
for proposed_mission in self.propose_missions():
self.plan_mission(proposed_mission)
self.stagger_missions()
for cp in self.objective_finder.friendly_control_points():
inventory = self.game.aircraft_inventory.for_control_point(cp)
for aircraft, available in inventory.all_aircraft:
@ -467,6 +473,34 @@ class CoalitionMissionPlanner:
flight_plan_builder.populate_flight_plan(flight)
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:
"""Emits a planning message to the player.

View File

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