mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Faction rework wip.
This commit is contained in:
parent
da2584d7ee
commit
24394d4d00
124
game/factions/faction.py
Normal file
124
game/factions/faction.py
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
import logging
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
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.doctrine import Doctrine
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Faction:
|
||||||
|
|
||||||
|
# Country used by this faction
|
||||||
|
country: str
|
||||||
|
|
||||||
|
# Nice name of the faction
|
||||||
|
name: str
|
||||||
|
|
||||||
|
# Available aircraft
|
||||||
|
aircrafts: [UnitType]
|
||||||
|
|
||||||
|
# Available awacs aircraft
|
||||||
|
awacs: [UnitType]
|
||||||
|
|
||||||
|
# Available tanker aircraft
|
||||||
|
tankers: [UnitType]
|
||||||
|
|
||||||
|
# Available frontline units
|
||||||
|
frontline_units: [VehicleType]
|
||||||
|
|
||||||
|
# Available artillery units
|
||||||
|
artillery_units: [VehicleType]
|
||||||
|
|
||||||
|
# Infantry units used
|
||||||
|
infantry_units: [VehicleType]
|
||||||
|
|
||||||
|
# List of units that can be deployed as SHORAD
|
||||||
|
shorad_units: [VehicleType]
|
||||||
|
|
||||||
|
# Possible SAMS site generators for this faction
|
||||||
|
sams: [str]
|
||||||
|
|
||||||
|
# Required mods or asset packs
|
||||||
|
requirements: {str: str}
|
||||||
|
|
||||||
|
# Possible carrier names
|
||||||
|
carrier_names: [str]
|
||||||
|
|
||||||
|
# Possible helicopter carrier names
|
||||||
|
lha_names: [str]
|
||||||
|
|
||||||
|
# Navy group generators
|
||||||
|
navy_generators: [str]
|
||||||
|
|
||||||
|
# Available destroyers
|
||||||
|
destroyers: [str]
|
||||||
|
|
||||||
|
# Available cruisers
|
||||||
|
cruisers: [str]
|
||||||
|
|
||||||
|
# JTAC
|
||||||
|
has_jtac: bool
|
||||||
|
|
||||||
|
# Unit to use as JTAC
|
||||||
|
jtac_unit: str
|
||||||
|
|
||||||
|
# doctrine
|
||||||
|
doctrine: Doctrine
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json):
|
||||||
|
|
||||||
|
faction = Faction()
|
||||||
|
|
||||||
|
faction.country = json.get("country", "USA")
|
||||||
|
faction.name = json.get("name", "???")
|
||||||
|
|
||||||
|
faction.aircrafts = [f for f in [aircraft_loader(aircraft) for aircraft in json.get("aircrafts", [])] is not None]
|
||||||
|
faction.awacs = [f for f in [aircraft_loader(aircraft) for aircraft in json.get("awacs", [])] is not None]
|
||||||
|
faction.tankers = [f for f in [aircraft_loader(aircraft) for aircraft in json.get("tankers", [])] is not None]
|
||||||
|
|
||||||
|
|
||||||
|
def aircraft_loader(aircraft: str) -> Optional[PlaneType]:
|
||||||
|
"""
|
||||||
|
Find aircraft by name
|
||||||
|
:param aircraft: Aircraft name as string
|
||||||
|
:return: The aircraft as a PyDCS type
|
||||||
|
"""
|
||||||
|
if aircraft in plane_map.keys():
|
||||||
|
return plane_map[aircraft]
|
||||||
|
else:
|
||||||
|
for mother_class in [PlaneType, Unarmed, Infantry, Armor, AirDefence, Artillery, Fortification]:
|
||||||
|
if getattr(mother_class, vehicle) is not None:
|
||||||
|
return getattr(mother_class, vehicle)
|
||||||
|
logging.info("FACTION ERROR : Unable to find " + aircraft + " in pydcs")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def vehicle_loader(vehicle: str) -> Optional[VehicleType]:
|
||||||
|
"""
|
||||||
|
Find vehicle by name
|
||||||
|
:param vehicle: Vehicle name as string
|
||||||
|
:return: The vehicle as a PyDCS type
|
||||||
|
"""
|
||||||
|
if vehicle in plane_map.keys():
|
||||||
|
return plane_map[vehicle]
|
||||||
|
else:
|
||||||
|
for mother_class in [Armor, Unarmed, Infantry, Armor, AirDefence, Artillery, Fortification]:
|
||||||
|
if getattr(mother_class, vehicle) is not None:
|
||||||
|
return getattr(mother_class, vehicle)
|
||||||
|
logging.info("FACTION ERROR : Unable to find " + vehicle + " in pydcs")
|
||||||
|
return None
|
||||||
|
|
||||||
|
vehicle_map
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
28
game/factions/faction_loader.py
Normal file
28
game/factions/faction_loader.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
FACTION_DIRECTORY = "./resources/factions/"
|
||||||
|
|
||||||
|
def load_factions() -> {}:
|
||||||
|
files = os.listdir(FACTION_DIRECTORY)
|
||||||
|
files = [f for f in files if f.endswith(".json")]
|
||||||
|
|
||||||
|
factions = {}
|
||||||
|
|
||||||
|
for f in files:
|
||||||
|
path = os.path.join(FACTION_DIRECTORY, f)
|
||||||
|
logging.info("Loading faction" + path)
|
||||||
|
try:
|
||||||
|
with open(path, "r") as fdata:
|
||||||
|
data = json.load(fdata)
|
||||||
|
factions[data["name"]] = data
|
||||||
|
logging.info("Loaded faction : " + path)
|
||||||
|
except:
|
||||||
|
logging.error("Unable to load faction : " + path)
|
||||||
|
|
||||||
|
return factions
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
load_factions()
|
||||||
81
resources/factions/china_2010.json
Normal file
81
resources/factions/china_2010.json
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"country": "China",
|
||||||
|
"name": "China 2010",
|
||||||
|
"aircrafts": [
|
||||||
|
"MiG_21Bis",
|
||||||
|
"Su_30",
|
||||||
|
"Su_33",
|
||||||
|
"J_11A",
|
||||||
|
"JF_17",
|
||||||
|
"Mi_8MT",
|
||||||
|
"Mi_28N"
|
||||||
|
],
|
||||||
|
"awacs": [
|
||||||
|
"KJ_2000"
|
||||||
|
],
|
||||||
|
"tankers": [
|
||||||
|
"IL_78M"
|
||||||
|
],
|
||||||
|
"frontline_units": [
|
||||||
|
"ZTZ_96B",
|
||||||
|
"MBT_T_55",
|
||||||
|
"ZBD_04A",
|
||||||
|
"IFV_BMP_1"
|
||||||
|
],
|
||||||
|
"artillery_units": [
|
||||||
|
"MLRS_9A52_Smerch",
|
||||||
|
"SPH_2S9_Nona"
|
||||||
|
],
|
||||||
|
"logistics_units": [
|
||||||
|
"Transport_Ural_375",
|
||||||
|
"Transport_UAZ_469"
|
||||||
|
],
|
||||||
|
"infantry_units": [
|
||||||
|
"Paratrooper_AKS",
|
||||||
|
"Infantry_Soldier_Rus",
|
||||||
|
"Paratrooper_RPG_16"
|
||||||
|
],
|
||||||
|
"shorad_units": [
|
||||||
|
"SAM_SA_9_Strela_1_9P31",
|
||||||
|
"SAM_SA_13_Strela_10M3_9A35M3",
|
||||||
|
"SPAAA_ZSU_23_4_Shilka",
|
||||||
|
"AAA_ZU_23_Closed"
|
||||||
|
],
|
||||||
|
"sams": [
|
||||||
|
"HQ7Generator",
|
||||||
|
"SA10Generator",
|
||||||
|
"SA6Generator"
|
||||||
|
],
|
||||||
|
"aircraft_carrier": [
|
||||||
|
"CV_1143_5_Admiral_Kuznetsov"
|
||||||
|
],
|
||||||
|
"carrier_names": [
|
||||||
|
"001 Liaoning",
|
||||||
|
"002 Shandong"
|
||||||
|
],
|
||||||
|
"helicopter_carrier": [
|
||||||
|
"Type_071_Amphibious_Transport_Dock"
|
||||||
|
],
|
||||||
|
"lhanames": [
|
||||||
|
"Kunlun Shan",
|
||||||
|
"Jinggang Shan",
|
||||||
|
"Changbai Shan",
|
||||||
|
"Yimeng Shan",
|
||||||
|
"Longhu Shan",
|
||||||
|
"Wuzhi Shan",
|
||||||
|
"Wudang Shan"
|
||||||
|
],
|
||||||
|
"destroyer": [
|
||||||
|
"Type_052B_Destroyer",
|
||||||
|
"Type_052C_Destroyer"
|
||||||
|
],
|
||||||
|
"cruiser": [
|
||||||
|
"Type_054A_Frigate"
|
||||||
|
],
|
||||||
|
"requirements": {},
|
||||||
|
"navy_generators": [
|
||||||
|
"Type54GroupGenerator"
|
||||||
|
],
|
||||||
|
"has_jtac": true,
|
||||||
|
"jtac_unit": "WingLoong_I"
|
||||||
|
}
|
||||||
75
resources/factions/russia_1990.json
Normal file
75
resources/factions/russia_1990.json
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
"country": "Russia",
|
||||||
|
"name": "Russia 1990",
|
||||||
|
"aircrafts": [
|
||||||
|
"MiG_23MLD",
|
||||||
|
"MiG_25PD",
|
||||||
|
"MiG_29A",
|
||||||
|
"MiG_29S",
|
||||||
|
"MiG_31",
|
||||||
|
"Su_27",
|
||||||
|
"Su_24M",
|
||||||
|
"Su_25",
|
||||||
|
"Ka_50"
|
||||||
|
],
|
||||||
|
"awacs": [
|
||||||
|
"A_50"
|
||||||
|
],
|
||||||
|
"tankers": [
|
||||||
|
"IL_78M"
|
||||||
|
],
|
||||||
|
"frontline_units": [
|
||||||
|
"ARV_BRDM_2",
|
||||||
|
"APC_BTR_80",
|
||||||
|
"IFV_BMD_1",
|
||||||
|
"IFV_BMP_1",
|
||||||
|
"MBT_T_55"
|
||||||
|
],
|
||||||
|
"artillery_units": [
|
||||||
|
"MLRS_9K57_Uragan_BM_27",
|
||||||
|
"SPH_2S19_Msta"
|
||||||
|
],
|
||||||
|
"logistics_units": [
|
||||||
|
"Transport_Ural_375",
|
||||||
|
"Transport_UAZ_469"
|
||||||
|
],
|
||||||
|
"infantry_units": [
|
||||||
|
"Paratrooper_AKS",
|
||||||
|
"Infantry_Soldier_Rus",
|
||||||
|
"Paratrooper_RPG_16"
|
||||||
|
],
|
||||||
|
"shorad_units": [
|
||||||
|
"SAM_SA_9_Strela_1_9P31",
|
||||||
|
"SAM_SA_13_Strela_10M3_9A35M3",
|
||||||
|
"SPAAA_ZSU_23_4_Shilka",
|
||||||
|
"AAA_ZU_23_Closed"
|
||||||
|
],
|
||||||
|
"sams": [
|
||||||
|
"SA6Generator",
|
||||||
|
"SA3Generator"
|
||||||
|
],
|
||||||
|
"aircraft_carrier": [
|
||||||
|
"CV_1143_5_Admiral_Kuznetsov"
|
||||||
|
],
|
||||||
|
"helicopter_carrier": [
|
||||||
|
],
|
||||||
|
"lhanames": [
|
||||||
|
],
|
||||||
|
"destroyer": [
|
||||||
|
"FF_1135M_Rezky"
|
||||||
|
],
|
||||||
|
"cruiser": [
|
||||||
|
"FSG_1241_1MP_Molniya"
|
||||||
|
],
|
||||||
|
"requirements": {},
|
||||||
|
"carrier_names": [
|
||||||
|
"Admiral Kuznetov",
|
||||||
|
"Admiral Gorshkov"
|
||||||
|
],
|
||||||
|
"navy_generators": [
|
||||||
|
"RussianNavyGroupGenerator",
|
||||||
|
"KiloSubGroupGenerator"
|
||||||
|
],
|
||||||
|
"has_jtac": true,
|
||||||
|
"jtac_unit": "MQ_9_Reaper"
|
||||||
|
}
|
||||||
81
resources/factions/usa_2005.json
Normal file
81
resources/factions/usa_2005.json
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"country": "USA",
|
||||||
|
"name": "USA 2005",
|
||||||
|
"aircrafts": [
|
||||||
|
"F_15C",
|
||||||
|
"F_15E",
|
||||||
|
"F_14B",
|
||||||
|
"FA_18C_hornet",
|
||||||
|
"F_16C_50",
|
||||||
|
"A_10C",
|
||||||
|
"A_10C_2",
|
||||||
|
"AV8BN",
|
||||||
|
"UH_1H",
|
||||||
|
"AH_64D"
|
||||||
|
],
|
||||||
|
"awacs": [
|
||||||
|
"E_3A"
|
||||||
|
],
|
||||||
|
"tankers": [
|
||||||
|
"KC_135",
|
||||||
|
"KC130"
|
||||||
|
],
|
||||||
|
"frontline_units": [
|
||||||
|
"MBT_M1A2_Abrams",
|
||||||
|
"ATGM_M1134_Stryker",
|
||||||
|
"APC_M1126_Stryker_ICV",
|
||||||
|
"IFV_M2A2_Bradley",
|
||||||
|
"IFV_LAV_25",
|
||||||
|
"APC_M1043_HMMWV_Armament",
|
||||||
|
"ATGM_M1045_HMMWV_TOW"
|
||||||
|
],
|
||||||
|
"artillery_units": [
|
||||||
|
"MLRS_M270",
|
||||||
|
"SPH_M109_Paladin"
|
||||||
|
],
|
||||||
|
"logistics_units": [
|
||||||
|
"Transport_M818"
|
||||||
|
],
|
||||||
|
"infantry_units": [
|
||||||
|
"Infantry_M4",
|
||||||
|
"Soldier_M249"
|
||||||
|
],
|
||||||
|
"shorad_units": [
|
||||||
|
"SAM_Avenger_M1097"
|
||||||
|
],
|
||||||
|
"sams": [
|
||||||
|
"HawkGenerator",
|
||||||
|
"PatriotGenerator"
|
||||||
|
],
|
||||||
|
"aircraft_carrier": [
|
||||||
|
"CVN_74_John_C__Stennis"
|
||||||
|
],
|
||||||
|
"helicopter_carrier": [
|
||||||
|
"LHA_1_Tarawa"
|
||||||
|
],
|
||||||
|
"destroyer": [
|
||||||
|
"USS_Arleigh_Burke_IIa"
|
||||||
|
],
|
||||||
|
"cruiser": [
|
||||||
|
"Ticonderoga_class"
|
||||||
|
],
|
||||||
|
"requirements": {},
|
||||||
|
"carrier_names": [
|
||||||
|
"CVN-71 Theodore Roosevelt",
|
||||||
|
"CVN-72 Abraham Lincoln",
|
||||||
|
"CVN-73 George Washington",
|
||||||
|
"CVN-74 John C. Stennis"
|
||||||
|
],
|
||||||
|
"lhanames": [
|
||||||
|
"LHA-1 Tarawa",
|
||||||
|
"LHA-2 Saipan",
|
||||||
|
"LHA-3 Belleau Wood",
|
||||||
|
"LHA-4 Nassau",
|
||||||
|
"LHA-5 Peleliu"
|
||||||
|
],
|
||||||
|
"navy_generators": [
|
||||||
|
"ArleighBurkeGroupGenerator"
|
||||||
|
],
|
||||||
|
"has_jtac": true,
|
||||||
|
"jtac_unit": "MQ_9_Reaper"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user