Fixed logging issues and SEAD flights departing without waiting.

This commit is contained in:
Khopa 2020-06-22 23:20:14 +02:00
parent 56cf6bdaa4
commit 93a4463f22
10 changed files with 94 additions and 58 deletions

View File

@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from game.db import REWARDS, PLAYER_BUDGET_BASE
from game.db import REWARDS, PLAYER_BUDGET_BASE, sys
from game.game_stats import GameStats
from gen.flights.ai_flight_planner import FlightPlanner
from gen.ground_forces.ai_ground_planner import GroundPlanner

View File

@ -363,7 +363,7 @@ class AircraftConflictGenerator:
group.task = SEAD.name
self._setup_group(group, SEAD, flight.client_count)
group.points[0].tasks.clear()
#group.points[0].tasks.append(SEADTaskAction())
group.points[0].tasks.append(NoTask())
group.points[0].tasks.append(OptReactOnThreat(OptReactOnThreat.Values.EvadeFire))
group.points[0].tasks.append(OptROE(OptROE.Values.OpenFire))
group.points[0].tasks.append(OptRestrictJettison(True))
@ -423,7 +423,7 @@ class AircraftConflictGenerator:
elif point.waypoint_type == FlightWaypointType.INGRESS_SEAD:
tgroup = self.m.find_group(point.targetGroup.group_identifier)
if group is not None:
if tgroup is not None:
task = AttackGroup(tgroup.id)
task.params["expend"] = "All"
task.params["attackQtyLimit"] = False

View File

@ -39,36 +39,60 @@ class BriefingGenerator:
return
flight_unit_name = db.unit_type_name(flight.unit_type)
self.description += 2 * "\n" + "-" * 50 + "\n"
self.description += "-" * 50 + "\n"
self.description += flight_unit_name + " x " + str(flight.count) + 2 * "\n"
self.description += "#0 -- TAKEOFF : Take off\n"
self.description += "#0 -- TAKEOFF : Take off from " + flight.from_cp.name + "\n"
for i, wpt in enumerate(flight.points):
self.description += "#" + str(1+i) + " -- " + wpt.name + " : " + wpt.description + "\n"
self.description += "#" + str(len(flight.points) + 1) + " -- RTB\n"
self.description += "-" * 50 + "\n"
def add_ally_flight_description(self, flight):
if flight.client_count == 0:
flight_unit_name = db.unit_type_name(flight.unit_type)
self.description += flight.flight_type.name + " " + flight_unit_name + " x " + str(flight.count) + ", departing in " + str(flight.scheduled_in) + " minutes \n"
def generate(self):
self.description = ""
self.description += "DCS Liberation turn #" + str(self.game.turn) + "\n"
self.description += "-"*50 + "\n"
self.description += "=" * 15 + "\n\n"
self.description += "Current situation:\n"
self.description += "=" * 15 + "\n\n"
self.description += "\n"*2
self.description += "Your flights:" + "\n"
self.description += "=" * 15 + "\n\n"
for planner in self.game.planners.values():
for flight in planner.flights:
self.add_flight_description(flight)
self.description += "\n"*2
self.description += "Planned ally flights:" + "\n"
self.description += "=" * 15 + "\n"
for planner in self.game.planners.values():
if planner.from_cp.captured and len(planner.flights) > 0:
self.description += "\nFrom " + planner.from_cp.full_name + " \n"
self.description += "-" * 50 + "\n\n"
for flight in planner.flights:
self.add_ally_flight_description(flight)
if self.freqs:
self.description += "\n\nComms Frequencies:\n"
self.description += "-" * 50 + "\n"
self.description += "=" * 15 + "\n"
for name, freq in self.freqs:
self.description += "\n{}: {}".format(name, freq)
self.description += "\n" + ("-" * 50) + "\n"
self.description += "{}: {}\n".format(name, freq)
self.description += ("-" * 50) + "\n"
for cp in self.game.theater.controlpoints:
if cp.captured and cp.cptype in [ControlPointType.LHA_GROUP, ControlPointType.AIRCRAFT_CARRIER_GROUP]:
self.description += cp.name + " TACAN : "
self.description += cp.name + "\n"
self.description += "TACAN : "
self.description += str(cp.tacanN)
if cp.tacanY:

View File

@ -1,3 +1,9 @@
from userdata import logging_config
# Logging setup
VERSION_STRING = "2.0RC7"
logging_config.init_logging(VERSION_STRING)
import logging
import os
import sys
@ -11,7 +17,7 @@ from qt_ui import uiconstants
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
from qt_ui.windows.QLiberationWindow import QLiberationWindow
from qt_ui.windows.preferences.QLiberationFirstStartWindow import QLiberationFirstStartWindow
from userdata import liberation_install, persistency, logging_config
from userdata import liberation_install, persistency
if __name__ == "__main__":
@ -21,9 +27,8 @@ if __name__ == "__main__":
with open("./resources/stylesheets/style.css") as stylesheet:
app.setStyleSheet(stylesheet.read())
# Logging setup
VERSION_STRING = "2.0RC7"
logging_config.init_logging(VERSION_STRING)
# Inject custom payload in pydcs framework
custom_payloads = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..\\resources\\customized_payloads")

View File

@ -1,3 +1,4 @@
import logging
import sys
import webbrowser
@ -163,12 +164,12 @@ class QLiberationWindow(QMainWindow):
wizard.accepted.connect(lambda: self.onGameGenerated(wizard.generatedGame))
def saveGame(self):
print("Saving game")
logging.info("Saving game")
persistency.save_game(self.game)
GameUpdateSignal.get_instance().updateGame(self.game)
def onGameGenerated(self, game: Game):
print("On Game generated")
logging.info("On Game generated")
self.game = game
GameUpdateSignal.get_instance().updateGame(self.game)
@ -198,7 +199,7 @@ class QLiberationWindow(QMainWindow):
about.setWindowTitle("About DCS Liberation")
about.setIcon(QMessageBox.Icon.Information)
about.setText(text)
print(about.textFormat())
logging.info(about.textFormat())
about.exec_()
def showLiberationDialog(self):
@ -206,6 +207,6 @@ class QLiberationWindow(QMainWindow):
self.subwindow.show()
def onDebriefing(self, debrief: DebriefingSignal):
print("On Debriefing")
logging.info("On Debriefing")
self.debriefing = QDebriefingWindow(debrief.debriefing, debrief.gameEvent, debrief.game)
self.debriefing.show()

View File

@ -1,12 +1,10 @@
import typing
from dcs.mission import *
from dcs.terrain import *
from theater.nevada import *
from theater.persiangulf import *
from theater.caucasus import *
from theater.controlpoint import *
from theater.nevada import *
def find_ground_location(near, theater, max, min) -> typing.Optional[Point]:
for _ in range(500):
@ -24,7 +22,7 @@ for cp in theater.enemy_points():
for _ in range(0, random.randrange(3, 6)):
p = find_ground_location(cp.position, theater, 120000, 5000)
if not p:
print("Didn't find ground location for {}".format(cp))
logging.info("Didn't find ground location for {}".format(cp))
continue
mission.flight_group_inflight(

View File

@ -119,12 +119,12 @@ def generate_groundobjects(theater: ConflictTheater, game):
for i in range(random.randint(3,6)):
print("GENERATE BASE DEFENSE")
logging.info("GENERATE BASE DEFENSE")
point = find_location(True, cp.position, theater, 1000, 2800, [], True)
print(point)
logging.info(point)
if point is None:
print("Couldn't find point for {} base defense".format(cp))
logging.info("Couldn't find point for {} base defense".format(cp))
continue
group_id = group_id + 1
@ -143,10 +143,10 @@ def generate_groundobjects(theater: ConflictTheater, game):
generate_airbase_defense_group(i, g, faction_name, game, cp)
cp.ground_objects.append(g)
print("---------------------------")
print("CP Generation : " + cp.name)
logging.info("---------------------------")
logging.info("CP Generation : " + cp.name)
for ground_object in cp.ground_objects:
print(ground_object.groups)
logging.info(ground_object.groups)
if "boat" in db.FACTIONS[faction_name].keys():
@ -159,7 +159,7 @@ def generate_groundobjects(theater: ConflictTheater, game):
point = find_location(False, cp.position, theater, 5000, 40000, [], False)
if point is None:
print("Couldn't find point for {} ships".format(cp))
logging.info("Couldn't find point for {} ships".format(cp))
continue
group_id = group_id + 1
@ -192,7 +192,7 @@ def generate_groundobjects(theater: ConflictTheater, game):
point = find_location(True, cp.position, theater, 2500, 40000, [], False)
if point is None:
print("Couldn't find point for {} missiles".format(cp))
logging.info("Couldn't find point for {} missiles".format(cp))
continue
group_id = group_id + 1
@ -218,9 +218,9 @@ def generate_groundobjects(theater: ConflictTheater, game):
def generate_airbase_defense_group(airbase_defense_group_id, ground_obj:TheaterGroundObject, faction, game, cp):
print("GENERATE AIR DEFENSE GROUP")
print(faction)
print(airbase_defense_group_id)
logging.info("GENERATE AIR DEFENSE GROUP")
logging.info(faction)
logging.info(airbase_defense_group_id)
if airbase_defense_group_id == 0:
group = generate_armor_group(faction, game, ground_obj)
@ -337,7 +337,7 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat
point = find_location(tpl_category != "oil", cp.position, theater, 10000, 40000, cp.ground_objects)
if point is None:
print("Couldn't find point for {}".format(cp))
logging.info("Couldn't find point for {}".format(cp))
continue
object_id = 0

View File

@ -36,11 +36,15 @@ class Debriefing:
self.weapons_fired = state_data["weapons_fired"]
self.mission_ended = state_data["mission_ended"]
print(self.base_capture_events)
print(self.killed_aircrafts)
print(self.killed_ground_units)
print(self.weapons_fired)
print(self.mission_ended)
logging.info("--------------------------------")
logging.info("Starting Debriefing preprocessing")
logging.info("--------------------------------")
logging.info(self.base_capture_events)
logging.info(self.killed_aircrafts)
logging.info(self.killed_ground_units)
logging.info(self.weapons_fired)
logging.info(self.mission_ended)
logging.info("--------------------------------")
self.player_country_id = db.country_id_from_name(game.player_country)
self.enemy_country_id = db.country_id_from_name(game.enemy_country)
@ -59,7 +63,7 @@ class Debriefing:
if type is not None:
self.dead_aircraft.append(aircraft)
except Exception as e:
print(e)
logging.error(e)
for unit in self.killed_ground_units:
try:
@ -70,13 +74,14 @@ class Debriefing:
if type is not None:
self.dead_units.append(unit)
except Exception as e:
print(e)
logging.error(e)
for unit in self.killed_ground_units:
for cp in game.theater.controlpoints:
print(cp.name)
print(cp.captured)
logging.info(cp.name)
logging.info(cp.captured)
if cp.captured:
country = self.player_country_id
else:
@ -84,8 +89,8 @@ class Debriefing:
player_unit = (country == self.player_country_id)
for i, ground_object in enumerate(cp.ground_objects):
print(unit)
print(ground_object.string_identifier)
logging.info(unit)
logging.info(ground_object.string_identifier)
if ground_object.matches_string_identifier(unit):
unit = DebriefingDeadUnitInfo(country, player_unit, ground_object.dcs_identifier)
self.dead_buildings.append(unit)
@ -103,10 +108,10 @@ class Debriefing:
self.player_dead_buildings = [a for a in self.dead_buildings if a.country_id == self.player_country_id]
self.enemy_dead_buildings = [a for a in self.dead_buildings if a.country_id == self.enemy_country_id]
print(self.player_dead_aircraft)
print(self.enemy_dead_aircraft)
print(self.player_dead_units)
print(self.enemy_dead_units)
logging.info(self.player_dead_aircraft)
logging.info(self.enemy_dead_aircraft)
logging.info(self.player_dead_units)
logging.info(self.enemy_dead_units)
self.player_dead_aircraft_dict = {}
for a in self.player_dead_aircraft:
@ -150,13 +155,15 @@ class Debriefing:
else:
self.enemy_dead_buildings_dict[a.type] = 1
print("DEBRIEFING PRE PROCESS")
print(self.player_dead_aircraft_dict)
print(self.enemy_dead_aircraft_dict)
print(self.player_dead_units_dict)
print(self.enemy_dead_units_dict)
print(self.player_dead_buildings_dict)
print(self.enemy_dead_buildings_dict)
logging.info("--------------------------------")
logging.info("Debriefing pre process results :")
logging.info("--------------------------------")
logging.info(self.player_dead_aircraft_dict)
logging.info(self.enemy_dead_aircraft_dict)
logging.info(self.player_dead_units_dict)
logging.info(self.enemy_dead_units_dict)
logging.info(self.player_dead_buildings_dict)
logging.info(self.enemy_dead_buildings_dict)
def _poll_new_debriefing_log(callback: typing.Callable, game):

View File

@ -7,6 +7,7 @@ def init_logging(version_string):
if not os.path.isdir("./logs"):
os.mkdir("logs")
logging.basicConfig(level="DEBUG")
logger = logging.getLogger()
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')

View File

@ -42,7 +42,7 @@ def restore_game():
save = pickle.load(f)
return save
except:
print("Invalid Save game")
logging.error("Invalid Save game")
return None