mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Merge pull request #2002 from dcs-liberation/fix_issue_1966
Fix issue 1966
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_percentage: 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_percentage", None),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from typing import Optional, TYPE_CHECKING, Dict, Union
|
||||
|
||||
from game.squadrons import Squadron
|
||||
from game.squadrons.squadrondef import SquadronDef
|
||||
@@ -29,7 +30,12 @@ class DefaultSquadronAssigner:
|
||||
self.coalition.player
|
||||
):
|
||||
for squadron_config in self.config.by_location[control_point]:
|
||||
squadron_def = self.find_squadron_for(squadron_config, control_point)
|
||||
|
||||
squadron_def = self.override_squadron_defaults(
|
||||
self.find_squadron_for(squadron_config, control_point),
|
||||
squadron_config,
|
||||
)
|
||||
|
||||
if squadron_def is None:
|
||||
logging.info(
|
||||
f"{self.coalition.faction.name} has no aircraft compatible "
|
||||
@@ -48,6 +54,7 @@ class DefaultSquadronAssigner:
|
||||
def find_squadron_for(
|
||||
self, config: SquadronConfig, control_point: ControlPoint
|
||||
) -> Optional[SquadronDef]:
|
||||
|
||||
for preferred_aircraft in config.aircraft:
|
||||
squadron_def = self.find_preferred_squadron(
|
||||
preferred_aircraft, config.primary, control_point
|
||||
@@ -142,3 +149,21 @@ class DefaultSquadronAssigner:
|
||||
):
|
||||
return squadron
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def override_squadron_defaults(
|
||||
squadron_def: Optional[SquadronDef], config: SquadronConfig
|
||||
) -> Optional[SquadronDef]:
|
||||
|
||||
if squadron_def is None:
|
||||
return None
|
||||
|
||||
overrides: Dict[str, Union[str, int]] = {}
|
||||
if config.name is not None:
|
||||
overrides["name"] = config.name
|
||||
if config.nickname is not None:
|
||||
overrides["nickname"] = config.nickname
|
||||
if config.female_pilot_percentage is not None:
|
||||
overrides["female_pilot_percentage"] = config.female_pilot_percentage
|
||||
|
||||
return dataclasses.replace(squadron_def, **overrides)
|
||||
|
||||
@@ -50,6 +50,7 @@ class SquadronDefGenerator:
|
||||
livery=None,
|
||||
mission_types=tuple(tasks_for_aircraft(aircraft)),
|
||||
operating_bases=OperatingBases.default_for_aircraft(aircraft),
|
||||
female_pilot_percentage=6,
|
||||
pilot_pool=[],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import random
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional, Sequence, TYPE_CHECKING
|
||||
@@ -32,6 +33,7 @@ class Squadron:
|
||||
livery: Optional[str]
|
||||
mission_types: tuple[FlightType, ...]
|
||||
operating_bases: OperatingBases
|
||||
female_pilot_percentage: int
|
||||
|
||||
#: The pool of pilots that have not yet been assigned to the squadron. This only
|
||||
#: happens when a preset squadron defines more preset pilots than the squadron limit
|
||||
@@ -159,7 +161,11 @@ class Squadron:
|
||||
new_pilots = self.pilot_pool[:count]
|
||||
self.pilot_pool = self.pilot_pool[count:]
|
||||
count -= len(new_pilots)
|
||||
new_pilots.extend([Pilot(self.faker.name()) for _ in range(count)])
|
||||
for _ in range(count):
|
||||
if random.randint(1, 100) > self.female_pilot_percentage:
|
||||
new_pilots.append(Pilot(self.faker.name_male()))
|
||||
else:
|
||||
new_pilots.append(Pilot(self.faker.name_female()))
|
||||
self.current_roster.extend(new_pilots)
|
||||
self.available_pilots.extend(new_pilots)
|
||||
|
||||
@@ -428,6 +434,7 @@ class Squadron:
|
||||
squadron_def.livery,
|
||||
squadron_def.mission_types,
|
||||
squadron_def.operating_bases,
|
||||
squadron_def.female_pilot_percentage,
|
||||
squadron_def.pilot_pool,
|
||||
coalition,
|
||||
game.settings,
|
||||
|
||||
@@ -27,6 +27,7 @@ class SquadronDef:
|
||||
livery: Optional[str]
|
||||
mission_types: tuple[FlightType, ...]
|
||||
operating_bases: OperatingBases
|
||||
female_pilot_percentage: int
|
||||
pilot_pool: list[Pilot]
|
||||
claimed: bool = False
|
||||
|
||||
@@ -75,6 +76,7 @@ class SquadronDef:
|
||||
|
||||
pilots = [Pilot(n, player=False) for n in data.get("pilots", [])]
|
||||
pilots.extend([Pilot(n, player=True) for n in data.get("players", [])])
|
||||
female_pilot_percentage = data.get("female_pilot_percentage", 6)
|
||||
|
||||
mission_types = [FlightType.from_name(n) for n in data["mission_types"]]
|
||||
tasks = tasks_for_aircraft(unit_type)
|
||||
@@ -95,5 +97,6 @@ class SquadronDef:
|
||||
livery=data.get("livery"),
|
||||
mission_types=tuple(mission_types),
|
||||
operating_bases=OperatingBases.from_yaml(unit_type, data.get("bases", {})),
|
||||
female_pilot_percentage=female_pilot_percentage,
|
||||
pilot_pool=pilots,
|
||||
)
|
||||
|
||||
@@ -123,4 +123,9 @@ VERSION = _build_version_string()
|
||||
#: Version 9.1
|
||||
#: * Campaign files can optionally define a start date with
|
||||
#: `recommended_start_date: YYYY-MM-DD`.
|
||||
CAMPAIGN_FORMAT_VERSION = (9, 1)
|
||||
#:
|
||||
#: Version 9.2
|
||||
#: * Squadrons defined in campaign files can optionally setup squadrons' name,
|
||||
#: nickname and/or generated female pilot name percentage
|
||||
#:
|
||||
CAMPAIGN_FORMAT_VERSION = (9, 2)
|
||||
|
||||
Reference in New Issue
Block a user