Merge pull request #716 from SimonC6R/sold-aircraft-state

Adds a buffer for sold aircraft/vehicles.
This commit is contained in:
Dan Albert
2021-01-05 02:12:49 -08:00
committed by GitHub
4 changed files with 45 additions and 11 deletions

View File

@@ -136,17 +136,12 @@ class QRecruitBehaviour:
self.update_available_budget()
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]
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:
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_available_budget()

View File

@@ -92,7 +92,13 @@ 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
# 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)
self.hangar_status.update_label()

View File

@@ -5,8 +5,10 @@ from PySide2.QtWidgets import (
QScrollArea,
QVBoxLayout,
QWidget,
QMessageBox,
)
from dcs.task import PinpointStrike
from dcs.unittype import FlyingType, UnitType
from game import db
from game.theater import ControlPoint
@@ -57,3 +59,12 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
scroll.setWidget(scroll_content)
main_layout.addWidget(scroll)
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)