mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Estimate preferred patrol altitude based on max speed
This commit is contained in:
parent
04cdb6fbfc
commit
a3e3e9046f
@ -180,6 +180,34 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
|||||||
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)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def preferred_patrol_altitude(self) -> Distance:
|
||||||
|
if self.patrol_altitude:
|
||||||
|
return self.patrol_altitude
|
||||||
|
else:
|
||||||
|
# Estimate based on max speed
|
||||||
|
# Aircaft with max speed 200 kph will prefer patrol at 5000 ft
|
||||||
|
# Aircraft with max speed 2700 kph will prefer pratrol at 33 000 ft
|
||||||
|
altitude_for_lowest_speed = feet(5 * 100)
|
||||||
|
altitude_for_highest_speed = feet(33 * 1000)
|
||||||
|
lowest_speed = kph(200)
|
||||||
|
highest_speed = kph(2700)
|
||||||
|
factor = (self.max_speed - lowest_speed).kph / (
|
||||||
|
highest_speed - lowest_speed
|
||||||
|
).kph
|
||||||
|
altitude = (
|
||||||
|
altitude_for_lowest_speed
|
||||||
|
+ (altitude_for_highest_speed - altitude_for_lowest_speed) * factor
|
||||||
|
)
|
||||||
|
logging.debug(
|
||||||
|
f"Preferred patrol altitude for {self.dcs_unit_type.id}: {altitude.feet}"
|
||||||
|
)
|
||||||
|
rounded_altitude = feet(round(1000 * round(altitude.feet / 1000)))
|
||||||
|
return max(
|
||||||
|
altitude_for_lowest_speed,
|
||||||
|
min(altitude_for_highest_speed, rounded_altitude),
|
||||||
|
)
|
||||||
|
|
||||||
def alloc_flight_radio(self, radio_registry: RadioRegistry) -> RadioFrequency:
|
def alloc_flight_radio(self, radio_registry: RadioRegistry) -> RadioFrequency:
|
||||||
from gen.radios import ChannelInUseError, kHz
|
from gen.radios import ChannelInUseError, kHz
|
||||||
|
|
||||||
|
|||||||
@ -1116,11 +1116,12 @@ class FlightPlanBuilder:
|
|||||||
raise InvalidObjectiveLocation(flight.flight_type, location)
|
raise InvalidObjectiveLocation(flight.flight_type, location)
|
||||||
|
|
||||||
start_pos, end_pos = self.racetrack_for_objective(location, barcap=True)
|
start_pos, end_pos = self.racetrack_for_objective(location, barcap=True)
|
||||||
patrol_alt = meters(
|
|
||||||
random.randint(
|
preferred_alt = flight.unit_type.preferred_patrol_altitude
|
||||||
int(self.doctrine.min_patrol_altitude.meters),
|
randomized_alt = preferred_alt + feet(random.randint(-2, 1) * 1000)
|
||||||
int(self.doctrine.max_patrol_altitude.meters),
|
patrol_alt = max(
|
||||||
)
|
self.doctrine.min_patrol_altitude,
|
||||||
|
min(self.doctrine.max_patrol_altitude, randomized_alt),
|
||||||
)
|
)
|
||||||
|
|
||||||
builder = WaypointBuilder(flight, self.coalition)
|
builder = WaypointBuilder(flight, self.coalition)
|
||||||
@ -1355,11 +1356,11 @@ class FlightPlanBuilder:
|
|||||||
"""
|
"""
|
||||||
location = self.package.target
|
location = self.package.target
|
||||||
|
|
||||||
patrol_alt = meters(
|
preferred_alt = flight.unit_type.preferred_patrol_altitude
|
||||||
random.randint(
|
randomized_alt = preferred_alt + feet(random.randint(-2, 1) * 1000)
|
||||||
int(self.doctrine.min_patrol_altitude.meters),
|
patrol_alt = max(
|
||||||
int(self.doctrine.max_patrol_altitude.meters),
|
self.doctrine.min_patrol_altitude,
|
||||||
)
|
min(self.doctrine.max_patrol_altitude, randomized_alt),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create points
|
# Create points
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user