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
This commit is contained in:
Dan Albert 2021-05-07 17:20:23 -07:00
parent 8320c6940b
commit 2cf3b3be2b
2 changed files with 22 additions and 15 deletions

View File

@ -12,9 +12,10 @@ Saves from 2.5 are not compatible with 3.0.
* **[Modding]** Can now install custom factions to <DCS saved games>/Liberation/Factions instead of the Liberation install directory. * **[Modding]** Can now install custom factions to <DCS saved games>/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 ## Fixes
* **[Campaign AI]** Fixed bug causing AI to over-purchase cheap aircraft.
# 2.5.1 # 2.5.1
## Features/Improvements ## Features/Improvements

View File

@ -192,8 +192,9 @@ class ProcurementAi:
aircraft_for_task(request.task_capability), airbase, request.number, budget aircraft_for_task(request.task_capability), airbase, request.number, budget
) )
def purchase_aircraft(self, budget: float) -> float: def fulfill_aircraft_request(
for request in self.game.procurement_requests_for(self.is_player): self, request: AircraftProcurementRequest, budget: float
) -> float:
for airbase in self.best_airbases_for(request): for airbase in self.best_airbases_for(request):
unit = self.affordable_aircraft_for(request, airbase, budget) unit = self.affordable_aircraft_for(request, airbase, budget)
if unit is None: if unit is None:
@ -206,7 +207,12 @@ class ProcurementAi:
budget -= db.PRICES[unit] * request.number budget -= db.PRICES[unit] * request.number
airbase.pending_unit_deliveries.order({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):
budget = self.fulfill_aircraft_request(request, budget)
return budget return budget
@property @property