diff --git a/game/event/event.py b/game/event/event.py index 0c44c1d0..e55685e3 100644 --- a/game/event/event.py +++ b/game/event/event.py @@ -22,6 +22,10 @@ DIFFICULTY_LOG_BASE = 1.1 EVENT_DEPARTURE_MAX_DISTANCE = 340000 +MINOR_DEFEAT_INFLUENCE = 0.1 +DEFEAT_INFLUENCE = 0.3 +STRONG_DEFEAT_INFLUENCE = 0.5 + class Event: silent = False informational = False @@ -153,12 +157,14 @@ class Event: # ------------------------------ # Destroyed ground units + killed_unit_count_by_cp = {cp.id: 0 for cp in self.game.theater.controlpoints} cp_map = {cp.id: cp for cp in self.game.theater.controlpoints} for killed_ground_unit in debriefing.killed_ground_units: try: cpid = int(killed_ground_unit.split("|")[3]) type = db.unit_type_from_name(killed_ground_unit.split("|")[4]) if cpid in cp_map.keys(): + killed_unit_count_by_cp[cpid] = killed_unit_count_by_cp[cpid] + 1 cp = cp_map[cpid] if type in cp.base.armor.keys(): logging.info("Ground unit destroyed : " + str(type)) @@ -195,7 +201,6 @@ class Event: # ------------------------------ # Captured bases - if self.game.player_country in db.BLUEFOR_FACTIONS: coalition = 2 # Value in DCS mission event for BLUE else: @@ -225,6 +230,69 @@ class Event: except Exception as e: print(e) + # ----------------------------------- + # Compute damage to bases + for cp in self.game.theater.player_points(): + enemy_cps = [e for e in cp.connected_points if not e.captured] + for enemy_cp in enemy_cps: + print("Compute frontline progression for : " + cp.name + " to " + enemy_cp.name) + + delta = 0 + player_won = True + ally_casualties = killed_unit_count_by_cp[cp.id] + enemy_casualties = killed_unit_count_by_cp[enemy_cp.id] + ally_units_alive = cp.base.total_armor + enemy_units_alive = enemy_cp.base.total_armor + + print(ally_units_alive) + print(enemy_units_alive) + print(ally_casualties) + print(enemy_casualties) + + ratio = (1.0 + enemy_casualties) / (1.0 + ally_casualties) + + if ally_units_alive == 0: + player_won = False + delta = STRONG_DEFEAT_INFLUENCE + elif enemy_units_alive == 0: + player_won = True + delta = STRONG_DEFEAT_INFLUENCE + elif cp.stances[enemy_cp.id] == CombatStance.RETREAT: + player_won = False + delta = STRONG_DEFEAT_INFLUENCE + else: + if enemy_casualties > ally_casualties: + player_won = True + if cp.stances[enemy_cp.id] == CombatStance.BREAKTHROUGH: + delta = STRONG_DEFEAT_INFLUENCE + else: + if ratio > 3: + delta = STRONG_DEFEAT_INFLUENCE + elif ratio < 1.5: + delta = MINOR_DEFEAT_INFLUENCE + else: + delta = DEFEAT_INFLUENCE + elif ally_casualties > enemy_casualties: + player_won = False + if cp.stances[enemy_cp.id] == CombatStance.BREAKTHROUGH: + delta = STRONG_DEFEAT_INFLUENCE + else: + delta = STRONG_DEFEAT_INFLUENCE + + # No progress with defensive strategies + if player_won and cp.stances[enemy_cp.id] in [CombatStance.DEFENSIVE, CombatStance.AMBUSH]: + print("Defensive stance, no progress") + delta = 0 + + if player_won: + print(cp.name + " won ! factor > " + str(delta)) + cp.base.affect_strength(delta) + enemy_cp.base.affect_strength(-delta) + else: + print(enemy_cp.name + " won ! factor > " + str(delta)) + enemy_cp.base.affect_strength(delta) + cp.base.affect_strength(-delta) + def skip(self): pass diff --git a/game/event/frontlineattack.py b/game/event/frontlineattack.py index d9ec1359..9cd787d5 100644 --- a/game/event/frontlineattack.py +++ b/game/event/frontlineattack.py @@ -60,17 +60,6 @@ class FrontlineAttackEvent(Event): def commit(self, debriefing: Debriefing): super(FrontlineAttackEvent, self).commit(debriefing) - if self.from_cp.captured: - if self.is_successfull(debriefing): - self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) - else: - self.to_cp.base.affect_strength(+self.STRENGTH_INFLUENCE) - else: - if self.is_successfull(debriefing): - self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) - else: - self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) - def skip(self): if self.to_cp.captured: self.to_cp.base.affect_strength(-0.1) diff --git a/gen/armor.py b/gen/armor.py index 41dbafdb..9ce408b9 100644 --- a/gen/armor.py +++ b/gen/armor.py @@ -25,7 +25,7 @@ class GroundConflictGenerator: self.enemy_planned_combat_groups = enemy_planned_combat_groups self.player_planned_combat_groups = player_planned_combat_groups self.player_stance = CombatStance(player_stance) - self.enemy_stance = CombatStance.AGGRESIVE if len(enemy_planned_combat_groups) > len(player_planned_combat_groups) else CombatStance.DEFENSIVE + self.enemy_stance = random.choice([CombatStance.AGGRESIVE, CombatStance.AGGRESIVE, CombatStance.AGGRESIVE, CombatStance.ELIMINATION, CombatStance.BREAKTHROUGH]) if len(enemy_planned_combat_groups) > len(player_planned_combat_groups) else random.choice([CombatStance.DEFENSIVE, CombatStance.DEFENSIVE, CombatStance.DEFENSIVE, CombatStance.AMBUSH, CombatStance.AGGRESIVE]) self.game = game def _group_point(self, point) -> Point: @@ -283,7 +283,7 @@ class GroundConflictGenerator: while i < 25: # 25 attempt for valid position heading_diff = -90 if isplayer else 90 shifted = conflict_position[0].point_from_heading(self.conflict.heading, - random.randint(-combat_width / 2, combat_width / 2)) + random.randint((int)(-combat_width / 2), (int)(combat_width / 2))) final_position = shifted.point_from_heading(self.conflict.heading + heading_diff, distance_from_frontline) if self.conflict.theater.is_on_land(final_position): diff --git a/qt_ui/main.py b/qt_ui/main.py index b1778d12..374edb85 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -2,11 +2,10 @@ import logging import os import sys from shutil import copyfile -from time import sleep import dcs from PySide2.QtGui import QPixmap -from PySide2.QtWidgets import QApplication, QLabel, QSplashScreen +from PySide2.QtWidgets import QApplication, QSplashScreen from dcs import installation from qt_ui import uiconstants diff --git a/qt_ui/windows/QWaitingForMissionResultWindow.py b/qt_ui/windows/QWaitingForMissionResultWindow.py index 047a794b..bd880262 100644 --- a/qt_ui/windows/QWaitingForMissionResultWindow.py +++ b/qt_ui/windows/QWaitingForMissionResultWindow.py @@ -45,30 +45,30 @@ class QWaitingForMissionResultWindow(QDialog): def initUi(self): self.layout = QGridLayout() - self.gridLayout = QVBoxLayout() - self.gridLayout.addWidget(QLabel("You are clear for takeoff")) - self.gridLayout.addWidget(QLabel("")) - self.gridLayout.addWidget(QLabel("