@@ -27,12 +27,30 @@ def load_context(self, replay):
2727 pass
2828
2929 def _str_prefix (self ):
30- return "{0}\t " .format (Length (seconds = int (self .frame / 16 )))
30+ return "{0}\t " .format (Length (seconds = int (self .frame / 16 )))
3131
3232 def __str__ (self ):
3333 return self ._str_prefix () + self .name
3434
3535
36+ class PlayerSetupEvent (TrackerEvent ):
37+ """ Sent during game setup to help us organize players better """
38+ def __init__ (self , frames , data , build ):
39+ super (PlayerSetupEvent , self ).__init__ (frames )
40+
41+ #: The player id of the player we are setting up
42+ self .pid = data [0 ]
43+
44+ #: The type of this player. One of 1=human, 2=cpu, 3=neutral, 4=hostile
45+ self .type = data [1 ]
46+
47+ #: The user id of the player we are setting up. None of not human
48+ self .uid = data [2 ]
49+
50+ #: The slot id of the player we are setting up. None if not playing
51+ self .sid = data [3 ]
52+
53+
3654class PlayerStatsEvent (TrackerEvent ):
3755 """
3856 Player Stats events are generated for all players that were in the game even if they've since
@@ -181,10 +199,10 @@ def __init__(self, frames, data, build):
181199 self .resources_killed = self .minerals_killed + self .vespene_killed
182200
183201 #: The food supply currently used
184- self .food_used = clamp (self .stats [29 ])/ 4096.0
202+ self .food_used = clamp (self .stats [29 ]) / 4096.0
185203
186204 #: The food supply currently available
187- self .food_made = clamp (self .stats [30 ])/ 4096.0
205+ self .food_made = clamp (self .stats [30 ]) / 4096.0
188206
189207 #: The total mineral value of all active forces
190208 self .minerals_used_active_forces = clamp (self .stats [31 ])
@@ -211,7 +229,7 @@ def __init__(self, frames, data, build):
211229 self .ff_vespene_lost_technology = clamp (self .stats [38 ]) if build >= 26490 else None
212230
213231 def __str__ (self ):
214- return self ._str_prefix ()+ "{0: >15} - Stats Update" .format (self .player )
232+ return self ._str_prefix () + "{0: >15} - Stats Update" .format (self .player )
215233
216234
217235class UnitBornEvent (TrackerEvent ):
@@ -255,19 +273,24 @@ def __init__(self, frames, data, build):
255273 #: The player object that controls this unit. 0 means neutral unit
256274 self .unit_controller = None
257275
258- #: The x coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
259- #: Location prior to rounding marks the center of the unit footprint .
260- self .x = data [5 ] * 4
276+ #: The x coordinate of the center of the born unit's footprint. Only 4 point resolution
277+ #: prior to Starcraft Patch 2.1 .
278+ self .x = data [5 ]
261279
262- #: The y coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
263- #: Location prior to rounding marks the center of the unit footprint .
264- self .y = data [6 ] * 4
280+ #: The y coordinate of the center of the born unit's footprint. Only 4 point resolution
281+ #: prior to Starcraft Patch 2.1 .
282+ self .y = data [6 ]
265283
266284 #: The map location of the unit birth
267285 self .location = (self .x , self .y )
268286
287+ if build < 27950 :
288+ self .x = self .x * 4
289+ self .y = self .y * 4
290+ self .location = (self .x , self .y )
291+
269292 def __str__ (self ):
270- return self ._str_prefix ()+ "{0: >15} - Unit born {1}" .format (self .unit_upkeeper , self .unit )
293+ return self ._str_prefix () + "{0: >15} - Unit born {1}" .format (self .unit_upkeeper , self .unit )
271294
272295
273296class UnitDiedEvent (TrackerEvent ):
@@ -296,19 +319,39 @@ def __init__(self, frames, data, build):
296319 #: The player object of the that killed the unit. Not always available.
297320 self .killer = None
298321
299- #: The x coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
300- #: Location prior to rounding marks the center of the unit footprint .
301- self .x = data [3 ] * 4
322+ #: The x coordinate of the center of the dying unit's footprint. Only 4 point resolution
323+ #: prior to Starcraft Patch 2.1 .
324+ self .x = data [3 ]
302325
303- #: The y coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
304- #: Location prior to rounding marks the center of the unit footprint .
305- self .y = data [4 ] * 4
326+ #: The y coordinate of the center of the dying unit's footprint. Only 4 point resolution
327+ #: prior to Starcraft Patch 2.1 .
328+ self .y = data [4 ]
306329
307330 #: The map location the unit was killed at.
308331 self .location = (self .x , self .y )
309332
333+ #: The index portion of the killing unit's id. Available for build 27950+
334+ self .killer_unit_index = None
335+
336+ #: The recycle portion of the killing unit's id. Available for build 27950+
337+ self .killer_unit_recycle = None
338+
339+ #: The unique id of the unit doing the killing. Available for build 27950+
340+ self .killer_unit_id = None
341+
342+ if build < 27950 :
343+ self .x = self .x * 4
344+ self .y = self .y * 4
345+ self .location = (self .x , self .y )
346+ else :
347+ # Starcraft patch 2.1 introduced killer unit indexes
348+ self .killer_unit_index = data [5 ]
349+ self .killer_unit_recycle = data [6 ]
350+ if self .killer_unit_index :
351+ self .killer_unit_id = self .killer_unit_index << 18 | self .killer_unit_recycle
352+
310353 def __str__ (self ):
311- return self ._str_prefix ()+ "{0: >15} - Unit died {1}." .format (self .unit .owner , self .unit )
354+ return self ._str_prefix () + "{0: >15} - Unit died {1}." .format (self .unit .owner , self .unit )
312355
313356
314357class UnitOwnerChangeEvent (TrackerEvent ):
@@ -344,7 +387,7 @@ def __init__(self, frames, data, build):
344387 self .unit_controller = None
345388
346389 def __str__ (self ):
347- return self ._str_prefix ()+ "{0: >15} took {1}" .format (self .unit_upkeeper , self .unit )
390+ return self ._str_prefix () + "{0: >15} took {1}" .format (self .unit_upkeeper , self .unit )
348391
349392
350393class UnitTypeChangeEvent (TrackerEvent ):
@@ -372,7 +415,7 @@ def __init__(self, frames, data, build):
372415 self .unit_type_name = data [2 ].decode ('utf8' )
373416
374417 def __str__ (self ):
375- return self ._str_prefix ()+ "{0: >15} - Unit {0} type changed to {1}" .format (self .unit .owner , self .unit , self .unit_type_name )
418+ return self ._str_prefix () + "{0: >15} - Unit {0} type changed to {1}" .format (self .unit .owner , self .unit , self .unit_type_name )
376419
377420
378421class UpgradeCompleteEvent (TrackerEvent ):
@@ -395,7 +438,7 @@ def __init__(self, frames, data, build):
395438 self .count = data [2 ]
396439
397440 def __str__ (self ):
398- return self ._str_prefix ()+ "{0: >15} - {1}upgrade completed" .format (self .player , self .upgrade_type_name )
441+ return self ._str_prefix () + "{0: >15} - {1}upgrade completed" .format (self .player , self .upgrade_type_name )
399442
400443
401444class UnitInitEvent (TrackerEvent ):
@@ -434,19 +477,24 @@ def __init__(self, frames, data, build):
434477 #: The player object that controls this unit. 0 means neutral unit
435478 self .unit_controller = None
436479
437- #: The x coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
438- #: Location prior to rounding marks the center of the unit footprint .
439- self .x = data [5 ] * 4
480+ #: The x coordinate of the center of the init unit's footprint. Only 4 point resolution
481+ #: prior to Starcraft Patch 2.1 .
482+ self .x = data [5 ]
440483
441- #: The y coordinate of the location with 4 point resolution. E.g. 13.75 recorded as 12.
442- #: Location prior to rounding marks the center of the unit footprint .
443- self .y = data [6 ] * 4
484+ #: The y coordinate of the center of the init unit's footprint. Only 4 point resolution
485+ #: prior to Starcraft Patch 2.1 .
486+ self .y = data [6 ]
444487
445488 #: The map location the unit was started at
446489 self .location = (self .x , self .y )
447490
491+ if build < 27950 :
492+ self .x = self .x * 4
493+ self .y = self .y * 4
494+ self .location = (self .x , self .y )
495+
448496 def __str__ (self ):
449- return self ._str_prefix ()+ "{0: >15} - Unit initiated {1}" .format (self .unit_upkeeper , self .unit )
497+ return self ._str_prefix () + "{0: >15} - Unit initiated {1}" .format (self .unit_upkeeper , self .unit )
450498
451499
452500class UnitDoneEvent (TrackerEvent ):
@@ -470,7 +518,7 @@ def __init__(self, frames, data, build):
470518 self .unit = None
471519
472520 def __str__ (self ):
473- return self ._str_prefix ()+ "{0: >15} - Unit {1} done" .format (self .unit .owner , self .unit )
521+ return self ._str_prefix () + "{0: >15} - Unit {1} done" .format (self .unit .owner , self .unit )
474522
475523
476524class UnitPositionsEvent (TrackerEvent ):
@@ -491,17 +539,20 @@ def __init__(self, frames, data, build):
491539 #: A dict mapping of units that had their position updated to their positions
492540 self .units = dict ()
493541
494- #: A list of (unit_index, (x,y)) derived from the first_unit_index and items. Like the other
495- #: tracker events, these coordinates have 4 point resolution. (15,25) recorded as (12,24).
496- #: Location prior to rounding marks the center of the unit footprint.
542+ #: A list of (unit_index, (x,y)) derived from the first_unit_index and items. Prior to
543+ #: Starcraft Patch 2.1 the coordinates have 4 point resolution. (15,25) recorded as (12,24).
544+ #: Location prior to any rounding marks the center of the unit footprint.
497545 self .positions = list ()
498546
499547 unit_index = self .first_unit_index
500548 for i in range (0 , len (self .items ), 3 ):
501549 unit_index += self .items [i ]
502- x = self .items [i + 1 ]* 4
503- y = self .items [i + 2 ]* 4
550+ x = self .items [i + 1 ]
551+ y = self .items [i + 2 ]
552+ if build < 27950 :
553+ x = x * 4
554+ y = y * 4
504555 self .positions .append ((unit_index , (x , y )))
505556
506557 def __str__ (self ):
507- return self ._str_prefix ()+ "Unit positions update"
558+ return self ._str_prefix () + "Unit positions update"
0 commit comments