mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Merge pull request #1552 from dcs-liberation/better-tarcap-racetracks-2
Better TARCAP racetracks
This commit is contained in:
commit
7417429fdb
@ -62,6 +62,8 @@ class Distance:
|
|||||||
def __mul__(self, other: Union[float, int]) -> Distance:
|
def __mul__(self, other: Union[float, int]) -> Distance:
|
||||||
return meters(self.meters * other)
|
return meters(self.meters * other)
|
||||||
|
|
||||||
|
__rmul__ = __mul__
|
||||||
|
|
||||||
def __truediv__(self, other: Union[float, int]) -> Distance:
|
def __truediv__(self, other: Union[float, int]) -> Distance:
|
||||||
return meters(self.meters / other)
|
return meters(self.meters / other)
|
||||||
|
|
||||||
@ -147,6 +149,8 @@ class Speed:
|
|||||||
def __mul__(self, other: Union[float, int]) -> Speed:
|
def __mul__(self, other: Union[float, int]) -> Speed:
|
||||||
return kph(self.kph * other)
|
return kph(self.kph * other)
|
||||||
|
|
||||||
|
__rmul__ = __mul__
|
||||||
|
|
||||||
def __truediv__(self, other: Union[float, int]) -> Speed:
|
def __truediv__(self, other: Union[float, int]) -> Speed:
|
||||||
return kph(self.kph / other)
|
return kph(self.kph / other)
|
||||||
|
|
||||||
|
|||||||
@ -1115,7 +1115,7 @@ class FlightPlanBuilder:
|
|||||||
if isinstance(location, FrontLine):
|
if isinstance(location, FrontLine):
|
||||||
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.cap_racetrack_for_objective(location, barcap=True)
|
||||||
|
|
||||||
preferred_alt = flight.unit_type.preferred_patrol_altitude
|
preferred_alt = flight.unit_type.preferred_patrol_altitude
|
||||||
randomized_alt = preferred_alt + feet(random.randint(-2, 1) * 1000)
|
randomized_alt = preferred_alt + feet(random.randint(-2, 1) * 1000)
|
||||||
@ -1244,7 +1244,7 @@ class FlightPlanBuilder:
|
|||||||
bullseye=builder.bullseye(),
|
bullseye=builder.bullseye(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def racetrack_for_objective(
|
def cap_racetrack_for_objective(
|
||||||
self, location: MissionTarget, barcap: bool
|
self, location: MissionTarget, barcap: bool
|
||||||
) -> Tuple[Point, Point]:
|
) -> Tuple[Point, Point]:
|
||||||
closest_cache = ObjectiveDistanceCache.get_closest_airfields(location)
|
closest_cache = ObjectiveDistanceCache.get_closest_airfields(location)
|
||||||
@ -1276,6 +1276,7 @@ class FlightPlanBuilder:
|
|||||||
- self.doctrine.cap_engagement_range
|
- self.doctrine.cap_engagement_range
|
||||||
- nautical_miles(5)
|
- nautical_miles(5)
|
||||||
)
|
)
|
||||||
|
max_track_length = self.doctrine.cap_max_track_length
|
||||||
else:
|
else:
|
||||||
# Other race tracks (TARCAPs, currently) just try to keep some
|
# Other race tracks (TARCAPs, currently) just try to keep some
|
||||||
# distance from the nearest enemy airbase, but since they are by
|
# distance from the nearest enemy airbase, but since they are by
|
||||||
@ -1289,6 +1290,11 @@ class FlightPlanBuilder:
|
|||||||
)
|
)
|
||||||
distance_to_no_fly = distance_to_airfield - min_distance_from_enemy
|
distance_to_no_fly = distance_to_airfield - min_distance_from_enemy
|
||||||
|
|
||||||
|
# TARCAPs fly short racetracks because they need to react faster.
|
||||||
|
max_track_length = self.doctrine.cap_min_track_length + 0.3 * (
|
||||||
|
self.doctrine.cap_max_track_length - self.doctrine.cap_min_track_length
|
||||||
|
)
|
||||||
|
|
||||||
min_cap_distance = min(
|
min_cap_distance = min(
|
||||||
self.doctrine.cap_min_distance_from_cp, distance_to_no_fly
|
self.doctrine.cap_min_distance_from_cp, distance_to_no_fly
|
||||||
)
|
)
|
||||||
@ -1300,11 +1306,12 @@ class FlightPlanBuilder:
|
|||||||
heading.degrees,
|
heading.degrees,
|
||||||
random.randint(int(min_cap_distance.meters), int(max_cap_distance.meters)),
|
random.randint(int(min_cap_distance.meters), int(max_cap_distance.meters)),
|
||||||
)
|
)
|
||||||
diameter = random.randint(
|
|
||||||
|
track_length = random.randint(
|
||||||
int(self.doctrine.cap_min_track_length.meters),
|
int(self.doctrine.cap_min_track_length.meters),
|
||||||
int(self.doctrine.cap_max_track_length.meters),
|
int(max_track_length.meters),
|
||||||
)
|
)
|
||||||
start = end.point_from_heading(heading.opposite.degrees, diameter)
|
start = end.point_from_heading(heading.opposite.degrees, track_length)
|
||||||
return start, end
|
return start, end
|
||||||
|
|
||||||
def aewc_orbit(self, location: MissionTarget) -> Point:
|
def aewc_orbit(self, location: MissionTarget) -> Point:
|
||||||
@ -1327,33 +1334,6 @@ class FlightPlanBuilder:
|
|||||||
orbit_heading.degrees, orbit_distance.meters
|
orbit_heading.degrees, orbit_distance.meters
|
||||||
)
|
)
|
||||||
|
|
||||||
def racetrack_for_frontline(
|
|
||||||
self, origin: Point, front_line: FrontLine
|
|
||||||
) -> Tuple[Point, Point]:
|
|
||||||
# Find targets waypoints
|
|
||||||
ingress, heading, distance = Conflict.frontline_vector(front_line, self.theater)
|
|
||||||
center = ingress.point_from_heading(heading.degrees, distance / 2)
|
|
||||||
orbit_center = center.point_from_heading(
|
|
||||||
heading.left.degrees,
|
|
||||||
random.randint(
|
|
||||||
int(nautical_miles(6).meters), int(nautical_miles(15).meters)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
combat_width = distance / 2
|
|
||||||
if combat_width > 500000:
|
|
||||||
combat_width = 500000
|
|
||||||
if combat_width < 35000:
|
|
||||||
combat_width = 35000
|
|
||||||
|
|
||||||
radius = combat_width * 1.25
|
|
||||||
start = orbit_center.point_from_heading(heading.degrees, radius)
|
|
||||||
end = orbit_center.point_from_heading(heading.opposite.degrees, radius)
|
|
||||||
|
|
||||||
if end.distance_to_point(origin) < start.distance_to_point(origin):
|
|
||||||
start, end = end, start
|
|
||||||
return start, end
|
|
||||||
|
|
||||||
def generate_tarcap(self, flight: Flight) -> TarCapFlightPlan:
|
def generate_tarcap(self, flight: Flight) -> TarCapFlightPlan:
|
||||||
"""Generate a CAP flight plan for the given front line.
|
"""Generate a CAP flight plan for the given front line.
|
||||||
|
|
||||||
@ -1375,13 +1355,7 @@ class FlightPlanBuilder:
|
|||||||
|
|
||||||
# Create points
|
# Create points
|
||||||
builder = WaypointBuilder(flight, self.coalition)
|
builder = WaypointBuilder(flight, self.coalition)
|
||||||
|
orbit0p, orbit1p = self.cap_racetrack_for_objective(location, barcap=False)
|
||||||
if isinstance(location, FrontLine):
|
|
||||||
orbit0p, orbit1p = self.racetrack_for_frontline(
|
|
||||||
flight.departure.position, location
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
orbit0p, orbit1p = self.racetrack_for_objective(location, barcap=False)
|
|
||||||
|
|
||||||
start, end = builder.race_track(orbit0p, orbit1p, patrol_alt)
|
start, end = builder.race_track(orbit0p, orbit1p, patrol_alt)
|
||||||
return TarCapFlightPlan(
|
return TarCapFlightPlan(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user