From 200c13dc31b40a385102275c42e3d55a691a3ef6 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 21 Nov 2020 13:26:02 -0800 Subject: [PATCH 1/3] Remove dead code. --- resources/tools/generate_loadout_check.py | 35 ----------------------- 1 file changed, 35 deletions(-) delete mode 100644 resources/tools/generate_loadout_check.py diff --git a/resources/tools/generate_loadout_check.py b/resources/tools/generate_loadout_check.py deleted file mode 100644 index 21a6e997..00000000 --- a/resources/tools/generate_loadout_check.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -import sys -import dcs - -from game import db -from gen.aircraft import AircraftConflictGenerator - -dcs.planes.FlyingType.payload_dirs = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "..\\payloads")] - -mis = dcs.Mission(dcs.terrain.PersianGulf()) -pos = dcs.terrain.PersianGulf().khasab().position -airgen = AircraftConflictGenerator(mis, None, None, None) - -for t, uts in db.UNIT_BY_TASK.items(): - if t != dcs.task.CAP and t != dcs.task.CAS: - continue - - pos.y = dcs.terrain.PersianGulf().khasab().position.x - for t in t == dcs.task.CAP and [dcs.task.CAP, dcs.task.Escort] or [t]: - pos.x += 10000 - for ut in uts: - pos.y += 5000 - ctr = mis.country([v["country"] for k, v in db.FACTIONS.items() if ut in v.units][0]) - - g = mis.flight_group_inflight( - country=ctr, - name="{} - {}".format(t.name, ut), - aircraft_type=ut, - position=pos, - altitude=10000 - ) - g.task = t.name - airgen._setup_group(g, t, 0, {}) - -mis.save("loadout_test.miz") From 851c2d88a9cb4a3d814a7106a40c6e835e5cdd48 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 21 Nov 2020 13:30:43 -0800 Subject: [PATCH 2/3] Factor out Lua generation. --- game/operation/operation.py | 310 ++++++++++++++++++------------------ 1 file changed, 159 insertions(+), 151 deletions(-) diff --git a/game/operation/operation.py b/game/operation/operation.py index 1e01065b..57a70630 100644 --- a/game/operation/operation.py +++ b/game/operation/operation.py @@ -320,157 +320,7 @@ class Operation: if self.game.settings.perf_smoke_gen: visualgen.generate() - luaData = {} - luaData["AircraftCarriers"] = {} - luaData["Tankers"] = {} - luaData["AWACs"] = {} - luaData["JTACs"] = {} - luaData["TargetPoints"] = {} - - self.assign_channels_to_flights(airgen.flights, - airsupportgen.air_support) - - for tanker in airsupportgen.air_support.tankers: - luaData["Tankers"][tanker.callsign] = { - "dcsGroupName": tanker.dcsGroupName, - "callsign": tanker.callsign, - "variant": tanker.variant, - "radio": tanker.freq.mhz, - "tacan": str(tanker.tacan.number) + tanker.tacan.band.name - } - - if self.is_awacs_enabled: - for awacs in airsupportgen.air_support.awacs: - luaData["AWACs"][awacs.callsign] = { - "dcsGroupName": awacs.dcsGroupName, - "callsign": awacs.callsign, - "radio": awacs.freq.mhz - } - - for jtac in jtacs: - luaData["JTACs"][jtac.callsign] = { - "dcsGroupName": jtac.dcsGroupName, - "callsign": jtac.callsign, - "zone": jtac.region, - "dcsUnit": jtac.unit_name, - "laserCode": jtac.code - } - - for flight in airgen.flights: - if flight.friendly and flight.flight_type in [FlightType.ANTISHIP, FlightType.DEAD, FlightType.SEAD, FlightType.STRIKE]: - flightType = flight.flight_type.name - flightTarget = flight.package.target - if flightTarget: - flightTargetName = None - flightTargetType = None - if hasattr(flightTarget, 'obj_name'): - flightTargetName = flightTarget.obj_name - flightTargetType = flightType + f" TGT ({flightTarget.category})" - elif hasattr(flightTarget, 'name'): - flightTargetName = flightTarget.name - flightTargetType = flightType + " TGT (Airbase)" - luaData["TargetPoints"][flightTargetName] = { - "name": flightTargetName, - "type": flightTargetType, - "position": { "x": flightTarget.position.x, "y": flightTarget.position.y} - } - - # set a LUA table with data from Liberation that we want to set - # at the moment it contains Liberation's install path, and an overridable definition for the JTACAutoLase function - # later, we'll add data about the units and points having been generated, in order to facilitate the configuration of the plugin lua scripts - state_location = "[[" + os.path.abspath(".") + "]]" - lua = """ --- setting configuration table -env.info("DCSLiberation|: setting configuration table") - --- all data in this table is overridable. -dcsLiberation = {} - --- the base location for state.json; if non-existent, it'll be replaced with LIBERATION_EXPORT_DIR, TEMP, or DCS working directory -dcsLiberation.installPath=""" + state_location + """ - -""" - # Process the tankers - lua += """ - --- list the tankers generated by Liberation -dcsLiberation.Tankers = { -""" - for key in luaData["Tankers"]: - data = luaData["Tankers"][key] - dcsGroupName= data["dcsGroupName"] - callsign = data["callsign"] - variant = data["variant"] - tacan = data["tacan"] - radio = data["radio"] - lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', variant='{variant}', tacan='{tacan}', radio='{radio}' }}, \n" - #lua += f" {{name='{dcsGroupName}', description='{callsign} ({variant})', information='Tacan:{tacan} Radio:{radio}' }}, \n" - lua += "}" - - # Process the AWACSes - lua += """ - --- list the AWACs generated by Liberation -dcsLiberation.AWACs = { -""" - for key in luaData["AWACs"]: - data = luaData["AWACs"][key] - dcsGroupName= data["dcsGroupName"] - callsign = data["callsign"] - radio = data["radio"] - lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', radio='{radio}' }}, \n" - #lua += f" {{name='{dcsGroupName}', description='{callsign} (AWACS)', information='Radio:{radio}' }}, \n" - lua += "}" - - # Process the JTACs - lua += """ - --- list the JTACs generated by Liberation -dcsLiberation.JTACs = { -""" - for key in luaData["JTACs"]: - data = luaData["JTACs"][key] - dcsGroupName= data["dcsGroupName"] - callsign = data["callsign"] - zone = data["zone"] - laserCode = data["laserCode"] - dcsUnit = data["dcsUnit"] - lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', zone='{zone}', laserCode='{laserCode}', dcsUnit='{dcsUnit}' }}, \n" - #lua += f" {{name='{dcsGroupName}', description='JTAC {callsign} ', information='Laser:{laserCode}', jtac={laserCode} }}, \n" - lua += "}" - - # Process the Target Points - lua += """ - --- list the target points generated by Liberation -dcsLiberation.TargetPoints = { -""" - for key in luaData["TargetPoints"]: - data = luaData["TargetPoints"][key] - name = data["name"] - pointType = data["type"] - positionX = data["position"]["x"] - positionY = data["position"]["y"] - lua += f" {{name='{name}', pointType='{pointType}', positionX='{positionX}', positionY='{positionY}' }}, \n" - #lua += f" {{name='{pointType} {name}', point{{x={positionX}, z={positionY} }} }}, \n" - lua += "}" - - lua += """ - --- list the airbases generated by Liberation --- dcsLiberation.Airbases = {} - --- list the aircraft carriers generated by Liberation --- dcsLiberation.Carriers = {} - --- later, we'll add more data to the table - -""" - - - trigger = TriggerStart(comment="Set DCS Liberation data") - trigger.add_action(DoScript(String(lua))) - self.current_mission.triggerrules.triggers.append(trigger) + self.generate_lua(airgen, airsupportgen, jtacs) # Inject Plugins Lua Scripts and data for plugin in LuaPluginManager.plugins(): @@ -505,3 +355,161 @@ dcsLiberation.TargetPoints = { aircraft_data.channel_allocator.assign_channels_for_flight( flight, air_support ) + + def generate_lua(self, airgen: AircraftConflictGenerator, + airsupportgen: AirSupportConflictGenerator, + jtacs: List[JtacInfo]) -> None: + luaData = {} + luaData["AircraftCarriers"] = {} + luaData["Tankers"] = {} + luaData["AWACs"] = {} + luaData["JTACs"] = {} + luaData["TargetPoints"] = {} + + self.assign_channels_to_flights(airgen.flights, + airsupportgen.air_support) + + for tanker in airsupportgen.air_support.tankers: + luaData["Tankers"][tanker.callsign] = { + "dcsGroupName": tanker.dcsGroupName, + "callsign": tanker.callsign, + "variant": tanker.variant, + "radio": tanker.freq.mhz, + "tacan": str(tanker.tacan.number) + tanker.tacan.band.name + } + + if self.is_awacs_enabled: + for awacs in airsupportgen.air_support.awacs: + luaData["AWACs"][awacs.callsign] = { + "dcsGroupName": awacs.dcsGroupName, + "callsign": awacs.callsign, + "radio": awacs.freq.mhz + } + + for jtac in jtacs: + luaData["JTACs"][jtac.callsign] = { + "dcsGroupName": jtac.dcsGroupName, + "callsign": jtac.callsign, + "zone": jtac.region, + "dcsUnit": jtac.unit_name, + "laserCode": jtac.code + } + + for flight in airgen.flights: + if flight.friendly and flight.flight_type in [FlightType.ANTISHIP, + FlightType.DEAD, + FlightType.SEAD, + FlightType.STRIKE]: + flightType = flight.flight_type.name + flightTarget = flight.package.target + if flightTarget: + flightTargetName = None + flightTargetType = None + if hasattr(flightTarget, 'obj_name'): + flightTargetName = flightTarget.obj_name + flightTargetType = flightType + f" TGT ({flightTarget.category})" + elif hasattr(flightTarget, 'name'): + flightTargetName = flightTarget.name + flightTargetType = flightType + " TGT (Airbase)" + luaData["TargetPoints"][flightTargetName] = { + "name": flightTargetName, + "type": flightTargetType, + "position": {"x": flightTarget.position.x, + "y": flightTarget.position.y} + } + + # set a LUA table with data from Liberation that we want to set + # at the moment it contains Liberation's install path, and an overridable definition for the JTACAutoLase function + # later, we'll add data about the units and points having been generated, in order to facilitate the configuration of the plugin lua scripts + state_location = "[[" + os.path.abspath(".") + "]]" + lua = """ + -- setting configuration table + env.info("DCSLiberation|: setting configuration table") + + -- all data in this table is overridable. + dcsLiberation = {} + + -- the base location for state.json; if non-existent, it'll be replaced with LIBERATION_EXPORT_DIR, TEMP, or DCS working directory + dcsLiberation.installPath=""" + state_location + """ + + """ + # Process the tankers + lua += """ + + -- list the tankers generated by Liberation + dcsLiberation.Tankers = { + """ + for key in luaData["Tankers"]: + data = luaData["Tankers"][key] + dcsGroupName = data["dcsGroupName"] + callsign = data["callsign"] + variant = data["variant"] + tacan = data["tacan"] + radio = data["radio"] + lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', variant='{variant}', tacan='{tacan}', radio='{radio}' }}, \n" + # lua += f" {{name='{dcsGroupName}', description='{callsign} ({variant})', information='Tacan:{tacan} Radio:{radio}' }}, \n" + lua += "}" + + # Process the AWACSes + lua += """ + + -- list the AWACs generated by Liberation + dcsLiberation.AWACs = { + """ + for key in luaData["AWACs"]: + data = luaData["AWACs"][key] + dcsGroupName = data["dcsGroupName"] + callsign = data["callsign"] + radio = data["radio"] + lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', radio='{radio}' }}, \n" + # lua += f" {{name='{dcsGroupName}', description='{callsign} (AWACS)', information='Radio:{radio}' }}, \n" + lua += "}" + + # Process the JTACs + lua += """ + + -- list the JTACs generated by Liberation + dcsLiberation.JTACs = { + """ + for key in luaData["JTACs"]: + data = luaData["JTACs"][key] + dcsGroupName = data["dcsGroupName"] + callsign = data["callsign"] + zone = data["zone"] + laserCode = data["laserCode"] + dcsUnit = data["dcsUnit"] + lua += f" {{dcsGroupName='{dcsGroupName}', callsign='{callsign}', zone='{zone}', laserCode='{laserCode}', dcsUnit='{dcsUnit}' }}, \n" + # lua += f" {{name='{dcsGroupName}', description='JTAC {callsign} ', information='Laser:{laserCode}', jtac={laserCode} }}, \n" + lua += "}" + + # Process the Target Points + lua += """ + + -- list the target points generated by Liberation + dcsLiberation.TargetPoints = { + """ + for key in luaData["TargetPoints"]: + data = luaData["TargetPoints"][key] + name = data["name"] + pointType = data["type"] + positionX = data["position"]["x"] + positionY = data["position"]["y"] + lua += f" {{name='{name}', pointType='{pointType}', positionX='{positionX}', positionY='{positionY}' }}, \n" + # lua += f" {{name='{pointType} {name}', point{{x={positionX}, z={positionY} }} }}, \n" + lua += "}" + + lua += """ + + -- list the airbases generated by Liberation + -- dcsLiberation.Airbases = {} + + -- list the aircraft carriers generated by Liberation + -- dcsLiberation.Carriers = {} + + -- later, we'll add more data to the table + + """ + + trigger = TriggerStart(comment="Set DCS Liberation data") + trigger.add_action(DoScript(String(lua))) + self.current_mission.triggerrules.triggers.append(trigger) \ No newline at end of file From bf7df6721abf5717eb7e9a3ee52fd8982539c541 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 21 Nov 2020 15:00:07 -0800 Subject: [PATCH 3/3] Fix turn 0. `Game.initialize_turn` doesn't run on turn zero, so we have to set up the unit order events when we create the `Game`. --- game/game.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game/game.py b/game/game.py index 8f691b52..889e5c66 100644 --- a/game/game.py +++ b/game/game.py @@ -101,6 +101,9 @@ class Game: self.theater.controlpoints ) + for cp in self.theater.controlpoints: + cp.pending_unit_deliveries = self.units_delivery_event(cp) + self.sanitize_sides() self.on_load()