mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Faction rework, working :)
This commit is contained in:
10
game/db.py
10
game/db.py
@@ -1325,6 +1325,7 @@ def upgrade_to_supercarrier(unit, name: str):
|
||||
else:
|
||||
return unit
|
||||
|
||||
|
||||
def unit_task(unit: UnitType) -> Optional[Task]:
|
||||
for task, units in UNIT_BY_TASK.items():
|
||||
if unit in units:
|
||||
@@ -1336,8 +1337,10 @@ def unit_task(unit: UnitType) -> Optional[Task]:
|
||||
print(unit.name + " cause issue")
|
||||
return None
|
||||
|
||||
|
||||
def find_unittype(for_task: Task, country_name: str) -> List[UnitType]:
|
||||
return [x for x in UNIT_BY_TASK[for_task] if x in FACTIONS[country_name]["units"]]
|
||||
return [x for x in UNIT_BY_TASK[for_task] if x in FACTIONS[country_name].units]
|
||||
|
||||
|
||||
def find_infantry(country_name: str) -> List[UnitType]:
|
||||
inf = [
|
||||
@@ -1354,14 +1357,17 @@ def find_infantry(country_name: str) -> List[UnitType]:
|
||||
Infantry.Infantry_M1_Garand, Infantry.Infantry_M1_Garand, Infantry.Infantry_M1_Garand,
|
||||
Infantry.Infantry_Soldier_Insurgents, Infantry.Infantry_Soldier_Insurgents, Infantry.Infantry_Soldier_Insurgents
|
||||
]
|
||||
return [x for x in inf if x in FACTIONS[country_name]["units"]]
|
||||
return [x for x in inf if x in FACTIONS[country_name].infantry_units]
|
||||
|
||||
|
||||
def unit_type_name(unit_type) -> str:
|
||||
return unit_type.id and unit_type.id or unit_type.name
|
||||
|
||||
|
||||
def unit_type_name_2(unit_type) -> str:
|
||||
return unit_type.name and unit_type.name or unit_type.id
|
||||
|
||||
|
||||
def unit_type_from_name(name: str) -> Optional[UnitType]:
|
||||
if name in vehicle_map:
|
||||
return vehicle_map[name]
|
||||
|
||||
@@ -7,6 +7,7 @@ from dcs.planes import PlaneType, plane_map
|
||||
from dcs.unittype import VehicleType, UnitType
|
||||
from dcs.vehicles import vehicle_map, Armor, Unarmed, Infantry, Fortification, Artillery, AirDefence
|
||||
|
||||
from game.data.building_data import WW2_ALLIES_BUILDINGS, DEFAULT_AVAILABLE_BUILDINGS, WW2_GERMANY_BUILDINGS
|
||||
from game.data.doctrine import Doctrine, MODERN_DOCTRINE, COLDWAR_DOCTRINE, WWII_DOCTRINE
|
||||
|
||||
|
||||
@@ -41,14 +42,23 @@ class Faction:
|
||||
logistics_units: [VehicleType]
|
||||
|
||||
# List of units that can be deployed as SHORAD
|
||||
shorad_units: [VehicleType]
|
||||
shorads: [str]
|
||||
|
||||
# Possible SAMS site generators for this faction
|
||||
sams: [str]
|
||||
|
||||
# Possible Missile site generators for this faction
|
||||
missiles: [str]
|
||||
|
||||
# Required mods or asset packs
|
||||
requirements: {str: str}
|
||||
|
||||
# possible aircraft carrier units
|
||||
aircraft_carrier: [UnitType]
|
||||
|
||||
# possible helicopter carrier units
|
||||
helicopter_carrier: [UnitType]
|
||||
|
||||
# Possible carrier names
|
||||
carrier_names: [str]
|
||||
|
||||
@@ -64,15 +74,24 @@ class Faction:
|
||||
# Available cruisers
|
||||
cruisers: [str]
|
||||
|
||||
# JTAC
|
||||
# How many navy group should we try to generate per CP on startup for this faction
|
||||
navy_group_count: int
|
||||
|
||||
# How many missiles group should we try to generate per CP on startup for this faction
|
||||
missiles_group_count: int
|
||||
|
||||
# Whether this faction has JTAC access
|
||||
has_jtac: bool
|
||||
|
||||
# Unit to use as JTAC
|
||||
# Unit to use as JTAC for this faction
|
||||
jtac_unit: str
|
||||
|
||||
# doctrine
|
||||
doctrine: Doctrine
|
||||
|
||||
# List of available buildings for this faction
|
||||
building_set: [str]
|
||||
|
||||
def __init__(self):
|
||||
self.country = ""
|
||||
self.name = ""
|
||||
@@ -83,14 +102,19 @@ class Faction:
|
||||
self.artillery_units = []
|
||||
self.infantry_units = []
|
||||
self.logistics_units = []
|
||||
self.shorad_units = []
|
||||
self.shorads = []
|
||||
self.sams = []
|
||||
self.missiles = []
|
||||
self.requirements = {}
|
||||
self.aircraft_carrier = []
|
||||
self.helicopter_carrier = []
|
||||
self.carrier_names = []
|
||||
self.lha_names = []
|
||||
self.navy_generators = []
|
||||
self.destroyers = []
|
||||
self.cruisers = []
|
||||
self.navy_group_count = 0
|
||||
self.missiles_group_count = 0
|
||||
self.has_jtac = False
|
||||
self.jtac_unit = ""
|
||||
self.doctrine = None
|
||||
@@ -111,18 +135,23 @@ class Faction:
|
||||
faction.artillery_units = [f for f in [vehicle_loader(vehicle) for vehicle in json.get("artillery_units", [])] if f is not None]
|
||||
faction.infantry_units = [f for f in [vehicle_loader(vehicle) for vehicle in json.get("infantry_units", [])] if f is not None]
|
||||
faction.logistics_units = [f for f in [vehicle_loader(vehicle) for vehicle in json.get("logistics_units", [])] if f is not None]
|
||||
faction.shorad_units = [f for f in [vehicle_loader(vehicle) for vehicle in json.get("shorad_units", [])] if f is not None]
|
||||
faction.shorads = [f for f in [vehicle_loader(vehicle) for vehicle in json.get("shorads", [])] if f is not None]
|
||||
|
||||
faction.sams = json.get("sams", [])
|
||||
faction.missiles = json.get("missiles", [])
|
||||
faction.name = json.get("requirements", {})
|
||||
|
||||
faction.carrier_names = json.get("carrier_names", [])
|
||||
faction.lha_names = json.get("lha_names", [])
|
||||
faction.navy_generators = json.get("navy_generators", [])
|
||||
faction.aircraft_carrier = [f for f in [ship_loader(vehicle) for vehicle in json.get("aircraft_carrier", [])] if f is not None]
|
||||
faction.helicopter_carrier = [f for f in [ship_loader(vehicle) for vehicle in json.get("helicopter_carrier", [])] if f is not None]
|
||||
faction.destroyers = [f for f in [ship_loader(vehicle) for vehicle in json.get("destroyers", [])] if f is not None]
|
||||
faction.cruisers = [f for f in [ship_loader(vehicle) for vehicle in json.get("cruisers", [])] if f is not None]
|
||||
faction.has_jtac = json.get("has_jtac", False)
|
||||
faction.jtac_unit = json.get("jtac_unit", "")
|
||||
faction.jtac_unit = aircraft_loader(json.get("jtac_unit", None))
|
||||
faction.navy_group_count = int(json.get("navy_group_count", 1))
|
||||
faction.missiles_group_count = int(json.get("missiles_group_count", 0))
|
||||
|
||||
# Load doctrine
|
||||
doctrine = json.get("doctrine", "modern")
|
||||
@@ -133,6 +162,15 @@ class Faction:
|
||||
else:
|
||||
faction.doctrine = WWII_DOCTRINE
|
||||
|
||||
# Load the building set
|
||||
building_set = json.get("building_set", "default")
|
||||
if building_set == "default":
|
||||
faction.building_set = DEFAULT_AVAILABLE_BUILDINGS
|
||||
elif building_set == "ww2ally":
|
||||
faction.building_set = WW2_ALLIES_BUILDINGS
|
||||
else:
|
||||
faction.building_set = WW2_GERMANY_BUILDINGS
|
||||
|
||||
return faction
|
||||
|
||||
@property
|
||||
@@ -146,7 +184,9 @@ def unit_loader(unit: str, class_repository:[]) -> Optional[PlaneType]:
|
||||
:param unit: Unit name as string
|
||||
:return: The unit as a PyDCS type
|
||||
"""
|
||||
if unit in plane_map.keys():
|
||||
if unit is None:
|
||||
return None
|
||||
elif unit in plane_map.keys():
|
||||
return plane_map[unit]
|
||||
else:
|
||||
for mother_class in class_repository:
|
||||
|
||||
16
game/game.py
16
game/game.py
@@ -26,6 +26,7 @@ from . import persistency
|
||||
from .debriefing import Debriefing
|
||||
from .event.event import Event, UnitsDeliveryEvent
|
||||
from .event.frontlineattack import FrontlineAttackEvent
|
||||
from .factions.faction import Faction
|
||||
from .infos.information import Information
|
||||
from .settings import Settings
|
||||
from plugin import LuaPluginManager
|
||||
@@ -76,9 +77,9 @@ class Game:
|
||||
self.events: List[Event] = []
|
||||
self.theater = theater
|
||||
self.player_name = player_name
|
||||
self.player_country = db.FACTIONS[player_name]["country"]
|
||||
self.player_country = db.FACTIONS[player_name].country
|
||||
self.enemy_name = enemy_name
|
||||
self.enemy_country = db.FACTIONS[enemy_name]["country"]
|
||||
self.enemy_country = db.FACTIONS[enemy_name].country
|
||||
self.turn = 0
|
||||
self.date = date(start_date.year, start_date.month, start_date.day)
|
||||
self.game_stats = GameStats()
|
||||
@@ -123,11 +124,11 @@ class Game:
|
||||
self.enemy_country = "Russia"
|
||||
|
||||
@property
|
||||
def player_faction(self) -> Dict[str, Any]:
|
||||
def player_faction(self) -> Faction:
|
||||
return db.FACTIONS[self.player_name]
|
||||
|
||||
@property
|
||||
def enemy_faction(self) -> Dict[str, Any]:
|
||||
def enemy_faction(self) -> Faction:
|
||||
return db.FACTIONS[self.enemy_name]
|
||||
|
||||
def _roll(self, prob, mult):
|
||||
@@ -314,7 +315,7 @@ class Game:
|
||||
potential_cp_armor = self.theater.enemy_points()
|
||||
|
||||
i = 0
|
||||
potential_units = [u for u in db.FACTIONS[self.enemy_name]["units"] if u in db.UNIT_BY_TASK[PinpointStrike]]
|
||||
potential_units = db.FACTIONS[self.enemy_name].frontline_units
|
||||
|
||||
print("Enemy Recruiting")
|
||||
print(potential_cp_armor)
|
||||
@@ -340,8 +341,9 @@ class Game:
|
||||
if budget_for_armored_units > 0:
|
||||
budget_for_aircraft += budget_for_armored_units
|
||||
|
||||
potential_units = [u for u in db.FACTIONS[self.enemy_name]["units"] if
|
||||
u in db.UNIT_BY_TASK[CAS] or u in db.UNIT_BY_TASK[CAP]]
|
||||
potential_units = [u for u in db.FACTIONS[self.enemy_name].aircrafts
|
||||
if u in db.UNIT_BY_TASK[CAS] or u in db.UNIT_BY_TASK[CAP]]
|
||||
|
||||
if len(potential_units) > 0 and len(potential_cp_armor) > 0:
|
||||
while budget_for_aircraft > 0:
|
||||
i = i + 1
|
||||
|
||||
@@ -66,9 +66,9 @@ class Operation:
|
||||
to_cp: ControlPoint):
|
||||
self.game = game
|
||||
self.attacker_name = attacker_name
|
||||
self.attacker_country = db.FACTIONS[attacker_name]["country"]
|
||||
self.attacker_country = db.FACTIONS[attacker_name].country
|
||||
self.defender_name = defender_name
|
||||
self.defender_country = db.FACTIONS[defender_name]["country"]
|
||||
self.defender_country = db.FACTIONS[defender_name].country
|
||||
print(self.defender_country, self.attacker_country)
|
||||
self.from_cp = from_cp
|
||||
self.departure_cp = departure_cp
|
||||
|
||||
Reference in New Issue
Block a user