mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
#1966 : Added female_pilot_ratio param in squadrons. Also possible to force name or nickname for squadrons in campaign yaml files.
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, TYPE_CHECKING, Union
|
||||
from typing import Any, TYPE_CHECKING, Union, Optional
|
||||
|
||||
from game.ato.flighttype import FlightType
|
||||
from game.theater.controlpoint import ControlPoint
|
||||
@@ -18,6 +18,10 @@ class SquadronConfig:
|
||||
secondary: list[FlightType]
|
||||
aircraft: list[str]
|
||||
|
||||
name: Optional[str]
|
||||
nickname: Optional[str]
|
||||
female_pilot_ratio: Optional[int]
|
||||
|
||||
@property
|
||||
def auto_assignable(self) -> set[FlightType]:
|
||||
return set(self.secondary) | {self.primary}
|
||||
@@ -33,7 +37,12 @@ class SquadronConfig:
|
||||
secondary = [FlightType(s) for s in secondary_raw]
|
||||
|
||||
return SquadronConfig(
|
||||
FlightType(data["primary"]), secondary, data.get("aircraft", [])
|
||||
FlightType(data["primary"]),
|
||||
secondary,
|
||||
data.get("aircraft", []),
|
||||
data.get("name", None),
|
||||
data.get("nickname", None),
|
||||
data.get("female_pilot_ratio", None),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
@@ -48,24 +49,41 @@ class DefaultSquadronAssigner:
|
||||
def find_squadron_for(
|
||||
self, config: SquadronConfig, control_point: ControlPoint
|
||||
) -> Optional[SquadronDef]:
|
||||
squadron_def = None
|
||||
for preferred_aircraft in config.aircraft:
|
||||
squadron_def = self.find_preferred_squadron(
|
||||
preferred_aircraft, config.primary, control_point
|
||||
)
|
||||
if squadron_def is not None:
|
||||
return squadron_def
|
||||
break
|
||||
|
||||
# If we didn't find any of the preferred types we should use any squadron
|
||||
# compatible with the primary task.
|
||||
squadron_def = self.find_squadron_for_task(config.primary, control_point)
|
||||
if squadron_def is not None:
|
||||
return squadron_def
|
||||
if squadron_def is None:
|
||||
squadron_def = self.find_squadron_for_task(config.primary, control_point)
|
||||
|
||||
# If we can't find any squadron matching the requirement, we should
|
||||
# create one.
|
||||
return self.air_wing.squadron_def_generator.generate_for_task(
|
||||
config.primary, control_point
|
||||
)
|
||||
if squadron_def is None:
|
||||
squadron_def = self.air_wing.squadron_def_generator.generate_for_task(
|
||||
config.primary, control_point
|
||||
)
|
||||
|
||||
# Override squadron def with squadron config parameters from campaign file, if defined
|
||||
if squadron_def is not None:
|
||||
|
||||
overrides = {}
|
||||
if config.name is not None:
|
||||
overrides["name"] = config.name
|
||||
if config.nickname is not None:
|
||||
overrides["nickname"] = config.nickname
|
||||
if config.female_pilot_ratio is not None:
|
||||
overrides["female_pilot_ratio"] = config.female_pilot_ratio
|
||||
|
||||
squadron_copy = dataclasses.replace(squadron_def, **overrides)
|
||||
return squadron_copy
|
||||
else:
|
||||
return None
|
||||
|
||||
def find_preferred_squadron(
|
||||
self, preferred_aircraft: str, task: FlightType, control_point: ControlPoint
|
||||
|
||||
@@ -50,6 +50,7 @@ class SquadronDefGenerator:
|
||||
livery=None,
|
||||
mission_types=tuple(tasks_for_aircraft(aircraft)),
|
||||
operating_bases=OperatingBases.default_for_aircraft(aircraft),
|
||||
female_pilot_ratio=6,
|
||||
pilot_pool=[],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user