forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildarcs.py
executable file
·73 lines (60 loc) · 2.05 KB
/
buildarcs.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
#!/usr/bin/env python
import game
from optparse import OptionParser
import sys
def default_input(prompt, default):
response = raw_input(prompt)
if response == '':
return default
return response.lower()
def main():
parser = OptionParser()
parser.add_option("-U", "--username", dest="username",
help="username of login")
parser.add_option("-P", "--password", dest="password",
help="password for login")
parser.add_option("-s", "--skip_level", dest="skip_level",
help="maximum society level to initiate a skip arc",
default=20,
type="int")
(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()
buildarcs(g, options.skip_level)
def buildarcs(g, level):
escorted = {'arcs': 1, 'frigates': 1}
solo = {'arcs': 1}
SOLO_PROMPT = 'build solo arc at "%s"? (Y/v/n): '
ESCORTED_PROMPT = 'build escorted arc at "%s"? (Y/v/n): '
print 'Looking for planets younger than %d to build arcs.' % level
print 'Name, ID, Society, Money, Antimatter, Steel'
for p in g.planets:
p.load()
if p.society < level:
confirm = 'y'
if p.can_build(solo):
print '"%s", %d, %d, %d, %d, %d' % (
p.name, p.planetid, p.society, p.money, p.antimatter, p.steel
)
while confirm == 'y' and p.can_build(solo):
if p.can_build(escorted):
confirm = default_input(ESCORTED_PROMPT % (p.name), 'y')
if confirm == 'y':
p.build_fleet(escorted, interactive=True)
elif confirm == 'v':
p.view()
confirm = 'y'
else:
confirm = default_input(SOLO_PROMPT % (p.name), 'y')
if confirm == 'y':
p.build_fleet(solo, interactive=True)
elif confirm == 'v':
p.view()
confirm = 'y'
if __name__ == "__main__":
main()