Interrupt fast-forward on air defense contact.

https://github.com/dcs-liberation/dcs_liberation/issues/1681
This commit is contained in:
Dan Albert 2021-10-26 23:06:58 -07:00
parent cd0c0f1b01
commit 9839787b6d
4 changed files with 18 additions and 2 deletions

View File

@ -134,6 +134,8 @@ class Flight:
def set_state(self, state: FlightState) -> None:
self.state = state
def on_game_tick(self, time: datetime, duration: timedelta) -> bool:
def on_game_tick(self, time: datetime, duration: timedelta) -> None:
self.state.on_game_tick(time, duration)
def should_halt_sim(self) -> bool:
return self.state.should_halt_sim()

View File

@ -123,6 +123,15 @@ class InFlight(FlightState):
"ingress point"
)
return True
threat_zone = self.flight.squadron.coalition.opponent.threat_zone
if threat_zone.threatened_by_air_defense(self.estimate_position()):
logging.info(
f"Interrupting simulation because {self.flight} has encountered enemy "
"air defenses"
)
return True
return False
@property

View File

@ -47,7 +47,8 @@ class AircraftSimulation:
def tick(self) -> bool:
interrupt_sim = False
for flight in self.iter_flights():
if flight.on_game_tick(self.time, TICK):
flight.on_game_tick(self.time, TICK)
if flight.should_halt_sim():
interrupt_sim = True
# TODO: Check for SAM or A2A contact.

View File

@ -104,6 +104,10 @@ class ThreatZones:
def _threatened_by_air_defense_geom(self, position: BaseGeometry) -> bool:
return self.air_defenses.intersects(position)
@threatened_by_air_defense.register
def _threatened_by_air_defense_dcs_point(self, position: DcsPoint) -> bool:
return self.threatened_by_air_defense(self.dcs_to_shapely_point(position))
@threatened_by_air_defense.register
def _threatened_by_air_defense_flight(self, flight: Flight) -> bool:
return self.threatened_by_air_defense(