From 2cf3b3be2b91ed5700c3168a927f2b4919819ddf Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 7 May 2021 17:20:23 -0700 Subject: [PATCH] Fix bug causing overpurchase of aircraft. After fulfilling a request we were not exiting the loop, so we'd fulfill the request for the aircraft at _all_ the bases capable of operating it until either the bases were full or the budget ran out. In factions like Iraq 1991 this could cause the budget to be spent on tons of cheap MiG-19s while never buying the more expensive Su-17s or Su-24s that they need to actually complete a package. https://github.com/dcs-liberation/dcs_liberation/issues/1058 --- changelog.md | 5 +++-- game/procurement.py | 32 +++++++++++++++++++------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 20558db0..9cf83eb7 100644 --- a/changelog.md +++ b/changelog.md @@ -10,11 +10,12 @@ Saves from 2.5 are not compatible with 3.0. * **[UI]** Campaigns generated for an older or newer version of the game will now be marked as incompatible. They can still be played, but bugs may be present. * **[Modding]** Campaigns now choose locations for factories to spawn. * **[Modding]** Can now install custom factions to /Liberation/Factions instead of the Liberation install directory. -* **[Performance Settings]** Added a settings to lower the number of smoke effects generated on frontlines. Lowered default settings for frontline smoke generators, so less smoke should be generated by default. - +* **[Performance Settings]** Added a settings to lower the number of smoke effects generated on frontlines. Lowered default settings for frontline smoke generators, so less smoke should be generated by default. ## Fixes +* **[Campaign AI]** Fixed bug causing AI to over-purchase cheap aircraft. + # 2.5.1 ## Features/Improvements diff --git a/game/procurement.py b/game/procurement.py index 28a5d9bb..d3410a12 100644 --- a/game/procurement.py +++ b/game/procurement.py @@ -192,21 +192,27 @@ class ProcurementAi: aircraft_for_task(request.task_capability), airbase, request.number, budget ) + def fulfill_aircraft_request( + self, request: AircraftProcurementRequest, budget: float + ) -> float: + for airbase in self.best_airbases_for(request): + unit = self.affordable_aircraft_for(request, airbase, budget) + if unit is None: + # Can't afford any aircraft capable of performing the + # required mission that can operate from this airbase. We + # might be able to afford aircraft at other airbases though, + # in the case where the airbase we attempted to use is only + # able to operate expensive aircraft. + continue + + budget -= db.PRICES[unit] * request.number + airbase.pending_unit_deliveries.order({unit: request.number}) + break + return budget + def purchase_aircraft(self, budget: float) -> float: for request in self.game.procurement_requests_for(self.is_player): - for airbase in self.best_airbases_for(request): - unit = self.affordable_aircraft_for(request, airbase, budget) - if unit is None: - # Can't afford any aircraft capable of performing the - # required mission that can operate from this airbase. We - # might be able to afford aircraft at other airbases though, - # in the case where the airbase we attempted to use is only - # able to operate expensive aircraft. - continue - - budget -= db.PRICES[unit] * request.number - airbase.pending_unit_deliveries.order({unit: request.number}) - + budget = self.fulfill_aircraft_request(request, budget) return budget @property