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.
This commit is contained in:
Dan Albert 2022-02-18 18:22:02 -08:00
parent 9b20a6d053
commit ab6f44cb6f
8 changed files with 42 additions and 71 deletions

View File

@ -1,3 +1,2 @@
from .game import Game from .game import Game
from . import db
from .version import VERSION from .version import VERSION

21
game/config.py Normal file
View File

@ -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,
}

View File

@ -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
"""

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from game.db import REWARDS from game.config import REWARDS
if TYPE_CHECKING: if TYPE_CHECKING:
from game import Game from game import Game

View File

@ -5,7 +5,7 @@ import random
from dataclasses import dataclass from dataclasses import dataclass
from typing import Iterator, List, Optional, TYPE_CHECKING, Tuple 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.data.groundunitclass import GroundUnitClass
from game.dcs.groundunittype import GroundUnitType from game.dcs.groundunittype import GroundUnitType
from game.theater import ControlPoint, MissionTarget from game.theater import ControlPoint, MissionTarget
@ -100,11 +100,11 @@ class ProcurementAi:
def repair_runways(self, budget: float) -> float: def repair_runways(self, budget: float) -> float:
for control_point in self.owned_points: for control_point in self.owned_points:
if budget < db.RUNWAY_REPAIR_COST: if budget < RUNWAY_REPAIR_COST:
break break
if control_point.runway_can_be_repaired: if control_point.runway_can_be_repaired:
control_point.begin_runway_repair() control_point.begin_runway_repair()
budget -= db.RUNWAY_REPAIR_COST budget -= RUNWAY_REPAIR_COST
if self.is_player: if self.is_player:
self.game.message( self.game.message(
"OPFOR has begun repairing the runway at " f"{control_point}" "OPFOR has begun repairing the runway at " f"{control_point}"

View File

@ -10,14 +10,15 @@ from PySide2.QtWidgets import (
QWidget, 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 ( from game.theater import (
AMMO_DEPOT_FRONTLINE_UNIT_CONTRIBUTION,
ControlPoint, ControlPoint,
ControlPointType, ControlPointType,
FREE_FRONTLINE_UNIT_SUPPLY, FREE_FRONTLINE_UNIT_SUPPLY,
AMMO_DEPOT_FRONTLINE_UNIT_CONTRIBUTION,
) )
from game.ato.flighttype import FlightType
from qt_ui.dialogs import Dialog from qt_ui.dialogs import Dialog
from qt_ui.models import GameModel from qt_ui.models import GameModel
from qt_ui.uiconstants import EVENT_ICONS from qt_ui.uiconstants import EVENT_ICONS
@ -139,14 +140,14 @@ class QBaseMenu2(QDialog):
@property @property
def can_afford_runway_repair(self) -> bool: 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: def begin_runway_repair(self) -> None:
if not self.can_afford_runway_repair: if not self.can_afford_runway_repair:
QMessageBox.critical( QMessageBox.critical(
self, self,
"Cannot repair runway", "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.", f"only ${self.game_model.game.blue.budget}M available.",
QMessageBox.Ok, QMessageBox.Ok,
) )
@ -161,7 +162,7 @@ class QBaseMenu2(QDialog):
return return
self.cp.begin_runway_repair() 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_repair_button()
self.update_intel_summary() self.update_intel_summary()
GameUpdateSignal.get_instance().updateGame(self.game_model.game) GameUpdateSignal.get_instance().updateGame(self.game_model.game)
@ -176,12 +177,12 @@ class QBaseMenu2(QDialog):
if self.can_repair_runway: if self.can_repair_runway:
if self.can_afford_runway_repair: 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) self.repair_button.setDisabled(False)
return return
else: else:
self.repair_button.setText( 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) self.repair_button.setDisabled(True)
return return

View File

@ -1,8 +1,9 @@
import os import os
from PySide2.QtGui import QPixmap from PySide2.QtGui import QPixmap
from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QVBoxLayout, QLabel from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QVBoxLayout
from game.db import REWARDS
from game.config import REWARDS
class QBuildingInfo(QGroupBox): class QBuildingInfo(QGroupBox):

View File

@ -14,19 +14,18 @@ from PySide2.QtWidgets import (
QSpinBox, QSpinBox,
QVBoxLayout, QVBoxLayout,
) )
from dcs import Point from dcs import Point, vehicles
from dcs import vehicles
from game import Game from game import Game
from game.config import REWARDS
from game.data.building_data import FORTIFICATION_BUILDINGS from game.data.building_data import FORTIFICATION_BUILDINGS
from game.db import REWARDS
from game.dcs.groundunittype import GroundUnitType from game.dcs.groundunittype import GroundUnitType
from game.theater import ControlPoint, TheaterGroundObject from game.theater import ControlPoint, TheaterGroundObject
from game.theater.theatergroundobject import ( from game.theater.theatergroundobject import (
VehicleGroupGroundObject,
SamGroundObject,
EwrGroundObject,
BuildingGroundObject, BuildingGroundObject,
EwrGroundObject,
SamGroundObject,
VehicleGroupGroundObject,
) )
from gen.defenses.armor_group_generator import generate_armor_group_of_type_and_size 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 from gen.sam.ewr_group_generator import get_faction_possible_ewrs_generator