Beispiel #1
0
    def create_flight(self) -> None:
        error = self.verify_form()
        if error is not None:
            QMessageBox.critical(self, "Could not create flight", error,
                                 QMessageBox.Ok)
            return

        task = self.task_selector.currentData()
        aircraft = self.aircraft_selector.currentData()
        origin = self.departure.currentData()
        arrival = self.arrival.currentData()
        divert = self.divert.currentData()
        size = self.flight_size_spinner.value()

        if arrival is None:
            arrival = origin

        flight = Flight(self.package,
                        self.country,
                        aircraft,
                        size,
                        task,
                        self.start_type.currentText(),
                        origin,
                        arrival,
                        divert,
                        custom_name=self.custom_name_text)
        flight.client_count = self.client_slots_spinner.value()

        # noinspection PyUnresolvedReferences
        self.created.emit(flight)
        self.close()
    def create_flight(self) -> None:
        error = self.verify_form()
        if error is not None:
            QMessageBox.critical(self, "Could not create flight", error,
                                 QMessageBox.Ok)
            return

        task = self.task_selector.currentData()
        aircraft = self.aircraft_selector.currentData()
        origin = self.departure.currentData()
        arrival = self.arrival.currentData()
        divert = self.divert.currentData()
        size = self.flight_size_spinner.value()

        if arrival is None:
            arrival = origin

        if isinstance(origin, OffMapSpawn):
            start_type = "In Flight"
        elif self.game.settings.perf_ai_parking_start:
            start_type = "Cold"
        else:
            start_type = "Warm"
        flight = Flight(self.package, aircraft, size, task, start_type, origin,
                        arrival, divert)
        flight.client_count = self.client_slots_spinner.value()

        # noinspection PyUnresolvedReferences
        self.created.emit(flight)
        self.close()
    def generate_planned_flight(self, cp, country, flight: Flight):
        try:
            if flight.client_count == 0 and self.game.settings.perf_ai_parking_start:
                flight.start_type = "Warm"

            if flight.start_type == "In Flight":
                group = self._generate_group(name=namegen.next_unit_name(
                    country, cp.id, flight.unit_type),
                                             side=country,
                                             unit_type=flight.unit_type,
                                             count=flight.count,
                                             client_count=0,
                                             at=cp.position)
            else:
                st = StartType.Runway
                if flight.start_type == "Cold":
                    st = StartType.Cold
                elif flight.start_type == "Warm":
                    st = StartType.Warm

                if cp.cptype in [
                        ControlPointType.AIRCRAFT_CARRIER_GROUP,
                        ControlPointType.LHA_GROUP
                ]:
                    group_name = cp.get_carrier_group_name()
                    group = self._generate_at_group(
                        name=namegen.next_unit_name(country, cp.id,
                                                    flight.unit_type),
                        side=country,
                        unit_type=flight.unit_type,
                        count=flight.count,
                        client_count=0,
                        at=self.m.find_group(group_name),
                        start_type=st)
                else:
                    group = self._generate_at_airport(
                        name=namegen.next_unit_name(country, cp.id,
                                                    flight.unit_type),
                        side=country,
                        unit_type=flight.unit_type,
                        count=flight.count,
                        client_count=0,
                        airport=cp.airport,
                        start_type=st)
        except Exception:
            # Generated when there is no place on Runway or on Parking Slots
            flight.start_type = "In Flight"
            group = self._generate_group(name=namegen.next_unit_name(
                country, cp.id, flight.unit_type),
                                         side=country,
                                         unit_type=flight.unit_type,
                                         count=flight.count,
                                         client_count=0,
                                         at=cp.position)
            group.points[0].alt = 1500

        flight.group = group
        return group
Beispiel #4
0
 def delete_flight(self, flight: Flight) -> None:
     """Removes the given flight from the package."""
     index = self.package.flights.index(flight)
     self.beginRemoveRows(QModelIndex(), index, index)
     if flight.cargo is not None:
         flight.cargo.transport = None
     self.game_model.game.aircraft_inventory.return_from_flight(flight)
     flight.clear_roster()
     self.package.remove_flight(flight)
     self.endRemoveRows()
     self.update_tot()
Beispiel #5
0
    def commision_strike(self):
        """
        Pick some aircraft to assign them to STRIKE tasks
        """
        possible_aircraft = [
            k for k, v in self.aircraft_inventory.items()
            if k in STRIKE_CAPABLE and v >= 2
        ]
        inventory = dict({
            k: v
            for k, v in self.aircraft_inventory.items()
            if k in possible_aircraft
        })

        if len(self.potential_strike_targets) > 0:

            offset = random.randint(0, 5)
            for i in range(
                    int(MISSION_DURATION /
                        self.doctrine["STRIKE_EVERY_X_MINUTES"])):

                if len(self.potential_strike_targets) <= 0:
                    break

                try:
                    unit = random.choice(
                        [k for k, v in inventory.items() if v >= 2])
                except IndexError:
                    break

                if unit in DRONES:
                    count = 1
                else:
                    count = 2

                inventory[unit] = inventory[unit] - count
                flight = Flight(unit, count, self.from_cp, FlightType.STRIKE)

                flight.points = []
                flight.scheduled_in = offset + i * random.randint(
                    self.doctrine["STRIKE_EVERY_X_MINUTES"] - 5,
                    self.doctrine["STRIKE_EVERY_X_MINUTES"] + 5)

                location = self.potential_strike_targets[0][0]
                self.potential_strike_targets.pop(0)

                self.generate_strike(flight, location)

                self.strike_flights.append(flight)
                self.flights.append(flight)

            # Update inventory
            for k, v in inventory.items():
                self.aircraft_inventory[k] = v
Beispiel #6
0
    def plan_flight(self, plan: ProposedFlight) -> bool:
        """Allocates aircraft for the given flight and adds them to the package.

        If no suitable aircraft are available, False is returned. If the failed
        flight was critical and the rest of the mission will be scrubbed, the
        caller should return any previously planned flights to the inventory
        using release_planned_aircraft.
        """
        assignment = self.allocator.find_aircraft_for_flight(plan)
        if assignment is None:
            return False
        airfield, aircraft = assignment
        if isinstance(airfield, OffMapSpawn):
            start_type = "In Flight"
        else:
            start_type = self.start_type

        flight = Flight(
            self.package,
            self.package_country,
            aircraft,
            plan.num_aircraft,
            plan.task,
            start_type,
            departure=airfield,
            arrival=airfield,
            divert=self.find_divert_field(aircraft, airfield),
        )
        self.package.add_flight(flight)
        return True
    def draw_test_flight_plan(self, scene: QGraphicsScene, task: FlightType,
                              point_near_target: Point, player: bool) -> None:
        for line in self.shortest_path_segments:
            try:
                scene.removeItem(line)
            except RuntimeError:
                pass

        self.clear_flight_paths(scene)

        target = self.game.theater.closest_target(point_near_target)

        if player:
            origin = self.game.theater.player_points()[0]
        else:
            origin = self.game.theater.enemy_points()[0]

        package = Package(target)
        flight = Flight(package,
                        F_16C_50,
                        2,
                        task,
                        start_type="Warm",
                        departure=origin,
                        arrival=origin,
                        divert=None)
        package.add_flight(flight)
        planner = FlightPlanBuilder(self.game, package, is_player=player)
        try:
            planner.populate_flight_plan(flight)
        except InvalidObjectiveLocation:
            return

        package.time_over_target = TotEstimator(package).earliest_tot()
        self.draw_flight_plan(scene, flight, selected=True)
Beispiel #8
0
    def create_flight(self) -> None:
        error = self.verify_form()
        if error is not None:
            QMessageBox.critical(self, "Could not create flight", error, QMessageBox.Ok)
            return

        task = self.task_selector.currentData()
        squadron = self.squadron_selector.currentData()
        origin = self.departure.currentData()
        arrival = self.arrival.currentData()
        divert = self.divert.currentData()
        roster = self.roster_editor.roster

        if arrival is None:
            arrival = origin

        flight = Flight(
            self.package,
            self.country,
            squadron,
            # A bit of a hack to work around the old API. Not actually relevant because
            # the roster is passed explicitly. Needs a refactor.
            roster.max_size,
            task,
            self.start_type.currentText(),
            origin,
            arrival,
            divert,
            custom_name=self.custom_name_text,
            roster=roster,
        )

        # noinspection PyUnresolvedReferences
        self.created.emit(flight)
        self.accept()
Beispiel #9
0
    def commision_cas(self):
        """
        Pick some aircraft to assign them to CAS
        """

        possible_aircraft = [
            k for k, v in self.aircraft_inventory.items()
            if k in CAS_CAPABLE and v >= 2
        ]
        inventory = dict({
            k: v
            for k, v in self.aircraft_inventory.items()
            if k in possible_aircraft
        })
        cas_location = self._get_cas_locations()

        if len(cas_location) > 0:

            offset = random.randint(0, 5)
            for i in range(
                    int(MISSION_DURATION /
                        self.doctrine["CAS_EVERY_X_MINUTES"])):

                try:
                    unit = random.choice(
                        [k for k, v in inventory.items() if v >= 2])
                except IndexError:
                    break

                inventory[unit] = inventory[unit] - 2
                flight = Flight(unit, 2, self.from_cp, FlightType.CAS)
                flight.points = []
                flight.scheduled_in = offset + i * random.randint(
                    self.doctrine["CAS_EVERY_X_MINUTES"] - 5,
                    self.doctrine["CAS_EVERY_X_MINUTES"] + 5)
                location = random.choice(cas_location)

                self.generate_cas(flight, flight.from_cp, location)

                self.cas_flights.append(flight)
                self.flights.append(flight)

            # Update inventory
            for k, v in inventory.items():
                self.aircraft_inventory[k] = v
Beispiel #10
0
    def commision_cap(self):
        """
        Pick some aircraft to assign them to defensive CAP roles (BARCAP)
        """

        possible_aircraft = [
            k for k, v in self.aircraft_inventory.items()
            if k in CAP_CAPABLE and v >= 2
        ]
        inventory = dict({
            k: v
            for k, v in self.aircraft_inventory.items()
            if k in possible_aircraft
        })

        offset = random.randint(0, 5)
        for i in range(
                int(MISSION_DURATION / self.doctrine["CAP_EVERY_X_MINUTES"])):

            try:
                unit = random.choice(
                    [k for k, v in inventory.items() if v >= 2])
            except IndexError:
                break

            inventory[unit] = inventory[unit] - 2
            flight = Flight(unit, 2, self.from_cp, FlightType.CAP)

            flight.points = []
            flight.scheduled_in = offset + i * random.randint(
                self.doctrine["CAP_EVERY_X_MINUTES"] - 5,
                self.doctrine["CAP_EVERY_X_MINUTES"] + 5)

            if len(self._get_cas_locations()) > 0:
                enemy_cp = random.choice(self._get_cas_locations())
                self.generate_frontline_cap(flight, flight.from_cp, enemy_cp)
            else:
                self.generate_barcap(flight, flight.from_cp)

            self.cap_flights.append(flight)
            self.flights.append(flight)

        # Update inventory
        for k, v in inventory.items():
            self.aircraft_inventory[k] = v
Beispiel #11
0
    def commision_interceptors(self):
        """
        Pick some aircraft to assign them to interception roles
        """

        # At least try to generate one interceptor group
        number_of_interceptor_groups = min(
            max(
                sum([v for k, v in self.aircraft_inventory.items()]) / 4,
                self.doctrine["MAX_NUMBER_OF_INTERCEPTION_GROUP"]), 1)
        possible_interceptors = [
            k for k in self.aircraft_inventory.keys() if k in INTERCEPT_CAPABLE
        ]

        if len(possible_interceptors) <= 0:
            possible_interceptors = [
                k for k, v in self.aircraft_inventory.items()
                if k in CAP_CAPABLE and v >= 2
            ]

        if number_of_interceptor_groups > 0:
            inventory = dict({
                k: v
                for k, v in self.aircraft_inventory.items()
                if k in possible_interceptors
            })
            for i in range(number_of_interceptor_groups):
                try:
                    unit = random.choice(
                        [k for k, v in inventory.items() if v >= 2])
                except IndexError:
                    break
                inventory[unit] = inventory[unit] - 2
                flight = Flight(unit, 2, self.from_cp, FlightType.INTERCEPTION)
                flight.scheduled_in = 1
                flight.points = []

                self.interceptor_flights.append(flight)
                self.flights.append(flight)

            # Update inventory
            for k, v in inventory.items():
                self.aircraft_inventory[k] = v
    def create_flight(self) -> None:
        error = self.verify_form()
        if error is not None:
            QMessageBox.critical(self, "Could not create flight", error,
                                 QMessageBox.Ok)
            return

        task = self.task_selector.currentData()
        aircraft = self.aircraft_selector.currentData()
        origin = self.airfield_selector.currentData()
        size = self.flight_size_spinner.value()

        if self.game.settings.perf_ai_parking_start:
            start_type = "Cold"
        else:
            start_type = "Warm"
        flight = Flight(self.package, aircraft, size, origin, task, start_type)
        flight.client_count = self.client_slots_spinner.value()

        # noinspection PyUnresolvedReferences
        self.created.emit(flight)
        self.close()
Beispiel #13
0
    def plan_flight(self, plan: ProposedFlight) -> bool:
        """Allocates aircraft for the given flight and adds them to the package.

        If no suitable aircraft are available, False is returned. If the failed
        flight was critical and the rest of the mission will be scrubbed, the
        caller should return any previously planned flights to the inventory
        using release_planned_aircraft.
        """
        assignment = self.allocator.find_aircraft_for_flight(plan)
        if assignment is None:
            return False
        airfield, aircraft = assignment
        flight = Flight(self.package, aircraft, plan.num_aircraft, airfield,
                        plan.task, self.start_type)
        self.package.add_flight(flight)
        return True
Beispiel #14
0
    def create_airlift_flight(
        self, squadron: Squadron, inventory: ControlPointAircraftInventory
    ) -> int:
        available_aircraft = inventory.available(squadron.aircraft)
        capacity_each = 1 if squadron.aircraft.dcs_unit_type.helicopter else 2
        required = math.ceil(self.transfer.size / capacity_each)
        flight_size = min(
            required,
            available_aircraft,
            squadron.aircraft.dcs_unit_type.group_size_max,
        )
        # TODO: Use number_of_available_pilots directly once feature flag is gone.
        # The number of currently available pilots is not relevant when pilot limits
        # are disabled.
        if not squadron.can_provide_pilots(flight_size):
            flight_size = squadron.number_of_available_pilots
        capacity = flight_size * capacity_each

        if capacity < self.transfer.size:
            transfer = self.game.transfers.split_transfer(self.transfer, capacity)
        else:
            transfer = self.transfer

        player = inventory.control_point.captured
        flight = Flight(
            self.package,
            self.game.country_for(player),
            squadron,
            flight_size,
            FlightType.TRANSPORT,
            self.game.settings.default_start_type,
            departure=inventory.control_point,
            arrival=inventory.control_point,
            divert=None,
            cargo=transfer,
        )

        transport = Airlift(transfer, flight, self.next_stop)
        transfer.transport = transport

        self.package.add_flight(flight)
        planner = FlightPlanBuilder(self.game, self.package, self.for_player)
        planner.populate_flight_plan(flight)
        self.game.aircraft_inventory.claim_for_flight(flight)
        return flight_size
    def create_flight(self):
        aircraft_type = self.select_type_aircraft.currentData()
        count = self.select_count_of_aircraft.value()

        if self.available[aircraft_type] < count:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText("Not enough aircraft of this type are available. Only " + str(self.available[aircraft_type]) + " available.")
            msg.setWindowTitle("Not enough aircraft")
            msg.setStandardButtons(QMessageBox.Ok)
            msg.setWindowFlags(Qt.WindowStaysOnTopHint)
            msg.exec_()
            return
        else:
            flight = Flight(aircraft_type, count, self.from_cp, self.select_flight_type.currentData())
            self.planner.flights.append(flight)
            self.planner.custom_flights.append(flight)
            if self.flight_view is not None:
                self.flight_view.set_flight_planner(self.planner, len(self.planner.flights)-1)
            self.close()