diff --git a/Generator/RotorOpsImport.py b/Generator/RotorOpsImport.py index b0d91b3..a76c9c2 100644 --- a/Generator/RotorOpsImport.py +++ b/Generator/RotorOpsImport.py @@ -1,6 +1,7 @@ import math import dcs from MissionGenerator import logger +import RotorOpsUnits import os @@ -20,6 +21,7 @@ def __init__(self, mizfile): self.helicopters = [] self.extractUnits() + self.default_loadouts = RotorOpsUnits.getDefaultLoadouts() def getStatics(self): return self.statics @@ -140,6 +142,7 @@ def copyVehicles(self, mission, dest_country_name, dest_name, dest_point=None, d return new_groups + # This method applies the default player loadouts to the helicopters def copyHelicopters(self, mission, dest_country_name, dest_name, dest_point, dest_heading=0, start_type=None): logger.info("Copying " + str(len(self.helicopters)) + " helicopters as " + dest_name) @@ -185,12 +188,8 @@ def copyHelicopters(self, mission, dest_country_name, dest_name, dest_point, des ng.points[0].type = group.points[0].type ng.units[0].heading = group.units[0].heading ng.units[0].skill = group.units[0].skill - ng.units[0].livery_id = group.units[0].livery_id - ng.units[0].pylons = group.units[0].pylons ng.units[0].fuel = group.units[0].fuel - ng.units[0].gun = group.units[0].gun - ng.units[0].hardpoint_racks = group.units[0].hardpoint_racks - ng.frequency = group.frequency + RotorOpsUnits.applyLoadoutsToGroup(ng, self.default_loadouts) new_groups.append(ng) else: logger.warn("No pad unit (ie FARP, carrier) found, so can't add helicopters.") diff --git a/Generator/RotorOpsMission.py b/Generator/RotorOpsMission.py index f456e03..2838a10 100644 --- a/Generator/RotorOpsMission.py +++ b/Generator/RotorOpsMission.py @@ -80,52 +80,7 @@ def addResources(self, sound_directory, script_directory): logger.info("Adding script to mission: " + filename) self.scripts[filename] = self.m.map_resource.add_resource_file(filename) - def getUnitsFromMiz(self, file, side='both'): - - forces = {} - vehicles = [] - attack_helos = [] - transport_helos = [] - attack_planes = [] - fighter_planes = [] - helicopters = [] - - source_mission = dcs.mission.Mission() - - try: - source_mission.load_file(file) - if side == 'both': - sides = ['red', 'blue'] - else: - sides = [side] - for side in sides: - for country_name in source_mission.coalition.get(side).countries: - country_obj = source_mission.coalition.get(side).countries[country_name] - for vehicle_group in country_obj.vehicle_group: - vehicles.append(vehicle_group) - for helicopter_group in country_obj.helicopter_group: - helicopters.append(helicopter_group) - if helicopter_group.task == 'CAS': - attack_helos.append(helicopter_group) - elif helicopter_group.task == 'Transport': - transport_helos.append(helicopter_group) - for plane_group in country_obj.plane_group: - if plane_group.task == 'CAS': - attack_planes.append(plane_group) - elif plane_group.task == 'CAP': - fighter_planes.append(plane_group) - - forces["vehicles"] = vehicles - forces["attack_helos"] = attack_helos - forces["transport_helos"] = transport_helos - forces["attack_planes"] = attack_planes - forces["fighter_planes"] = fighter_planes - forces["helicopters"] = helicopters - - return forces - - except: - logger.error("Failed to load units from " + file) + def generateMission(self, window, options): @@ -166,8 +121,8 @@ def generateMission(self, window, options): self.addMods() self.importObjects(options) - red_forces = self.getUnitsFromMiz(options["red_forces_path"], "both") - blue_forces = self.getUnitsFromMiz(options["blue_forces_path"], "both") + red_forces = RotorOpsUnits.getUnitsFromMiz(options["red_forces_path"], "both") + blue_forces = RotorOpsUnits.getUnitsFromMiz(options["blue_forces_path"], "both") # add images to briefing if options["rotorops_server"]: @@ -648,6 +603,7 @@ def swapSides(self, options): def addPlayerHelos(self, options): client_helos = RotorOpsUnits.client_helos + default_loadouts = RotorOpsUnits.getDefaultLoadouts() unslotted_count = 0 slotted_count = 0 @@ -656,16 +612,6 @@ def addPlayerHelos(self, options): client_helos = [dcs.helicopters.helicopter_map[ helicopter]] # if our ui slot option matches a specific helicopter type name - # get loadouts from miz file and put into a simple dict - default_loadouts = {} - default_unit_groups = self.getUnitsFromMiz(directories.home_dir + "\\config\\blue_player_loadouts.miz", "blue") - for helicopter_group in default_unit_groups["helicopters"]: - default_loadouts[helicopter_group.units[0].unit_type.id] = {} - default_loadouts[helicopter_group.units[0].unit_type.id]["pylons"] = helicopter_group.units[0].pylons - default_loadouts[helicopter_group.units[0].unit_type.id]["livery_id"] = helicopter_group.units[0].livery_id - default_loadouts[helicopter_group.units[0].unit_type.id]["fuel"] = helicopter_group.units[0].fuel - default_loadouts[helicopter_group.units[0].unit_type.id]["frequency"] = helicopter_group.frequency - # find friendly carriers and farps carrier = self.m.country(jtf_blue).find_ship_group(name="HELO_CARRIER") if not carrier: @@ -770,19 +716,10 @@ def addPlayerHelos(self, options): if fg: slotted_count = slotted_count + 1 fg.units[0].set_client() - # fg.load_task_default_loadout(dcs.task.CAS) - if helotype.id in default_loadouts: - fg.units[0].pylons = default_loadouts[helotype.id]["pylons"] - fg.units[0].livery_id = default_loadouts[helotype.id]["livery_id"] - fg.units[0].fuel = default_loadouts[helotype.id]["fuel"] - fg.frequency = default_loadouts[helotype.id]["frequency"] - + RotorOpsUnits.applyLoadoutsToGroup(fg, default_loadouts) # setup wingman for single player if len(fg.units) == 2: fg.units[1].skill = dcs.unit.Skill.High - fg.units[1].pylons = fg.units[0].pylons - fg.units[1].livery_id = fg.units[0].livery_id - fg.units[1].fuel = fg.units[0].fuel else: logger.warn("No parking available for " + helotype.id) unslotted_count = unslotted_count + 1 @@ -1347,3 +1284,6 @@ def addSourceStatics(self, options): self.m.farp(self.m.country(jtf_blue), "FAT COW FARP " + str(i), insert_point.random_point_within(1000, 1000), hidden=True, dead=False, farp_type=dcs.unit.InvisibleFARP) + + + diff --git a/Generator/RotorOpsUnits.py b/Generator/RotorOpsUnits.py index 813b195..00f8957 100644 --- a/Generator/RotorOpsUnits.py +++ b/Generator/RotorOpsUnits.py @@ -1,5 +1,7 @@ import dcs import aircraftMods +from MissionGenerator import logger, directories + client_helos = [ dcs.helicopters.UH_1H, @@ -95,4 +97,87 @@ ] +def getUnitsFromMiz(file, side='both'): + forces = {} + vehicles = [] + attack_helos = [] + transport_helos = [] + attack_planes = [] + fighter_planes = [] + helicopters = [] + planes = [] + + source_mission = dcs.mission.Mission() + + try: + source_mission.load_file(file) + if side == 'both': + sides = ['red', 'blue'] + else: + sides = [side] + for side in sides: + for country_name in source_mission.coalition.get(side).countries: + country_obj = source_mission.coalition.get(side).countries[country_name] + for vehicle_group in country_obj.vehicle_group: + vehicles.append(vehicle_group) + for helicopter_group in country_obj.helicopter_group: + helicopters.append(helicopter_group) + if helicopter_group.task == 'CAS': + attack_helos.append(helicopter_group) + elif helicopter_group.task == 'Transport': + transport_helos.append(helicopter_group) + for plane_group in country_obj.plane_group: + planes.append(plane_group) + if plane_group.task == 'CAS': + attack_planes.append(plane_group) + elif plane_group.task == 'CAP': + fighter_planes.append(plane_group) + + forces["vehicles"] = vehicles + forces["attack_helos"] = attack_helos + forces["transport_helos"] = transport_helos + forces["attack_planes"] = attack_planes + forces["fighter_planes"] = fighter_planes + forces["helicopters"] = helicopters + forces["aircraft"] = planes + helicopters + + return forces + + except: + logger.error("Failed to load units from " + file) + +def getDefaultLoadouts(): + print("Getting default loadouts") + default_loadouts = {} + groups = getUnitsFromMiz(directories.home_dir + "\\config\\blue_player_loadouts.miz", "blue") + for group in groups["aircraft"]: + default_loadouts[group.units[0].unit_type.id] = {} + default_loadouts[group.units[0].unit_type.id]["pylons"] = group.units[0].pylons + default_loadouts[group.units[0].unit_type.id]["livery_id"] = group.units[0].livery_id + default_loadouts[group.units[0].unit_type.id]["group_frequency"] = group.frequency + if hasattr(group.units[0], "radio"): + default_loadouts[group.units[0].unit_type.id]["radio"] = group.units[0].radio + else: + logger.warn("No radios found in loadout for " + group.units[0].unit_type.id + ". Is it set as a client aircraft?") + default_loadouts[group.units[0].unit_type.id]["gun"] = group.units[0].gun + default_loadouts[group.units[0].unit_type.id]["hardpoint_racks"] = group.units[0].hardpoint_racks + return default_loadouts + +def applyLoadoutsToGroup(group, loadouts): + for unit in group.units: + if unit.unit_type.id not in loadouts: + logger.warn("No loadout found for " + unit.unit_type.id) + continue + + loadout = loadouts[unit.unit_type.id] + unit.pylons = loadout.get("pylons", unit.pylons) + unit.livery_id = loadout.get("livery_id", unit.livery_id) + group.frequency = loadout.get("group_frequency", group.frequency) + if hasattr(unit, "radio"): + unit.radio = loadout.get("radio", unit.radio) + else: + logger.warn("No radios to apply for " + unit.unit_type.id) + unit.gun = loadout.get("gun", unit.gun) + unit.hardpoint_racks = loadout.get("hardpoint_racks", unit.hardpoint_racks) + return group diff --git a/config/blue_player_loadouts.miz b/config/blue_player_loadouts.miz index 588fab2..19e3114 100644 Binary files a/config/blue_player_loadouts.miz and b/config/blue_player_loadouts.miz differ diff --git a/scripts/RotorOpsServer.lua b/scripts/RotorOpsServer.lua index 9a1e646..1974ab7 100644 --- a/scripts/RotorOpsServer.lua +++ b/scripts/RotorOpsServer.lua @@ -52,50 +52,6 @@ end RotorOpsServer.checkGameState() ---The following code for integrating the server bot spawn credits with PERKS works fine, but it needs to --- be moved to a server script so it's not dependent on this mission script. - --- function RotorOpsServer.convertPointsToSpawnCredits(playerName, points) --- if dcsbot then --- env.info("RotorOpsServer: Converting "..points.." points to spawn credits for "..playerName) --- dcsbot.addUserPoints(playerName, points) --- return true --- end --- return false --- end --- --- function RotorOpsServer.addPerks() --- env.info("RotorOpsServer: Adding perks to RotorOpsPerks.") --- ---- PERKS: Convert points to spawn credits ---- --- --- RotorOpsPerks.perks["spawnCredits"] = { --- perk_name='spawnCredits', --- display_name='Buy 100 Spawn Slot Credits', --- cost=100, --- cooldown=0, --- max_per_player=1000000, --- max_per_mission=1000000, --- at_mark=false, --- at_position=true, --- enabled=true, --- sides={0,1,2}, --- } --- --- RotorOpsPerks.perks.spawnCredits["action_function"] = function(args) --- local playerName = Unit.getByName(args.player_unit_name):getPlayerName() --- return RotorOpsServer.convertPointsToSpawnCredits(playerName, 100) --- end --- --- ---- End of Spawn Credits Perk ---- --- --- end --- --- if dcsbot then --- RotorOpsServer.addPerks() --- else --- env.warning("RotorOpsServer: DCSBot not found. Perks not added.") --- end -