Implemented PretenseNameGenerator.pretense_trimmed_cp_name to remove Scandic characters from Pretense zone names.

This commit is contained in:
MetalStormGhost 2024-05-21 00:25:20 +03:00
parent 9775d3b97c
commit bfe008775d
5 changed files with 69 additions and 30 deletions

View File

@ -27,6 +27,7 @@ from game.missiongenerator.missiondata import MissionData
from game.pretense.pretenseflightgroupconfigurator import ( from game.pretense.pretenseflightgroupconfigurator import (
PretenseFlightGroupConfigurator, PretenseFlightGroupConfigurator,
) )
from game.pretense.pretenseflightgroupspawner import PretenseNameGenerator
from game.radio.radios import RadioRegistry from game.radio.radios import RadioRegistry
from game.radio.tacan import TacanRegistry from game.radio.tacan import TacanRegistry
from game.runways import RunwayData from game.runways import RunwayData
@ -772,7 +773,7 @@ class PretenseAircraftGenerator:
cp: Control point to generate aircraft for. cp: Control point to generate aircraft for.
flight: The current flight being generated. flight: The current flight being generated.
""" """
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
for side in range(1, 3): for side in range(1, 3):
if cp_name_trimmed not in cp.coalition.game.pretense_air[side]: if cp_name_trimmed not in cp.coalition.game.pretense_air[side]:
@ -792,7 +793,7 @@ class PretenseAircraftGenerator:
flight: The current flight being generated. flight: The current flight being generated.
""" """
flight_type = flight.flight_type flight_type = flight.flight_type
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
for side in range(1, 3): for side in range(1, 3):
if cp_name_trimmed not in flight.coalition.game.pretense_air[side]: if cp_name_trimmed not in flight.coalition.game.pretense_air[side]:

View File

@ -32,11 +32,19 @@ class PretenseNameGenerator(NameGenerator):
@classmethod @classmethod
def next_pretense_aircraft_name(cls, cp: ControlPoint, flight: Flight) -> str: def next_pretense_aircraft_name(cls, cp: ControlPoint, flight: Flight) -> str:
cls.aircraft_number += 1 cls.aircraft_number += 1
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = cls.pretense_trimmed_cp_name(cp.name)
return "{}-{}-{}".format( return "{}-{}-{}".format(
cp_name_trimmed, str(flight.flight_type).lower(), cls.aircraft_number cp_name_trimmed, str(flight.flight_type).lower(), cls.aircraft_number
) )
@classmethod
def pretense_trimmed_cp_name(cls, cp_name: str):
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()])
cp_name_trimmed = cp_name_trimmed.replace("ä", "a")
cp_name_trimmed = cp_name_trimmed.replace("ö", "o")
cp_name_trimmed = cp_name_trimmed.replace("ø", "o")
return cp_name_trimmed
namegen = PretenseNameGenerator namegen = PretenseNameGenerator
# Air-start AI aircraft which are faster than this on WWII terrains # Air-start AI aircraft which are faster than this on WWII terrains
@ -83,7 +91,7 @@ class PretenseFlightGroupSpawner(FlightGroupSpawner):
== self.flight.coalition.game.coalition_for(is_player) == self.flight.coalition.game.coalition_for(is_player)
else 1 else 1
) )
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
if self.flight.client_count == 0: if self.flight.client_count == 0:
self.flight.coalition.game.pretense_air[cp_side][cp_name_trimmed][ self.flight.coalition.game.pretense_air[cp_side][cp_name_trimmed][
@ -98,14 +106,6 @@ class PretenseFlightGroupSpawner(FlightGroupSpawner):
def generate_flight_at_departure(self) -> FlyingGroup[Any]: def generate_flight_at_departure(self) -> FlyingGroup[Any]:
cp = self.flight.departure cp = self.flight.departure
name = namegen.next_pretense_aircraft_name(cp, self.flight) name = namegen.next_pretense_aircraft_name(cp, self.flight)
is_player = True
cp_side = (
2
if self.flight.coalition
== self.flight.coalition.game.coalition_for(is_player)
else 1
)
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()])
try: try:
if self.start_type is StartType.IN_FLIGHT: if self.start_type is StartType.IN_FLIGHT:

View File

@ -24,6 +24,7 @@ from game.dcs.aircrafttype import AircraftType
from game.missiongenerator.luagenerator import LuaGenerator from game.missiongenerator.luagenerator import LuaGenerator
from game.missiongenerator.missiondata import MissionData from game.missiongenerator.missiondata import MissionData
from game.plugins import LuaPluginManager from game.plugins import LuaPluginManager
from game.pretense.pretenseflightgroupspawner import PretenseNameGenerator
from game.pretense.pretensetgogenerator import PretenseGroundObjectGenerator from game.pretense.pretensetgogenerator import PretenseGroundObjectGenerator
from game.theater import Airfield, OffMapSpawn, TheaterGroundObject from game.theater import Airfield, OffMapSpawn, TheaterGroundObject
from game.theater.iadsnetwork.iadsrole import IadsRole from game.theater.iadsnetwork.iadsrole import IadsRole
@ -266,7 +267,7 @@ class PretenseLuaGenerator(LuaGenerator):
def generate_pretense_land_upgrade_supply(self, cp_name: str, cp_side: int) -> str: def generate_pretense_land_upgrade_supply(self, cp_name: str, cp_side: int) -> str:
lua_string_zones = "" lua_string_zones = ""
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp_name)
cp_side_str = "blue" if cp_side == PRETENSE_BLUE_SIDE else "red" cp_side_str = "blue" if cp_side == PRETENSE_BLUE_SIDE else "red"
cp = self.game.theater.controlpoints[0] cp = self.game.theater.controlpoints[0]
for loop_cp in self.game.theater.controlpoints: for loop_cp in self.game.theater.controlpoints:
@ -531,7 +532,7 @@ class PretenseLuaGenerator(LuaGenerator):
def generate_pretense_sea_upgrade_supply(self, cp_name: str, cp_side: int) -> str: def generate_pretense_sea_upgrade_supply(self, cp_name: str, cp_side: int) -> str:
lua_string_zones = "" lua_string_zones = ""
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp_name)
cp_side_str = "blue" if cp_side == PRETENSE_BLUE_SIDE else "red" cp_side_str = "blue" if cp_side == PRETENSE_BLUE_SIDE else "red"
supply_ship = "oilPump" supply_ship = "oilPump"
@ -715,7 +716,7 @@ class PretenseLuaGenerator(LuaGenerator):
is_artillery_zone = random.choice([True, False]) is_artillery_zone = random.choice([True, False])
lua_string_zones = "" lua_string_zones = ""
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp_name)
lua_string_zones += f"zones.{cp_name_trimmed}:defineUpgrades(" + "{\n" lua_string_zones += f"zones.{cp_name_trimmed}:defineUpgrades(" + "{\n"
lua_string_zones += " [1] = { --red side\n" lua_string_zones += " [1] = { --red side\n"
@ -815,7 +816,7 @@ class PretenseLuaGenerator(LuaGenerator):
def generate_pretense_zone_sea(self, cp_name: str) -> str: def generate_pretense_zone_sea(self, cp_name: str) -> str:
lua_string_zones = "" lua_string_zones = ""
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp_name)
lua_string_zones += f"zones.{cp_name_trimmed}:defineUpgrades(" + "{\n" lua_string_zones += f"zones.{cp_name_trimmed}:defineUpgrades(" + "{\n"
lua_string_zones += " [1] = { --red side\n" lua_string_zones += " [1] = { --red side\n"
@ -853,7 +854,7 @@ class PretenseLuaGenerator(LuaGenerator):
cp_carrier_group_name: str | None, cp_carrier_group_name: str | None,
) -> str: ) -> str:
lua_string_carrier = "\n" lua_string_carrier = "\n"
cp_name_trimmed = "".join([i for i in cp_name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp_name)
link4carriers = [Stennis, CVN_71, CVN_72, CVN_73, CVN_75, Forrestal] link4carriers = [Stennis, CVN_71, CVN_72, CVN_73, CVN_75, Forrestal]
is_link4carrier = False is_link4carrier = False
@ -1587,6 +1588,19 @@ class PretenseLuaGenerator(LuaGenerator):
cp_name_conn_other = "".join( cp_name_conn_other = "".join(
[i for i in other_cp_name if i.isalnum() or i.isspace() or i == "-"] [i for i in other_cp_name if i.isalnum() or i.isspace() or i == "-"]
) )
cp_name_conn = cp_name_conn.replace("Ä", "A")
cp_name_conn = cp_name_conn.replace("Ö", "O")
cp_name_conn = cp_name_conn.replace("Ø", "O")
cp_name_conn = cp_name_conn.replace("ä", "a")
cp_name_conn = cp_name_conn.replace("ö", "o")
cp_name_conn = cp_name_conn.replace("ø", "o")
cp_name_conn_other = cp_name_conn_other.replace("Ä", "A")
cp_name_conn_other = cp_name_conn_other.replace("Ö", "O")
cp_name_conn_other = cp_name_conn_other.replace("Ø", "O")
cp_name_conn_other = cp_name_conn_other.replace("ä", "a")
cp_name_conn_other = cp_name_conn_other.replace("ö", "o")
cp_name_conn_other = cp_name_conn_other.replace("ø", "o")
lua_string_connman = ( lua_string_connman = (
f" cm: addConnection('{cp_name_conn}', '{cp_name_conn_other}')\n" f" cm: addConnection('{cp_name_conn}', '{cp_name_conn_other}')\n"
) )
@ -1637,10 +1651,16 @@ class PretenseLuaGenerator(LuaGenerator):
lua_string_carriers += self.generate_pretense_carrier_zones() lua_string_carriers += self.generate_pretense_carrier_zones()
for cp in self.game.theater.controlpoints: for cp in self.game.theater.controlpoints:
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
cp_name = "".join( cp_name = "".join(
[i for i in cp.name if i.isalnum() or i.isspace() or i == "-"] [i for i in cp.name if i.isalnum() or i.isspace() or i == "-"]
) )
cp_name.replace("Ä", "A")
cp_name.replace("Ö", "O")
cp_name.replace("Ø", "O")
cp_name.replace("ä", "a")
cp_name.replace("ö", "o")
cp_name.replace("ø", "o")
cp_side = 2 if cp.captured else 1 cp_side = 2 if cp.captured else 1
if isinstance(cp, OffMapSpawn): if isinstance(cp, OffMapSpawn):
@ -1665,6 +1685,12 @@ class PretenseLuaGenerator(LuaGenerator):
self.game.pretense_ground_supply[side][cp_name_trimmed] = list() self.game.pretense_ground_supply[side][cp_name_trimmed] = list()
if cp_name_trimmed not in self.game.pretense_ground_assault[cp_side]: if cp_name_trimmed not in self.game.pretense_ground_assault[cp_side]:
self.game.pretense_ground_assault[side][cp_name_trimmed] = list() self.game.pretense_ground_assault[side][cp_name_trimmed] = list()
cp_name = cp_name.replace("Ä", "A")
cp_name = cp_name.replace("Ö", "O")
cp_name = cp_name.replace("Ø", "O")
cp_name = cp_name.replace("ä", "a")
cp_name = cp_name.replace("ö", "o")
cp_name = cp_name.replace("ø", "o")
lua_string_zones += ( lua_string_zones += (
f"zones.{cp_name_trimmed} = ZoneCommand:new('{cp_name}')\n" f"zones.{cp_name_trimmed} = ZoneCommand:new('{cp_name}')\n"
) )
@ -1783,7 +1809,9 @@ class PretenseLuaGenerator(LuaGenerator):
cp_side_captured = cp_side == 2 cp_side_captured = cp_side == 2
if cp_side_captured != cp.captured: if cp_side_captured != cp.captured:
continue continue
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
cp.name
)
for mission_type in self.game.pretense_air[cp_side][cp_name_trimmed]: for mission_type in self.game.pretense_air[cp_side][cp_name_trimmed]:
if mission_type == FlightType.PRETENSE_CARGO: if mission_type == FlightType.PRETENSE_CARGO:
for air_group in self.game.pretense_air[cp_side][ for air_group in self.game.pretense_air[cp_side][
@ -1796,7 +1824,9 @@ class PretenseLuaGenerator(LuaGenerator):
lua_string_supply += "local offmapZones = {\n" lua_string_supply += "local offmapZones = {\n"
for cp in self.game.theater.controlpoints: for cp in self.game.theater.controlpoints:
if isinstance(cp, Airfield): if isinstance(cp, Airfield):
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
cp.name
)
lua_string_supply += f" zones.{cp_name_trimmed},\n" lua_string_supply += f" zones.{cp_name_trimmed},\n"
lua_string_supply += "}\n" lua_string_supply += "}\n"

View File

@ -38,6 +38,7 @@ from game.missiongenerator.tgogenerator import (
GenericCarrierGenerator, GenericCarrierGenerator,
) )
from game.point_with_heading import PointWithHeading from game.point_with_heading import PointWithHeading
from game.pretense.pretenseflightgroupspawner import PretenseNameGenerator
from game.radio.radios import RadioRegistry from game.radio.radios import RadioRegistry
from game.radio.tacan import TacanRegistry, TacanBand, TacanUsage from game.radio.tacan import TacanRegistry, TacanBand, TacanUsage
from game.runways import RunwayData from game.runways import RunwayData
@ -356,8 +357,8 @@ class PretenseGroundObjectGenerator(GroundObjectGenerator):
def generate(self) -> None: def generate(self) -> None:
if self.culled: if self.culled:
return return
cp_name_trimmed = "".join( cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
[i for i in self.ground_object.control_point.name.lower() if i.isalpha()] self.ground_object.control_point.name
) )
country_name_trimmed = "".join( country_name_trimmed = "".join(
[i for i in self.country.shortname.lower() if i.isalpha()] [i for i in self.country.shortname.lower() if i.isalpha()]
@ -456,8 +457,8 @@ class PretenseGroundObjectGenerator(GroundObjectGenerator):
control_point = other_cp control_point = other_cp
break break
cp_name_trimmed = "".join( cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
[i for i in control_point.name.lower() if i.isalpha()] control_point.name
) )
is_player = True is_player = True
side = ( side = (
@ -565,8 +566,8 @@ class PretenseGroundObjectGenerator(GroundObjectGenerator):
control_point = other_cp control_point = other_cp
break break
cp_name_trimmed = "".join( cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
[i for i in control_point.name.lower() if i.isalpha()] control_point.name
) )
is_player = True is_player = True
side = ( side = (
@ -825,7 +826,7 @@ class PretenseTgoGenerator(TgoGenerator):
def generate(self) -> None: def generate(self) -> None:
for cp in self.game.theater.controlpoints: for cp in self.game.theater.controlpoints:
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
for side in range(1, 3): for side in range(1, 3):
if cp_name_trimmed not in self.game.pretense_ground_supply[side]: if cp_name_trimmed not in self.game.pretense_ground_supply[side]:
self.game.pretense_ground_supply[side][cp_name_trimmed] = list() self.game.pretense_ground_supply[side][cp_name_trimmed] = list()

View File

@ -35,6 +35,7 @@ from numpy import cross, einsum, arctan2
from shapely import MultiPolygon, Point as ShapelyPoint from shapely import MultiPolygon, Point as ShapelyPoint
from game.naming import ALPHA_MILITARY from game.naming import ALPHA_MILITARY
from game.pretense.pretenseflightgroupspawner import PretenseNameGenerator
from game.theater import Airfield from game.theater import Airfield
from game.theater.controlpoint import Fob, TRIGGER_RADIUS_CAPTURE, OffMapSpawn from game.theater.controlpoint import Fob, TRIGGER_RADIUS_CAPTURE, OffMapSpawn
@ -357,6 +358,12 @@ class PretenseTriggerGenerator:
cp_name = "".join( cp_name = "".join(
[i for i in cp.name if i.isalnum() or i.isspace() or i == "-"] [i for i in cp.name if i.isalnum() or i.isspace() or i == "-"]
) )
cp_name = cp_name.replace("Ä", "A")
cp_name = cp_name.replace("Ö", "O")
cp_name = cp_name.replace("Ø", "O")
cp_name = cp_name.replace("ä", "a")
cp_name = cp_name.replace("ö", "o")
cp_name = cp_name.replace("ø", "o")
if not isinstance(cp, OffMapSpawn): if not isinstance(cp, OffMapSpawn):
zone_color = {1: 0.0, 2: 0.0, 3: 0.0, 4: 0.15} zone_color = {1: 0.0, 2: 0.0, 3: 0.0, 4: 0.15}
self.mission.triggers.add_triggerzone( self.mission.triggers.add_triggerzone(
@ -366,7 +373,7 @@ class PretenseTriggerGenerator:
name=cp_name, name=cp_name,
color=zone_color, color=zone_color,
) )
cp_name_trimmed = "".join([i for i in cp.name.lower() if i.isalpha()]) cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(cp.name)
tgo_num = 0 tgo_num = 0
for tgo in cp.ground_objects: for tgo in cp.ground_objects:
if cp.is_fleet or tgo.sea_object: if cp.is_fleet or tgo.sea_object:
@ -414,8 +421,8 @@ class PretenseTriggerGenerator:
cp_airport = self.mission.terrain.airport_by_id(airfield.airport.id) cp_airport = self.mission.terrain.airport_by_id(airfield.airport.id)
if cp_airport is None: if cp_airport is None:
continue continue
cp_name_trimmed = "".join( cp_name_trimmed = PretenseNameGenerator.pretense_trimmed_cp_name(
[i for i in cp_airport.name.lower() if i.isalpha()] cp_airport.name
) )
zone_color = {1: 0.0, 2: 1.0, 3: 0.5, 4: 0.15} zone_color = {1: 0.0, 2: 1.0, 3: 0.5, 4: 0.15}
if cp_airport is None: if cp_airport is None: