mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Move faction cache out of db.py.
This commit is contained in:
parent
36f74ae0a9
commit
b4742ad54c
@ -27,7 +27,6 @@ from dcs.vehicles import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
# PATCH pydcs data with MODS
|
# PATCH pydcs data with MODS
|
||||||
from game.factions.faction_loader import FactionLoader
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
---------- BEGINNING OF CONFIGURATION SECTION
|
---------- BEGINNING OF CONFIGURATION SECTION
|
||||||
@ -55,12 +54,6 @@ For example, player accessible Hornet is called `FA_18C_hornet`, and MANPAD Igla
|
|||||||
# to be cheap enough to repair with a single turn's income.
|
# to be cheap enough to repair with a single turn's income.
|
||||||
RUNWAY_REPAIR_COST = 100
|
RUNWAY_REPAIR_COST = 100
|
||||||
|
|
||||||
"""
|
|
||||||
Units separated by country.
|
|
||||||
country : DCS Country name
|
|
||||||
"""
|
|
||||||
FACTIONS = FactionLoader()
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Possible time periods for new games
|
Possible time periods for new games
|
||||||
|
|
||||||
|
|||||||
4
game/factions/__init__.py
Normal file
4
game/factions/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from .faction import Faction
|
||||||
|
from .faction_loader import FactionLoader
|
||||||
|
|
||||||
|
FACTIONS = FactionLoader()
|
||||||
@ -4,7 +4,8 @@ from typing import Optional
|
|||||||
|
|
||||||
from dcs.unitgroup import VehicleGroup
|
from dcs.unitgroup import VehicleGroup
|
||||||
|
|
||||||
from game import db, Game
|
from game import Game
|
||||||
|
from game.factions import FACTIONS
|
||||||
from game.theater.theatergroundobject import CoastalSiteGroundObject
|
from game.theater.theatergroundobject import CoastalSiteGroundObject
|
||||||
from gen.coastal.silkworm import SilkwormGenerator
|
from gen.coastal.silkworm import SilkwormGenerator
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ def generate_coastal_group(
|
|||||||
:return: The generated group, or None if this faction does not support coastal
|
:return: The generated group, or None if this faction does not support coastal
|
||||||
defenses.
|
defenses.
|
||||||
"""
|
"""
|
||||||
faction = db.FACTIONS[faction_name]
|
faction = FACTIONS[faction_name]
|
||||||
if len(faction.coastal_defenses) > 0:
|
if len(faction.coastal_defenses) > 0:
|
||||||
generators = faction.coastal_defenses
|
generators = faction.coastal_defenses
|
||||||
if len(generators) > 0:
|
if len(generators) > 0:
|
||||||
|
|||||||
@ -3,9 +3,10 @@ from typing import Optional
|
|||||||
|
|
||||||
from dcs.unitgroup import VehicleGroup
|
from dcs.unitgroup import VehicleGroup
|
||||||
|
|
||||||
from game import db, Game
|
from game import Game
|
||||||
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.factions import FACTIONS
|
||||||
from game.theater.theatergroundobject import VehicleGroupGroundObject
|
from game.theater.theatergroundobject import VehicleGroupGroundObject
|
||||||
from gen.defenses.armored_group_generator import (
|
from gen.defenses.armored_group_generator import (
|
||||||
ArmoredGroupGenerator,
|
ArmoredGroupGenerator,
|
||||||
@ -27,7 +28,7 @@ def generate_armor_group(
|
|||||||
GroundUnitClass.Tank,
|
GroundUnitClass.Tank,
|
||||||
)
|
)
|
||||||
possible_unit = [
|
possible_unit = [
|
||||||
u for u in db.FACTIONS[faction].frontline_units if u.unit_class in armor_types
|
u for u in FACTIONS[faction].frontline_units if u.unit_class in armor_types
|
||||||
]
|
]
|
||||||
if len(possible_unit) > 0:
|
if len(possible_unit) > 0:
|
||||||
unit_type = random.choice(possible_unit)
|
unit_type = random.choice(possible_unit)
|
||||||
|
|||||||
@ -2,14 +2,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from dcs.unitgroup import ShipGroup
|
from dcs.unitgroup import ShipGroup
|
||||||
|
|
||||||
from game import db
|
from game.factions import FACTIONS
|
||||||
from game.theater.theatergroundobject import (
|
from game.theater.theatergroundobject import (
|
||||||
LhaGroundObject,
|
|
||||||
CarrierGroundObject,
|
CarrierGroundObject,
|
||||||
|
LhaGroundObject,
|
||||||
ShipGroundObject,
|
ShipGroundObject,
|
||||||
)
|
)
|
||||||
from gen.fleet.carrier_group import CarrierGroupGenerator
|
from gen.fleet.carrier_group import CarrierGroupGenerator
|
||||||
@ -21,10 +21,10 @@ from gen.fleet.dd_group import (
|
|||||||
from gen.fleet.lacombattanteII import LaCombattanteIIGroupGenerator
|
from gen.fleet.lacombattanteII import LaCombattanteIIGroupGenerator
|
||||||
from gen.fleet.lha_group import LHAGroupGenerator
|
from gen.fleet.lha_group import LHAGroupGenerator
|
||||||
from gen.fleet.ru_dd_group import (
|
from gen.fleet.ru_dd_group import (
|
||||||
RussianNavyGroupGenerator,
|
|
||||||
GrishaGroupGenerator,
|
GrishaGroupGenerator,
|
||||||
MolniyaGroupGenerator,
|
|
||||||
KiloSubGroupGenerator,
|
KiloSubGroupGenerator,
|
||||||
|
MolniyaGroupGenerator,
|
||||||
|
RussianNavyGroupGenerator,
|
||||||
TangoSubGroupGenerator,
|
TangoSubGroupGenerator,
|
||||||
)
|
)
|
||||||
from gen.fleet.schnellboot import SchnellbootGroupGenerator
|
from gen.fleet.schnellboot import SchnellbootGroupGenerator
|
||||||
@ -59,7 +59,7 @@ def generate_ship_group(
|
|||||||
This generate a ship group
|
This generate a ship group
|
||||||
:return: The generated group, or None if this faction does not support ships.
|
:return: The generated group, or None if this faction does not support ships.
|
||||||
"""
|
"""
|
||||||
faction = db.FACTIONS[faction_name]
|
faction = FACTIONS[faction_name]
|
||||||
if len(faction.navy_generators) > 0:
|
if len(faction.navy_generators) > 0:
|
||||||
gen = random.choice(faction.navy_generators)
|
gen = random.choice(faction.navy_generators)
|
||||||
if gen in SHIP_MAP.keys():
|
if gen in SHIP_MAP.keys():
|
||||||
@ -86,7 +86,7 @@ def generate_carrier_group(
|
|||||||
:param ground_object: The ground object which will own the ship group
|
:param ground_object: The ground object which will own the ship group
|
||||||
:return: The generated group.
|
:return: The generated group.
|
||||||
"""
|
"""
|
||||||
generator = CarrierGroupGenerator(game, ground_object, db.FACTIONS[faction])
|
generator = CarrierGroupGenerator(game, ground_object, FACTIONS[faction])
|
||||||
generator.generate()
|
generator.generate()
|
||||||
return generator.get_generated_group()
|
return generator.get_generated_group()
|
||||||
|
|
||||||
@ -101,6 +101,6 @@ def generate_lha_group(
|
|||||||
:param ground_object: The ground object which will own the ship group
|
:param ground_object: The ground object which will own the ship group
|
||||||
:return: The generated group.
|
:return: The generated group.
|
||||||
"""
|
"""
|
||||||
generator = LHAGroupGenerator(game, ground_object, db.FACTIONS[faction])
|
generator = LHAGroupGenerator(game, ground_object, FACTIONS[faction])
|
||||||
generator.generate()
|
generator.generate()
|
||||||
return generator.get_generated_group()
|
return generator.get_generated_group()
|
||||||
|
|||||||
@ -4,7 +4,8 @@ from typing import Optional
|
|||||||
|
|
||||||
from dcs.unitgroup import VehicleGroup
|
from dcs.unitgroup import VehicleGroup
|
||||||
|
|
||||||
from game import db, Game
|
from game import Game
|
||||||
|
from game.factions import FACTIONS
|
||||||
from game.theater.theatergroundobject import MissileSiteGroundObject
|
from game.theater.theatergroundobject import MissileSiteGroundObject
|
||||||
from gen.missiles.scud_site import ScudGenerator
|
from gen.missiles.scud_site import ScudGenerator
|
||||||
from gen.missiles.v1_group import V1GroupGenerator
|
from gen.missiles.v1_group import V1GroupGenerator
|
||||||
@ -19,7 +20,7 @@ def generate_missile_group(
|
|||||||
This generate a missiles group
|
This generate a missiles group
|
||||||
:return: Nothing, but put the group reference inside the ground object
|
:return: Nothing, but put the group reference inside the ground object
|
||||||
"""
|
"""
|
||||||
faction = db.FACTIONS[faction_name]
|
faction = FACTIONS[faction_name]
|
||||||
if len(faction.missiles) > 0:
|
if len(faction.missiles) > 0:
|
||||||
generators = faction.missiles
|
generators = faction.missiles
|
||||||
if len(generators) > 0:
|
if len(generators) > 0:
|
||||||
|
|||||||
@ -15,8 +15,8 @@ from dcs.payloads import PayloadDirectories
|
|||||||
from game import Game, VERSION, persistency
|
from game import Game, VERSION, persistency
|
||||||
from game.campaignloader.campaign import Campaign
|
from game.campaignloader.campaign import Campaign
|
||||||
from game.data.weapons import Pylon, Weapon, WeaponGroup
|
from game.data.weapons import Pylon, Weapon, WeaponGroup
|
||||||
from game.db import FACTIONS
|
|
||||||
from game.dcs.aircrafttype import AircraftType
|
from game.dcs.aircrafttype import AircraftType
|
||||||
|
from game.factions import FACTIONS
|
||||||
from game.profiling import logged_duration
|
from game.profiling import logged_duration
|
||||||
from game.server import EventStream, GameContext, Server
|
from game.server import EventStream, GameContext, Server
|
||||||
from game.settings import Settings
|
from game.settings import Settings
|
||||||
|
|||||||
@ -11,7 +11,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
from game.campaignloader.campaign import Campaign
|
from game.campaignloader.campaign import Campaign
|
||||||
from game.factions.faction import Faction
|
from game.factions import FACTIONS, Faction
|
||||||
from game.settings import Settings
|
from game.settings import Settings
|
||||||
from game.theater.start_generator import GameGenerator, GeneratorSettings, ModSettings
|
from game.theater.start_generator import GameGenerator, GeneratorSettings, ModSettings
|
||||||
from qt_ui.widgets.QLiberationCalendar import QLiberationCalendar
|
from qt_ui.widgets.QLiberationCalendar import QLiberationCalendar
|
||||||
@ -179,7 +179,7 @@ class FactionSelection(QtWidgets.QWizardPage):
|
|||||||
|
|
||||||
blueFaction = QtWidgets.QLabel("<b>Player Faction :</b>")
|
blueFaction = QtWidgets.QLabel("<b>Player Faction :</b>")
|
||||||
self.blueFactionSelect = QtWidgets.QComboBox()
|
self.blueFactionSelect = QtWidgets.QComboBox()
|
||||||
for f in db.FACTIONS:
|
for f in FACTIONS:
|
||||||
self.blueFactionSelect.addItem(f)
|
self.blueFactionSelect.addItem(f)
|
||||||
blueFaction.setBuddy(self.blueFactionSelect)
|
blueFaction.setBuddy(self.blueFactionSelect)
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ class FactionSelection(QtWidgets.QWizardPage):
|
|||||||
self.redFactionDescription.setReadOnly(True)
|
self.redFactionDescription.setReadOnly(True)
|
||||||
|
|
||||||
# Setup default selected factions
|
# Setup default selected factions
|
||||||
for i, r in enumerate(db.FACTIONS):
|
for i, r in enumerate(FACTIONS):
|
||||||
self.redFactionSelect.addItem(r)
|
self.redFactionSelect.addItem(r)
|
||||||
if r == "Russia 1990":
|
if r == "Russia 1990":
|
||||||
self.redFactionSelect.setCurrentIndex(i)
|
self.redFactionSelect.setCurrentIndex(i)
|
||||||
@ -241,10 +241,10 @@ class FactionSelection(QtWidgets.QWizardPage):
|
|||||||
self.blueFactionSelect.clear()
|
self.blueFactionSelect.clear()
|
||||||
self.redFactionSelect.clear()
|
self.redFactionSelect.clear()
|
||||||
|
|
||||||
for f in db.FACTIONS:
|
for f in FACTIONS:
|
||||||
self.blueFactionSelect.addItem(f)
|
self.blueFactionSelect.addItem(f)
|
||||||
|
|
||||||
for i, r in enumerate(db.FACTIONS):
|
for i, r in enumerate(FACTIONS):
|
||||||
self.redFactionSelect.addItem(r)
|
self.redFactionSelect.addItem(r)
|
||||||
if r == campaign.recommended_enemy_faction:
|
if r == campaign.recommended_enemy_faction:
|
||||||
self.redFactionSelect.setCurrentIndex(i)
|
self.redFactionSelect.setCurrentIndex(i)
|
||||||
@ -255,8 +255,8 @@ class FactionSelection(QtWidgets.QWizardPage):
|
|||||||
|
|
||||||
def updateUnitRecap(self):
|
def updateUnitRecap(self):
|
||||||
|
|
||||||
red_faction = db.FACTIONS[self.redFactionSelect.currentText()]
|
red_faction = FACTIONS[self.redFactionSelect.currentText()]
|
||||||
blue_faction = db.FACTIONS[self.blueFactionSelect.currentText()]
|
blue_faction = FACTIONS[self.blueFactionSelect.currentText()]
|
||||||
|
|
||||||
template = jinja_env.get_template("factiontemplate_EN.j2")
|
template = jinja_env.get_template("factiontemplate_EN.j2")
|
||||||
|
|
||||||
@ -268,11 +268,11 @@ class FactionSelection(QtWidgets.QWizardPage):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def selected_blue_faction(self) -> Faction:
|
def selected_blue_faction(self) -> Faction:
|
||||||
return db.FACTIONS[self.blueFactionSelect.currentText()]
|
return FACTIONS[self.blueFactionSelect.currentText()]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def selected_red_faction(self) -> Faction:
|
def selected_red_faction(self) -> Faction:
|
||||||
return db.FACTIONS[self.redFactionSelect.currentText()]
|
return FACTIONS[self.redFactionSelect.currentText()]
|
||||||
|
|
||||||
|
|
||||||
class TheaterConfiguration(QtWidgets.QWizardPage):
|
class TheaterConfiguration(QtWidgets.QWizardPage):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user