mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Refactor ground objects and prepare template system
- completly refactored the way TGO handles groups and replaced the usage of the pydcs ground groups (vehicle, ship, static) with an own Group and Unit class. - this allows us to only take care of dcs group generation during miz generation, where it should have always been. - We can now have any type of unit (even statics) in the same logic ground group we handle in liberation. this is independent from the dcs group handling. the dcs group will only be genarted when takeoff is pressed. - Refactored the unitmap and the scenery object handling to adopt to changes that now TGOs can hold all Units we want. - Cleaned up many many many lines of uneeded hacks to build stuff around dcs groups. - Removed IDs for TGOs as the names we generate are unique and for liberation to work we need no ids. Unique IDs for dcs will be generated for the units and groups only.
This commit is contained in:
@@ -35,7 +35,8 @@ class LossGrid(QGridLayout):
|
||||
self.add_loss_rows(
|
||||
debriefing.airlift_losses_by_type(player), lambda u: f"{u} from airlift"
|
||||
)
|
||||
self.add_loss_rows(debriefing.building_losses_by_type(player), lambda u: u)
|
||||
self.add_loss_rows(debriefing.ground_object_losses_by_type(player), lambda u: u)
|
||||
self.add_loss_rows(debriefing.scenery_losses_by_type(player), lambda u: u)
|
||||
|
||||
# TODO: Display dead ground object units and runways.
|
||||
|
||||
|
||||
@@ -169,12 +169,14 @@ class QWaitingForMissionResultWindow(QDialog):
|
||||
update_layout,
|
||||
)
|
||||
self.add_update_row(
|
||||
"Ground units lost at objective areas",
|
||||
"Ground Objects destroyed",
|
||||
len(list(debriefing.ground_object_losses)),
|
||||
update_layout,
|
||||
)
|
||||
self.add_update_row(
|
||||
"Buildings destroyed", len(list(debriefing.building_losses)), update_layout
|
||||
"Scenery Objects destroyed",
|
||||
len(list(debriefing.scenery_object_losses)),
|
||||
update_layout,
|
||||
)
|
||||
self.add_update_row(
|
||||
"Base capture events", len(debriefing.base_captures), update_layout
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
|
||||
from PySide2.QtGui import QPixmap
|
||||
from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QVBoxLayout
|
||||
from game.theater import GroundUnit
|
||||
|
||||
from game.config import REWARDS
|
||||
|
||||
@@ -9,16 +10,16 @@ from game.config import REWARDS
|
||||
class QBuildingInfo(QGroupBox):
|
||||
def __init__(self, building, ground_object):
|
||||
super(QBuildingInfo, self).__init__()
|
||||
self.building = building
|
||||
self.building: GroundUnit = building
|
||||
self.ground_object = ground_object
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
self.header = QLabel()
|
||||
path = os.path.join(
|
||||
"./resources/ui/units/buildings/" + self.building.dcs_identifier + ".png"
|
||||
"./resources/ui/units/buildings/" + self.building.type + ".png"
|
||||
)
|
||||
if self.building.is_dead:
|
||||
if not self.building.alive:
|
||||
pixmap = QPixmap("./resources/ui/units/buildings/dead.png")
|
||||
elif os.path.isfile(path):
|
||||
pixmap = QPixmap(path)
|
||||
@@ -26,8 +27,8 @@ class QBuildingInfo(QGroupBox):
|
||||
pixmap = QPixmap("./resources/ui/units/buildings/missing.png")
|
||||
self.header.setPixmap(pixmap)
|
||||
name = "<b>{}</b> {}".format(
|
||||
self.building.dcs_identifier[0:18],
|
||||
"[DEAD]" if self.building.is_dead else "",
|
||||
self.building.type[0:18],
|
||||
"[DEAD]" if not self.building.alive else "",
|
||||
)
|
||||
self.name = QLabel(name)
|
||||
self.name.setProperty("style", "small")
|
||||
@@ -35,9 +36,11 @@ class QBuildingInfo(QGroupBox):
|
||||
layout.addWidget(self.header)
|
||||
layout.addWidget(self.name)
|
||||
|
||||
if self.building.category in REWARDS.keys():
|
||||
income_label_text = "Value: " + str(REWARDS[self.building.category]) + "M"
|
||||
if self.building.is_dead:
|
||||
if self.ground_object.category in REWARDS.keys():
|
||||
income_label_text = (
|
||||
"Value: " + str(REWARDS[self.ground_object.category]) + "M"
|
||||
)
|
||||
if not self.building.alive:
|
||||
income_label_text = "<s>" + income_label_text + "</s>"
|
||||
self.reward = QLabel(income_label_text)
|
||||
layout.addWidget(self.reward)
|
||||
|
||||
@@ -107,58 +107,21 @@ class QGroundObjectMenu(QDialog):
|
||||
self.intelLayout = QGridLayout()
|
||||
i = 0
|
||||
for g in self.ground_object.groups:
|
||||
if not hasattr(g, "units_losts"):
|
||||
g.units_losts = []
|
||||
for unit in g.units:
|
||||
unit_display_name = unit.type
|
||||
dcs_unit_type = vehicles.vehicle_map.get(unit.type)
|
||||
if dcs_unit_type is not None:
|
||||
# Hack: Don't know which variant is used.
|
||||
try:
|
||||
unit_display_name = next(
|
||||
GroundUnitType.for_dcs_type(dcs_unit_type)
|
||||
).name
|
||||
except StopIteration:
|
||||
pass
|
||||
self.intelLayout.addWidget(
|
||||
QLabel(
|
||||
"<b>Unit #"
|
||||
+ str(unit.id)
|
||||
+ " - "
|
||||
+ str(unit_display_name)
|
||||
+ "</b>"
|
||||
),
|
||||
i,
|
||||
0,
|
||||
QLabel(f"<b>Unit {str(unit.display_name)}</b>"), i, 0
|
||||
)
|
||||
i = i + 1
|
||||
|
||||
for unit in g.units_losts:
|
||||
dcs_unit_type = vehicles.vehicle_map.get(unit.type)
|
||||
if dcs_unit_type is None:
|
||||
continue
|
||||
|
||||
# Hack: Don't know which variant is used.
|
||||
|
||||
try:
|
||||
unit_type = next(GroundUnitType.for_dcs_type(dcs_unit_type))
|
||||
name = unit_type.name
|
||||
price = unit_type.price
|
||||
except StopIteration:
|
||||
name = dcs_unit_type.name
|
||||
price = 0
|
||||
|
||||
self.intelLayout.addWidget(
|
||||
QLabel(f"<b>Unit #{unit.id} - {name}</b> [DEAD]"), i, 0
|
||||
)
|
||||
if self.cp.captured:
|
||||
if not unit.alive and self.cp.captured:
|
||||
price = unit.unit_type.price if unit.unit_type else 0
|
||||
repair = QPushButton(f"Repair [{price}M]")
|
||||
repair.setProperty("style", "btn-success")
|
||||
repair.clicked.connect(
|
||||
lambda u=unit, g=g, p=unit_type.price: self.repair_unit(g, u, p)
|
||||
lambda u=unit, p=price: self.repair_unit(u, p)
|
||||
)
|
||||
self.intelLayout.addWidget(repair, i, 1)
|
||||
i = i + 1
|
||||
i += 1
|
||||
|
||||
stretch = QVBoxLayout()
|
||||
stretch.addStretch()
|
||||
self.intelLayout.addLayout(stretch, i, 0)
|
||||
@@ -169,19 +132,19 @@ class QGroundObjectMenu(QDialog):
|
||||
j = 0
|
||||
total_income = 0
|
||||
received_income = 0
|
||||
for i, building in enumerate(self.buildings):
|
||||
if building.dcs_identifier not in FORTIFICATION_BUILDINGS:
|
||||
for static in self.ground_object.statics:
|
||||
if static not in FORTIFICATION_BUILDINGS:
|
||||
self.buildingsLayout.addWidget(
|
||||
QBuildingInfo(building, self.ground_object), j / 3, j % 3
|
||||
QBuildingInfo(static, self.ground_object), j / 3, j % 3
|
||||
)
|
||||
j = j + 1
|
||||
|
||||
if building.category in REWARDS.keys():
|
||||
total_income = total_income + REWARDS[building.category]
|
||||
if not building.is_dead:
|
||||
received_income = received_income + REWARDS[building.category]
|
||||
if self.ground_object.category in REWARDS.keys():
|
||||
total_income += REWARDS[self.ground_object.category]
|
||||
if static.alive:
|
||||
received_income += REWARDS[self.ground_object.category]
|
||||
else:
|
||||
logging.warning(building.category + " not in REWARDS")
|
||||
logging.warning(self.ground_object.category + " not in REWARDS")
|
||||
|
||||
self.financesBox = QGroupBox("Finances: ")
|
||||
self.financesBoxLayout = QGridLayout()
|
||||
@@ -235,11 +198,10 @@ class QGroundObjectMenu(QDialog):
|
||||
self.sell_all_button.setText("Disband (+$" + str(self.total_value) + "M)")
|
||||
self.total_value = total_value
|
||||
|
||||
def repair_unit(self, group, unit, price):
|
||||
def repair_unit(self, unit, price):
|
||||
if self.game.blue.budget > price:
|
||||
self.game.blue.budget -= price
|
||||
group.units_losts = [u for u in group.units_losts if u.id != unit.id]
|
||||
group.units.append(unit)
|
||||
unit.alive = True
|
||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
||||
|
||||
# Remove destroyed units in the vicinity
|
||||
|
||||
Reference in New Issue
Block a user