mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
parent
efd2c40cfc
commit
5b7ff8bdd6
@ -80,6 +80,8 @@ class Flight(SidcDescribable, RadioFrequencyContainer, TacanContainer):
|
|||||||
self.tacan = channel
|
self.tacan = channel
|
||||||
self.tcn_name = callsign
|
self.tcn_name = callsign
|
||||||
|
|
||||||
|
self.initialize_fuel()
|
||||||
|
|
||||||
# Only used by transport missions.
|
# Only used by transport missions.
|
||||||
self.cargo = cargo
|
self.cargo = cargo
|
||||||
|
|
||||||
@ -204,19 +206,19 @@ class Flight(SidcDescribable, RadioFrequencyContainer, TacanContainer):
|
|||||||
self.roster.clear()
|
self.roster.clear()
|
||||||
self.squadron.claim_inventory(-self.count)
|
self.squadron.claim_inventory(-self.count)
|
||||||
|
|
||||||
def max_takeoff_fuel(self) -> Optional[float]:
|
def initialize_fuel(self) -> None:
|
||||||
# Special case so Su 33 and C101 can take off
|
|
||||||
unit_type = self.unit_type.dcs_unit_type
|
unit_type = self.unit_type.dcs_unit_type
|
||||||
|
self.fuel = unit_type.fuel_max
|
||||||
|
# Special cases where we want less fuel for takeoff
|
||||||
if unit_type == Su_33:
|
if unit_type == Su_33:
|
||||||
if self.flight_type.is_air_to_air:
|
if self.flight_type.is_air_to_air:
|
||||||
return Su_33.fuel_max / 2.2
|
self.fuel = Su_33.fuel_max / 2.2
|
||||||
else:
|
else:
|
||||||
return Su_33.fuel_max * 0.8
|
self.fuel = Su_33.fuel_max * 0.8
|
||||||
elif unit_type in {C_101EB, C_101CC}:
|
elif unit_type in {C_101EB, C_101CC}:
|
||||||
return unit_type.fuel_max * 0.5
|
self.fuel = unit_type.fuel_max * 0.5
|
||||||
elif unit_type == Hercules:
|
elif unit_type == Hercules:
|
||||||
return unit_type.fuel_max * 0.75
|
self.fuel = unit_type.fuel_max * 0.75
|
||||||
return None
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|||||||
@ -82,9 +82,7 @@ class FlightState(ABC):
|
|||||||
|
|
||||||
def estimate_fuel(self) -> float:
|
def estimate_fuel(self) -> float:
|
||||||
"""Returns the estimated remaining fuel **in kilograms**."""
|
"""Returns the estimated remaining fuel **in kilograms**."""
|
||||||
if (max_takeoff_fuel := self.flight.max_takeoff_fuel()) is not None:
|
return self.flight.fuel
|
||||||
return max_takeoff_fuel
|
|
||||||
return self.flight.unit_type.dcs_unit_type.fuel_max
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@ -200,6 +200,10 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
def helicopter(self) -> bool:
|
def helicopter(self) -> bool:
|
||||||
return self.dcs_unit_type.helicopter
|
return self.dcs_unit_type.helicopter
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_fuel(self) -> float:
|
||||||
|
return self.dcs_unit_type.fuel_max
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def max_speed(self) -> Speed:
|
def max_speed(self) -> Speed:
|
||||||
return kph(self.dcs_unit_type.max_speed)
|
return kph(self.dcs_unit_type.max_speed)
|
||||||
|
|||||||
@ -76,3 +76,4 @@ class Migrator:
|
|||||||
try_set_attr(f, "frequency")
|
try_set_attr(f, "frequency")
|
||||||
try_set_attr(f, "tacan")
|
try_set_attr(f, "tacan")
|
||||||
try_set_attr(f, "tcn_name")
|
try_set_attr(f, "tcn_name")
|
||||||
|
try_set_attr(f, "fuel", f.unit_type.max_fuel)
|
||||||
|
|||||||
@ -249,12 +249,4 @@ class FlightGroupConfigurator:
|
|||||||
)
|
)
|
||||||
fuel = 100
|
fuel = 100
|
||||||
for unit, pilot in zip(self.group.units, self.flight.roster.pilots):
|
for unit, pilot in zip(self.group.units, self.flight.roster.pilots):
|
||||||
if pilot is not None and pilot.player:
|
|
||||||
unit.fuel = fuel
|
unit.fuel = fuel
|
||||||
elif (max_takeoff_fuel := self.flight.max_takeoff_fuel()) is not None:
|
|
||||||
unit.fuel = max_takeoff_fuel
|
|
||||||
else:
|
|
||||||
# pydcs arbitrarily reduces the fuel of in-flight spawns by 10%. We do
|
|
||||||
# our own tracking, so undo that.
|
|
||||||
# https://github.com/pydcs/dcs/commit/303a81a8e0c778599fe136dd22cb2ae8123639a6
|
|
||||||
unit.fuel = self.flight.unit_type.dcs_unit_type.fuel_max
|
|
||||||
|
|||||||
@ -3,9 +3,12 @@ from PySide2.QtWidgets import (
|
|||||||
QComboBox,
|
QComboBox,
|
||||||
QFrame,
|
QFrame,
|
||||||
QLabel,
|
QLabel,
|
||||||
|
QHBoxLayout,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QScrollArea,
|
QScrollArea,
|
||||||
QWidget,
|
QWidget,
|
||||||
|
QSpinBox,
|
||||||
|
QSlider,
|
||||||
)
|
)
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
@ -28,6 +31,70 @@ class DcsLoadoutSelector(QComboBox):
|
|||||||
self.setCurrentText(flight.loadout.name)
|
self.setCurrentText(flight.loadout.name)
|
||||||
|
|
||||||
|
|
||||||
|
class DcsFuelSelector(QHBoxLayout):
|
||||||
|
LBS2KGS_FACTOR = 0.45359237
|
||||||
|
|
||||||
|
def __init__(self, flight: Flight) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.flight = flight
|
||||||
|
self.unit_changing = False
|
||||||
|
|
||||||
|
self.label = QLabel("Internal Fuel Quantity: ")
|
||||||
|
self.addWidget(self.label)
|
||||||
|
|
||||||
|
self.max_fuel = int(flight.unit_type.dcs_unit_type.fuel_max)
|
||||||
|
self.fuel = QSlider(Qt.Horizontal)
|
||||||
|
self.fuel.setRange(0, self.max_fuel)
|
||||||
|
self.fuel.setValue(min(round(self.flight.fuel), self.max_fuel))
|
||||||
|
self.fuel.valueChanged.connect(self.on_fuel_change)
|
||||||
|
self.addWidget(self.fuel, 1)
|
||||||
|
|
||||||
|
self.fuel_spinner = QSpinBox()
|
||||||
|
self.fuel_spinner.setRange(0, self.max_fuel)
|
||||||
|
self.fuel_spinner.setValue(self.fuel.value())
|
||||||
|
self.fuel_spinner.valueChanged.connect(self.update_fuel_slider)
|
||||||
|
self.addWidget(self.fuel_spinner)
|
||||||
|
|
||||||
|
self.unit = QComboBox()
|
||||||
|
self.unit.insertItems(0, ["kg", "lbs"])
|
||||||
|
self.unit.currentIndexChanged.connect(self.on_unit_change)
|
||||||
|
self.unit.setCurrentIndex(1)
|
||||||
|
self.addWidget(self.unit)
|
||||||
|
|
||||||
|
def on_fuel_change(self, value: int) -> None:
|
||||||
|
self.flight.fuel = value
|
||||||
|
if self.unit.currentIndex() == 0:
|
||||||
|
self.fuel_spinner.setValue(value)
|
||||||
|
elif self.unit.currentIndex() == 1 and not self.unit_changing:
|
||||||
|
self.fuel_spinner.setValue(self.kg2lbs(value))
|
||||||
|
|
||||||
|
def update_fuel_slider(self, value: int) -> None:
|
||||||
|
if self.unit_changing:
|
||||||
|
return
|
||||||
|
if self.unit.currentIndex() == 0:
|
||||||
|
self.fuel.setValue(value)
|
||||||
|
elif self.unit.currentIndex() == 1:
|
||||||
|
self.unit_changing = True
|
||||||
|
self.fuel.setValue(self.lbs2kg(value))
|
||||||
|
self.unit_changing = False
|
||||||
|
|
||||||
|
def on_unit_change(self, index: int) -> None:
|
||||||
|
self.unit_changing = True
|
||||||
|
if index == 0:
|
||||||
|
self.fuel_spinner.setMaximum(self.max_fuel)
|
||||||
|
self.fuel_spinner.setValue(self.fuel.value())
|
||||||
|
elif index == 1:
|
||||||
|
self.fuel_spinner.setMaximum(self.kg2lbs(self.max_fuel))
|
||||||
|
self.fuel_spinner.setValue(self.kg2lbs(self.fuel.value()))
|
||||||
|
self.unit_changing = False
|
||||||
|
|
||||||
|
def kg2lbs(self, value: int) -> int:
|
||||||
|
return round(value / self.LBS2KGS_FACTOR)
|
||||||
|
|
||||||
|
def lbs2kg(self, value: int) -> int:
|
||||||
|
return round(value * self.LBS2KGS_FACTOR)
|
||||||
|
|
||||||
|
|
||||||
class QFlightPayloadTab(QFrame):
|
class QFlightPayloadTab(QFrame):
|
||||||
def __init__(self, flight: Flight, game: Game):
|
def __init__(self, flight: Flight, game: Game):
|
||||||
super(QFlightPayloadTab, self).__init__()
|
super(QFlightPayloadTab, self).__init__()
|
||||||
@ -48,12 +115,15 @@ class QFlightPayloadTab(QFrame):
|
|||||||
self.property_editor = QWidget()
|
self.property_editor = QWidget()
|
||||||
self.property_editor.setLayout(PropertyEditor(self.flight))
|
self.property_editor.setLayout(PropertyEditor(self.flight))
|
||||||
self.scroll_area.setWidget(self.property_editor)
|
self.scroll_area.setWidget(self.property_editor)
|
||||||
|
|
||||||
layout.addWidget(self.scroll_area)
|
layout.addWidget(self.scroll_area)
|
||||||
|
|
||||||
|
self.fuel_selector = DcsFuelSelector(flight)
|
||||||
|
layout.addLayout(self.fuel_selector)
|
||||||
|
|
||||||
self.loadout_selector = DcsLoadoutSelector(flight)
|
self.loadout_selector = DcsLoadoutSelector(flight)
|
||||||
self.loadout_selector.currentIndexChanged.connect(self.on_new_loadout)
|
self.loadout_selector.currentIndexChanged.connect(self.on_new_loadout)
|
||||||
layout.addWidget(self.loadout_selector)
|
layout.addWidget(self.loadout_selector)
|
||||||
layout.addWidget(self.payload_editor)
|
layout.addWidget(self.payload_editor, stretch=1)
|
||||||
layout.addWidget(docsText)
|
layout.addWidget(docsText)
|
||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user