Decoupling and generalization of templates

Improvement for factions and templates which will allow decoupling of the templates from the actual units
- Implement UnitGroup class which matches unit_types and possible templates as the needed abstraction layer for decoupling.
- Refactor UnitType, Add ShipUnitType and all ships we currently use
- Remove serialized template.json and migrated to multiple yaml templates (one for each template) and multiple .miz
- Reorganized a lot of templates and started with generalization of many types (AAA, Flak, SHORAD, Navy)
- Fixed a lot of bugs from the previous reworks (group name generation, strike targets...)
- Reorganized the faction file completly. removed redundant lists, added presets for complex groups / families of units like sams
- Reworked the building template handling. Some templates are unused like "village"
- Reworked how groups from templates can be merged again for the dcs group creation (e.g. the skynet plugin requires them to be in the same group)
- Allow to define alternative tasks
This commit is contained in:
RndName
2022-01-29 00:42:58 +01:00
parent daf4704fe7
commit 60c8c80480
27 changed files with 1481 additions and 958 deletions

View File

@@ -1,15 +1,15 @@
from dataclasses import dataclass
from datetime import timedelta
from game.data.groundunitclass import GroundUnitClass
from game.data.units import UnitClass
from game.utils import Distance, feet, nautical_miles
@dataclass
class GroundUnitProcurementRatios:
ratios: dict[GroundUnitClass, float]
ratios: dict[UnitClass, float]
def for_unit_class(self, unit_class: GroundUnitClass) -> float:
def for_unit_class(self, unit_class: UnitClass) -> float:
try:
return self.ratios[unit_class] / sum(self.ratios.values())
except KeyError:
@@ -104,13 +104,13 @@ MODERN_DOCTRINE = Doctrine(
sweep_distance=nautical_miles(60),
ground_unit_procurement_ratios=GroundUnitProcurementRatios(
{
GroundUnitClass.Tank: 3,
GroundUnitClass.Atgm: 2,
GroundUnitClass.Apc: 2,
GroundUnitClass.Ifv: 3,
GroundUnitClass.Artillery: 1,
GroundUnitClass.Shorads: 2,
GroundUnitClass.Recon: 1,
UnitClass.Tank: 3,
UnitClass.Atgm: 2,
UnitClass.Apc: 2,
UnitClass.Ifv: 3,
UnitClass.Artillery: 1,
UnitClass.SHORAD: 2,
UnitClass.Recon: 1,
}
),
)
@@ -141,13 +141,13 @@ COLDWAR_DOCTRINE = Doctrine(
sweep_distance=nautical_miles(40),
ground_unit_procurement_ratios=GroundUnitProcurementRatios(
{
GroundUnitClass.Tank: 4,
GroundUnitClass.Atgm: 2,
GroundUnitClass.Apc: 3,
GroundUnitClass.Ifv: 2,
GroundUnitClass.Artillery: 1,
GroundUnitClass.Shorads: 2,
GroundUnitClass.Recon: 1,
UnitClass.Tank: 4,
UnitClass.Atgm: 2,
UnitClass.Apc: 3,
UnitClass.Ifv: 2,
UnitClass.Artillery: 1,
UnitClass.SHORAD: 2,
UnitClass.Recon: 1,
}
),
)
@@ -178,12 +178,12 @@ WWII_DOCTRINE = Doctrine(
sweep_distance=nautical_miles(10),
ground_unit_procurement_ratios=GroundUnitProcurementRatios(
{
GroundUnitClass.Tank: 3,
GroundUnitClass.Atgm: 3,
GroundUnitClass.Apc: 3,
GroundUnitClass.Artillery: 1,
GroundUnitClass.Shorads: 3,
GroundUnitClass.Recon: 1,
UnitClass.Tank: 3,
UnitClass.Atgm: 3,
UnitClass.Apc: 3,
UnitClass.Artillery: 1,
UnitClass.SHORAD: 3,
UnitClass.Recon: 1,
}
),
)

View File

@@ -1,17 +0,0 @@
from __future__ import annotations
from enum import unique, Enum
@unique
class GroundUnitClass(Enum):
Tank = "Tank"
Atgm = "ATGM"
Ifv = "IFV"
Apc = "APC"
Artillery = "Artillery"
Logistics = "Logistics"
Recon = "Recon"
Infantry = "Infantry"
Shorads = "SHORADS"
Manpads = "MANPADS"

63
game/data/groups.py Normal file
View File

@@ -0,0 +1,63 @@
from enum import Enum
class GroupRole(Enum):
Unknow = "Unknown"
AntiAir = "AntiAir"
Building = "Building"
Naval = "Naval"
GroundForce = "GroundForce"
Defenses = "Defenses"
Air = "Air"
class GroupTask(Enum):
EWR = "EarlyWarningRadar"
AAA = "AAA"
SHORAD = "SHORAD"
MERAD = "MERAD"
LORAD = "LORAD"
AircraftCarrier = "AircraftCarrier"
HelicopterCarrier = "HelicopterCarrier"
Navy = "Navy"
BaseDefense = "BaseDefense" # Ground
FrontLine = "FrontLine"
Air = "Air"
Missile = "Missile"
Coastal = "Coastal"
Factory = "Factory"
Ammo = "Ammo"
Oil = "Oil"
FOB = "FOB"
StrikeTarget = "StrikeTarget"
Comms = "Comms"
Power = "Power"
ROLE_TASKINGS: dict[GroupRole, list[GroupTask]] = {
GroupRole.Unknow: [], # No Tasking
GroupRole.AntiAir: [
GroupTask.EWR,
GroupTask.AAA,
GroupTask.SHORAD,
GroupTask.MERAD,
GroupTask.LORAD,
],
GroupRole.GroundForce: [GroupTask.BaseDefense, GroupTask.FrontLine],
GroupRole.Naval: [
GroupTask.AircraftCarrier,
GroupTask.HelicopterCarrier,
GroupTask.Navy,
],
GroupRole.Building: [
GroupTask.Factory,
GroupTask.Ammo,
GroupTask.Oil,
GroupTask.FOB,
GroupTask.StrikeTarget,
GroupTask.Comms,
GroupTask.Power,
],
GroupRole.Defenses: [GroupTask.Missile, GroupTask.Coastal],
GroupRole.Air: [GroupTask.Air],
}

40
game/data/units.py Normal file
View File

@@ -0,0 +1,40 @@
from __future__ import annotations
from enum import unique, Enum
from game.data.groups import GroupRole, GroupTask
@unique
class UnitClass(Enum):
Unknown = "Unknown"
Tank = "Tank"
Atgm = "ATGM"
Ifv = "IFV"
Apc = "APC"
Artillery = "Artillery"
Logistics = "Logistics"
Recon = "Recon"
Infantry = "Infantry"
AAA = "AAA"
SHORAD = "SHORAD"
Manpad = "Manpad"
SR = "SearchRadar"
STR = "SearchTrackRadar"
LowAltSR = "LowAltSearchRadar"
TR = "TrackRadar"
LN = "Launcher"
EWR = "EarlyWarningRadar"
TELAR = "TELAR"
Missile = "Missile"
AircraftCarrier = "AircraftCarrier"
HelicopterCarrier = "HelicopterCarrier"
Destroyer = "Destroyer"
Cruiser = "Cruiser"
Submarine = "Submarine"
LandingShip = "LandingShip"
Boat = "Boat"
Plane = "Plane"
def to_dict(self) -> str:
return self.value