mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Attempt to reset the simulation on abort.
This is optional because I really don't know if I trust it. I don't see much wrong with it (aside from the warning about not using it with auto- resolve, because it won't restore lost aircraft), but it's really not something I'd built for since it's not going to be possible as the RTS features grow. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2735.
This commit is contained in:
@@ -11,12 +11,12 @@ from game.ato.flightstate import (
|
||||
Uninitialized,
|
||||
)
|
||||
from .combat import CombatInitiator, FrozenCombat
|
||||
from .gameupdateevents import GameUpdateEvents
|
||||
from .simulationresults import SimulationResults
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
from game.ato import Flight
|
||||
from .gameupdateevents import GameUpdateEvents
|
||||
|
||||
|
||||
class AircraftSimulation:
|
||||
@@ -69,9 +69,13 @@ class AircraftSimulation:
|
||||
for flight in self.iter_flights():
|
||||
flight.state.reinitialize(now)
|
||||
|
||||
def reset(self) -> None:
|
||||
def reset(self, events: GameUpdateEvents | None = None) -> None:
|
||||
if events is None:
|
||||
events = GameUpdateEvents()
|
||||
for flight in self.iter_flights():
|
||||
flight.set_state(Uninitialized(flight, self.game.settings))
|
||||
events.update_flight(flight)
|
||||
self.combats = []
|
||||
|
||||
def iter_flights(self) -> Iterator[Flight]:
|
||||
packages = itertools.chain(
|
||||
|
||||
@@ -36,6 +36,14 @@ class GameLoop:
|
||||
def elapsed_time(self) -> timedelta:
|
||||
return self.sim.time - self.game.conditions.start_time
|
||||
|
||||
def reset(self) -> None:
|
||||
self.pause()
|
||||
self.events = GameUpdateEvents()
|
||||
self.sim.reset(self.events)
|
||||
self.send_update(rate_limit=False)
|
||||
self.started = False
|
||||
self.completed = False
|
||||
|
||||
def start(self) -> None:
|
||||
if self.started:
|
||||
raise RuntimeError("Cannot start game loop because it has already started")
|
||||
|
||||
@@ -33,6 +33,11 @@ class MissionSimulation:
|
||||
self.completed = False
|
||||
self.time = self.game.conditions.start_time
|
||||
|
||||
def reset(self, events: GameUpdateEvents) -> None:
|
||||
self.completed = False
|
||||
self.time = self.game.conditions.start_time
|
||||
self.aircraft_simulation.reset(events)
|
||||
|
||||
def begin_simulation(self) -> None:
|
||||
self.time = self.game.conditions.start_time
|
||||
self.aircraft_simulation.begin_simulation()
|
||||
|
||||
Reference in New Issue
Block a user