From ab6f44cb6f0a5860eb13cda407a94cfc44598fd3 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 18 Feb 2022 18:22:02 -0800 Subject: [PATCH] Move remnants of db.py to config.py. This is now just a few prices and income configurations. Both should probably be defined in YAML but for now this makes the name "db" usable again. --- game/__init__.py | 1 - game/config.py | 21 ++++++++ game/db.py | 50 ------------------- game/income.py | 2 +- game/procurement.py | 6 +-- qt_ui/windows/basemenu/QBaseMenu2.py | 17 ++++--- qt_ui/windows/groundobject/QBuildingInfo.py | 5 +- .../windows/groundobject/QGroundObjectMenu.py | 11 ++-- 8 files changed, 42 insertions(+), 71 deletions(-) create mode 100644 game/config.py delete mode 100644 game/db.py diff --git a/game/__init__.py b/game/__init__.py index c651b19d..250f4a35 100644 --- a/game/__init__.py +++ b/game/__init__.py @@ -1,3 +1,2 @@ from .game import Game -from . import db from .version import VERSION diff --git a/game/config.py b/game/config.py new file mode 100644 index 00000000..5f84f241 --- /dev/null +++ b/game/config.py @@ -0,0 +1,21 @@ +# This should probably be much higher, but the AI doesn't rollover their budget +# and isn't smart enough to save to repair a critical runway anyway, so it has +# to be cheap enough to repair with a single turn's income. +RUNWAY_REPAIR_COST = 100 + +REWARDS = { + "power": 4, + "warehouse": 2, + "ware": 2, + "fuel": 2, + "ammo": 2, + "farp": 1, + # TODO: Should generate no cash once they generate units. + # https://github.com/dcs-liberation/dcs_liberation/issues/1036 + "factory": 10, + "comms": 10, + "oil": 10, + "derrick": 8, + "village": 0.25, + "allycamp": 0.5, +} diff --git a/game/db.py b/game/db.py deleted file mode 100644 index a56d6025..00000000 --- a/game/db.py +++ /dev/null @@ -1,50 +0,0 @@ -# mypy can't resolve these if they're wildcard imports for some reason. - -# PATCH pydcs data with MODS - -""" ----------- BEGINNING OF CONFIGURATION SECTION -""" - -""" -All aircraft names in this file should correspond with naming provided in following files: - -* https://github.com/pydcs/dcs/blob/master/dcs/planes.py - for planes -* https://github.com/pydcs/dcs/blob/master/dcs/helicopters.py - for helicopters -* https://github.com/pydcs/dcs/blob/master/dcs/vehicles.py - for vehicles (this include all of the ground vehicles) - -You can find names at the bottom of the file in following format: - -x_map = { - "Name of the unit in game": Identifier, -} - -from this example `Identifier` should be used (which may or may not include category of the unit and dot + underscore characters). -For example, player accessible Hornet is called `FA_18C_hornet`, and MANPAD Igla is called `AirDefence.MANPADS_SA_18_Igla_S_Grouse` -""" - -# This should probably be much higher, but the AI doesn't rollover their budget -# and isn't smart enough to save to repair a critical runway anyway, so it has -# to be cheap enough to repair with a single turn's income. -RUNWAY_REPAIR_COST = 100 - -REWARDS = { - "power": 4, - "warehouse": 2, - "ware": 2, - "fuel": 2, - "ammo": 2, - "farp": 1, - # TODO: Should generate no cash once they generate units. - # https://github.com/dcs-liberation/dcs_liberation/issues/1036 - "factory": 10, - "comms": 10, - "oil": 10, - "derrick": 8, - "village": 0.25, - "allycamp": 0.5, -} - -""" ----------- END OF CONFIGURATION SECTION -""" diff --git a/game/income.py b/game/income.py index f9a74eb6..bcbe2aa0 100644 --- a/game/income.py +++ b/game/income.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING -from game.db import REWARDS +from game.config import REWARDS if TYPE_CHECKING: from game import Game diff --git a/game/procurement.py b/game/procurement.py index 4650141b..e4de6d98 100644 --- a/game/procurement.py +++ b/game/procurement.py @@ -5,7 +5,7 @@ import random from dataclasses import dataclass from typing import Iterator, List, Optional, TYPE_CHECKING, Tuple -from game import db +from game.config import RUNWAY_REPAIR_COST from game.data.groundunitclass import GroundUnitClass from game.dcs.groundunittype import GroundUnitType from game.theater import ControlPoint, MissionTarget @@ -100,11 +100,11 @@ class ProcurementAi: def repair_runways(self, budget: float) -> float: for control_point in self.owned_points: - if budget < db.RUNWAY_REPAIR_COST: + if budget < RUNWAY_REPAIR_COST: break if control_point.runway_can_be_repaired: control_point.begin_runway_repair() - budget -= db.RUNWAY_REPAIR_COST + budget -= RUNWAY_REPAIR_COST if self.is_player: self.game.message( "OPFOR has begun repairing the runway at " f"{control_point}" diff --git a/qt_ui/windows/basemenu/QBaseMenu2.py b/qt_ui/windows/basemenu/QBaseMenu2.py index 9e4937e5..bee42a62 100644 --- a/qt_ui/windows/basemenu/QBaseMenu2.py +++ b/qt_ui/windows/basemenu/QBaseMenu2.py @@ -10,14 +10,15 @@ from PySide2.QtWidgets import ( QWidget, ) -from game import Game, db +from game import Game +from game.ato.flighttype import FlightType +from game.config import RUNWAY_REPAIR_COST from game.theater import ( + AMMO_DEPOT_FRONTLINE_UNIT_CONTRIBUTION, ControlPoint, ControlPointType, FREE_FRONTLINE_UNIT_SUPPLY, - AMMO_DEPOT_FRONTLINE_UNIT_CONTRIBUTION, ) -from game.ato.flighttype import FlightType from qt_ui.dialogs import Dialog from qt_ui.models import GameModel from qt_ui.uiconstants import EVENT_ICONS @@ -139,14 +140,14 @@ class QBaseMenu2(QDialog): @property def can_afford_runway_repair(self) -> bool: - return self.game_model.game.blue.budget >= db.RUNWAY_REPAIR_COST + return self.game_model.game.blue.budget >= RUNWAY_REPAIR_COST def begin_runway_repair(self) -> None: if not self.can_afford_runway_repair: QMessageBox.critical( self, "Cannot repair runway", - f"Runway repair costs ${db.RUNWAY_REPAIR_COST}M but you have " + f"Runway repair costs ${RUNWAY_REPAIR_COST}M but you have " f"only ${self.game_model.game.blue.budget}M available.", QMessageBox.Ok, ) @@ -161,7 +162,7 @@ class QBaseMenu2(QDialog): return self.cp.begin_runway_repair() - self.game_model.game.blue.budget -= db.RUNWAY_REPAIR_COST + self.game_model.game.blue.budget -= RUNWAY_REPAIR_COST self.update_repair_button() self.update_intel_summary() GameUpdateSignal.get_instance().updateGame(self.game_model.game) @@ -176,12 +177,12 @@ class QBaseMenu2(QDialog): if self.can_repair_runway: if self.can_afford_runway_repair: - self.repair_button.setText(f"Repair ${db.RUNWAY_REPAIR_COST}M") + self.repair_button.setText(f"Repair ${RUNWAY_REPAIR_COST}M") self.repair_button.setDisabled(False) return else: self.repair_button.setText( - f"Cannot afford repair ${db.RUNWAY_REPAIR_COST}M" + f"Cannot afford repair ${RUNWAY_REPAIR_COST}M" ) self.repair_button.setDisabled(True) return diff --git a/qt_ui/windows/groundobject/QBuildingInfo.py b/qt_ui/windows/groundobject/QBuildingInfo.py index 3f484f15..05c1b8f6 100644 --- a/qt_ui/windows/groundobject/QBuildingInfo.py +++ b/qt_ui/windows/groundobject/QBuildingInfo.py @@ -1,8 +1,9 @@ import os from PySide2.QtGui import QPixmap -from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QVBoxLayout, QLabel -from game.db import REWARDS +from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QVBoxLayout + +from game.config import REWARDS class QBuildingInfo(QGroupBox): diff --git a/qt_ui/windows/groundobject/QGroundObjectMenu.py b/qt_ui/windows/groundobject/QGroundObjectMenu.py index 5622682f..ef4b32b9 100644 --- a/qt_ui/windows/groundobject/QGroundObjectMenu.py +++ b/qt_ui/windows/groundobject/QGroundObjectMenu.py @@ -14,19 +14,18 @@ from PySide2.QtWidgets import ( QSpinBox, QVBoxLayout, ) -from dcs import Point -from dcs import vehicles +from dcs import Point, vehicles from game import Game +from game.config import REWARDS from game.data.building_data import FORTIFICATION_BUILDINGS -from game.db import REWARDS from game.dcs.groundunittype import GroundUnitType from game.theater import ControlPoint, TheaterGroundObject from game.theater.theatergroundobject import ( - VehicleGroupGroundObject, - SamGroundObject, - EwrGroundObject, BuildingGroundObject, + EwrGroundObject, + SamGroundObject, + VehicleGroupGroundObject, ) from gen.defenses.armor_group_generator import generate_armor_group_of_type_and_size from gen.sam.ewr_group_generator import get_faction_possible_ewrs_generator