forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
listplanets
executable file
·58 lines (49 loc) · 1.52 KB
/
listplanets
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
#!/usr/bin/env python
# vim: set ts=2 sw=2 expandtab:
import game
from optparse import OptionParser
import sys
parser = OptionParser()
parser.add_option("-U", "--username", dest="username",
help="username of login")
parser.add_option("-P", "--password", dest="password",
help="password for login")
(options, args) = parser.parse_args()
g=game.Galaxy()
if options.username and options.password:
# explicit login
g.login(options.username, options.password, force=True)
else:
# try to pick up stored credentials
g.login()
count = 0
print 'Name, ID, Society, Population, Money, Food, Steel, Tax, Tarif, Distance, Upgrades, Upgrades Avail'
for p in g.planets:
if p.load():
count += 1
if (count % 100) == 0:
g.write_planet_cache()
# build list of upgrades
upgrades = ""
showcomma = False
for idx, status in enumerate(p.upgrades):
if status > game.UPGRADE_AVAILABLE:
if showcomma:
upgrades += ","
upgrades += game.UPGRADES[idx]
showcomma = True
# build list of available upgrades
upgrades_avail = ""
showcomma = False
for idx, status in enumerate(p.upgrades):
if status == game.UPGRADE_AVAILABLE:
if showcomma:
upgrades_avail += ","
upgrades_avail += "%s" % game.UPGRADES[idx]
showcomma = True
print '"%s", %d, %d, %d, %d, %d, %d, %d, %.1f, %.1f, {%s}, {%s}' % (
p.name, p.owner, p.planetid, p.society, p.population,
p.money, p.food, p.steel, p.tax, p.tarif,
upgrades, upgrades_avail
)
g.write_planet_cache()