dcs-retribution/game/missiongenerator/environmentgenerator.py
Raffson d1b484f560
Support for auto-fog
implemented as a setting...
2024-12-26 02:51:58 +01:00

54 lines
2.1 KiB
Python

from datetime import datetime
from typing import Optional
from dcs.mission import Mission
from game.weather.atmosphericconditions import AtmosphericConditions
from game.weather.clouds import Clouds
from game.weather.conditions import Conditions
from game.weather.fog import Fog
from game.weather.wind import WindConditions
class EnvironmentGenerator:
def __init__(
self, mission: Mission, conditions: Conditions, time: datetime, auto_fog: bool
) -> None:
self.mission = mission
self.conditions = conditions
self.time = time
self.auto_fog = auto_fog
def set_atmospheric(self, atmospheric: AtmosphericConditions) -> None:
self.mission.weather.qnh = atmospheric.qnh.mm_hg
self.mission.weather.season_temperature = atmospheric.temperature_celsius
self.mission.weather.turbulence_at_ground = int(atmospheric.turbulence_per_10cm)
def set_clouds(self, clouds: Optional[Clouds]) -> None:
if clouds is None:
return
self.mission.weather.clouds_base = clouds.base
self.mission.weather.clouds_thickness = clouds.thickness
self.mission.weather.clouds_density = clouds.density
self.mission.weather.clouds_iprecptns = clouds.precipitation
self.mission.weather.clouds_preset = clouds.preset
def set_fog(self, fog: Optional[Fog]) -> None:
self.mission.weather.auto_fog = self.auto_fog
if fog is None:
return
self.mission.weather.fog_visibility = int(fog.visibility.meters)
self.mission.weather.fog_thickness = fog.thickness
def set_wind(self, wind: WindConditions) -> None:
self.mission.weather.wind_at_ground = wind.at_0m
self.mission.weather.wind_at_2000 = wind.at_2000m
self.mission.weather.wind_at_8000 = wind.at_8000m
def generate(self) -> None:
self.mission.start_time = self.time
self.set_atmospheric(self.conditions.weather.atmospheric)
self.set_clouds(self.conditions.weather.clouds)
self.set_fog(self.conditions.weather.fog)
self.set_wind(self.conditions.weather.wind)