mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add EWR Jammer plugin
This commit is contained in:
@@ -111,6 +111,7 @@ class WeaponType(Enum):
|
||||
LGB = "LGB"
|
||||
TGP = "TGP"
|
||||
DECOY = "DECOY"
|
||||
JAMMER = "JAMMER"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ from .aircraftpainter import AircraftPainter
|
||||
from .flightdata import FlightData
|
||||
from .flightgroupconfigurator import FlightGroupConfigurator
|
||||
from .flightgroupspawner import FlightGroupSpawner
|
||||
from ...data.weapons import WeaponType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -67,6 +68,10 @@ class AircraftGenerator:
|
||||
self.mission_data = mission_data
|
||||
self.helipads = helipads
|
||||
|
||||
self.ewrj_package_dict: Dict[int, List[FlyingGroup[Any]]] = {}
|
||||
self.ewrj = settings.plugins.get("ewrj")
|
||||
self.need_ecm = settings.plugin_option("ewrj.ecm_required")
|
||||
|
||||
@cached_property
|
||||
def use_client(self) -> bool:
|
||||
"""True if Client should be used instead of Player."""
|
||||
@@ -216,8 +221,25 @@ class AircraftGenerator:
|
||||
wpt.link_unit = hpad.id
|
||||
self.helipads[flight.arrival].units.append(hpad)
|
||||
|
||||
if self.ewrj:
|
||||
self._track_ewrj_flight(flight, group)
|
||||
|
||||
return group
|
||||
|
||||
def _track_ewrj_flight(self, flight: Flight, group: FlyingGroup[Any]) -> None:
|
||||
if not self.ewrj_package_dict.get(id(flight.package)):
|
||||
self.ewrj_package_dict[id(flight.package)] = []
|
||||
if (
|
||||
flight.package.primary_flight
|
||||
and flight is flight.package.primary_flight
|
||||
or flight.client_count
|
||||
and (
|
||||
not self.need_ecm
|
||||
or flight.loadout.has_weapon_of_type(WeaponType.JAMMER)
|
||||
)
|
||||
):
|
||||
self.ewrj_package_dict[id(flight.package)].append(group)
|
||||
|
||||
def _reserve_frequencies_and_tacan(self, ato: AirTaskingOrder) -> None:
|
||||
for package in ato.packages:
|
||||
if package.frequency is None:
|
||||
|
||||
@@ -5,7 +5,11 @@ from datetime import datetime
|
||||
from typing import Any, Optional, TYPE_CHECKING
|
||||
|
||||
from dcs import Mission
|
||||
from dcs.action import DoScript
|
||||
from dcs.flyingunit import FlyingUnit
|
||||
from dcs.task import OptReactOnThreat
|
||||
from dcs.translation import String
|
||||
from dcs.triggers import TriggerStart
|
||||
from dcs.unit import Skill
|
||||
from dcs.unitgroup import FlyingGroup
|
||||
|
||||
@@ -131,6 +135,20 @@ class FlightGroupConfigurator:
|
||||
laser_codes.append(self.laser_code_registry.get_next_laser_code())
|
||||
else:
|
||||
laser_codes.append(None)
|
||||
settings = self.flight.coalition.game.settings
|
||||
if not player or not settings.plugins.get("ewrj"):
|
||||
return
|
||||
jammer_required = settings.plugin_option("ewrj.ecm_required")
|
||||
if jammer_required:
|
||||
ecm = WeaponTypeEnum.JAMMER
|
||||
if not self.flight.loadout.has_weapon_of_type(ecm):
|
||||
return
|
||||
ewrj_menu_trigger = TriggerStart(comment=f"EWRJ-{unit.name}")
|
||||
ewrj_menu_trigger.add_action(DoScript(String(f'EWJamming("{unit.name}")')))
|
||||
self.mission.triggerrules.triggers.append(ewrj_menu_trigger)
|
||||
self.group.points[0].tasks[0] = OptReactOnThreat(
|
||||
OptReactOnThreat.Values.PassiveDefense
|
||||
)
|
||||
|
||||
def setup_radios(self) -> RadioFrequency:
|
||||
freq = self.flight.frequency
|
||||
|
||||
@@ -9,6 +9,7 @@ import dcs.lua
|
||||
from dcs import Mission, Point
|
||||
from dcs.coalition import Coalition
|
||||
from dcs.countries import country_dict
|
||||
from dcs.task import OptReactOnThreat
|
||||
|
||||
from game.atcdata import AtcData
|
||||
from game.dcs.beacons import Beacons
|
||||
@@ -80,6 +81,7 @@ class MissionGenerator:
|
||||
self.add_airfields_to_unit_map()
|
||||
self.initialize_registries()
|
||||
|
||||
LuaGenerator(self.game, self.mission, self.mission_data).generate()
|
||||
EnvironmentGenerator(self.mission, self.game.conditions, self.time).generate()
|
||||
|
||||
tgo_generator = TgoGenerator(
|
||||
@@ -105,7 +107,6 @@ class MissionGenerator:
|
||||
TriggerGenerator(self.mission, self.game).generate()
|
||||
ForcedOptionsGenerator(self.mission, self.game).generate()
|
||||
VisualsGenerator(self.mission, self.game).generate()
|
||||
LuaGenerator(self.game, self.mission, self.mission_data).generate()
|
||||
DrawingsGenerator(self.mission, self.game).generate()
|
||||
|
||||
self.setup_combined_arms()
|
||||
@@ -118,6 +119,22 @@ class MissionGenerator:
|
||||
|
||||
return self.unit_map
|
||||
|
||||
@staticmethod
|
||||
def _configure_ewrj(gen: AircraftGenerator) -> None:
|
||||
for groups in gen.ewrj_package_dict.values():
|
||||
optrot = groups[0].points[0].tasks[0]
|
||||
assert isinstance(optrot, OptReactOnThreat)
|
||||
if (
|
||||
len(groups) == 1
|
||||
and optrot.value != OptReactOnThreat.Values.PassiveDefense
|
||||
):
|
||||
# primary flight with no EWR-Jamming capability
|
||||
continue
|
||||
for group in groups:
|
||||
group.points[0].tasks[0] = OptReactOnThreat(
|
||||
OptReactOnThreat.Values.PassiveDefense
|
||||
)
|
||||
|
||||
def setup_mission_coalitions(self) -> None:
|
||||
self.mission.coalition["blue"] = Coalition(
|
||||
"blue", bullseye=self.game.blue.bullseye.to_pydcs()
|
||||
@@ -253,6 +270,9 @@ class MissionGenerator:
|
||||
continue
|
||||
flight.aircraft_type.assign_channels_for_flight(flight, self.mission_data)
|
||||
|
||||
if self.game.settings.plugins.get("ewrj"):
|
||||
self._configure_ewrj(aircraft_generator)
|
||||
|
||||
def generate_destroyed_units(self) -> None:
|
||||
"""Add destroyed units to the Mission"""
|
||||
if not self.game.settings.perf_destroyed_units:
|
||||
|
||||
Reference in New Issue
Block a user