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

@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import Optional, List, TYPE_CHECKING
from datetime import datetime, timedelta
from typing import Any, Optional, List, TYPE_CHECKING
from gen.flights.loadouts import Loadout
@@ -14,6 +15,7 @@ if TYPE_CHECKING:
from .flighttype import FlightType
from .flightwaypoint import FlightWaypoint
from .package import Package
from .starttype import StartType
class Flight:
@@ -24,7 +26,7 @@ class Flight:
squadron: Squadron,
count: int,
flight_type: FlightType,
start_type: str,
start_type: StartType,
divert: Optional[ControlPoint],
custom_name: Optional[str] = None,
cargo: Optional[TransferOrder] = None,

15
game/ato/starttype.py Normal file
View File

@@ -0,0 +1,15 @@
from enum import Enum, unique
@unique
class StartType(Enum):
"""The start type for a Flight.
This is distinct from dcs.mission.StartType because we need a fourth state:
IN_FLIGHT.
"""
IN_FLIGHT = "In Flight"
RUNWAY = "Runway"
COLD = "Cold"
WARM = "Warm"

View File

@@ -6,6 +6,7 @@ from game.utils import nautical_miles
from ..ato.package import Package
from game.theater import MissionTarget, OffMapSpawn, ControlPoint
from ..ato.flight import Flight
from ..ato.starttype import StartType
if TYPE_CHECKING:
from game.dcs.aircrafttype import AircraftType
@@ -24,7 +25,7 @@ class PackageBuilder:
air_wing: AirWing,
is_player: bool,
package_country: str,
start_type: str,
start_type: StartType,
asap: bool,
) -> None:
self.closest_airfields = closest_airfields

View File

@@ -13,6 +13,7 @@ from .choicesoption import choices_option
from .minutesoption import minutes_option
from .optiondescription import OptionDescription, SETTING_DESCRIPTION_KEY
from .skilloption import skill_option
from ..ato.starttype import StartType
@unique
@@ -323,12 +324,12 @@ class Settings:
"option only allows the player to wait on the ground.</strong>"
),
)
default_start_type: str = choices_option(
default_start_type: StartType = choices_option(
"Default start type for AI aircraft",
page=MISSION_GENERATOR_PAGE,
section=GAMEPLAY_SECTION,
choices=["Cold", "Warm", "Runway", "In Flight"],
default="Cold",
choices={v.value: v for v in StartType},
default=StartType.COLD,
detail=(
"Warning: Options other than Cold will significantly reduce the number of "
"targets available for OCA/Aircraft missions, and OCA/Aircraft flights "

View File

@@ -49,6 +49,7 @@ from .theatergroundobject import (
TheaterGroundObject,
BuildingGroundObject,
)
from ..ato.starttype import StartType
from ..dcs.aircrafttype import AircraftType
from ..dcs.groundunittype import GroundUnitType
from ..utils import nautical_miles
@@ -681,7 +682,7 @@ class ControlPoint(MissionTarget, ABC):
self.base.set_strength_to_minimum()
@property
def required_aircraft_start_type(self) -> Optional[str]:
def required_aircraft_start_type(self) -> Optional[StartType]:
return None
@abstractmethod
@@ -1151,8 +1152,8 @@ class OffMapSpawn(ControlPoint):
return True
@property
def required_aircraft_start_type(self) -> Optional[str]:
return "In Flight"
def required_aircraft_start_type(self) -> Optional[StartType]:
return StartType.IN_FLIGHT
@property
def heading(self) -> Heading:

View File

@@ -5,17 +5,16 @@ import logging
import random
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional, TYPE_CHECKING, Any
from typing import Optional, TYPE_CHECKING
from dcs.cloud_presets import Clouds as PydcsClouds
from dcs.weather import CloudPreset, Weather as PydcsWeather, Wind
from game.settings import Settings
from game.utils import Distance, Heading, meters, interpolate, Pressure, inches_hg
from game.theater.seasonalconditions import determine_season
if TYPE_CHECKING:
from game.settings import Settings
from game.theater import ConflictTheater
from game.theater.seasonalconditions import SeasonalConditions