mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Increase size of navmesh to avoid planning issues.
The tradeoff is that any flights that might have previously routed _around_ a threat near the edge of the map may no longer do so as the zones at the edge are significantly larger now. Fixes https://github.com/Khopa/dcs_liberation/issues/903
This commit is contained in:
parent
b2fafc22dd
commit
0f07b2c095
@ -21,6 +21,10 @@ from game.threatzones import ThreatZones
|
|||||||
from game.utils import nautical_miles
|
from game.utils import nautical_miles
|
||||||
|
|
||||||
|
|
||||||
|
class NavMeshError(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NavMeshPoly:
|
class NavMeshPoly:
|
||||||
def __init__(self, ident: int, poly: Polygon, threatened: bool) -> None:
|
def __init__(self, ident: int, poly: Polygon, threatened: bool) -> None:
|
||||||
self.ident = ident
|
self.ident = ident
|
||||||
@ -125,7 +129,7 @@ class NavMesh:
|
|||||||
path.append(current.world_point)
|
path.append(current.world_point)
|
||||||
previous = came_from[current]
|
previous = came_from[current]
|
||||||
if previous is None:
|
if previous is None:
|
||||||
raise RuntimeError(
|
raise NavMeshError(
|
||||||
f"Could not reconstruct path to {destination} from {origin}"
|
f"Could not reconstruct path to {destination} from {origin}"
|
||||||
)
|
)
|
||||||
current = previous
|
current = previous
|
||||||
@ -140,10 +144,12 @@ class NavMesh:
|
|||||||
def shortest_path(self, origin: Point, destination: Point) -> List[Point]:
|
def shortest_path(self, origin: Point, destination: Point) -> List[Point]:
|
||||||
origin_poly = self.localize(origin)
|
origin_poly = self.localize(origin)
|
||||||
if origin_poly is None:
|
if origin_poly is None:
|
||||||
raise ValueError(f"Origin point {origin} is outside the navmesh")
|
raise NavMeshError(f"Origin point {origin} is outside the navmesh")
|
||||||
destination_poly = self.localize(destination)
|
destination_poly = self.localize(destination)
|
||||||
if destination_poly is None:
|
if destination_poly is None:
|
||||||
raise ValueError(f"Origin point {destination} is outside the navmesh")
|
raise NavMeshError(
|
||||||
|
f"Destination point {destination} is outside the navmesh"
|
||||||
|
)
|
||||||
|
|
||||||
return self._shortest_path(
|
return self._shortest_path(
|
||||||
NavPoint(self.dcs_to_shapely_point(origin), origin_poly),
|
NavPoint(self.dcs_to_shapely_point(origin), origin_poly),
|
||||||
@ -203,7 +209,7 @@ class NavMesh:
|
|||||||
# threatened airbases at the map edges have room to retreat from the
|
# threatened airbases at the map edges have room to retreat from the
|
||||||
# threat without running off the navmesh.
|
# threat without running off the navmesh.
|
||||||
return box(*LineString(points).bounds).buffer(
|
return box(*LineString(points).bounds).buffer(
|
||||||
nautical_miles(100).meters, resolution=1
|
nautical_miles(200).meters, resolution=1
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -796,7 +796,17 @@ class FlightPlanBuilder:
|
|||||||
raise RuntimeError("Flight must be a part of the package")
|
raise RuntimeError("Flight must be a part of the package")
|
||||||
if self.package.waypoints is None:
|
if self.package.waypoints is None:
|
||||||
self.regenerate_package_waypoints()
|
self.regenerate_package_waypoints()
|
||||||
|
|
||||||
|
from game.navmesh import NavMeshError
|
||||||
|
|
||||||
|
try:
|
||||||
flight.flight_plan = self.generate_flight_plan(flight, custom_targets)
|
flight.flight_plan = self.generate_flight_plan(flight, custom_targets)
|
||||||
|
except NavMeshError as ex:
|
||||||
|
color = "blue" if self.is_player else "red"
|
||||||
|
raise PlanningError(
|
||||||
|
f"Could not plan {color} {flight.flight_type.value} from "
|
||||||
|
f"{flight.departure} to {flight.package.target}"
|
||||||
|
) from ex
|
||||||
|
|
||||||
def generate_flight_plan(
|
def generate_flight_plan(
|
||||||
self, flight: Flight, custom_targets: Optional[List[Unit]]
|
self, flight: Flight, custom_targets: Optional[List[Unit]]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user