Streamlining

This commit is contained in:
Raffson 2023-10-07 18:53:16 +02:00
parent 75498fe061
commit 62a40db9ea
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
6 changed files with 21 additions and 25 deletions

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Iterator
from dataclasses import dataclass
from datetime import timedelta
from typing import TYPE_CHECKING, Type, Optional
from typing import TYPE_CHECKING, Type
from game.theater import FrontLine
from game.utils import Distance, Speed, kph, dcs_to_shapely_point
@ -23,7 +23,7 @@ if TYPE_CHECKING:
@dataclass
class CasLayout(PatrollingLayout):
ingress: Optional[FlightWaypoint]
ingress: FlightWaypoint
def iter_waypoints(self) -> Iterator[FlightWaypoint]:
yield self.departure
@ -92,17 +92,14 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]):
FrontLineConflictDescription,
)
bounds = FrontLineConflictDescription.frontline_bounds(
location, self.theater, self.coalition.game.settings
)
ingress = bounds.left_position
center = bounds.center
egress = bounds.right_position
bounds = FrontLineConflictDescription.frontline_bounds(location, self.theater)
patrol_start = bounds.left_position
patrol_end = bounds.right_position
start_distance = ingress.distance_to_point(self.flight.departure.position)
end_distance = egress.distance_to_point(self.flight.departure.position)
start_distance = patrol_start.distance_to_point(self.flight.departure.position)
end_distance = patrol_end.distance_to_point(self.flight.departure.position)
if end_distance < start_distance:
patrol_start, patrol_end = ingress, egress
patrol_start, patrol_end = patrol_end, patrol_start
builder = WaypointBuilder(self.flight)
@ -116,7 +113,7 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]):
ip_solver = IpSolver(
dcs_to_shapely_point(self.flight.departure.position),
dcs_to_shapely_point(ingress),
dcs_to_shapely_point(patrol_start),
self.doctrine,
self.threat_zones.all,
)
@ -127,19 +124,19 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]):
if dump_debug_info:
ip_solver.dump_debug_info()
ingress_point = ingress.new_in_same_map(
ingress_point = patrol_start.new_in_same_map(
ingress_point_shapely.x, ingress_point_shapely.y
)
patrol_start_waypoint = builder.nav(
ingress, ingress_egress_altitude, use_agl_patrol_altitude
patrol_start, ingress_egress_altitude, use_agl_patrol_altitude
)
patrol_start_waypoint.name = "FLOT START"
patrol_start_waypoint.pretty_name = "FLOT start"
patrol_start_waypoint.description = "FLOT boundary"
patrol_end_waypoint = builder.nav(
egress, ingress_egress_altitude, use_agl_patrol_altitude
patrol_end, ingress_egress_altitude, use_agl_patrol_altitude
)
patrol_end_waypoint.name = "FLOT END"
patrol_end_waypoint.pretty_name = "FLOT end"
@ -159,7 +156,7 @@ class Builder(IBuilder[CasFlightPlan, CasLayout]):
use_agl_patrol_altitude,
),
nav_from=builder.nav_path(
egress,
patrol_end,
self.flight.arrival.position,
ingress_egress_altitude,
use_agl_patrol_altitude,

View File

@ -366,9 +366,7 @@ class AircraftType(UnitType[Type[FlyingType]]):
@staticmethod
def _migrator() -> Dict[str, str]:
return {
"F-15E Strike Eagle (AI)": "F-15E Strike Eagle"
}
return {"F-15E Strike Eagle (AI)": "F-15E Strike Eagle"}
@classmethod
def named(cls, name: str) -> AircraftType:

View File

@ -86,7 +86,7 @@ class DrawingsGenerator:
"""
for front_line in self.game.theater.conflicts():
bounds = FrontLineConflictDescription.frontline_bounds(
front_line, self.game.theater, self.game.settings
front_line, self.game.theater
)
end_point = bounds.left_position.point_from_heading(

View File

@ -72,11 +72,12 @@ class FrontLineConflictDescription:
@classmethod
def frontline_bounds(
cls, front_line: FrontLine, theater: ConflictTheater, settings: Settings
cls, front_line: FrontLine, theater: ConflictTheater
) -> FrontLineBounds:
"""
Returns a vector for a valid frontline location avoiding exclusion zones.
"""
settings = front_line.coalition.game.settings
center_position, heading = cls.frontline_position(front_line, theater, settings)
left_heading = heading.left
right_heading = heading.right
@ -96,12 +97,12 @@ class FrontLineConflictDescription:
@classmethod
def frontline_cas_conflict(
cls, front_line: FrontLine, theater: ConflictTheater, settings: Settings
cls, front_line: FrontLine, theater: ConflictTheater
) -> FrontLineConflictDescription:
# TODO: Break apart the front-line and air conflict descriptions.
# We're wastefully not caching the front-line bounds here because air conflicts
# can't compute bounds, only a position.
bounds = cls.frontline_bounds(front_line, theater, settings)
bounds = cls.frontline_bounds(front_line, theater)
conflict = cls(
theater=theater,
front_line=front_line,

View File

@ -204,7 +204,7 @@ class MissionGenerator:
player_cp = front_line.blue_cp
enemy_cp = front_line.red_cp
conflict = FrontLineConflictDescription.frontline_cas_conflict(
front_line, self.game.theater, self.game.settings
front_line, self.game.theater
)
# Generate frontline ops
player_gp = self.game.ground_planners[player_cp.id].units_per_cp[

View File

@ -81,7 +81,7 @@ class VisualsGenerator:
continue
bounds = FrontLineConflictDescription.frontline_bounds(
front_line, self.game.theater, self.game.settings
front_line, self.game.theater
)
for offset in range(