From ad8e70c250bdd840ddeb5bf0d7b463ed14edaea8 Mon Sep 17 00:00:00 2001 From: RndName Date: Sun, 25 Jul 2021 14:59:56 +0200 Subject: [PATCH] fix generation of empty transfer during cp capture when a cp capture happens and the next cp has pending unit deliveries then they will be redeployed to the newly captured cp. The redeploy was drecreasing the num of pending unit deliveries for the old cp but was not removing them completly from the dict when all were removed (cherry picked from commit 67fa4a891077af74bc9fe99d27c662c0c32da83a) --- changelog.md | 1 + game/unitdelivery.py | 5 ++++- qt_ui/windows/basemenu/QRecruitBehaviour.py | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 5c476b6e..934c12bb 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ Saves from 4.0.0 are compatible with 4.1.0. * **[Mission Generation]** The lua data for other plugins is now generated correctly * **[Mission Generation]** Fixed problem with opfor planning missions against sold ground objects like SAMs * **[Mission Generation]** The legacy always-available tanker option no longer prevents mission creation. +* **[Mission Generation]** Prevent the creation of a transfer order with 0 units for a rare situtation when a point was captured. * **[Mission Generation]** Fix occasional KeyError preventing mission generation when all units of the same type in a convoy were killed. * **[UI]** Statistics window tick marks are now always integers. * **[UI]** Statistics window now shows the correct info for the turn diff --git a/game/unitdelivery.py b/game/unitdelivery.py index ff7841c6..258ea409 100644 --- a/game/unitdelivery.py +++ b/game/unitdelivery.py @@ -39,7 +39,10 @@ class PendingUnitDeliveries: def sell(self, units: dict[UnitType[Any], int]) -> None: for k, v in units.items(): - self.units[k] -= v + if self.units[k] > v: + self.units[k] -= v + else: + del self.units[k] def refund_all(self, game: Game) -> None: self.refund(game, self.units) diff --git a/qt_ui/windows/basemenu/QRecruitBehaviour.py b/qt_ui/windows/basemenu/QRecruitBehaviour.py index 5eb7534a..c62f123c 100644 --- a/qt_ui/windows/basemenu/QRecruitBehaviour.py +++ b/qt_ui/windows/basemenu/QRecruitBehaviour.py @@ -209,8 +209,6 @@ class QRecruitBehaviour: if self.pending_deliveries.available_next_turn(unit_type) > 0: self.budget += unit_type.price self.pending_deliveries.sell({unit_type: 1}) - if self.pending_deliveries.units[unit_type] == 0: - del self.pending_deliveries.units[unit_type] self.update_purchase_controls() self.update_available_budget() return True