mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Clean up convoy code.
This commit is contained in:
@@ -44,7 +44,7 @@ from game.theater.conflicttheater import FrontLine, ReferencePoint
|
||||
from game.theater.theatergroundobject import (
|
||||
TheaterGroundObject,
|
||||
)
|
||||
from game.transfers import RoadTransferOrder
|
||||
from game.transfers import Convoy, RoadTransferOrder
|
||||
from game.utils import Distance, meters, nautical_miles
|
||||
from game.weather import TimeOfDay
|
||||
from gen import Conflict, Package
|
||||
@@ -827,7 +827,7 @@ class QLiberationMap(QGraphicsView):
|
||||
self,
|
||||
scene: QGraphicsScene,
|
||||
frontline: FrontLine,
|
||||
convoys: List[RoadTransferOrder],
|
||||
convoys: List[Convoy],
|
||||
) -> None:
|
||||
"""
|
||||
Thanks to Alquimista for sharing a python implementation of the bezier algorithm this is adapted from.
|
||||
@@ -895,7 +895,15 @@ class QLiberationMap(QGraphicsView):
|
||||
def draw_supply_route_between(self, a: ControlPoint, b: ControlPoint) -> None:
|
||||
scene = self.scene()
|
||||
|
||||
convoys = self._transfers_between(a, b)
|
||||
convoy_map = self.game.transfers.convoys
|
||||
convoys = []
|
||||
convoy = convoy_map.find_convoy(a, b)
|
||||
if convoy is not None:
|
||||
convoys.append(convoy)
|
||||
convoy = convoy_map.find_convoy(b, a)
|
||||
if convoy is not None:
|
||||
convoys.append(convoy)
|
||||
|
||||
frontline = FrontLine(a, b, self.game.theater)
|
||||
if a.front_is_active(b):
|
||||
if DisplayOptions.actual_frontline_pos:
|
||||
@@ -909,7 +917,7 @@ class QLiberationMap(QGraphicsView):
|
||||
self,
|
||||
scene: QGraphicsScene,
|
||||
frontline: FrontLine,
|
||||
convoys: List[RoadTransferOrder],
|
||||
convoys: List[Convoy],
|
||||
) -> None:
|
||||
posx = frontline.position
|
||||
h = frontline.attack_heading
|
||||
@@ -925,7 +933,7 @@ class QLiberationMap(QGraphicsView):
|
||||
self,
|
||||
scene: QGraphicsScene,
|
||||
frontline: FrontLine,
|
||||
convoys: List[RoadTransferOrder],
|
||||
convoys: List[Convoy],
|
||||
) -> None:
|
||||
self.draw_bezier_frontline(scene, frontline, convoys)
|
||||
vector = Conflict.frontline_vector(
|
||||
|
||||
@@ -9,7 +9,7 @@ from PySide2.QtWidgets import (
|
||||
)
|
||||
|
||||
from game.theater import ControlPoint
|
||||
from game.transfers import RoadTransferOrder
|
||||
from game.transfers import Convoy
|
||||
from qt_ui.uiconstants import COLORS
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class SupplyRouteSegment(QGraphicsLineItem):
|
||||
y1: float,
|
||||
control_point_a: ControlPoint,
|
||||
control_point_b: ControlPoint,
|
||||
convoys: List[RoadTransferOrder],
|
||||
convoys: List[Convoy],
|
||||
parent: Optional[QGraphicsItem] = None,
|
||||
) -> None:
|
||||
super().__init__(x0, y0, x1, y1, parent)
|
||||
@@ -37,19 +37,18 @@ class SupplyRouteSegment(QGraphicsLineItem):
|
||||
def has_convoys(self) -> bool:
|
||||
return bool(self.convoys)
|
||||
|
||||
@cached_property
|
||||
def convoy_size(self) -> int:
|
||||
return sum(sum(c.units.values()) for c in self.convoys)
|
||||
|
||||
def make_tooltip(self) -> str:
|
||||
if not self.has_convoys:
|
||||
return "No convoys present on this supply route."
|
||||
units = "units" if self.convoy_size > 1 else "unit"
|
||||
|
||||
return (
|
||||
f"{self.convoy_size} {units} transferring between {self.control_point_a} "
|
||||
f"and {self.control_point_b}."
|
||||
)
|
||||
convoys = []
|
||||
for convoy in self.convoys:
|
||||
units = "units" if convoy.size > 1 else "unit"
|
||||
convoys.append(
|
||||
f"{convoy.size} {units} transferring from {convoy.origin} to "
|
||||
f"{convoy.destination}"
|
||||
)
|
||||
return "\n".join(convoys)
|
||||
|
||||
@property
|
||||
def line_color(self) -> QColor:
|
||||
|
||||
@@ -12,15 +12,15 @@ from PySide2.QtWidgets import (
|
||||
|
||||
from game import db
|
||||
from game.theater import ControlPoint
|
||||
from game.transfers import Convoy, RoadTransferOrder
|
||||
from game.transfers import Convoy
|
||||
from qt_ui.dialogs import Dialog
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.uiconstants import VEHICLES_ICONS
|
||||
|
||||
|
||||
class DepartingConvoyInfo(QGroupBox):
|
||||
def __init__(self, convoy: RoadTransferOrder, game_model: GameModel) -> None:
|
||||
super().__init__(f"To {convoy.destination}")
|
||||
def __init__(self, convoy: Convoy, game_model: GameModel) -> None:
|
||||
super().__init__(f"{convoy.name} to {convoy.destination}")
|
||||
self.convoy = convoy
|
||||
|
||||
main_layout = QVBoxLayout()
|
||||
@@ -61,7 +61,7 @@ class DepartingConvoyInfo(QGroupBox):
|
||||
# complicated. We could instead generate this at the start of the turn (and
|
||||
# update whenever transfers are created or canceled) and also use that time to
|
||||
# precalculate things like the next stop and group names.
|
||||
Dialog.open_new_package_dialog(Convoy(self.convoy), parent=self.window())
|
||||
Dialog.open_new_package_dialog(self.convoy, parent=self.window())
|
||||
|
||||
|
||||
class DepartingConvoysList(QFrame):
|
||||
@@ -78,9 +78,8 @@ class DepartingConvoysList(QFrame):
|
||||
task_box_layout = QGridLayout()
|
||||
scroll_content.setLayout(task_box_layout)
|
||||
|
||||
for convoy in game_model.game.transfers:
|
||||
if convoy.position != cp:
|
||||
continue
|
||||
convoy_map = game_model.game.transfers.convoys
|
||||
for convoy in convoy_map.departing_from(cp):
|
||||
group_info = DepartingConvoyInfo(convoy, game_model)
|
||||
task_box_layout.addWidget(group_info)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user