@@ -170,8 +170,11 @@ def load_context(self, replay):
170
170
if self .unit_id in replay .objects :
171
171
self .unit = replay .objects [self .unit_id ]
172
172
else :
173
- # Create a new unit, but we don't have a type name map yet!
174
- self .unit = None
173
+ # TODO: How to tell if something is hallucination?
174
+ self .unit = replay .datapack .create_unit (self .unit_id , self .unit_type_name , 0 , self .frame )
175
+ self .unit .location = self .location
176
+ replay .objects [self .unit_id ] = self .unit
177
+ replay .active_units [self .unit_id_index ] = self .unit
175
178
176
179
177
180
class UnitDiedEvent (TrackerEvent ):
@@ -204,8 +207,11 @@ def __init__(self, frames, data):
204
207
def load_context (self , replay ):
205
208
if self .unit_id in replay .objects :
206
209
self .unit = replay .objects [self .unit_id ]
210
+ self .unit .location = self .location
211
+ del replay .active_units [self .unit_id_index ]
207
212
else :
208
213
# Create a new unit, but we don't have a type name map yet!
214
+ print "Unit died before it was born!"
209
215
self .unit = None
210
216
211
217
if self .killer_pid : # This field isn't always available
@@ -245,6 +251,7 @@ def load_context(self, replay):
245
251
self .unit = replay .objects [self .unit_id ]
246
252
else :
247
253
# Create a new unit, but we don't have a type name map yet!
254
+ print "Unit owner changed before it was born!"
248
255
self .unit = None
249
256
250
257
@@ -269,8 +276,9 @@ def __init__(self, frames, data):
269
276
def load_context (self , replay ):
270
277
if self .unit_id in replay .objects :
271
278
self .unit = replay .objects [self .unit_id ]
279
+ replay .datapack .change_type (self .unit , self .unit_type_name , self .frame )
272
280
else :
273
- # Create a new unit, but we don't have a type name map yet!
281
+ print "Unit type changed before it was born!"
274
282
self .unit = None
275
283
276
284
@@ -293,6 +301,7 @@ def __init__(self, frames, data):
293
301
def load_context (self , replay ):
294
302
self .player = replay .player [self .pid ]
295
303
# TODO: We don't have upgrade -> ability maps
304
+ # TODO: we can probably do the same thing we did for units
296
305
297
306
298
307
class UnitInitEvent (TrackerEvent ):
@@ -338,8 +347,12 @@ def load_context(self, replay):
338
347
if self .unit_id in replay .objects :
339
348
self .unit = replay .objects [self .unit_id ]
340
349
else :
341
- # Create a new unit, but we don't have a type name map yet!
342
- self .unit = None
350
+ # TODO: How to tell if something is hallucination?
351
+ self .unit = replay .datapack .create_unit (self .unit_id , self .unit_type_name , 0 , self .frame )
352
+ replay .objects [self .unit_id ] = self .unit
353
+ replay .active_units [self .unit_id_index ] = self .unit
354
+
355
+ self .unit .location = self .location
343
356
344
357
345
358
class UnitDoneEvent (TrackerEvent ):
@@ -361,7 +374,7 @@ def load_context(self, replay):
361
374
if self .unit_id in replay .objects :
362
375
self .unit = replay .objects [self .unit_id ]
363
376
else :
364
- # Create a new unit, but we don't have a type name map yet!
377
+ print "Unit done before it was started!"
365
378
self .unit = None
366
379
367
380
@@ -377,6 +390,16 @@ def __init__(self, frames, data):
377
390
#: ???
378
391
self .items = data [1 ]
379
392
393
+
394
+ self .units = list ()
395
+
396
+ self .positions = list ()
397
+ unit_index = self .first_unit_index
398
+ for i in range (0 , len (self .items ), 3 ):
399
+ unit_index += self .items [i ]
400
+ x = self .items [i + 1 ]* 4
401
+ y = self .items [i + 2 ]* 4
402
+ self .positions .append ((unit_index , (x ,y )))
380
403
""" We need to be able to find units without the recycle id, can't do this yet!
381
404
unitTagIndex = event['m_firstUnitIndex']
382
405
for i in xrange(len(event['m_items']) / 3):
@@ -385,3 +408,12 @@ def __init__(self, frames, data):
385
408
y = event['m_items'][i * 3 + 2] * 4
386
409
# the unit with unitTagIndex is now at coordinate (x, y)
387
410
"""
411
+
412
+ def load_context (self , replay ):
413
+ for unit_index , (x ,y ) in self .positions :
414
+ if unit_index in replay .active_units :
415
+ unit = replay .active_units [unit_index ]
416
+ unit .location = (x ,y )
417
+ self .units .append (unit )
418
+ else :
419
+ print "Unit moved that doesn't exist!"
0 commit comments