mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Require factories for purchasing ground units.
https://github.com/Khopa/dcs_liberation/issues/986
This commit is contained in:
parent
67b341cbd6
commit
627f18c42b
@ -31,6 +31,7 @@ from game.point_with_heading import PointWithHeading
|
|||||||
from .theatergroundobject import (
|
from .theatergroundobject import (
|
||||||
BaseDefenseGroundObject,
|
BaseDefenseGroundObject,
|
||||||
EwrGroundObject,
|
EwrGroundObject,
|
||||||
|
FactoryGroundObject,
|
||||||
GenericCarrierGroundObject,
|
GenericCarrierGroundObject,
|
||||||
SamGroundObject,
|
SamGroundObject,
|
||||||
TheaterGroundObject,
|
TheaterGroundObject,
|
||||||
@ -312,6 +313,16 @@ class ControlPoint(MissionTarget, ABC):
|
|||||||
connected.extend(cp.transitive_connected_friendly_points(seen))
|
connected.extend(cp.transitive_connected_friendly_points(seen))
|
||||||
return connected
|
return connected
|
||||||
|
|
||||||
|
def can_recruit_ground_units(self, game: Game) -> bool:
|
||||||
|
"""Returns True if this control point is capable of recruiting ground units."""
|
||||||
|
if not game.settings.enable_new_ground_unit_recruitment:
|
||||||
|
return True
|
||||||
|
|
||||||
|
for tgo in self.connected_objectives:
|
||||||
|
if isinstance(tgo, FactoryGroundObject) and not tgo.is_dead:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_carrier(self):
|
def is_carrier(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -56,7 +56,6 @@ class QRecruitBehaviour:
|
|||||||
unit_type: Type[UnitType],
|
unit_type: Type[UnitType],
|
||||||
layout: QLayout,
|
layout: QLayout,
|
||||||
row: int,
|
row: int,
|
||||||
disabled: bool = False,
|
|
||||||
) -> int:
|
) -> int:
|
||||||
exist = QGroupBox()
|
exist = QGroupBox()
|
||||||
exist.setProperty("style", "buy-box")
|
exist.setProperty("style", "buy-box")
|
||||||
@ -100,19 +99,31 @@ class QRecruitBehaviour:
|
|||||||
|
|
||||||
buy = QPushButton("+")
|
buy = QPushButton("+")
|
||||||
buy.setProperty("style", "btn-buy")
|
buy.setProperty("style", "btn-buy")
|
||||||
buy.setDisabled(disabled)
|
buy.setDisabled(not self.enable_purchase(unit_type))
|
||||||
buy.setMinimumSize(16, 16)
|
buy.setMinimumSize(16, 16)
|
||||||
buy.setMaximumSize(16, 16)
|
buy.setMaximumSize(16, 16)
|
||||||
buy.clicked.connect(lambda: self.buy(unit_type))
|
|
||||||
|
def on_buy():
|
||||||
|
self.buy(unit_type)
|
||||||
|
buy.setDisabled(not self.enable_purchase(unit_type))
|
||||||
|
sell.setDisabled(not self.enable_sale(unit_type))
|
||||||
|
|
||||||
|
buy.clicked.connect(on_buy)
|
||||||
buy.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
buy.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||||
|
|
||||||
sell = QPushButton("-")
|
sell = QPushButton("-")
|
||||||
sell.setProperty("style", "btn-sell")
|
sell.setProperty("style", "btn-sell")
|
||||||
sell.setDisabled(disabled)
|
sell.setDisabled(not self.enable_sale(unit_type))
|
||||||
sell.setMinimumSize(16, 16)
|
sell.setMinimumSize(16, 16)
|
||||||
sell.setMaximumSize(16, 16)
|
sell.setMaximumSize(16, 16)
|
||||||
sell.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
sell.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||||
sell.clicked.connect(lambda: self.sell(unit_type))
|
|
||||||
|
def on_sell():
|
||||||
|
self.sell(unit_type)
|
||||||
|
sell.setDisabled(not self.enable_sale(unit_type))
|
||||||
|
buy.setDisabled(not self.enable_purchase(unit_type))
|
||||||
|
|
||||||
|
sell.clicked.connect(on_sell)
|
||||||
|
|
||||||
info = QGroupBox()
|
info = QGroupBox()
|
||||||
info.setProperty("style", "buy-box")
|
info.setProperty("style", "buy-box")
|
||||||
@ -123,7 +134,6 @@ class QRecruitBehaviour:
|
|||||||
|
|
||||||
unitInfo = QPushButton("i")
|
unitInfo = QPushButton("i")
|
||||||
unitInfo.setProperty("style", "btn-info")
|
unitInfo.setProperty("style", "btn-info")
|
||||||
unitInfo.setDisabled(disabled)
|
|
||||||
unitInfo.setMinimumSize(16, 16)
|
unitInfo.setMinimumSize(16, 16)
|
||||||
unitInfo.setMaximumSize(16, 16)
|
unitInfo.setMaximumSize(16, 16)
|
||||||
unitInfo.clicked.connect(lambda: self.info(unit_type))
|
unitInfo.clicked.connect(lambda: self.info(unit_type))
|
||||||
@ -169,13 +179,13 @@ class QRecruitBehaviour:
|
|||||||
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
|
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
|
||||||
|
|
||||||
def buy(self, unit_type: Type[UnitType]):
|
def buy(self, unit_type: Type[UnitType]):
|
||||||
|
if not self.enable_purchase(unit_type):
|
||||||
|
logging.error(f"Purchase of {unit_type.id} not allowed at {self.cp.name}")
|
||||||
|
return
|
||||||
|
|
||||||
price = db.PRICES[unit_type]
|
price = db.PRICES[unit_type]
|
||||||
if self.budget >= price:
|
|
||||||
self.pending_deliveries.order({unit_type: 1})
|
self.pending_deliveries.order({unit_type: 1})
|
||||||
self.budget -= price
|
self.budget -= price
|
||||||
else:
|
|
||||||
# TODO : display modal warning
|
|
||||||
logging.info("Not enough money !")
|
|
||||||
self._update_count_label(unit_type)
|
self._update_count_label(unit_type)
|
||||||
self.update_available_budget()
|
self.update_available_budget()
|
||||||
|
|
||||||
@ -189,6 +199,13 @@ class QRecruitBehaviour:
|
|||||||
self._update_count_label(unit_type)
|
self._update_count_label(unit_type)
|
||||||
self.update_available_budget()
|
self.update_available_budget()
|
||||||
|
|
||||||
|
def enable_purchase(self, unit_type: Type[UnitType]) -> bool:
|
||||||
|
price = db.PRICES[unit_type]
|
||||||
|
return self.budget >= price
|
||||||
|
|
||||||
|
def enable_sale(self, unit_type: Type[UnitType]) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
def info(self, unit_type):
|
def info(self, unit_type):
|
||||||
self.info_window = QUnitInfoWindow(self.game_model.game, unit_type)
|
self.info_window = QUnitInfoWindow(self.game_model.game, unit_type)
|
||||||
self.info_window.show()
|
self.info_window.show()
|
||||||
|
|||||||
@ -77,12 +77,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
for unit_type in sorted_units:
|
for unit_type in sorted_units:
|
||||||
row = self.add_purchase_row(
|
row = self.add_purchase_row(unit_type, task_box_layout, row)
|
||||||
unit_type,
|
|
||||||
task_box_layout,
|
|
||||||
row,
|
|
||||||
disabled=not self.cp.can_operate(unit_type),
|
|
||||||
)
|
|
||||||
stretch = QVBoxLayout()
|
stretch = QVBoxLayout()
|
||||||
stretch.addStretch()
|
stretch.addStretch()
|
||||||
task_box_layout.addLayout(stretch, row, 0)
|
task_box_layout.addLayout(stretch, row, 0)
|
||||||
@ -97,6 +92,20 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
main_layout.addWidget(scroll)
|
main_layout.addWidget(scroll)
|
||||||
self.setLayout(main_layout)
|
self.setLayout(main_layout)
|
||||||
|
|
||||||
|
def enable_purchase(self, unit_type: Type[UnitType]) -> bool:
|
||||||
|
if not issubclass(unit_type, FlyingType):
|
||||||
|
return False
|
||||||
|
if not self.cp.can_operate(unit_type):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def enable_sale(self, unit_type: Type[UnitType]) -> bool:
|
||||||
|
if not issubclass(unit_type, FlyingType):
|
||||||
|
return False
|
||||||
|
if not self.cp.can_operate(unit_type):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def buy(self, unit_type):
|
def buy(self, unit_type):
|
||||||
if self.maximum_units > 0:
|
if self.maximum_units > 0:
|
||||||
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
||||||
|
|||||||
@ -67,14 +67,8 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
main_layout.addWidget(scroll)
|
main_layout.addWidget(scroll)
|
||||||
self.setLayout(main_layout)
|
self.setLayout(main_layout)
|
||||||
|
|
||||||
def sell(self, unit_type: Type[UnitType]) -> None:
|
def enable_purchase(self, unit_type: Type[UnitType]) -> bool:
|
||||||
if self.pending_deliveries.pending_orders(unit_type) <= 0:
|
return self.cp.can_recruit_ground_units(self.game_model.game)
|
||||||
QMessageBox.critical(
|
|
||||||
self,
|
def enable_sale(self, unit_type: Type[UnitType]) -> bool:
|
||||||
"Could not sell ground unit",
|
return self.pending_deliveries.pending_orders(unit_type) > 0
|
||||||
f"Attempted to cancel order of one {unit_type.id} at {self.cp.name} "
|
|
||||||
"but no orders are pending.",
|
|
||||||
QMessageBox.Ok,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
super().sell(unit_type)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user