From dde74af6b59627e2716799edf043f9c3d22aaea2 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 1 Nov 2020 13:59:44 -0800 Subject: [PATCH] Fix client/player detection. Client needs to be used if there are other player slots in *any* flight, not just the same group. Fixes https://github.com/Khopa/dcs_liberation/issues/297 --- changelog.md | 3 ++- gen/aircraft.py | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index cb587d0a..0fc0e19a 100644 --- a/changelog.md +++ b/changelog.md @@ -10,7 +10,8 @@ * **[Moddability]** Custom campaigns can be designed through json files ## Fixes : -* **[Campaign generator]** Ship group and offshore buildings should not be generated on land anymore +* **[Campaign generator]** Ship group and offshore buildings should not be generated on land anymore +* **[Mission Generator]** Fixed player/client confusion when a flight had only one player slot. * **[UI]** Missing TER weapons in custom payload now selectable. # 2.1.5 diff --git a/gen/aircraft.py b/gen/aircraft.py index 9e67e521..55ad44ce 100644 --- a/gen/aircraft.py +++ b/gen/aircraft.py @@ -4,7 +4,8 @@ import logging import random from dataclasses import dataclass from datetime import timedelta -from typing import Dict, List, Optional, Type, Union +from functools import cached_property +from typing import Dict, List, Optional, Type, Union, TYPE_CHECKING from dcs import helicopters from dcs.action import AITaskPush, ActivateGroup @@ -90,6 +91,9 @@ from .flights.traveltime import TotEstimator from .naming import namegen from .runways import RunwayAssigner +if TYPE_CHECKING: + from game import Game + WARM_START_HELI_AIRSPEED = 120 WARM_START_HELI_ALT = 500 WARM_START_ALTITUDE = 3000 @@ -551,7 +555,7 @@ AIRCRAFT_DATA["P-47D-30"] = AIRCRAFT_DATA["P-51D"] class AircraftConflictGenerator: def __init__(self, mission: Mission, conflict: Conflict, settings: Settings, - game, radio_registry: RadioRegistry): + game: Game, radio_registry: RadioRegistry): self.m = mission self.game = game self.settings = settings @@ -559,6 +563,21 @@ class AircraftConflictGenerator: self.radio_registry = radio_registry self.flights: List[FlightData] = [] + @cached_property + def use_client(self) -> bool: + """True if Client should be used instead of Player.""" + blue_clients = self.client_slots_in_ato(self.game.blue_ato) + red_clients = self.client_slots_in_ato(self.game.red_ato) + return blue_clients + red_clients > 1 + + @staticmethod + def client_slots_in_ato(ato: AirTaskingOrder) -> int: + total = 0 + for package in ato.packages: + for flight in package.flights: + total += flight.client_count + return total + def get_intra_flight_channel(self, airframe: UnitType) -> RadioFrequency: """Allocates an intra-flight channel to a group. @@ -608,13 +627,12 @@ class AircraftConflictGenerator: for unit_instance in group.units: unit_instance.livery_id = db.PLANE_LIVERY_OVERRIDES[unit_type] - single_client = flight.client_count == 1 for idx in range(0, min(len(group.units), flight.client_count)): unit = group.units[idx] - if single_client: - unit.set_player() - else: + if self.use_client: unit.set_client() + else: + unit.set_player() # Do not generate player group with late activation. if group.late_activation: