Skip to content

Commit a2060a4

Browse files
committed
Fixed a small bug and added player.is_ai
1 parent 25858de commit a2060a4

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

sc2reader/objects.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,16 @@ class PlayerSummary():
254254

255255
#: The index of the player in the game
256256
pid = int()
257+
258+
#: The index of the players team in the game
259+
teamid = int()
257260

258261
#: The race the player used
259262
race = str()
260263

264+
#: If the player is a computer
265+
is_ai = False
266+
261267
#: Battle.Net id of the player
262268
bnetid = int()
263269

@@ -283,8 +289,11 @@ def __init__(self, pid):
283289
self.pid = pid
284290

285291
def __str__(self):
286-
return '{} - {}/{}/'.format(self.race, self.subregion, self.bnetid)
287-
292+
if not self.is_ai:
293+
return '{} - {} - {}/{}/'.format(self.teamid, self.race, self.subregion, self.bnetid)
294+
else:
295+
return '{} - {} - AI'.format(self.teamid, self.race)
296+
288297
def get_stats(self):
289298
s = ''
290299
for k in self.stats:

sc2reader/resources.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class GameSummary(Resource):
426426
#: time2 seems to be more accurate than time1
427427
time2 = int()
428428

429-
#: Players, a list of :class`PlayerSummary` from the game
429+
#: Players, a dict of :class`PlayerSummary` from the game
430430
players = list()
431431

432432
#: Map image urls
@@ -437,6 +437,11 @@ class GameSummary(Resource):
437437

438438
def __init__(self, summary_file, filename=None, **options):
439439
super(GameSummary, self).__init__(summary_file, filename,**options)
440+
441+
self.players = list()
442+
self.image_urls = list()
443+
self.localization_urls = dict()
444+
440445
self.data = zlib.decompress(summary_file.read()[16:])
441446
self.parts = list()
442447
buffer = utils.ReplayBuffer(self.data)
@@ -466,18 +471,26 @@ def __init__(self, summary_file, filename=None, **options):
466471

467472
player = PlayerSummary(player_struct[0][0])
468473
player.race = RACE_CODES[''.join(reversed(player_struct[2]))]
469-
player.bnetid = player_struct[0][1][0][3]
470-
player.subregion = player_struct[0][1][0][2]
471-
472-
# int
473-
player.unknown1 = player_struct[0][1][0]
474-
# {0:long1, 1:long2}
475-
# Example:
476-
# { 0: 3405691582L, 1: 11402158793782460416L}
477-
player.unknown2 = player_struct[0][1][1]
474+
player.teamid = player_struct[1][0]
478475

476+
# Is the player an ai?
477+
if type(player_struct[0][1]) == type(int()):
478+
player.is_ai = True
479+
else:
480+
player.is_ai = False
481+
482+
player.bnetid = player_struct[0][1][0][3]
483+
player.subregion = player_struct[0][1][0][2]
484+
485+
# int
486+
player.unknown1 = player_struct[0][1][0]
487+
# {0:long1, 1:long2}
488+
# Example:
489+
# { 0: 3405691582L, 1: 11402158793782460416L}
490+
player.unknown2 = player_struct[0][1][1]
491+
479492
self.players.append(player)
480-
493+
481494
# Parse graph and stats stucts, for each player
482495
for p in self.players:
483496

0 commit comments

Comments
 (0)