mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Factor out Coalition from Game.
This commit is contained in:
@@ -12,11 +12,10 @@ from PySide2.QtCore import (
|
||||
)
|
||||
from PySide2.QtGui import QIcon
|
||||
|
||||
from game import db
|
||||
from game.game import Game
|
||||
from game.squadrons import Squadron, Pilot
|
||||
from game.theater.missiontarget import MissionTarget
|
||||
from game.transfers import TransferOrder
|
||||
from game.transfers import TransferOrder, PendingTransfers
|
||||
from gen.ato import AirTaskingOrder, Package
|
||||
from gen.flights.flight import Flight, FlightType
|
||||
from gen.flights.traveltime import TotEstimator
|
||||
@@ -281,9 +280,9 @@ class AtoModel(QAbstractListModel):
|
||||
self.package_models.clear()
|
||||
if self.game is not None:
|
||||
if player:
|
||||
self.ato = self.game.blue_ato
|
||||
self.ato = self.game.blue.ato
|
||||
else:
|
||||
self.ato = self.game.red_ato
|
||||
self.ato = self.game.red.ato
|
||||
else:
|
||||
self.ato = AirTaskingOrder()
|
||||
self.endResetModel()
|
||||
@@ -316,8 +315,12 @@ class TransferModel(QAbstractListModel):
|
||||
super().__init__()
|
||||
self.game_model = game_model
|
||||
|
||||
@property
|
||||
def transfers(self) -> PendingTransfers:
|
||||
return self.game_model.game.coalition_for(player=True).transfers
|
||||
|
||||
def rowCount(self, parent: QModelIndex = QModelIndex()) -> int:
|
||||
return self.game_model.game.transfers.pending_transfer_count
|
||||
return self.transfers.pending_transfer_count
|
||||
|
||||
def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Any:
|
||||
if not index.isValid():
|
||||
@@ -345,7 +348,7 @@ class TransferModel(QAbstractListModel):
|
||||
"""Updates the game with the new unit transfer."""
|
||||
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())
|
||||
# TODO: Needs to regenerate base inventory tab.
|
||||
self.game_model.game.transfers.new_transfer(transfer)
|
||||
self.transfers.new_transfer(transfer)
|
||||
self.endInsertRows()
|
||||
|
||||
def cancel_transfer_at_index(self, index: QModelIndex) -> None:
|
||||
@@ -354,15 +357,15 @@ class TransferModel(QAbstractListModel):
|
||||
|
||||
def cancel_transfer(self, transfer: TransferOrder) -> None:
|
||||
"""Cancels the planned unit transfer at the given index."""
|
||||
index = self.game_model.game.transfers.index_of_transfer(transfer)
|
||||
index = self.transfers.index_of_transfer(transfer)
|
||||
self.beginRemoveRows(QModelIndex(), index, index)
|
||||
# TODO: Needs to regenerate base inventory tab.
|
||||
self.game_model.game.transfers.cancel_transfer(transfer)
|
||||
self.transfers.cancel_transfer(transfer)
|
||||
self.endRemoveRows()
|
||||
|
||||
def transfer_at_index(self, index: QModelIndex) -> TransferOrder:
|
||||
"""Returns the transfer located at the given index."""
|
||||
return self.game_model.game.transfers.transfer_at_index(index.row())
|
||||
return self.transfers.transfer_at_index(index.row())
|
||||
|
||||
|
||||
class AirWingModel(QAbstractListModel):
|
||||
@@ -488,8 +491,8 @@ class GameModel:
|
||||
self.ato_model = AtoModel(self, AirTaskingOrder())
|
||||
self.red_ato_model = AtoModel(self, AirTaskingOrder())
|
||||
else:
|
||||
self.ato_model = AtoModel(self, self.game.blue_ato)
|
||||
self.red_ato_model = AtoModel(self, self.game.red_ato)
|
||||
self.ato_model = AtoModel(self, self.game.blue.ato)
|
||||
self.red_ato_model = AtoModel(self, self.game.red.ato)
|
||||
|
||||
def ato_model_for(self, player: bool) -> AtoModel:
|
||||
if player:
|
||||
|
||||
@@ -24,8 +24,8 @@ class QFactionsInfos(QGroupBox):
|
||||
|
||||
def setGame(self, game: Game):
|
||||
if game is not None:
|
||||
self.player_name.setText(game.player_faction.name)
|
||||
self.enemy_name.setText(game.enemy_faction.name)
|
||||
self.player_name.setText(game.blue.faction.name)
|
||||
self.enemy_name.setText(game.red.faction.name)
|
||||
else:
|
||||
self.player_name.setText("")
|
||||
self.enemy_name.setText("")
|
||||
|
||||
@@ -168,7 +168,7 @@ class QTopPanel(QFrame):
|
||||
package.time_over_target = estimator.earliest_tot()
|
||||
|
||||
def ato_has_clients(self) -> bool:
|
||||
for package in self.game.blue_ato.packages:
|
||||
for package in self.game.blue.ato.packages:
|
||||
for flight in package.flights:
|
||||
if flight.client_count > 0:
|
||||
return True
|
||||
@@ -236,7 +236,7 @@ class QTopPanel(QFrame):
|
||||
|
||||
def check_no_missing_pilots(self) -> bool:
|
||||
missing_pilots = []
|
||||
for package in self.game.blue_ato.packages:
|
||||
for package in self.game.blue.ato.packages:
|
||||
for flight in package.flights:
|
||||
if flight.missing_pilots > 0:
|
||||
missing_pilots.append((package, flight))
|
||||
@@ -282,8 +282,8 @@ class QTopPanel(QFrame):
|
||||
closest_cps[0],
|
||||
closest_cps[1],
|
||||
self.game.theater.controlpoints[0].position,
|
||||
self.game.player_faction.name,
|
||||
self.game.enemy_faction.name,
|
||||
self.game.blue.faction.name,
|
||||
self.game.red.faction.name,
|
||||
)
|
||||
|
||||
unit_map = self.game.initiate_event(game_event)
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import Iterable, Type
|
||||
from PySide2.QtWidgets import QComboBox
|
||||
from dcs.unittype import FlyingType
|
||||
|
||||
from game import db
|
||||
from gen.flights.ai_flight_planner_db import aircraft_for_task
|
||||
from gen.flights.flight import FlightType
|
||||
|
||||
@@ -13,16 +12,12 @@ class QAircraftTypeSelector(QComboBox):
|
||||
"""Combo box for selecting among the given aircraft types."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
aircraft_types: Iterable[Type[FlyingType]],
|
||||
country: str,
|
||||
mission_type: FlightType,
|
||||
self, aircraft_types: Iterable[Type[FlyingType]], mission_type: FlightType
|
||||
) -> None:
|
||||
super().__init__()
|
||||
|
||||
self.model().sort(0)
|
||||
self.setSizeAdjustPolicy(self.AdjustToContents)
|
||||
self.country = country
|
||||
self.update_items(mission_type, aircraft_types)
|
||||
|
||||
def update_items(self, mission_type: FlightType, aircraft_types):
|
||||
|
||||
@@ -336,8 +336,12 @@ class SupplyRouteJs(QObject):
|
||||
|
||||
def find_transports(self) -> List[MultiGroupTransport]:
|
||||
if self.sea_route:
|
||||
return self.find_in_transport_map(self.game.transfers.cargo_ships)
|
||||
return self.find_in_transport_map(self.game.transfers.convoys)
|
||||
return self.find_in_transport_map(
|
||||
self.game.blue.transfers.cargo_ships
|
||||
) + self.find_in_transport_map(self.game.red.transfers.cargo_ships)
|
||||
return self.find_in_transport_map(
|
||||
self.game.blue.transfers.convoys
|
||||
) + self.find_in_transport_map(self.game.red.transfers.convoys)
|
||||
|
||||
@Property(list, notify=activeTransportsChanged)
|
||||
def activeTransports(self) -> List[str]:
|
||||
@@ -672,8 +676,8 @@ class NavMeshJs(QObject):
|
||||
@classmethod
|
||||
def from_game(cls, game: Game) -> NavMeshJs:
|
||||
return NavMeshJs(
|
||||
cls.to_polys(game.blue_navmesh, game.theater),
|
||||
cls.to_polys(game.red_navmesh, game.theater),
|
||||
cls.to_polys(game.blue.nav_mesh, game.theater),
|
||||
cls.to_polys(game.red.nav_mesh, game.theater),
|
||||
)
|
||||
|
||||
|
||||
@@ -870,8 +874,8 @@ class MapModel(QObject):
|
||||
|
||||
def reset_atos(self) -> None:
|
||||
self._flights = self._flights_in_ato(
|
||||
self.game.blue_ato, blue=True
|
||||
) + self._flights_in_ato(self.game.red_ato, blue=False)
|
||||
self.game.blue.ato, blue=True
|
||||
) + self._flights_in_ato(self.game.red.ato, blue=False)
|
||||
self.flightsChanged.emit()
|
||||
|
||||
@Property(list, notify=flightsChanged)
|
||||
|
||||
@@ -3,12 +3,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Iterator
|
||||
|
||||
from PySide2.QtCore import (
|
||||
QItemSelectionModel,
|
||||
QModelIndex,
|
||||
Qt,
|
||||
QSize,
|
||||
)
|
||||
from PySide2.QtCore import QItemSelectionModel, QModelIndex, QSize
|
||||
from PySide2.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QCheckBox,
|
||||
@@ -183,7 +178,7 @@ class AirInventoryView(QWidget):
|
||||
self.table.setSortingEnabled(True)
|
||||
|
||||
def iter_allocated_aircraft(self) -> Iterator[AircraftInventoryData]:
|
||||
for package in self.game_model.game.blue_ato.packages:
|
||||
for package in self.game_model.game.blue.ato.packages:
|
||||
for flight in package.flights:
|
||||
yield from AircraftInventoryData.from_flight(flight)
|
||||
|
||||
|
||||
@@ -73,11 +73,15 @@ class DepartingConvoysList(QFrame):
|
||||
task_box_layout = QGridLayout()
|
||||
scroll_content.setLayout(task_box_layout)
|
||||
|
||||
for convoy in game_model.game.transfers.convoys.departing_from(cp):
|
||||
for convoy in game_model.game.coalition_for(
|
||||
cp.captured
|
||||
).transfers.convoys.departing_from(cp):
|
||||
group_info = DepartingConvoyInfo(convoy)
|
||||
task_box_layout.addWidget(group_info)
|
||||
|
||||
for cargo_ship in game_model.game.transfers.cargo_ships.departing_from(cp):
|
||||
for cargo_ship in game_model.game.coalition_for(
|
||||
cp.captured
|
||||
).transfers.cargo_ships.departing_from(cp):
|
||||
group_info = DepartingConvoyInfo(cargo_ship)
|
||||
task_box_layout.addWidget(group_info)
|
||||
|
||||
|
||||
@@ -195,7 +195,9 @@ class QBaseMenu2(QDialog):
|
||||
ground_unit_limit = self.cp.frontline_unit_count_limit
|
||||
deployable_unit_info = ""
|
||||
|
||||
allocated = self.cp.allocated_ground_units(self.game_model.game.transfers)
|
||||
allocated = self.cp.allocated_ground_units(
|
||||
self.game_model.game.coalition_for(self.cp.captured).transfers
|
||||
)
|
||||
unit_overage = max(
|
||||
allocated.total_present - self.cp.frontline_unit_count_limit, 0
|
||||
)
|
||||
|
||||
@@ -45,7 +45,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
row = 0
|
||||
|
||||
unit_types: Set[AircraftType] = set()
|
||||
for unit_type in self.game_model.game.player_faction.aircrafts:
|
||||
for unit_type in self.game_model.game.blue.faction.aircrafts:
|
||||
if self.cp.is_carrier and not unit_type.carrier_capable:
|
||||
continue
|
||||
if self.cp.is_lha and not unit_type.lha_capable:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
|
||||
from PySide2 import QtCore
|
||||
from PySide2.QtGui import Qt
|
||||
from PySide2.QtWidgets import (
|
||||
QComboBox,
|
||||
@@ -307,7 +306,7 @@ class QBuyGroupForGroundObjectDialog(QDialog):
|
||||
self.buySamBox = QGroupBox("Buy SAM site :")
|
||||
self.buyArmorBox = QGroupBox("Buy defensive position :")
|
||||
|
||||
faction = self.game.player_faction
|
||||
faction = self.game.blue.faction
|
||||
|
||||
# Sams
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class QFlightCreator(QDialog):
|
||||
self.game = game
|
||||
self.package = package
|
||||
self.custom_name_text = None
|
||||
self.country = self.game.player_country
|
||||
self.country = self.game.blue.country_name
|
||||
|
||||
self.setWindowTitle("Create flight")
|
||||
self.setWindowIcon(EVENT_ICONS["strike"])
|
||||
@@ -52,7 +52,6 @@ class QFlightCreator(QDialog):
|
||||
|
||||
self.aircraft_selector = QAircraftTypeSelector(
|
||||
self.game.aircraft_inventory.available_types_for_player,
|
||||
self.game.player_country,
|
||||
self.task_selector.currentData(),
|
||||
)
|
||||
self.aircraft_selector.setCurrentIndex(0)
|
||||
|
||||
Reference in New Issue
Block a user