Disallow selling ground units.

Ground units should be transferred to a new location, not sold and
repurchased.

https://github.com/Khopa/dcs_liberation/issues/823
This commit is contained in:
Dan Albert 2021-04-18 16:32:02 -07:00
parent 3b72c13f9d
commit 5e054cfc77
3 changed files with 12 additions and 6 deletions

View File

@ -5,6 +5,7 @@ Saves from 2.5 are not compatible with 2.6.
## Features/Improvements
* **[Campaign]** Ground units can now be transferred by road. See https://github.com/Khopa/dcs_liberation/wiki/Unit-Transfers for more information.
* **[Campaign]** Ground units can no longer be sold. To move units to a new location, transfer them.
## Fixes

View File

@ -469,12 +469,15 @@ class UnitsDeliveryEvent:
logging.info(f"Refunding {count} {unit_type.id} at {self.to_cp.name}")
game.adjust_budget(price * count, player=self.to_cp.captured)
def available_next_turn(self, unit_type: Type[UnitType]) -> int:
def pending_orders(self, unit_type: Type[UnitType]) -> int:
pending_units = self.units.get(unit_type)
if pending_units is None:
pending_units = 0
return pending_units
def available_next_turn(self, unit_type: Type[UnitType]) -> int:
current_units = self.to_cp.base.total_units_of_type(unit_type)
return pending_units + current_units
return self.pending_orders(unit_type) + current_units
def process(self, game: Game) -> None:
bought_units: Dict[Type[UnitType], int] = {}

View File

@ -1,3 +1,5 @@
from typing import Type
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
QFrame,
@ -65,13 +67,13 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
main_layout.addWidget(scroll)
self.setLayout(main_layout)
def sell(self, unit_type: UnitType):
if self.pending_deliveries.available_next_turn(unit_type) <= 0:
def sell(self, unit_type: Type[UnitType]) -> None:
if self.pending_deliveries.pending_orders(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.",
f"Attempted to cancel order of one {unit_type.id} at {self.cp.name} "
"but no orders are pending.",
QMessageBox.Ok,
)
return