@@ -19,12 +19,30 @@ def load_context(self, replay):
1919 pass
2020
2121 def _str_prefix (self ):
22- return "{0}\t " .format (Length (seconds = int (self .frame / 16 )))
22+ return "{0}\t " .format (Length (seconds = int (self .frame / 16 )))
2323
2424 def __str__ (self ):
2525 return self ._str_prefix () + self .name
2626
2727
28+ class PlayerSetupEvent (TrackerEvent ):
29+ """ Sent during game setup to help us organize players better """
30+ def __init__ (self , frames , data , build ):
31+ super (PlayerSetupEvent , self ).__init__ (frames )
32+
33+ #: The player id of the player we are setting up
34+ self .pid = data [0 ]
35+
36+ #: The type of this player. One of 1=human, 2=cpu, 3=neutral, 4=hostile
37+ self .type = data [1 ]
38+
39+ #: The user id of the player we are setting up. None of not human
40+ self .uid = data [2 ]
41+
42+ #: The slot id of the player we are setting up. None if not playing
43+ self .sid = data [3 ]
44+
45+
2846class PlayerStatsEvent (TrackerEvent ):
2947 """
3048 Player Stats events are generated for all players that were in the game
@@ -178,10 +196,10 @@ def __init__(self, frames, data, build):
178196 self .resources_killed = self .minerals_killed + self .vespene_killed
179197
180198 #: The food supply currently used
181- self .food_used = clamp (self .stats [29 ])/ 4096.0
199+ self .food_used = clamp (self .stats [29 ]) / 4096.0
182200
183201 #: The food supply currently available
184- self .food_made = clamp (self .stats [30 ])/ 4096.0
202+ self .food_made = clamp (self .stats [30 ]) / 4096.0
185203
186204 #: The total mineral value of all active forces
187205 self .minerals_used_active_forces = clamp (self .stats [31 ])
@@ -208,7 +226,7 @@ def __init__(self, frames, data, build):
208226 self .ff_vespene_lost_technology = clamp (self .stats [38 ]) if build >= 26490 else None
209227
210228 def __str__ (self ):
211- return self ._str_prefix ()+ "{0: >15} - Stats Update" .format (self .player )
229+ return self ._str_prefix () + "{0: >15} - Stats Update" .format (self .player )
212230
213231
214232class UnitBornEvent (TrackerEvent ):
@@ -256,17 +274,24 @@ def __init__(self, frames, data, build):
256274 #: The player object that controls this unit. 0 means neutral unit
257275 self .unit_controller = None
258276
259- #: The x coordinate of the location
260- self .x = data [5 ] * 4
277+ #: The x coordinate of the center of the born unit's footprint. Only 4 point resolution
278+ #: prior to Starcraft Patch 2.1.
279+ self .x = data [5 ]
261280
262- #: The y coordinate of the location
263- self .y = data [6 ] * 4
281+ #: The y coordinate of the center of the born unit's footprint. Only 4 point resolution
282+ #: prior to Starcraft Patch 2.1.
283+ self .y = data [6 ]
264284
265285 #: The map location of the unit birth
266286 self .location = (self .x , self .y )
267287
288+ if build < 27950 :
289+ self .x = self .x * 4
290+ self .y = self .y * 4
291+ self .location = (self .x , self .y )
292+
268293 def __str__ (self ):
269- return self ._str_prefix ()+ "{0: >15} - Unit born {1}" .format (self .unit_upkeeper , self .unit )
294+ return self ._str_prefix () + "{0: >15} - Unit born {1}" .format (self .unit_upkeeper , self .unit )
270295
271296
272297class UnitDiedEvent (TrackerEvent ):
@@ -298,17 +323,39 @@ def __init__(self, frames, data, build):
298323 #: The player object of the that killed the unit. Not always available.
299324 self .killer = None
300325
301- #: The x coordinate of the location
302- self .x = data [3 ] * 4
326+ #: The x coordinate of the center of the dying unit's footprint. Only 4 point resolution
327+ #: prior to Starcraft Patch 2.1.
328+ self .x = data [3 ]
303329
304- #: The y coordinate of the location
305- self .y = data [4 ] * 4
330+ #: The y coordinate of the center of the dying unit's footprint. Only 4 point resolution
331+ #: prior to Starcraft Patch 2.1.
332+ self .y = data [4 ]
306333
307334 #: The map location the unit was killed at.
308335 self .location = (self .x , self .y )
309336
337+ #: The index portion of the killing unit's id. Available for build 27950+
338+ self .killer_unit_index = None
339+
340+ #: The recycle portion of the killing unit's id. Available for build 27950+
341+ self .killer_unit_recycle = None
342+
343+ #: The unique id of the unit doing the killing. Available for build 27950+
344+ self .killer_unit_id = None
345+
346+ if build < 27950 :
347+ self .x = self .x * 4
348+ self .y = self .y * 4
349+ self .location = (self .x , self .y )
350+ else :
351+ # Starcraft patch 2.1 introduced killer unit indexes
352+ self .killer_unit_index = data [5 ]
353+ self .killer_unit_recycle = data [6 ]
354+ if self .killer_unit_index :
355+ self .killer_unit_id = self .killer_unit_index << 18 | self .killer_unit_recycle
356+
310357 def __str__ (self ):
311- return self ._str_prefix ()+ "{0: >15} - Unit died {1}." .format (self .unit .owner , self .unit )
358+ return self ._str_prefix () + "{0: >15} - Unit died {1}." .format (self .unit .owner , self .unit )
312359
313360
314361class UnitOwnerChangeEvent (TrackerEvent ):
@@ -342,7 +389,7 @@ def __init__(self, frames, data, build):
342389 self .unit_controller = None
343390
344391 def __str__ (self ):
345- return self ._str_prefix ()+ "{0: >15} took {1}" .format (self .unit_upkeeper , self .unit )
392+ return self ._str_prefix () + "{0: >15} took {1}" .format (self .unit_upkeeper , self .unit )
346393
347394
348395class UnitTypeChangeEvent (TrackerEvent ):
@@ -367,7 +414,7 @@ def __init__(self, frames, data, build):
367414 self .unit_type_name = data [2 ].decode ('utf8' )
368415
369416 def __str__ (self ):
370- return self ._str_prefix ()+ "{0: >15} - Unit {0} type changed to {1}" .format (self .unit .owner , self .unit , self .unit_type_name )
417+ return self ._str_prefix () + "{0: >15} - Unit {0} type changed to {1}" .format (self .unit .owner , self .unit , self .unit_type_name )
371418
372419
373420class UpgradeCompleteEvent (TrackerEvent ):
@@ -389,7 +436,7 @@ def __init__(self, frames, data, build):
389436 self .count = data [2 ]
390437
391438 def __str__ (self ):
392- return self ._str_prefix ()+ "{0: >15} - {1}upgrade completed" .format (self .player , self .upgrade_type_name )
439+ return self ._str_prefix () + "{0: >15} - {1}upgrade completed" .format (self .player , self .upgrade_type_name )
393440
394441
395442class UnitInitEvent (TrackerEvent ):
@@ -432,17 +479,24 @@ def __init__(self, frames, data, build):
432479 #: The player object that controls this unit. 0 means neutral unit
433480 self .unit_controller = None
434481
435- #: The x coordinate of the location
436- self .x = data [5 ] * 4
482+ #: The x coordinate of the center of the init unit's footprint. Only 4 point resolution
483+ #: prior to Starcraft Patch 2.1.
484+ self .x = data [5 ]
437485
438- #: The y coordinate of the location
439- self .y = data [6 ] * 4
486+ #: The y coordinate of the center of the init unit's footprint. Only 4 point resolution
487+ #: prior to Starcraft Patch 2.1.
488+ self .y = data [6 ]
440489
441490 #: The map location the unit was started at
442491 self .location = (self .x , self .y )
443492
493+ if build < 27950 :
494+ self .x = self .x * 4
495+ self .y = self .y * 4
496+ self .location = (self .x , self .y )
497+
444498 def __str__ (self ):
445- return self ._str_prefix ()+ "{0: >15} - Unit initiated {1}" .format (self .unit_upkeeper , self .unit )
499+ return self ._str_prefix () + "{0: >15} - Unit initiated {1}" .format (self .unit_upkeeper , self .unit )
446500
447501
448502class UnitDoneEvent (TrackerEvent ):
@@ -470,7 +524,7 @@ def __init__(self, frames, data, build):
470524 self .unit = None
471525
472526 def __str__ (self ):
473- return self ._str_prefix ()+ "{0: >15} - Unit {1} done" .format (self .unit .owner , self .unit )
527+ return self ._str_prefix () + "{0: >15} - Unit {1} done" .format (self .unit .owner , self .unit )
474528
475529
476530class UnitPositionsEvent (TrackerEvent ):
@@ -488,15 +542,20 @@ def __init__(self, frames, data, build):
488542 #: A dict mapping of units that had their position updated to their positions
489543 self .units = dict ()
490544
491- #: A list of (unit_index, (x,y)) derived from the first_unit_index and items
545+ #: A list of (unit_index, (x,y)) derived from the first_unit_index and items. Prior to
546+ #: Starcraft Patch 2.1 the coordinates have 4 point resolution. (15,25) recorded as (12,24).
547+ #: Location prior to any rounding marks the center of the unit footprint.
492548 self .positions = list ()
493549
494550 unit_index = self .first_unit_index
495551 for i in range (0 , len (self .items ), 3 ):
496552 unit_index += self .items [i ]
497- x = self .items [i + 1 ]* 4
498- y = self .items [i + 2 ]* 4
553+ x = self .items [i + 1 ]
554+ y = self .items [i + 2 ]
555+ if build < 27950 :
556+ x = x * 4
557+ y = y * 4
499558 self .positions .append ((unit_index , (x , y )))
500559
501560 def __str__ (self ):
502- return self ._str_prefix ()+ "Unit positions update"
561+ return self ._str_prefix () + "Unit positions update"
0 commit comments