예제 #1
0
 def activate_beacons(group: ShipGroup, tacan: TacanChannel, callsign: str,
                      icls: int) -> None:
     group.points[0].tasks.append(
         ActivateBeaconCommand(channel=tacan.number,
                               modechannel=tacan.band.value,
                               callsign=callsign,
                               unit_id=group.units[0].id,
                               aa=False))
     group.points[0].tasks.append(
         ActivateICLSCommand(icls, unit_id=group.units[0].id))
예제 #2
0
    def configure_refueling_actions(self, waypoint: MovingPoint) -> None:
        waypoint.add_task(Tanker())

        if self.flight.unit_type.dcs_unit_type.tacan:
            tanker_info = self.air_support.tankers[-1]
            tacan = tanker_info.tacan
            tacan_callsign = {
                "Texaco": "TEX",
                "Arco": "ARC",
                "Shell": "SHL",
            }.get(tanker_info.callsign)

            waypoint.add_task(
                ActivateBeaconCommand(
                    tacan.number,
                    tacan.band.value,
                    tacan_callsign,
                    bearing=True,
                    unit_id=self.group.units[0].id,
                    aa=True,
                ))
예제 #3
0
    def generate(self, is_awacs_enabled):
        player_cp = self.conflict.from_cp if self.conflict.from_cp.captured else self.conflict.to_cp

        fallback_tanker_number = 0

        for i, tanker_unit_type in enumerate(
                db.find_unittype(Refueling, self.conflict.attackers_side)):
            variant = db.unit_type_name(tanker_unit_type)
            freq = self.radio_registry.alloc_uhf()
            tacan = self.tacan_registry.alloc_for_band(TacanBand.Y)
            tanker_heading = self.conflict.to_cp.position.heading_between_point(
                self.conflict.from_cp.position) + TANKER_HEADING_OFFSET * i
            tanker_position = player_cp.position.point_from_heading(
                tanker_heading, TANKER_DISTANCE)
            tanker_group = self.mission.refuel_flight(
                country=self.mission.country(self.game.player_country),
                name=namegen.next_tanker_name(
                    self.mission.country(self.game.player_country),
                    tanker_unit_type),
                airport=None,
                plane_type=tanker_unit_type,
                position=tanker_position,
                altitude=TANKER_ALT,
                race_distance=58000,
                frequency=freq.mhz,
                start_type=StartType.Warm,
                speed=574,
                tacanchannel=str(tacan),
            )
            tanker_group.set_frequency(freq.mhz)

            callsign = callsign_for_support_unit(tanker_group)
            tacan_callsign = {
                "Texaco": "TEX",
                "Arco": "ARC",
                "Shell": "SHL",
            }.get(callsign)
            if tacan_callsign is None:
                # The dict above is all the callsigns currently in the game, but
                # non-Western countries don't use the callsigns and instead just
                # use numbers. It's possible that none of those nations have
                # TACAN compatible refueling aircraft, but fallback just in
                # case.
                tacan_callsign = f"TK{fallback_tanker_number}"
                fallback_tanker_number += 1

            if tanker_unit_type != IL_78M:
                # Override PyDCS tacan channel.
                tanker_group.points[0].tasks.pop()
                tanker_group.points[0].tasks.append(
                    ActivateBeaconCommand(tacan.number, tacan.band.value,
                                          tacan_callsign, True,
                                          tanker_group.units[0].id, True))

            tanker_group.points[0].tasks.append(SetInvisibleCommand(True))
            tanker_group.points[0].tasks.append(SetImmortalCommand(True))

            self.air_support.tankers.append(
                TankerInfo(str(tanker_group.name), callsign, variant, freq,
                           tacan))

        if is_awacs_enabled:
            try:
                freq = self.radio_registry.alloc_uhf()
                awacs_unit = db.find_unittype(AWACS,
                                              self.conflict.attackers_side)[0]
                awacs_flight = self.mission.awacs_flight(
                    country=self.mission.country(self.game.player_country),
                    name=namegen.next_awacs_name(
                        self.mission.country(self.game.player_country)),
                    plane_type=awacs_unit,
                    altitude=AWACS_ALT,
                    airport=None,
                    position=self.conflict.position.random_point_within(
                        AWACS_DISTANCE, AWACS_DISTANCE),
                    frequency=freq.mhz,
                    start_type=StartType.Warm,
                )
                awacs_flight.set_frequency(freq.mhz)

                awacs_flight.points[0].tasks.append(SetInvisibleCommand(True))
                awacs_flight.points[0].tasks.append(SetImmortalCommand(True))

                self.air_support.awacs.append(
                    AwacsInfo(str(awacs_flight.name),
                              callsign_for_support_unit(awacs_flight), freq))
            except:
                print("No AWACS for faction")
    def generate(self) -> None:
        player_cp = (self.conflict.blue_cp if self.conflict.blue_cp.captured
                     else self.conflict.red_cp)

        country = self.mission.country(self.game.blue.country_name)

        if not self.game.settings.disable_legacy_tanker:
            fallback_tanker_number = 0

            for i, tanker_unit_type in enumerate(
                    self.game.faction_for(player=True).tankers):
                unit_type = tanker_unit_type.dcs_unit_type
                if not issubclass(unit_type, PlaneType):
                    logging.warning(
                        f"Refueling aircraft {unit_type} must be a plane")
                    continue

                # TODO: Make loiter altitude a property of the unit type.
                alt, airspeed = self._get_tanker_params(
                    tanker_unit_type.dcs_unit_type)
                freq = self.radio_registry.alloc_uhf()
                tacan = self.tacan_registry.alloc_for_band(
                    TacanBand.Y, TacanUsage.AirToAir)
                tanker_heading = Heading.from_degrees(
                    self.conflict.red_cp.position.heading_between_point(
                        self.conflict.blue_cp.position) +
                    TANKER_HEADING_OFFSET * i)
                tanker_position = player_cp.position.point_from_heading(
                    tanker_heading.degrees, TANKER_DISTANCE)
                tanker_group = self.mission.refuel_flight(
                    country=country,
                    name=namegen.next_tanker_name(country, tanker_unit_type),
                    airport=None,
                    plane_type=unit_type,
                    position=tanker_position,
                    altitude=alt,
                    race_distance=58000,
                    frequency=freq.mhz,
                    start_type=StartType.Warm,
                    speed=airspeed,
                    tacanchannel=str(tacan),
                )
                tanker_group.set_frequency(freq.mhz)

                callsign = callsign_for_support_unit(tanker_group)
                tacan_callsign = {
                    "Texaco": "TEX",
                    "Arco": "ARC",
                    "Shell": "SHL",
                }.get(callsign)
                if tacan_callsign is None:
                    # The dict above is all the callsigns currently in the game, but
                    # non-Western countries don't use the callsigns and instead just
                    # use numbers. It's possible that none of those nations have
                    # TACAN compatible refueling aircraft, but fallback just in
                    # case.
                    tacan_callsign = f"TK{fallback_tanker_number}"
                    fallback_tanker_number += 1

                if tanker_unit_type != IL_78M:
                    # Override PyDCS tacan channel.
                    tanker_group.points[0].tasks.pop()
                    tanker_group.points[0].tasks.append(
                        ActivateBeaconCommand(
                            tacan.number,
                            tacan.band.value,
                            tacan_callsign,
                            True,
                            tanker_group.units[0].id,
                            True,
                        ))

                tanker_group.points[0].tasks.append(SetInvisibleCommand(True))
                tanker_group.points[0].tasks.append(SetImmortalCommand(True))

                self.air_support.tankers.append(
                    TankerInfo(
                        str(tanker_group.name),
                        callsign,
                        tanker_unit_type.name,
                        freq,
                        tacan,
                        start_time=None,
                        end_time=None,
                        blue=True,
                    ))

        if not self.game.settings.disable_legacy_aewc:
            possible_awacs = [
                a for a in self.game.faction_for(player=True).aircrafts
                if a in AEWC_CAPABLE
            ]

            if not possible_awacs:
                logging.warning("No AWACS for faction")
                return

            awacs_unit = possible_awacs[0]
            freq = self.radio_registry.alloc_uhf()

            unit_type = awacs_unit.dcs_unit_type
            if not issubclass(unit_type, PlaneType):
                logging.warning(f"AWACS aircraft {unit_type} must be a plane")
                return

            awacs_flight = self.mission.awacs_flight(
                country=country,
                name=namegen.next_awacs_name(country),
                plane_type=unit_type,
                altitude=AWACS_ALT,
                airport=None,
                position=self.conflict.position.random_point_within(
                    AWACS_DISTANCE, AWACS_DISTANCE),
                frequency=freq.mhz,
                start_type=StartType.Warm,
            )
            awacs_flight.set_frequency(freq.mhz)

            awacs_flight.points[0].tasks.append(SetInvisibleCommand(True))
            awacs_flight.points[0].tasks.append(SetImmortalCommand(True))

            self.air_support.awacs.append(
                AwacsInfo(
                    group_name=str(awacs_flight.name),
                    callsign=callsign_for_support_unit(awacs_flight),
                    freq=freq,
                    depature_location=None,
                    start_time=None,
                    end_time=None,
                    blue=True,
                ))
예제 #5
0
def create_mission(campaign):
    m = dcs.Mission(terrain.Caucasus())
    # setup airports
    for name, airport in campaign.airports.items():
        coal_name = airport.coalition.value
        print(coal_name)
        assert (m.terrain.airports[name].set_coalition(coal_name))

    usa = m.country("USA")
    russia = m.country("Russia")
    sochi = m.terrain.sochi_adler()
    ship_pos = sochi.position - dcs.Point(50000, 50000)
    print(f"{sochi.position=}")
    print(f"{ship_pos=}")
    cvbg = m.ship_group(country=usa,
                        name="CVN 74 Stennis",
                        _type=ships.CVN_74_John_C__Stennis,
                        position=ship_pos)

    tasks = cvbg.points[0].tasks
    tasks.append(ActivateICLSCommand(unit_id=cvbg.id, channel=5))
    tasks.append(
        ActivateBeaconCommand(unit_id=cvbg.id,
                              channel=69,
                              callsign="STN",
                              aa=False))
    cvbg.add_waypoint(ship_pos + dcs.Point(0, -100 * 1000))
    cvbg.add_waypoint(ship_pos + dcs.Point(-30 * 1000, -100 * 1000))
    cvbg.add_waypoint(ship_pos + dcs.Point(-30 * 1000, 0))
    # cvbg.add_waypoint(ship_pos)
    # cvbg.add_waypoint(ship_pos + dcs.Point(0, -100*1000))
    # cvbg.add_waypoint(ship_pos + dcs.Point(-30*1000, -100*1000))
    # cvbg.add_waypoint(ship_pos + dcs.Point(-30*1000, 0))
    # cvbg.add_waypoint(ship_pos)

    name = namegen.next_unit_name(usa)
    fg = m.flight_group_from_unit(country=usa,
                                  name=name,
                                  aircraft_type=planes.FA_18C_hornet,
                                  maintask=None,
                                  start_type=StartType.Warm,
                                  pad_group=cvbg,
                                  group_size=4)
    fg.set_client()

    offset = dcs.Point(random() * 1000.0, random() * 1000.0)
    orientation = random() * 360.
    sa2_pos = sochi.position + offset
    p = fg.add_waypoint(ship_pos + dcs.Point(1000, 3000), feet_to_meters(8000))
    pos = point_along_route(p.position, sochi.position, 50 * 2000)
    p = fg.add_waypoint(pos, feet_to_meters(26000))
    fg.add_waypoint(point_along_route(p.position, sochi.position, -1000),
                    feet_to_meters(26000))
    fg.land_at(cvbg)

    make_sa2_site(m, russia, sa2_pos, orientation)

    awacs = m.awacs_flight(usa,
                           "AWACS",
                           planes.E_3A,
                           None,
                           dcs.Point(sochi.position.x + 20000,
                                     sochi.position.y + 80000),
                           race_distance=80 * 1000,
                           heading=90,
                           speed=knots_to_kph(500),
                           altitude=feet_to_meters(30000))
    tasks = awacs.points[0].tasks
    tasks.append(EPLRS())
    campaign.mission = m
    return m