forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendhome
executable file
·63 lines (50 loc) · 1.77 KB
/
sendhome
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
#!/usr/bin/env python
# vim: set ts=2 sw=2 expandtab:
import game
from optparse import OptionParser
import sys
import shape
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("-n", "--noupgrade", dest="doupgrade",
action="store_false", default=True, help="dry run")
parser.add_option("-d", "--disposition", dest="disposition",
type="string", default="", help="only for fleets with this disposition")
parser.add_option("-s", "--source_route", dest="source",
type="string", help="route enclosing source")
(options, args) = parser.parse_args()
if options.source == None:
print "not enough arguments"
parser.print_help()
sys.exit(1)
print "options " + str(options)
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()
try:
source_route = g.find_route(options.source)
source_shape = shape.Polygon(*(source_route.points))
except:
print "could't find source route"
sys.exit(1)
SendHome(g, options.doupgrade, source_shape, options.disposition)
def SendHome(g, doupgrade, source, disposition=""):
g.load_fleet_cache()
for f in g.fleets:
f.load()
if source.inside(f.coords):
if disposition == "" or f.disposition == disposition:
print "moving fleet %s to home planet %s" % (f, f.home)
if doupgrade:
success = f.move_to_planet(f.home)
g.write_fleet_cache()
if __name__ == "__main__":
main()