Minor cleanup of notification system.

This commit is contained in:
Dan Albert 2021-09-05 21:14:18 -07:00
parent 12ad4fbf63
commit 18336f58d3
3 changed files with 18 additions and 48 deletions

View File

@ -8,7 +8,6 @@ from dcs.task import Task
from game import persistency from game import persistency
from game.debriefing import Debriefing from game.debriefing import Debriefing
from game.infos.information import Information
from game.operation.operation import Operation from game.operation.operation import Operation
from game.theater import ControlPoint from game.theater import ControlPoint
from gen.ato import AirTaskingOrder from gen.ato import AirTaskingOrder
@ -173,13 +172,10 @@ class Event:
def commit_building_losses(self, debriefing: Debriefing) -> None: def commit_building_losses(self, debriefing: Debriefing) -> None:
for loss in debriefing.building_losses: for loss in debriefing.building_losses:
loss.ground_object.kill() loss.ground_object.kill()
self.game.informations.append( self.game.message(
Information( "Building destroyed",
"Building destroyed", f"{loss.ground_object.dcs_identifier} has been destroyed at "
f"{loss.ground_object.dcs_identifier} has been destroyed at " f"location {loss.ground_object.obj_name}",
f"location {loss.ground_object.obj_name}",
self.game.turn,
)
) )
@staticmethod @staticmethod
@ -191,19 +187,16 @@ class Event:
for captured in debriefing.base_captures: for captured in debriefing.base_captures:
try: try:
if captured.captured_by_player: if captured.captured_by_player:
info = Information( self.game.message(
f"{captured.control_point} captured!", f"{captured.control_point} captured!",
f"We took control of {captured.control_point}.", f"We took control of {captured.control_point}.",
self.game.turn,
) )
else: else:
info = Information( self.game.message(
f"{captured.control_point} lost!", f"{captured.control_point} lost!",
f"The enemy took control of {captured.control_point}.", f"The enemy took control of {captured.control_point}.",
self.game.turn,
) )
self.game.informations.append(info)
captured.control_point.capture(self.game, captured.captured_by_player) captured.control_point.capture(self.game, captured.captured_by_player)
logging.info(f"Will run redeploy for {captured.control_point}") logging.info(f"Will run redeploy for {captured.control_point}")
self.redeploy_units(captured.control_point) self.redeploy_units(captured.control_point)
@ -330,34 +323,28 @@ class Event:
# Handle the case where there are no casualties at all on either side but both sides still have units # Handle the case where there are no casualties at all on either side but both sides still have units
if delta == 0.0: if delta == 0.0:
print(status_msg) print(status_msg)
info = Information( self.game.message(
"Frontline Report", "Frontline Report",
f"Our ground forces from {cp.name} reached a stalemate with enemy forces from {enemy_cp.name}.", f"Our ground forces from {cp.name} reached a stalemate with enemy forces from {enemy_cp.name}.",
self.game.turn,
) )
self.game.informations.append(info)
else: else:
if player_won: if player_won:
print(status_msg) print(status_msg)
cp.base.affect_strength(delta) cp.base.affect_strength(delta)
enemy_cp.base.affect_strength(-delta) enemy_cp.base.affect_strength(-delta)
info = Information( self.game.message(
"Frontline Report", "Frontline Report",
f"Our ground forces from {cp.name} are making progress toward {enemy_cp.name}. {status_msg}", f"Our ground forces from {cp.name} are making progress toward {enemy_cp.name}. {status_msg}",
self.game.turn,
) )
self.game.informations.append(info)
else: else:
print(status_msg) print(status_msg)
enemy_cp.base.affect_strength(delta) enemy_cp.base.affect_strength(delta)
cp.base.affect_strength(-delta) cp.base.affect_strength(-delta)
info = Information( self.game.message(
"Frontline Report", "Frontline Report",
f"Our ground forces from {cp.name} are losing ground against the enemy forces from " f"Our ground forces from {cp.name} are losing ground against the enemy forces from "
f"{enemy_cp.name}. {status_msg}", f"{enemy_cp.name}. {status_msg}",
self.game.turn,
) )
self.game.informations.append(info)
def redeploy_units(self, cp: ControlPoint) -> None: def redeploy_units(self, cp: ControlPoint) -> None:
""" " """ "
@ -410,10 +397,8 @@ class Event:
total_units_redeployed += move_count total_units_redeployed += move_count
if total_units_redeployed > 0: if total_units_redeployed > 0:
text = ( self.game.message(
"Units redeployed",
f"{total_units_redeployed} units have been redeployed from " f"{total_units_redeployed} units have been redeployed from "
f"{source.name} to {destination.name}" f"{source.name} to {destination.name}",
) )
info = Information("Units redeployed", text, self.game.turn)
self.game.informations.append(info)
logging.info(text)

View File

@ -105,8 +105,8 @@ class Game:
self.game_stats = GameStats() self.game_stats = GameStats()
self.notes = "" self.notes = ""
self.ground_planners: dict[int, GroundPlanner] = {} self.ground_planners: dict[int, GroundPlanner] = {}
self.informations = [] self.informations: list[Information] = []
self.informations.append(Information("Game Start", "-" * 40, 0)) self.message("Game Start", "-" * 40)
# Culling Zones are for areas around points of interest that contain things we may not wish to cull. # Culling Zones are for areas around points of interest that contain things we may not wish to cull.
self.__culling_zones: List[Point] = [] self.__culling_zones: List[Point] = []
self.__destroyed_units: list[dict[str, Union[float, str]]] = [] self.__destroyed_units: list[dict[str, Union[float, str]]] = []
@ -269,9 +269,7 @@ class Game:
Args: Args:
skipped: True if the turn was skipped. skipped: True if the turn was skipped.
""" """
self.informations.append( self.message("End of turn #" + str(self.turn), "-" * 40)
Information("End of turn #" + str(self.turn), "-" * 40, 0)
)
self.turn += 1 self.turn += 1
# The coalition-specific turn finalization *must* happen before unit deliveries, # The coalition-specific turn finalization *must* happen before unit deliveries,
@ -404,8 +402,8 @@ class Game:
gplanner.plan_groundwar() gplanner.plan_groundwar()
self.ground_planners[cp.id] = gplanner self.ground_planners[cp.id] = gplanner
def message(self, text: str) -> None: def message(self, title: str, text: str = "") -> None:
self.informations.append(Information(text, turn=self.turn)) self.informations.append(Information(title, text, turn=self.turn))
@property @property
def current_turn_time_of_day(self) -> TimeOfDay: def current_turn_time_of_day(self) -> TimeOfDay:

View File

@ -22,7 +22,6 @@ from dcs.forcedoptions import ForcedOptions
import qt_ui.uiconstants as CONST import qt_ui.uiconstants as CONST
from game.game import Game from game.game import Game
from game.infos.information import Information
from game.settings import Settings, AutoAtoBehavior from game.settings import Settings, AutoAtoBehavior
from qt_ui.widgets.QLabeledWidget import QLabeledWidget from qt_ui.widgets.QLabeledWidget import QLabeledWidget
from qt_ui.widgets.spinsliders import TenthsSpinSlider, TimeInputs from qt_ui.widgets.spinsliders import TenthsSpinSlider, TimeInputs
@ -894,18 +893,6 @@ class QSettingsWindow(QDialog):
def cheatMoney(self, amount): def cheatMoney(self, amount):
logging.info("CHEATING FOR AMOUNT : " + str(amount) + "M") logging.info("CHEATING FOR AMOUNT : " + str(amount) + "M")
self.game.blue.budget += amount self.game.blue.budget += amount
if amount > 0:
self.game.informations.append(
Information(
"CHEATER",
"You are a cheater and you should feel bad",
self.game.turn,
)
)
else:
self.game.informations.append(
Information("CHEATER", "You are still a cheater !", self.game.turn)
)
GameUpdateSignal.get_instance().updateGame(self.game) GameUpdateSignal.get_instance().updateGame(self.game)
def applySettings(self): def applySettings(self):