Skip to content

Commit

Permalink
static_groups: Test FARP loading and support SingleHeliPad
Browse files Browse the repository at this point in the history
  • Loading branch information
rp- committed May 2, 2020
1 parent 23228a2 commit 1fe5731
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dcs/coalition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import planes
from . import helicopters
from . import ships
from dcs.unit import Vehicle, Plane, Helicopter, Static, Ship, FARP
from dcs.unit import Vehicle, Plane, Helicopter, Static, Ship, FARP, SingleHeliPad
from dcs.point import MovingPoint, StaticPoint
from dcs.country import Country

Expand Down Expand Up @@ -173,6 +173,10 @@ def load_from_dict(self, mission, d):
static = FARP(
unit_id=imp_unit["unitId"],
name=mission.translation.get_string(imp_unit["name"]))
elif imp_unit["type"] == "SINGLE_HELIPAD":
static = SingleHeliPad(
unit_id=imp_unit["unitId"],
name=mission.translation.get_string(imp_unit["name"]))
else:
static = Static(
unit_id=imp_unit["unitId"],
Expand Down
33 changes: 29 additions & 4 deletions dcs/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def dict(self):


class Static(Unit):
def __init__(self, unit_id=None, name=None, _type: Union[str,Type[UnitType]] = None):
def __init__(self, unit_id=None, name=None, _type: Union[str, Type[UnitType]] = None):
if not isinstance(_type, str):
_id = _type.id
_class = _type
Expand Down Expand Up @@ -326,14 +326,14 @@ def __init__(self, unit_id=None, name=None, frequency=127.5, modulation=0, calls
super(FARP, self).__init__(unit_id, name, "FARP")
self.category = "Heliports"
self.shape_name = "FARPS"
self.heliport_frequency = frequency
self.heliport_frequency: float = frequency
self.heliport_modulation = modulation
self.heliport_callsign_id = callsign_id
self.heliport_callsign_id: int = callsign_id
self.can_cargo = False

def load_from_dict(self, d):
super(FARP, self).load_from_dict(d)
self.heliport_frequency = d.get("heliport_frequency")
self.heliport_frequency = float(d.get("heliport_frequency", 127.5))
self.heliport_modulation = d.get("heliport_modulation")
self.heliport_callsign_id = d.get("heliport_callsign_id", 0)

Expand All @@ -344,3 +344,28 @@ def dict(self):
d["heliport_callsign_id"] = self.heliport_callsign_id

return d


class SingleHeliPad(Static):
def __init__(self, unit_id=None, name=None, frequency=127.5, modulation=0, callsign_id=1):
super(SingleHeliPad, self).__init__(unit_id, name, "SINGLE_HELIPAD")
self.category = "Heliports"
self.shape_name = "FARP"
self.heliport_frequency: float = frequency
self.heliport_modulation = modulation
self.heliport_callsign_id: int = callsign_id
self.can_cargo = False

def load_from_dict(self, d):
super(SingleHeliPad, self).load_from_dict(d)
self.heliport_frequency = float(d.get("heliport_frequency", 127.5))
self.heliport_modulation = d.get("heliport_modulation")
self.heliport_callsign_id = d.get("heliport_callsign_id", 0)

def dict(self):
d = super(SingleHeliPad, self).dict()
d["heliport_frequency"] = self.heliport_frequency
d["heliport_modulation"] = self.heliport_modulation
d["heliport_callsign_id"] = self.heliport_callsign_id

return d
4 changes: 4 additions & 0 deletions dcs/unitgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,18 @@ def __init__(self, _id, name=None):
super(StaticGroup, self).__init__(_id, name)
self.dead = False
self.heading = 0
self.link_offset: Optional[bool] = False

def load_from_dict(self, d):
super(StaticGroup, self).load_from_dict(d)
self.heading = math.degrees(d["heading"])
self.dead = d["dead"]
self.link_offset = d.get("linkOffset")

def dict(self):
d = super(StaticGroup, self).dict()
d["dead"] = self.dead
d["heading"] = round(math.radians(self.heading), 13)
if self.link_offset is not None:
d["linkOffset"] = self.link_offset
return d
Binary file modified tests/loadtest.miz
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/test_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,23 @@ def test_loadmission(self):
m = dcs.mission.Mission()
self.assertTrue(m.load_file('tests/loadtest.miz'))

usa = m.country(dcs.countries.USA.name)

# find single heli pad
single_farp_group = usa.find_static_group("HeliSingle")
single_farp: dcs.unit.SingleHeliPad = single_farp_group.units[0]
self.assertIsNotNone(single_farp)
self.assertEqual(single_farp_group.heading, 0)
self.assertEqual(single_farp.heading, 0)
self.assertEqual(single_farp.heliport_callsign_id, 1)
self.assertEqual(single_farp.heliport_frequency, 127.5)

# check blue farp
blue_farp_group = usa.find_static_group("FARP")
blue_farp: dcs.unit.FARP = blue_farp_group.units[0]
self.assertIsNotNone(blue_farp)
self.assertEqual(int(blue_farp.heading), 62)
self.assertEqual(blue_farp.heliport_callsign_id, 2)
self.assertEqual(blue_farp.heliport_frequency, 128.5)

m.save('missions/loadtest.miz')

0 comments on commit 1fe5731

Please sign in to comment.