Dan'ts notes

commit 35ab9103cebf823bab85fbb1c9ff4bc2b9c5701a
Author: walterroach <37820425+walterroach@users.noreply.github.com>
Date:   Fri Oct 30 22:25:42 2020 -0500

    more cleanup

commit d3d008bc6b29f328ad48063bd4b0520e1b819d68
Author: walterroach <37820425+walterroach@users.noreply.github.com>
Date:   Fri Oct 30 22:17:59 2020 -0500

    More briefinggen cleanup

commit b2033f091d7191aecefb86fecb5cb060c074706e
Author: walterroach <37820425+walterroach@users.noreply.github.com>
Date:   Fri Oct 30 22:08:48 2020 -0500

    briefinggen cleanup

commit 72ea0196c22d9493df078765800f3fafb9c054dc
Author: walterroach <37820425+walterroach@users.noreply.github.com>
Date:   Fri Oct 30 21:57:52 2020 -0500

    Add notifier method back to Operation

commit efd39a9e03d02b9d581637d0d1c289af68e749c3
Author: walterroach <37820425+walterroach@users.noreply.github.com>
Date:   Fri Oct 30 21:34:37 2020 -0500

    Revert "Move kneeboard and briefing gen to unified"
    Removes properties added to Operation
    This reverts commit 941f2af77074d79b992ae859a0108b67aac5460c.
This commit is contained in:
walterroach 2020-10-30 22:27:02 -05:00 committed by Dan Albert
parent 6a6133e5cd
commit 3dc7dc3d1a
5 changed files with 75 additions and 74 deletions

View File

@ -35,7 +35,4 @@ class FrontlineAttackOperation(Operation):
conflict=conflict)
def generate(self):
## TODO: What are these for?
# self.briefinggen.title = "Frontline CAS"
# self.briefinggen.description = "Provide CAS for the ground forces attacking enemy lines. Operation will be considered successful if total number of enemy units will be lower than your own by a factor of 1.5 (i.e. with 12 units from both sides, enemy forces need to be reduced to at least 8), meaning that you (and, probably, your wingmans) should concentrate on destroying the enemy units. Target base strength will be lowered as a result. Be advised that your flight will not attack anything until you explicitly tell them so by comms menu."
super(FrontlineAttackOperation, self).generate()

View File

@ -47,6 +47,7 @@ class Operation:
airsupportgen = None # type: AirSupportConflictGenerator
visualgen = None # type: VisualGenerator
groundobjectgen = None # type: GroundObjectsGenerator
briefinggen = None # type: BriefingGenerator
forcedoptionsgen = None # type: ForcedOptionsGenerator
radio_registry: Optional[RadioRegistry] = None
tacan_registry: Optional[TacanRegistry] = None
@ -75,7 +76,6 @@ class Operation:
self.to_cp = to_cp
self.is_quick = False
self.plugin_scripts: List[str] = []
self.subscribed_generators = [KneeboardGenerator, BriefingGenerator]
def units_of(self, country_name: str) -> List[UnitType]:
return []
@ -90,6 +90,7 @@ class Operation:
def initialize(self, mission: Mission, conflict: Conflict):
self.current_mission = mission
self.conflict = conflict
# self.briefinggen = BriefingGenerator(self.current_mission, self.game) Is it safe to remove this, or does it also break save compat?
def prepare(self, terrain: Terrain, is_quick: bool):
with open("resources/default_options.lua", "r") as f:
@ -164,25 +165,34 @@ class Operation:
trigger.add_action(DoScriptFile(fileref))
self.current_mission.triggerrules.triggers.append(trigger)
def notify_subscribed_generators(self):
'''Generates subscribed MissionInfoGenerator objects (currently kneeboards and briefings)
'''
gens: List[MissionInfoGenerator] = [gen(self.current_mission, game=self.game) for gen in self.subscribed_generators]
def notify_info_generators(
self,
groundobjectgen: GroundObjectsGenerator,
airsupportgen: AirSupportConflictGenerator,
jtacs: List[JtacInfo],
airgen: AircraftConflictGenerator,
):
"""Generates subscribed MissionInfoGenerator objects (currently kneeboards and briefings)
"""
gens: List[MissionInfoGenerator] = [
KneeboardGenerator(self.current_mission, self.game),
BriefingGenerator(self.current_mission, self.game)
]
for gen in gens:
for dynamic_runway in self.groundobjectgen.runways.values():
for dynamic_runway in groundobjectgen.runways.values():
gen.add_dynamic_runway(dynamic_runway)
for tanker in self.airsupportgen.air_support.tankers:
for tanker in airsupportgen.air_support.tankers:
gen.add_tanker(tanker)
if self.is_awacs_enabled:
for awacs in self.airsupportgen.air_support.awacs:
for awacs in airsupportgen.air_support.awacs:
gen.add_awacs(awacs)
for jtac in self.jtacs:
for jtac in jtacs:
gen.add_jtac(jtac)
for flight in self.airgen.flights:
for flight in airgen.flights:
gen.add_flight(flight)
gen.generate()
@ -221,14 +231,14 @@ class Operation:
# Generate ground object first
self.groundobjectgen = GroundObjectsGenerator(
groundobjectgen = GroundObjectsGenerator(
self.current_mission,
self.conflict,
self.game,
radio_registry,
tacan_registry
)
self.groundobjectgen.generate()
groundobjectgen.generate()
# Generate destroyed units
for d in self.game.get_destroyed_units():
@ -250,29 +260,29 @@ class Operation:
)
# Air Support (Tanker & Awacs)
self.airsupportgen = AirSupportConflictGenerator(
airsupportgen = AirSupportConflictGenerator(
self.current_mission, self.conflict, self.game, radio_registry,
tacan_registry)
self.airsupportgen.generate(self.is_awacs_enabled)
airsupportgen.generate(self.is_awacs_enabled)
# Generate Activity on the map
self.airgen = AircraftConflictGenerator(
airgen = AircraftConflictGenerator(
self.current_mission, self.conflict, self.game.settings, self.game,
radio_registry)
self.airgen.generate_flights(
airgen.generate_flights(
self.current_mission.country(self.game.player_country),
self.game.blue_ato,
self.groundobjectgen.runways
groundobjectgen.runways
)
self.airgen.generate_flights(
airgen.generate_flights(
self.current_mission.country(self.game.enemy_country),
self.game.red_ato,
self.groundobjectgen.runways
groundobjectgen.runways
)
# Generate ground units on frontline everywhere
self.jtacs: List[JtacInfo] = []
jtacs: List[JtacInfo] = []
for front_line in self.game.theater.conflicts(True):
player_cp = front_line.control_point_a
enemy_cp = front_line.control_point_b
@ -285,7 +295,7 @@ class Operation:
enemy_gp = self.game.ground_planners[enemy_cp.id].units_per_cp[player_cp.id]
groundConflictGen = GroundConflictGenerator(self.current_mission, conflict, self.game, player_gp, enemy_gp, player_cp.stances[enemy_cp.id])
groundConflictGen.generate()
self.jtacs.extend(groundConflictGen.jtacs)
jtacs.extend(groundConflictGen.jtacs)
# Setup combined arms parameters
self.current_mission.groundControl.pilot_can_control_vehicles = self.ca_slots > 0
@ -317,10 +327,10 @@ class Operation:
luaData["JTACs"] = {}
luaData["TargetPoints"] = {}
self.assign_channels_to_flights(self.airgen.flights,
self.airsupportgen.air_support)
self.assign_channels_to_flights(airgen.flights,
airsupportgen.air_support)
for tanker in self.airsupportgen.air_support.tankers:
for tanker in airsupportgen.air_support.tankers:
luaData["Tankers"][tanker.callsign] = {
"dcsGroupName": tanker.dcsGroupName,
"callsign": tanker.callsign,
@ -330,14 +340,14 @@ class Operation:
}
if self.is_awacs_enabled:
for awacs in self.airsupportgen.air_support.awacs:
for awacs in airsupportgen.air_support.awacs:
luaData["AWACs"][awacs.callsign] = {
"dcsGroupName": awacs.dcsGroupName,
"callsign": awacs.callsign,
"radio": awacs.freq.mhz
}
for jtac in self.jtacs:
for jtac in jtacs:
luaData["JTACs"][jtac.callsign] = {
"dcsGroupName": jtac.dcsGroupName,
"callsign": jtac.callsign,
@ -346,7 +356,7 @@ class Operation:
"laserCode": jtac.code
}
for flight in self.airgen.flights:
for flight in airgen.flights:
if flight.friendly and flight.flight_type in [FlightType.ANTISHIP, FlightType.DEAD, FlightType.SEAD, FlightType.STRIKE]:
flightType = flight.flight_type.name
flightTarget = flight.package.target
@ -467,11 +477,8 @@ dcsLiberation.TargetPoints = {
plugin.injectScripts(self)
plugin.injectConfiguration(self)
self.assign_channels_to_flights(self.airgen.flights,
self.airsupportgen.air_support)
# Generate kneeboard and briefing
self.notify_subscribed_generators()
self.assign_channels_to_flights(airgen.flights,
airsupportgen.air_support)
def assign_channels_to_flights(self, flights: List[FlightData],
air_support: AirSupport) -> None:

View File

@ -1,20 +1,19 @@
'''
"""
Briefing generation logic
'''
"""
from __future__ import annotations
import os
import random
import logging
from dataclasses import dataclass
from theater.frontline import FrontLine
from typing import List, Dict, TYPE_CHECKING, Optional
from typing import List, Dict, TYPE_CHECKING
from jinja2 import Environment, FileSystemLoader, select_autoescape
from dcs.mission import Mission
from .aircraft import FlightData
from .airsupportgen import AwacsInfo, TankerInfo
from .armor import JtacInfo
# from .conflictgen import Conflict
from theater import ControlPoint
from .ground_forces.combat_stance import CombatStance
from .radios import RadioFrequency
@ -23,7 +22,6 @@ from .runways import RunwayData
if TYPE_CHECKING:
from game import Game
@dataclass
class CommInfo:
"""Communications information for the kneeboard."""
@ -43,7 +41,7 @@ class FrontLineInfo:
@property
def _random_frontline_sentence(self) -> str:
'''Random sentences for start of situation briefing'''
"""Random sentences for start of situation briefing"""
templates = [
f"There are combats between {self.player_base.name} and {self.enemy_base.name}. ",
f"The war on the ground is still going on between {self.player_base.name} and {self.enemy_base.name}. ",
@ -55,22 +53,22 @@ class FrontLineInfo:
@property
def _zero_units_sentence(self) -> str:
'''Situation description if either side has zero units on a frontline'''
"""Situation description if either side has zero units on a frontline"""
if self.player_zero:
return ("We do not have a single vehicle available to hold our position. The situation is critical, "
f"and we will lose ground inevitably betweeen {self.player_base.name} and {self.enemy_base.name}")
elif self.enemy_zero:
return ("The enemy forces have been crushed, we will be able to make significant progress"
f" toward {self.enemy_base.name}.")
return ''
return ""
@property
def _advantage_description(self) -> str:
'''Situation description for when player has a numerical advantage
"""Situation description for when player has a numerical advantage
Returns:
str
'''
"""
if self.stance == CombatStance.AGGRESSIVE:
return (
"On this location, our ground forces will try to make "
@ -95,18 +93,18 @@ class FrontLineInfo:
)
# TODO: Write a situation description for player RETREAT stance
elif self.stance == CombatStance.RETREAT:
return ''
return ""
else:
logging.warning('Briefing did not receive a known CombatStance')
return ''
logging.warning("Briefing did not receive a known CombatStance")
return ""
@property
def _disadvantage_description(self) -> str:
'''Situation description for when player has a numerical disadvantage
"""Situation description for when player has a numerical disadvantage
Returns:
str
'''
"""
if self.stance == CombatStance.AGGRESSIVE:
return (
"On this location, our ground forces will try an audacious "
@ -131,18 +129,18 @@ class FrontLineInfo:
)
# TODO: Write a situation description for player RETREAT stance
elif self.stance == CombatStance.RETREAT:
return ''
return ""
else:
logging.warning('Briefing did not receive a known CombatStance')
return ''
logging.warning("Briefing did not receive a known CombatStance")
return ""
@property
def brief(self) -> str:
'''Situation briefing string
"""Situation briefing string
Returns:
str
'''
"""
if self._zero_units_sentence:
return self._zero_units_sentence
situation = self._random_frontline_sentence
@ -159,7 +157,7 @@ class MissionInfoGenerator:
Examples of subtypes include briefing generators, kneeboard generators, etc.
"""
def __init__(self, mission: Mission, game: 'Game') -> None:
def __init__(self, mission: Mission, game: Game) -> None:
self.mission = mission
self.game = game
self.awacs: List[AwacsInfo] = []
@ -212,11 +210,11 @@ class MissionInfoGenerator:
self.tankers.append(tanker)
def add_frontline(self, frontline: FrontLineInfo) -> None:
'''Adds a frontline to the briefing
"""Adds a frontline to the briefing
Arguments:
frontline {FrontLineInfo} -- [description]
'''
frontline: Frontline conflict information
"""
self.frontlines.append(frontline)
def add_dynamic_runway(self, runway: RunwayData) -> None:
@ -234,25 +232,24 @@ class MissionInfoGenerator:
class BriefingGenerator(MissionInfoGenerator):
def __init__(self, mission: Mission, game: 'Game'):
def __init__(self, mission: Mission, game: "Game"):
super().__init__(mission, game)
# self.conflict = conflict
self.title = ""
self.description = ""
self.allied_flights_by_departure: Dict[str, List[FlightData]] = {}
env = Environment(
loader=FileSystemLoader('resources/briefing/templates'),
loader=FileSystemLoader("resources/briefing/templates"),
autoescape=select_autoescape(
disabled_extensions=('txt'),
disabled_extensions=("txt"),
default_for_string=True,
default=True,
)
)
self.template = env.get_template('briefingtemplate_EN.j2')
self.template = env.get_template("briefingtemplate_EN.j2")
def generate(self) -> None:
'''Generate the mission briefing
'''
"""Generate the mission briefing
"""
self._generate_frontline_info()
self.generate_allied_flights_by_departure()
self.mission.set_description_text(self.template.render(vars(self)))
@ -260,15 +257,15 @@ class BriefingGenerator(MissionInfoGenerator):
"./resources/ui/splash_screen.png"))
def _generate_frontline_info(self) -> None:
'''Build FrontLineInfo objects from FrontLine type and append to briefing.
'''
"""Build FrontLineInfo objects from FrontLine type and append to briefing.
"""
for front_line in self.game.theater.conflicts(from_player=True):
self.add_frontline(FrontLineInfo(front_line))
# TODO: This should determine if runway is friendly through a method more robust than the existing string match
def generate_allied_flights_by_departure(self) -> None:
'''Create iterable to display allied flights grouped by departure airfield.
'''
"""Create iterable to display allied flights grouped by departure airfield.
"""
for flight in self.flights:
if not flight.client_units and flight.friendly:
name = flight.departure.airfield_name

View File

@ -311,7 +311,7 @@ class BriefingPage(KneeboardPage):
class KneeboardGenerator(MissionInfoGenerator):
"""Creates kneeboard pages for each client flight in the mission."""
def __init__(self, mission: Mission, game: 'Game') -> None:
def __init__(self, mission: Mission, game: "Game") -> None:
super().__init__(mission, game)
def generate(self) -> None:

View File

@ -14,8 +14,8 @@ class QGroundForcesStrategySelector(QComboBox):
self.cp.stances[enemy_cp.id] = CombatStance.DEFENSIVE
for i, stance in enumerate(CombatStance):
self.addItem(stance.name, userData=CombatStance(i))
if self.cp.stances[enemy_cp.id] == CombatStance(i):
self.addItem(stance.name, userData=stance)
if self.cp.stances[enemy_cp.id] == stance:
self.setCurrentIndex(i)
self.currentTextChanged.connect(self.on_change)