Added a new setting: "Maximum frontline length (km)"

It replaces the FRONTLINE_LENGTH constant, which was used previously. The default setting for the frontline length has been set to match the FRONTLINE_LENGTH value (80 km), but I feel the default should be a bit shorter. Discussion on the topic would be welcome.
This commit is contained in:
MetalStormGhost
2022-04-16 11:26:21 +03:00
committed by Raffson
parent 96a5a8e2ef
commit e1bf0ed47a
9 changed files with 36 additions and 19 deletions

View File

@@ -52,9 +52,8 @@ class CasFlightPlan(PatrollingFlightPlan[CasLayout]):
@property
def engagement_distance(self) -> Distance:
from game.missiongenerator.frontlineconflictdescription import FRONTLINE_LENGTH
return meters(FRONTLINE_LENGTH) / 2
max_length = self.flight.coalition.game.settings.max_frontline_length * 1000
return meters(max_length) / 2
@property
def combat_speed_waypoints(self) -> set[FlightWaypoint]:
@@ -79,7 +78,7 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]):
)
ingress, heading, distance = FrontLineConflictDescription.frontline_vector(
location, self.theater
location, self.theater, self.coalition.game.settings
)
center = ingress.point_from_heading(heading.degrees, distance / 2)
egress = ingress.point_from_heading(heading.degrees, distance)

View File

@@ -490,7 +490,7 @@ class Game:
# By default, use the existing frontline conflict position
for front_line in self.theater.conflicts():
position = FrontLineConflictDescription.frontline_position(
front_line, self.theater
front_line, self.theater, self.settings
)
zones.append(position[0])
zones.append(front_line.blue_cp.position)

View File

@@ -90,7 +90,7 @@ class DrawingsGenerator:
heading,
distance,
) = FrontLineConflictDescription.frontline_vector(
front_line, self.game.theater
front_line, self.game.theater, self.game.settings
)
end_point = plane_start.point_from_heading(heading.degrees, distance)

View File

@@ -97,11 +97,11 @@ class FlotGenerator:
def generate(self) -> None:
position = FrontLineConflictDescription.frontline_position(
self.conflict.front_line, self.game.theater
self.conflict.front_line, self.game.theater, self.game.settings
)
frontline_vector = FrontLineConflictDescription.frontline_vector(
self.conflict.front_line, self.game.theater
self.conflict.front_line, self.game.theater, self.game.settings
)
# Create player groups at random position

View File

@@ -7,14 +7,12 @@ from dcs.country import Country
from dcs.mapping import Point
from shapely.geometry import LineString, Point as ShapelyPoint
from game.settings import Settings
from game.theater.conflicttheater import ConflictTheater, FrontLine
from game.theater.controlpoint import ControlPoint
from game.utils import Heading
FRONTLINE_LENGTH = 80000
class FrontLineConflictDescription:
def __init__(
self,
@@ -54,12 +52,12 @@ class FrontLineConflictDescription:
@classmethod
def frontline_position(
cls, frontline: FrontLine, theater: ConflictTheater
cls, frontline: FrontLine, theater: ConflictTheater, settings: Settings
) -> Tuple[Point, Heading]:
attack_heading = frontline.attack_heading
position = cls.find_ground_position(
frontline.position,
FRONTLINE_LENGTH,
settings.max_frontline_length * 1000,
attack_heading.right,
theater,
)
@@ -69,19 +67,25 @@ class FrontLineConflictDescription:
@classmethod
def frontline_vector(
cls, front_line: FrontLine, theater: ConflictTheater
cls, front_line: FrontLine, theater: ConflictTheater, settings: Settings
) -> Tuple[Point, Heading, int]:
"""
Returns a vector for a valid frontline location avoiding exclusion zones.
"""
center_position, heading = cls.frontline_position(front_line, theater)
center_position, heading = cls.frontline_position(front_line, theater, settings)
left_heading = heading.left
right_heading = heading.right
left_position = cls.extend_ground_position(
center_position, int(FRONTLINE_LENGTH / 2), left_heading, theater
center_position,
int(settings.max_frontline_length * 1000 / 2),
left_heading,
theater,
)
right_position = cls.extend_ground_position(
center_position, int(FRONTLINE_LENGTH / 2), right_heading, theater
center_position,
int(settings.max_frontline_length * 1000 / 2),
right_heading,
theater,
)
distance = int(left_position.distance_to_point(right_position))
return left_position, right_heading, distance
@@ -95,9 +99,12 @@ class FrontLineConflictDescription:
defender: Country,
front_line: FrontLine,
theater: ConflictTheater,
settings: Settings,
) -> FrontLineConflictDescription:
assert cls.has_frontline_between(front_line.blue_cp, front_line.red_cp)
position, heading, distance = cls.frontline_vector(front_line, theater)
position, heading, distance = cls.frontline_vector(
front_line, theater, settings
)
conflict = cls(
position=position,
heading=heading,

View File

@@ -202,6 +202,7 @@ class MissionGenerator:
self.mission.country(self.game.red.country_name),
front_line,
self.game.theater,
self.game.settings,
)
# Generate frontline ops
player_gp = self.game.ground_planners[player_cp.id].units_per_cp[

View File

@@ -84,7 +84,7 @@ class VisualsGenerator:
heading,
distance,
) = FrontLineConflictDescription.frontline_vector(
front_line, self.game.theater
front_line, self.game.theater, self.game.settings
)
if not plane_start:
continue

View File

@@ -394,6 +394,15 @@ class Settings:
min=30,
max=150,
)
# Mission specific
max_frontline_length: int = bounded_int_option(
"Maximum frontline length (km)",
page=MISSION_GENERATOR_PAGE,
section=GAMEPLAY_SECTION,
default=80,
min=1,
max=100,
)
# Performance
perf_smoke_gen: bool = boolean_option(