mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
This is the first step in a larger project to add play/pause buttons to the Liberation UI so the mission can be generated at any point. docs/design/turnless.md describes the plan. This adds an option to fast forward the turn to first contact before generating the mission. None of that is reflected in the UI (for now), but the miz will be generated with many flights in the air. For now "first contact" means as soon as any flight reaches its IP. I'll follow up to add threat checking so that air-to-air combat also triggers this, as will entering a SAM's threat zone. This also includes an option to halt fast-forward whenever a player flight reaches a certain mission-prep phase. This can be used to avoid fast forwarding past the player's startup time, taxi time, or takeoff time. By default this option is disabled so player aircraft may start in the air (possibly even at their IP if they're the first mission to reach IP). Fuel states do not currently account for distance traveled during fast forward. That will come later. https://github.com/dcs-liberation/dcs_liberation/issues/1681
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Optional, TYPE_CHECKING
|
|
|
|
from game.debriefing import Debriefing
|
|
from game.missiongenerator import MissionGenerator
|
|
from game.sim.aircraftsimulation import AircraftSimulation
|
|
from game.sim.missionresultsprocessor import MissionResultsProcessor
|
|
from game.unitmap import UnitMap
|
|
|
|
if TYPE_CHECKING:
|
|
from game import Game
|
|
|
|
|
|
class MissionSimulation:
|
|
def __init__(self, game: Game) -> None:
|
|
self.game = game
|
|
self.unit_map: Optional[UnitMap] = None
|
|
self.time = game.conditions.start_time
|
|
|
|
def run(self) -> None:
|
|
sim = AircraftSimulation(self.game)
|
|
sim.run()
|
|
self.time = sim.time
|
|
|
|
def generate_miz(self, output: Path) -> None:
|
|
self.unit_map = MissionGenerator(self.game, self.time).generate_miz(output)
|
|
|
|
def debrief_current_state(
|
|
self, state_path: Path, force_end: bool = False
|
|
) -> Debriefing:
|
|
if self.unit_map is None:
|
|
raise RuntimeError(
|
|
"Simulation has no unit map. Results processing began before a mission "
|
|
"was generated."
|
|
)
|
|
|
|
with state_path.open("r", encoding="utf-8") as state_file:
|
|
data = json.load(state_file)
|
|
if force_end:
|
|
data["mission_ended"] = True
|
|
return Debriefing(data, self.game, self.unit_map)
|
|
|
|
def process_results(self, debriefing: Debriefing) -> None:
|
|
if self.unit_map is None:
|
|
raise RuntimeError(
|
|
"Simulation has no unit map. Results processing began before a mission "
|
|
"was generated."
|
|
)
|
|
|
|
MissionResultsProcessor(self.game).commit(debriefing)
|
|
|
|
def finish(self) -> None:
|
|
self.unit_map = None
|