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:

View File

@ -189,6 +189,12 @@ class Game:
front_line.control_point_a,
front_line.control_point_b)
def adjust_budget(self, amount: float, player: bool) -> None:
if player:
self.budget += amount
else:
self.enemy_budget += amount
def process_player_income(self):
self.budget += Income(self, player=True).total

View File

@ -21,16 +21,17 @@ from dcs.unittype import FlyingType
from game import db
from gen.ground_forces.ai_ground_planner_db import TYPE_SHORAD
from gen.runways import RunwayAssigner, RunwayData
from gen.ground_forces.combat_stance import CombatStance
from gen.runways import RunwayAssigner, RunwayData
from .base import Base
from .missiontarget import MissionTarget
from .theatergroundobject import (
BaseDefenseGroundObject,
EwrGroundObject,
GenericCarrierGroundObject,
SamGroundObject,
TheaterGroundObject,
VehicleGroupGroundObject, GenericCarrierGroundObject,
VehicleGroupGroundObject,
)
from ..weather import Conditions
@ -366,6 +367,9 @@ class ControlPoint(MissionTarget, ABC):
# TODO: Should be Airbase specific.
def capture(self, game: Game, for_player: bool) -> None:
if self.pending_unit_deliveries is not None:
self.pending_unit_deliveries.refund_all()
if for_player:
self.captured = True
else: