Skip to content

Commit

Permalink
parking slot loading: fix old parking format also for helicopters
Browse files Browse the repository at this point in the history
  • Loading branch information
rp- committed Jul 23, 2020
1 parent 3304015 commit 2e1ba3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
42 changes: 26 additions & 16 deletions dcs/coalition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Dict
from typing import Dict, Union, TYPE_CHECKING
from . import countries
from . import unitgroup
from . import planes
Expand All @@ -10,6 +10,9 @@
from dcs.point import MovingPoint, StaticPoint
from dcs.country import Country

if TYPE_CHECKING:
from . import Mission


class Coalition:
def __init__(self, name, bullseye=None):
Expand All @@ -36,6 +39,26 @@ def _import_static_point(mission, group: unitgroup.Group, imp_group) -> unitgrou
group.add_point(point)
return group

@staticmethod
def _park_unit_on_airport(mission: 'Mission', group: unitgroup.Group, unit: Union[Plane, Helicopter]):
if group.points[0].airdrome_id is not None and unit.parking is not None:
airport = mission.terrain.airport_by_id(group.points[0].airdrome_id)
slot = airport.parking_slot(unit.parking)
if slot is not None:
unit.set_parking(slot)
else:
print("WARN: Parking slot id '{i}' for unit '{u}' in group '{p}' on airport '{a}' "
"not valid, placing on next free"
.format(i=unit.parking, u=unit.name, a=airport.name, p=group.name),
file=sys.stderr)
slot = airport.free_parking_slot(unit.unit_type)
if slot is not None:
unit.set_parking(slot)
else:
print("ERRO: No free parking slots for unit '{u}' in unit group '{p}' on airport '{a}', ignoring"
.format(u=unit.name, a=airport.name, p=group.name),
file=sys.stderr)

def load_from_dict(self, mission, d):
for country_idx in d["country"]:
imp_country = d["country"][country_idx]
Expand Down Expand Up @@ -108,17 +131,7 @@ def load_from_dict(self, mission, d):
_country=_country)
plane.load_from_dict(imp_unit)

if plane_group.points[0].airdrome_id is not None and plane.parking is not None:
airport = mission.terrain.airport_by_id(plane_group.points[0].airdrome_id)
slot = airport.parking_slot(plane.parking)
if slot is not None:
plane.set_parking(slot)
else:
print("Parking slot id '{i}' for '{p}' on airport '{a}' not valid, placing on next free"
.format(i=plane.parking, a=airport.name, p=plane_group.name),
file=sys.stderr)
slot = airport.free_parking_slot(plane.unit_type)
plane.set_parking(slot)
self._park_unit_on_airport(mission, plane_group, plane)

mission.current_unit_id = max(mission.current_unit_id, plane.id)
plane_group.add_unit(plane)
Expand Down Expand Up @@ -151,10 +164,7 @@ def load_from_dict(self, mission, d):
_country=_country)
heli.load_from_dict(imp_unit)

if helicopter_group.points[0].airdrome_id is not None and heli.parking is not None:
airport = mission.terrain.airport_by_id(helicopter_group.points[0].airdrome_id)
slot = airport.parking_slot(heli.parking)
heli.set_parking(slot)
self._park_unit_on_airport(mission, helicopter_group, heli)

mission.current_unit_id = max(mission.current_unit_id, heli.id)
helicopter_group.add_unit(heli)
Expand Down
4 changes: 2 additions & 2 deletions dcs/terrain/terrain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# terrain module
from typing import List, Dict, Optional, Tuple, Set
from typing import List, Dict, Optional, Tuple, Set, Type
from collections import defaultdict, deque
from dcs import mapping, lua, point
from dcs import unittype, weather
Expand Down Expand Up @@ -211,7 +211,7 @@ def free_parking_slots(self, aircraft_type: unittype.FlyingType) -> List[Parking
else:
return self._free_parking_slots_resolve_v2(aircraft_type)

def free_parking_slot(self, aircraft_type: unittype.FlyingType) -> Optional[ParkingSlot]:
def free_parking_slot(self, aircraft_type: Type[unittype.FlyingType]) -> Optional[ParkingSlot]:
slots = self.free_parking_slots(aircraft_type)
if slots:
return slots[0]
Expand Down

0 comments on commit 2e1ba3f

Please sign in to comment.