Halt sim on A2A contact.

https://github.com/dcs-liberation/dcs_liberation/issues/1681
This commit is contained in:
Dan Albert
2021-10-27 00:45:39 -07:00
parent 9839787b6d
commit b2cbf4b6f4
13 changed files with 202 additions and 64 deletions

View File

@@ -0,0 +1,37 @@
from __future__ import annotations
from typing import Optional, TYPE_CHECKING
from dcs import Point
from shapely.geometry import Point as ShapelyPoint
from shapely.ops import unary_union
from game.ato.flightstate import InFlight
if TYPE_CHECKING:
from game.ato import Flight
from game.ato.airtaaskingorder import AirTaskingOrder
from game.threatzones import ThreatPoly
class AircraftEngagementZones:
def __init__(self, threat_zones: ThreatPoly) -> None:
self.threat_zones = threat_zones
def covers(self, position: Point) -> bool:
return self.threat_zones.intersects(ShapelyPoint(position.x, position.y))
@classmethod
def from_ato(cls, ato: AirTaskingOrder) -> AircraftEngagementZones:
commit_regions = []
for package in ato.packages:
for flight in package.flights:
if (region := cls.commit_region(flight)) is not None:
commit_regions.append(region)
return AircraftEngagementZones(unary_union(commit_regions))
@classmethod
def commit_region(cls, flight: Flight) -> Optional[ThreatPoly]:
if isinstance(flight.state, InFlight):
return flight.state.a2a_commit_region()
return None

View File

@@ -17,6 +17,7 @@ from game.ato.flightstate import (
WaitingForStart,
)
from game.ato.starttype import StartType
from game.sim.aircraftengagementzones import AircraftEngagementZones
from gen.flights.traveltime import TotEstimator
if TYPE_CHECKING:
@@ -45,18 +46,17 @@ class AircraftSimulation:
return
def tick(self) -> bool:
interrupt_sim = False
for flight in self.iter_flights():
flight.on_game_tick(self.time, TICK)
if flight.should_halt_sim():
interrupt_sim = True
# TODO: Check for SAM or A2A contact.
# Generate an engagement poly for all active air-to-air aircraft per-coalition
# and compare those against aircraft positions. If any aircraft intersects an
# enemy air-threat region, generate the mission. Also check against enemy SAM
# zones.
return interrupt_sim
# Finish updating all flights before computing engagement zones so that the new
# positions are used.
blue_a2a = AircraftEngagementZones.from_ato(self.game.blue.ato)
red_a2a = AircraftEngagementZones.from_ato(self.game.red.ato)
for flight in self.iter_flights():
if flight.should_halt_sim(red_a2a if flight.squadron.player else blue_a2a):
return True
return False
def set_initial_flight_states(self) -> None:
now = self.game.conditions.start_time
@@ -78,7 +78,7 @@ class AircraftSimulation:
elif flight.start_type is StartType.RUNWAY:
flight.set_state(Takeoff(flight, self.game.settings, now))
elif flight.start_type is StartType.IN_FLIGHT:
flight.set_state(InFlight(flight, self.game.settings))
flight.set_state(InFlight(flight, self.game.settings, waypoint_index=0))
else:
raise ValueError(f"Unknown start type {flight.start_type} for {flight}")