Allow skill level selection

This commit is contained in:
Mr.Alien 2024-05-17 18:29:36 +02:00 committed by Spencer Shepard
parent 2b108d7746
commit b898b4dbdd
7 changed files with 101 additions and 28 deletions

View File

@ -1,6 +1,7 @@
import json import json
import dcs.installation import dcs.installation
import dcs.unit
import yaml import yaml
import sys import sys
import os import os
@ -14,7 +15,6 @@ import logging
import requests import requests
from packaging import version as ver from packaging import version as ver
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QApplication, QDialog, QMainWindow, QMessageBox, QCheckBox, QSpinBox, QSplashScreen, QFileDialog, QRadioButton, QApplication, QDialog, QMainWindow, QMessageBox, QCheckBox, QSpinBox, QSplashScreen, QFileDialog, QRadioButton,
QInputDialog, QDialogButtonBox, QVBoxLayout, QLabel, QComboBox QInputDialog, QDialogButtonBox, QVBoxLayout, QLabel, QComboBox
@ -104,6 +104,10 @@ defenders_text = "Defending Forces:"
attackers_text = "Attacking Forces:" attackers_text = "Attacking Forces:"
ratings_json = None ratings_json = None
skillNameList = ["From Template", "Average", "Good", "High", "Excellent", "Random"]
skillValueList = [None, dcs.unit.Skill.Average, dcs.unit.Skill.Good, dcs.unit.Skill.High, dcs.unit.Skill.Excellent, dcs.unit.Skill.Random]
logger.info("RotorOps v" + version.version_string) logger.info("RotorOps v" + version.version_string)
logger.info("pydcs DCS installation directory: " + dcs.installation.get_dcs_install_directory()) logger.info("pydcs DCS installation directory: " + dcs.installation.get_dcs_install_directory())
logger.info("pydcs DCS saved games directory: " + dcs.installation.get_dcs_saved_games_directory()) logger.info("pydcs DCS saved games directory: " + dcs.installation.get_dcs_saved_games_directory())
@ -323,6 +327,9 @@ class Window(QMainWindow, Ui_MainWindow):
for forces in self.forces_list: for forces in self.forces_list:
self.redforces_comboBox.addItem(forces.name) self.redforces_comboBox.addItem(forces.name)
self.blueforces_comboBox.addItem(forces.name) self.blueforces_comboBox.addItem(forces.name)
for skill in skillNameList:
self.redforces_skill_comboBox.addItem(skill)
self.blueforces_skill_comboBox.addItem(skill)
def getImports(self): def getImports(self):
self.imports_list = [] self.imports_list = []
@ -617,6 +624,8 @@ class Window(QMainWindow, Ui_MainWindow):
red_forces = self.forces_list[self.redforces_comboBox.currentIndex()] red_forces = self.forces_list[self.redforces_comboBox.currentIndex()]
blue_forces = self.forces_list[self.blueforces_comboBox.currentIndex()] blue_forces = self.forces_list[self.blueforces_comboBox.currentIndex()]
red_forces_skill = skillValueList[self.redforces_skill_comboBox.currentIndex()]
blue_forces_skill = skillValueList[self.blueforces_skill_comboBox.currentIndex()]
scenario_name = self.scenario.name scenario_name = self.scenario.name
scenario_path = self.scenario.path scenario_path = self.scenario.path
@ -637,6 +646,8 @@ class Window(QMainWindow, Ui_MainWindow):
"scenario_name": scenario_name, "scenario_name": scenario_name,
"red_forces_path": red_forces.path, "red_forces_path": red_forces.path,
"blue_forces_path": blue_forces.path, "blue_forces_path": blue_forces.path,
"red_forces_skill": red_forces_skill,
"blue_forces_skill": blue_forces_skill,
"red_quantity": self.redqty_spinBox.value(), "red_quantity": self.redqty_spinBox.value(),
"blue_quantity": self.blueqty_spinBox.value(), "blue_quantity": self.blueqty_spinBox.value(),
"inf_spawn_qty": self.inf_spawn_spinBox.value(), "inf_spawn_qty": self.inf_spawn_spinBox.value(),

View File

@ -49,7 +49,7 @@ class Ui_MainWindow(object):
self.advanced_defenses_checkBox.setFont(font) self.advanced_defenses_checkBox.setFont(font)
self.advanced_defenses_checkBox.setObjectName("advanced_defenses_checkBox") self.advanced_defenses_checkBox.setObjectName("advanced_defenses_checkBox")
self.red_forces_label = QtWidgets.QLabel(self.centralwidget) self.red_forces_label = QtWidgets.QLabel(self.centralwidget)
self.red_forces_label.setGeometry(QtCore.QRect(470, 80, 171, 27)) self.red_forces_label.setGeometry(QtCore.QRect(470, 80, 81, 27))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(10) font.setPointSize(10)
font.setBold(False) font.setBold(False)
@ -87,7 +87,7 @@ class Ui_MainWindow(object):
self.defense_checkBox.setCheckable(True) self.defense_checkBox.setCheckable(True)
self.defense_checkBox.setObjectName("defense_checkBox") self.defense_checkBox.setObjectName("defense_checkBox")
self.redqty_spinBox = QtWidgets.QSpinBox(self.centralwidget) self.redqty_spinBox = QtWidgets.QSpinBox(self.centralwidget)
self.redqty_spinBox.setGeometry(QtCore.QRect(1070, 80, 51, 31)) self.redqty_spinBox.setGeometry(QtCore.QRect(1090, 80, 51, 31))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(12) font.setPointSize(12)
self.redqty_spinBox.setFont(font) self.redqty_spinBox.setFont(font)
@ -97,7 +97,7 @@ class Ui_MainWindow(object):
self.redqty_spinBox.setProperty("value", 2) self.redqty_spinBox.setProperty("value", 2)
self.redqty_spinBox.setObjectName("redqty_spinBox") self.redqty_spinBox.setObjectName("redqty_spinBox")
self.redforces_comboBox = QtWidgets.QComboBox(self.centralwidget) self.redforces_comboBox = QtWidgets.QComboBox(self.centralwidget)
self.redforces_comboBox.setGeometry(QtCore.QRect(660, 80, 391, 33)) self.redforces_comboBox.setGeometry(QtCore.QRect(560, 80, 391, 33))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
@ -130,14 +130,14 @@ class Ui_MainWindow(object):
self.scenario_label_5.setAlignment(QtCore.Qt.AlignCenter) self.scenario_label_5.setAlignment(QtCore.Qt.AlignCenter)
self.scenario_label_5.setObjectName("scenario_label_5") self.scenario_label_5.setObjectName("scenario_label_5")
self.blue_forces_label = QtWidgets.QLabel(self.centralwidget) self.blue_forces_label = QtWidgets.QLabel(self.centralwidget)
self.blue_forces_label.setGeometry(QtCore.QRect(470, 30, 161, 27)) self.blue_forces_label.setGeometry(QtCore.QRect(470, 30, 81, 27))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(10) font.setPointSize(10)
font.setBold(False) font.setBold(False)
self.blue_forces_label.setFont(font) self.blue_forces_label.setFont(font)
self.blue_forces_label.setObjectName("blue_forces_label") self.blue_forces_label.setObjectName("blue_forces_label")
self.blueqty_spinBox = QtWidgets.QSpinBox(self.centralwidget) self.blueqty_spinBox = QtWidgets.QSpinBox(self.centralwidget)
self.blueqty_spinBox.setGeometry(QtCore.QRect(1070, 30, 51, 31)) self.blueqty_spinBox.setGeometry(QtCore.QRect(1090, 30, 51, 31))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(12) font.setPointSize(12)
self.blueqty_spinBox.setFont(font) self.blueqty_spinBox.setFont(font)
@ -147,7 +147,7 @@ class Ui_MainWindow(object):
self.blueqty_spinBox.setProperty("value", 3) self.blueqty_spinBox.setProperty("value", 3)
self.blueqty_spinBox.setObjectName("blueqty_spinBox") self.blueqty_spinBox.setObjectName("blueqty_spinBox")
self.blueforces_comboBox = QtWidgets.QComboBox(self.centralwidget) self.blueforces_comboBox = QtWidgets.QComboBox(self.centralwidget)
self.blueforces_comboBox.setGeometry(QtCore.QRect(660, 30, 391, 33)) self.blueforces_comboBox.setGeometry(QtCore.QRect(560, 30, 391, 33))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(9) font.setPointSize(9)
font.setBold(False) font.setBold(False)
@ -486,9 +486,25 @@ class Ui_MainWindow(object):
icon1.addPixmap(QtGui.QPixmap("resources/floppy-disk.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon1.addPixmap(QtGui.QPixmap("resources/floppy-disk.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.saveConfigButton.setIcon(icon1) self.saveConfigButton.setIcon(icon1)
self.saveConfigButton.setObjectName("saveConfigButton") self.saveConfigButton.setObjectName("saveConfigButton")
self.blueforces_skill_comboBox = QtWidgets.QComboBox(self.centralwidget)
self.blueforces_skill_comboBox.setGeometry(QtCore.QRect(960, 31, 120, 33))
font = QtGui.QFont()
font.setPointSize(9)
font.setBold(False)
font.setWeight(50)
self.blueforces_skill_comboBox.setFont(font)
self.blueforces_skill_comboBox.setObjectName("blueforces_skill_comboBox")
self.redforces_skill_comboBox = QtWidgets.QComboBox(self.centralwidget)
self.redforces_skill_comboBox.setGeometry(QtCore.QRect(960, 80, 120, 33))
font = QtGui.QFont()
font.setPointSize(9)
font.setBold(False)
font.setWeight(50)
self.redforces_skill_comboBox.setFont(font)
self.redforces_skill_comboBox.setObjectName("redforces_skill_comboBox")
MainWindow.setCentralWidget(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 24)) self.menubar.setGeometry(QtCore.QRect(0, 0, 1280, 21))
self.menubar.setObjectName("menubar") self.menubar.setObjectName("menubar")
self.menuMap = QtWidgets.QMenu(self.menubar) self.menuMap = QtWidgets.QMenu(self.menubar)
self.menuMap.setObjectName("menuMap") self.menuMap.setObjectName("menuMap")

View File

@ -102,7 +102,7 @@
<rect> <rect>
<x>470</x> <x>470</x>
<y>80</y> <y>80</y>
<width>171</width> <width>81</width>
<height>27</height> <height>27</height>
</rect> </rect>
</property> </property>
@ -215,7 +215,7 @@ p, li { white-space: pre-wrap; }
<widget class="QSpinBox" name="redqty_spinBox"> <widget class="QSpinBox" name="redqty_spinBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>1070</x> <x>1090</x>
<y>80</y> <y>80</y>
<width>51</width> <width>51</width>
<height>31</height> <height>31</height>
@ -245,7 +245,7 @@ p, li { white-space: pre-wrap; }
<widget class="QComboBox" name="redforces_comboBox"> <widget class="QComboBox" name="redforces_comboBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>660</x> <x>560</x>
<y>80</y> <y>80</y>
<width>391</width> <width>391</width>
<height>33</height> <height>33</height>
@ -334,7 +334,7 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>470</x> <x>470</x>
<y>30</y> <y>30</y>
<width>161</width> <width>81</width>
<height>27</height> <height>27</height>
</rect> </rect>
</property> </property>
@ -351,7 +351,7 @@ p, li { white-space: pre-wrap; }
<widget class="QSpinBox" name="blueqty_spinBox"> <widget class="QSpinBox" name="blueqty_spinBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>1070</x> <x>1090</x>
<y>30</y> <y>30</y>
<width>51</width> <width>51</width>
<height>31</height> <height>31</height>
@ -381,7 +381,7 @@ p, li { white-space: pre-wrap; }
<widget class="QComboBox" name="blueforces_comboBox"> <widget class="QComboBox" name="blueforces_comboBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>660</x> <x>560</x>
<y>30</y> <y>30</y>
<width>391</width> <width>391</width>
<height>33</height> <height>33</height>
@ -1401,6 +1401,40 @@ p, li { white-space: pre-wrap; }
<normaloff>resources/floppy-disk.png</normaloff>resources/floppy-disk.png</iconset> <normaloff>resources/floppy-disk.png</normaloff>resources/floppy-disk.png</iconset>
</property> </property>
</widget> </widget>
<widget class="QComboBox" name="blueforces_skill_comboBox">
<property name="geometry">
<rect>
<x>960</x>
<y>31</y>
<width>120</width>
<height>33</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
</widget>
<widget class="QComboBox" name="redforces_skill_comboBox">
<property name="geometry">
<rect>
<x>960</x>
<y>80</y>
<width>120</width>
<height>33</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
</widget>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
@ -1408,7 +1442,7 @@ p, li { white-space: pre-wrap; }
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1280</width> <width>1280</width>
<height>24</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuMap"> <widget class="QMenu" name="menuMap">

View File

@ -32,9 +32,9 @@ class ImportObjects:
def getHelicopters(self): def getHelicopters(self):
return self.helicopters return self.helicopters
def copyAll(self, mission, dest_country_name, dest_name, dest_point=None, dest_heading=0, start_type=None): def copyAll(self, mission, dest_country_name, dest_name, dest_point=None, dest_heading=0, start_type=None, skill=None):
return self.copyStatics(mission, dest_country_name, dest_name, dest_point, dest_heading), \ return self.copyStatics(mission, dest_country_name, dest_name, dest_point, dest_heading), \
self.copyVehicles(mission, dest_country_name, dest_name, dest_point, dest_heading), \ self.copyVehicles(mission, dest_country_name, dest_name, dest_point, dest_heading, skill), \
self.copyHelicopters(mission, dest_country_name, dest_name, dest_point, dest_heading, start_type) self.copyHelicopters(mission, dest_country_name, dest_name, dest_point, dest_heading, start_type)
def anchorByGroupName(self, group_name): def anchorByGroupName(self, group_name):
@ -107,7 +107,7 @@ class ImportObjects:
return new_groups return new_groups
def copyVehicles(self, mission, dest_country_name, dest_name, dest_point=None, dest_heading=0): def copyVehicles(self, mission, dest_country_name, dest_name, dest_point=None, dest_heading=0, skill=None):
logger.info("Copying " + str(len(self.vehicles)) + " vehicle groups as " + dest_name) logger.info("Copying " + str(len(self.vehicles)) + " vehicle groups as " + dest_name)
new_groups = [] new_groups = []
@ -129,6 +129,8 @@ class ImportObjects:
# ng.units[0].livery_id = group.units[0].livery_id # ng.units[0].livery_id = group.units[0].livery_id
ng.units[0].name = dest_name + " " + group.units[i].name ng.units[0].name = dest_name + " " + group.units[i].name
if skill:
ng.units[0].skill = skill
new_groups.append(ng) new_groups.append(ng)
else: else:
@ -138,6 +140,8 @@ class ImportObjects:
u.position = group.units[i].position u.position = group.units[i].position
u.heading = group.units[i].heading u.heading = group.units[i].heading
# u.livery_id = group.units[i].livery_id # u.livery_id = group.units[i].livery_id
if skill:
u.skill = skill
ng.add_unit(u) ng.add_unit(u)
return new_groups return new_groups
@ -196,7 +200,7 @@ class ImportObjects:
return new_groups return new_groups
def copyVehiclesAsGroup(self, mission, dest_country_name, dest_name, dest_point, dest_heading=0): def copyVehiclesAsGroup(self, mission, dest_country_name, dest_name, dest_point, dest_heading=0, skill=None):
logger.info("Copying " + str(len(self.vehicles)) + " vehicle groups as single group name: " + dest_name) logger.info("Copying " + str(len(self.vehicles)) + " vehicle groups as single group name: " + dest_name)
new_group = None new_group = None
@ -216,6 +220,8 @@ class ImportObjects:
unit_count = unit_count + 1 unit_count = unit_count + 1
# new_group.units[0].livery_id = group.units[0].livery_id # new_group.units[0].livery_id = group.units[0].livery_id
new_group.units[0].name = dest_name + " " + group.units[i].name new_group.units[0].name = dest_name + " " + group.units[i].name
if skill:
new_group.units[0].skill = skill
else: else:
@ -226,6 +232,8 @@ class ImportObjects:
u.heading = group.units[i].heading u.heading = group.units[i].heading
# u.livery_id = group.units[i].livery_id # u.livery_id = group.units[i].livery_id
if skill:
u.skill = skill
new_group.add_unit(u) new_group.add_unit(u)
unit_count = unit_count + 1 unit_count = unit_count + 1

View File

@ -194,7 +194,7 @@ class RotorOpsMission:
for zone_name in self.red_zones: for zone_name in self.red_zones:
if red_forces["vehicles"]: if red_forces["vehicles"]:
self.addGroundGroups(self.red_zones[zone_name], self.m.country(jtf_red), red_forces["vehicles"], self.addGroundGroups(self.red_zones[zone_name], self.m.country(jtf_red), red_forces["vehicles"],
options["red_quantity"]) options["red_quantity"], options["red_forces_skill"])
if options["zone_farps"] != "farp_never" and not options["defending"]: if options["zone_farps"] != "farp_never" and not options["defending"]:
helicopters = False helicopters = False
@ -238,7 +238,7 @@ class RotorOpsMission:
for i, zone_name in enumerate(self.blue_zones): for i, zone_name in enumerate(self.blue_zones):
if blue_forces["vehicles"]: if blue_forces["vehicles"]:
self.addGroundGroups(self.blue_zones[zone_name], self.m.country(jtf_blue), blue_forces["vehicles"], self.addGroundGroups(self.blue_zones[zone_name], self.m.country(jtf_blue), blue_forces["vehicles"],
options["blue_quantity"]) options["blue_quantity"], options["blue_forces_skill"])
# Add blue zone FARPS (not late activated) for defensive mode # Add blue zone FARPS (not late activated) for defensive mode
if options["zone_farps"] != "farp_never" and options["defending"]: if options["zone_farps"] != "farp_never" and options["defending"]:
@ -447,10 +447,10 @@ class RotorOpsMission:
if copy_vehicles: if copy_vehicles:
if vehicles_single_group: if vehicles_single_group:
vehicle_group = i.copyVehiclesAsGroup(self.m, country, vehicles_name, position, vehicle_group = i.copyVehiclesAsGroup(self.m, country, vehicles_name, position,
heading) heading, options["blue_forces_skill"] if country == jtf_blue else options["red_forces_skill"] )
else: else:
i.copyVehicles(self.m, country, vehicles_name, i.copyVehicles(self.m, country, vehicles_name,
position, heading) position, heading, options["blue_forces_skill"] if country == jtf_blue else options["red_forces_skill"] )
# Add client helicopters and farp objects # Add client helicopters and farp objects
if copy_helicopters: if copy_helicopters:
@ -461,7 +461,7 @@ class RotorOpsMission:
return vehicle_group # for setting properties such as late activation return vehicle_group # for setting properties such as late activation
def addGroundGroups(self, zone, _country, groups, quantity): def addGroundGroups(self, zone, _country, groups, quantity, skill):
for a in range(0, quantity): for a in range(0, quantity):
group = random.choice(groups) group = random.choice(groups)
@ -470,7 +470,7 @@ class RotorOpsMission:
if dcs.vehicles.vehicle_map[unit.type]: if dcs.vehicles.vehicle_map[unit.type]:
unit_types.append(dcs.vehicles.vehicle_map[unit.type]) unit_types.append(dcs.vehicles.vehicle_map[unit.type])
country = self.m.country(_country.name) country = self.m.country(_country.name)
self.m.vehicle_group_platoon( ng = self.m.vehicle_group_platoon(
country, country,
zone.name + '-GND ' + str(a + 1), zone.name + '-GND ' + str(a + 1),
unit_types, unit_types,
@ -478,6 +478,9 @@ class RotorOpsMission:
heading=random.randint(0, 359), heading=random.randint(0, 359),
formation=dcs.unitgroup.VehicleGroup.Formation.Scattered, formation=dcs.unitgroup.VehicleGroup.Formation.Scattered,
) )
if skill:
for unit in ng.units:
unit.skill = skill
def getCoalitionAirports(self, side: str): def getCoalitionAirports(self, side: str):
coalition_airports = [] coalition_airports = []

View File

@ -110,7 +110,8 @@ def getUnitsFromMiz(file, side='both'):
source_mission = dcs.mission.Mission() source_mission = dcs.mission.Mission()
try: #try:
if True:
source_mission.load_file(file) source_mission.load_file(file)
if side == 'both': if side == 'both':
sides = ['red', 'blue'] sides = ['red', 'blue']
@ -144,8 +145,8 @@ def getUnitsFromMiz(file, side='both'):
return forces return forces
except: #except:
logger.error("Failed to load units from " + file) # logger.error("Failed to load units from " + file)
def getDefaultLoadouts(): def getDefaultLoadouts():
print("Getting default loadouts") print("Getting default loadouts")

Binary file not shown.