mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Adds a buffer for sold aircraft/vehicles.
This feature allows you to cancel the sales of aircraft or ground vehicles if needed. Upon clicking the minus button, a count of sold units will be appended to the unit count. This count responds to both further presses of the minus button, and also to presses of the plus button. No further units will be requested for the next turn until all sold units have been re-bought. I've tested a bunch of different scenarios with this: - Selling and rebuying a unit - the budget increases and decreases as expected. - Selling one unit, buying a unit worth the new player budget, and then trying to rebuy the old unit - the old unit cannot be rebought until the budget has been freed up for it. - Closing the base window and re-opening it - the sold unit count is retained. - Ending the turn - the sold unit count is reset back to 0 as expected. Contributes to Khopa/dcs_liberation#365
This commit is contained in:
parent
34bdc0e80b
commit
366ac4ee14
@ -98,6 +98,7 @@ class GlobalAircraftInventory:
|
||||
inventory = self.inventories[control_point]
|
||||
for aircraft, count in control_point.base.aircraft.items():
|
||||
inventory.add_aircraft(aircraft, count)
|
||||
control_point.base.sold_units[aircraft] = 0
|
||||
|
||||
def for_control_point(
|
||||
self,
|
||||
|
||||
@ -29,6 +29,7 @@ class Base:
|
||||
self.aa: Dict[AirDefence, int] = {}
|
||||
self.commision_points: Dict[Type, float] = {}
|
||||
self.strength = 1
|
||||
self.sold_units = {}
|
||||
|
||||
@property
|
||||
def total_aircraft(self) -> int:
|
||||
|
||||
@ -117,6 +117,7 @@ class GroundPlanner:
|
||||
print(key)
|
||||
continue
|
||||
|
||||
self.cp.base.sold_units[key] = 0
|
||||
available = self.cp.base.armor[key]
|
||||
while available > 0:
|
||||
|
||||
|
||||
@ -61,7 +61,13 @@ class QRecruitBehaviour:
|
||||
unitName = QLabel("<b>" + db.unit_type_name_2(unit_type) + "</b>")
|
||||
unitName.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
|
||||
|
||||
existing_units = QLabel(str(existing_units))
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
existing_units = QLabel("<b>{} (-{})</b>".format(existing_units, sold_count))
|
||||
else:
|
||||
existing_units = QLabel(str(existing_units))
|
||||
existing_units.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
|
||||
amount_bought = QLabel("<b>{}</b>".format(str(scheduled_units)))
|
||||
@ -117,9 +123,17 @@ class QRecruitBehaviour:
|
||||
unit_type in self.pending_deliveries.units and "{}".format(self.pending_deliveries.units[unit_type]) or "0"
|
||||
))
|
||||
|
||||
self.existing_units_labels[unit_type].setText("<b>{}</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type)
|
||||
))
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
self.existing_units_labels[unit_type].setText("<b>{} (-{})</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type), self.cp.base.sold_units[unit_type]
|
||||
))
|
||||
else:
|
||||
self.existing_units_labels[unit_type].setText("<b>{}</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type)
|
||||
))
|
||||
|
||||
def update_available_budget(self) -> None:
|
||||
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
|
||||
@ -127,8 +141,16 @@ class QRecruitBehaviour:
|
||||
def buy(self, unit_type: Type[UnitType]):
|
||||
price = db.PRICES[unit_type]
|
||||
if self.budget >= price:
|
||||
self.pending_deliveries.order({unit_type: 1})
|
||||
self.budget -= price
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
self.cp.base.sold_units[unit_type] -= 1
|
||||
self.cp.base.commision_units({unit_type: 1})
|
||||
self.budget -= price
|
||||
else:
|
||||
self.pending_deliveries.order({unit_type: 1})
|
||||
self.budget -= price
|
||||
else:
|
||||
# TODO : display modal warning
|
||||
logging.info("Not enough money !")
|
||||
@ -146,6 +168,7 @@ class QRecruitBehaviour:
|
||||
price = db.PRICES[unit_type]
|
||||
self.budget += price
|
||||
self.cp.base.commit_losses({unit_type: 1})
|
||||
self.cp.base.sold_units[unit_type] += 1
|
||||
|
||||
self._update_count_label(unit_type)
|
||||
self.update_available_budget()
|
||||
|
||||
@ -85,6 +85,8 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
self.setLayout(main_layout)
|
||||
|
||||
def buy(self, unit_type):
|
||||
global_inventory = self.game_model.game.aircraft_inventory
|
||||
inventory = global_inventory.for_control_point(self.cp)
|
||||
if self.maximum_units > 0:
|
||||
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
||||
logging.debug(f"No space for additional aircraft at {self.cp}.")
|
||||
@ -92,7 +94,11 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
self, "No space for additional aircraft",
|
||||
f"There is no parking space left at {self.cp.name} to accommodate another plane.", QMessageBox.Ok)
|
||||
return
|
||||
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
inventory.add_aircraft(unit_type, 1)
|
||||
super().buy(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user