Cleanup the killed map objects recognition

removed the extra array to track killed_map_objects and reuse the existing killed_ground_units routine to remove duplicate code and possible confusion

cherry-pick from 41392585
This commit is contained in:
RndName 2022-01-02 12:55:10 +01:00
parent 24e904134e
commit 475cb4851a
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 2 additions and 18 deletions

View File

@ -101,12 +101,9 @@ class StateData:
#: Names of aircraft units that were killed during the mission.
killed_aircraft: List[str]
#: Names of vehicle (and ship) units that were killed during the mission.
#: Names of vehicles, ships or buildings 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]]]
@ -125,7 +122,6 @@ 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"],
)
@ -327,16 +323,6 @@ 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

@ -343,7 +343,7 @@ class SceneryGenerator(BuildingSiteGenerator):
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}"'
f'killed_ground_units[#killed_ground_units + 1] = "{trigger_zone.name}"'
)
t.actions.append(DoScript(script_string))
self.m.triggerrules.triggers.append(t)

View File

@ -8,7 +8,6 @@ killed_aircrafts = {} -- killed aircraft will be added via S_EVENT_CRASH event
killed_ground_units = {} -- killed units will be added via S_EVENT_DEAD event
base_capture_events = {}
destroyed_objects_positions = {} -- will be added via S_EVENT_DEAD event
killed_map_objects = {} -- killed map objects will be added via TriggerRules
mission_ended = false
local function ends_with(str, ending)
@ -36,7 +35,6 @@ function write_state()
["base_capture_events"] = base_capture_events,
["mission_ended"] = mission_ended,
["destroyed_objects_positions"] = destroyed_objects_positions,
["killed_map_objects"] = killed_map_objects,
}
if not json then
local message = string.format("Unable to save DCS Liberation state to %s, JSON library is not loaded !", _debriefing_file_location)