Build a proper type for StartType.

This commit is contained in:
Dan Albert
2021-10-22 11:29:40 -07:00
parent be69d17345
commit b0787d9a3f
8 changed files with 65 additions and 40 deletions

View File

@@ -14,7 +14,7 @@ from dcs.condition import CoalitionHasAirdrome, TimeAfter
from dcs.country import Country
from dcs.flyingunit import FlyingUnit
from dcs.mapping import Point
from dcs.mission import Mission, StartType
from dcs.mission import Mission, StartType as DcsStartType
from dcs.planes import (
AJS37,
B_17G,
@@ -67,6 +67,7 @@ from dcs.unitgroup import FlyingGroup, ShipGroup, StaticGroup
from dcs.unittype import FlyingType
from game import db
from game.ato.starttype import StartType
from game.data.weapons import Pylon, WeaponType as WeaponTypeEnum
from game.dcs.aircrafttype import AircraftType
from game.factions.faction import Faction
@@ -258,19 +259,19 @@ class AircraftConflictGenerator:
return total
@staticmethod
def _start_type(start_type: str) -> StartType:
def _start_type(start_type: str) -> DcsStartType:
if start_type == "Runway":
return StartType.Runway
return DcsStartType.Runway
elif start_type == "Cold":
return StartType.Cold
return StartType.Warm
return DcsStartType.Cold
return DcsStartType.Warm
@staticmethod
def _start_type_at_group(
start_type: str,
unit_type: Type[FlyingType],
at: Union[ShipGroup, StaticGroup],
) -> StartType:
) -> DcsStartType:
group_units = at.units
# Setting Su-33s starting from the non-supercarrier Kuznetsov to take off from runway
# to work around a DCS AI issue preventing Su-33s from taking off when set to "Takeoff from ramp" (#1352)
@@ -279,7 +280,7 @@ class AircraftConflictGenerator:
and group_units[0] is not None
and group_units[0].type == KUZNECOW.id
):
return StartType.Runway
return DcsStartType.Runway
else:
return AircraftConflictGenerator._start_type(start_type)
@@ -490,7 +491,7 @@ class AircraftConflictGenerator:
parking_slots=None,
)
def _generate_inflight(
def _generate_over_departure(
self, name: str, side: Country, flight: Flight, origin: ControlPoint
) -> FlyingGroup[Any]:
assert flight.count > 0
@@ -652,7 +653,7 @@ class AircraftConflictGenerator:
continue
for flight in package.flights:
logging.info(f"Generating flight: {flight.unit_type}")
group = self.generate_planned_flight(flight.from_cp, country, flight)
group = self.generate_planned_flight(country, flight)
self.unit_map.add_aircraft(group, flight)
self.setup_flight_group(group, package, flight, dynamic_runways)
self.create_waypoints(group, package, flight)
@@ -691,7 +692,7 @@ class AircraftConflictGenerator:
squadron,
1,
FlightType.BARCAP,
"Cold",
StartType.COLD,
divert=None,
)
@@ -753,14 +754,14 @@ class AircraftConflictGenerator:
coalition = self.game.coalition_for(flight.departure.captured).coalition_id
trigger.add_condition(CoalitionHasAirdrome(coalition, flight.from_cp.id))
def generate_planned_flight(
self, cp: ControlPoint, country: Country, flight: Flight
def generate_flight_at_departure(
self, country: Country, flight: Flight, start_type: StartType
) -> FlyingGroup[Any]:
name = namegen.next_aircraft_name(country, cp.id, flight)
group: FlyingGroup[Any]
name = namegen.next_aircraft_name(country, flight.departure.id, flight)
cp = flight.departure
try:
if flight.start_type == "In Flight":
group = self._generate_inflight(
if start_type is StartType.IN_FLIGHT:
group = self._generate_over_departure(
name=name, side=country, flight=flight, origin=cp
)
return group
@@ -777,7 +778,7 @@ class AircraftConflictGenerator:
side=country,
unit_type=flight.unit_type.dcs_unit_type,
count=flight.count,
start_type=flight.start_type,
start_type=start_type.value,
at=carrier_group,
)
else:
@@ -788,7 +789,7 @@ class AircraftConflictGenerator:
side=country,
unit_type=flight.unit_type.dcs_unit_type,
count=flight.count,
start_type=flight.start_type,
start_type=start_type.value,
cp=cp,
)
@@ -801,22 +802,26 @@ class AircraftConflictGenerator:
side=country,
unit_type=flight.unit_type.dcs_unit_type,
count=flight.count,
start_type=flight.start_type,
start_type=start_type.value,
airport=cp.airport,
)
except Exception as e:
except NoParkingSlotError:
# Generated when there is no place on Runway or on Parking Slots
logging.error(e)
logging.warning(
logging.exception(
"No room on runway or parking slots. Starting from the air."
)
flight.start_type = "In Flight"
group = self._generate_inflight(
flight.start_type = StartType.IN_FLIGHT
group = self._generate_over_departure(
name=name, side=country, flight=flight, origin=cp
)
group.points[0].alt = 1500
return group
def generate_planned_flight(
self, country: Country, flight: Flight
) -> FlyingGroup[Any]:
return self.generate_flight_at_departure(country, flight, flight.start_type)
@staticmethod
def set_reduced_fuel(
flight: Flight, group: FlyingGroup[Any], unit_type: Type[FlyingType]
@@ -1360,7 +1365,7 @@ class AircraftConflictGenerator:
# Late activation causes the aircraft to not be spawned
# until triggered.
self.set_activation_time(flight, group, start_time)
elif flight.start_type == "Cold":
elif flight.start_type is StartType.COLD:
# Setting the start time causes the AI to wait until the
# specified time to begin their startup sequence.
self.set_startup_time(flight, group, start_time)
@@ -1374,7 +1379,7 @@ class AircraftConflictGenerator:
@staticmethod
def should_activate_late(flight: Flight) -> bool:
if flight.start_type != "Cold":
if flight.start_type is StartType.COLD:
# Avoid spawning aircraft in the air or on the runway until it's
# time for their mission. Also avoid burning through gas spawning
# hot aircraft hours before their takeoff time.

View File

@@ -19,6 +19,7 @@ from dcs.mapping import Point
from dcs.unit import Unit
from shapely.geometry import Point as ShapelyPoint
from game.ato.starttype import StartType
from game.data.doctrine import Doctrine
from game.dcs.aircrafttype import FuelConsumption
from game.flightplan import IpZoneGeometry, JoinZoneGeometry, HoldZoneGeometry
@@ -275,7 +276,7 @@ class FlightPlan:
return start_time
def estimate_startup(self) -> timedelta:
if self.flight.start_type == "Cold":
if self.flight.start_type is StartType.COLD:
if self.flight.client_count:
return timedelta(minutes=10)
else:
@@ -284,7 +285,7 @@ class FlightPlan:
return timedelta()
def estimate_ground_ops(self) -> timedelta:
if self.flight.start_type in ("Runway", "In Flight"):
if self.flight.start_type in {StartType.RUNWAY, StartType.IN_FLIGHT}:
return timedelta()
if self.flight.from_cp.is_fleet:
return timedelta(minutes=2)