Refunding unfulfilled orders on capture.

Fixes https://github.com/Khopa/dcs_liberation/issues/682
This commit is contained in:
Dan Albert
2020-12-28 00:47:42 -08:00
parent 802eff1faa
commit de325c1208
3 changed files with 26 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ from game.operation.operation import Operation
from game.theater import ControlPoint
from gen import AirTaskingOrder
from gen.ground_forces.combat_stance import CombatStance
from ..db import PRICES
from ..unitmap import UnitMap
if TYPE_CHECKING:
@@ -362,6 +363,19 @@ class UnitsDeliveryEvent(Event):
for k, v in units.items():
self.units[k] = self.units.get(k, 0) + v
def refund_all(self) -> None:
while self.units:
unit_type, count = self.units.popitem()
try:
price = PRICES[unit_type]
except KeyError:
logging.error(f"Could not refund {unit_type.id}, price unknown")
continue
logging.info(
f"Refunding {count} {unit_type.id} at {self.to_cp.name}")
self.game.adjust_budget(price * count, player=self.to_cp.captured)
def skip(self) -> None:
for k, v in self.units.items():
if self.to_cp.captured: