Merge faction sams and shorads into air_defenses.

Fixes https://github.com/Khopa/dcs_liberation/issues/473. Air defenses
for bases, strike locations, and fixed IADS will now all downgrade to
lower tier systems as needed. Strike locations will still be spawned as
an equally weighted random generator from either the medium or long
range groups, but will use a short range system if none are available to
the faction.

I've made the change in a way that leaves factions compatible, but will
follow up to clean up our built-in factions.
This commit is contained in:
Dan Albert 2020-11-27 17:42:59 -08:00
parent e8aa9839b0
commit bd60760f9d
4 changed files with 13 additions and 22 deletions

View File

@ -51,11 +51,8 @@ class Faction:
# Logistics units used
logistics_units: List[VehicleType] = field(default_factory=list)
# List of units that can be deployed as SHORAD
shorads: List[str] = field(default_factory=list)
# Possible SAMS site generators for this faction
sams: List[str] = field(default_factory=list)
air_defenses: List[str] = field(default_factory=list)
# Possible EWR generators for this faction.
ewrs: List[str] = field(default_factory=list)
@ -146,9 +143,14 @@ class Faction:
faction.logistics_units = load_all_vehicles(
json.get("logistics_units", []))
faction.sams = json.get("sams", [])
faction.ewrs = json.get("ewrs", [])
faction.shorads = json.get("shorads", [])
faction.air_defenses = json.get("air_defenses", [])
# Compatibility for older factions. All air defenses now belong to a
# single group and the generator decides what belongs where.
faction.air_defenses.extend(json.get("sams", []))
faction.air_defenses.extend(json.get("shorads", []))
faction.missiles = json.get("missiles", [])
faction.requirements = json.get("requirements", {})

View File

@ -39,7 +39,6 @@ from gen.sam.airdefensegroupgenerator import AirDefenseRange
from gen.sam.sam_group_generator import (
generate_anti_air_group,
generate_ewr_group,
generate_shorad_group,
)
from . import (
ConflictTheater,
@ -530,7 +529,8 @@ class BaseDefenseGenerator:
g = SamGroundObject(namegen.random_objective_name(), group_id,
position, self.control_point, for_airbase=True)
group = generate_shorad_group(self.game, g, self.faction)
group = generate_anti_air_group(self.game, g, self.faction,
ranges=[{AirDefenseRange.Short}])
if group is None:
logging.error(
f"Could not generate SHORAD group at {self.control_point}")

View File

@ -156,7 +156,7 @@ def get_faction_possible_sams_generator(
Return the list of possible SAM generator for the given faction
:param faction: Faction name to search units for
"""
return [SAM_MAP[s] for s in faction.sams]
return [SAM_MAP[s] for s in faction.air_defenses]
def get_faction_possible_ewrs_generator(faction: Faction) -> List[Type[GroupGenerator]]:
@ -233,14 +233,3 @@ def generate_ewr_group(game: Game, ground_object: TheaterGroundObject,
generator.generate()
return generator.get_generated_group()
return None
def generate_shorad_group(game: Game, ground_object: SamGroundObject,
faction: Faction) -> Optional[VehicleGroup]:
if len(faction.shorads) > 0:
sam = random.choice(faction.shorads)
generator = SAM_MAP[sam](game, ground_object)
generator.generate()
return generator.get_generated_group()
else:
return generate_anti_air_group(game, ground_object, faction)

View File

@ -71,9 +71,9 @@ class TestFactionLoader(unittest.TestCase):
self.assertIn(Infantry.Infantry_M4, faction.infantry_units)
self.assertIn(Infantry.Soldier_M249, faction.infantry_units)
self.assertIn("AvengerGenerator", faction.shorads)
self.assertIn("AvengerGenerator", faction.air_defenses)
self.assertIn("HawkGenerator", faction.sams)
self.assertIn("HawkGenerator", faction.air_defenses)
self.assertIn(CVN_74_John_C__Stennis, faction.aircraft_carrier)
self.assertIn(LHA_1_Tarawa, faction.helicopter_carrier)