Skip to content

Commit 7f30ddf

Browse files
committed
Be safe and print warnings for tracker events.
1 parent 60b6e0f commit 7f30ddf

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

sc2reader/events/tracker.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,15 @@ def __init__(self, frames, data):
175175
self.location = (self.x, self.y)
176176

177177
def load_context(self, replay):
178-
if self.control_pid: # 0 means neutral unit
178+
if self.control_pid in replay.player:
179179
self.unit_controller = replay.player[self.control_pid]
180+
elif self.control_pid != 0:
181+
print "Unknown controller pid", self.control_pid
180182

181-
if self.upkeep_pid: # 0 means neutral unit
183+
if self.upkeep_pid in replay.player:
182184
self.unit_upkeeper = replay.player[self.upkeep_pid]
185+
elif self.upkeep_pid != 0:
186+
print "Unknown upkeep pid", self.upkeep_pid
183187

184188
if self.unit_id in replay.objects:
185189
# This can happen because game events are done first
@@ -233,12 +237,17 @@ def load_context(self, replay):
233237
self.unit = replay.objects[self.unit_id]
234238
self.unit.death = self.frame
235239
self.unit.location = self.location
236-
del replay.active_units[self.unit_id_index]
240+
if self.unit_id_index in replay.active_units:
241+
del replay.active_units[self.unit_id_index]
242+
else:
243+
print "Unable to delete unit, not index not active", self.unit_id_index
237244
else:
238245
print "Unit died before it was born!"
239246

240-
if self.killer_pid: # This field isn't always available
247+
if self.killer_pid in replay.player:
241248
self.killer = replay.player[self.killer_pid]
249+
elif self.killer_pid:
250+
print "Unknown killer pid", self.killer_pid
242251

243252

244253
class UnitOwnerChangeEvent(TrackerEvent):
@@ -272,11 +281,15 @@ def __init__(self, frames, data):
272281
self.unit_controller = None
273282

274283
def load_context(self, replay):
275-
if self.control_pid:
284+
if self.control_pid in replay.player:
276285
self.unit_controller = replay.player[self.control_pid]
286+
elif self.control_pid != 0:
287+
print "Unknown controller pid", self.control_pid
277288

278-
if self.upkeep_pid:
289+
if self.upkeep_pid in replay.player:
279290
self.unit_upkeeper = replay.player[self.upkeep_pid]
291+
elif self.upkeep_pid != 0:
292+
print "Unknown upkeep pid", self.upkeep_pid
280293

281294
if self.unit_id in replay.objects:
282295
self.unit = replay.objects[self.unit_id]
@@ -334,7 +347,10 @@ def __init__(self, frames, data):
334347

335348

336349
def load_context(self, replay):
337-
self.player = replay.player[self.pid]
350+
if self.pid in replay.player:
351+
self.player = replay.player[self.pid]
352+
else:
353+
print "Unknown upgrade pid", self.pid
338354
# TODO: We don't have upgrade -> ability maps
339355
# TODO: we can probably do the same thing we did for units
340356

@@ -382,15 +398,21 @@ def __init__(self, frames, data):
382398
self.location = (self.x, self.y)
383399

384400
def load_context(self, replay):
385-
if self.control_pid: # 0 means neutral unit
401+
if self.control_pid in replay.player:
386402
self.unit_controller = replay.player[self.control_pid]
403+
elif self.control_pid != 0:
404+
print "Unknown controller pid", self.control_pid
387405

388-
if self.upkeep_pid: # 0 means neutral unit
406+
if self.upkeep_pid in replay.player:
389407
self.unit_upkeeper = replay.player[self.upkeep_pid]
408+
elif self.upkeep_pid != 0:
409+
print "Unknown upkeep pid", self.upkeep_pid
390410

391411
if self.unit_id in replay.objects:
392412
# This can happen because game events are done first
393413
self.unit = replay.objects[self.unit_id]
414+
if self.unit._type_class.str_id != self.unit_type_name:
415+
print "CONFLICT {} <-_-> {}".format(self.unit._type_class.str_id, self.unit_type_name)
394416
else:
395417
# TODO: How to tell if something is hallucination?
396418
self.unit = replay.datapack.create_unit(self.unit_id, self.unit_type_name, 0, self.frame)

0 commit comments

Comments
 (0)