forked from travisg/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildmerchantmen.py
executable file
·69 lines (57 loc) · 2.04 KB
/
buildmerchantmen.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
#!/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()
buildmerchantmen(g, options.skip_level)
def buildmerchantmen(g, level):
"""Build merchants at new planets that could have built an arc but didn't"""
merchant = {'merchantmen': 1}
arc = {'arcs': 1}
arc_cost = game.ship_cost(arc)
print 'Looking for planets younger than %d to build merchantmen.' % level
print 'Name, ID, Society, Money, Antimatter, Steel'
for p in g.planets:
p.load()
if p.society < level and p.steel[0] > arc_cost['steel']:
neighbors = None
if p.can_build(merchant):
neighbors = g.my_planets_near(p)
print '"%s", %d, %d, %d, %d, %d' % (
p.name, p.planetid, p.society, p.money, p.antimatter[0], p.steel[0]
)
while p.can_build(merchant) and len(neighbors) > 0:
try:
fleet = p.build_fleet(merchant,
interactive=False,
skip_check=True)
sink = neighbors.pop(0)['planet']
print "moving %d to %s" % (fleet.fleetid, sink.name)
fleet.move_to_planet(sink)
except:
# something blew up, move on
neighbors = []
if __name__ == "__main__":
main()