mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Disallow partially specified generics.
This commit is contained in:
parent
fc32b98341
commit
69c3d41a8a
@ -2,6 +2,8 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from dcs.unit import UnitType as DcsUnitType
|
||||||
|
|
||||||
from game.dcs.aircrafttype import AircraftType
|
from game.dcs.aircrafttype import AircraftType
|
||||||
from game.dcs.groundunittype import GroundUnitType
|
from game.dcs.groundunittype import GroundUnitType
|
||||||
from game.dcs.unittype import UnitType
|
from game.dcs.unittype import UnitType
|
||||||
@ -31,7 +33,7 @@ class Base:
|
|||||||
total += unit_type.price * count
|
total += unit_type.price * count
|
||||||
return total
|
return total
|
||||||
|
|
||||||
def total_units_of_type(self, unit_type: UnitType) -> int:
|
def total_units_of_type(self, unit_type: UnitType[DcsUnitType]) -> int:
|
||||||
return sum(
|
return sum(
|
||||||
[
|
[
|
||||||
c
|
c
|
||||||
|
|||||||
@ -519,14 +519,14 @@ class TransportMap(Generic[TransportType]):
|
|||||||
yield from destination_dict.values()
|
yield from destination_dict.values()
|
||||||
|
|
||||||
|
|
||||||
class ConvoyMap(TransportMap):
|
class ConvoyMap(TransportMap[Convoy]):
|
||||||
def create_transport(
|
def create_transport(
|
||||||
self, origin: ControlPoint, destination: ControlPoint
|
self, origin: ControlPoint, destination: ControlPoint
|
||||||
) -> Convoy:
|
) -> Convoy:
|
||||||
return Convoy(origin, destination)
|
return Convoy(origin, destination)
|
||||||
|
|
||||||
|
|
||||||
class CargoShipMap(TransportMap):
|
class CargoShipMap(TransportMap[CargoShip]):
|
||||||
def create_transport(
|
def create_transport(
|
||||||
self, origin: ControlPoint, destination: ControlPoint
|
self, origin: ControlPoint, destination: ControlPoint
|
||||||
) -> CargoShip:
|
) -> CargoShip:
|
||||||
|
|||||||
@ -5,6 +5,8 @@ from collections import defaultdict
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, TYPE_CHECKING, Any
|
from typing import Optional, TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from dcs.unittype import UnitType as DcsUnitType
|
||||||
|
|
||||||
from game.theater import ControlPoint
|
from game.theater import ControlPoint
|
||||||
from .dcs.groundunittype import GroundUnitType
|
from .dcs.groundunittype import GroundUnitType
|
||||||
from .dcs.unittype import UnitType
|
from .dcs.unittype import UnitType
|
||||||
@ -28,16 +30,16 @@ class PendingUnitDeliveries:
|
|||||||
self.destination = destination
|
self.destination = destination
|
||||||
|
|
||||||
# Maps unit type to order quantity.
|
# Maps unit type to order quantity.
|
||||||
self.units: dict[UnitType, int] = defaultdict(int)
|
self.units: dict[UnitType[DcsUnitType], int] = defaultdict(int)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Pending delivery to {self.destination}"
|
return f"Pending delivery to {self.destination}"
|
||||||
|
|
||||||
def order(self, units: dict[UnitType, int]) -> None:
|
def order(self, units: dict[UnitType[DcsUnitType], int]) -> None:
|
||||||
for k, v in units.items():
|
for k, v in units.items():
|
||||||
self.units[k] += v
|
self.units[k] += v
|
||||||
|
|
||||||
def sell(self, units: dict[UnitType, int]) -> None:
|
def sell(self, units: dict[UnitType[DcsUnitType], int]) -> None:
|
||||||
for k, v in units.items():
|
for k, v in units.items():
|
||||||
self.units[k] -= v
|
self.units[k] -= v
|
||||||
|
|
||||||
@ -46,27 +48,27 @@ class PendingUnitDeliveries:
|
|||||||
self.units = defaultdict(int)
|
self.units = defaultdict(int)
|
||||||
|
|
||||||
def refund_ground_units(self, game: Game) -> None:
|
def refund_ground_units(self, game: Game) -> None:
|
||||||
ground_units: dict[UnitType[Any], int] = {
|
ground_units: dict[UnitType[DcsUnitType], int] = {
|
||||||
u: self.units[u] for u in self.units.keys() if isinstance(u, GroundUnitType)
|
u: self.units[u] for u in self.units.keys() if isinstance(u, GroundUnitType)
|
||||||
}
|
}
|
||||||
self.refund(game, ground_units)
|
self.refund(game, ground_units)
|
||||||
for gu in ground_units.keys():
|
for gu in ground_units.keys():
|
||||||
del self.units[gu]
|
del self.units[gu]
|
||||||
|
|
||||||
def refund(self, game: Game, units: dict[UnitType, int]) -> None:
|
def refund(self, game: Game, units: dict[UnitType[DcsUnitType], int]) -> None:
|
||||||
for unit_type, count in units.items():
|
for unit_type, count in units.items():
|
||||||
logging.info(f"Refunding {count} {unit_type} at {self.destination.name}")
|
logging.info(f"Refunding {count} {unit_type} at {self.destination.name}")
|
||||||
game.adjust_budget(
|
game.adjust_budget(
|
||||||
unit_type.price * count, player=self.destination.captured
|
unit_type.price * count, player=self.destination.captured
|
||||||
)
|
)
|
||||||
|
|
||||||
def pending_orders(self, unit_type: UnitType) -> int:
|
def pending_orders(self, unit_type: UnitType[DcsUnitType]) -> int:
|
||||||
pending_units = self.units.get(unit_type)
|
pending_units = self.units.get(unit_type)
|
||||||
if pending_units is None:
|
if pending_units is None:
|
||||||
pending_units = 0
|
pending_units = 0
|
||||||
return pending_units
|
return pending_units
|
||||||
|
|
||||||
def available_next_turn(self, unit_type: UnitType) -> int:
|
def available_next_turn(self, unit_type: UnitType[DcsUnitType]) -> int:
|
||||||
current_units = self.destination.base.total_units_of_type(unit_type)
|
current_units = self.destination.base.total_units_of_type(unit_type)
|
||||||
return self.pending_orders(unit_type) + current_units
|
return self.pending_orders(unit_type) + current_units
|
||||||
|
|
||||||
@ -79,9 +81,9 @@ class PendingUnitDeliveries:
|
|||||||
)
|
)
|
||||||
self.refund_ground_units(game)
|
self.refund_ground_units(game)
|
||||||
|
|
||||||
bought_units: dict[UnitType, int] = {}
|
bought_units: dict[UnitType[DcsUnitType], int] = {}
|
||||||
units_needing_transfer: dict[GroundUnitType, int] = {}
|
units_needing_transfer: dict[GroundUnitType, int] = {}
|
||||||
sold_units: dict[UnitType, int] = {}
|
sold_units: dict[UnitType[DcsUnitType], int] = {}
|
||||||
for unit_type, count in self.units.items():
|
for unit_type, count in self.units.items():
|
||||||
coalition = "Ally" if self.destination.captured else "Enemy"
|
coalition = "Ally" if self.destination.captured else "Enemy"
|
||||||
d: dict[Any, int]
|
d: dict[Any, int]
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import time
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from dcs.country import Country
|
from dcs.country import Country
|
||||||
|
from dcs.unittype import UnitType as DcsUnitType
|
||||||
|
|
||||||
from game.dcs.aircrafttype import AircraftType
|
from game.dcs.aircrafttype import AircraftType
|
||||||
from game.dcs.unittype import UnitType
|
from game.dcs.unittype import UnitType
|
||||||
@ -293,7 +294,9 @@ class NameGenerator:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def next_unit_name(cls, country: Country, parent_base_id: int, unit_type: UnitType):
|
def next_unit_name(
|
||||||
|
cls, country: Country, parent_base_id: int, unit_type: UnitType[DcsUnitType]
|
||||||
|
) -> str:
|
||||||
cls.number += 1
|
cls.number += 1
|
||||||
return "unit|{}|{}|{}|{}|".format(
|
return "unit|{}|{}|{}|{}|".format(
|
||||||
country.id, cls.number, parent_base_id, unit_type.name
|
country.id, cls.number, parent_base_id, unit_type.name
|
||||||
@ -301,8 +304,8 @@ class NameGenerator:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def next_infantry_name(
|
def next_infantry_name(
|
||||||
cls, country: Country, parent_base_id: int, unit_type: UnitType
|
cls, country: Country, parent_base_id: int, unit_type: UnitType[DcsUnitType]
|
||||||
):
|
) -> str:
|
||||||
cls.infantry_number += 1
|
cls.infantry_number += 1
|
||||||
return "infantry|{}|{}|{}|{}|".format(
|
return "infantry|{}|{}|{}|{}|".format(
|
||||||
country.id,
|
country.id,
|
||||||
|
|||||||
2
mypy.ini
2
mypy.ini
@ -3,7 +3,7 @@
|
|||||||
check_untyped_defs = True
|
check_untyped_defs = True
|
||||||
# disallow_any_decorated = True
|
# disallow_any_decorated = True
|
||||||
# disallow_any_expr = True
|
# disallow_any_expr = True
|
||||||
# disallow_any_generics = True
|
disallow_any_generics = True
|
||||||
# disallow_any_unimported = True
|
# disallow_any_unimported = True
|
||||||
disallow_untyped_decorators = True
|
disallow_untyped_decorators = True
|
||||||
# disallow_untyped_defs = True
|
# disallow_untyped_defs = True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user