mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
There are some TODOs here but th behavior is flagged off by default. The biggest TODO here is that the time spent frozen is not simulated, so flights that are engaged by SAMs will unfreeze, move slightly, then re- freeze. https://github.com/dcs-liberation/dcs_liberation/issues/1680
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
import random
|
|
from collections.abc import Iterator
|
|
from datetime import timedelta
|
|
from typing import TYPE_CHECKING
|
|
|
|
from game.ato.flightstate import InCombat
|
|
from .frozencombat import FrozenCombat
|
|
|
|
if TYPE_CHECKING:
|
|
from game.ato import Flight
|
|
from game.theater import TheaterGroundObject
|
|
from ..simulationresults import SimulationResults
|
|
|
|
|
|
class DefendingSam(FrozenCombat):
|
|
def __init__(
|
|
self,
|
|
freeze_duration: timedelta,
|
|
flight: Flight,
|
|
air_defenses: list[TheaterGroundObject],
|
|
) -> None:
|
|
super().__init__(freeze_duration)
|
|
self.flight = flight
|
|
self.air_defenses = air_defenses
|
|
|
|
def because(self) -> str:
|
|
sams = ", ".join(str(d) for d in self.air_defenses)
|
|
return f"{self.flight} is engaged by enemy air defenses: {sams}"
|
|
|
|
def describe(self) -> str:
|
|
return f"engaged by enemy air defenses"
|
|
|
|
def iter_flights(self) -> Iterator[Flight]:
|
|
yield self.flight
|
|
|
|
def resolve(self, results: SimulationResults) -> None:
|
|
assert isinstance(self.flight.state, InCombat)
|
|
if random.random() / self.flight.count >= 0.5:
|
|
logging.debug(f"Air defense combat auto-resolved with {self.flight} lost")
|
|
self.flight.kill(results)
|
|
else:
|
|
logging.debug(
|
|
f"Air defense combat auto-resolved with {self.flight} surviving"
|
|
)
|
|
self.flight.state.exit_combat()
|