diff --git a/game/db.py b/game/db.py index c73f7dbf..05eaad06 100644 --- a/game/db.py +++ b/game/db.py @@ -1244,7 +1244,7 @@ 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]: +def unit_type_from_name(name: str) -> Optional[Type[UnitType]]: if name in vehicle_map: return vehicle_map[name] elif name in plane_map: diff --git a/game/event/event.py b/game/event/event.py index c4506fab..db8e5ee6 100644 --- a/game/event/event.py +++ b/game/event/event.py @@ -107,14 +107,16 @@ class Event: for destroyed_aircraft in debriefing.killed_aircrafts: try: cpid = int(destroyed_aircraft.split("|")[3]) - type = db.unit_type_from_name(destroyed_aircraft.split("|")[4]) - if cpid in cp_map.keys(): + aircraft = db.unit_type_from_name( + destroyed_aircraft.split("|")[4]) + if cpid in cp_map: cp = cp_map[cpid] - if type in cp.base.aircraft.keys(): - logging.info("Aircraft destroyed : " + str(type)) - cp.base.aircraft[type] = max(0, cp.base.aircraft[type]-1) - except Exception as e: - print(e) + if aircraft in cp.base.aircraft: + logging.info(f"Aircraft destroyed: {aircraft}") + cp.base.aircraft[aircraft] = max( + 0, cp.base.aircraft[aircraft] - 1) + except Exception: + logging.exception("Failed to commit destroyed aircraft") # ------------------------------ # Destroyed ground units @@ -123,13 +125,13 @@ class Event: for killed_ground_unit in debriefing.killed_ground_units: try: cpid = int(killed_ground_unit.split("|")[3]) - type = db.unit_type_from_name(killed_ground_unit.split("|")[4]) + aircraft = db.unit_type_from_name(killed_ground_unit.split("|")[4]) if cpid in cp_map.keys(): killed_unit_count_by_cp[cpid] = killed_unit_count_by_cp[cpid] + 1 cp = cp_map[cpid] - if type in cp.base.armor.keys(): - logging.info("Ground unit destroyed : " + str(type)) - cp.base.armor[type] = max(0, cp.base.armor[type] - 1) + if aircraft in cp.base.armor.keys(): + logging.info("Ground unit destroyed : " + str(aircraft)) + cp.base.armor[aircraft] = max(0, cp.base.armor[aircraft] - 1) except Exception as e: print(e) diff --git a/game/inventory.py b/game/inventory.py index 3c92a80f..80adb72b 100644 --- a/game/inventory.py +++ b/game/inventory.py @@ -2,7 +2,7 @@ from __future__ import annotations from collections import defaultdict -from typing import Dict, Iterable, Iterator, Set, Tuple, TYPE_CHECKING +from typing import Dict, Iterable, Iterator, Set, Tuple, TYPE_CHECKING, Type from dcs.unittype import FlyingType @@ -17,9 +17,9 @@ class ControlPointAircraftInventory: def __init__(self, control_point: ControlPoint) -> None: self.control_point = control_point - self.inventory: Dict[FlyingType, int] = defaultdict(int) + self.inventory: Dict[Type[FlyingType], int] = defaultdict(int) - def add_aircraft(self, aircraft: FlyingType, count: int) -> None: + def add_aircraft(self, aircraft: Type[FlyingType], count: int) -> None: """Adds aircraft to the inventory. Args: @@ -28,7 +28,7 @@ class ControlPointAircraftInventory: """ self.inventory[aircraft] += count - def remove_aircraft(self, aircraft: FlyingType, count: int) -> None: + def remove_aircraft(self, aircraft: Type[FlyingType], count: int) -> None: """Removes aircraft from the inventory. Args: @@ -47,7 +47,7 @@ class ControlPointAircraftInventory: ) self.inventory[aircraft] -= count - def available(self, aircraft: FlyingType) -> int: + def available(self, aircraft: Type[FlyingType]) -> int: """Returns the number of available aircraft of the given type. Args: diff --git a/game/theater/base.py b/game/theater/base.py index 40f604fc..ba8a72f8 100644 --- a/game/theater/base.py +++ b/game/theater/base.py @@ -22,7 +22,7 @@ BASE_MIN_STRENGTH = 0 class Base: def __init__(self): - self.aircraft: Dict[FlyingType, int] = {} + self.aircraft: Dict[Type[FlyingType], int] = {} self.armor: Dict[VehicleType, int] = {} self.aa: Dict[AirDefence, int] = {} self.commision_points: Dict[Type, float] = {} diff --git a/gen/flights/flight.py b/gen/flights/flight.py index 56d9d04a..276a6396 100644 --- a/gen/flights/flight.py +++ b/gen/flights/flight.py @@ -2,7 +2,7 @@ from __future__ import annotations from datetime import timedelta from enum import Enum -from typing import Dict, List, Optional, TYPE_CHECKING +from typing import Dict, List, Optional, TYPE_CHECKING, Type from dcs.mapping import Point from dcs.point import MovingPoint, PointAction @@ -133,8 +133,8 @@ class FlightWaypoint: class Flight: - def __init__(self, package: Package, unit_type: FlyingType, count: int, - flight_type: FlightType, start_type: str, + def __init__(self, package: Package, unit_type: Type[FlyingType], + count: int, flight_type: FlightType, start_type: str, departure: ControlPoint, arrival: ControlPoint, divert: Optional[ControlPoint]) -> None: self.package = package diff --git a/qt_ui/windows/basemenu/QRecruitBehaviour.py b/qt_ui/windows/basemenu/QRecruitBehaviour.py index 8e0e77d3..7f462c57 100644 --- a/qt_ui/windows/basemenu/QRecruitBehaviour.py +++ b/qt_ui/windows/basemenu/QRecruitBehaviour.py @@ -1,4 +1,5 @@ import logging +from typing import Type from PySide2.QtWidgets import ( QGroupBox, @@ -106,7 +107,7 @@ class QRecruitBehaviour: return row + 1 - def _update_count_label(self, unit_type: UnitType): + def _update_count_label(self, unit_type: Type[UnitType]): self.bought_amount_labels[unit_type].setText("{}".format( unit_type in self.pending_deliveries.units and "{}".format(self.pending_deliveries.units[unit_type]) or "0" @@ -125,7 +126,7 @@ class QRecruitBehaviour: child.setText( QRecruitBehaviour.BUDGET_FORMAT.format(self.budget)) - def buy(self, unit_type): + def buy(self, unit_type: Type[UnitType]): price = db.PRICES[unit_type] if self.budget >= price: self.pending_deliveries.deliver({unit_type: 1})