From c7f9bfbb43f05c16895646a6bd45de149b3e83b6 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 25 Dec 2020 18:41:46 -0800 Subject: [PATCH] Sell off incomplete opfor squadrons. Short term fix for https://github.com/Khopa/dcs_liberation/issues/41. --- changelog.md | 1 + game/game.py | 3 +-- game/procurement.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index fb4e944a..7a3461c7 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ Saves from 2.3 are not compatible with 2.4. * **[Flight Planner]** Non-custom flight plans will now navigate around threat areas en route to the target area when practical. * **[Campaign AI]** Auto-purchase now prefers airfields that are not within range of the enemy. * **[Campaign AI]** Auto-purchase now prefers the best aircraft for the task, but will attempt to maintain some variety. +* **[Campaign AI]** Opfor now sells off odd aircraft since they're unlikely to be used. * **[Mission Generator]** Multiple groups are created for complex SAM sites (SAMs with additional point defense or SHORADS), improving Skynet behavior. * **[Skynet]** Point defenses are now configured to remain on to protect the site they accompany. diff --git a/game/game.py b/game/game.py index 8cac0a1b..8a7313f7 100644 --- a/game/game.py +++ b/game/game.py @@ -4,7 +4,7 @@ import random import sys from datetime import date, datetime, timedelta from enum import Enum -from typing import Any, Dict, Iterator, List, Tuple +from typing import Any, Dict, List from dcs.action import Coalition from dcs.mapping import Point @@ -12,7 +12,6 @@ from dcs.task import CAP, CAS, PinpointStrike from dcs.vehicles import AirDefence from game import db -from game.db import PLAYER_BUDGET_BASE, REWARDS from game.inventory import GlobalAircraftInventory from game.models.game_stats import GameStats from game.plugins import LuaPluginManager diff --git a/game/procurement.py b/game/procurement.py index 945b1aa3..090bdb3a 100644 --- a/game/procurement.py +++ b/game/procurement.py @@ -56,10 +56,38 @@ class ProcurementAi: armor_budget = math.ceil(budget / 2) budget -= armor_budget budget += self.reinforce_front_line(armor_budget) + + # Don't sell overstock aircraft until after we've bought runways and + # front lines. Any budget we free up should be earmarked for aircraft. + if not self.is_player: + budget += self.sell_incomplete_squadrons() if self.manage_aircraft: budget = self.purchase_aircraft(budget, aircraft_requests) return budget + def sell_incomplete_squadrons(self) -> int: + # Selling incomplete squadrons gives us more money to spend on the next + # turn. This serves as a short term fix for + # https://github.com/Khopa/dcs_liberation/issues/41. + # + # Only incomplete squadrons which are unlikely to get used will be sold + # rather than all unused aircraft because the unused aircraft are what + # make OCA strikes worthwhile. + # + # This option is only used by the AI since players cannot cancel sales + # (https://github.com/Khopa/dcs_liberation/issues/365). + total = 0 + for cp in self.game.theater.control_points_for(self.is_player): + inventory = self.game.aircraft_inventory.for_control_point(cp) + for aircraft, available in inventory.all_aircraft: + # We only ever plan even groups, so the odd aircraft is unlikely + # to get used. + if available % 2 == 0: + continue + inventory.remove_aircraft(aircraft, 1) + total += db.PRICES[aircraft] + return total + def repair_runways(self, budget: int) -> int: for control_point in self.owned_points: if budget < db.RUNWAY_REPAIR_COST: