Fixing issues after using actual Country in Faction

This commit is contained in:
Raffson 2023-05-18 16:24:49 +02:00
parent cca45d3729
commit da109146c9
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
7 changed files with 29 additions and 31 deletions

View File

@ -19,7 +19,6 @@ from game.ato.flightstate import Completed
from game.ato.flighttype import FlightType from game.ato.flighttype import FlightType
from game.ato.package import Package from game.ato.package import Package
from game.ato.starttype import StartType from game.ato.starttype import StartType
from game.factions.faction import Faction
from game.missiongenerator.lasercoderegistry import LaserCodeRegistry from game.missiongenerator.lasercoderegistry import LaserCodeRegistry
from game.missiongenerator.missiondata import MissionData from game.missiongenerator.missiondata import MissionData
from game.radio.radios import RadioRegistry from game.radio.radios import RadioRegistry
@ -159,14 +158,12 @@ class AircraftGenerator:
for squadron in control_point.squadrons: for squadron in control_point.squadrons:
try: try:
self._spawn_unused_for(squadron, country, faction) self._spawn_unused_for(squadron, country)
except NoParkingSlotError: except NoParkingSlotError:
# If we run out of parking, stop spawning aircraft at this base. # If we run out of parking, stop spawning aircraft at this base.
break break
def _spawn_unused_for( def _spawn_unused_for(self, squadron: Squadron, country: Country) -> None:
self, squadron: Squadron, country: Country, faction: Faction
) -> None:
assert isinstance(squadron.location, Airfield) assert isinstance(squadron.location, Airfield)
for _ in range(squadron.untasked_aircraft): for _ in range(squadron.untasked_aircraft):
# Creating a flight even those this isn't a fragged mission lets us # Creating a flight even those this isn't a fragged mission lets us

View File

@ -30,8 +30,12 @@ class CargoShipGenerator:
def generate_cargo_ship(self, ship: CargoShip) -> ShipGroup: def generate_cargo_ship(self, ship: CargoShip) -> ShipGroup:
waypoints = ship.route waypoints = ship.route
country = self.game.coalition_for(ship.player_owned).faction.country
country = self.mission.country(country.name)
group = self.mission.ship_group( group = self.mission.ship_group(
self.game.coalition_for(ship.player_owned).faction.country, country,
ship.name, ship.name,
HandyWind, HandyWind,
position=waypoints[0], position=waypoints[0],

View File

@ -76,9 +76,10 @@ class ConvoyGenerator:
main_unit_type, main_unit_count = unit_types[0] main_unit_type, main_unit_count = unit_types[0]
faction = self.game.coalition_for(for_player).faction faction = self.game.coalition_for(for_player).faction
country = self.mission.country(faction.country.name)
group = self.mission.vehicle_group( group = self.mission.vehicle_group(
faction.country, country,
name, name,
main_unit_type.dcs_unit_type, main_unit_type.dcs_unit_type,
position=position, position=position,

View File

@ -1,6 +1,5 @@
from __future__ import annotations from __future__ import annotations
import logging
import math import math
import random import random
from datetime import timedelta from datetime import timedelta
@ -159,8 +158,9 @@ class FlotGenerator:
if utype is None: if utype is None:
utype = AircraftType.named("MQ-9 Reaper") utype = AircraftType.named("MQ-9 Reaper")
country = self.mission.country(self.game.blue.faction.country.name)
jtac = self.mission.flight_group( jtac = self.mission.flight_group(
country=self.game.blue.faction.country, country=country,
name=namegen.next_jtac_name(), name=namegen.next_jtac_name(),
aircraft_type=utype.dcs_unit_type, aircraft_type=utype.dcs_unit_type,
position=position[0], position=position[0],
@ -753,6 +753,7 @@ class FlotGenerator:
self.conflict.heading.left if is_player else self.conflict.heading.right self.conflict.heading.left if is_player else self.conflict.heading.right
) )
country = self.game.coalition_for(is_player).faction.country country = self.game.coalition_for(is_player).faction.country
country = self.mission.country(country.name)
for group in groups: for group in groups:
if group.role == CombatGroupRole.ARTILLERY: if group.role == CombatGroupRole.ARTILLERY:
distance_from_frontline = ( distance_from_frontline = (

View File

@ -43,13 +43,6 @@ if TYPE_CHECKING:
from game import Game 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: class MissionGenerator:
def __init__(self, game: Game, time: datetime) -> None: def __init__(self, game: Game, time: datetime) -> None:
self.game = game self.game = game
@ -65,6 +58,9 @@ class MissionGenerator:
self.generation_started = False 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: with open("resources/default_options.lua", "r", encoding="utf-8") as f:
options = dcs.lua.loads(f.read())["options"] options = dcs.lua.loads(f.read())["options"]
ext_view = game.settings.external_views_allowed ext_view = game.settings.external_views_allowed
@ -133,15 +129,13 @@ class MissionGenerator:
"neutrals", bullseye=Bullseye(Point(0, 0, self.mission.terrain)).to_pydcs() "neutrals", bullseye=Bullseye(Point(0, 0, self.mission.terrain)).to_pydcs()
) )
p_country = self.game.blue.faction.country self.mission.coalition["blue"].add_country(self.p_country)
e_country = self.game.red.faction.country self.mission.coalition["red"].add_country(self.e_country)
self.mission.coalition["blue"].add_country(p_country)
self.mission.coalition["red"].add_country(e_country)
belligerents = {p_country, e_country} belligerents = {self.p_country.id, self.e_country.id}
for country in country_dict.keys(): for country_id in country_dict.keys():
if country not in belligerents: if country_id not in belligerents:
self.mission.coalition["neutrals"].add_country(country_dict[country]()) self.mission.coalition["neutrals"].add_country(country_dict[country_id]())
def add_airfields_to_unit_map(self) -> None: def add_airfields_to_unit_map(self) -> None:
for control_point in self.game.theater.controlpoints: for control_point in self.game.theater.controlpoints:
@ -236,19 +230,19 @@ class MissionGenerator:
aircraft_generator.clear_parking_slots() aircraft_generator.clear_parking_slots()
aircraft_generator.generate_flights( aircraft_generator.generate_flights(
self.game.blue.faction.country, self.p_country,
self.game.blue.ato, self.game.blue.ato,
tgo_generator.runways, tgo_generator.runways,
) )
aircraft_generator.generate_flights( aircraft_generator.generate_flights(
self.game.red.faction.country, self.e_country,
self.game.red.ato, self.game.red.ato,
tgo_generator.runways, tgo_generator.runways,
) )
if not self.game.settings.perf_disable_idle_aircraft: if not self.game.settings.perf_disable_idle_aircraft:
aircraft_generator.spawn_unused_aircraft( aircraft_generator.spawn_unused_aircraft(
self.game.blue.faction.country, self.p_country,
self.game.red.faction.country, self.e_country,
) )
self.mission_data.flights = aircraft_generator.flights 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) 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): if utype is not None and not self.game.position_culled(pos):
self.mission.static_group( self.mission.static_group(
country=self.game.blue.faction.country, country=self.p_country,
name="", name="",
_type=utype, _type=utype,
hidden=True, hidden=True,

View File

@ -687,7 +687,7 @@ class TgoGenerator:
def generate(self) -> None: def generate(self) -> None:
for cp in self.game.theater.controlpoints: 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 # Generate helipads
helipad_gen = HelipadGenerator( helipad_gen = HelipadGenerator(

View File

@ -73,6 +73,7 @@ class VisualsGenerator:
self.game = game self.game = game
def _generate_frontline_smokes(self) -> None: def _generate_frontline_smokes(self) -> None:
country = self.mission.country(self.game.red.faction.country.name)
for front_line in self.game.theater.conflicts(): for front_line in self.game.theater.conflicts():
from_cp = front_line.blue_cp from_cp = front_line.blue_cp
to_cp = front_line.red_cp to_cp = front_line.red_cp
@ -99,7 +100,7 @@ class VisualsGenerator:
break break
self.mission.static_group( self.mission.static_group(
self.game.red.faction.country, country,
"", "",
_type=v, _type=v,
position=pos, position=pos,