Refactor Templates to Layouts, Review and Cleanup

- Fix tgogenerator
- Fix UI for ForceGroup and Layouts
- Fix ammo depot handling
- Split bigger files in smaller meaningful files (TGO, layouts, forces)
- Renamed Template to Layout
- Renamed GroundGroup to TheaterGroup and GroundUnit to TheaterUnit
- Reorganize Layouts and UnitGroups to a ArmedForces class and ForceGroup similar to the AirWing and Squadron
- Reworded the UnitClass, GroupRole, GroupTask (adopted to PEP8) and reworked the connection from Role and Task
- added comments
- added missing unit classes
- added temp workaround for missing classes
- add repariable property to TheaterUnit
- Review and Cleanup

Added serialization for loaded templates

Loading the templates from the .miz files takes a lot of computation time and in the future there will be more templates added to the system. Therefore a local pickle serialization for the loaded templates was re-added:
- The pickle will be created the first time the TemplateLoader will be accessed
- Pickle is stored in Liberation SaveDir
- Added UI option to (re-)import templates
This commit is contained in:
RndName
2022-02-10 12:23:16 +01:00
parent 1ae6503ceb
commit 2c17a9a52e
138 changed files with 1985 additions and 3096 deletions

View File

@@ -20,13 +20,11 @@ from typing import (
Set,
TYPE_CHECKING,
Tuple,
Union,
)
from dcs.mapping import Point
from dcs.ships import Forrestal, KUZNECOW, LHA_Tarawa, Stennis, Type_071
from dcs.terrain.terrain import Airport, ParkingSlot
from dcs.unit import Unit
from dcs.unitgroup import ShipGroup, StaticGroup
from game.dcs.helpers import unit_type_from_name
@@ -39,14 +37,10 @@ from gen.runways import RunwayAssigner, RunwayData
from .base import Base
from .missiontarget import MissionTarget
from .theatergroundobject import (
BuildingGroundObject,
GenericCarrierGroundObject,
TheaterGroundObject,
BuildingGroundObject,
CarrierGroundObject,
LhaGroundObject,
GroundUnit,
)
from .theatergroup import TheaterUnit
from ..ato.starttype import StartType
from ..data.units import UnitClass
from ..dcs.aircrafttype import AircraftType
@@ -525,8 +519,8 @@ class ControlPoint(MissionTarget, ABC):
for group in g.groups:
for u in group.units:
if u.unit_type and u.unit_type.unit_class in [
UnitClass.AircraftCarrier,
UnitClass.HelicopterCarrier,
UnitClass.AIRCRAFT_CARRIER,
UnitClass.HELICOPTER_CARRIER,
]:
return group.group_name
return None
@@ -816,28 +810,26 @@ class ControlPoint(MissionTarget, ABC):
return self.front_line_capacity_with(self.active_ammo_depots_count)
@property
def all_ammo_depots(self) -> Iterator[BuildingGroundObject]:
def all_ammo_depots(self) -> Iterator[TheaterGroundObject]:
for tgo in self.connected_objectives:
if not tgo.is_ammo_depot:
continue
assert isinstance(tgo, BuildingGroundObject)
yield tgo
@property
def active_ammo_depots(self) -> Iterator[BuildingGroundObject]:
for tgo in self.all_ammo_depots:
if not tgo.is_dead:
if tgo.is_ammo_depot:
yield tgo
def ammo_depot_count(self, alive_only: bool = False) -> int:
return sum(
ammo_depot.alive_unit_count if alive_only else ammo_depot.unit_count
for ammo_depot in self.all_ammo_depots
)
@property
def active_ammo_depots_count(self) -> int:
"""Return the number of available ammo depots"""
return len(list(self.active_ammo_depots))
return self.ammo_depot_count(True)
@property
def total_ammo_depots_count(self) -> int:
"""Return the number of ammo depots, including dead ones"""
return len(list(self.all_ammo_depots))
return self.ammo_depot_count()
@property
def active_fuel_depots_count(self) -> int:
@@ -856,7 +848,7 @@ class ControlPoint(MissionTarget, ABC):
return len([obj for obj in self.connected_objectives if obj.category == "fuel"])
@property
def strike_targets(self) -> list[GroundUnit]:
def strike_targets(self) -> list[TheaterUnit]:
return []
@property
@@ -1008,7 +1000,7 @@ class NavalControlPoint(ControlPoint, ABC):
# while its escorts are still alive.
for group in self.find_main_tgo().groups:
for u in group.units:
if unit_type_from_name(u.type) in [
if u.type in [
Forrestal,
Stennis,
LHA_Tarawa,