reworked the skynet group name generation

- added information about the role of the aa site
- moved handling of ground name from tgo to the sam generator to make the tgo cleaner
- adjusted the skynet-config lua to the changes

(cherry picked from commit de443fa3f0)
This commit is contained in:
RndName
2021-07-01 16:00:04 +02:00
committed by Dan Albert
parent a8bd3df46f
commit 201fe121ff
11 changed files with 97 additions and 35 deletions

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from enum import Enum
from typing import Iterator, List
@@ -9,11 +11,31 @@ from game.theater.theatergroundobject import SamGroundObject
from gen.sam.group_generator import GroupGenerator
class SkynetRole(Enum):
#: A radar SAM that should be controlled by Skynet.
Sam = "Sam"
#: A radar SAM that should be controlled and used as an EWR by Skynet.
SamAsEwr = "SamAsEwr"
#: An air defense unit that should be used as point defense by Skynet.
PointDefense = "PD"
#: All other types of groups that might be present in a SAM TGO. This includes
#: SHORADS, AAA, supply trucks, etc. Anything that shouldn't be controlled by Skynet
#: should use this role.
NoSkynetBehavior = "NoSkynetBehavior"
class AirDefenseRange(Enum):
AAA = "AAA"
Short = "short"
Medium = "medium"
Long = "long"
AAA = ("AAA", SkynetRole.NoSkynetBehavior)
Short = ("short", SkynetRole.NoSkynetBehavior)
Medium = ("medium", SkynetRole.Sam)
Long = ("long", SkynetRole.SamAsEwr)
def __init__(self, description: str, default_role: SkynetRole) -> None:
self.range_name = description
self.default_role = default_role
class AirDefenseGroupGenerator(GroupGenerator, ABC):
@@ -24,18 +46,32 @@ class AirDefenseGroupGenerator(GroupGenerator, ABC):
price: int
def __init__(self, game: Game, ground_object: SamGroundObject) -> None:
ground_object.skynet_capable = True
super().__init__(game, ground_object)
self.vg.name = self.group_name_for_role(self.vg.id, self.primary_group_role())
self.auxiliary_groups: List[VehicleGroup] = []
def add_auxiliary_group(self, name_suffix: str) -> VehicleGroup:
group = VehicleGroup(
self.game.next_group_id(), "|".join([self.go.group_name, name_suffix])
)
def add_auxiliary_group(self, role: SkynetRole) -> VehicleGroup:
gid = self.game.next_group_id()
group = VehicleGroup(gid, self.group_name_for_role(gid, role))
self.auxiliary_groups.append(group)
return group
def group_name_for_role(self, gid: int, role: SkynetRole) -> str:
if role is SkynetRole.NoSkynetBehavior:
# No special naming needed for air defense groups that don't participate in
# Skynet.
return f"{self.go.group_name}|{gid}"
# For those that do, we need a prefix of `$COLOR|SAM| so our Skynet config picks
# the group up at all. To support PDs we need to append the ID of the TGO so
# that the PD will know which group it's protecting. We then append the role so
# our config knows what to do with the group, and finally the GID of *this*
# group to ensure no conflicts.
return "|".join(
[self.go.faction_color, "SAM", str(self.go.group_id), role.value, str(gid)]
)
def get_generated_group(self) -> VehicleGroup:
raise RuntimeError(
"Deprecated call to AirDefenseGroupGenerator.get_generated_group "
@@ -52,3 +88,7 @@ class AirDefenseGroupGenerator(GroupGenerator, ABC):
@abstractmethod
def range(cls) -> AirDefenseRange:
...
@classmethod
def primary_group_role(cls) -> SkynetRole:
return cls.range().default_role