Esempio n. 1
0
 def __init__(self, game: Game, ground_object: TheaterGroundObject,
              faction: Faction):
     self.game = game
     self.go = ground_object
     self.position = ground_object.position
     self.heading = random.randint(0, 359)
     self.faction = faction
     self.vg = unitgroup.ShipGroup(self.game.next_group_id(),
                                   self.go.group_name)
     wp = self.vg.add_waypoint(self.position, 0)
     wp.ETA_locked = True
Esempio n. 2
0
 def __init__(self, game: Game, ground_object: NavalGroundObject,
              faction: Faction):
     super().__init__(
         game,
         ground_object,
         unitgroup.ShipGroup(game.next_group_id(),
                             ground_object.group_name),
     )
     self.faction = faction
     wp = self.vg.add_waypoint(self.position, 0)
     wp.ETA_locked = True
Esempio n. 3
0
    def load_from_dict(self, mission, d):
        for country_idx in d["country"]:
            imp_country = d["country"][country_idx]
            _country = countries.get_by_id(imp_country["id"])

            if "vehicle" in imp_country:
                for vgroup_idx in imp_country["vehicle"]["group"]:
                    vgroup = imp_country["vehicle"]["group"][vgroup_idx]
                    vg = unitgroup.VehicleGroup(
                        vgroup["groupId"],
                        mission.translation.get_string(vgroup["name"]),
                        vgroup["start_time"])
                    vg.load_from_dict(vgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   vg.id)

                    Coalition._import_moving_point(mission, vg, vgroup)

                    # units
                    for imp_unit_idx in vgroup["units"]:
                        imp_unit = vgroup["units"][imp_unit_idx]
                        unit = Vehicle(id=imp_unit["unitId"],
                                       name=mission.translation.get_string(
                                           imp_unit["name"]),
                                       _type=imp_unit["type"])
                        unit.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      unit.id)
                        vg.add_unit(unit)
                    _country.add_vehicle_group(vg)

            if "ship" in imp_country:
                for group_idx in imp_country["ship"]["group"]:
                    imp_group = imp_country["ship"]["group"][group_idx]
                    vg = unitgroup.ShipGroup(
                        imp_group["groupId"],
                        mission.translation.get_string(imp_group["name"]),
                        imp_group["start_time"])
                    vg.load_from_dict(imp_group)
                    mission.current_group_id = max(mission.current_group_id,
                                                   vg.id)

                    Coalition._import_moving_point(mission, vg, imp_group)

                    # units
                    for imp_unit_idx in imp_group["units"]:
                        imp_unit = imp_group["units"][imp_unit_idx]
                        unit = Ship(id=imp_unit["unitId"],
                                    name=mission.translation.get_string(
                                        imp_unit["name"]),
                                    _type=ships.ship_map[imp_unit["type"]])
                        unit.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      unit.id)
                        vg.add_unit(unit)
                    _country.add_ship_group(vg)

            if "plane" in imp_country:
                for pgroup_idx in imp_country["plane"]["group"]:
                    pgroup = imp_country["plane"]["group"][pgroup_idx]
                    plane_group = unitgroup.PlaneGroup(
                        pgroup["groupId"],
                        mission.translation.get_string(pgroup["name"]),
                        pgroup["start_time"])
                    plane_group.load_from_dict(pgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   plane_group.id)

                    Coalition._import_moving_point(mission, plane_group,
                                                   pgroup)

                    # units
                    for imp_unit_idx in pgroup["units"]:
                        imp_unit = pgroup["units"][imp_unit_idx]
                        plane = Plane(_id=imp_unit["unitId"],
                                      name=mission.translation.get_string(
                                          imp_unit["name"]),
                                      _type=planes.plane_map[imp_unit["type"]],
                                      _country=_country)
                        plane.load_from_dict(imp_unit)

                        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)

                    # check runway start
                    # if plane_group.points[0].airdrome_id is not None and plane_group.units[0].parking is None:
                    #     airport = mission.terrain.airport_by_id(plane_group.points[0].airdrome_id)
                    #     airport.occupy_runway(plane_group)
                    _country.add_plane_group(plane_group)

            if "helicopter" in imp_country:
                for pgroup_idx in imp_country["helicopter"]["group"]:
                    pgroup = imp_country["helicopter"]["group"][pgroup_idx]
                    helicopter_group = unitgroup.HelicopterGroup(
                        pgroup["groupId"],
                        mission.translation.get_string(pgroup["name"]),
                        pgroup["start_time"])
                    helicopter_group.load_from_dict(pgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   helicopter_group.id)

                    Coalition._import_moving_point(mission, helicopter_group,
                                                   pgroup)

                    # units
                    for imp_unit_idx in pgroup["units"]:
                        imp_unit = pgroup["units"][imp_unit_idx]
                        heli = Helicopter(
                            _id=imp_unit["unitId"],
                            name=mission.translation.get_string(
                                imp_unit["name"]),
                            _type=helicopters.helicopter_map[imp_unit["type"]],
                            _country=_country)
                        heli.load_from_dict(imp_unit)

                        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)

                    # check runway start
                    # if helicopter_group.points[0].airdrome_id is not None and helicopter_group.units[0].parking is None:
                    #     airport = mission.terrain.airport_by_id(helicopter_group.points[0].airdrome_id)
                    #     airport.occupy_runway(helicopter_group)
                    _country.add_helicopter_group(helicopter_group)

            if "static" in imp_country:
                for sgroup_idx in imp_country["static"]["group"]:
                    sgroup = imp_country["static"]["group"][sgroup_idx]
                    static_group = unitgroup.StaticGroup(
                        sgroup["groupId"],
                        mission.translation.get_string(sgroup["name"]))
                    static_group.load_from_dict(sgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   static_group.id)

                    Coalition._import_static_point(mission, static_group,
                                                   sgroup)

                    # units
                    for imp_unit_idx in sgroup["units"]:
                        imp_unit = sgroup["units"][imp_unit_idx]
                        if imp_unit["type"] == "FARP":
                            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"],
                                name=mission.translation.get_string(
                                    imp_unit["name"]),
                                _type=imp_unit["type"])
                        static.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      static.id)
                        static_group.add_unit(static)
                    _country.add_static_group(static_group)
            self.add_country(_country)
Esempio n. 4
0
    def load_from_dict(self, mission, d) -> List[StatusMessage]:
        status: List[StatusMessage] = []
        for country_idx in d["country"]:
            imp_country = d["country"][country_idx]
            _country = countries.get_by_id(imp_country["id"])

            if "vehicle" in imp_country:
                for vgroup_idx in imp_country["vehicle"]["group"]:
                    vgroup = imp_country["vehicle"]["group"][vgroup_idx]
                    vg = unitgroup.VehicleGroup(
                        vgroup["groupId"],
                        self.get_name(mission, vgroup["name"]),
                        vgroup["start_time"])
                    vg.load_from_dict(vgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   vg.id)

                    Coalition._import_moving_point(mission, vg, vgroup)

                    # units
                    for imp_unit_idx in vgroup["units"]:
                        imp_unit = vgroup["units"][imp_unit_idx]
                        unit = Vehicle(id=imp_unit["unitId"],
                                       name=self.get_name(
                                           mission, imp_unit["name"]),
                                       _type=imp_unit["type"])
                        unit.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      unit.id)
                        vg.add_unit(unit)
                    _country.add_vehicle_group(vg)

            if "ship" in imp_country:
                for group_idx in imp_country["ship"]["group"]:
                    imp_group = imp_country["ship"]["group"][group_idx]
                    vg = unitgroup.ShipGroup(
                        imp_group["groupId"],
                        self.get_name(mission, imp_group["name"]),
                        imp_group["start_time"])
                    vg.load_from_dict(imp_group)
                    mission.current_group_id = max(mission.current_group_id,
                                                   vg.id)

                    Coalition._import_moving_point(mission, vg, imp_group)

                    # units
                    for imp_unit_idx in imp_group["units"]:
                        imp_unit = imp_group["units"][imp_unit_idx]
                        unit = Ship(id=imp_unit["unitId"],
                                    name=self.get_name(mission,
                                                       imp_unit["name"]),
                                    _type=ships.ship_map[imp_unit["type"]])
                        unit.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      unit.id)
                        vg.add_unit(unit)
                    _country.add_ship_group(vg)

            if "plane" in imp_country:
                for pgroup_idx in imp_country["plane"]["group"]:
                    pgroup = imp_country["plane"]["group"][pgroup_idx]
                    plane_group = unitgroup.PlaneGroup(
                        pgroup["groupId"],
                        self.get_name(mission, pgroup["name"]),
                        pgroup["start_time"])
                    plane_group.load_from_dict(pgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   plane_group.id)

                    Coalition._import_moving_point(mission, plane_group,
                                                   pgroup)

                    # units
                    for imp_unit_idx in pgroup["units"]:
                        imp_unit = pgroup["units"][imp_unit_idx]
                        plane = Plane(_id=imp_unit["unitId"],
                                      name=self.get_name(
                                          mission, imp_unit["name"]),
                                      _type=planes.plane_map[imp_unit["type"]],
                                      _country=_country)
                        plane.load_from_dict(imp_unit)

                        if _country.reserve_onboard_num(plane.onboard_num):
                            msg = "{c} Plane '{p}' already using tail number: {t}".format(
                                c=self.name.upper(),
                                p=plane.name,
                                t=plane.onboard_num)
                            status.append(
                                StatusMessage(
                                    msg, MessageType.ONBOARD_NUM_DUPLICATE,
                                    MessageSeverity.WARN))
                            print("WARN:", msg, file=sys.stderr)
                        status += 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)

                    # check runway start
                    # if plane_group.points[0].airdrome_id is not None and plane_group.units[0].parking is None:
                    #     airport = mission.terrain.airport_by_id(plane_group.points[0].airdrome_id)
                    #     airport.occupy_runway(plane_group)
                    _country.add_plane_group(plane_group)

            if "helicopter" in imp_country:
                for pgroup_idx in imp_country["helicopter"]["group"]:
                    pgroup = imp_country["helicopter"]["group"][pgroup_idx]
                    helicopter_group = unitgroup.HelicopterGroup(
                        pgroup["groupId"],
                        self.get_name(mission, pgroup["name"]),
                        pgroup["start_time"])
                    helicopter_group.load_from_dict(pgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   helicopter_group.id)

                    Coalition._import_moving_point(mission, helicopter_group,
                                                   pgroup)

                    # units
                    for imp_unit_idx in pgroup["units"]:
                        imp_unit = pgroup["units"][imp_unit_idx]
                        heli = Helicopter(
                            _id=imp_unit["unitId"],
                            name=self.get_name(mission, imp_unit["name"]),
                            _type=helicopters.helicopter_map[imp_unit["type"]],
                            _country=_country)
                        heli.load_from_dict(imp_unit)

                        if _country.reserve_onboard_num(heli.onboard_num):
                            msg = "{c} Helicopter '{h}' already using tail number: {t}".format(
                                c=self.name.upper(),
                                h=heli.name,
                                t=heli.onboard_num)
                            status.append(
                                StatusMessage(
                                    msg, MessageType.ONBOARD_NUM_DUPLICATE,
                                    MessageSeverity.WARN))
                            print("WARN:", msg, file=sys.stderr)
                        status += 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)

                    # check runway start
                    # if helicopter_group.points[0].airdrome_id is not None and helicopter_group.units[0].parking is None:
                    #     airport = mission.terrain.airport_by_id(helicopter_group.points[0].airdrome_id)
                    #     airport.occupy_runway(helicopter_group)
                    _country.add_helicopter_group(helicopter_group)

            if "static" in imp_country:
                for sgroup_idx in imp_country["static"]["group"]:
                    sgroup = imp_country["static"]["group"][sgroup_idx]
                    static_group = unitgroup.StaticGroup(
                        sgroup["groupId"],
                        self.get_name(mission, sgroup["name"]))
                    static_group.load_from_dict(sgroup)
                    mission.current_group_id = max(mission.current_group_id,
                                                   static_group.id)

                    Coalition._import_static_point(mission, static_group,
                                                   sgroup)

                    # units
                    for imp_unit_idx in sgroup["units"]:
                        imp_unit = sgroup["units"][imp_unit_idx]
                        if imp_unit["type"] == "FARP":
                            static = FARP(unit_id=imp_unit["unitId"],
                                          name=self.get_name(
                                              mission, imp_unit["name"]))
                        elif imp_unit["type"] == "SINGLE_HELIPAD":
                            static = SingleHeliPad(unit_id=imp_unit["unitId"],
                                                   name=self.get_name(
                                                       mission,
                                                       imp_unit["name"]))
                        else:
                            static = Static(unit_id=imp_unit["unitId"],
                                            name=self.get_name(
                                                mission, imp_unit["name"]),
                                            _type=imp_unit["type"])
                        static.load_from_dict(imp_unit)

                        mission.current_unit_id = max(mission.current_unit_id,
                                                      static.id)
                        static_group.add_unit(static)
                    _country.add_static_group(static_group)
            self.add_country(_country)
        return status