mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Refactor the sell unit changes as requested.
It works more simply now, and also doesn't immediately sell the unit. Also adds a matching UI dialog popup for selling too many ground units.
This commit is contained in:
@@ -342,6 +342,8 @@ class UnitsDeliveryEvent:
|
||||
def __init__(self, control_point: ControlPoint) -> None:
|
||||
self.to_cp = control_point
|
||||
self.units: Dict[Type[UnitType], int] = {}
|
||||
self.bought_units = {}
|
||||
self.sold_units = {}
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "Pending delivery to {}".format(self.to_cp)
|
||||
@@ -350,6 +352,10 @@ class UnitsDeliveryEvent:
|
||||
for k, v in units.items():
|
||||
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]]:
|
||||
while self.units:
|
||||
yield self.units.popitem()
|
||||
@@ -371,7 +377,16 @@ class UnitsDeliveryEvent:
|
||||
coalition = "Ally" if self.to_cp.captured else "Enemy"
|
||||
aircraft = unit_type.id
|
||||
name = self.to_cp.name
|
||||
game.message(
|
||||
f"{coalition} reinforcements: {aircraft} x {count} at {name}")
|
||||
self.to_cp.base.commision_units(self.units)
|
||||
if count >= 0:
|
||||
self.bought_units[unit_type] = count
|
||||
game.message(
|
||||
f"{coalition} reinforcements: {aircraft} x {count} at {name}")
|
||||
else:
|
||||
self.sold_units[unit_type] = 0 - count
|
||||
game.message(
|
||||
f"{coalition} sold: {aircraft} x {0 - count} at {name}")
|
||||
self.to_cp.base.commision_units(self.bought_units)
|
||||
self.to_cp.base.commit_losses(self.sold_units)
|
||||
self.units = {}
|
||||
self.bought_units = {}
|
||||
self.sold_units = {}
|
||||
|
||||
@@ -98,7 +98,6 @@ 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,7 +29,6 @@ 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:
|
||||
|
||||
Reference in New Issue
Block a user