mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Move pydcs helper function out of db.
This commit is contained in:
parent
b4742ad54c
commit
4f64329f25
27
game/db.py
27
game/db.py
@ -1,16 +1,10 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional, Type
|
from typing import Type
|
||||||
|
|
||||||
from dcs.countries import country_dict
|
from dcs.countries import country_dict
|
||||||
from dcs.helicopters import (
|
|
||||||
helicopter_map,
|
|
||||||
)
|
|
||||||
|
|
||||||
# mypy can't resolve these if they're wildcard imports for some reason.
|
# mypy can't resolve these if they're wildcard imports for some reason.
|
||||||
from dcs.planes import (
|
|
||||||
plane_map,
|
|
||||||
)
|
|
||||||
from dcs.ships import (
|
from dcs.ships import (
|
||||||
CVN_71,
|
CVN_71,
|
||||||
CVN_72,
|
CVN_72,
|
||||||
@ -19,12 +13,8 @@ from dcs.ships import (
|
|||||||
CV_1143_5,
|
CV_1143_5,
|
||||||
KUZNECOW,
|
KUZNECOW,
|
||||||
Stennis,
|
Stennis,
|
||||||
ship_map,
|
|
||||||
)
|
|
||||||
from dcs.unittype import ShipType, UnitType
|
|
||||||
from dcs.vehicles import (
|
|
||||||
vehicle_map,
|
|
||||||
)
|
)
|
||||||
|
from dcs.unittype import ShipType
|
||||||
|
|
||||||
# PATCH pydcs data with MODS
|
# PATCH pydcs data with MODS
|
||||||
|
|
||||||
@ -141,19 +131,6 @@ def upgrade_to_supercarrier(unit: Type[ShipType], name: str) -> Type[ShipType]:
|
|||||||
return unit
|
return unit
|
||||||
|
|
||||||
|
|
||||||
def unit_type_from_name(name: str) -> Optional[Type[UnitType]]:
|
|
||||||
if name in vehicle_map:
|
|
||||||
return vehicle_map[name]
|
|
||||||
elif name in plane_map:
|
|
||||||
return plane_map[name]
|
|
||||||
elif name in ship_map:
|
|
||||||
return ship_map[name]
|
|
||||||
if name in helicopter_map:
|
|
||||||
return helicopter_map[name]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def country_id_from_name(name: str) -> int:
|
def country_id_from_name(name: str) -> int:
|
||||||
for k, v in country_dict.items():
|
for k, v in country_dict.items():
|
||||||
if v.name == name:
|
if v.name == name:
|
||||||
|
|||||||
0
game/dcs/__init__.py
Normal file
0
game/dcs/__init__.py
Normal file
20
game/dcs/helpers.py
Normal file
20
game/dcs/helpers.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from typing import Optional, Type
|
||||||
|
|
||||||
|
from dcs.helicopters import helicopter_map
|
||||||
|
from dcs.planes import plane_map
|
||||||
|
from dcs.ships import ship_map
|
||||||
|
from dcs.unittype import UnitType
|
||||||
|
from dcs.vehicles import vehicle_map
|
||||||
|
|
||||||
|
|
||||||
|
def unit_type_from_name(name: str) -> Optional[Type[UnitType]]:
|
||||||
|
if name in vehicle_map:
|
||||||
|
return vehicle_map[name]
|
||||||
|
elif name in plane_map:
|
||||||
|
return plane_map[name]
|
||||||
|
elif name in ship_map:
|
||||||
|
return ship_map[name]
|
||||||
|
if name in helicopter_map:
|
||||||
|
return helicopter_map[name]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
@ -39,7 +39,6 @@ from game.ato.flighttype import FlightType
|
|||||||
from game.ato.flightwaypoint import FlightWaypoint
|
from game.ato.flightwaypoint import FlightWaypoint
|
||||||
from game.ato.flightwaypointtype import FlightWaypointType
|
from game.ato.flightwaypointtype import FlightWaypointType
|
||||||
from game.data.alic import AlicCodes
|
from game.data.alic import AlicCodes
|
||||||
from game.db import unit_type_from_name
|
|
||||||
from game.dcs.aircrafttype import AircraftType
|
from game.dcs.aircrafttype import AircraftType
|
||||||
from game.radio.radios import RadioFrequency
|
from game.radio.radios import RadioFrequency
|
||||||
from game.theater import ConflictTheater, LatLon, TheaterGroundObject
|
from game.theater import ConflictTheater, LatLon, TheaterGroundObject
|
||||||
@ -50,6 +49,7 @@ from gen.runways import RunwayData
|
|||||||
from .aircraft.flightdata import FlightData
|
from .aircraft.flightdata import FlightData
|
||||||
from .airsupportgenerator import AwacsInfo, TankerInfo
|
from .airsupportgenerator import AwacsInfo, TankerInfo
|
||||||
from .briefinggenerator import CommInfo, JtacInfo, MissionInfoGenerator
|
from .briefinggenerator import CommInfo, JtacInfo, MissionInfoGenerator
|
||||||
|
from ..dcs.helpers import unit_type_from_name
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game import Game
|
from game import Game
|
||||||
|
|||||||
@ -11,6 +11,7 @@ from dcs.coalition import Coalition
|
|||||||
from dcs.countries import country_dict
|
from dcs.countries import country_dict
|
||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
|
from game.dcs.helpers import unit_type_from_name
|
||||||
from game.missiongenerator.aircraft.aircraftgenerator import (
|
from game.missiongenerator.aircraft.aircraftgenerator import (
|
||||||
AircraftGenerator,
|
AircraftGenerator,
|
||||||
)
|
)
|
||||||
@ -283,7 +284,7 @@ class MissionGenerator:
|
|||||||
raise TypeError(
|
raise TypeError(
|
||||||
"Expected the type of the destroyed static to be a string"
|
"Expected the type of the destroyed static to be a string"
|
||||||
)
|
)
|
||||||
utype = db.unit_type_from_name(type_name)
|
utype = unit_type_from_name(type_name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.warning(f"Destroyed unit has no type: {d}")
|
logging.warning(f"Destroyed unit has no type: {d}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -46,7 +46,7 @@ from dcs.vehicles import vehicle_map
|
|||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
from game.data.building_data import FORTIFICATION_UNITS, FORTIFICATION_UNITS_ID
|
from game.data.building_data import FORTIFICATION_UNITS, FORTIFICATION_UNITS_ID
|
||||||
from game.db import unit_type_from_name
|
from game.dcs.helpers import unit_type_from_name
|
||||||
from game.radio.radios import RadioFrequency, RadioRegistry
|
from game.radio.radios import RadioFrequency, RadioRegistry
|
||||||
from game.radio.tacan import TacanBand, TacanChannel, TacanRegistry, TacanUsage
|
from game.radio.tacan import TacanBand, TacanChannel, TacanRegistry, TacanUsage
|
||||||
from game.theater import ControlPoint, TheaterGroundObject
|
from game.theater import ControlPoint, TheaterGroundObject
|
||||||
|
|||||||
@ -29,7 +29,7 @@ from dcs.terrain.terrain import Airport, ParkingSlot
|
|||||||
from dcs.unit import Unit
|
from dcs.unit import Unit
|
||||||
from dcs.unitgroup import ShipGroup, StaticGroup
|
from dcs.unitgroup import ShipGroup, StaticGroup
|
||||||
|
|
||||||
from game import db
|
from game.dcs.helpers import unit_type_from_name
|
||||||
from game.point_with_heading import PointWithHeading
|
from game.point_with_heading import PointWithHeading
|
||||||
from game.scenery_group import SceneryGroup
|
from game.scenery_group import SceneryGroup
|
||||||
from game.utils import Heading
|
from game.utils import Heading
|
||||||
@ -520,7 +520,7 @@ class ControlPoint(MissionTarget, ABC):
|
|||||||
if g.dcs_identifier == "CARRIER":
|
if g.dcs_identifier == "CARRIER":
|
||||||
for group in g.groups:
|
for group in g.groups:
|
||||||
for u in group.units:
|
for u in group.units:
|
||||||
if db.unit_type_from_name(u.type) in [
|
if unit_type_from_name(u.type) in [
|
||||||
Forrestal,
|
Forrestal,
|
||||||
Stennis,
|
Stennis,
|
||||||
KUZNECOW,
|
KUZNECOW,
|
||||||
@ -529,7 +529,7 @@ class ControlPoint(MissionTarget, ABC):
|
|||||||
elif g.dcs_identifier == "LHA":
|
elif g.dcs_identifier == "LHA":
|
||||||
for group in g.groups:
|
for group in g.groups:
|
||||||
for u in group.units:
|
for u in group.units:
|
||||||
if db.unit_type_from_name(u.type) in [LHA_Tarawa]:
|
if unit_type_from_name(u.type) in [LHA_Tarawa]:
|
||||||
return group.name
|
return group.name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -1012,7 +1012,7 @@ class NavalControlPoint(ControlPoint, ABC):
|
|||||||
# while its escorts are still alive.
|
# while its escorts are still alive.
|
||||||
for group in self.find_main_tgo().groups:
|
for group in self.find_main_tgo().groups:
|
||||||
for u in group.units:
|
for u in group.units:
|
||||||
if db.unit_type_from_name(u.type) in [
|
if unit_type_from_name(u.type) in [
|
||||||
Forrestal,
|
Forrestal,
|
||||||
Stennis,
|
Stennis,
|
||||||
LHA_Tarawa,
|
LHA_Tarawa,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from dcs.unit import Unit
|
|||||||
from dcs.unitgroup import ShipGroup, VehicleGroup
|
from dcs.unitgroup import ShipGroup, VehicleGroup
|
||||||
from dcs.vehicles import vehicle_map
|
from dcs.vehicles import vehicle_map
|
||||||
|
|
||||||
from .. import db
|
from game.dcs.helpers import unit_type_from_name
|
||||||
from ..data.radar_db import LAUNCHER_TRACKER_PAIRS, TELARS, TRACK_RADARS
|
from ..data.radar_db import LAUNCHER_TRACKER_PAIRS, TELARS, TRACK_RADARS
|
||||||
from ..utils import Distance, Heading, meters
|
from ..utils import Distance, Heading, meters
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ class TheaterGroundObject(MissionTarget, Generic[GroupT]):
|
|||||||
|
|
||||||
max_range = meters(0)
|
max_range = meters(0)
|
||||||
for u in group.units:
|
for u in group.units:
|
||||||
unit = db.unit_type_from_name(u.type)
|
unit = unit_type_from_name(u.type)
|
||||||
if unit is None:
|
if unit is None:
|
||||||
logging.error(f"Unknown unit type {u.type}")
|
logging.error(f"Unknown unit type {u.type}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user