mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Remove one user of UNIT_BY_TASK.
This commit is contained in:
parent
914691eaa7
commit
ef35ad90b8
12
game/db.py
12
game/db.py
@ -1331,18 +1331,6 @@ def upgrade_to_supercarrier(unit, name: str):
|
||||
return unit
|
||||
|
||||
|
||||
def unit_task(unit: UnitType) -> Optional[Task]:
|
||||
for task, units in UNIT_BY_TASK.items():
|
||||
if unit in units:
|
||||
return task
|
||||
|
||||
if unit in SAM_CONVERT:
|
||||
return unit_task(SAM_CONVERT[unit])
|
||||
|
||||
print(unit.name + " cause issue")
|
||||
return None
|
||||
|
||||
|
||||
def find_unittype(for_task: Type[MainTask], country_name: str) -> List[Type[UnitType]]:
|
||||
return [x for x in UNIT_BY_TASK[for_task] if x in FACTIONS[country_name].units]
|
||||
|
||||
|
||||
@ -434,7 +434,7 @@ class Event:
|
||||
moved_units[frontline_unit] = int(count * move_factor)
|
||||
total_units_redeployed = total_units_redeployed + int(count * move_factor)
|
||||
|
||||
destination.base.commision_units(moved_units)
|
||||
destination.base.commission_units(moved_units)
|
||||
source.base.commit_losses(moved_units)
|
||||
|
||||
# Also transfer pending deliveries.
|
||||
|
||||
@ -3,11 +3,8 @@ import logging
|
||||
import typing
|
||||
from typing import Dict, Type
|
||||
|
||||
from dcs.task import AWACS, CAP, CAS, Embarking, PinpointStrike, Transport
|
||||
from dcs.unittype import FlyingType, VehicleType
|
||||
from dcs.vehicles import AirDefence
|
||||
from dcs.unittype import FlyingType, VehicleType, UnitType
|
||||
|
||||
from game import db
|
||||
from game.db import PRICES
|
||||
|
||||
BASE_MAX_STRENGTH = 1
|
||||
@ -47,30 +44,23 @@ class Base:
|
||||
]
|
||||
)
|
||||
|
||||
def commision_units(self, units: typing.Dict[typing.Any, int]):
|
||||
|
||||
def commission_units(self, units: typing.Dict[typing.Type[UnitType], int]):
|
||||
for unit_type, unit_count in units.items():
|
||||
if unit_count <= 0:
|
||||
continue
|
||||
|
||||
for_task = db.unit_task(unit_type)
|
||||
|
||||
target_dict = None
|
||||
if (
|
||||
for_task == AWACS
|
||||
or for_task == CAS
|
||||
or for_task == CAP
|
||||
or for_task == Embarking
|
||||
or for_task == Transport
|
||||
):
|
||||
target_dict = self.aircraft
|
||||
elif for_task == PinpointStrike:
|
||||
if issubclass(unit_type, VehicleType):
|
||||
target_dict = self.armor
|
||||
|
||||
if target_dict is not None:
|
||||
target_dict[unit_type] = target_dict.get(unit_type, 0) + unit_count
|
||||
elif issubclass(unit_type, FlyingType):
|
||||
target_dict = self.aircraft
|
||||
else:
|
||||
logging.error("Unable to determine target dict for " + str(unit_type))
|
||||
logging.error(
|
||||
f"Unexpected unit type of {unit_type}: "
|
||||
f"{unit_type.__module__}.{unit_type.__name__}"
|
||||
)
|
||||
return
|
||||
|
||||
target_dict[unit_type] = target_dict.get(unit_type, 0) + unit_count
|
||||
|
||||
def commit_losses(self, units_lost: typing.Dict[typing.Any, int]):
|
||||
|
||||
|
||||
@ -541,7 +541,7 @@ class ControlPoint(MissionTarget, ABC):
|
||||
while self.base.armor:
|
||||
unit_type, count = self.base.armor.popitem()
|
||||
for _ in range(count):
|
||||
destination.control_point.base.commision_units({unit_type: 1})
|
||||
destination.control_point.base.commission_units({unit_type: 1})
|
||||
destination = heapq.heappushpop(destinations, destination)
|
||||
|
||||
def capture_aircraft(
|
||||
@ -589,7 +589,7 @@ class ControlPoint(MissionTarget, ABC):
|
||||
return
|
||||
parking = destination.unclaimed_parking(game)
|
||||
transfer_amount = min([parking, count])
|
||||
destination.base.commision_units({airframe: transfer_amount})
|
||||
destination.base.commission_units({airframe: transfer_amount})
|
||||
count -= transfer_amount
|
||||
|
||||
def retreat_air_units(self, game: Game) -> None:
|
||||
|
||||
@ -109,7 +109,7 @@ class TransferOrder:
|
||||
|
||||
def disband_at(self, location: ControlPoint) -> None:
|
||||
logging.info(f"Units halting at {location}.")
|
||||
location.base.commision_units(self.units)
|
||||
location.base.commission_units(self.units)
|
||||
self.units.clear()
|
||||
|
||||
@property
|
||||
@ -562,7 +562,7 @@ class PendingTransfers:
|
||||
if transfer.transport is not None:
|
||||
self.cancel_transport(transfer.transport, transfer)
|
||||
self.pending_transfers.remove(transfer)
|
||||
transfer.origin.base.commision_units(transfer.units)
|
||||
transfer.origin.base.commission_units(transfer.units)
|
||||
|
||||
def perform_transfers(self) -> None:
|
||||
incomplete = []
|
||||
|
||||
@ -104,11 +104,11 @@ class PendingUnitDeliveries:
|
||||
game.message(f"{coalition} sold: {name} x {-count} at {source}")
|
||||
|
||||
self.units = defaultdict(int)
|
||||
self.destination.base.commision_units(bought_units)
|
||||
self.destination.base.commission_units(bought_units)
|
||||
self.destination.base.commit_losses(sold_units)
|
||||
|
||||
if units_needing_transfer:
|
||||
ground_unit_source.base.commision_units(units_needing_transfer)
|
||||
ground_unit_source.base.commission_units(units_needing_transfer)
|
||||
self.create_transfer(game, ground_unit_source, units_needing_transfer)
|
||||
|
||||
def create_transfer(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user