Flesh out intel displays.

* Add enemy air and ground unit reports.
* Changes the summary to be a comparison of relative strengths rather
  than raw enemy numbers.

Fixes https://github.com/Khopa/dcs_liberation/issues/658
This commit is contained in:
Dan Albert
2020-12-25 16:00:44 -08:00
parent 1f4516b954
commit 3bdf1377c0
4 changed files with 195 additions and 25 deletions

View File

@@ -1,32 +1,42 @@
from typing import Optional
from PySide2.QtWidgets import (
QGridLayout,
QGroupBox,
QHBoxLayout,
QLabel,
QPushButton,
QVBoxLayout,
)
from game import Game
from game.income import Income
from qt_ui.windows.intel import IntelWindow
class QIntelBox(QGroupBox):
def __init__(self, game: Game) -> None:
super().__init__("Intel")
self.setProperty("style", "IntelSummary")
self.game = game
columns = QHBoxLayout()
self.setLayout(columns)
summary = QVBoxLayout()
summary = QGridLayout()
columns.addLayout(summary)
self.total_aircraft = QLabel()
summary.addWidget(self.total_aircraft)
self.total_ground_forces = QLabel()
summary.addWidget(self.total_ground_forces)
summary.addWidget(QLabel("Air superiority:"), 0, 0)
self.air_strength = QLabel()
summary.addWidget(self.air_strength, 0, 1)
summary.addWidget(QLabel("Front line:"), 1, 0)
self.ground_strength = QLabel()
summary.addWidget(self.ground_strength, 1, 1)
summary.addWidget(QLabel("Economic strength:"), 2, 0)
self.economic_strength = QLabel()
summary.addWidget(self.economic_strength, 2, 1)
details = QPushButton("Details")
columns.addWidget(details)
@@ -40,17 +50,57 @@ class QIntelBox(QGroupBox):
self.game = game
self.update_summary()
@staticmethod
def forces_strength_text(own: int, enemy: int) -> str:
if not enemy:
return "enemy eliminated"
ratio = own / enemy
if ratio < 0.6:
return "outnumbered"
if ratio < 0.8:
return "slightly outnumbered"
if ratio < 1.2:
return "evenly matched"
if ratio < 1.4:
return "slight advantage"
return "strong advantage"
def economic_strength_text(self) -> str:
assert self.game is not None
own = Income(self.game, player=True).total
enemy = Income(self.game, player=False).total
if not enemy:
return "enemy economy ruined"
ratio = own / enemy
if ratio < 0.6:
return "strong disadvantage"
if ratio < 0.8:
return "slight disadvantage"
if ratio < 1.2:
return "evenly matched"
if ratio < 1.4:
return "slight advantage"
return "strong advantage"
def update_summary(self) -> None:
if self.game is None:
aircraft = 0
ground_units = 0
else:
data = self.game.game_stats.data_per_turn[-1]
aircraft = data.enemy_units.aircraft_count
ground_units = data.enemy_units.vehicles_count
self.total_aircraft.setText(f"Total enemy aircraft: {aircraft}")
self.total_ground_forces.setText(
f"Total enemy ground units: {ground_units}")
self.air_strength.setText("no data")
self.ground_strength.setText("no data")
self.economic_strength.setText("no data")
return
data = self.game.game_stats.data_per_turn[-1]
self.air_strength.setText(self.forces_strength_text(
data.allied_units.aircraft_count,
data.enemy_units.aircraft_count))
self.ground_strength.setText(self.forces_strength_text(
data.allied_units.vehicles_count,
data.enemy_units.vehicles_count))
self.economic_strength.setText(self.economic_strength_text())
def open_details_window(self) -> None:
self.details_window = IntelWindow(self.game)