def __init__(self, package: Package, flight: Flight): super(QFlightItem, self).__init__() self.package = package self.flight = flight if db.unit_type_name(self.flight.unit_type).replace("/", " ") in AIRCRAFT_ICONS.keys(): icon = QIcon((AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)])) self.setIcon(icon) self.setEditable(False) estimator = TotEstimator(self.package) delay = estimator.mission_start_time(flight) self.setText("["+str(self.flight.flight_type.name[:6])+"] " + str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type) + " in " + str(delay))
def __init__(self, flight: Flight): super(QFlightItem, self).__init__() self.flight = flight if db.unit_type_name(self.flight.unit_type).replace( "/", " ") in AIRCRAFT_ICONS.keys(): icon = QIcon( (AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)])) self.setIcon(icon) self.setEditable(False) self.setText("[" + str(self.flight.flight_type.name[:6]) + "] " + str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type) + " in " + str(self.flight.scheduled_in) + " minutes")
def __init__(self, package: Package, flight: Flight): super(QFlightItem, self).__init__() self.package = package self.flight = flight if ( db.unit_type_name(self.flight.unit_type).replace("/", " ") in AIRCRAFT_ICONS.keys() ): icon = QIcon((AIRCRAFT_ICONS[db.unit_type_name(self.flight.unit_type)])) self.setIcon(icon) self.setEditable(False) estimator = TotEstimator(self.package) delay = estimator.mission_start_time(flight) self.setText(f"{flight} in {delay}")
def add_ally_flight_description(self, flight: FlightData): assert not flight.client_units aircraft = flight.aircraft_type flight_unit_name = db.unit_type_name(aircraft) self.description += ( f"{flight.flight_type.name} {flight_unit_name} x {flight.size}, " f"departing in {flight.departure_delay} minutes\n")
def first_row_text(self, index: QModelIndex) -> str: flight = self.flight(index) task = flight.flight_type count = flight.count name = db.unit_type_name(flight.unit_type) estimator = TotEstimator(self.package) delay = estimator.mission_start_time(flight) return f"[{task}] {count} x {name} in {delay}"
def next_infantry_name(cls, country: Country, parent_base_id: int, unit_type: UnitType): cls.infantry_number += 1 return "infantry|{}|{}|{}|{}|".format( country.id, cls.infantry_number, parent_base_id, db.unit_type_name(unit_type), )
def generate(self, is_awacs_enabled): player_cp = self.conflict.from_cp if self.conflict.from_cp.captured else self.conflict.to_cp CALLSIGNS = ["TKR", "TEX", "FUL", "FUE", ""] for i, tanker_unit_type in enumerate( db.find_unittype(Refueling, self.conflict.attackers_side)): self.generated_tankers.append(db.unit_type_name(tanker_unit_type)) 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)), airport=None, plane_type=tanker_unit_type, position=tanker_position, altitude=TANKER_ALT, race_distance=58000, frequency=130 + i, start_type=StartType.Warm, speed=574, tacanchannel="{}X".format(60 + i), ) if tanker_unit_type != IL_78M: tanker_group.points[0].tasks.pop( ) # Override PyDCS tacan channel tanker_group.points[0].tasks.append( ActivateBeaconCommand(97 + 1, "X", CALLSIGNS[i], True, tanker_group.units[0].id, True)) tanker_group.points[0].tasks.append(SetInvisibleCommand(True)) tanker_group.points[0].tasks.append(SetImmortalCommand(True)) if is_awacs_enabled: try: 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=233, start_type=StartType.Warm, ) awacs_flight.points[0].tasks.append(SetInvisibleCommand(True)) awacs_flight.points[0].tasks.append(SetImmortalCommand(True)) except: print("No AWACS for faction")
def text_for_flight(self, flight: Flight) -> str: """Returns the text that should be displayed for the flight.""" task = flight.flight_type.name count = flight.count name = db.unit_type_name(flight.unit_type) estimator = TotEstimator(self.package) delay = datetime.timedelta( seconds=int(estimator.mission_start_time(flight).total_seconds())) origin = flight.from_cp.name return f"[{task}] {count} x {name} from {origin} in {delay}"
def add_flight_description(self, flight: FlightData): assert flight.client_units aircraft = flight.aircraft_type flight_unit_name = db.unit_type_name(aircraft) self.description += "-" * 50 + "\n" self.description += f"{flight_unit_name} x {flight.size + 2}\n\n" for i, wpt in enumerate(flight.waypoints): self.description += f"#{i + 1} -- {wpt.name} : {wpt.description}\n" self.description += f"#{len(flight.waypoints) + 1} -- RTB\n\n"
def __init__(self, flight): super(QFlightTypeTaskInfo, self).__init__("Flight") self.flight = flight layout = QGridLayout() self.aircraft_icon = QLabel() if db.unit_type_name(self.flight.unit_type) in AIRCRAFT_ICONS: self.aircraft_icon.setPixmap(AIRCRAFT_ICONS[db.unit_type_name( self.flight.unit_type)]) self.task = QLabel("Task :") self.task_type = QLabel(flight.flight_type.name) self.task_type.setProperty("style", flight.flight_type.name) layout.addWidget(self.aircraft_icon, 0, 0) layout.addWidget(self.task, 1, 0) layout.addWidget(self.task_type, 1, 1) self.setLayout(layout)
def generate(self, is_awacs_enabled): player_cp = self.conflict.from_cp if self.conflict.from_cp.captured else self.conflict.to_cp for i, tanker_unit_type in enumerate( db.find_unittype(Refueling, self.conflict.attackers_side.name)): self.generated_tankers.append(db.unit_type_name(tanker_unit_type)) 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), name=namegen.next_tanker_name( self.mission.country(self.game.player)), airport=None, plane_type=tanker_unit_type, position=tanker_position, altitude=TANKER_ALT, frequency=130 + i, start_type=StartType.Warm, tacanchannel="{}X".format(97 + i), ) tanker_group.points[0].tasks.append( ActivateBeaconCommand(channel=97 + i, unit_id=tanker_group.id, aa=False)) tanker_group.points[0].tasks.append(SetInvisibleCommand(True)) tanker_group.points[0].tasks.append(SetImmortalCommand(True)) if is_awacs_enabled: awacs_unit = db.find_unittype(AWACS, self.conflict.attackers_side.name)[0] awacs_flight = self.mission.awacs_flight( country=self.mission.country(self.game.player), name=namegen.next_awacs_name( self.mission.country(self.game.player)), plane_type=awacs_unit, altitude=AWACS_ALT, airport=None, position=self.conflict.position.random_point_within( AWACS_DISTANCE, AWACS_DISTANCE), frequency=133, start_type=StartType.Warm, ) awacs_flight.points[0].tasks.append(SetInvisibleCommand(True)) awacs_flight.points[0].tasks.append(SetImmortalCommand(True))
def next_aircraft_name(cls, country: Country, parent_base_id: int, flight: Flight): cls.aircraft_number += 1 try: if flight.custom_name: name_str = flight.custom_name else: name_str = "{} {}".format(flight.package.target.name, flight.flight_type) except AttributeError: # Here to maintain save compatibility with 2.3 name_str = "{} {}".format(flight.package.target.name, flight.flight_type) return "{}|{}|{}|{}|{}|".format(name_str, country.id, cls.aircraft_number, parent_base_id, db.unit_type_name(flight.unit_type))
def add_flight_description(self, flight): if flight.client_count <= 0: return flight_unit_name = db.unit_type_name(flight.unit_type) self.description += "-" * 50 + "\n" self.description += flight_unit_name + " x " + str( flight.count) + 2 * "\n" self.description += "#0 -- TAKEOFF : Take off from " + flight.from_cp.name + "\n" for i, wpt in enumerate(flight.points): self.description += "#" + str( 1 + i) + " -- " + wpt.name + " : " + wpt.description + "\n" self.description += "#" + str(len(flight.points) + 1) + " -- RTB\n" self.description += "-" * 50 + "\n"
def init_ui(self): layout = QVBoxLayout() intel = QGroupBox("Intel") intelLayout = QVBoxLayout() units = { CAP: db.find_unittype(CAP, self.game.enemy_name), Embarking: db.find_unittype(Embarking, self.game.enemy_name), CAS: db.find_unittype(CAS, self.game.enemy_name), PinpointStrike: db.find_unittype(PinpointStrike, self.game.enemy_name), } for task_type in units.keys(): units_column = list(set(units[task_type])) if sum([self.cp.base.total_units_of_type(u) for u in units_column]) > 0: group = QGroupBox(db.task_name(task_type)) groupLayout = QGridLayout() group.setLayout(groupLayout) row = 0 for unit_type in units_column: existing_units = self.cp.base.total_units_of_type( unit_type) if existing_units == 0: continue groupLayout.addWidget( QLabel("<b>" + db.unit_type_name(unit_type) + "</b>"), row, 0) groupLayout.addWidget(QLabel(str(existing_units)), row, 1) row += 1 intelLayout.addWidget(group) intelLayout.addStretch() intel.setLayout(intelLayout) layout.addWidget(intel) layout.addStretch() self.setLayout(layout)
def add_flight_description(self, flight): if flight.client_count <= 0: return flight_unit_name = db.unit_type_name(flight.unit_type) self.description += "-" * 50 + "\n" self.description += flight_unit_name + " x " + str(flight.count) + 2 * "\n" self.description += "#0 -- TAKEOFF : Take off from " + flight.from_cp.name + "\n" for i, wpt in enumerate(flight.points): self.description += "#" + str(1+i) + " -- " + wpt.name + " : " + wpt.description + "\n" self.description += "#" + str(len(flight.points) + 1) + " -- RTB\n\n" group = flight.group if group is not None: for i, nav_target in enumerate(group.nav_target_points): self.description += nav_target.text_comment + "\n" self.description += "\n" self.description += "-" * 50 + "\n"
def next_tanker_name(self, country, unit_type): self.number += 1 return "tanker|{}|{}|0|{}".format(country.id, self.number, db.unit_type_name(unit_type))
def next_tanker_name(cls, country: Country, unit_type: UnitType): cls.number += 1 return "tanker|{}|{}|0|{}".format( country.id, cls.number, db.unit_type_name(unit_type) )
def next_infantry_name(self, country, parent_base_id, unit_type): self.number += 1 return "infantry|{}|{}|{}|{}|".format(country.id, self.number, parent_base_id, db.unit_type_name(unit_type))
def update(self, flight): self.flight = flight self.setText("[" + str(self.flight.flight_type.name[:6]) + "] " + str(self.flight.count) + " x " + db.unit_type_name(self.flight.unit_type) + " in " + str(self.flight.scheduled_in) + " minutes")
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 add_ally_flight_description(self, flight): if flight.client_count == 0: flight_unit_name = db.unit_type_name(flight.unit_type) self.description += flight.flight_type.name + " " + flight_unit_name + " x " + str(flight.count) + ", departing in " + str(flight.scheduled_in) + " minutes \n"
def initUI(self): self.layout = QVBoxLayout() header = QLabel(self) header.setGeometry(0, 0, 655, 106) pixmap = QPixmap("./resources/ui/debriefing.png") header.setPixmap(pixmap) self.layout.addWidget(header) self.layout.addStretch() title = QLabel("<b>Casualty report</b>") self.layout.addWidget(title) # Player lost units lostUnits = QGroupBox( f"{self.debriefing.player_country}'s lost units:") lostUnitsLayout = QGridLayout() lostUnits.setLayout(lostUnitsLayout) row = 0 player_air_losses = self.debriefing.air_losses.by_type(player=True) for unit_type, count in player_air_losses.items(): try: lostUnitsLayout.addWidget( QLabel(db.unit_get_expanded_info(self.debriefing.player_country, unit_type, 'name')), row, 0) lostUnitsLayout.addWidget(QLabel(str(count)), row, 1) row += 1 except AttributeError: logging.exception( f"Issue adding {unit_type} to debriefing information") front_line_losses = self.debriefing.front_line_losses_by_type( player=True ) for unit_type, count in front_line_losses.items(): try: lostUnitsLayout.addWidget( QLabel(db.unit_type_name(unit_type)), row, 0) lostUnitsLayout.addWidget(QLabel(str(count)), row, 1) row += 1 except AttributeError: logging.exception( f"Issue adding {unit_type} to debriefing information") building_losses = self.debriefing.building_losses_by_type(player=True) for building, count in building_losses.items(): try: lostUnitsLayout.addWidget(QLabel(building), row, 0) lostUnitsLayout.addWidget(QLabel(str(count)), row, 1) row += 1 except AttributeError: logging.exception( f"Issue adding {building} to debriefing information") self.layout.addWidget(lostUnits) # Enemy lost units enemylostUnits = QGroupBox( f"{self.debriefing.enemy_country}'s lost units:") enemylostUnitsLayout = QGridLayout() enemylostUnits.setLayout(enemylostUnitsLayout) enemy_air_losses = self.debriefing.air_losses.by_type(player=False) for unit_type, count in enemy_air_losses.items(): try: enemylostUnitsLayout.addWidget( QLabel(db.unit_get_expanded_info(self.debriefing.enemy_country, unit_type, 'name')), row, 0) enemylostUnitsLayout.addWidget(QLabel(str(count)), row, 1) row += 1 except AttributeError: logging.exception( f"Issue adding {unit_type} to debriefing information") front_line_losses = self.debriefing.front_line_losses_by_type( player=False ) for unit_type, count in front_line_losses.items(): if count == 0: continue enemylostUnitsLayout.addWidget(QLabel(db.unit_type_name(unit_type)), row, 0) enemylostUnitsLayout.addWidget(QLabel("{}".format(count)), row, 1) row += 1 building_losses = self.debriefing.building_losses_by_type(player=False) for building, count in building_losses.items(): try: enemylostUnitsLayout.addWidget(QLabel(building), row, 0) enemylostUnitsLayout.addWidget(QLabel("{}".format(count)), row, 1) row += 1 except AttributeError: logging.exception( f"Issue adding {building} to debriefing information") self.layout.addWidget(enemylostUnits) # TODO: Display dead ground object units and runways. # confirm button okay = QPushButton("Okay") okay.clicked.connect(self.close) self.layout.addWidget(okay) self.setLayout(self.layout)
def __repr__(self): return self.flight_type.name + " | " + str(self.count) + "x" + db.unit_type_name(self.unit_type) \ + " (" + str(len(self.points)) + " wpt)"
def __repr__(self): name = db.unit_type_name(self.unit_type) if self.custom_name: return f"{self.custom_name} {self.count} x {name}" return f"[{self.flight_type}] {self.count} x {name}"
def icon_for_flight(flight: Flight) -> Optional[QIcon]: """Returns the icon that should be displayed for the flight.""" name = db.unit_type_name(flight.unit_type) if name in AIRCRAFT_ICONS: return QIcon(AIRCRAFT_ICONS[name]) return None
def next_unit_name(self, country, unit_type): self.number += 1 return "unit|{}|{}|{}|".format(country.id, self.number, db.unit_type_name(unit_type))
def __repr__(self): return self.flight_type.name + " | " + str(self.count) + "x" + db.unit_type_name(self.unit_type) \ + " in " + str(self.scheduled_in) + " minutes (" + str(len(self.points)) + " wpt)"
def __repr__(self): name = db.unit_type_name(self.unit_type) return f"[{self.flight_type}] {self.count} x {name}"