mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix unit variants to actually allow variance.
This was always the intent, but apparently it wasn't implemented correctly. All properties of the unit type can now be overridden per variant.
This commit is contained in:
parent
ee3bdf9fd7
commit
0ec375ad89
@ -230,6 +230,7 @@ BAI/ANTISHIP/DEAD/STRIKE/BARCAP/CAS/OCA/AIR-ASSAULT (main) missions
|
|||||||
* **[Mission Generation]** Restored previous AI behavior for anti-ship missions. A DCS update caused only a single aircraft in a flight to attack. The full flight will now attack like they used to.
|
* **[Mission Generation]** Restored previous AI behavior for anti-ship missions. A DCS update caused only a single aircraft in a flight to attack. The full flight will now attack like they used to.
|
||||||
* **[Mission Generation]** Fix generation of OCA Runway missions to allow LGBs to be used.
|
* **[Mission Generation]** Fix generation of OCA Runway missions to allow LGBs to be used.
|
||||||
* **[Mission Generation]** Fixed AI flights flying far too slowly toward NAV points.
|
* **[Mission Generation]** Fixed AI flights flying far too slowly toward NAV points.
|
||||||
|
* **[Modding]** Unit variants can now actually override base unit type properties.
|
||||||
* **[Plugins]** Fixed Lua errors in Skynet plugin that would occur whenever one coalition had no IADS nodes.
|
* **[Plugins]** Fixed Lua errors in Skynet plugin that would occur whenever one coalition had no IADS nodes.
|
||||||
* **[UI]** Fixed deleting waypoints in custom flight plans deleting the wrong waypoint.
|
* **[UI]** Fixed deleting waypoints in custom flight plans deleting the wrong waypoint.
|
||||||
* **[UI]** Fixed flight properties UI to support F-15E S4+ laser codes.
|
* **[UI]** Fixed flight properties UI to support F-15E S4+ laser codes.
|
||||||
|
|||||||
@ -399,11 +399,11 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _set_props_overrides(
|
def _set_props_overrides(
|
||||||
config: Dict[str, Any], aircraft: Type[FlyingType], data_path: Path
|
config: Dict[str, Any], aircraft: Type[FlyingType]
|
||||||
) -> None:
|
) -> None:
|
||||||
if aircraft.property_defaults is None:
|
if aircraft.property_defaults is None:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"'{data_path.name}' attempted to set default prop that does not exist."
|
f"'{aircraft.id}' attempted to set default prop that does not exist."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
for k in config:
|
for k in config:
|
||||||
@ -411,25 +411,22 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
aircraft.property_defaults[k] = config[k]
|
aircraft.property_defaults[k] = config[k]
|
||||||
else:
|
else:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"'{data_path.name}' attempted to set default prop '{k}' that does not exist"
|
f"'{aircraft.id}' attempted to set default prop '{k}' that does not exist"
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _each_variant_of(cls, aircraft: Type[FlyingType]) -> Iterator[AircraftType]:
|
def _data_directory(cls) -> Path:
|
||||||
# Replace slashes with underscores because slashes are not allowed in filenames
|
return Path("resources/units/aircraft")
|
||||||
aircraft_id = aircraft.id.replace("/", "_")
|
|
||||||
data_path = Path("resources/units/aircraft") / f"{aircraft_id}.yaml"
|
|
||||||
if not data_path.exists():
|
|
||||||
logging.warning(f"No data for {aircraft_id}; it will not be available")
|
|
||||||
return
|
|
||||||
|
|
||||||
with data_path.open(encoding="utf-8") as data_file:
|
@classmethod
|
||||||
data = yaml.safe_load(data_file)
|
def _variant_from_dict(
|
||||||
|
cls, aircraft: Type[FlyingType], variant_id: str, data: dict[str, Any]
|
||||||
|
) -> AircraftType:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
price = data["price"]
|
price = data["price"]
|
||||||
except KeyError as ex:
|
except KeyError as ex:
|
||||||
raise KeyError(f"Missing required price field: {data_path}") from ex
|
raise KeyError(f"Missing required price field") from ex
|
||||||
|
|
||||||
radio_config = RadioConfig.from_data(data.get("radios", {}))
|
radio_config = RadioConfig.from_data(data.get("radios", {}))
|
||||||
patrol_config = PatrolConfig.from_data(data.get("patrol", {}))
|
patrol_config = PatrolConfig.from_data(data.get("patrol", {}))
|
||||||
@ -441,7 +438,7 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
nautical_miles(50) if aircraft.helicopter else nautical_miles(150)
|
nautical_miles(50) if aircraft.helicopter else nautical_miles(150)
|
||||||
)
|
)
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"{aircraft_id} does not specify a max_range. Defaulting to "
|
f"{variant_id} does not specify a max_range. Defaulting to "
|
||||||
f"{mission_range.nautical_miles}NM"
|
f"{mission_range.nautical_miles}NM"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -472,7 +469,7 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
|
|
||||||
prop_overrides = data.get("default_overrides")
|
prop_overrides = data.get("default_overrides")
|
||||||
if prop_overrides is not None:
|
if prop_overrides is not None:
|
||||||
cls._set_props_overrides(prop_overrides, aircraft, data_path)
|
cls._set_props_overrides(prop_overrides, aircraft)
|
||||||
|
|
||||||
from game.ato.flighttype import FlightType
|
from game.ato.flighttype import FlightType
|
||||||
|
|
||||||
@ -480,19 +477,12 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
for task_name, priority in data.get("tasks", {}).items():
|
for task_name, priority in data.get("tasks", {}).items():
|
||||||
task_priorities[FlightType(task_name)] = priority
|
task_priorities[FlightType(task_name)] = priority
|
||||||
|
|
||||||
if FlightType.SEAD in task_priorities:
|
return AircraftType(
|
||||||
task_priorities[FlightType.SEAD_SWEEP] = task_priorities[FlightType.SEAD]
|
|
||||||
|
|
||||||
cls._custom_weapon_injections(aircraft, data)
|
|
||||||
cls._user_weapon_injections(aircraft)
|
|
||||||
|
|
||||||
for variant in data.get("variants", [aircraft.id]):
|
|
||||||
yield AircraftType(
|
|
||||||
dcs_unit_type=aircraft,
|
dcs_unit_type=aircraft,
|
||||||
variant_id=variant,
|
variant_id=variant_id,
|
||||||
description=data.get(
|
description=data.get(
|
||||||
"description",
|
"description",
|
||||||
f"No data. <a href=\"https://google.com/search?q=DCS+{variant.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant}</span></a>",
|
f"No data. <a href=\"https://google.com/search?q=DCS+{variant_id.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant_id}</span></a>",
|
||||||
),
|
),
|
||||||
year_introduced=introduction,
|
year_introduced=introduction,
|
||||||
country_of_origin=data.get("origin", "No data."),
|
country_of_origin=data.get("origin", "No data."),
|
||||||
@ -517,8 +507,8 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
unit_class=unit_class,
|
unit_class=unit_class,
|
||||||
cabin_size=data.get("cabin_size", 10 if aircraft.helicopter else 0),
|
cabin_size=data.get("cabin_size", 10 if aircraft.helicopter else 0),
|
||||||
can_carry_crates=data.get("can_carry_crates", aircraft.helicopter),
|
can_carry_crates=data.get("can_carry_crates", aircraft.helicopter),
|
||||||
has_built_in_target_pod=data.get("has_built_in_target_pod", False),
|
|
||||||
task_priorities=task_priorities,
|
task_priorities=task_priorities,
|
||||||
|
has_built_in_target_pod=data.get("has_built_in_target_pod", False),
|
||||||
laser_code_configs=[
|
laser_code_configs=[
|
||||||
LaserCodeConfig.from_yaml(d) for d in data.get("laser_codes", [])
|
LaserCodeConfig.from_yaml(d) for d in data.get("laser_codes", [])
|
||||||
],
|
],
|
||||||
|
|||||||
@ -6,7 +6,6 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, ClassVar, Iterator, Optional, Type
|
from typing import Any, ClassVar, Iterator, Optional, Type
|
||||||
|
|
||||||
import yaml
|
|
||||||
from dcs.unittype import VehicleType
|
from dcs.unittype import VehicleType
|
||||||
from dcs.vehicles import vehicle_map
|
from dcs.vehicles import vehicle_map
|
||||||
|
|
||||||
@ -97,15 +96,13 @@ class GroundUnitType(UnitType[Type[VehicleType]]):
|
|||||||
yield from vehicle_map.values()
|
yield from vehicle_map.values()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _each_variant_of(cls, vehicle: Type[VehicleType]) -> Iterator[GroundUnitType]:
|
def _data_directory(cls) -> Path:
|
||||||
data_path = Path("resources/units/ground_units") / f"{vehicle.id}.yaml"
|
return Path("resources/units/ground_units")
|
||||||
if not data_path.exists():
|
|
||||||
logging.warning(f"No data for {vehicle.id}; it will not be available")
|
|
||||||
return
|
|
||||||
|
|
||||||
with data_path.open(encoding="utf-8") as data_file:
|
|
||||||
data = yaml.safe_load(data_file)
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _variant_from_dict(
|
||||||
|
cls, vehicle: Type[VehicleType], variant_id: str, data: dict[str, Any]
|
||||||
|
) -> GroundUnitType:
|
||||||
try:
|
try:
|
||||||
introduction = data["introduced"]
|
introduction = data["introduced"]
|
||||||
if introduction is None:
|
if introduction is None:
|
||||||
@ -120,15 +117,14 @@ class GroundUnitType(UnitType[Type[VehicleType]]):
|
|||||||
else:
|
else:
|
||||||
unit_class = UnitClass(class_name)
|
unit_class = UnitClass(class_name)
|
||||||
|
|
||||||
for variant in data.get("variants", [vehicle.id]):
|
return GroundUnitType(
|
||||||
yield GroundUnitType(
|
|
||||||
dcs_unit_type=vehicle,
|
dcs_unit_type=vehicle,
|
||||||
unit_class=unit_class,
|
unit_class=unit_class,
|
||||||
spawn_weight=data.get("spawn_weight", 0),
|
spawn_weight=data.get("spawn_weight", 0),
|
||||||
variant_id=variant,
|
variant_id=variant_id,
|
||||||
description=data.get(
|
description=data.get(
|
||||||
"description",
|
"description",
|
||||||
f"No data. <a href=\"https://google.com/search?q=DCS+{variant.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant}</span></a>",
|
f"No data. <a href=\"https://google.com/search?q=DCS+{variant_id.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant_id}</span></a>",
|
||||||
),
|
),
|
||||||
year_introduced=introduction,
|
year_introduced=introduction,
|
||||||
country_of_origin=data.get("origin", "No data."),
|
country_of_origin=data.get("origin", "No data."),
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import ClassVar, Iterator, Type, Any
|
from typing import ClassVar, Iterator, Type, Any
|
||||||
|
|
||||||
import yaml
|
|
||||||
from dcs.ships import ship_map
|
from dcs.ships import ship_map
|
||||||
from dcs.unittype import ShipType
|
from dcs.unittype import ShipType
|
||||||
|
|
||||||
@ -53,15 +51,13 @@ class ShipUnitType(UnitType[Type[ShipType]]):
|
|||||||
yield from ship_map.values()
|
yield from ship_map.values()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _each_variant_of(cls, ship: Type[ShipType]) -> Iterator[ShipUnitType]:
|
def _data_directory(cls) -> Path:
|
||||||
data_path = Path("resources/units/ships") / f"{ship.id}.yaml"
|
return Path("resources/units/ships")
|
||||||
if not data_path.exists():
|
|
||||||
logging.warning(f"No data for {ship.id}; it will not be available")
|
|
||||||
return
|
|
||||||
|
|
||||||
with data_path.open(encoding="utf-8") as data_file:
|
|
||||||
data = yaml.safe_load(data_file)
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _variant_from_dict(
|
||||||
|
cls, ship: Type[ShipType], variant_id: str, data: dict[str, Any]
|
||||||
|
) -> ShipUnitType:
|
||||||
try:
|
try:
|
||||||
introduction = data["introduced"]
|
introduction = data["introduced"]
|
||||||
if introduction is None:
|
if introduction is None:
|
||||||
@ -72,18 +68,17 @@ class ShipUnitType(UnitType[Type[ShipType]]):
|
|||||||
class_name = data.get("class")
|
class_name = data.get("class")
|
||||||
unit_class = UnitClass(class_name)
|
unit_class = UnitClass(class_name)
|
||||||
|
|
||||||
for variant in data.get("variants", [ship.id]):
|
return ShipUnitType(
|
||||||
yield ShipUnitType(
|
|
||||||
dcs_unit_type=ship,
|
dcs_unit_type=ship,
|
||||||
unit_class=unit_class,
|
unit_class=unit_class,
|
||||||
variant_id=variant,
|
variant_id=variant_id,
|
||||||
description=data.get(
|
description=data.get(
|
||||||
"description",
|
"description",
|
||||||
f"No data. <a href=\"https://google.com/search?q=DCS+{variant.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant}</span></a>",
|
f"No data. <a href=\"https://google.com/search?q=DCS+{variant_id.replace(' ', '+')}\"><span style=\"color:#FFFFFF\">Google {variant_id}</span></a>",
|
||||||
),
|
),
|
||||||
year_introduced=introduction,
|
year_introduced=introduction,
|
||||||
country_of_origin=data.get("origin", "No data."),
|
country_of_origin=data.get("origin", "No data."),
|
||||||
manufacturer=data.get("manufacturer", "No data."),
|
manufacturer=data.get("manufacturer", "No data."),
|
||||||
role=data.get("role", "No data."),
|
role=data.get("role", "No data."),
|
||||||
price=data.get("price"),
|
price=data["price"],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import ClassVar, Generic, Iterator, Type, TypeVar
|
from pathlib import Path
|
||||||
from typing_extensions import Self
|
from typing import ClassVar, Generic, Iterator, Type, TypeVar, Any
|
||||||
|
|
||||||
|
import yaml
|
||||||
from dcs.unittype import UnitType as DcsUnitType
|
from dcs.unittype import UnitType as DcsUnitType
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
from game.data.units import UnitClass
|
from game.data.units import UnitClass
|
||||||
|
|
||||||
@ -50,8 +53,29 @@ class UnitType(ABC, Generic[DcsUnitTypeT]):
|
|||||||
def each_dcs_type() -> Iterator[DcsUnitTypeT]:
|
def each_dcs_type() -> Iterator[DcsUnitTypeT]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _data_directory(cls) -> Path:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _each_variant_of(cls, unit: DcsUnitTypeT) -> Iterator[Self]:
|
def _each_variant_of(cls, unit: DcsUnitTypeT) -> Iterator[Self]:
|
||||||
|
data_path = cls._data_directory() / f"{unit.id}.yaml"
|
||||||
|
if not data_path.exists():
|
||||||
|
logging.warning(f"No data for {unit.id}; it will not be available")
|
||||||
|
return
|
||||||
|
|
||||||
|
with data_path.open(encoding="utf-8") as data_file:
|
||||||
|
data = yaml.safe_load(data_file)
|
||||||
|
|
||||||
|
for variant_id, variant_data in data.get("variants", {unit.id: {}}).items():
|
||||||
|
if variant_data is None:
|
||||||
|
variant_data = {}
|
||||||
|
yield cls._variant_from_dict(unit, variant_id, data | variant_data)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _variant_from_dict(
|
||||||
|
cls, dcs_unit_type: DcsUnitTypeT, variant_id: str, data: dict[str, Any]
|
||||||
|
) -> Self:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user