forked from dcs-liberation/dcs_liberation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Build common interface for waypoint geometry constraints.
Fixes dcs-liberation#3085.
- Loading branch information
Showing
9 changed files
with
528 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from shapely.geometry import MultiPolygon, Point | ||
|
||
from game.data.doctrine import Doctrine | ||
from game.flightplan.waypointsolver import WaypointSolver | ||
from game.flightplan.waypointstrategy import WaypointStrategy | ||
from game.utils import meters, nautical_miles | ||
|
||
|
||
class ThreatTolerantIpStrategy(WaypointStrategy): | ||
def __init__( | ||
self, | ||
departure: Point, | ||
target: Point, | ||
threat_zones: MultiPolygon, | ||
) -> None: | ||
super().__init__(threat_zones) | ||
self.prerequisite(target).min_distance_from(departure, nautical_miles(10)) | ||
self.require().at_least(nautical_miles(5)).away_from(departure) | ||
self.require().at_most(meters(departure.distance(target))).away_from(departure) | ||
self.require().at_least(nautical_miles(10)).away_from(target) | ||
max_ip_range = min(nautical_miles(45), departure.distance(target)) | ||
self.require().at_most(max_ip_range).away_from(target) | ||
self.threat_tolerance(target, max_ip_range, nautical_miles(5)) | ||
self.nearest(departure) | ||
|
||
|
||
class UnsafeIpStrategy(WaypointStrategy): | ||
def __init__( | ||
self, | ||
departure: Point, | ||
target: Point, | ||
threat_zones: MultiPolygon, | ||
) -> None: | ||
super().__init__(threat_zones) | ||
self.prerequisite(target).min_distance_from(departure, nautical_miles(10)) | ||
self.require().at_least(nautical_miles(5)).away_from(departure) | ||
self.require().at_most(meters(departure.distance(target))).away_from(departure) | ||
self.require().at_least(nautical_miles(10)).away_from(target) | ||
max_ip_range = min(nautical_miles(45), departure.distance(target)) | ||
self.require().at_most(max_ip_range).away_from(target) | ||
self.nearest(departure) | ||
|
||
|
||
class SafeIpStrategy(WaypointStrategy): | ||
def __init__( | ||
self, | ||
departure: Point, | ||
target: Point, | ||
doctrine: Doctrine, | ||
threat_zones: MultiPolygon, | ||
) -> None: | ||
super().__init__(threat_zones) | ||
self.prerequisite(departure).safe() | ||
self.prerequisite(target).min_distance_from( | ||
departure, doctrine.min_ingress_distance | ||
) | ||
self.require().at_least(nautical_miles(5)).away_from(departure) | ||
self.require().at_most(meters(departure.distance(target))).away_from(departure) | ||
self.require().at_least(doctrine.min_ingress_distance).away_from(target) | ||
self.require().at_most( | ||
min(doctrine.max_ingress_distance, meters(departure.distance(target))) | ||
).away_from(target) | ||
self.require().safe() | ||
self.nearest(departure) | ||
|
||
|
||
class IpSolver(WaypointSolver): | ||
def __init__( | ||
self, | ||
departure: Point, | ||
target: Point, | ||
doctrine: Doctrine, | ||
threat_zones: MultiPolygon, | ||
) -> None: | ||
super().__init__() | ||
self.add_strategy(SafeIpStrategy(departure, target, doctrine, threat_zones)) | ||
self.add_strategy(ThreatTolerantIpStrategy(departure, target, threat_zones)) | ||
self.add_strategy(UnsafeIpStrategy(departure, target, threat_zones)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from dcs import Point | ||
|
||
if TYPE_CHECKING: | ||
from .waypointstrategy import WaypointStrategy | ||
|
||
|
||
class WaypointSolver: | ||
def __init__(self) -> None: | ||
self.strategies: list[WaypointStrategy] = [] | ||
self.debug_output_directory: Path | None = None | ||
|
||
def add_strategy(self, strategy: WaypointStrategy) -> None: | ||
self.strategies.append(strategy) | ||
|
||
def set_debug_output_directory(self, path: Path) -> None: | ||
self.debug_output_directory = path | ||
|
||
def dump_debug_info(self) -> None: | ||
path = self.debug_output_directory | ||
if path is None: | ||
return | ||
|
||
def solve(self) -> Point: | ||
if not self.strategies: | ||
raise ValueError( | ||
"WaypointSolver.solve() called before any strategies were added" | ||
) | ||
|
||
for strategy in self.strategies: | ||
if (point := strategy.find()) is not None: | ||
return point | ||
|
||
self.dump_debug_info() | ||
debug_details = "No debug output directory set" | ||
if (debug_path := self.debug_output_directory) is not None: | ||
debug_details = f"Debug details written to {debug_path}" | ||
raise RuntimeError(f"No solutions found for waypoint. {debug_details}") |
Oops, something went wrong.