mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Rework killed map_objects recognition
- removed the map_object_id from the TGO - add a new TriggerRule with the MapObjectIsDead Condition which adds the map object to the killed_map_objects array in the state.json - Use the trigger_zone_name as the unique identifier used for the unit_map to recognize the kill
This commit is contained in:
@@ -99,6 +99,9 @@ class StateData:
|
||||
#: Names of vehicle (and ship) units that were killed during the mission.
|
||||
killed_ground_units: List[str]
|
||||
|
||||
#: Names of map objects that were killed during the mission.
|
||||
killed_map_objects: list[str]
|
||||
|
||||
#: List of descriptions of destroyed statics. Format of each element is a mapping of
|
||||
#: the coordinate type ("x", "y", "z", "type", "orientation") to the value.
|
||||
destroyed_statics: List[dict[str, Union[float, str]]]
|
||||
@@ -117,6 +120,7 @@ class StateData:
|
||||
# Also normalize dead map objects (which are ints) to strings. The unit map
|
||||
# only stores strings.
|
||||
killed_ground_units=list({str(u) for u in data["killed_ground_units"]}),
|
||||
killed_map_objects=data["killed_map_objects"],
|
||||
destroyed_statics=data["destroyed_objects_positions"],
|
||||
base_capture_events=data["base_capture_events"],
|
||||
)
|
||||
@@ -318,6 +322,16 @@ class Debriefing:
|
||||
losses.enemy_airlifts.append(airlift_unit)
|
||||
continue
|
||||
|
||||
# Find killed map objects and mark them as loss
|
||||
for map_object in self.state_data.killed_map_objects:
|
||||
building = self.unit_map.building_or_fortification(map_object)
|
||||
if building is not None:
|
||||
if building.ground_object.control_point.captured:
|
||||
losses.player_buildings.append(building)
|
||||
else:
|
||||
losses.enemy_buildings.append(building)
|
||||
continue
|
||||
|
||||
return losses
|
||||
|
||||
def base_capture_events(self) -> List[BaseCaptureEvent]:
|
||||
|
||||
@@ -24,7 +24,8 @@ from typing import (
|
||||
)
|
||||
|
||||
from dcs import Mission, Point, unitgroup
|
||||
from dcs.action import SceneryDestructionZone
|
||||
from dcs.action import SceneryDestructionZone, DoScript
|
||||
from dcs.condition import MapObjectIsDead
|
||||
from dcs.country import Country
|
||||
from dcs.point import StaticPoint
|
||||
from dcs.statics import Fortification, fortification_map, warehouse_map
|
||||
@@ -35,7 +36,8 @@ from dcs.task import (
|
||||
OptAlarmState,
|
||||
FireAtPoint,
|
||||
)
|
||||
from dcs.triggers import TriggerStart, TriggerZone
|
||||
from dcs.translation import String
|
||||
from dcs.triggers import TriggerStart, TriggerZone, Event, TriggerOnce
|
||||
from dcs.unit import Ship, Unit, Vehicle, InvisibleFARP
|
||||
from dcs.unitgroup import ShipGroup, StaticGroup, VehicleGroup
|
||||
from dcs.unittype import StaticType, ShipType, VehicleType
|
||||
@@ -296,7 +298,9 @@ class SceneryGenerator(BuildingSiteGenerator):
|
||||
# this trigger rule is applied. Otherwise you can kill a
|
||||
# structure twice.
|
||||
if self.ground_object.is_dead:
|
||||
self.generate_dead_trigger_rule(trigger_zone)
|
||||
self.generate_destruction_trigger_rule(trigger_zone)
|
||||
else:
|
||||
self.generate_on_dead_trigger_rule(trigger_zone)
|
||||
|
||||
# Tell Liberation to manage this groundobjectsgen as part of the campaign.
|
||||
self.register_scenery()
|
||||
@@ -324,7 +328,7 @@ class SceneryGenerator(BuildingSiteGenerator):
|
||||
zone.properties,
|
||||
)
|
||||
|
||||
def generate_dead_trigger_rule(self, trigger_zone: TriggerZone) -> None:
|
||||
def generate_destruction_trigger_rule(self, trigger_zone: TriggerZone) -> None:
|
||||
# Add destruction zone trigger
|
||||
t = TriggerStart(comment="Destruction")
|
||||
t.actions.append(
|
||||
@@ -332,6 +336,17 @@ class SceneryGenerator(BuildingSiteGenerator):
|
||||
)
|
||||
self.m.triggerrules.triggers.append(t)
|
||||
|
||||
def generate_on_dead_trigger_rule(self, trigger_zone: TriggerZone) -> None:
|
||||
# Add a TriggerRule with the MapObjectIsDead condition to recognize killed
|
||||
# map objects and add them to the state.json with a DoScript
|
||||
t = TriggerOnce(Event.NoEvent, f"MapObjectIsDead Trigger {trigger_zone.id}")
|
||||
t.add_condition(MapObjectIsDead(trigger_zone.id))
|
||||
script_string = String(
|
||||
f'killed_map_objects[#killed_map_objects + 1] = "{trigger_zone.name}"'
|
||||
)
|
||||
t.actions.append(DoScript(script_string))
|
||||
self.m.triggerrules.triggers.append(t)
|
||||
|
||||
def register_scenery(self) -> None:
|
||||
scenery = self.ground_object
|
||||
assert isinstance(scenery, SceneryGroundObject)
|
||||
|
||||
@@ -319,16 +319,6 @@ class SceneryGroundObject(BuildingGroundObject):
|
||||
is_fob_structure=False,
|
||||
)
|
||||
self.zone = zone
|
||||
try:
|
||||
# In the default TriggerZone using "assign as..." in the DCS Mission Editor,
|
||||
# property three has the scenery's object ID as its value.
|
||||
self.map_object_id = self.zone.properties[3]["value"]
|
||||
except (IndexError, KeyError):
|
||||
logging.exception(
|
||||
"Invalid TriggerZone for Scenery definition. The third property must "
|
||||
"be the map object ID."
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
class FactoryGroundObject(BuildingGroundObject):
|
||||
|
||||
@@ -221,7 +221,7 @@ class UnitMap:
|
||||
self.buildings[name] = Building(ground_object)
|
||||
|
||||
def add_scenery(self, ground_object: SceneryGroundObject) -> None:
|
||||
name = str(ground_object.map_object_id)
|
||||
name = str(ground_object.zone.name)
|
||||
if name in self.buildings:
|
||||
raise RuntimeError(
|
||||
f"Duplicate TGO unit: {name}. TriggerZone name: "
|
||||
|
||||
Reference in New Issue
Block a user