def get_fallback_channel(unit_type: UnitType) -> RadioFrequency: if unit_type in helicopter_map.values() and unit_type != UH_1H: return HELICOPTER_CHANNEL german_ww2_aircraft = [ Bf_109K_4, FW_190A8, FW_190D9, Ju_88A4, ] if unit_type in german_ww2_aircraft: return GERMAN_WW2_CHANNEL allied_ww2_aircraft = [ I_16, P_47D_30, P_51D, P_51D_30_NA, SpitfireLFMkIX, SpitfireLFMkIXCW, ] if unit_type in allied_ww2_aircraft: return ALLIES_WW2_CHANNEL return UHF_FALLBACK_CHANNEL
def __init__(self, cp: ControlPoint, game_model: GameModel) -> None: QFrame.__init__(self) self.cp = cp self.game_model = game_model self.purchase_groups = {} self.bought_amount_labels = {} self.existing_units_labels = {} # Determine maximum number of aircrafts that can be bought self.set_maximum_units(self.cp.total_aircraft_parking) self.bought_amount_labels = {} self.existing_units_labels = {} self.hangar_status = QHangarStatus(game_model, self.cp) main_layout = QVBoxLayout() scroll_content = QWidget() task_box_layout = QGridLayout() row = 0 unit_types: Set[AircraftType] = set() for unit_type in self.game_model.game.player_faction.aircrafts: if self.cp.is_carrier and not unit_type.carrier_capable: continue if self.cp.is_lha and not unit_type.lha_capable: continue if (self.cp.cptype in [ControlPointType.FOB, ControlPointType.FARP] and unit_type not in helicopter_map.values()): continue unit_types.add(unit_type) sorted_units = sorted( unit_types, key=lambda u: u.name, ) for row, unit_type in enumerate(sorted_units): self.add_purchase_row(unit_type, task_box_layout, row) stretch = QVBoxLayout() stretch.addStretch() task_box_layout.addLayout(stretch, row, 0) scroll_content.setLayout(task_box_layout) scroll = QScrollArea() scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) scroll.setWidgetResizable(True) scroll.setWidget(scroll_content) main_layout.addLayout(self.hangar_status) main_layout.addWidget(scroll) self.setLayout(main_layout)
def init_ui(self): main_layout = QVBoxLayout() tasks = [CAP, CAS, AWACS] scroll_content = QWidget() task_box_layout = QGridLayout() row = 0 unit_types: Set[Type[FlyingType]] = set() for task in tasks: units = db.find_unittype(task, self.game_model.game.player_name) if not units: continue for unit in units: if not issubclass(unit, FlyingType): continue if self.cp.is_carrier and unit not in db.CARRIER_CAPABLE: continue if self.cp.is_lha and unit not in db.LHA_CAPABLE: continue if (self.cp.cptype in [ControlPointType.FOB, ControlPointType.FARP] and unit not in helicopter_map.values()): continue unit_types.add(unit) sorted_units = sorted( unit_types, key=lambda u: db.unit_get_expanded_info( self.game_model.game.player_country, u, "name"), ) for unit_type in sorted_units: row = self.add_purchase_row( unit_type, task_box_layout, row, disabled=not self.cp.can_operate(unit_type), ) stretch = QVBoxLayout() stretch.addStretch() task_box_layout.addLayout(stretch, row, 0) scroll_content.setLayout(task_box_layout) scroll = QScrollArea() scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) scroll.setWidgetResizable(True) scroll.setWidget(scroll_content) main_layout.addLayout(self.hangar_status) main_layout.addWidget(scroll) self.setLayout(main_layout)
def choose_units(for_task: Task, factor: float, count: int, country: str) -> List[UnitType]: suitable_unittypes = find_unittype(for_task, country) suitable_unittypes = [ x for x in suitable_unittypes if x not in helicopter_map.values() ] suitable_unittypes.sort(key=lambda x: PRICES[x]) idx = int(len(suitable_unittypes) * factor) variety = int(count + count * factor / 2) index_start = min(idx, len(suitable_unittypes) - variety) index_end = min(idx + variety, len(suitable_unittypes)) return list(set(suitable_unittypes[index_start:index_end]))
def _each_unit_type() -> Iterator[Type[FlyingType]]: yield from helicopter_map.values() yield from plane_map.values()