mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix #414
Since there's little difference between the two generators for `generate_plugin_data`, we'll have the pretense lua-generator call its super...
This commit is contained in:
parent
add26ab18e
commit
b5225f03a1
@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
@ -20,14 +19,12 @@ from dcs.vehicles import AirDefence, Unarmed
|
||||
from game.ato import FlightType
|
||||
from game.coalition import Coalition
|
||||
from game.data.units import UnitClass
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from game.missiongenerator.luagenerator import LuaGenerator
|
||||
from game.missiongenerator.missiondata import MissionData
|
||||
from game.plugins import LuaPluginManager
|
||||
from game.pretense.pretenseflightgroupspawner import PretenseNameGenerator
|
||||
from game.pretense.pretensetgogenerator import PretenseGroundObjectGenerator
|
||||
from game.theater import Airfield, OffMapSpawn, TheaterGroundObject
|
||||
from game.theater.iadsnetwork.iadsrole import IadsRole
|
||||
from game.theater import Airfield, OffMapSpawn
|
||||
from game.utils import escape_string_for_lua
|
||||
from pydcs_extensions import IRON_DOME_LN, DAVID_SLING_LN
|
||||
|
||||
@ -82,171 +79,8 @@ class PretenseLuaGenerator(LuaGenerator):
|
||||
self.mission.triggerrules.triggers.append(t)
|
||||
|
||||
def generate_plugin_data(self) -> None:
|
||||
lua_data = LuaData("dcsRetribution")
|
||||
|
||||
install_path = lua_data.add_item("installPath")
|
||||
install_path.set_value(os.path.abspath("."))
|
||||
|
||||
lua_data.add_item("Airbases")
|
||||
carriers_object = lua_data.add_item("Carriers")
|
||||
|
||||
for carrier in self.mission_data.carriers:
|
||||
carrier_item = carriers_object.add_item()
|
||||
carrier_item.add_key_value("dcsGroupName", carrier.group_name)
|
||||
carrier_item.add_key_value("unit_name", carrier.unit_name)
|
||||
carrier_item.add_key_value("callsign", carrier.callsign)
|
||||
carrier_item.add_key_value("radio", str(carrier.freq.mhz))
|
||||
carrier_item.add_key_value(
|
||||
"tacan", str(carrier.tacan.number) + carrier.tacan.band.name
|
||||
)
|
||||
|
||||
tankers_object = lua_data.add_item("Tankers")
|
||||
for tanker in self.mission_data.tankers:
|
||||
tanker_item = tankers_object.add_item()
|
||||
tanker_item.add_key_value("dcsGroupName", tanker.group_name)
|
||||
tanker_item.add_key_value("callsign", tanker.callsign)
|
||||
tanker_item.add_key_value("variant", tanker.variant)
|
||||
tanker_item.add_key_value("radio", str(tanker.freq.mhz))
|
||||
if tanker.tacan is not None:
|
||||
tanker_item.add_key_value(
|
||||
"tacan", str(tanker.tacan.number) + tanker.tacan.band.name
|
||||
)
|
||||
|
||||
awacs_object = lua_data.add_item("AWACs")
|
||||
for awacs in self.mission_data.awacs:
|
||||
awacs_item = awacs_object.add_item()
|
||||
awacs_item.add_key_value("dcsGroupName", awacs.group_name)
|
||||
awacs_item.add_key_value("callsign", awacs.callsign)
|
||||
awacs_item.add_key_value("radio", str(awacs.freq.mhz))
|
||||
|
||||
jtacs_object = lua_data.add_item("JTACs")
|
||||
for jtac in self.mission_data.jtacs:
|
||||
jtac_item = jtacs_object.add_item()
|
||||
jtac_item.add_key_value("dcsGroupName", jtac.group_name)
|
||||
jtac_item.add_key_value("callsign", jtac.callsign)
|
||||
jtac_item.add_key_value("zone", jtac.region)
|
||||
jtac_item.add_key_value("dcsUnit", jtac.unit_name)
|
||||
jtac_item.add_key_value("laserCode", jtac.code)
|
||||
jtac_item.add_key_value("radio", str(jtac.freq.mhz))
|
||||
jtac_item.add_key_value("modulation", jtac.freq.modulation.name)
|
||||
|
||||
logistics_object = lua_data.add_item("Logistics")
|
||||
logistics_flights = logistics_object.add_item("flights")
|
||||
crates_object = logistics_object.add_item("crates")
|
||||
spawnable_crates: dict[str, str] = {}
|
||||
transports: list[AircraftType] = []
|
||||
for logistic_info in self.mission_data.logistics:
|
||||
if logistic_info.transport not in transports:
|
||||
transports.append(logistic_info.transport)
|
||||
coalition_color = "blue" if logistic_info.blue else "red"
|
||||
logistics_item = logistics_flights.add_item()
|
||||
logistics_item.add_data_array("pilot_names", logistic_info.pilot_names)
|
||||
logistics_item.add_key_value("pickup_zone", logistic_info.pickup_zone)
|
||||
logistics_item.add_key_value("drop_off_zone", logistic_info.drop_off_zone)
|
||||
logistics_item.add_key_value("target_zone", logistic_info.target_zone)
|
||||
logistics_item.add_key_value("side", str(2 if logistic_info.blue else 1))
|
||||
logistics_item.add_key_value("logistic_unit", logistic_info.logistic_unit)
|
||||
logistics_item.add_key_value(
|
||||
"aircraft_type", logistic_info.transport.dcs_id
|
||||
)
|
||||
logistics_item.add_key_value(
|
||||
"preload", "true" if logistic_info.preload else "false"
|
||||
)
|
||||
for cargo in logistic_info.cargo:
|
||||
if cargo.unit_type not in spawnable_crates:
|
||||
spawnable_crates[cargo.unit_type] = str(200 + len(spawnable_crates))
|
||||
crate_weight = spawnable_crates[cargo.unit_type]
|
||||
for i in range(cargo.amount):
|
||||
cargo_item = crates_object.add_item()
|
||||
cargo_item.add_key_value("weight", crate_weight)
|
||||
cargo_item.add_key_value("coalition", coalition_color)
|
||||
cargo_item.add_key_value("zone", cargo.spawn_zone)
|
||||
transport_object = logistics_object.add_item("transports")
|
||||
for transport in transports:
|
||||
transport_item = transport_object.add_item()
|
||||
transport_item.add_key_value("aircraft_type", transport.dcs_id)
|
||||
transport_item.add_key_value("cabin_size", str(transport.cabin_size))
|
||||
transport_item.add_key_value(
|
||||
"troops", "true" if transport.cabin_size > 0 else "false"
|
||||
)
|
||||
transport_item.add_key_value(
|
||||
"crates", "true" if transport.can_carry_crates else "false"
|
||||
)
|
||||
spawnable_crates_object = logistics_object.add_item("spawnable_crates")
|
||||
for unit, weight in spawnable_crates.items():
|
||||
crate_item = spawnable_crates_object.add_item()
|
||||
crate_item.add_key_value("unit", unit)
|
||||
crate_item.add_key_value("weight", weight)
|
||||
|
||||
target_points = lua_data.add_item("TargetPoints")
|
||||
for flight in self.mission_data.flights:
|
||||
if flight.friendly and flight.flight_type in [
|
||||
FlightType.ANTISHIP,
|
||||
FlightType.DEAD,
|
||||
FlightType.SEAD,
|
||||
FlightType.STRIKE,
|
||||
]:
|
||||
flight_type = str(flight.flight_type)
|
||||
flight_target = flight.package.target
|
||||
if flight_target:
|
||||
flight_target_name = None
|
||||
flight_target_type = None
|
||||
if isinstance(flight_target, TheaterGroundObject):
|
||||
flight_target_name = flight_target.obj_name
|
||||
flight_target_type = (
|
||||
flight_type + f" TGT ({flight_target.category})"
|
||||
)
|
||||
elif hasattr(flight_target, "name"):
|
||||
flight_target_name = flight_target.name
|
||||
flight_target_type = flight_type + " TGT (Airbase)"
|
||||
target_item = target_points.add_item()
|
||||
if flight_target_name:
|
||||
target_item.add_key_value("name", flight_target_name)
|
||||
if flight_target_type:
|
||||
target_item.add_key_value("type", flight_target_type)
|
||||
target_item.add_key_value(
|
||||
"positionX", str(flight_target.position.x)
|
||||
)
|
||||
target_item.add_key_value(
|
||||
"positionY", str(flight_target.position.y)
|
||||
)
|
||||
|
||||
for cp in self.game.theater.controlpoints:
|
||||
coalition_object = (
|
||||
lua_data.get_or_create_item("BlueAA")
|
||||
if cp.captured
|
||||
else lua_data.get_or_create_item("RedAA")
|
||||
)
|
||||
for ground_object in cp.ground_objects:
|
||||
for g in ground_object.groups:
|
||||
threat_range = g.max_threat_range()
|
||||
|
||||
if not threat_range:
|
||||
continue
|
||||
|
||||
aa_item = coalition_object.add_item()
|
||||
aa_item.add_key_value("name", ground_object.name)
|
||||
aa_item.add_key_value("range", str(threat_range.meters))
|
||||
aa_item.add_key_value("positionX", str(ground_object.position.x))
|
||||
aa_item.add_key_value("positionY", str(ground_object.position.y))
|
||||
|
||||
# Generate IADS Lua Item
|
||||
iads_object = lua_data.add_item("IADS")
|
||||
for node in self.game.theater.iads_network.skynet_nodes(self.game):
|
||||
coalition = iads_object.get_or_create_item("BLUE" if node.player else "RED")
|
||||
iads_type = coalition.get_or_create_item(node.iads_role.value)
|
||||
iads_element = iads_type.add_item()
|
||||
iads_element.add_key_value("dcsGroupName", node.dcs_name)
|
||||
if node.iads_role in [IadsRole.SAM, IadsRole.SAM_AS_EWR]:
|
||||
# add additional SkynetProperties to SAM Sites
|
||||
for property, value in node.properties.items():
|
||||
iads_element.add_key_value(property, value)
|
||||
for role, connections in node.connections.items():
|
||||
iads_element.add_data_array(role, connections)
|
||||
|
||||
trigger = TriggerStart(comment="Set DCS Retribution data")
|
||||
trigger.add_action(DoScript(String(lua_data.create_operations_lua())))
|
||||
self.mission.triggerrules.triggers.append(trigger)
|
||||
super().generate_plugin_data()
|
||||
# Add any custom plugin data for pretense below...
|
||||
|
||||
@staticmethod
|
||||
def generate_sam_from_preset(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user