-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
75 lines (55 loc) · 1.95 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Application imports.
import war2pud
# 3rd party imports.
import numpy
def main():
reader = war2pud.PUDFileReader('Garden of War.pud')
reader.loadassets()
pud = war2pud.model.PUD()
for section_name, data in reader.readsections():
if section_name == 'TYPE':
pud.type = data['type']
pud.id = data['id']
elif section_name == 'DESC':
pud.description = data
elif section_name == 'DIM ':
pud.width, pud.height = data[0], data[1]
elif section_name == 'VER ':
pud.version = data
elif section_name == 'OWNR':
for index, type in enumerate(data):
pud.players[index].type = reader._allowedplayertypes[type]
elif section_name == 'SIDE':
for index, race in enumerate(data):
pud.players[index].race = reader._allowedraces[race]['name']
elif section_name == 'AIPL':
for index, ai in enumerate(data):
pud.players[index].ai = reader._allowedai[ai]['name']
elif section_name == 'SGLD':
for index, gold in enumerate(data):
pud.players[index].gold = gold
elif section_name == 'SLBR':
for index, lumber in enumerate(data):
pud.players[index].lumber = lumber
elif section_name == 'SOIL':
for index, oil in enumerate(data):
pud.players[index].oil = oil
elif section_name == 'UNIT':
pud.units = data
elif section_name == 'ERA ':
pud.terrain = reader._terrains[data]['name']
elif section_name == 'MTXM':
tiles = numpy.zeros((pud.width, pud.height))
for h in range(pud.height):
for w in range(pud.width):
tiles[w, h] = data[w * h]
pud.tiles = tiles
print 'Type:', pud.type
print 'ID:', hex(pud.id)
print 'Version:', pud.version
print 'Size:', pud.width, 'x', pud.height
print 'Description:', pud.description
print 'Terrain:', pud.terrain
print 'Players:', sum([1 for p in pud.players if p.type != 'unused' and p.race != 'neutral'])
if __name__ == '__main__':
main()