3
3
4
4
class TrackerEvent (object ):
5
5
def __init__ (self , frames ):
6
+ #: The frame of the game this event was applied
6
7
self .frame = frames
7
8
8
9
def __str__ (self ):
10
+ """ Dumps the event data to a json string. """
9
11
return json .dumps (self .__dict__ )
10
12
11
13
def load_context (self , replay ):
@@ -21,6 +23,9 @@ def __init__(self, frames, data):
21
23
#: Id of the player the stats are for
22
24
self .pid = data [0 ]
23
25
26
+ #: The Player object that these stats apply to
27
+ self .player = None
28
+
24
29
#: An ordered list of all the available stats
25
30
self .stats = data [1 ]
26
31
@@ -142,6 +147,9 @@ def __init__(self, frames, data):
142
147
#: The unique id of the unit being born
143
148
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
144
149
150
+ #: The unit object that was born
151
+ self .unit = None
152
+
145
153
#: The unit type name of the unit being born
146
154
self .unit_type_name = data [2 ]
147
155
@@ -151,6 +159,12 @@ def __init__(self, frames, data):
151
159
#: The id of the player that pays upkeep for this unit.
152
160
self .upkeep_pid = data [4 ]
153
161
162
+ #: The player object that pays upkeep for this one. 0 means neutral unit
163
+ self .unit_upkeeper = None
164
+
165
+ #: The player object that controls this unit. 0 means neutral unit
166
+ self .unit_controller = None
167
+
154
168
#: The x coordinate of the location
155
169
self .x = data [5 ]
156
170
@@ -168,14 +182,18 @@ def load_context(self, replay):
168
182
self .unit_upkeeper = replay .player [self .upkeep_pid ]
169
183
170
184
if self .unit_id in replay .objects :
185
+ # This can happen because game events are done first
171
186
self .unit = replay .objects [self .unit_id ]
172
187
else :
173
188
# TODO: How to tell if something is hallucination?
174
189
self .unit = replay .datapack .create_unit (self .unit_id , self .unit_type_name , 0 , self .frame )
175
- self .unit .location = self .location
176
190
replay .objects [self .unit_id ] = self .unit
177
191
replay .active_units [self .unit_id_index ] = self .unit
178
192
193
+ self .unit .location = self .location
194
+ self .unit .birth = self .frame
195
+ self .unit .owner = self .unit_upkeeper
196
+
179
197
180
198
class UnitDiedEvent (TrackerEvent ):
181
199
name = 'UnitDiedEvent'
@@ -192,9 +210,15 @@ def __init__(self, frames, data):
192
210
#: The unique id of the unit being killed
193
211
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
194
212
213
+ #: The unit object that died
214
+ self .unit = None
215
+
195
216
#: The id of the player that killed this unit. None when not available.
196
217
self .killer_pid = data [2 ]
197
218
219
+ #: The player object of the that killed the unit. Not always available.
220
+ self .killer = None
221
+
198
222
#: The x coordinate of the location
199
223
self .x = data [3 ]
200
224
@@ -207,12 +231,11 @@ def __init__(self, frames, data):
207
231
def load_context (self , replay ):
208
232
if self .unit_id in replay .objects :
209
233
self .unit = replay .objects [self .unit_id ]
234
+ self .unit .death = self .frame
210
235
self .unit .location = self .location
211
236
del replay .active_units [self .unit_id_index ]
212
237
else :
213
- # Create a new unit, but we don't have a type name map yet!
214
238
print "Unit died before it was born!"
215
- self .unit = None
216
239
217
240
if self .killer_pid : # This field isn't always available
218
241
self .killer = replay .player [self .killer_pid ]
@@ -233,26 +256,33 @@ def __init__(self, frames, data):
233
256
#: The unique id of the unit changing ownership
234
257
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
235
258
259
+ #: The unit object that is affected by this event
260
+ self .unit = None
261
+
236
262
#: The new id of the player that controls this unit.
237
263
self .control_pid = data [2 ]
238
264
239
265
#: The new id of the player that pays upkeep for this unit.
240
266
self .upkeep_pid = data [3 ]
241
267
268
+ #: The player object that pays upkeep for this one. 0 means neutral unit
269
+ self .unit_upkeeper = None
270
+
271
+ #: The player object that controls this unit. 0 means neutral unit
272
+ self .unit_controller = None
242
273
243
274
def load_context (self , replay ):
244
- if self .control_pid : # 0 means neutral unit
275
+ if self .control_pid :
245
276
self .unit_controller = replay .player [self .control_pid ]
246
277
247
- if self .upkeep_pid : # 0 means neutral unit
278
+ if self .upkeep_pid :
248
279
self .unit_upkeeper = replay .player [self .upkeep_pid ]
249
280
250
281
if self .unit_id in replay .objects :
251
282
self .unit = replay .objects [self .unit_id ]
283
+ self .unit .owner = self .unit_upkeeper
252
284
else :
253
- # Create a new unit, but we don't have a type name map yet!
254
285
print "Unit owner changed before it was born!"
255
- self .unit = None
256
286
257
287
258
288
class UnitTypeChangeEvent (TrackerEvent ):
@@ -270,6 +300,9 @@ def __init__(self, frames, data):
270
300
#: The unique id of the unit changing type
271
301
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
272
302
303
+ #: The unit object that was changed
304
+ self .unit = None
305
+
273
306
#: The the new unit type name
274
307
self .unit_type_name = data [2 ]
275
308
@@ -279,7 +312,6 @@ def load_context(self, replay):
279
312
replay .datapack .change_type (self .unit , self .unit_type_name , self .frame )
280
313
else :
281
314
print "Unit type changed before it was born!"
282
- self .unit = None
283
315
284
316
285
317
class UpgradeCompleteEvent (TrackerEvent ):
@@ -291,6 +323,9 @@ def __init__(self, frames, data):
291
323
#: The player that completed the upgrade
292
324
self .pid = data [0 ]
293
325
326
+ #: The Player object that completed the upgrade
327
+ self .player = None
328
+
294
329
#: The name of the upgrade
295
330
self .upgrade_type_name = data [1 ]
296
331
@@ -319,6 +354,9 @@ def __init__(self, frames, data):
319
354
#: The unique id of the stated unit
320
355
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
321
356
357
+ #: The unit object that was started (e.g. started to warp in)
358
+ self .unit = None
359
+
322
360
#: The the new unit type name
323
361
self .unit_type_name = data [2 ]
324
362
@@ -328,6 +366,12 @@ def __init__(self, frames, data):
328
366
#: The id of the player that pays upkeep for this unit.
329
367
self .upkeep_pid = data [4 ]
330
368
369
+ #: The player object that pays upkeep for this one. 0 means neutral unit
370
+ self .unit_upkeeper = None
371
+
372
+ #: The player object that controls this unit. 0 means neutral unit
373
+ self .unit_controller = None
374
+
331
375
#: The x coordinate of the location
332
376
self .x = data [5 ]
333
377
@@ -345,14 +389,17 @@ def load_context(self, replay):
345
389
self .unit_upkeeper = replay .player [self .upkeep_pid ]
346
390
347
391
if self .unit_id in replay .objects :
392
+ # This can happen because game events are done first
348
393
self .unit = replay .objects [self .unit_id ]
349
394
else :
350
395
# TODO: How to tell if something is hallucination?
351
396
self .unit = replay .datapack .create_unit (self .unit_id , self .unit_type_name , 0 , self .frame )
352
397
replay .objects [self .unit_id ] = self .unit
353
398
replay .active_units [self .unit_id_index ] = self .unit
354
399
400
+ self .unit .owner = self .unit_upkeeper
355
401
self .unit .location = self .location
402
+ self .unit .birth = self .frame
356
403
357
404
358
405
class UnitDoneEvent (TrackerEvent ):
@@ -370,12 +417,14 @@ def __init__(self, frames, data):
370
417
#: The unique id of the finished unit
371
418
self .unit_id = self .unit_id_index << 16 | self .unit_id_recycle
372
419
420
+ #: The unit object that was finished
421
+ self .unit = None
422
+
373
423
def load_context (self , replay ):
374
424
if self .unit_id in replay .objects :
375
425
self .unit = replay .objects [self .unit_id ]
376
426
else :
377
427
print "Unit done before it was started!"
378
- self .unit = None
379
428
380
429
381
430
class UnitPositionsEvent (TrackerEvent ):
@@ -384,30 +433,24 @@ class UnitPositionsEvent(TrackerEvent):
384
433
def __init__ (self , frames , data ):
385
434
super (UnitPositionsEvent , self ).__init__ (frames )
386
435
387
- #: ???
436
+ #: The starting unit index point.
388
437
self .first_unit_index = data [0 ]
389
438
390
- #: ???
439
+ #: An ordered list of unit/point data interpreted as below.
391
440
self .items = data [1 ]
392
441
393
-
442
+ #: A list of units that had their position updated by this event
394
443
self .units = list ()
395
444
445
+ #: A list of (unit_index, (x,y)) derived from the first_unit_index and items
396
446
self .positions = list ()
447
+
397
448
unit_index = self .first_unit_index
398
449
for i in range (0 , len (self .items ), 3 ):
399
450
unit_index += self .items [i ]
400
451
x = self .items [i + 1 ]* 4
401
452
y = self .items [i + 2 ]* 4
402
453
self .positions .append ((unit_index , (x ,y )))
403
- """ We need to be able to find units without the recycle id, can't do this yet!
404
- unitTagIndex = event['m_firstUnitIndex']
405
- for i in xrange(len(event['m_items']) / 3):
406
- unitTagIndex += event['m_items'][i * 3 + 0]
407
- x = event['m_items'][i * 3 + 1] * 4
408
- y = event['m_items'][i * 3 + 2] * 4
409
- # the unit with unitTagIndex is now at coordinate (x, y)
410
- """
411
454
412
455
def load_context (self , replay ):
413
456
for unit_index , (x ,y ) in self .positions :
0 commit comments