Add mechanism to prevent double counting of damage induced kills when… (#3371)

… DCS reports multiple hits

This PR fixes a bug introduced when tracking OCA/Aircraft kills that
results in double counting when DCS reports multiple hits, typically
when guns are used.
This commit is contained in:
zhexu14 2024-04-10 16:28:21 +10:00 committed by GitHub
parent 3234a2b28a
commit 9611c01b93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -391,6 +391,9 @@ class Debriefing:
else:
enemy_losses.append(aircraft)
# Keep track of damaged units that are counted as killed so we don't double count
# when DCS reports damage multiple times.
units_killed_by_damage = set()
for unit_data in self.state_data.unit_hit_point_updates:
damaged_unit = FlyingUnitHitPointUpdate.from_json(unit_data, self.unit_map)
if damaged_unit is None:
@ -399,6 +402,9 @@ class Debriefing:
# If unit already killed, nothing to do.
if unit_data["name"] in self.state_data.killed_aircraft:
continue
if unit_data["name"] in units_killed_by_damage:
continue
units_killed_by_damage.add(unit_data["name"])
if damaged_unit.is_friendly(to_player=True):
player_losses.append(damaged_unit.unit)
else: