Simplfy fast forward settings, introduce ability to skip combat instead of resolving. (#3448)

This PR simplifies fast forward settings and introduces the ability to
skip combat instead of resolving.
This commit is contained in:
zhexu14
2024-10-15 20:10:53 +11:00
committed by GitHub
parent 5d0ddea753
commit df43d2eed6
12 changed files with 108 additions and 92 deletions

View File

@@ -10,6 +10,7 @@ from typing_extensions import TYPE_CHECKING
from game.ato.flightstate import (
Uninitialized,
)
from game.settings.settings import FastForwardStopCondition, CombatResolutionMethod
from .combat import CombatInitiator, FrozenCombat
from .gameupdateevents import GameUpdateEvents
from .simulationresults import SimulationResults
@@ -32,7 +33,7 @@ class AircraftSimulation:
def on_game_tick(
self, events: GameUpdateEvents, time: datetime, duration: timedelta
) -> None:
if not self.game.settings.auto_resolve_combat and self.combats:
if not self._auto_resolve_combat() and self.combats:
logging.error(
"Cannot resume simulation because aircraft are in combat and "
"auto-resolve is disabled"
@@ -42,7 +43,13 @@ class AircraftSimulation:
still_active = []
for combat in self.combats:
if combat.on_game_tick(time, duration, self.results, events):
if combat.on_game_tick(
time,
duration,
self.results,
events,
self.game.settings.combat_resolution_method,
):
events.end_combat(combat)
else:
still_active.append(combat)
@@ -61,7 +68,7 @@ class AircraftSimulation:
events.complete_simulation()
return
if not self.game.settings.auto_resolve_combat and self.combats:
if not self._auto_resolve_combat() and self.combats:
events.complete_simulation()
def set_initial_flight_states(self) -> None:
@@ -80,3 +87,11 @@ class AircraftSimulation:
)
for package in packages:
yield from package.flights
def _auto_resolve_combat(self) -> bool:
return (
self.game.settings.fast_forward_stop_condition
!= FastForwardStopCondition.DISABLED
and self.game.settings.combat_resolution_method
!= CombatResolutionMethod.PAUSE
)

View File

@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING
from shapely.ops import unary_union
from game.ato.flightstate import InCombat, InFlight
from game.settings.settings import CombatResolutionMethod
from game.utils import dcs_to_shapely_point
from .joinablecombat import JoinableCombat
from .. import GameUpdateEvents
@@ -67,7 +68,15 @@ class AirCombat(JoinableCombat):
events: GameUpdateEvents,
time: datetime,
elapsed_time: timedelta,
resolution_method: CombatResolutionMethod,
) -> None:
if resolution_method is CombatResolutionMethod.SKIP:
for flight in self.flights:
assert isinstance(flight.state, InCombat)
flight.state.exit_combat(events, time, elapsed_time)
return
blue = []
red = []
for flight in self.flights:

View File

@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING
from .frozencombat import FrozenCombat
from .. import GameUpdateEvents
from ...ato.flightstate import InCombat
from game.settings.settings import CombatResolutionMethod
if TYPE_CHECKING:
from game.ato import Flight
@@ -34,6 +35,7 @@ class AtIp(FrozenCombat):
events: GameUpdateEvents,
time: datetime,
elapsed_time: timedelta,
resolution_method: CombatResolutionMethod,
) -> None:
logging.debug(
f"{self.flight} attack on {self.flight.package.target} auto-resolved with "

View File

@@ -7,6 +7,7 @@ from datetime import datetime, timedelta
from typing import TYPE_CHECKING
from game.ato.flightstate import InCombat
from game.settings.settings import CombatResolutionMethod
from .frozencombat import FrozenCombat
from .. import GameUpdateEvents
@@ -43,8 +44,14 @@ class DefendingSam(FrozenCombat):
events: GameUpdateEvents,
time: datetime,
elapsed_time: timedelta,
resolution_method: CombatResolutionMethod,
) -> None:
assert isinstance(self.flight.state, InCombat)
if resolution_method is CombatResolutionMethod.SKIP:
self.flight.state.exit_combat(events, time, elapsed_time)
return
if random.random() >= 0.5:
logging.debug(f"Air defense combat auto-resolved with {self.flight} lost")
self.flight.kill(results, events)

View File

@@ -7,6 +7,7 @@ from datetime import datetime, timedelta
from typing import TYPE_CHECKING
from game.ato.flightstate import InCombat, InFlight
from game.settings.settings import CombatResolutionMethod
from .. import GameUpdateEvents
if TYPE_CHECKING:
@@ -26,10 +27,11 @@ class FrozenCombat(ABC):
duration: timedelta,
results: SimulationResults,
events: GameUpdateEvents,
resolution_method: CombatResolutionMethod,
) -> bool:
self.elapsed_time += duration
if self.elapsed_time >= self.freeze_duration:
self.resolve(results, events, time, self.elapsed_time)
self.resolve(results, events, time, self.elapsed_time, resolution_method)
return True
return False
@@ -40,6 +42,7 @@ class FrozenCombat(ABC):
events: GameUpdateEvents,
time: datetime,
elapsed_time: timedelta,
resolution_method: CombatResolutionMethod,
) -> None: ...
@abstractmethod

View File

@@ -65,7 +65,7 @@ class GameLoop:
self.start()
logging.info("Running sim to first contact")
while not self.completed:
self.tick(suppress_events=True)
self.tick(suppress_events=False)
def pause_and_generate_miz(self, output: Path) -> None:
self.pause()