Skip to content

Commit 8c8c908

Browse files
committed
When we have tracker events, don't change type with game events.
Fixes #152.
1 parent c89e58d commit 8c8c908

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sc2reader/engine/plugins/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ def handleTargetAbilityEvent(self, event, replay):
4949

5050
if event.target_unit_id in replay.objects:
5151
event.target = replay.objects[event.target_unit_id]
52-
if not event.target.is_type(event.target_unit_type):
52+
if not replay.tracker_events and not event.target.is_type(event.target_unit_type):
5353
replay.datapack.change_type(event.target, event.target_unit_type, event.frame)
5454
else:
55+
# Often when the target_unit_id is not in replay.objects it is 0 because it
56+
# is a target building/destructable hidden by fog of war. Perhaps we can match
57+
# it through the fog using location?
5558
unit = replay.datapack.create_unit(event.target_unit_id, event.target_unit_type, 0x00, event.frame)
5659
event.target = unit
5760
replay.objects[event.target_unit_id] = unit

sc2reader/events/game.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,12 @@ def __init__(self, frame, pid, data):
278278
self.target_timer = self.ability_type_data.get('timer', None)
279279

280280
#: Unique id of the target unit. Available for TargetUnit type events.
281+
#: This id can be 0 when the target unit is shrouded by fog of war.
281282
self.target_unit_id = self.ability_type_data.get('unit_tag', None)
282283

283-
#: A reference to the targetted unit
284+
#: A reference to the targetted unit. When the :attr:`target_unit_id` is
285+
#: 0 this target unit is a generic, reused fog of war unit of the :attr:`target_unit_type`
286+
#: with an id of zero. It should not be confused with a real unit.
284287
self.target_unit = None
285288

286289
#: Current integer type id of the target unit. Available for TargetUnit type events.

0 commit comments

Comments
 (0)