Refactor front line code to make sides explicit.

A was intended to be the blue point and B was intended to be the red
point. Make this a part of the name so that's clear, and clean up
related code to keep that reliable.
This commit is contained in:
Dan Albert
2021-05-07 20:56:39 -07:00
parent 12f474ecbe
commit b0c24f6e51
13 changed files with 125 additions and 154 deletions

View File

@@ -409,13 +409,7 @@ class ObjectiveFinder:
def front_lines(self) -> Iterator[FrontLine]:
"""Iterates over all active front lines in the theater."""
for cp in self.friendly_control_points():
for connected in cp.connected_points:
if connected.is_friendly(self.is_player):
continue
if Conflict.has_frontline_between(cp, connected):
yield FrontLine(cp, connected, self.game.theater)
yield from self.game.theater.conflicts()
def vulnerable_control_points(self) -> Iterator[ControlPoint]:
"""Iterates over friendly CPs that are vulnerable to enemy CPs.
@@ -447,19 +441,19 @@ class ObjectiveFinder:
def convoys(self) -> Iterator[Convoy]:
for front_line in self.front_lines():
if front_line.control_point_a.is_friendly(self.is_player):
enemy_cp = front_line.control_point_a
if front_line.blue_cp.is_friendly(self.is_player):
enemy_cp = front_line.blue_cp
else:
enemy_cp = front_line.control_point_b
enemy_cp = front_line.red_cp
yield from self.game.transfers.convoys.travelling_to(enemy_cp)
def cargo_ships(self) -> Iterator[CargoShip]:
for front_line in self.front_lines():
if front_line.control_point_a.is_friendly(self.is_player):
enemy_cp = front_line.control_point_a
if front_line.blue_cp.is_friendly(self.is_player):
enemy_cp = front_line.blue_cp
else:
enemy_cp = front_line.control_point_b
enemy_cp = front_line.red_cp
yield from self.game.transfers.cargo_ships.travelling_to(enemy_cp)

View File

@@ -1320,11 +1320,9 @@ class FlightPlanBuilder:
def racetrack_for_frontline(
self, origin: Point, front_line: FrontLine
) -> Tuple[Point, Point]:
ally_cp, enemy_cp = front_line.control_points
# Find targets waypoints
ingress, heading, distance = Conflict.frontline_vector(
ally_cp, enemy_cp, self.game.theater
front_line, self.game.theater
)
center = ingress.point_from_heading(heading, distance / 2)
orbit_center = center.point_from_heading(
@@ -1533,7 +1531,7 @@ class FlightPlanBuilder:
raise InvalidObjectiveLocation(flight.flight_type, location)
ingress, heading, distance = Conflict.frontline_vector(
location.control_points[0], location.control_points[1], self.game.theater
location, self.game.theater
)
center = ingress.point_from_heading(heading, distance / 2)
egress = ingress.point_from_heading(heading, distance)