Skip to content

Commit 3eebdaa

Browse files
committed
Continued parsing build orders, nothing completed yet
1 parent c1979f6 commit 3eebdaa

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

extract.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
'Structures Built',
3333
'Structures Razed Count'
3434
]
35+
# Obviously not complete
36+
abilities = {
37+
0x5602 : 'Warp Gate',
38+
0x3402 : 'Extended Thermal Lance',
39+
0x4402 : 'Metabolic Boost',
40+
41+
}
3542

3643
def getRealm(str):
3744
if str == '\x00\x00S2':
@@ -95,12 +102,23 @@ def toUnit(bo_unit):
95102
if bo_unit >> 24 == 1:
96103
return {'name':unitData.type(i).name, 'id':hex(i)}
97104
return None
105+
def toAbility(bo_ability):
106+
#print(hex(flip_int(bo_unit, 4)))
107+
i = ((bo_ability & 0xff) << 8) | 0x02
108+
if bo_ability >> 24 == 2:
109+
return {'name':abilities[i] if i in abilities else "Unknown ability", 'type':hex(i), 'id':hex(bo_ability)}
110+
111+
return None
98112
def getBuildOrder(unit_structs, index):
99113
''' [ {supply, time, unit} ] '''
100114
bo = []
101115
for unit_struct in unit_structs:
102116
for u in unit_struct:
103-
unit = toUnit(u[0][1])
117+
# is unit
118+
if u[0][1] >> 24 == 1:
119+
unit = toUnit(u[0][1])
120+
elif u[0][1] >> 24 == 2:
121+
unit = toAbility(u[0][1])
104122
if not unit:
105123
continue
106124
for entry in u[1][index]:
@@ -109,7 +127,7 @@ def getBuildOrder(unit_structs, index):
109127
'total_supply' : entry[1]&0xff,
110128
'time' : toTime(entry[2]),
111129
'time_hex' : hex(entry[2]>>8),
112-
'unit' : unit,
130+
'order' : unit,
113131
'build_index' : entry[1] >> 16,
114132
'struct_as_hex' : {0:hex(entry[0]),
115133
1:hex(entry[1]),
@@ -118,6 +136,20 @@ def getBuildOrder(unit_structs, index):
118136
})
119137
bo.sort(key=lambda x: x['build_index'])
120138
return bo
139+
def getBuildOrderOthers(struct):
140+
ret = list()
141+
for x in struct:
142+
if x[1][1] > 0xffff:
143+
ret.append({
144+
'type':x[1][1],
145+
'type_hex':hex(x[1][1]),
146+
'player':x[2][0][1],
147+
'others':[x[2][0][2],
148+
#x[2][2][1],
149+
#x[2][2][2],
150+
x[4]]
151+
})
152+
return ret
121153

122154
def getBuildOrders(data):
123155
unit_structs = [x[0] for x in data[5:]]
@@ -128,7 +160,7 @@ def getBuildOrders(data):
128160
players[i] = bo
129161
all = [u for p in players for u in players[p]]
130162
all.sort(key=lambda x: x['build_index'])
131-
return [players, all]
163+
return [players, all, getBuildOrderOthers(data[1][0])]
132164

133165
def main():
134166
arg = sys.argv[2] if len(sys.argv) >= 3 else "pprint"
@@ -146,5 +178,13 @@ def main():
146178
pprint.PrettyPrinter(indent=2).pprint(data)
147179
elif arg == "bo":
148180
pprint.PrettyPrinter(indent=2).pprint(getBuildOrders(data))
149-
181+
elif arg == "bo2":
182+
bos = getBuildOrders(data)[0]
183+
for p in bos:
184+
for u in bos[p]:
185+
print("{}:{} {} {}/{}".format(u['time'] / 60,
186+
u['time'] % 60,
187+
u['unit']['name'],
188+
u['supply'],
189+
u['total_supply']))
150190
main()

0 commit comments

Comments
 (0)