Skip to content

Commit d64df3b

Browse files
committed
Finally straighten out all these player list/dicts
Now as follows: * human/humans -> human entities, indexed by uid * computer/computers -> computer entities, indexed by pid * player/players -> actually playing in the game, indexed by pid * observer/observers -> observing the game, indexed by uid * entities -> players + observers || humans + computers, indexed by pid * client/clients - (deprecated) same as human/humans * people/person - (deprecated) same as entity/entities
1 parent 7d55fd1 commit d64df3b

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

sc2reader/engine/plugins/selection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SelectionTracker(object):
1212
1313
Exposes the following interface, directly integrated into the player:
1414
15-
for person in replay.people:
15+
for person in replay.entities:
1616
total_errors = person.selection_errors
1717
1818
selection = person.selection
@@ -24,7 +24,7 @@ class SelectionTracker(object):
2424
# TODO: list a few error inducing sitations
2525
"""
2626
def handleInitGame(self, event, replay):
27-
for person in replay.people:
27+
for person in replay.entities:
2828
person.selection = dict()
2929
for i in range(11):
3030
person.selection[i] = list()

sc2reader/factories/plugins/replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def SelectionTracker(replay):
126126
debug = replay.opt.debug
127127
logger = log_utils.get_logger(SelectionTracker)
128128

129-
for person in replay.people:
129+
for person in replay.entities:
130130
# TODO: A more robust person interface might be nice
131131
person.selection_errors = 0
132132
player_selections = GameState(PlayerSelection())

sc2reader/resources.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class Replay(Resource):
164164
#: only the human players from the :attr:`people` list
165165
humans = list()
166166

167+
#: A list of :class:`Computer` objects from the game.
168+
computers = list()
169+
167170
#: A list of all the chat message events from the game
168171
messages = list()
169172

@@ -211,10 +214,19 @@ def __init__(self, replay_file, filename=None, load_level=4, engine=sc2reader.en
211214
self.events = list()
212215
self.events_by_type = defaultdict(list)
213216
self.teams, self.team = list(), dict()
214-
self.players, self.player = list(), utils.PersonDict()
217+
218+
self.player = utils.PersonDict()
219+
self.observer = utils.PersonDict()
220+
self.human = utils.PersonDict()
221+
self.computer = utils.PersonDict()
222+
self.entity = utils.PersonDict()
223+
224+
self.players = list()
215225
self.observers = list() # Unordered list of Observer
216-
self.people, self.humans = list(), list() # Unordered list of Players+Observers
217-
self.person = utils.PersonDict() # Maps pid to Player/Observer
226+
self.humans = list()
227+
self.computers = list()
228+
self.entities = list()
229+
218230
self.attributes = defaultdict(dict)
219231
self.messages = list()
220232
self.recorder = None # Player object
@@ -397,14 +409,19 @@ def get_team(team_id):
397409
entity.team.players.append(entity)
398410
self.players.append(entity)
399411
self.player[entity.pid] = entity
400-
401412
else:
402413
self.observers.append(entity)
414+
self.observer[entity.uid] = entity
403415

404416
if entity.is_human:
405-
self.person[entity.pid] = entity
406-
self.client[entity.uid] = entity
407-
self.people.append(entity)
417+
self.humans.append(entity)
418+
self.human[entity.uid] = entity
419+
else:
420+
self.computers.append(entity)
421+
self.computer[entity.pid] = entity
422+
423+
# Index by pid so that we can match events to players in pre-HotS replays
424+
self.entity[entity.pid] = entity
408425

409426
# Pull results up for teams
410427
for team in self.teams:
@@ -418,7 +435,12 @@ def get_team(team_id):
418435
team.result = 'Unknown'
419436

420437
self.teams.sort(key=lambda t: t.number)
421-
self.humans = self.clients = self.people
438+
439+
# These are all deprecated
440+
self.clients = self.humans
441+
self.people = self.entities
442+
self.client = self.human
443+
self.person = self.entity
422444

423445
self.real_type = real_type(self.teams)
424446

sc2reader/scripts/sc2parse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def main():
4545
if not args.one_each or replay.is_ladder:
4646
replay = sc2reader.load_replay(path, debug=True)
4747

48-
client_pids = set([client.pid for client in replay.clients])
48+
human.pids = set([human.pid for human in replay.humans])
4949
event_pids = set([event.player.pid for event in replay.events if getattr(event, 'player', None)])
5050
player_pids = set([player.pid for player in replay.players if player.is_human])
5151
ability_pids = set([event.player.pid for event in replay.events if 'AbilityEvent' in event.name])
52-
if client_pids != event_pids:
53-
print('Event Pid problem! pids={pids} but event pids={event_pids}'.format(pids=client_pids, event_pids=event_pids))
52+
if human.pids != event_pids:
53+
print('Event Pid problem! pids={pids} but event pids={event_pids}'.format(pids=human.pids, event_pids=event_pids))
5454
print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))
5555
elif player_pids != ability_pids:
5656
print('Ability Pid problem! pids={pids} but event pids={event_pids}'.format(pids=player_pids, event_pids=ability_pids))

0 commit comments

Comments
 (0)