From dd2b61edf3eddac169e2293e93987284fc167d82 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 24 Oct 2020 12:24:29 -0700 Subject: [PATCH] Use FrontLine in ConflictTheater.conflicts. --- game/game.py | 17 +++++++++++------ game/operation/operation.py | 4 +++- gen/briefinggen.py | 10 +++------- gen/visualgen.py | 4 +++- theater/conflicttheater.py | 11 +++++++---- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/game/game.py b/game/game.py index bd0f68f7..2b8f7689 100644 --- a/game/game.py +++ b/game/game.py @@ -141,8 +141,10 @@ class Game: self.events.append(event_class(self, player_cp, enemy_cp, enemy_cp.position, self.player_name, self.enemy_name)) def _generate_events(self): - for player_cp, enemy_cp in self.theater.conflicts(True): - self._generate_player_event(FrontlineAttackEvent, player_cp, enemy_cp) + for front_line in self.theater.conflicts(True): + self._generate_player_event(FrontlineAttackEvent, + front_line.control_point_a, + front_line.control_point_b) def commision_unit_types(self, cp: ControlPoint, for_task: Task) -> List[UnitType]: importance_factor = (cp.importance - IMPORTANCE_LOW) / (IMPORTANCE_HIGH - IMPORTANCE_LOW) @@ -388,10 +390,13 @@ class Game: points = [] # By default, use the existing frontline conflict position - for conflict in self.theater.conflicts(): - points.append(Conflict.frontline_position(self.theater, conflict[0], conflict[1])[0]) - points.append(conflict[0].position) - points.append(conflict[1].position) + for front_line in self.theater.conflicts(): + position = Conflict.frontline_position(self.theater, + front_line.control_point_a, + front_line.control_point_b) + points.append(position[0]) + points.append(front_line.control_point_a.position) + points.append(front_line.control_point_b.position) # If there is no conflict take the center point between the two nearest opposing bases if len(points) == 0: diff --git a/game/operation/operation.py b/game/operation/operation.py index 3c32210c..4b738c1f 100644 --- a/game/operation/operation.py +++ b/game/operation/operation.py @@ -253,7 +253,9 @@ class Operation: # Generate ground units on frontline everywhere jtacs: List[JtacInfo] = [] - for player_cp, enemy_cp in self.game.theater.conflicts(True): + for front_line in self.game.theater.conflicts(True): + player_cp = front_line.control_point_a + enemy_cp = front_line.control_point_b conflict = Conflict.frontline_cas_conflict(self.attacker_name, self.defender_name, self.current_mission.country(self.attacker_country), self.current_mission.country(self.defender_country), diff --git a/gen/briefinggen.py b/gen/briefinggen.py index 63f29396..bd9acf0d 100644 --- a/gen/briefinggen.py +++ b/gen/briefinggen.py @@ -194,14 +194,10 @@ class BriefingGenerator(MissionInfoGenerator): conflict_number = 0 - for c in self.game.theater.conflicts(): + for front_line in self.game.theater.conflicts(from_player=True): conflict_number = conflict_number + 1 - if c[0].captured: - player_base = c[0] - enemy_base = c[1] - else: - player_base = c[1] - enemy_base = c[0] + player_base = front_line.control_point_a + enemy_base = front_line.control_point_b has_numerical_superiority = player_base.base.total_armor > enemy_base.base.total_armor self.description += self.__random_frontline_sentence(player_base.name, enemy_base.name) diff --git a/gen/visualgen.py b/gen/visualgen.py index 5bc315e5..efd0c1f9 100644 --- a/gen/visualgen.py +++ b/gen/visualgen.py @@ -98,7 +98,9 @@ class VisualGenerator: self.game = game def _generate_frontline_smokes(self): - for from_cp, to_cp in self.game.theater.conflicts(): + for front_line in self.game.theater.conflicts(): + from_cp = front_line.control_point_a + to_cp = front_line.control_point_b if from_cp.is_global or to_cp.is_global: continue diff --git a/theater/conflicttheater.py b/theater/conflicttheater.py index 4339236b..4095f2aa 100644 --- a/theater/conflicttheater.py +++ b/theater/conflicttheater.py @@ -1,7 +1,6 @@ from __future__ import annotations -import json -from typing import Any, Dict, Iterator, List, Optional, Tuple +from typing import Any, Dict, Iterator, List, Optional, Tuple, TYPE_CHECKING from dcs.mapping import Point from dcs.terrain import ( @@ -17,6 +16,9 @@ from dcs.terrain.terrain import Terrain from .controlpoint import ControlPoint from .landmap import Landmap, load_landmap, poly_contains +if TYPE_CHECKING: + from . import FrontLine + SIZE_TINY = 150 SIZE_SMALL = 600 SIZE_REGULAR = 1000 @@ -125,10 +127,11 @@ class ConflictTheater: def player_points(self) -> List[ControlPoint]: return [point for point in self.controlpoints if point.captured] - def conflicts(self, from_player=True) -> Iterator[Tuple[ControlPoint, ControlPoint]]: + def conflicts(self, from_player=True) -> Iterator[FrontLine]: + from . import FrontLine # Circular import that needs to be resolved. for cp in [x for x in self.controlpoints if x.captured == from_player]: for connected_point in [x for x in cp.connected_points if x.captured != from_player]: - yield cp, connected_point + yield FrontLine(cp, connected_point) def enemy_points(self) -> List[ControlPoint]: return [point for point in self.controlpoints if not point.captured]