def init_ui(self): self.header = QLabel() path = os.path.join("./resources/ui/units/buildings/" + self.building.dcs_identifier + ".png") if self.building.is_dead: pixmap = QPixmap("./resources/ui/units/buildings/dead.png") elif os.path.isfile(path): pixmap = QPixmap(path) else: pixmap = QPixmap("./resources/ui/units/buildings/missing.png") self.header.setPixmap(pixmap) name = "<b>{}</b> {}".format(self.building.dcs_identifier[0:18], "[DEAD]" if self.building.is_dead else "") self.name = QLabel(name) self.name.setProperty("style", "small") layout = QVBoxLayout() layout.addWidget(self.header) layout.addWidget(self.name) if self.building.category in REWARDS.keys(): income_label_text = 'Value: ' + str(REWARDS[self.building.category]) + "M" if self.building.is_dead: income_label_text = '<s>' + income_label_text + '</s>' self.reward = QLabel(income_label_text) layout.addWidget(self.reward) footer = QHBoxLayout() self.setLayout(layout)
def production_per_turn(self) -> int: production = 0 for building in self.buildings: if building.is_dead: continue if building.category in REWARDS.keys(): production += REWARDS[building.category] return production
def budget_reward_amount(self): reward = 0 if len(self.theater.player_points()) > 0: reward = PLAYER_BUDGET_BASE * len(self.theater.player_points()) for cp in self.theater.player_points(): for g in cp.ground_objects: if g.category in REWARDS.keys(): reward = reward + REWARDS[g.category] return reward else: return reward
def doLayout(self): self.update_total_value() self.intelBox = QGroupBox("Units :") self.intelLayout = QGridLayout() i = 0 for g in self.ground_object.groups: if not hasattr(g, "units_losts"): g.units_losts = [] for unit in g.units: unit_display_name = unit.type dcs_unit_type = vehicles.vehicle_map.get(unit.type) if dcs_unit_type is not None: # Hack: Don't know which variant is used. try: unit_display_name = next( GroundUnitType.for_dcs_type(dcs_unit_type) ).name except StopIteration: pass self.intelLayout.addWidget( QLabel( "<b>Unit #" + str(unit.id) + " - " + str(unit_display_name) + "</b>" ), i, 0, ) i = i + 1 for unit in g.units_losts: dcs_unit_type = vehicles.vehicle_map.get(unit.type) if dcs_unit_type is None: continue # Hack: Don't know which variant is used. try: unit_type = next(GroundUnitType.for_dcs_type(dcs_unit_type)) name = unit_type.name price = unit_type.price except StopIteration: name = dcs_unit_type.name price = 0 self.intelLayout.addWidget( QLabel(f"<b>Unit #{unit.id} - {name}</b> [DEAD]"), i, 0 ) if self.cp.captured: repair = QPushButton(f"Repair [{price}M]") repair.setProperty("style", "btn-success") repair.clicked.connect( lambda u=unit, g=g, p=unit_type.price: self.repair_unit(g, u, p) ) self.intelLayout.addWidget(repair, i, 1) i = i + 1 stretch = QVBoxLayout() stretch.addStretch() self.intelLayout.addLayout(stretch, i, 0) self.buildingBox = QGroupBox("Buildings :") self.buildingsLayout = QGridLayout() j = 0 total_income = 0 received_income = 0 for i, building in enumerate(self.buildings): if building.dcs_identifier not in FORTIFICATION_BUILDINGS: self.buildingsLayout.addWidget( QBuildingInfo(building, self.ground_object), j / 3, j % 3 ) j = j + 1 if building.category in REWARDS.keys(): total_income = total_income + REWARDS[building.category] if not building.is_dead: received_income = received_income + REWARDS[building.category] else: logging.warning(building.category + " not in REWARDS") self.financesBox = QGroupBox("Finances: ") self.financesBoxLayout = QGridLayout() self.financesBoxLayout.addWidget( QLabel("Available: " + str(total_income) + "M"), 2, 1 ) self.financesBoxLayout.addWidget( QLabel("Receiving: " + str(received_income) + "M"), 2, 2 ) self.financesBox.setLayout(self.financesBoxLayout) self.buildingBox.setLayout(self.buildingsLayout) self.intelBox.setLayout(self.intelLayout)
def _enemy_reinforcement(self): """ Compute and commision reinforcement for enemy bases """ MAX_ARMOR = 30 * self.settings.multiplier MAX_AIRCRAFT = 25 * self.settings.multiplier production = 0.0 for enemy_point in self.theater.enemy_points(): for g in enemy_point.ground_objects: if g.category in REWARDS.keys(): production = production + REWARDS[g.category] production = production * 0.75 budget_for_armored_units = production / 2 budget_for_aircraft = production / 2 potential_cp_armor = [] for cp in self.theater.enemy_points(): for cpe in cp.connected_points: if cpe.captured and cp.base.total_armor < MAX_ARMOR: potential_cp_armor.append(cp) if len(potential_cp_armor) == 0: potential_cp_armor = self.theater.enemy_points() i = 0 potential_units = [ u for u in db.FACTIONS[self.enemy_name]["units"] if u in db.UNIT_BY_TASK[PinpointStrike] ] print("Enemy Recruiting") print(potential_cp_armor) print(budget_for_armored_units) print(potential_units) if len(potential_units) > 0 and len(potential_cp_armor) > 0: while budget_for_armored_units > 0: i = i + 1 if i > 50 or budget_for_armored_units <= 0: break target_cp = random.choice(potential_cp_armor) if target_cp.base.total_armor >= MAX_ARMOR: continue unit = random.choice(potential_units) price = db.PRICES[unit] * 2 budget_for_armored_units -= price * 2 target_cp.base.armor[unit] = target_cp.base.armor.get(unit, 0) + 2 info = Information("Enemy Reinforcement", unit.id + " x 2 at " + target_cp.name, self.turn) print(str(info)) self.informations.append(info) if budget_for_armored_units > 0: budget_for_aircraft += budget_for_armored_units potential_units = [ u for u in db.FACTIONS[self.enemy_name]["units"] if u in db.UNIT_BY_TASK[CAS] or u in db.UNIT_BY_TASK[CAP] ] if len(potential_units) > 0 and len(potential_cp_armor) > 0: while budget_for_aircraft > 0: i = i + 1 if i > 50 or budget_for_aircraft <= 0: break target_cp = random.choice(potential_cp_armor) if target_cp.base.total_planes >= MAX_AIRCRAFT: continue unit = random.choice(potential_units) price = db.PRICES[unit] * 2 budget_for_aircraft -= price * 2 target_cp.base.aircraft[unit] = target_cp.base.aircraft.get( unit, 0) + 2 info = Information("Enemy Reinforcement", unit.id + " x 2 at " + target_cp.name, self.turn) print(str(info)) self.informations.append(info)
def doLayout(self): self.update_total_value() self.intelBox = QGroupBox("Units :") self.intelLayout = QGridLayout() i = 0 for g in self.ground_object.groups: if not hasattr(g, "units_losts"): g.units_losts = [] for u in g.units: self.intelLayout.addWidget( QLabel("<b>Unit #" + str(u.id) + " - " + str(u.type) + "</b>"), i, 0) i = i + 1 for u in g.units_losts: utype = unit_type_of(u) if utype in PRICES: price = PRICES[utype] else: price = 6 self.intelLayout.addWidget( QLabel("<b>Unit #" + str(u.id) + " - " + str(u.type) + "</b> [DEAD]"), i, 0) if self.cp.captured: repair = QPushButton("Repair [" + str(price) + "M]") repair.setProperty("style", "btn-success") repair.clicked.connect( lambda u=u, g=g, p=price: self.repair_unit(g, u, p)) self.intelLayout.addWidget(repair, i, 1) i = i + 1 stretch = QVBoxLayout() stretch.addStretch() self.intelLayout.addLayout(stretch, i, 0) self.buildingBox = QGroupBox("Buildings :") self.buildingsLayout = QGridLayout() j = 0 total_income = 0 received_income = 0 for i, building in enumerate(self.buildings): if building.dcs_identifier not in FORTIFICATION_BUILDINGS: self.buildingsLayout.addWidget( QBuildingInfo(building, self.ground_object), j / 3, j % 3) j = j + 1 if building.category in REWARDS.keys(): total_income = total_income + REWARDS[building.category] if not building.is_dead: received_income = received_income + REWARDS[ building.category] else: logging.warning(building.category + " not in REWARDS") self.financesBox = QGroupBox("Finances: ") self.financesBoxLayout = QGridLayout() self.financesBoxLayout.addWidget( QLabel("Available: " + str(total_income) + "M"), 2, 1) self.financesBoxLayout.addWidget( QLabel("Receiving: " + str(received_income) + "M"), 2, 2) self.financesBox.setLayout(self.financesBoxLayout) self.buildingBox.setLayout(self.buildingsLayout) self.intelBox.setLayout(self.intelLayout)
def production_per_turn(self) -> int: production = 0 for g in self.control_point.ground_objects: if g.category in REWARDS.keys(): production += REWARDS[g.category] return production