From da109146c97d638b2741e33a8dd82b9261fdd6ad Mon Sep 17 00:00:00 2001 From: Raffson Date: Thu, 18 May 2023 16:24:49 +0200 Subject: [PATCH] Fixing issues after using actual Country in Faction --- .../aircraft/aircraftgenerator.py | 7 ++-- game/missiongenerator/cargoshipgenerator.py | 6 +++- game/missiongenerator/convoygenerator.py | 3 +- game/missiongenerator/flotgenerator.py | 5 +-- game/missiongenerator/missiongenerator.py | 34 ++++++++----------- game/missiongenerator/tgogenerator.py | 2 +- game/missiongenerator/visualsgenerator.py | 3 +- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/game/missiongenerator/aircraft/aircraftgenerator.py b/game/missiongenerator/aircraft/aircraftgenerator.py index 4c5c9622..2aee7b13 100644 --- a/game/missiongenerator/aircraft/aircraftgenerator.py +++ b/game/missiongenerator/aircraft/aircraftgenerator.py @@ -19,7 +19,6 @@ from game.ato.flightstate import Completed from game.ato.flighttype import FlightType from game.ato.package import Package from game.ato.starttype import StartType -from game.factions.faction import Faction from game.missiongenerator.lasercoderegistry import LaserCodeRegistry from game.missiongenerator.missiondata import MissionData from game.radio.radios import RadioRegistry @@ -159,14 +158,12 @@ class AircraftGenerator: for squadron in control_point.squadrons: try: - self._spawn_unused_for(squadron, country, faction) + self._spawn_unused_for(squadron, country) except NoParkingSlotError: # If we run out of parking, stop spawning aircraft at this base. break - def _spawn_unused_for( - self, squadron: Squadron, country: Country, faction: Faction - ) -> None: + def _spawn_unused_for(self, squadron: Squadron, country: Country) -> None: assert isinstance(squadron.location, Airfield) for _ in range(squadron.untasked_aircraft): # Creating a flight even those this isn't a fragged mission lets us diff --git a/game/missiongenerator/cargoshipgenerator.py b/game/missiongenerator/cargoshipgenerator.py index 460420e2..b6f3b282 100644 --- a/game/missiongenerator/cargoshipgenerator.py +++ b/game/missiongenerator/cargoshipgenerator.py @@ -30,8 +30,12 @@ class CargoShipGenerator: def generate_cargo_ship(self, ship: CargoShip) -> ShipGroup: waypoints = ship.route + + country = self.game.coalition_for(ship.player_owned).faction.country + country = self.mission.country(country.name) + group = self.mission.ship_group( - self.game.coalition_for(ship.player_owned).faction.country, + country, ship.name, HandyWind, position=waypoints[0], diff --git a/game/missiongenerator/convoygenerator.py b/game/missiongenerator/convoygenerator.py index 6fc1cf41..1c40a85a 100644 --- a/game/missiongenerator/convoygenerator.py +++ b/game/missiongenerator/convoygenerator.py @@ -76,9 +76,10 @@ class ConvoyGenerator: main_unit_type, main_unit_count = unit_types[0] faction = self.game.coalition_for(for_player).faction + country = self.mission.country(faction.country.name) group = self.mission.vehicle_group( - faction.country, + country, name, main_unit_type.dcs_unit_type, position=position, diff --git a/game/missiongenerator/flotgenerator.py b/game/missiongenerator/flotgenerator.py index e71f9137..f95d74b2 100644 --- a/game/missiongenerator/flotgenerator.py +++ b/game/missiongenerator/flotgenerator.py @@ -1,6 +1,5 @@ from __future__ import annotations -import logging import math import random from datetime import timedelta @@ -159,8 +158,9 @@ class FlotGenerator: if utype is None: utype = AircraftType.named("MQ-9 Reaper") + country = self.mission.country(self.game.blue.faction.country.name) jtac = self.mission.flight_group( - country=self.game.blue.faction.country, + country=country, name=namegen.next_jtac_name(), aircraft_type=utype.dcs_unit_type, position=position[0], @@ -753,6 +753,7 @@ class FlotGenerator: self.conflict.heading.left if is_player else self.conflict.heading.right ) country = self.game.coalition_for(is_player).faction.country + country = self.mission.country(country.name) for group in groups: if group.role == CombatGroupRole.ARTILLERY: distance_from_frontline = ( diff --git a/game/missiongenerator/missiongenerator.py b/game/missiongenerator/missiongenerator.py index 3cdd417e..e9f545b1 100644 --- a/game/missiongenerator/missiongenerator.py +++ b/game/missiongenerator/missiongenerator.py @@ -43,13 +43,6 @@ if TYPE_CHECKING: from game import Game -def country_id_from_name(name: str) -> int: - for k, v in country_dict.items(): - if v.name == name: - return k - return -1 - - class MissionGenerator: def __init__(self, game: Game, time: datetime) -> None: self.game = game @@ -65,6 +58,9 @@ class MissionGenerator: self.generation_started = False + self.p_country = country_dict[self.game.blue.faction.country.id]() + self.e_country = country_dict[self.game.red.faction.country.id]() + with open("resources/default_options.lua", "r", encoding="utf-8") as f: options = dcs.lua.loads(f.read())["options"] ext_view = game.settings.external_views_allowed @@ -133,15 +129,13 @@ class MissionGenerator: "neutrals", bullseye=Bullseye(Point(0, 0, self.mission.terrain)).to_pydcs() ) - p_country = self.game.blue.faction.country - e_country = self.game.red.faction.country - self.mission.coalition["blue"].add_country(p_country) - self.mission.coalition["red"].add_country(e_country) + self.mission.coalition["blue"].add_country(self.p_country) + self.mission.coalition["red"].add_country(self.e_country) - belligerents = {p_country, e_country} - for country in country_dict.keys(): - if country not in belligerents: - self.mission.coalition["neutrals"].add_country(country_dict[country]()) + belligerents = {self.p_country.id, self.e_country.id} + for country_id in country_dict.keys(): + if country_id not in belligerents: + self.mission.coalition["neutrals"].add_country(country_dict[country_id]()) def add_airfields_to_unit_map(self) -> None: for control_point in self.game.theater.controlpoints: @@ -236,19 +230,19 @@ class MissionGenerator: aircraft_generator.clear_parking_slots() aircraft_generator.generate_flights( - self.game.blue.faction.country, + self.p_country, self.game.blue.ato, tgo_generator.runways, ) aircraft_generator.generate_flights( - self.game.red.faction.country, + self.e_country, self.game.red.ato, tgo_generator.runways, ) if not self.game.settings.perf_disable_idle_aircraft: aircraft_generator.spawn_unused_aircraft( - self.game.blue.faction.country, - self.game.red.faction.country, + self.p_country, + self.e_country, ) self.mission_data.flights = aircraft_generator.flights @@ -278,7 +272,7 @@ class MissionGenerator: pos = Point(cast(float, d["x"]), cast(float, d["z"]), self.mission.terrain) if utype is not None and not self.game.position_culled(pos): self.mission.static_group( - country=self.game.blue.faction.country, + country=self.p_country, name="", _type=utype, hidden=True, diff --git a/game/missiongenerator/tgogenerator.py b/game/missiongenerator/tgogenerator.py index 7bb0b62a..f20d6ae1 100644 --- a/game/missiongenerator/tgogenerator.py +++ b/game/missiongenerator/tgogenerator.py @@ -687,7 +687,7 @@ class TgoGenerator: def generate(self) -> None: for cp in self.game.theater.controlpoints: - country = self.game.coalition_for(cp.captured).faction.country + country = self.m.country(cp.coalition.faction.country.name) # Generate helipads helipad_gen = HelipadGenerator( diff --git a/game/missiongenerator/visualsgenerator.py b/game/missiongenerator/visualsgenerator.py index 2ae52282..d75dbd09 100644 --- a/game/missiongenerator/visualsgenerator.py +++ b/game/missiongenerator/visualsgenerator.py @@ -73,6 +73,7 @@ class VisualsGenerator: self.game = game def _generate_frontline_smokes(self) -> None: + country = self.mission.country(self.game.red.faction.country.name) for front_line in self.game.theater.conflicts(): from_cp = front_line.blue_cp to_cp = front_line.red_cp @@ -99,7 +100,7 @@ class VisualsGenerator: break self.mission.static_group( - self.game.red.faction.country, + country, "", _type=v, position=pos,