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:
RndName
2021-12-31 17:10:23 +01:00
parent ffd8152b36
commit e070d5bf0d
6 changed files with 40 additions and 18 deletions

View File

@@ -104,6 +104,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]]]
@@ -122,6 +125,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"],
)
@@ -323,6 +327,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]:

View File

@@ -316,16 +316,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):

View File

@@ -217,7 +217,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: "