Use navmesh to plan strike-like flight plans.

The cases where the target is extremely close to the origin point still
use the old flight plan pattern. This is probably fine.

https://github.com/Khopa/dcs_liberation/issues/292
This commit is contained in:
Dan Albert
2020-12-23 19:12:35 -08:00
parent d95f623ca9
commit 81af5d7497
4 changed files with 139 additions and 33 deletions

View File

@@ -208,8 +208,11 @@ class NavMesh:
points.append(ShapelyPoint(cp.position.x, cp.position.y))
for tgo in cp.ground_objects:
points.append(ShapelyPoint(tgo.position.x, tgo.position.y))
return box(*LineString(points).bounds).buffer(nautical_miles(60).meters,
resolution=1)
# Needs to be a large enough boundary beyond the known points so that
# threatened airbases at the map edges have room to retreat from the
# threat without running off the navmesh.
return box(*LineString(points).bounds).buffer(
nautical_miles(100).meters, resolution=1)
@staticmethod
def create_navpolys(polys: List[Polygon],

View File

@@ -11,9 +11,9 @@ from shapely.geometry import (
Polygon,
)
from shapely.geometry.base import BaseGeometry
from shapely.ops import unary_union
from shapely.ops import nearest_points, unary_union
from game.utils import nautical_miles
from game.utils import Distance, meters, nautical_miles
from gen.flights.flight import Flight
if TYPE_CHECKING:
@@ -29,9 +29,23 @@ class ThreatZones:
self.air_defenses = air_defenses
self.all = unary_union([airbases, air_defenses])
def threatened(self, position: BaseGeometry) -> bool:
def closest_boundary(self, point: DcsPoint) -> DcsPoint:
boundary, _ = nearest_points(self.all.boundary,
self.dcs_to_shapely_point(point))
return DcsPoint(boundary.x, boundary.y)
@singledispatchmethod
def threatened(self, position) -> bool:
raise NotImplementedError
@threatened.register
def _threatened_geometry(self, position: BaseGeometry) -> bool:
return self.all.intersects(position)
@threatened.register
def _threatened_dcs_point(self, position: DcsPoint) -> bool:
return self.all.intersects(self.dcs_to_shapely_point(position))
def path_threatened(self, a: DcsPoint, b: DcsPoint) -> bool:
return self.threatened(LineString(
[self.dcs_to_shapely_point(a), self.dcs_to_shapely_point(b)]))