mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
refactor frontline brief generation
This commit is contained in:
parent
0143e5641f
commit
6878b57fba
@ -90,8 +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.conflict, self.game)
|
||||
self.briefinggen = BriefingGenerator(self.current_mission, self.game)
|
||||
|
||||
def prepare(self, terrain: Terrain, is_quick: bool):
|
||||
with open("resources/default_options.lua", "r") as f:
|
||||
|
||||
@ -27,6 +27,110 @@ class CommInfo:
|
||||
name: str
|
||||
freq: RadioFrequency
|
||||
|
||||
class FrontLineInfo:
|
||||
def __init__(self, front_line: FrontLine):
|
||||
self.front_line: FrontLine = front_line
|
||||
self.player_base: ControlPoint = front_line.control_point_a
|
||||
self.enemy_base: ControlPoint = front_line.control_point_b
|
||||
self.player_zero: bool = self.player_base.base.total_armor == 0
|
||||
self.enemy_zero: bool = self.enemy_base.base.total_armor == 0
|
||||
self.advantage: bool = self.player_base.base.total_armor > self.enemy_base.base.total_armor
|
||||
self.stance: CombatStance = self.player_base.stances[self.enemy_base.id]
|
||||
|
||||
|
||||
@property
|
||||
def _random_frontline_sentence(self) -> str:
|
||||
'''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}. ",
|
||||
f"Our ground forces in {self.player_base.name} are opposed to enemy forces based in {self.enemy_base.name}. ",
|
||||
f"Our forces from {self.player_base.name} are fighting enemies based in {self.enemy_base.name}. ",
|
||||
f"There is an active frontline between {self.player_base.name} and {self.enemy_base.name}. ",
|
||||
]
|
||||
return random.choice(templates)
|
||||
|
||||
@property
|
||||
def _zero_units_sentence(self) -> str:
|
||||
'''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, and we will lose ground inevitably.")
|
||||
elif self.enemy_zero:
|
||||
return ("The enemy forces have been crushed, we will be able to make significant progress"
|
||||
f" toward {enemy_base.name}.")
|
||||
return None
|
||||
|
||||
@property
|
||||
def _advantage_description(self) -> str:
|
||||
'''Situation description for when player has numerical advantage on the frontline'''
|
||||
if self.stance == CombatStance.AGGRESSIVE:
|
||||
return (
|
||||
"On this location, our ground forces will try to make "
|
||||
"progress against the enemy. As the enemy is outnumbered, "
|
||||
"our forces should have no issue making progress."
|
||||
)
|
||||
elif self.stance == CombatStance.ELIMINATION:
|
||||
return (
|
||||
"On this location, our ground forces will focus on the destruction of enemy"
|
||||
f"assets, before attempting to make progress toward {enemy_base.name}. "
|
||||
"The enemy is already outnumbered, and this maneuver might draw a final "
|
||||
"blow to their forces."
|
||||
)
|
||||
elif self.stance == CombatStance.BREAKTHROUGH:
|
||||
return (
|
||||
"On this location, our ground forces will focus on progression toward "
|
||||
f"{enemy_base.name}."
|
||||
)
|
||||
elif self.stance in [CombatStance.DEFENSIVE, CombatStance.AMBUSH]:
|
||||
return (
|
||||
"On this location, our ground forces will hold position. We are not expecting an enemy assault."
|
||||
)
|
||||
# TODO: Write a situation description for player RETREAT stance
|
||||
elif self.stance == CombatStance.RETREAT:
|
||||
return ''
|
||||
else:
|
||||
logging.warning('Briefing did not receive a known CombatStance')
|
||||
|
||||
@property
|
||||
def _disadvantage_description(self):
|
||||
if self.stance == CombatStance.AGGRESSIVE:
|
||||
return (
|
||||
"On this location, our ground forces will try an audacious "
|
||||
"assault against enemies in superior numbers. The operation"
|
||||
" is risky, and the enemy might counter attack."
|
||||
)
|
||||
elif self.stance == CombatStance.ELIMINATION:
|
||||
return (
|
||||
"On this location, our ground forces will try an audacious assault against "
|
||||
"enemies in superior numbers. The operation is risky, and the enemy might "
|
||||
"counter attack.\n"
|
||||
)
|
||||
elif self.stance == CombatStance.BREAKTHROUGH:
|
||||
return (
|
||||
"On this location, our ground forces have been ordered to rush toward "
|
||||
f"{enemy_base.name}. Wish them luck... We are also expecting a counter attack."
|
||||
)
|
||||
elif self.stance in [CombatStance.DEFENSIVE, CombatStance.AMBUSH]:
|
||||
return (
|
||||
"On this location, our ground forces have been ordered to hold still, "
|
||||
"and defend against enemy attacks. An enemy assault might be iminent."
|
||||
)
|
||||
# TODO: Write a situation description for player RETREAT stance
|
||||
elif self.stance == CombatStance.RETREAT:
|
||||
return ''
|
||||
else:
|
||||
logging.warning('Briefing did not receive a known CombatStance')
|
||||
|
||||
@property
|
||||
def brief(self):
|
||||
if self._zero_units_sentence:
|
||||
return self._zero_units_sentence
|
||||
situation = self._random_frontline_sentence
|
||||
if self.advantage:
|
||||
situation += self._advantage_description
|
||||
else:
|
||||
situation += self._disadvantage_description
|
||||
class MissionInfoGenerator:
|
||||
"""Base type for generators of mission information for the player.
|
||||
|
||||
@ -122,13 +226,16 @@ class BriefingGenerator(MissionInfoGenerator):
|
||||
def generate(self):
|
||||
self._generate_frontline_info()
|
||||
self.generate_allied_flights_by_departure()
|
||||
with open('testgen.txt', 'w') as file:
|
||||
file.write(self.template.render(vars(self)))
|
||||
self.mission.set_description_text(self.template.render(vars(self)))
|
||||
self.mission.add_picture_blue(os.path.abspath(
|
||||
"./resources/ui/splash_screen.png"))
|
||||
|
||||
def _generate_frontline_info(self):
|
||||
for front_line in self.game.theater.conflicts(from_player=True):
|
||||
self.add_frontline(front_line)
|
||||
print(front_line.name)
|
||||
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:
|
||||
@ -139,109 +246,3 @@ class BriefingGenerator(MissionInfoGenerator):
|
||||
self.allied_flights_by_departure[name].append(flight)
|
||||
else:
|
||||
self.allied_flights_by_departure[name] = [flight]
|
||||
|
||||
@dataclass
|
||||
class FrontLineInfo:
|
||||
front_line: FrontLine
|
||||
description: str = FrontLine.name
|
||||
player_base: ControlPoint = FrontLine.control_point_a
|
||||
enemy_base: ControlPoint = FrontLine.control_point_b
|
||||
player_zero: bool = player_base.base.total_armor == 0
|
||||
enemy_zero: bool = enemy_base.base.total_armor == 0
|
||||
advantage: bool = player_base.base.total_armor > enemy_base.base.total_armor
|
||||
stance: CombatStance = player_base.stances[enemy_base.id]
|
||||
|
||||
|
||||
@property
|
||||
def _random_frontline_sentence(self) -> str:
|
||||
'''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}. ",
|
||||
f"Our ground forces in {self.player_base.name} are opposed to enemy forces based in {self.enemy_base.name}. ",
|
||||
f"Our forces from {self.player_base.name} are fighting enemies based in {self.enemy_base.name}. ",
|
||||
f"There is an active frontline between {self.player_base.name} and {self.enemy_base.name}. ",
|
||||
]
|
||||
return random.choice(templates)
|
||||
|
||||
@property
|
||||
def _zero_units_sentence(self) -> str:
|
||||
'''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, and we will lose ground inevitably.")
|
||||
elif self.enemy_zero:
|
||||
return ("The enemy forces have been crushed, we will be able to make significant progress"
|
||||
f" toward {enemy_base.name}.")
|
||||
|
||||
@property
|
||||
def _advantage_description(self) -> str:
|
||||
'''Situation description for when player has numerical advantage on the frontline'''
|
||||
if self.stance == CombatStance.AGGRESSIVE:
|
||||
return (
|
||||
"On this location, our ground forces will try to make "
|
||||
"progress against the enemy. As the enemy is outnumbered, "
|
||||
"our forces should have no issue making progress."
|
||||
)
|
||||
elif self.stance == CombatStance.ELIMINATION:
|
||||
return (
|
||||
"On this location, our ground forces will focus on the destruction of enemy"
|
||||
f"assets, before attempting to make progress toward {enemy_base.name}. "
|
||||
"The enemy is already outnumbered, and this maneuver might draw a final "
|
||||
"blow to their forces."
|
||||
)
|
||||
elif self.stance == CombatStance.BREAKTHROUGH:
|
||||
return (
|
||||
"On this location, our ground forces will focus on progression toward "
|
||||
f"{enemy_base.name}."
|
||||
)
|
||||
elif self.stance in [CombatStance.DEFENSIVE, CombatStance.AMBUSH]:
|
||||
return (
|
||||
"On this location, our ground forces will hold position. We are not expecting an enemy assault."
|
||||
)
|
||||
# TODO: Write a situation description for player RETREAT stance
|
||||
elif self.stance == CombatStance.RETREAT:
|
||||
return ''
|
||||
else:
|
||||
logging.warning('Briefing did not receive a known CombatStance')
|
||||
|
||||
@property
|
||||
def _disadvantage_description(self):
|
||||
if self.stance == CombatStance.AGGRESSIVE:
|
||||
return (
|
||||
"On this location, our ground forces will try an audacious "
|
||||
"assault against enemies in superior numbers. The operation"
|
||||
" is risky, and the enemy might counter attack."
|
||||
)
|
||||
elif self.stance == CombatStance.ELIMINATION:
|
||||
return (
|
||||
"On this location, our ground forces will try an audacious assault against "
|
||||
"enemies in superior numbers. The operation is risky, and the enemy might "
|
||||
"counter attack.\n"
|
||||
)
|
||||
elif self.stance == CombatStance.BREAKTHROUGH:
|
||||
return (
|
||||
"On this location, our ground forces have been ordered to rush toward "
|
||||
f"{enemy_base.name}. Wish them luck... We are also expecting a counter attack."
|
||||
)
|
||||
elif self.stance in [CombatStance.DEFENSIVE, CombatStance.AMBUSH]:
|
||||
return (
|
||||
"On this location, our ground forces have been ordered to hold still, "
|
||||
"and defend against enemy attacks. An enemy assault might be iminent."
|
||||
)
|
||||
# TODO: Write a situation description for player RETREAT stance
|
||||
elif self.stance == CombatStance.RETREAT:
|
||||
return ''
|
||||
else:
|
||||
logging.warning('Briefing did not receive a known CombatStance')
|
||||
|
||||
@property
|
||||
def brief(self):
|
||||
if self.player_zero:
|
||||
return self._zero_units_sentence
|
||||
|
||||
situation = self._zero_units_sentence
|
||||
if self.advantage:
|
||||
situation += self._advantage_description
|
||||
else:
|
||||
situation += self._disadvantage_description
|
||||
Loading…
x
Reference in New Issue
Block a user