Skip to content

Commit f20aed1

Browse files
committed
Improve the available values on the PlayerStatsEvent
1 parent c0eeb2a commit f20aed1

File tree

1 file changed

+78
-31
lines changed

1 file changed

+78
-31
lines changed

sc2reader/events/tracker.py

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*-
22
import json
3+
import functools
4+
35
from sc2reader.utils import Length
46

7+
clamp = functools.partial(max, 0)
8+
59
class TrackerEvent(object):
610
def __init__(self, frames):
711
#: The frame of the game this event was applied
@@ -17,6 +21,13 @@ def __str__(self):
1721
return self._str_prefix() + self.name
1822

1923
class PlayerStatsEvent(TrackerEvent):
24+
"""
25+
Sometimes values in these fields can be negative.
26+
Clamp them to 0 until this is fixed.
27+
28+
An additional stats event is sent the frame that a player leaves.
29+
That player still gets normal stats events for the rest of the game though.
30+
"""
2031
name = 'PlayerStatsEvent'
2132

2233
def __init__(self, frames, data):
@@ -32,91 +43,127 @@ def __init__(self, frames, data):
3243
self.stats = data[1]
3344

3445
#: Minerals currently available to the player
35-
self.minerals_current = self.stats[0]
46+
self.minerals_current = clamp(self.stats[0])
3647

3748
#: Vespene currently available to the player
38-
self.vespene_current = self.stats[1]
49+
self.vespene_current = clamp(self.stats[1])
3950

4051
#: The rate the player is collecting minerals
41-
self.minerals_collection_rate = self.stats[2]
52+
self.minerals_collection_rate = clamp(self.stats[2])
4253

4354
#: The rate the player is collecting vespene
44-
self.vespene_collection_rate = self.stats[3]
55+
self.vespene_collection_rate = clamp(self.stats[3])
4556

4657
#: The number of active workers the player has
47-
self.workers_active_count = self.stats[4]
58+
self.workers_active_count = clamp(self.stats[4])
4859

4960
#: The total mineral cost of army units (buildings?) currently being built/queued
50-
self.minerals_used_in_progress_army = self.stats[5]
61+
self.minerals_used_in_progress_army = clamp(self.stats[5])
5162

5263
#: The total mineral cost of economy units (buildings?) currently being built/queued
53-
self.minerals_used_in_progress_economy = self.stats[6]
64+
self.minerals_used_in_progress_economy = clamp(self.stats[6])
5465

5566
#: The total mineral cost of technology research (buildings?) currently being built/queued
56-
self.minerals_used_in_process_technology = self.stats[7]
67+
self.minerals_used_in_progress_technology = clamp(self.stats[7])
68+
69+
#: The total mineral cost of all things in progress
70+
self.minerals_used_in_progress = self.minerals_used_in_progress_army + self.minerals_used_in_progress_economy + self.minerals_used_in_progress_technology
5771

5872
#: The total vespene cost of army units (buildings?) currently being built/queued
59-
self.vespene_used_in_progress_army = self.stats[8]
73+
self.vespene_used_in_progress_army = clamp(self.stats[8])
6074

6175
#: The total vespene cost of economy units (buildings?) currently being built/queued.
62-
self.vespene_used_in_progress_economy = self.stats[9]
76+
self.vespene_used_in_progress_economy = clamp(self.stats[9])
6377

6478
#: The total vespene cost of technology research (buildings?) currently being built/queued.
65-
self.vespene_used_in_progress_technology = self.stats[10]
79+
self.vespene_used_in_progress_technology = clamp(self.stats[10])
80+
81+
#: The total vespene cost of all things in progress
82+
self.vespene_used_in_progress = self.vespene_used_in_progress_army + self.vespene_used_in_progress_economy + self.vespene_used_in_progress_technology
83+
84+
#: The total cost of all things in progress
85+
self.resources_used_in_progress = self.minerals_used_in_progress + self.vespene_used_in_progress
6686

6787
#: The total mineral cost of current army units (buildings?)
68-
self.minerals_used_current_army = self.stats[11]
88+
self.minerals_used_current_army = clamp(self.stats[11])
6989

7090
#: The total mineral cost of current economy units (buildings?)
71-
self.minerals_used_current_economy = self.stats[12]
91+
self.minerals_used_current_economy = clamp(self.stats[12])
7292

7393
#: The total mineral cost of current technology research (buildings?)
74-
self.minerals_used_current_technology = self.stats[13]
94+
self.minerals_used_current_technology = clamp(self.stats[13])
95+
96+
#: The total mineral cost of all current things
97+
self.minerals_used_current = self.minerals_used_current_army + self.minerals_used_current_economy + self.minerals_used_current_technology
7598

7699
#: The total vespene cost of current army units (buildings?)
77-
self.vespene_used_current_army = self.stats[14]
100+
self.vespene_used_current_army = clamp(self.stats[14])
78101

79102
#: The total vespene cost of current economy units (buildings?)
80-
self.vespene_used_current_economy = self.stats[15]
103+
self.vespene_used_current_economy = clamp(self.stats[15])
81104

82105
#: The total vespene cost of current technology research (buildings?)
83-
self.vespene_used_current_technology = self.stats[16]
106+
self.vespene_used_current_technology = clamp(self.stats[16])
107+
108+
#: The total vepsene cost of all current things
109+
self.vespene_used_current = self.vespene_used_current_army + self.vespene_used_current_economy + self.vespene_used_current_technology
110+
111+
#: The total cost of all things current
112+
self.resources_used_current = self.minerals_used_current + self.vespene_used_current
84113

85114
#: The total mineral cost of all army units (buildings?) lost
86-
self.minerals_lost_army = self.stats[17]
115+
self.minerals_lost_army = clamp(self.stats[17])
116+
117+
#: The total mineral cost of all economy units (buildings?) lost
118+
self.minerals_lost_economy = clamp(self.stats[18])
87119

88-
#: The total minerals cost of all economy units (buildings?) lost
89-
self.minerals_lost_economy = self.stats[18]
120+
#: The total mineral cost of all technology research (buildings?) lost
121+
self.minerals_lost_technology = clamp(self.stats[19])
90122

91-
#: The total minerals cost of all technology research (buildings?) lost
92-
self.minerals_lost_technology = self.stats[19]
123+
#: The total mineral cost of all lost things
124+
self.minerals_lost = self.minerals_lost_army + self.minerals_lost_economy + self.minerals_lost_technology
93125

94126
#: The total vespene cost of all army units (buildings?) lost
95-
self.vespene_lost_army = self.stats[20]
127+
self.vespene_lost_army = clamp(self.stats[20])
96128

97129
#: The total vespene cost of all economy units (buildings?) lost
98-
self.vespene_lost_economy = self.stats[21]
130+
self.vespene_lost_economy = clamp(self.stats[21])
99131

100132
#: The total vespene cost of all technology research (buildings?) lost
101-
self.vespene_lost_technology = self.stats[22]
133+
self.vespene_lost_technology = clamp(self.stats[22])
134+
135+
#: The total vepsene cost of all lost things
136+
self.vespene_lost = self.vespene_lost_army + self.vespene_lost_economy + self.vespene_lost_technology
137+
138+
#: The total resource cost of all lost things
139+
self.resources_lost = self.minerals_lost + self.vespene_lost
102140

103141
#: The total mineral value of enemy army units (buildings?) killed
104-
self.minerals_killed_army = self.stats[23]
142+
self.minerals_killed_army = clamp(self.stats[23])
105143

106144
#: The total mineral value of enemy economy units (buildings?) killed
107-
self.minerals_killed_economy = self.stats[24]
145+
self.minerals_killed_economy = clamp(self.stats[24])
108146

109147
#: The total mineral value of enemy technology research (buildings?) killed
110-
self.minerals_killed_technology = self.stats[25]
148+
self.minerals_killed_technology = clamp(self.stats[25])
149+
150+
#: The total mineral value of all killed things
151+
self.minerals_killed = self.minerals_killed_army + self.minerals_killed_economy + self.minerals_killed_technology
111152

112153
#: The total vespene value of enemy army units (buildings?) killed
113-
self.vespene_killed_army = self.stats[26]
154+
self.vespene_killed_army = clamp(self.stats[26])
114155

115156
#: The total vespene value of enemy economy units (buildings?) killed
116-
self.vespene_killed_economy = self.stats[27]
157+
self.vespene_killed_economy = clamp(self.stats[27])
117158

118159
#: The total vespene value of enemy technology research (buildings?) killed
119-
self.vespene_killed_technology = self.stats[28]
160+
self.vespene_killed_technology = clamp(self.stats[28])
161+
162+
#: The total vespene cost of all killed things
163+
self.vespene_killed = self.vespene_killed_army + self.vespene_killed_economy + self.vespene_killed_technology
164+
165+
#: The total resource cost of all killed things
166+
self.resources_killed = self.minerals_killed + self.vespene_killed
120167

121168
#: The food supply currently used
122169
self.food_used = self.stats[29]

0 commit comments

Comments
 (0)