Skip to content

Commit

Permalink
Added a --ls-max option to 'run' command
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Jan 17, 2015
1 parent 15f2300 commit c85bd31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

[work in progress]
. (kfsone) Added a "--ls-max" option to "run" for filtering stations
. (kfsone) +140 Systems
. (tKE) "buy" sub-command now supports ship names (find a ship vendor)
. (kfsone) Partial code/documentation cleanup
. (kfsone) Added a "getRoute" function to TradeDB()
Expand Down
19 changes: 18 additions & 1 deletion commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
metavar='N',
type=int,
),
ParseArgument('--max-days-old', '-MD',
ParseArgument('--age', '--max-days-old', '-MD',
help='Maximum age (in days) of trade data to use.',
metavar='DAYS',
type=float,
Expand All @@ -113,6 +113,13 @@
type=float,
dest='lsPenalty'
),
ParseArgument('--ls-max',
help='Only consider stations upto this many ls from their star.',
metavar='LS',
dest='maxLs',
type=int,
default=0,
),
ParseArgument('--unique',
help='Only visit each station once.',
action='store_true',
Expand Down Expand Up @@ -372,12 +379,20 @@ def checkStationSuitability(cmdenv, station, src):
"requirement.".format(
src, station.name(),
))
mls = cmdenv.maxLs
if mls and station.lsFromStar > mls:
raise CommandLineError(
"{} station {} does not meet max-ls requirement "
"requirement.".format(
src, station.name(),
))


def filterStationSet(src, cmdenv, stnSet):
if not stnSet:
return stnSet
bm, mps = cmdenv.blackMarket, cmdenv.maxPadSize
mls = cmdenv.maxLs
for place in stnSet:
if not isinstance(place, Station):
continue
Expand All @@ -390,6 +405,8 @@ def filterStationSet(src, cmdenv, stnSet):
if bm and place.blackMarket != 'Y':
stnSet.remove(place)
continue
if mls and place.lsFromStar > mls:
stnSet.remove(place)
if not stnSet:
raise CommandLineError(
"No {} station met your criteria.".format(
Expand Down
1 change: 1 addition & 0 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ def considerStation(dstStation, dest):
maxLyPer=maxLyPer,
avoidPlaces=avoidPlaces,
maxPadSize=tdenv.padSize,
maxLsFromStar=tdenv.maxLs,
):
dstStation = dest.station
if dstStation is srcStation:
Expand Down
6 changes: 5 additions & 1 deletion tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,9 @@ def getDestinations(self,
maxLyPer=None,
avoidPlaces=None,
trading=False,
maxPadSize=None):
maxPadSize=None,
maxLsFromStar=0,
):
"""
Gets a list of the Station destinations that can be reached
from this Station within the specified constraints.
Expand Down Expand Up @@ -1410,6 +1412,8 @@ def getDestinations(self,
continue
if (maxPadSize and not station.checkPadSize(maxPadSize)):
continue
if (maxLsFromStar and station.lsFromStar > maxLsFromStar):
continue
destStations.append(
Destination(node.system,
station,
Expand Down

0 comments on commit c85bd31

Please sign in to comment.