mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix ForceGroup merging and PresetGroup handling
This commit is contained in:
parent
d0fe058a24
commit
892bd9f069
@ -28,7 +28,7 @@ class ArmedForces:
|
|||||||
for force_group in self.forces:
|
for force_group in self.forces:
|
||||||
if force_group.tasks == new_group.tasks:
|
if force_group.tasks == new_group.tasks:
|
||||||
# Update existing group if tasks are equal
|
# Update existing group if tasks are equal
|
||||||
force_group.update_group(new_group)
|
force_group.merge_group(new_group)
|
||||||
return
|
return
|
||||||
# Add a new force group
|
# Add a new force group
|
||||||
self.forces.append(new_group)
|
self.forces.append(new_group)
|
||||||
@ -38,7 +38,10 @@ class ArmedForces:
|
|||||||
This will create a ForceGroup for each generic Layout and PresetGroup"""
|
This will create a ForceGroup for each generic Layout and PresetGroup"""
|
||||||
|
|
||||||
# Initialize with preset_groups from the faction
|
# Initialize with preset_groups from the faction
|
||||||
self.forces = [preset_group for preset_group in faction.preset_groups]
|
self.forces = [
|
||||||
|
preset_group.initialize_for_faction(faction)
|
||||||
|
for preset_group in faction.preset_groups
|
||||||
|
]
|
||||||
|
|
||||||
# Generate ForceGroup for all generic layouts by iterating over
|
# Generate ForceGroup for all generic layouts by iterating over
|
||||||
# all layouts which are usable by the given faction.
|
# all layouts which are usable by the given faction.
|
||||||
|
|||||||
@ -92,26 +92,24 @@ class ForceGroup:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
def initialize_for_faction(self, faction: Faction) -> ForceGroup:
|
||||||
def for_faction_by_name(cls, name: str, faction: Faction) -> ForceGroup:
|
"""Initialize a ForceGroup for the given Faction.
|
||||||
"""Load a PresetGroup as ForceGroup with faction sensitive handling"""
|
This adds accessible units to LayoutGroups with the fill property"""
|
||||||
force_group = cls.named(name)
|
for layout in self.layouts:
|
||||||
for layout in force_group.layouts:
|
for group in layout.all_groups:
|
||||||
for groups in layout.groups.values():
|
if group.fill and not self.has_unit_for_layout_group(group):
|
||||||
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):
|
for unit_type in group.possible_types_for_faction(faction):
|
||||||
if issubclass(unit_type, VehicleType):
|
if issubclass(unit_type, VehicleType):
|
||||||
force_group.units.append(
|
self.units.append(
|
||||||
next(GroundUnitType.for_dcs_type(unit_type))
|
next(GroundUnitType.for_dcs_type(unit_type))
|
||||||
)
|
)
|
||||||
elif issubclass(unit_type, ShipType):
|
elif issubclass(unit_type, ShipType):
|
||||||
force_group.units.append(
|
self.units.append(
|
||||||
next(ShipUnitType.for_dcs_type(unit_type))
|
next(ShipUnitType.for_dcs_type(unit_type))
|
||||||
)
|
)
|
||||||
elif issubclass(unit_type, StaticType):
|
elif issubclass(unit_type, StaticType):
|
||||||
force_group.statics.append(unit_type)
|
self.statics.append(unit_type)
|
||||||
return force_group
|
return self
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def named(cls, name: str) -> ForceGroup:
|
def named(cls, name: str) -> ForceGroup:
|
||||||
@ -159,9 +157,11 @@ class ForceGroup:
|
|||||||
"""Return random DCS Unit Type which can be used in the given TgoLayoutGroup"""
|
"""Return random DCS Unit Type which can be used in the given TgoLayoutGroup"""
|
||||||
return random.choice(self.dcs_unit_types_for_group(group))
|
return random.choice(self.dcs_unit_types_for_group(group))
|
||||||
|
|
||||||
def update_group(self, new_group: ForceGroup) -> None:
|
def merge_group(self, new_group: ForceGroup) -> None:
|
||||||
"""Update the group from another group.
|
"""Merge the group with another similar group."""
|
||||||
This will merge units, statics and layouts."""
|
# Unified name for the resulting group
|
||||||
|
self.name = ", ".join([t.description for t in self.tasks])
|
||||||
|
# merge units, statics and layouts
|
||||||
self.units = list(set(self.units + new_group.units))
|
self.units = list(set(self.units + new_group.units))
|
||||||
self.statics = list(set(self.statics + new_group.statics))
|
self.statics = list(set(self.statics + new_group.statics))
|
||||||
self.layouts = list(set(self.layouts + new_group.layouts))
|
self.layouts = list(set(self.layouts + new_group.layouts))
|
||||||
|
|||||||
@ -214,10 +214,8 @@ class Faction:
|
|||||||
ShipUnitType.named(n) for n in json.get("naval_units", [])
|
ShipUnitType.named(n) for n in json.get("naval_units", [])
|
||||||
]
|
]
|
||||||
|
|
||||||
# This has to be loaded AFTER GroundUnitType and ShipUnitType to work properly
|
|
||||||
faction.preset_groups = [
|
faction.preset_groups = [
|
||||||
ForceGroup.for_faction_by_name(n, faction)
|
ForceGroup.named(n) for n in json.get("preset_groups", [])
|
||||||
for n in json.get("preset_groups", [])
|
|
||||||
]
|
]
|
||||||
|
|
||||||
faction.requirements = json.get("requirements", {})
|
faction.requirements = json.get("requirements", {})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user