From f396ff7f120cd2984263e17b996f5afb40bf5d09 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 5 Dec 2020 21:18:23 -0800 Subject: [PATCH] Add procurement automation for players. The allows the players to use the same auto-purchase mechanics that the AI uses. The behavior is very bad, but it's no worse than what OPFOR deals with. There's a lot that needs to be improved before this is really a good choice for the player: * Option to adjust budget balance between front lines and airbases. * Disallow negative budgets (which incidentally will cause more aircraft to be purchased, since the armor purchases currently accidentally spend the aircraft budget). * Buy less randomly: https://github.com/Khopa/dcs_liberation/issues/361. * Obey parking limits. * Use the delivery events rather than instant delivery (also allows the player to cancel orders they don't want). Fixes https://github.com/Khopa/dcs_liberation/issues/362 --- game/game.py | 6 +-- game/settings.py | 5 +++ qt_ui/windows/settings/QSettingsWindow.py | 53 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/game/game.py b/game/game.py index 61b9b2b2..82dd998a 100644 --- a/game/game.py +++ b/game/game.py @@ -243,9 +243,9 @@ class Game: self, for_player=True, faction=self.player_faction, - manage_runways=False, - manage_front_line=False, - manage_aircraft=False + manage_runways=self.settings.automate_runway_repair, + manage_front_line=self.settings.automate_front_line_reinforcements, + manage_aircraft=self.settings.automate_aircraft_reinforcements ).spend_budget(self.budget) if not no_action and self.turn > 1: diff --git a/game/settings.py b/game/settings.py index 8dae3061..255159b5 100644 --- a/game/settings.py +++ b/game/settings.py @@ -25,6 +25,11 @@ class Settings: player_income_multiplier: float = 1.0 enemy_income_multiplier: float = 1.0 + # Campaign management + automate_runway_repair: bool = False + automate_front_line_reinforcements: bool = False + automate_aircraft_reinforcements: bool = False + # Performance oriented perf_red_alert_state: bool = True perf_smoke_gen: bool = True diff --git a/qt_ui/windows/settings/QSettingsWindow.py b/qt_ui/windows/settings/QSettingsWindow.py index fae49153..5a99d6b8 100644 --- a/qt_ui/windows/settings/QSettingsWindow.py +++ b/qt_ui/windows/settings/QSettingsWindow.py @@ -55,6 +55,7 @@ class QSettingsWindow(QDialog): self.game = game self.pluginsPage = None self.pluginsOptionsPage = None + self.campaign_management_page = QWidget() self.setModal(True) self.setWindowTitle("Settings") @@ -83,6 +84,14 @@ class QSettingsWindow(QDialog): self.categoryModel.appendRow(difficulty) self.right_layout.addWidget(self.difficultyPage) + self.init_campaign_management_layout() + campaign_management = QStandardItem("Campaign Management") + campaign_management.setIcon(CONST.ICONS["Money"]) + campaign_management.setEditable(False) + campaign_management.setSelectable(True) + self.categoryModel.appendRow(campaign_management) + self.right_layout.addWidget(self.campaign_management_page) + self.initGeneratorLayout() generator = QStandardItem("Mission Generator") generator.setIcon(CONST.ICONS["Generator"]) @@ -234,6 +243,50 @@ class QSettingsWindow(QDialog): self.missionRestrictionsSettings.setLayout(self.missionRestrictionsLayout) self.difficultyLayout.addWidget(self.missionRestrictionsSettings) + def init_campaign_management_layout(self) -> None: + campaign_layout = QVBoxLayout() + campaign_layout.setAlignment(Qt.AlignTop) + self.campaign_management_page.setLayout(campaign_layout) + + automation = QGroupBox("HQ Automation (WORK IN PROGRESS)") + campaign_layout.addWidget(automation) + + automation_layout = QGridLayout() + automation.setLayout(automation_layout) + + def set_runway_automation(value: bool) -> None: + self.game.settings.automate_runway_repair = value + + def set_front_line_automation(value: bool) -> None: + self.game.settings.automate_front_line_reinforcements = value + + def set_aircraft_automation(value: bool) -> None: + self.game.settings.automate_aircraft_reinforcements = value + + runway_repair = QCheckBox() + runway_repair.setChecked( + self.game.settings.automate_runway_repair) + runway_repair.toggled.connect(set_runway_automation) + + automation_layout.addWidget(QLabel("Automate runway repairs"), 0, 0) + automation_layout.addWidget(runway_repair, 0, 1, Qt.AlignRight) + + front_line = QCheckBox() + front_line.setChecked( + self.game.settings.automate_front_line_reinforcements) + front_line.toggled.connect(set_front_line_automation) + + automation_layout.addWidget( + QLabel("Automate front-line purchases"), 1, 0) + automation_layout.addWidget(front_line, 1, 1, Qt.AlignRight) + + aircraft = QCheckBox() + aircraft.setChecked( + self.game.settings.automate_aircraft_reinforcements) + aircraft.toggled.connect(set_aircraft_automation) + + automation_layout.addWidget(QLabel("Automate aircraft purchases"), 2, 0) + automation_layout.addWidget(aircraft, 2, 1, Qt.AlignRight) def initGeneratorLayout(self): self.generatorPage = QWidget()