From 2557383946354e644fd0c6f35e256ab8e7910554 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 22 Nov 2020 13:25:22 -0800 Subject: [PATCH 1/2] Fix type of default map visibility setting. The UI sets these to the proper enum types; only the default is wrong. Fix the default and clean up the associated code. Note that this does minorly break save compatibility and alters default behavior, since previously we were ignoring the default option. Ignoring the default looks unintentional since there is no explicit "don't force this option" setting in the UI. Existing saves can be fixed simply by changing this option to something else and then back. --- game/settings.py | 4 +++- gen/forcedoptionsgen.py | 27 +++++++-------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/game/settings.py b/game/settings.py index 1e54c1b4..8bcf53b6 100644 --- a/game/settings.py +++ b/game/settings.py @@ -1,6 +1,8 @@ from dataclasses import dataclass, field from typing import Dict, Optional +from dcs.forcedoptions import ForcedOptions + @dataclass class Settings: @@ -15,7 +17,7 @@ class Settings: player_skill: str = "Good" enemy_skill: str = "Average" enemy_vehicle_skill: str = "Average" - map_coalition_visibility: str = "All Units" + map_coalition_visibility: ForcedOptions.Views = ForcedOptions.Views.All labels: str = "Full" only_player_takeoff: bool = True # Legacy parameter do not use night_disabled: bool = False diff --git a/gen/forcedoptionsgen.py b/gen/forcedoptionsgen.py index dff54bc4..65e213b5 100644 --- a/gen/forcedoptionsgen.py +++ b/gen/forcedoptionsgen.py @@ -1,17 +1,14 @@ from __future__ import annotations -import logging -from typing import TYPE_CHECKING from enum import IntEnum +from typing import TYPE_CHECKING from dcs.mission import Mission -from dcs.forcedoptions import ForcedOptions - -from .conflictgen import * if TYPE_CHECKING: from game.game import Game + class Labels(IntEnum): Off = 0 Full = 1 @@ -20,28 +17,18 @@ class Labels(IntEnum): class ForcedOptionsGenerator: - def __init__(self, mission: Mission, game: Game): + def __init__(self, mission: Mission, game: Game) -> None: self.mission = mission self.game = game - def _set_options_view(self): + def _set_options_view(self) -> None: + self.mission.forced_options.options_view = self.game.settings.map_coalition_visibility - if self.game.settings.map_coalition_visibility == ForcedOptions.Views.All: - self.mission.forced_options.options_view = ForcedOptions.Views.All - elif self.game.settings.map_coalition_visibility == ForcedOptions.Views.Allies: - self.mission.forced_options.options_view = ForcedOptions.Views.Allies - elif self.game.settings.map_coalition_visibility == ForcedOptions.Views.OnlyAllies: - self.mission.forced_options.options_view = ForcedOptions.Views.OnlyAllies - elif self.game.settings.map_coalition_visibility == ForcedOptions.Views.MyAircraft: - self.mission.forced_options.options_view = ForcedOptions.Views.MyAircraft - elif self.game.settings.map_coalition_visibility == ForcedOptions.Views.OnlyMap: - self.mission.forced_options.options_view = ForcedOptions.Views.OnlyMap - - def _set_external_views(self): + def _set_external_views(self) -> None: if not self.game.settings.external_views_allowed: self.mission.forced_options.external_views = self.game.settings.external_views_allowed - def _set_labels(self): + def _set_labels(self) -> None: if self.game.settings.labels == "Abbreviated": self.mission.forced_options.labels = int(Labels.Abbreviated) elif self.game.settings.labels == "Dot Only": From 17b0cee50720bfa9203504112cb6070fec75dd92 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 22 Nov 2020 13:25:04 -0800 Subject: [PATCH 2/2] Add unrestricted SATNAV support to factions. Enabled for bluefor modern, since they ought to have GPS but seemingly don't. This change does nothing until https://github.com/pydcs/dcs/pull/102 lands and we update to it. --- game/factions/faction.py | 11 +++++++++++ gen/forcedoptionsgen.py | 10 +++++++--- resources/factions/bluefor_modern.json | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/game/factions/faction.py b/game/factions/faction.py index b0caf4bb..45071530 100644 --- a/game/factions/faction.py +++ b/game/factions/faction.py @@ -108,6 +108,15 @@ class Faction: # List of default livery overrides liveries_overrides: Dict[UnitType, List[str]] = field(default_factory=dict) + #: Set to True if the faction should force the "Unrestricted satnav" option + #: for the mission. This option enables GPS for capable aircraft regardless + #: of the time period or operator. For example, the CJTF "countries" don't + #: appear to have GPS capability, so they need this. + #: + #: Note that this option cannot be set per-side. If either faction needs it, + #: both will use it. + unrestricted_satnav: bool = False + @classmethod def from_json(cls: Type[Faction], json: Dict[str, Any]) -> Faction: @@ -194,6 +203,8 @@ class Faction: if k is not None: faction.liveries_overrides[k] = [s.lower() for s in v] + faction.unrestricted_satnav = json.get("unrestricted_satnav", False) + return faction @property diff --git a/gen/forcedoptionsgen.py b/gen/forcedoptionsgen.py index 65e213b5..bccf981a 100644 --- a/gen/forcedoptionsgen.py +++ b/gen/forcedoptionsgen.py @@ -36,10 +36,14 @@ class ForcedOptionsGenerator: elif self.game.settings.labels == "Off": self.mission.forced_options.labels = int(Labels.Off) + def _set_unrestricted_satnav(self) -> None: + blue = self.game.player_faction + red = self.game.enemy_faction + if blue.unrestricted_satnav or red.unrestricted_satnav: + self.mission.forced_options.unrestricted_satnav = True + def generate(self): self._set_options_view() self._set_external_views() self._set_labels() - - - \ No newline at end of file + self._set_unrestricted_satnav() diff --git a/resources/factions/bluefor_modern.json b/resources/factions/bluefor_modern.json index 49e2e1cf..eb913019 100644 --- a/resources/factions/bluefor_modern.json +++ b/resources/factions/bluefor_modern.json @@ -96,5 +96,6 @@ "ArleighBurkeGroupGenerator" ], "has_jtac": true, - "jtac_unit": "MQ_9_Reaper" + "jtac_unit": "MQ_9_Reaper", + "unrestricted_satnav": true }