Skip to content

Commit

Permalink
"run" --from now accepts a System name
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 6, 2014
1 parent 00cb850 commit 1d3df72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.1.5 Dec 04 2014
. (kfsone) "run" --from will now accept a System name
. (kfsone) "update" GUI will now do some sanity checking on prices
. (kfsone) "nav" with -vv will show direct distance left to destination
. (kfsone) Minor speed improvements to "nav"
Expand Down
31 changes: 24 additions & 7 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
),
ParseArgument('--from',
help='Starting system/station.',
dest='origin',
dest='starting',
metavar='STATION',
),
ParseArgument('--to',
Expand Down Expand Up @@ -219,8 +219,17 @@ def validateRunArguments(tdb, cmdenv):
if cmdenv.maxJumpsPer < 0:
raise CommandLineError("Negative jumps: you're already there?")

if cmdenv.startStation:
cmdenv.origins = [ cmdenv.startStation ]
if cmdenv.origPlace:
if isinstance(cmdenv.origPlace, System):
cmdenv.origins = list(cmdenv.origPlace.stations)
if not cmdenv.origins:
raise CommandLineError(
"No stations at origin system, {}"
.format(cmdenv.origPlace.name())
)
else:
cmdenv.origins = [ cmdenv.origPlace ]
cmdenv.startStation = cmdenv.origPlace
else:
cmdenv.origins = [ station for station in tdb.stationByID.values() ]

Expand All @@ -245,7 +254,7 @@ def validateRunArguments(tdb, cmdenv):
# How many of the hops do not have pre-determined stations. For example,
# when the user uses "--from", they pre-determine the starting station.
fixedRoutePoints = 0
if cmdenv.startStation:
if cmdenv.origPlace:
fixedRoutePoints += 1
if cmdenv.destPlace:
fixedRoutePoints += 1
Expand Down Expand Up @@ -298,6 +307,14 @@ def validateRunArguments(tdb, cmdenv):
if stopStn and stopStn.itemCount == 0:
raise NoDataError("End station {} doesn't have any price data.".format(
stopStn.name()))
if cmdenv.origins:
tradingOrigins = [
stn for stn in cmdenv.origins
if stn.itemCount > 0
]
if not tradingOrigins:
raise NoDataError("No price data at origin stations.")
cmdenv.origins = tradingOrigins

if startStn:
tdb.loadStationTrades([startStn.ID])
Expand All @@ -324,7 +341,7 @@ def run(results, cmdenv, tdb):

from tradecalc import TradeCalc, Route

startStn, viaSet = cmdenv.startStation, cmdenv.viaSet
origPlace, viaSet = cmdenv.origPlace, cmdenv.viaSet

avoidPlaces = cmdenv.avoidPlaces

Expand All @@ -346,15 +363,15 @@ def run(results, cmdenv, tdb):
]
numHops = cmdenv.hops
lastHop = numHops - 1
viaStartPos = 1 if startStn else 0
viaStartPos = 1 if origPlace else 0
cmdenv.maxJumps = None

cmdenv.DEBUG0(
"From {fromStn}, To {toStn}, Via {via}, "
"Cap {cap}, Credits {cr}, "
"Hops {hops}, Jumps/Hop {jumpsPer}, Ly/Jump {lyPer:.2f}"
"\n".format(
fromStn=startStn.name() if startStn else 'Anywhere',
fromStn=origPlace.name() if origPlace else 'Anywhere',
toStn=str([s.name() for s in stopStations]) if stopStations else 'Anywhere',
via=';'.join([stn.name() for stn in viaSet]) or 'None',
cap=cmdenv.capacity,
Expand Down

0 comments on commit 1d3df72

Please sign in to comment.