Skip to content

Commit b4125f0

Browse files
committed
Modify the TargetAbilityEvent interface.
Changes: * New Event.target_id and Event.target_type take the place of the previous Event.target field's components. * Event.target now is always a DataObject representing the target or None if no such object could be found. NOTE: If the targetted object is behind fog of war the unit id will not be available which creates a anonymous object of the specified type. These units are not added to the replay.objects lookup table.
1 parent bc96f3f commit b4125f0

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sc2reader/events.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,29 @@ def __str__(self):
143143
class TargetAbilityEvent(AbilityEvent):
144144
def __init__(self, framestamp, player, type, code, ability, target):
145145
super(TargetAbilityEvent, self).__init__(framestamp, player, type, code, ability)
146-
self.target = target
146+
self.target = None
147+
self.target_id, self.target_type = target
148+
#Forgot why we have to munge this
149+
self.target_type = self.target_type << 8 | 0x01
150+
147151

148152
def load_context(self, replay):
149153
super(TargetAbilityEvent, self).load_context(replay)
154+
uid = (self.target_id, self.target_type)
150155

151-
obj_id, obj_type = self.target
152-
obj_type = obj_type << 8 | 0x01 #Forgot why we have to munge this
153-
154-
if (obj_id, obj_type) in replay.objects:
155-
self.target = replay.objects[(obj_id, obj_type)]
156+
if uid in replay.objects:
157+
self.target = replay.objects[uid]
156158

157-
elif obj_id:
158-
if obj_type not in replay.datapack.types:
159-
self.target = DataObject(0x00)
159+
else:
160+
if self.target_type not in replay.datapack.types:
161+
self.target = None
160162
else:
161-
self.target = replay.datapack.types[obj_type](obj_id)
162-
replay.objects[(obj_id, obj_type)] = self.target
163+
unit_class = replay.datapack.types[self.target_type]
164+
self.target = unit_class(self.target_id)
165+
166+
# For units behind the fog of war, don't make an entry
167+
if self.target.id:
168+
replay.objects[uid] = self.target
163169

164170
def __str__(self):
165171
if self.target:

0 commit comments

Comments
 (0)