mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Implemented a separate generate_packages() method in PretenseAircraftGenerator to prevent generating the same ATO multiple times over.
This commit is contained in:
parent
a30fb0f368
commit
00bcd547d3
@ -301,9 +301,7 @@ class PretenseAircraftGenerator:
|
|||||||
flight_type = FlightType.REFUELING
|
flight_type = FlightType.REFUELING
|
||||||
aircraft_per_flight = PRETENSE_AI_TANKERS_PER_FLIGHT
|
aircraft_per_flight = PRETENSE_AI_TANKERS_PER_FLIGHT
|
||||||
else:
|
else:
|
||||||
if len(list(mission_types)) == 0:
|
|
||||||
continue
|
continue
|
||||||
flight_type = random.choice(list(mission_types))
|
|
||||||
|
|
||||||
if flight_type == FlightType.TRANSPORT:
|
if flight_type == FlightType.TRANSPORT:
|
||||||
flight = Flight(
|
flight = Flight(
|
||||||
@ -464,7 +462,27 @@ class PretenseAircraftGenerator:
|
|||||||
ato.add_package(package)
|
ato.add_package(package)
|
||||||
return
|
return
|
||||||
|
|
||||||
def initialize_pretense_data_structures(
|
def initialize_pretense_data_structures(self, cp: ControlPoint) -> None:
|
||||||
|
"""
|
||||||
|
Ensures that the data structures used to pass flight group information
|
||||||
|
to the Pretense init script lua are initialized for use in
|
||||||
|
PretenseFlightGroupSpawner and PretenseLuaGenerator.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cp: Control point to generate aircraft for.
|
||||||
|
flight: The current flight being generated.
|
||||||
|
"""
|
||||||
|
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalnum()])
|
||||||
|
|
||||||
|
for side in range(1, 3):
|
||||||
|
if cp_name_trimmed not in cp.coalition.game.pretense_air[side]:
|
||||||
|
cp.coalition.game.pretense_air[side][cp_name_trimmed] = {}
|
||||||
|
print(
|
||||||
|
f"Populated flight.coalition.game.pretense_air[{side}][{cp_name_trimmed}]"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
def initialize_pretense_data_structures_for_flight(
|
||||||
self, cp: ControlPoint, flight: Flight
|
self, cp: ControlPoint, flight: Flight
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
@ -477,24 +495,23 @@ class PretenseAircraftGenerator:
|
|||||||
flight: The current flight being generated.
|
flight: The current flight being generated.
|
||||||
"""
|
"""
|
||||||
flight_type = flight.flight_type.name
|
flight_type = flight.flight_type.name
|
||||||
is_player = True
|
|
||||||
cp_side = 2 if flight.coalition == self.game.coalition_for(is_player) else 1
|
|
||||||
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalnum()])
|
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalnum()])
|
||||||
|
|
||||||
if cp_name_trimmed not in flight.coalition.game.pretense_air[cp_side]:
|
for side in range(1, 3):
|
||||||
flight.coalition.game.pretense_air[cp_side][cp_name_trimmed] = {}
|
if cp_name_trimmed not in flight.coalition.game.pretense_air[side]:
|
||||||
|
flight.coalition.game.pretense_air[side][cp_name_trimmed] = {}
|
||||||
print(
|
print(
|
||||||
f"Populated flight.coalition.game.pretense_air[{cp_side}][{cp_name_trimmed}]"
|
f"Populated flight.coalition.game.pretense_air[{side}][{cp_name_trimmed}]"
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
flight_type
|
flight_type
|
||||||
not in flight.coalition.game.pretense_air[cp_side][cp_name_trimmed]
|
not in flight.coalition.game.pretense_air[side][cp_name_trimmed]
|
||||||
):
|
):
|
||||||
flight.coalition.game.pretense_air[cp_side][cp_name_trimmed][
|
flight.coalition.game.pretense_air[side][cp_name_trimmed][
|
||||||
flight_type
|
flight_type
|
||||||
] = list()
|
] = list()
|
||||||
print(
|
print(
|
||||||
f"Populated flight.coalition.game.pretense_air[{cp_side}][{cp_name_trimmed}][{flight_type}]"
|
f"Populated flight.coalition.game.pretense_air[{side}][{cp_name_trimmed}][{flight_type}]"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -503,7 +520,6 @@ class PretenseAircraftGenerator:
|
|||||||
country: Country,
|
country: Country,
|
||||||
cp: ControlPoint,
|
cp: ControlPoint,
|
||||||
ato: AirTaskingOrder,
|
ato: AirTaskingOrder,
|
||||||
dynamic_runways: Dict[str, RunwayData],
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Adds aircraft to the mission for every flight in the ATO.
|
"""Adds aircraft to the mission for every flight in the ATO.
|
||||||
|
|
||||||
@ -513,6 +529,7 @@ class PretenseAircraftGenerator:
|
|||||||
ato: The ATO to generate aircraft for.
|
ato: The ATO to generate aircraft for.
|
||||||
dynamic_runways: Runway data for carriers and FARPs.
|
dynamic_runways: Runway data for carriers and FARPs.
|
||||||
"""
|
"""
|
||||||
|
self.initialize_pretense_data_structures(cp)
|
||||||
|
|
||||||
if country == cp.coalition.faction.country:
|
if country == cp.coalition.faction.country:
|
||||||
offmap_transport_cp = self.find_pretense_cargo_plane_cp(cp)
|
offmap_transport_cp = self.find_pretense_cargo_plane_cp(cp)
|
||||||
@ -551,12 +568,20 @@ class PretenseAircraftGenerator:
|
|||||||
|
|
||||||
self._reserve_frequencies_and_tacan(ato)
|
self._reserve_frequencies_and_tacan(ato)
|
||||||
|
|
||||||
|
def generate_packages(
|
||||||
|
self,
|
||||||
|
country: Country,
|
||||||
|
ato: AirTaskingOrder,
|
||||||
|
dynamic_runways: Dict[str, RunwayData],
|
||||||
|
) -> None:
|
||||||
for package in reversed(sorted(ato.packages, key=lambda x: x.time_over_target)):
|
for package in reversed(sorted(ato.packages, key=lambda x: x.time_over_target)):
|
||||||
logging.info(f"Generating package for target: {package.target.name}")
|
logging.info(f"Generating package for target: {package.target.name}")
|
||||||
if not package.flights:
|
if not package.flights:
|
||||||
continue
|
continue
|
||||||
for flight in package.flights:
|
for flight in package.flights:
|
||||||
self.initialize_pretense_data_structures(cp, flight)
|
self.initialize_pretense_data_structures_for_flight(
|
||||||
|
flight.departure, flight
|
||||||
|
)
|
||||||
|
|
||||||
if flight.alive:
|
if flight.alive:
|
||||||
if not flight.squadron.location.runway_is_operational():
|
if not flight.squadron.location.runway_is_operational():
|
||||||
|
|||||||
@ -55,6 +55,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
class PretenseMissionGenerator(MissionGenerator):
|
class PretenseMissionGenerator(MissionGenerator):
|
||||||
def __init__(self, game: Game, time: datetime) -> None:
|
def __init__(self, game: Game, time: datetime) -> None:
|
||||||
|
super().__init__(game, time)
|
||||||
self.game = game
|
self.game = game
|
||||||
self.time = time
|
self.time = time
|
||||||
self.mission = Mission(game.theater.terrain)
|
self.mission = Mission(game.theater.terrain)
|
||||||
@ -218,6 +219,19 @@ class PretenseMissionGenerator(MissionGenerator):
|
|||||||
country,
|
country,
|
||||||
cp,
|
cp,
|
||||||
ato,
|
ato,
|
||||||
|
)
|
||||||
|
|
||||||
|
for cp in self.game.theater.controlpoints:
|
||||||
|
if cp.captured:
|
||||||
|
ato = self.game.blue.ato
|
||||||
|
country = self.p_country
|
||||||
|
else:
|
||||||
|
ato = self.game.red.ato
|
||||||
|
country = self.e_country
|
||||||
|
|
||||||
|
aircraft_generator.generate_packages(
|
||||||
|
country,
|
||||||
|
ato,
|
||||||
tgo_generator.runways,
|
tgo_generator.runways,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -228,41 +242,5 @@ class PretenseMissionGenerator(MissionGenerator):
|
|||||||
continue
|
continue
|
||||||
flight.aircraft_type.assign_channels_for_flight(flight, self.mission_data)
|
flight.aircraft_type.assign_channels_for_flight(flight, self.mission_data)
|
||||||
|
|
||||||
def notify_info_generators(
|
if self.game.settings.plugins.get("ewrj"):
|
||||||
self,
|
self._configure_ewrj(aircraft_generator)
|
||||||
) -> None:
|
|
||||||
"""Generates subscribed MissionInfoGenerator objects."""
|
|
||||||
mission_data = self.mission_data
|
|
||||||
gens: list[MissionInfoGenerator] = [
|
|
||||||
KneeboardGenerator(self.mission, self.game),
|
|
||||||
BriefingGenerator(self.mission, self.game),
|
|
||||||
]
|
|
||||||
for gen in gens:
|
|
||||||
for dynamic_runway in mission_data.runways:
|
|
||||||
gen.add_dynamic_runway(dynamic_runway)
|
|
||||||
|
|
||||||
for tanker in mission_data.tankers:
|
|
||||||
if tanker.blue:
|
|
||||||
gen.add_tanker(tanker)
|
|
||||||
|
|
||||||
for aewc in mission_data.awacs:
|
|
||||||
if aewc.blue:
|
|
||||||
gen.add_awacs(aewc)
|
|
||||||
|
|
||||||
for jtac in mission_data.jtacs:
|
|
||||||
if jtac.blue:
|
|
||||||
gen.add_jtac(jtac)
|
|
||||||
|
|
||||||
for flight in mission_data.flights:
|
|
||||||
gen.add_flight(flight)
|
|
||||||
gen.generate()
|
|
||||||
|
|
||||||
def setup_combined_arms(self) -> None:
|
|
||||||
settings = self.game.settings
|
|
||||||
commanders = settings.tactical_commander_count
|
|
||||||
self.mission.groundControl.pilot_can_control_vehicles = commanders > 0
|
|
||||||
|
|
||||||
self.mission.groundControl.blue_game_masters = settings.game_masters_count
|
|
||||||
self.mission.groundControl.blue_tactical_commander = commanders
|
|
||||||
self.mission.groundControl.blue_jtac = settings.jtac_count
|
|
||||||
self.mission.groundControl.blue_observer = settings.observer_count
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user