@@ -170,8 +170,11 @@ def load_context(self, replay):
170170 if self .unit_id in replay .objects :
171171 self .unit = replay .objects [self .unit_id ]
172172 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
175178
176179
177180class UnitDiedEvent (TrackerEvent ):
@@ -204,8 +207,11 @@ def __init__(self, frames, data):
204207 def load_context (self , replay ):
205208 if self .unit_id in replay .objects :
206209 self .unit = replay .objects [self .unit_id ]
210+ self .unit .location = self .location
211+ del replay .active_units [self .unit_id_index ]
207212 else :
208213 # Create a new unit, but we don't have a type name map yet!
214+ print "Unit died before it was born!"
209215 self .unit = None
210216
211217 if self .killer_pid : # This field isn't always available
@@ -245,6 +251,7 @@ def load_context(self, replay):
245251 self .unit = replay .objects [self .unit_id ]
246252 else :
247253 # Create a new unit, but we don't have a type name map yet!
254+ print "Unit owner changed before it was born!"
248255 self .unit = None
249256
250257
@@ -269,8 +276,9 @@ def __init__(self, frames, data):
269276 def load_context (self , replay ):
270277 if self .unit_id in replay .objects :
271278 self .unit = replay .objects [self .unit_id ]
279+ replay .datapack .change_type (self .unit , self .unit_type_name , self .frame )
272280 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!"
274282 self .unit = None
275283
276284
@@ -293,6 +301,7 @@ def __init__(self, frames, data):
293301 def load_context (self , replay ):
294302 self .player = replay .player [self .pid ]
295303 # TODO: We don't have upgrade -> ability maps
304+ # TODO: we can probably do the same thing we did for units
296305
297306
298307class UnitInitEvent (TrackerEvent ):
@@ -338,8 +347,12 @@ def load_context(self, replay):
338347 if self .unit_id in replay .objects :
339348 self .unit = replay .objects [self .unit_id ]
340349 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
343356
344357
345358class UnitDoneEvent (TrackerEvent ):
@@ -361,7 +374,7 @@ def load_context(self, replay):
361374 if self .unit_id in replay .objects :
362375 self .unit = replay .objects [self .unit_id ]
363376 else :
364- # Create a new unit, but we don't have a type name map yet!
377+ print "Unit done before it was started!"
365378 self .unit = None
366379
367380
@@ -377,6 +390,16 @@ def __init__(self, frames, data):
377390 #: ???
378391 self .items = data [1 ]
379392
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 )))
380403 """ We need to be able to find units without the recycle id, can't do this yet!
381404 unitTagIndex = event['m_firstUnitIndex']
382405 for i in xrange(len(event['m_items']) / 3):
@@ -385,3 +408,12 @@ def __init__(self, frames, data):
385408 y = event['m_items'][i * 3 + 2] * 4
386409 # the unit with unitTagIndex is now at coordinate (x, y)
387410 """
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