diff --git a/gen/sam/genericsam_group_generator.py b/gen/sam/genericsam_group_generator.py index 00d5ed6e..8a35e51b 100644 --- a/gen/sam/genericsam_group_generator.py +++ b/gen/sam/genericsam_group_generator.py @@ -1,19 +1,15 @@ -import random +from abc import ABC -from dcs.vehicles import AirDefence -from game import db +from game import Game from gen.sam.group_generator import GroupGenerator +from theater.theatergroundobject import SamGroundObject -class GenericSamGroupGenerator(GroupGenerator): +class GenericSamGroupGenerator(GroupGenerator, ABC): """ This is the base for all SAM group generators """ - @property - def groupNamePrefix(self) -> str: - # prefix the SAM site for use with the Skynet IADS plugin - if self.faction == self.game.player_name: # this is the player faction - return "BLUE SAM " - else: - return "RED SAM " + def __init__(self, game: Game, ground_object: SamGroundObject) -> None: + ground_object.skynet_capable = True + super().__init__(game, ground_object) diff --git a/gen/sam/group_generator.py b/gen/sam/group_generator.py index 1bd57939..94738eef 100644 --- a/gen/sam/group_generator.py +++ b/gen/sam/group_generator.py @@ -22,20 +22,16 @@ if TYPE_CHECKING: # types rather than pydcs groups. class GroupGenerator: - def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Optional[Faction] = None): # faction is not mandatory because some subclasses do not use it + def __init__(self, game: Game, ground_object: TheaterGroundObject) -> None: self.game = game self.go = ground_object self.position = ground_object.position self.heading = random.randint(0, 359) - self.faction = faction - self.vg = unitgroup.VehicleGroup(self.game.next_group_id(), self.groupNamePrefix + self.go.group_identifier) + self.vg = unitgroup.VehicleGroup(self.game.next_group_id(), + self.go.group_name) wp = self.vg.add_waypoint(self.position, PointAction.OffRoad, 0) wp.ETA_locked = True - @property - def groupNamePrefix(self) -> str: - return "" - def generate(self): raise NotImplementedError @@ -96,7 +92,8 @@ class ShipGroupGenerator(GroupGenerator): self.position = ground_object.position self.heading = random.randint(0, 359) self.faction = faction - self.vg = unitgroup.ShipGroup(self.game.next_group_id(), self.groupNamePrefix + self.go.group_identifier) + self.vg = unitgroup.ShipGroup(self.game.next_group_id(), + self.go.group_name) wp = self.vg.add_waypoint(self.position, 0) wp.ETA_locked = True diff --git a/gen/sam/sam_group_generator.py b/gen/sam/sam_group_generator.py index 6acc2759..f0549718 100644 --- a/gen/sam/sam_group_generator.py +++ b/gen/sam/sam_group_generator.py @@ -36,6 +36,7 @@ from gen.sam.sam_zu23 import ZU23Generator from gen.sam.sam_zu23_ural import ZU23UralGenerator from gen.sam.sam_zu23_ural_insurgent import ZU23UralInsurgentGenerator from theater import TheaterGroundObject +from theater.theatergroundobject import SamGroundObject SAM_MAP = { "HawkGenerator": HawkGenerator, @@ -125,13 +126,13 @@ def generate_anti_air_group(game: Game, ground_object: TheaterGroundObject, possible_sams_generators = get_faction_possible_sams_generator(faction) if len(possible_sams_generators) > 0: sam_generator_class = random.choice(possible_sams_generators) - generator = sam_generator_class(game, ground_object, db.FACTIONS[faction]) + generator = sam_generator_class(game, ground_object) generator.generate() return generator.get_generated_group() return None -def generate_shorad_group(game: Game, ground_object: TheaterGroundObject, +def generate_shorad_group(game: Game, ground_object: SamGroundObject, faction_name: str) -> Optional[VehicleGroup]: faction = db.FACTIONS[faction_name] diff --git a/resources/plugins/skynetiads/skynetiads-config.lua b/resources/plugins/skynetiads/skynetiads-config.lua index ea6cb4a5..df12d512 100644 --- a/resources/plugins/skynetiads/skynetiads-config.lua +++ b/resources/plugins/skynetiads/skynetiads-config.lua @@ -72,10 +72,10 @@ if dcsLiberation and SkynetIADS then end --add EW units to the IADS: - iads:addEarlyWarningRadarsByPrefix(coalitionPrefix .. " EW") + iads:addEarlyWarningRadarsByPrefix(coalitionPrefix .. "|EWR|") --add SAM groups to the IADS: - iads:addSAMSitesByPrefix(coalitionPrefix .. " SAM") + iads:addSAMSitesByPrefix(coalitionPrefix .. "|SAM|") -- specific configurations, for each SAM type if actAsEwr then diff --git a/theater/start_generator.py b/theater/start_generator.py index 9e679f6c..536b7680 100644 --- a/theater/start_generator.py +++ b/theater/start_generator.py @@ -426,8 +426,8 @@ class GroundObjectGenerator: def generate_airbase_defense_group(airbase_defense_group_id: int, - ground_obj: TheaterGroundObject, - faction: str, game: Game) -> None: + ground_obj: SamGroundObject, faction: str, + game: Game) -> None: if airbase_defense_group_id == 0: group = generate_armor_group(faction, game, ground_obj) elif airbase_defense_group_id == 1 and random.randint(0, 1) == 0: diff --git a/theater/theatergroundobject.py b/theater/theatergroundobject.py index 34a98c87..47b022fa 100644 --- a/theater/theatergroundobject.py +++ b/theater/theatergroundobject.py @@ -203,6 +203,19 @@ class SamGroundObject(TheaterGroundObject): airbase_group=for_airbase, sea_object=False ) + # Set by the SAM unit generator if the generated group is compatible + # with Skynet. + self.skynet_capable = False + + @property + def group_name(self) -> str: + if self.skynet_capable: + # Prefix the group names of SAM sites with the side color so Skynet + # can find them. + color = "BLUE" if self.control_point.captured else "RED" + return f"{color}|SAM|{self.group_id}" + else: + return super().group_name class ShipGroundObject(TheaterGroundObject):