Fix targeting SAMs with strike missions.

The changes for Skynet unfortunately broke this because the names used
by the TGO and the name of the group itself were no longer in sync.
This deserves a larger cleanup where we decouple that naming
requirement (TGOs don't need a lot of the data they currently have),
but this works until we have the time to do that.

Fixes https://github.com/Khopa/dcs_liberation/issues/298
This commit is contained in:
Dan Albert 2020-11-06 18:08:40 -08:00
parent 853ee5aac4
commit 56b51c85bb
6 changed files with 32 additions and 25 deletions

View File

@ -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)

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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:

View File

@ -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):