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
|
||||
aircraft_per_flight = PRETENSE_AI_TANKERS_PER_FLIGHT
|
||||
else:
|
||||
if len(list(mission_types)) == 0:
|
||||
continue
|
||||
flight_type = random.choice(list(mission_types))
|
||||
continue
|
||||
|
||||
if flight_type == FlightType.TRANSPORT:
|
||||
flight = Flight(
|
||||
@ -464,7 +462,27 @@ class PretenseAircraftGenerator:
|
||||
ato.add_package(package)
|
||||
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
|
||||
) -> None:
|
||||
"""
|
||||
@ -477,25 +495,24 @@ class PretenseAircraftGenerator:
|
||||
flight: The current flight being generated.
|
||||
"""
|
||||
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()])
|
||||
|
||||
if cp_name_trimmed not in flight.coalition.game.pretense_air[cp_side]:
|
||||
flight.coalition.game.pretense_air[cp_side][cp_name_trimmed] = {}
|
||||
print(
|
||||
f"Populated flight.coalition.game.pretense_air[{cp_side}][{cp_name_trimmed}]"
|
||||
)
|
||||
if (
|
||||
flight_type
|
||||
not in flight.coalition.game.pretense_air[cp_side][cp_name_trimmed]
|
||||
):
|
||||
flight.coalition.game.pretense_air[cp_side][cp_name_trimmed][
|
||||
for side in range(1, 3):
|
||||
if cp_name_trimmed not in flight.coalition.game.pretense_air[side]:
|
||||
flight.coalition.game.pretense_air[side][cp_name_trimmed] = {}
|
||||
print(
|
||||
f"Populated flight.coalition.game.pretense_air[{side}][{cp_name_trimmed}]"
|
||||
)
|
||||
if (
|
||||
flight_type
|
||||
] = list()
|
||||
print(
|
||||
f"Populated flight.coalition.game.pretense_air[{cp_side}][{cp_name_trimmed}][{flight_type}]"
|
||||
)
|
||||
not in flight.coalition.game.pretense_air[side][cp_name_trimmed]
|
||||
):
|
||||
flight.coalition.game.pretense_air[side][cp_name_trimmed][
|
||||
flight_type
|
||||
] = list()
|
||||
print(
|
||||
f"Populated flight.coalition.game.pretense_air[{side}][{cp_name_trimmed}][{flight_type}]"
|
||||
)
|
||||
return
|
||||
|
||||
def generate_flights(
|
||||
@ -503,7 +520,6 @@ class PretenseAircraftGenerator:
|
||||
country: Country,
|
||||
cp: ControlPoint,
|
||||
ato: AirTaskingOrder,
|
||||
dynamic_runways: Dict[str, RunwayData],
|
||||
) -> None:
|
||||
"""Adds aircraft to the mission for every flight in the ATO.
|
||||
|
||||
@ -513,6 +529,7 @@ class PretenseAircraftGenerator:
|
||||
ato: The ATO to generate aircraft for.
|
||||
dynamic_runways: Runway data for carriers and FARPs.
|
||||
"""
|
||||
self.initialize_pretense_data_structures(cp)
|
||||
|
||||
if country == cp.coalition.faction.country:
|
||||
offmap_transport_cp = self.find_pretense_cargo_plane_cp(cp)
|
||||
@ -551,12 +568,20 @@ class PretenseAircraftGenerator:
|
||||
|
||||
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)):
|
||||
logging.info(f"Generating package for target: {package.target.name}")
|
||||
if not package.flights:
|
||||
continue
|
||||
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 not flight.squadron.location.runway_is_operational():
|
||||
|
||||
@ -55,6 +55,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class PretenseMissionGenerator(MissionGenerator):
|
||||
def __init__(self, game: Game, time: datetime) -> None:
|
||||
super().__init__(game, time)
|
||||
self.game = game
|
||||
self.time = time
|
||||
self.mission = Mission(game.theater.terrain)
|
||||
@ -218,9 +219,22 @@ class PretenseMissionGenerator(MissionGenerator):
|
||||
country,
|
||||
cp,
|
||||
ato,
|
||||
tgo_generator.runways,
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
self.mission_data.flights = aircraft_generator.flights
|
||||
|
||||
for flight in aircraft_generator.flights:
|
||||
@ -228,41 +242,5 @@ class PretenseMissionGenerator(MissionGenerator):
|
||||
continue
|
||||
flight.aircraft_type.assign_channels_for_flight(flight, self.mission_data)
|
||||
|
||||
def notify_info_generators(
|
||||
self,
|
||||
) -> 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
|
||||
if self.game.settings.plugins.get("ewrj"):
|
||||
self._configure_ewrj(aircraft_generator)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user