Don't allow operating on broken runways.

Doesn't allow helos or harriers to do it either even though they should
be able to because we don't currently support ground spawns, which would
be needed to prevent those aircraft from using the runway. Even then, I
don't know if they can be forced to *land* vertically.

Fixes https://github.com/Khopa/dcs_liberation/issues/432
This commit is contained in:
Dan Albert
2020-11-25 18:48:07 -08:00
parent a1b64bc72d
commit 2bd673a531
11 changed files with 54 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
"""Combo box for selecting aircraft types."""
from typing import Iterable
from typing import Iterable, Type
from PySide2.QtWidgets import QComboBox
@@ -9,7 +9,7 @@ from dcs.unittype import FlyingType
class QAircraftTypeSelector(QComboBox):
"""Combo box for selecting among the given aircraft types."""
def __init__(self, aircraft_types: Iterable[FlyingType]) -> None:
def __init__(self, aircraft_types: Iterable[Type[FlyingType]]) -> None:
super().__init__()
for aircraft in aircraft_types:
self.addItem(f"{aircraft.id}", userData=aircraft)

View File

@@ -1,10 +1,9 @@
"""Combo box for selecting a departure airfield."""
from typing import Iterable
from typing import Iterable, Type
from PySide2.QtWidgets import QComboBox
from dcs.unittype import FlyingType
from game import db
from game.theater.controlpoint import ControlPoint
@@ -16,7 +15,7 @@ class QArrivalAirfieldSelector(QComboBox):
"""
def __init__(self, destinations: Iterable[ControlPoint],
aircraft: FlyingType, optional_text: str) -> None:
aircraft: Type[FlyingType], optional_text: str) -> None:
super().__init__()
self.destinations = list(destinations)
self.aircraft = aircraft
@@ -33,7 +32,7 @@ class QArrivalAirfieldSelector(QComboBox):
def rebuild_selector(self) -> None:
self.clear()
for destination in self.destinations:
if destination.can_land(self.aircraft):
if destination.can_operate(self.aircraft):
self.addItem(destination.name, destination)
self.model().sort(0)
self.insertItem(0, self.optional_text, None)

View File

@@ -1,5 +1,5 @@
"""Combo box for selecting a departure airfield."""
from typing import Iterable
from typing import Iterable, Type
from PySide2.QtCore import Signal
from PySide2.QtWidgets import QComboBox
@@ -20,7 +20,7 @@ class QOriginAirfieldSelector(QComboBox):
def __init__(self, global_inventory: GlobalAircraftInventory,
origins: Iterable[ControlPoint],
aircraft: FlyingType) -> None:
aircraft: Type[FlyingType]) -> None:
super().__init__()
self.global_inventory = global_inventory
self.origins = list(origins)
@@ -37,12 +37,14 @@ class QOriginAirfieldSelector(QComboBox):
def rebuild_selector(self) -> None:
self.clear()
for origin in self.origins:
if not origin.can_operate(self.aircraft):
continue
inventory = self.global_inventory.for_control_point(origin)
available = inventory.available(self.aircraft)
if available:
self.addItem(f"{origin.name} ({available} available)", origin)
self.model().sort(0)
self.update()
@property
def available(self) -> int:

View File

@@ -33,7 +33,7 @@ class QMapControlPoint(QMapObject):
painter.setBrush(self.brush_color)
painter.setPen(self.pen_color)
if not self.control_point.has_runway():
if not self.control_point.runway_is_operational():
painter.setBrush(const.COLORS["black"])
painter.setPen(self.brush_color)

View File

@@ -20,9 +20,8 @@ class QBaseMenuTabs(QTabWidget):
self.intel = QIntelInfo(cp, game_model.game)
self.addTab(self.intel, "Intel")
else:
if cp.has_runway():
self.airfield_command = QAirfieldCommand(cp, game_model)
self.addTab(self.airfield_command, "Airfield Command")
self.airfield_command = QAirfieldCommand(cp, game_model)
self.addTab(self.airfield_command, "Airfield Command")
if cp.is_carrier:
self.base_defenses_hq = QBaseDefensesHQ(cp, game_model.game)

View File

@@ -5,6 +5,7 @@ from PySide2.QtWidgets import (
QGroupBox,
QHBoxLayout,
QLabel,
QLayout,
QPushButton,
QSizePolicy,
QSpacerItem,
@@ -45,7 +46,8 @@ class QRecruitBehaviour:
def budget(self, value: int) -> None:
self.game_model.game.budget = value
def add_purchase_row(self, unit_type, layout, row):
def add_purchase_row(self, unit_type: Type[UnitType], layout: QLayout,
row: int, disabled: bool = False) -> int:
exist = QGroupBox()
exist.setProperty("style", "buy-box")
exist.setMaximumHeight(36)
@@ -80,6 +82,7 @@ class QRecruitBehaviour:
buy = QPushButton("+")
buy.setProperty("style", "btn-buy")
buy.setDisabled(disabled)
buy.setMinimumSize(16, 16)
buy.setMaximumSize(16, 16)
buy.clicked.connect(lambda: self.buy(unit_type))
@@ -87,6 +90,7 @@ class QRecruitBehaviour:
sell = QPushButton("-")
sell.setProperty("style", "btn-sell")
sell.setDisabled(disabled)
sell.setMinimumSize(16, 16)
sell.setMaximumSize(16, 16)
sell.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))

View File

@@ -1,5 +1,5 @@
import logging
from typing import Optional, Set
from typing import Optional, Set, Type
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
@@ -13,7 +13,7 @@ from PySide2.QtWidgets import (
QWidget,
)
from dcs.task import CAP, CAS
from dcs.unittype import UnitType
from dcs.unittype import FlyingType, UnitType
from game import db
from game.theater import ControlPoint
@@ -51,12 +51,14 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
task_box_layout = QGridLayout()
row = 0
unit_types: Set[UnitType] = set()
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:
@@ -65,7 +67,9 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
sorted_units = sorted(unit_types, key=lambda u: db.unit_type_name_2(u))
for unit_type in sorted_units:
row = self.add_purchase_row(unit_type, task_box_layout, row)
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)