Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fleet building to the planet object #1

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6c82f0b
use cached credentials if they exist
Mar 13, 2012
db7378c
first pass at interactive building.
Mar 13, 2012
f0e8b86
pull fleet building into main file
Mar 15, 2012
62142f7
port buildarcs to new infrastructure
Mar 15, 2012
2ca2bd7
remove redundant data from buildfleet
Mar 15, 2012
762b2aa
quick mode for buildfleet and better command line handling
Mar 18, 2012
2aabefc
Add ability to view planets by ID.
Mar 18, 2012
0a57eca
fix some planet loading bugs
Mar 18, 2012
b88dde9
collect and scrap scripts to move resources
Mar 23, 2012
3305e33
turn scripts into packages so we can recycle state.
Apr 1, 2012
6a414cd
get caching working for planets and fleets
Apr 5, 2012
3c18685
build all the fleets\!
Apr 7, 2012
ed6d293
add planet and fleet list caching.
Apr 13, 2012
7cf4ec1
support upgrades
Apr 15, 2012
e30f89f
game.py: a few placeholder urls
travisg Apr 13, 2012
5df0d1f
basicupgrades.py: build the usual upgrades
travisg Apr 15, 2012
407a89a
game.py: some additional routines to query the state of an upgrade
travisg Apr 15, 2012
545746d
killms.py: quick utility to kill upgrades at 0%
travisg Apr 15, 2012
f35da1e
basicupgrades.py: be a lot more conservative about when to build MS1 …
travisg Apr 15, 2012
acc1634
basicupgrades.py: add option to mind control
travisg Apr 15, 2012
34d72bd
basiupgrades.py: dont bother with mind control if its SL 90+
travisg Apr 15, 2012
fc9811b
add .gitignore
travisg Apr 16, 2012
d5da8f6
listplanets: small tweak to make it slightly more readable
travisg Apr 18, 2012
0bf48f2
basicupgrades: add option to build planetary defense
travisg Apr 18, 2012
3bfb9a5
basicupgrades: lower minimum level for mind control to 70
travisg Apr 18, 2012
9748b1b
basicupgrades: write the planet cache when done
travisg Apr 18, 2012
176315d
game.py: bump the recursion limit to avoid a crash when writing large…
travisg Apr 18, 2012
e0a2a9d
game.py: tons of updates
travisg Apr 22, 2012
a3b6df7
listplanets,listfleets: save the cache every 250 items, in case the h…
travisg Apr 22, 2012
3c184d2
basicupgrades.py: squelch an extraneous print
travisg Apr 22, 2012
b8c0a6e
arc.py: semi generic arc builder
travisg Apr 22, 2012
04de8dd
game.py: make building of ships be aware of the presence of Military …
travisg Apr 23, 2012
e90ad2c
basicupgrades.py: allow building of military bases
travisg Apr 23, 2012
8c87fe2
buildbulkfreighters.py: add a dry run option
travisg Apr 23, 2012
78c6e94
create routes and load sectors
Apr 21, 2012
b04cebe
arc.py: fix a bug where the source planets were not properly sorted b…
travisg Apr 24, 2012
8d52443
canbuild.py: show the planets can build a particular type of ship
travisg Apr 24, 2012
b227231
refreshcache.py: make sure the cache files are up to date
travisg Apr 24, 2012
ebe29a9
game.py: drastically reduce memory usage by making sure some parser o…
travisg Apr 26, 2012
492d5cf
listfleets,listplanets,refreshcache: save the planet and fleet cache …
travisg Apr 26, 2012
a4e7b2e
canbuild.py: print the total at the bottom
travisg Apr 28, 2012
688f9a0
arc.py: add -l <num> option to leave a certain number of arcs at each…
travisg Apr 28, 2012
925d266
pull travisg branch into this repository
Apr 30, 2012
b3ed644
game.py: handle unnamed routes properly
May 1, 2012
a023ac2
listplanets: show the upgrades and available upgrades as a comma deli…
travisg May 2, 2012
91451df
arc.py: use routes to specify complex source and sink regions
May 3, 2012
598516f
Merge branch 'master' of https://github.com/travisg/davesgalaxy
May 3, 2012
b3af141
game.py: renaming routes, add new routes to list of routes
May 4, 2012
c5819bd
end of planet and fleet pages is no longer and HTTP error.
May 13, 2012
b39db3e
make some thing less verbose ,and other more verbose
May 31, 2012
769dece
follow routes
May 31, 2012
112cf33
fix a bug in build_fleet() when the planet cannot build
Jun 4, 2012
4854690
fix a bad merger in patrol.py
Jun 4, 2012
ff0e34f
report on status of bulkfreighter fleets
Jul 1, 2012
8d3f63a
make sure sink planet is loaded
Jul 1, 2012
66fa0cf
cache the state of the empire for future off-line rendering
Jul 1, 2012
e7b57df
try to get output to look good in a bubble chart
Jul 1, 2012
c25773a
game.py: inital fixes for v2, jsut enough to get arc.py working.
Jul 5, 2012
08bc1c3
game.py: fix fleet disposition scraper.
Jul 6, 2012
3f3501b
support escorted arcs for a dangerous galaxy
Oct 15, 2012
09d6df2
default to detroyers instead of frigates, in a quatloo-constrained ga…
Oct 15, 2012
abdbff6
update ship costs. TODO: figure out the formula
Oct 15, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.dat
*.pyc
*.json
*.bak
Binary file added EvalJavascript.scpt
Binary file not shown.
201 changes: 201 additions & 0 deletions arc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#!/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("-m", "--maxarcs", dest="maxarcs",
action="store", type="int", default=-1, help="maximum arcs to build")
parser.add_option("-p", "--perplanet", dest="perplanet",
action="store", type="int", default=-1, help="max arcs per planet")
parser.add_option("-l", "--leave", dest="leave",
action="store", type="int", default=0, help="min of arcs to leave on planet")

parser.add_option("-x", "--sx", dest="sx",
action="store", type="float", help="source x coordinate")
parser.add_option("-y", "--sy", dest="sy",
action="store", type="float", help="source y coordinate")
parser.add_option("-r", "--sr", dest="sr",
action="store", type="float", default=20.0, help="builder radius to consider")

parser.add_option("-X", "--tx", dest="tx",
action="store", type="float", help="target x coordinate")
parser.add_option("-Y", "--ty", dest="ty",
action="store", type="float", help="target y coordinate")
parser.add_option("-R", "--tr", dest="tr",
action="store", type="float", help="target radius to consider")

parser.add_option("-s", "--source_route", dest="source",
type="string", help="route enclosing source")
parser.add_option("-S", "--sink_route", dest="sink",
type="string", help="route enclosing sink")

(options, args) = parser.parse_args()

if (options.sx == None or options.sy == None) and options.source == None:
print "not enough arguments"
parser.print_help()
sys.exit(1)

# if they didn't set tx/ty/tr, copy from sx/sy/sr
if options.tx == None: options.tx = options.sx
if options.ty == None: options.ty = options.sy
if options.tr == None: options.tr = options.sr
if options.sink == None: options.sink = options.source

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()

sink_shape = None
if options.sink != None:
sink_route = g.find_route(options.sink)
sink_shape = shape.Polygon(*(sink_route.points))
else:
sink_shape = shape.Circle([options.tx, options.ty], options.tr)

source_shape = None
if options.source != None:
source_route = g.find_route(options.source)
source_shape = shape.Polygon(*(source_route.points))
else:
source_shape = shape.Circle([options.sx, options.sy], options.sr)

BuildArcs(g, options.doupgrade, options.maxarcs,
options.perplanet, options.leave,
source_shape, sink_shape)

def BuildArcs(g, doupgrade, maxarcs, perplanet, leave, source, sink,
escort=True):
manifest = { 'arcs': 1 }
if escort:
manifest['frigates'] = 1

# find a list of potential arc builders
print "looking for arc builders..."
total_arcs = 0
arc_builders = []
for p in g.planets:
if source.inside(p.location):
p.load()
count = p.how_many_can_build(manifest)
if count and p.society > 30 and p.population > 20000:
print "planet " + str(p) + " can build " + str(count) + " arcs"
p.distance_to_target = sink.distance(p.location)
arc_builders.append(p)
total_arcs += count

# sort arc builders by distance to target
arc_builders = sorted(arc_builders, key=lambda planet: planet.distance_to_target)

print "found " + str(len(arc_builders)) + " arc building planets capable of building " + str(total_arcs) + " arcs"

# load the sectors around the target point
print "looking for unowned planets at target location..."
sect = g.load_sectors(sink.bounding_box())
#print sect
unowned_targets = sect["planets"]["unowned"]

# trim planets to ones strictly within the radius specified
foo = []
for p in unowned_targets:
if sink.inside(p.location):
foo.append(p)
unowned_targets = foo

print "found " + str(len(unowned_targets)) + " unowned planets"

# trim the list of targets to ones that dont have an arc already incoming
#
print "trimming list of unowned planets..."
for f in g.fleets:
f.load()
try:
if f.disposition == "Colonize":
# look for destinations in the NAME-NUMBER form
pnum = int(f.destination.split('-')[1])
for p in unowned_targets:
if p.planetid == pnum:
print "fleet " + str(f) + " already heading for dest"
unowned_targets.remove(p)
break
except:
pass

print "now have " + str(len(unowned_targets)) + " unowned planets"

# build arcs
built = 0
if len(unowned_targets) > 0:
print "building arcs..."
arc = manifest
done = False
for p in arc_builders:
if done:
break

# trim the number we can build by per-planet limit
count = p.how_many_can_build(arc);
if perplanet > 0 and count > perplanet:
count = perplanet

# trim the number we can build by the min left limit
count -= leave
if count <= 0:
continue

# for this builder, find the closest unowned planets
for t in unowned_targets:
t.distance_to_target = game.distance_between(p.location, t.location)
unowned_targets = sorted(unowned_targets, key=lambda planet: planet.distance_to_target)

print "planet " + str(p) + " can build " + str(count) + " arcs"
while not done and count > 0 and p.can_build(arc):
t = unowned_targets[0]
print "looking to build to " + str(t) + " distance: " + str(t.distance_to_target)
if doupgrade:
fleet = p.build_fleet(arc)
if fleet:
fleet.move_to_planet(t)
else:
print " failed to build fleet"
count = 0
break

# cull this target from the list
unowned_targets.remove(t)
built += 1
count -= 1
maxarcs -= 1
if (maxarcs == 0):
done = True
if len(unowned_targets) == 0:
done = True

if built > 0:
if doupgrade:
print "built %d arcs" % built
else:
print "would have built %d arcs" % built

g.write_planet_cache()
g.write_fleet_cache()

if __name__ == "__main__":
main()
77 changes: 77 additions & 0 deletions basicupgrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# vim: set ts=2 sw=2 expandtab:

import game
from optparse import OptionParser
import sys

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("-b", "--military", dest="military",
action="store_true", default=False, help="build military base")
parser.add_option("-m", "--mindcontrol", dest="mindcontrol",
action="store_true", default=False, help="build mind control")
parser.add_option("-d", "--defense", dest="defense",
action="store_true", default=False, help="build planetary defense")
(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()

BuildUpgrades(g, options.doupgrade, options.mindcontrol, options.defense, options.military)
g.write_planet_cache()

def BuildUpgrade(p, doupgrade, upgrade):
total = 0
if doupgrade:
if p.start_upgrade(upgrade):
print "\tbuilt %s at %s." % (upgrade, p.name)
total += 1
else:
print "\tfailed to build %s at %s." % (upgrade, p.name)
else:
print "\twould have built %s at %s." % (upgrade, p.name)
return total

def BuildUpgrades(g, doupgrade, domindcontrol, dodefense, domilitary):
has_pd = []
total = 0

for p in g.planets:
p.load()
print "looking at planet " + p.name
if p.can_upgrade('Trade Incentives') and p.population >= 5000:
total += BuildUpgrade(p, doupgrade, 'Trade Incentives')
if p.society > 10 and p.can_upgrade('Long Range Sensors 1') and p.population >= 10000:
total += BuildUpgrade(p, doupgrade, 'Long Range Sensors 1')
if p.society > 20 and p.can_upgrade('Long Range Sensors 2') and p.population >= 12000:
total += BuildUpgrade(p, doupgrade, 'Long Range Sensors 2')
if p.society > 30 and p.can_upgrade('Slingshot') and p.population >= 20000:
total += BuildUpgrade(p, doupgrade, 'Slingshot')
if p.society > 40 and p.can_upgrade('Matter Synth 1') and p.population >= 200000:
total += BuildUpgrade(p, doupgrade, 'Matter Synth 1')
if p.society > 50 and p.can_upgrade('Matter Synth 2') and p.population >= 500000:
total += BuildUpgrade(p, doupgrade, 'Matter Synth 2')
if domilitary and p.society > 50 and p.can_upgrade('Military Base') and p.population >= 5000000:
total += BuildUpgrade(p, doupgrade, 'Military Base')
if dodefense and p.can_upgrade('Planetary Defense 1') and p.population >= 5000000:
total += BuildUpgrade(p, doupgrade, 'Planetary Defense 1')
if domindcontrol and p.can_upgrade('Mind Control'):
if p.society < 90 and p.society > 70:
total += BuildUpgrade(p, doupgrade, 'Mind Control')

print "started %d upgrades" % total

if __name__ == "__main__":
main()
73 changes: 73 additions & 0 deletions buildarcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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[0], p.steel[0]
)
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()
Loading