mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Fix #1966 : Refactored squadron default overrides in dedicated function
This commit is contained in:
parent
dc0562b3be
commit
61c1d12a86
@ -30,7 +30,12 @@ class DefaultSquadronAssigner:
|
|||||||
self.coalition.player
|
self.coalition.player
|
||||||
):
|
):
|
||||||
for squadron_config in self.config.by_location[control_point]:
|
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:
|
if squadron_def is None:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"{self.coalition.faction.name} has no aircraft compatible "
|
f"{self.coalition.faction.name} has no aircraft compatible "
|
||||||
@ -49,42 +54,26 @@ class DefaultSquadronAssigner:
|
|||||||
def find_squadron_for(
|
def find_squadron_for(
|
||||||
self, config: SquadronConfig, control_point: ControlPoint
|
self, config: SquadronConfig, control_point: ControlPoint
|
||||||
) -> Optional[SquadronDef]:
|
) -> Optional[SquadronDef]:
|
||||||
squadron_def = None
|
|
||||||
for preferred_aircraft in config.aircraft:
|
for preferred_aircraft in config.aircraft:
|
||||||
squadron_def = self.find_preferred_squadron(
|
squadron_def = self.find_preferred_squadron(
|
||||||
preferred_aircraft, config.primary, control_point
|
preferred_aircraft, config.primary, control_point
|
||||||
)
|
)
|
||||||
if squadron_def is not None:
|
if squadron_def is not None:
|
||||||
break
|
return squadron_def
|
||||||
|
|
||||||
# If we didn't find any of the preferred types we should use any squadron
|
# If we didn't find any of the preferred types we should use any squadron
|
||||||
# compatible with the primary task.
|
# compatible with the primary task.
|
||||||
if squadron_def is None:
|
|
||||||
squadron_def = self.find_squadron_for_task(config.primary, control_point)
|
squadron_def = self.find_squadron_for_task(config.primary, control_point)
|
||||||
|
if squadron_def is not None:
|
||||||
|
return squadron_def
|
||||||
|
|
||||||
# If we can't find any squadron matching the requirement, we should
|
# If we can't find any squadron matching the requirement, we should
|
||||||
# create one.
|
# create one.
|
||||||
if squadron_def is None:
|
return self.air_wing.squadron_def_generator.generate_for_task(
|
||||||
squadron_def = self.air_wing.squadron_def_generator.generate_for_task(
|
|
||||||
config.primary, control_point
|
config.primary, control_point
|
||||||
)
|
)
|
||||||
|
|
||||||
# Override squadron def with squadron config parameters from campaign file, if defined
|
|
||||||
if squadron_def is not 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
|
|
||||||
|
|
||||||
squadron_copy = dataclasses.replace(squadron_def, **overrides)
|
|
||||||
return squadron_copy
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def find_preferred_squadron(
|
def find_preferred_squadron(
|
||||||
self, preferred_aircraft: str, task: FlightType, control_point: ControlPoint
|
self, preferred_aircraft: str, task: FlightType, control_point: ControlPoint
|
||||||
) -> Optional[SquadronDef]:
|
) -> Optional[SquadronDef]:
|
||||||
@ -160,3 +149,21 @@ class DefaultSquadronAssigner:
|
|||||||
):
|
):
|
||||||
return squadron
|
return squadron
|
||||||
return None
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user