mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Merge pull request #716 from SimonC6R/sold-aircraft-state
Adds a buffer for sold aircraft/vehicles.
This commit is contained in:
commit
8a9177b459
@ -350,6 +350,10 @@ class UnitsDeliveryEvent:
|
|||||||
for k, v in units.items():
|
for k, v in units.items():
|
||||||
self.units[k] = self.units.get(k, 0) + v
|
self.units[k] = self.units.get(k, 0) + v
|
||||||
|
|
||||||
|
def sell(self, units: Dict[Type[UnitType], int]) -> None:
|
||||||
|
for k, v in units.items():
|
||||||
|
self.units[k] = self.units.get(k, 0) - v
|
||||||
|
|
||||||
def consume_each_order(self) -> Iterator[Tuple[Type[UnitType], int]]:
|
def consume_each_order(self) -> Iterator[Tuple[Type[UnitType], int]]:
|
||||||
while self.units:
|
while self.units:
|
||||||
yield self.units.popitem()
|
yield self.units.popitem()
|
||||||
@ -366,12 +370,30 @@ class UnitsDeliveryEvent:
|
|||||||
f"Refunding {count} {unit_type.id} at {self.to_cp.name}")
|
f"Refunding {count} {unit_type.id} at {self.to_cp.name}")
|
||||||
game.adjust_budget(price * count, player=self.to_cp.captured)
|
game.adjust_budget(price * count, player=self.to_cp.captured)
|
||||||
|
|
||||||
|
def available_next_turn(self, unit_type: Type[UnitType]) -> int:
|
||||||
|
pending_units = self.units.get(unit_type)
|
||||||
|
if pending_units is None:
|
||||||
|
pending_units = 0
|
||||||
|
current_units = self.to_cp.base.total_units_of_type(unit_type)
|
||||||
|
return pending_units + current_units
|
||||||
|
|
||||||
def process(self, game: Game) -> None:
|
def process(self, game: Game) -> None:
|
||||||
|
bought_units: Dict[Type[UnitType], int] = {}
|
||||||
|
sold_units: Dict[Type[UnitType], int] = {}
|
||||||
for unit_type, count in self.units.items():
|
for unit_type, count in self.units.items():
|
||||||
coalition = "Ally" if self.to_cp.captured else "Enemy"
|
coalition = "Ally" if self.to_cp.captured else "Enemy"
|
||||||
aircraft = unit_type.id
|
aircraft = unit_type.id
|
||||||
name = self.to_cp.name
|
name = self.to_cp.name
|
||||||
game.message(
|
if count >= 0:
|
||||||
f"{coalition} reinforcements: {aircraft} x {count} at {name}")
|
bought_units[unit_type] = count
|
||||||
self.to_cp.base.commision_units(self.units)
|
game.message(
|
||||||
|
f"{coalition} reinforcements: {aircraft} x {count} at {name}")
|
||||||
|
else:
|
||||||
|
sold_units[unit_type] = -count
|
||||||
|
game.message(
|
||||||
|
f"{coalition} sold: {aircraft} x {-count} at {name}")
|
||||||
|
self.to_cp.base.commision_units(bought_units)
|
||||||
|
self.to_cp.base.commit_losses(sold_units)
|
||||||
self.units = {}
|
self.units = {}
|
||||||
|
bought_units = {}
|
||||||
|
sold_units = {}
|
||||||
|
|||||||
@ -136,17 +136,12 @@ class QRecruitBehaviour:
|
|||||||
self.update_available_budget()
|
self.update_available_budget()
|
||||||
|
|
||||||
def sell(self, unit_type):
|
def sell(self, unit_type):
|
||||||
if self.pending_deliveries.units.get(unit_type, 0) > 0:
|
if self.pending_deliveries.available_next_turn(unit_type) > 0:
|
||||||
price = db.PRICES[unit_type]
|
price = db.PRICES[unit_type]
|
||||||
self.budget += price
|
self.budget += price
|
||||||
self.pending_deliveries.units[unit_type] = self.pending_deliveries.units[unit_type] - 1
|
self.pending_deliveries.sell({unit_type: 1})
|
||||||
if self.pending_deliveries.units[unit_type] == 0:
|
if self.pending_deliveries.units[unit_type] == 0:
|
||||||
del self.pending_deliveries.units[unit_type]
|
del self.pending_deliveries.units[unit_type]
|
||||||
elif self.cp.base.total_units_of_type(unit_type) > 0:
|
|
||||||
price = db.PRICES[unit_type]
|
|
||||||
self.budget += price
|
|
||||||
self.cp.base.commit_losses({unit_type: 1})
|
|
||||||
|
|
||||||
self._update_count_label(unit_type)
|
self._update_count_label(unit_type)
|
||||||
self.update_available_budget()
|
self.update_available_budget()
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,13 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
self, "No space for additional aircraft",
|
self, "No space for additional aircraft",
|
||||||
f"There is no parking space left at {self.cp.name} to accommodate another plane.", QMessageBox.Ok)
|
f"There is no parking space left at {self.cp.name} to accommodate another plane.", QMessageBox.Ok)
|
||||||
return
|
return
|
||||||
|
# If we change our mind about selling, we want the aircraft to be put
|
||||||
|
# back in the inventory immediately.
|
||||||
|
elif self.pending_deliveries.units.get(unit_type, 0) < 0:
|
||||||
|
global_inventory = self.game_model.game.aircraft_inventory
|
||||||
|
inventory = global_inventory.for_control_point(self.cp)
|
||||||
|
inventory.add_aircraft(unit_type, 1)
|
||||||
|
|
||||||
super().buy(unit_type)
|
super().buy(unit_type)
|
||||||
self.hangar_status.update_label()
|
self.hangar_status.update_label()
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,10 @@ from PySide2.QtWidgets import (
|
|||||||
QScrollArea,
|
QScrollArea,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
|
QMessageBox,
|
||||||
)
|
)
|
||||||
from dcs.task import PinpointStrike
|
from dcs.task import PinpointStrike
|
||||||
|
from dcs.unittype import FlyingType, UnitType
|
||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
from game.theater import ControlPoint
|
from game.theater import ControlPoint
|
||||||
@ -57,3 +59,12 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
scroll.setWidget(scroll_content)
|
scroll.setWidget(scroll_content)
|
||||||
main_layout.addWidget(scroll)
|
main_layout.addWidget(scroll)
|
||||||
self.setLayout(main_layout)
|
self.setLayout(main_layout)
|
||||||
|
|
||||||
|
def sell(self, unit_type: UnitType):
|
||||||
|
if self.pending_deliveries.available_next_turn(unit_type) <= 0:
|
||||||
|
QMessageBox.critical(
|
||||||
|
self, "Could not sell ground unit",
|
||||||
|
f"Attempted to sell one {unit_type.id} at {self.cp.name} "
|
||||||
|
"but none are available.", QMessageBox.Ok)
|
||||||
|
return
|
||||||
|
super().sell(unit_type)
|
||||||
Loading…
x
Reference in New Issue
Block a user