mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add Mbot's Call Artillery Script plugin (#410)
* Add Mbot's Call Artillery Script plugin * Applied PR comments * Fix for wrong indentation, remove unused client skill check, added changelog item
This commit is contained in:
@@ -45,7 +45,7 @@ from game.unitmap import UnitMap
|
||||
from game.utils import Heading
|
||||
from .frontlineconflictdescription import FrontLineConflictDescription
|
||||
from .groundforcepainter import GroundForcePainter
|
||||
from .missiondata import JtacInfo, MissionData
|
||||
from .missiondata import JtacInfo, MissionData, FrontlineUnitGroupsInfo
|
||||
from ..ato import FlightType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -198,6 +198,20 @@ class FlotGenerator:
|
||||
)
|
||||
)
|
||||
|
||||
for vehicle_group, combat_group in player_groups:
|
||||
self.mission_data.player_frontline_groups.append(
|
||||
FrontlineUnitGroupsInfo(
|
||||
group_name=vehicle_group.name, unit_type=combat_group.unit_type
|
||||
)
|
||||
)
|
||||
|
||||
for vehicle_group, combat_group in enemy_groups:
|
||||
self.mission_data.enemy_frontline_groups.append(
|
||||
FrontlineUnitGroupsInfo(
|
||||
group_name=vehicle_group.name, unit_type=combat_group.unit_type
|
||||
)
|
||||
)
|
||||
|
||||
def gen_infantry_group_for_group(
|
||||
self,
|
||||
group: VehicleGroup,
|
||||
|
||||
@@ -10,6 +10,7 @@ from dcs import Mission
|
||||
from dcs.action import DoScript, DoScriptFile
|
||||
from dcs.translation import String
|
||||
from dcs.triggers import TriggerStart
|
||||
from dcs.unit import Skill
|
||||
|
||||
from game.ato import FlightType
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
@@ -17,6 +18,7 @@ from game.plugins import LuaPluginManager
|
||||
from game.theater import TheaterGroundObject
|
||||
from game.theater.iadsnetwork.iadsrole import IadsRole
|
||||
from game.utils import escape_string_for_lua
|
||||
from game.data.units import UnitClass
|
||||
from .missiondata import MissionData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -211,6 +213,59 @@ class LuaGenerator:
|
||||
for role, connections in node.connections.items():
|
||||
iads_element.add_data_array(role, connections)
|
||||
|
||||
# Add artillery and support units info
|
||||
artillery_object = lua_data.add_item("artilleryGroups")
|
||||
ground_artillery_group_collection = artillery_object.get_or_create_item(
|
||||
"groundArtillery"
|
||||
)
|
||||
ship_artillery_group_collection = artillery_object.get_or_create_item(
|
||||
"shipArtillery"
|
||||
)
|
||||
|
||||
# First add all artillery units that are theater objects (mostly ships)
|
||||
for ground_object in self.game.theater.ground_objects:
|
||||
for group in ground_object.groups:
|
||||
# Check if first unit in group is ground-based or ship artillery
|
||||
group_first_unit = group.units[0]
|
||||
if group_first_unit.unit_type is None:
|
||||
continue
|
||||
if group_first_unit.unit_type.unit_class == UnitClass.ARTILLERY:
|
||||
ground_artillery_group = (
|
||||
ground_artillery_group_collection.add_item()
|
||||
)
|
||||
ground_artillery_group.add_key_value("groupName", group.group_name)
|
||||
elif group_first_unit.unit_type.unit_class in (
|
||||
UnitClass.CRUISER,
|
||||
UnitClass.DESTROYER,
|
||||
UnitClass.FRIGATE,
|
||||
):
|
||||
# TODO: we assume that these ship classes have guns... Which might not be the case.
|
||||
ship_artillery_group = ship_artillery_group_collection.add_item()
|
||||
ship_artillery_group.add_key_value("groupName", group.group_name)
|
||||
|
||||
# Add artillery that are frontline groups
|
||||
for frontline_group in (
|
||||
self.mission_data.player_frontline_groups
|
||||
+ self.mission_data.enemy_frontline_groups
|
||||
):
|
||||
if frontline_group.unit_type.unit_class == UnitClass.ARTILLERY:
|
||||
ground_artillery_group = ground_artillery_group_collection.add_item()
|
||||
ground_artillery_group.add_key_value(
|
||||
"groupName", frontline_group.group_name
|
||||
)
|
||||
|
||||
# Add forward observer (FO) (TODO: maybe adding new flight type "Foward Observer"?)
|
||||
forward_observer_object = lua_data.add_item("forwardObserverUnits")
|
||||
for flight in self.mission_data.flights:
|
||||
if len(flight.client_units) == 0:
|
||||
continue
|
||||
if flight.flight_type != FlightType.ARMED_RECON:
|
||||
continue
|
||||
|
||||
for client_unit in flight.client_units:
|
||||
forward_observer = forward_observer_object.add_item()
|
||||
forward_observer.add_key_value("unitName", client_unit.name)
|
||||
|
||||
trigger = TriggerStart(comment="Set DCS Retribution data")
|
||||
trigger.add_action(DoScript(String(lua_data.create_operations_lua())))
|
||||
self.mission.triggerrules.triggers.append(trigger)
|
||||
@@ -245,11 +300,23 @@ class LuaGenerator:
|
||||
trigger.add_action(DoScriptFile(fileref))
|
||||
self.mission.triggerrules.triggers.append(trigger)
|
||||
|
||||
def inject_other_plugin_resources(self, plugin_mnemonic: str, file: str) -> None:
|
||||
plugin_path = Path("./resources/plugins", plugin_mnemonic)
|
||||
|
||||
resource_path = Path(plugin_path, file)
|
||||
if not resource_path.exists():
|
||||
logging.error(f"Cannot find {resource_path} for plugin {plugin_mnemonic}")
|
||||
return
|
||||
|
||||
filename = resource_path.resolve()
|
||||
self.mission.map_resource.add_resource_file(filename)
|
||||
|
||||
def inject_plugins(self) -> None:
|
||||
for plugin in LuaPluginManager.plugins():
|
||||
if plugin.enabled:
|
||||
plugin.inject_scripts(self)
|
||||
plugin.inject_configuration(self)
|
||||
plugin.inject_other_resource_files(self)
|
||||
|
||||
|
||||
class LuaValue:
|
||||
|
||||
@@ -5,6 +5,7 @@ from datetime import datetime
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from game.dcs.groundunittype import GroundUnitType
|
||||
from game.missiongenerator.aircraft.flightdata import FlightData
|
||||
from game.runways import RunwayData
|
||||
|
||||
@@ -89,6 +90,12 @@ class LogisticsInfo:
|
||||
preload: bool = field(default=False)
|
||||
|
||||
|
||||
@dataclass
|
||||
class FrontlineUnitGroupsInfo:
|
||||
group_name: str
|
||||
unit_type: GroundUnitType
|
||||
|
||||
|
||||
@dataclass
|
||||
class MissionData:
|
||||
awacs: list[AwacsInfo] = field(default_factory=list)
|
||||
@@ -99,3 +106,5 @@ class MissionData:
|
||||
jtacs: list[JtacInfo] = field(default_factory=list)
|
||||
logistics: list[LogisticsInfo] = field(default_factory=list)
|
||||
cp_stack: dict[UUID, Distance] = field(default_factory=dict)
|
||||
player_frontline_groups: list[FrontlineUnitGroupsInfo] = field(default_factory=list)
|
||||
enemy_frontline_groups: list[FrontlineUnitGroupsInfo] = field(default_factory=list)
|
||||
|
||||
@@ -77,6 +77,7 @@ class LuaPluginDefinition:
|
||||
options: List[LuaPluginOption]
|
||||
work_orders: List[LuaPluginWorkOrder]
|
||||
config_work_orders: List[LuaPluginWorkOrder]
|
||||
other_resource_files: List[str]
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, name: str, path: Path) -> LuaPluginDefinition:
|
||||
@@ -124,6 +125,7 @@ class LuaPluginDefinition:
|
||||
options=options,
|
||||
work_orders=work_orders,
|
||||
config_work_orders=config_work_orders,
|
||||
other_resource_files=data.get("otherResourceFiles", []),
|
||||
)
|
||||
|
||||
|
||||
@@ -199,3 +201,10 @@ class LuaPlugin(PluginSettings):
|
||||
|
||||
for work_order in self.definition.config_work_orders:
|
||||
work_order.work(lua_generator)
|
||||
|
||||
def inject_other_resource_files(self, lua_generator: LuaGenerator) -> None:
|
||||
for resource_file in self.definition.other_resource_files:
|
||||
# TODO: should probably deconflict names of resources
|
||||
lua_generator.inject_other_plugin_resources(
|
||||
self.definition.identifier, resource_file
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user