Improve the optional unit handling in layouts

added the fill property to the layout groups which allows to specify if a optional layout group should be filled with a faction accessible unit if it was not defined by the preset groups. This is usefull to allow more generalized templates which for example may or may not have a Search Radar without adding one to all layouts (example: Rapier and Roland Sites which use the generic SHORAD layout)

this fixes an issue which prevented optional units like logistics to be added to the forcegroup if they were not defined in the preset group yaml
This commit is contained in:
RndName
2022-03-21 20:17:17 +01:00
parent 923549ef69
commit 4ace13c857
9 changed files with 51 additions and 3 deletions

View File

@@ -62,6 +62,8 @@ class ForceGroup:
units: set[UnitType[Any]] = set()
statics: set[Type[DcsUnitType]] = set()
for group in layout.all_groups:
if group.optional and not group.fill:
continue
for unit_type in group.possible_types_for_faction(faction):
if issubclass(unit_type, VehicleType):
units.add(next(GroundUnitType.for_dcs_type(unit_type)))
@@ -81,6 +83,36 @@ class ForceGroup:
def __str__(self) -> str:
return self.name
def has_unit_for_layout_group(self, group: TgoLayoutGroup) -> bool:
for unit in self.units:
if (
unit.dcs_unit_type in group.unit_types
or unit.unit_class in group.unit_classes
):
return True
return False
@classmethod
def for_faction_by_name(cls, name: str, faction: Faction) -> ForceGroup:
"""Load a PresetGroup as ForceGroup with faction sensitive handling"""
force_group = cls.named(name)
for layout in force_group.layouts:
for groups in layout.groups.values():
for group in groups:
if group.fill and not force_group.has_unit_for_layout_group(group):
for unit_type in group.possible_types_for_faction(faction):
if issubclass(unit_type, VehicleType):
force_group.units.append(
next(GroundUnitType.for_dcs_type(unit_type))
)
elif issubclass(unit_type, ShipType):
force_group.units.append(
next(ShipUnitType.for_dcs_type(unit_type))
)
elif issubclass(unit_type, StaticType):
force_group.statics.append(unit_type)
return force_group
@classmethod
def named(cls, name: str) -> ForceGroup:
if not cls._loaded: