diff --git a/game/armedforces/forcegroup.py b/game/armedforces/forcegroup.py index 7410e509..9609d6be 100644 --- a/game/armedforces/forcegroup.py +++ b/game/armedforces/forcegroup.py @@ -281,8 +281,15 @@ class ForceGroup: logging.error(f"ForceGroup {name} has no valid tasking") continue - units = [UnitType.named(unit) for unit in data.get("units")] - if not units: + units: list[UnitType[Any]] = [] + for unit in data.get("units"): + if GroundUnitType.exists(unit): + units.append(GroundUnitType.named(unit)) + elif ShipUnitType.exists(unit): + units.append(ShipUnitType.named(unit)) + else: + logging.error(f"Unit {unit} of ForceGroup {name} is invalid") + if len(units) == 0: logging.error(f"ForceGroup {name} has no valid units") continue diff --git a/game/dcs/unittype.py b/game/dcs/unittype.py index 54ff82eb..8ca3425b 100644 --- a/game/dcs/unittype.py +++ b/game/dcs/unittype.py @@ -45,7 +45,7 @@ class UnitType(ABC, Generic[DcsUnitTypeT]): @classmethod def named(cls, name: str) -> UnitType[Any]: - return cls._by_name[name] + raise NotImplementedError @classmethod def for_dcs_type(cls, dcs_unit_type: DcsUnitTypeT) -> Iterator[UnitType[Any]]: @@ -69,3 +69,13 @@ class UnitType(ABC, Generic[DcsUnitTypeT]): @cached_property def eplrs_capable(self) -> bool: return getattr(self.dcs_unit_type, "eplrs", False) + + @classmethod + def exists(cls, name: str) -> bool: + if not cls._loaded: + cls._load_all() + try: + cls.named(name) + return True + except (KeyError, AssertionError): + return False