diff --git a/README.md b/README.md index cfde5f7f..e79f231e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ You're in a ship with 8 cargo spaces that can make 8.56 ly per jump; you're will If we ran this, TD would search the galaxy for trade runs. But it could take us days to reach some of them. So lets say we're currently at Kummer City in the Andere system. - trade.py run --from "andere/kummer city" + trade.py run --from "andere/kummer city" --credits 5000 --capacity 8 --ly-per 8.56 --jumps 2 --hops 2 (The above represents a single line) @@ -121,7 +121,7 @@ There's a lot going on here: . Fine detail about stations (distance from star, has black market, etc), . "score" tells us how TD ranked this based on factors such as total gain, supercruise distances, number of jumps, etc, . Expected purchase/sale costs and rough data age (some crowd-sourced data can appear to be very old if it hasn't changed), - . How much we expect to gain each hop and the cr/ton we make, + . How much we expect to gain each hop and the cr/ton we make, Most users tend to use the in-game route planner and prefer the cleaner "--summary" presentation: @@ -442,6 +442,14 @@ For additional help on a specific command, such as 'update' use --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + --black-market --bm Only consider stations that have a black market. @@ -763,14 +771,14 @@ To take maximum advantage of Maddavo's services, you should consider using "-O c ##Elite Dangerous Mobile API import plugin: -Frontier provides an API for their mobile app. This can be used to report accurate information about your currently docked station such as market prices, shipyard, and other station information. The "edapi" plugin provides a way to accurately import this information into your prices file and optionally report the market prices to EDDN. +Frontier provides an API for their mobile app. This can be used to report accurate information about your currently docked station such as market prices, shipyard, and other station information. The "edapi" plugin provides a way to accurately import this information into your prices file and optionally report the market prices to EDDN. ###Basic usage: trade.py import --plug edapi This will query the API for information abotu your currently docked station and import any market prices and shipyard information - available. You will be prompted to enter any missing station information. + available. You will be prompted to enter any missing station information. trade.py imp -P edapi -O eddn This will do the same thing, but also post your market, shipyard, and @@ -834,7 +842,8 @@ Lists items bought / sold at a given station; with --detail (-v) also includes t Provides details of routes without worrying about trade. By default, if given a ship, it uses the maximum dry range of the ship. Use `--full` if you want to restrict to routes with a full cargo hold. - trade.py nav [-q | -v] [--ly-per] from to [--avoid] [--stations] [--no-planet] + trade.py nav [-q | -v] [--ly-per] from to + [--avoid] [--stations] [--no-planet | --planetary YN?] ###Options: @@ -860,7 +869,7 @@ Provides details of routes without worrying about trade. By default, if given a jump on the route have a station. "--ref 2" would require that you not make more than one stationless jump after another. - --pad-size ?SML + --pad-size SML? -p ?SML Specify pad size required for a station to be listed or considered for refuelling stops. Specify one or all pad sizes you are want, @@ -872,6 +881,14 @@ Provides details of routes without worrying about trade. By default, if given a --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + from Name of the starting system or a station in the system, @@ -930,6 +947,14 @@ Provides details of local stations without worrying about trade. By default, if --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + --stations Limit results to systems which have stations @@ -1053,8 +1078,8 @@ Finds stations that are selling / where you can buy, a named list of items or sh trade.py buy [-q | -v] [--supply N] [-P | -S] [--limit] [--near N] [--ly-per N] [--avoid PLACES] - [--pad-size PSML?] [--black-market | --bm] - [--one-stop | -1] [--no-planet] + [--pad-size SML?] [--black-market | --bm] + [--one-stop | -1] [--no-planet | --planetary YN?] category|item [category|item category|item,category|item,category|item …] ship [ship ship,ship …] @@ -1087,6 +1112,14 @@ Finds stations that are selling / where you can buy, a named list of items or sh --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + --black-market --bm Only consider stations known to have a black market. @@ -1138,8 +1171,9 @@ Looks for stations buying the specified item. trade.py sell [-q | -v] [--demand N] [-P] [--limit] [--near N] [--ly-per N] [--avoid PLACES] - [--pad-size PSML?] [--black-market | --bm] - [--no-planet] [--lt N] [--gt N] [--price-sort | -P] + [--pad-size SML?] [--black-market | --bm] + [--no-planet | --planetary YN?] + [--lt N] [--gt N] [--price-sort | -P] item ###Options: @@ -1185,6 +1219,14 @@ Looks for stations buying the specified item. --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + --lt credits --gt credits Specify min (gt) and max (lt) credit prices for items @@ -1299,6 +1341,14 @@ This command looks for known rare items within the space around a specified syst --no-planet Require stations to be in space. + --planetary YN? + --pla YN? + Limit result to stations with one of the specified planetary + attribute. + --pla Y? (on planet or unknown) + --pad ? (unknown only) + --pla N (in space only, equals --no-planet) + --legal --illegal Only list items known to be either legal or illegal. diff --git a/commands/buy_cmd.py b/commands/buy_cmd.py index 0eaebe46..3a307c0e 100644 --- a/commands/buy_cmd.py +++ b/commands/buy_cmd.py @@ -53,7 +53,10 @@ ), AvoidPlacesArgument(), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), BlackMarketSwitch(), MutuallyExclusiveGroup( ParseArgument( @@ -253,6 +256,7 @@ def run(results, cmdenv, tdb): oneStopMode = cmdenv.oneStop padSize = cmdenv.padSize + planetary = cmdenv.planetary wantNoPlanet = cmdenv.noPlanet wantBlackMarket = cmdenv.blackMarket @@ -264,6 +268,8 @@ def run(results, cmdenv, tdb): station = stationByID[stationID] if padSize and not station.checkPadSize(padSize): continue + if planetary and not station.checkPlanetary(planetary): + continue if wantNoPlanet and station.planetary != 'N': continue if wantBlackMarket and station.blackMarket != 'Y': @@ -356,7 +362,7 @@ def render(results, cmdenv, tdb): stnRowFmt.addColumn("Pad", '>', '3', key=lambda row: TradeDB.padSizes[row.station.maxPadSize]) stnRowFmt.addColumn("Plt", '>', '3', - key=lambda row: TradeDB.marketStates[row.station.planetary]) + key=lambda row: TradeDB.planetStates[row.station.planetary]) if not cmdenv.quiet: heading, underline = stnRowFmt.heading() diff --git a/commands/commandenv.py b/commands/commandenv.py index e70ec1be..459856dd 100644 --- a/commands/commandenv.py +++ b/commands/commandenv.py @@ -1,6 +1,6 @@ from __future__ import absolute_import, with_statement, print_function, division, unicode_literals from commands import * -from commands.exceptions import CommandLineError, PadSizeError +from commands.exceptions import CommandLineError, PadSizeError, PlanetaryError from tradedb import AmbiguityError, System, Station from tradeenv import TradeEnv @@ -75,6 +75,7 @@ def run(self, tdb): self.checkAvoids() self.checkVias() self.checkPadSize() + self.checkPlanetary() results = CommandResults(self) return self._cmd.run(results, self, tdb) @@ -219,3 +220,17 @@ def checkPadSize(self): if not value in 'SML?': raise PadSizeError(padSize) self.padSize = padSize + + def checkPlanetary(self): + planetary = getattr(self, 'planetary', None) + if not planetary: + return + planetary = ''.join(sorted(list(set(planetary)))).upper() + if planetary == '?NY': + self.planetary = None + return + self.planetary = planetary = planetary.upper() + for value in planetary: + if not value in 'YN?': + raise PlanetaryError(planetary) + self.planetary = planetary diff --git a/commands/exceptions.py b/commands/exceptions.py index 7d96e6d5..c6643aa9 100644 --- a/commands/exceptions.py +++ b/commands/exceptions.py @@ -54,9 +54,21 @@ class PadSizeError(CommandLineError): """ Raised when an invalid pad-size option is given. """ def __init__(self, value): super().__init__( - "Invalid --pad-size '{}: Use a combination of one or more " + "Invalid --pad-size '{}': Use a combination of one or more " "from 'S' for Small, 'M' for Medium, 'L' for Large or " "'?' for unknown, e.g. 'SML?' matches any pad size while " "'M?' matches medium or unknown or 'L' matches only large." .format(value) ) + + +class PlanetaryError(CommandLineError): + """ Raised when an invalid planetary option is given. """ + def __init__(self, value): + super().__init__( + "Invalid --planetary '{}': Use a combination of one or more " + "from 'Y' for Yes, 'N' for No or '?' for unknown, " + "e.g. 'YN?' matches any station while 'Y?' matches " + "yes or unknown or 'N' matches only planetary stations." + .format(value) + ) diff --git a/commands/local_cmd.py b/commands/local_cmd.py index 3d254349..5be37b34 100644 --- a/commands/local_cmd.py +++ b/commands/local_cmd.py @@ -32,7 +32,10 @@ default=None, ), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), ParseArgument('--stations', help='Limit to systems which have stations.', action='store_true', @@ -76,6 +79,7 @@ def run(results, cmdenv, tdb): showStations = cmdenv.detail wantStations = cmdenv.stations padSize = cmdenv.padSize + planetary = cmdenv.planetary wantNoPlanet = cmdenv.noPlanet wantTrading = cmdenv.trading wantShipYard = cmdenv.shipyard @@ -97,6 +101,8 @@ def station_filter(stations): continue if padSize and not station.checkPadSize(padSize): continue + if planetary and not station.checkPlanetary(planetary): + continue if wantOutfitting and station.outfitting != 'Y': continue if wantRearm and station.rearm != 'Y': @@ -205,7 +211,7 @@ def render(results, cmdenv, tdb): ).append( ColumnFormat("Plt", '>', '3', key=lambda row: \ - TradeDB.marketStates[row.station.planetary]) + TradeDB.planetStates[row.station.planetary]) ) if cmdenv.detail > 1: stnRowFmt.append( diff --git a/commands/nav_cmd.py b/commands/nav_cmd.py index c7698a3f..2154544c 100644 --- a/commands/nav_cmd.py +++ b/commands/nav_cmd.py @@ -38,7 +38,10 @@ dest='stationInterval', ), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), ] ###################################################################### @@ -105,6 +108,7 @@ def run(results, cmdenv, tdb): lastSys, totalLy, dirLy = srcSystem, 0.00, 0.00 maxPadSize = cmdenv.padSize + planetary = cmdenv.planetary noPlanet = cmdenv.noPlanet for (jumpSys, dist) in route: @@ -124,6 +128,8 @@ def run(results, cmdenv, tdb): for (station) in jumpSys.stations: if maxPadSize and not station.checkPadSize(maxPadSize): continue + if planetary and not station.checkPlanetary(planetary): + continue if noPlanet and station.planetary != 'N': continue rr = ResultRow( @@ -215,7 +221,7 @@ def render(results, cmdenv, tdb): ).append( ColumnFormat("Plt", '>', '3', key=lambda row: \ - TradeDB.marketStates[row.station.planetary]) + TradeDB.planetStates[row.station.planetary]) ) if cmdenv.detail > 1: stnRowFmt.append( diff --git a/commands/parsing.py b/commands/parsing.py index 18aae407..5a7fd940 100644 --- a/commands/parsing.py +++ b/commands/parsing.py @@ -1,5 +1,5 @@ from __future__ import absolute_import, with_statement, print_function, division, unicode_literals -from commands.exceptions import PadSizeError +from commands.exceptions import PadSizeError, PlanetaryError ###################################################################### # Parsing Helpers @@ -44,7 +44,7 @@ def __new__(cls, val, **kwargs): raise PadSizeError(val) for v in val: if "SML?".find(v.upper()) < 0: - raise PadSizeError(v) + raise PadSizeError(val.upper()) return super().__new__(cls, val, **kwargs) def __init__(self): @@ -126,9 +126,37 @@ class NoPlanetSwitch(SwitchArgument): help = 'Require stations to be in space.' +class PlanetaryArgument(int): + """ + argparse helper for --planetary + """ + class PlanetaryParser(str): + def __new__(cls, val, **kwargs): + if not isinstance(val, str): + raise PlanetaryError(val) + for v in val: + if "YN?".find(v.upper()) < 0: + raise PlanetaryError(val.upper()) + return super().__new__(cls, val, **kwargs) + + def __init__(self): + self.args = ['--planetary'] + self.kwargs = { + 'help': ( + 'Limit to stations with one of the specified planetary, ' + 'e.g. --pla YN? matches any station, --pla Y matches only ' + 'planetary stations.' + ), + 'dest': 'planetary', + 'metavar': 'PLANETARY', + 'type': 'planetary', + } + + __tdParserHelpers = { 'credits': CreditParser, 'padsize': PadSizeArgument.PadSizeParser, + 'planetary': PlanetaryArgument.PlanetaryParser, } def registerParserHelpers(into): diff --git a/commands/rares_cmd.py b/commands/rares_cmd.py index 27413c69..e3343b0c 100644 --- a/commands/rares_cmd.py +++ b/commands/rares_cmd.py @@ -43,7 +43,10 @@ type=int, ), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), ParseArgument('--price-sort', '-P', help='(When using --near) Sort by price not distance.', action='store_true', @@ -123,9 +126,10 @@ def run(results, cmdenv, tdb): # Lookup the system we're currently in. start = cmdenv.nearSystem - # Hoist the padSize and noPlanet parameter for convenience + # Hoist the padSize, noPlanet and planetary parameter for convenience padSize = cmdenv.padSize noPlanet = cmdenv.noPlanet + planetary = cmdenv.planetary # How far we're want to cast our net. maxLy = float(cmdenv.maxLyPer or 0.) @@ -162,6 +166,9 @@ def run(results, cmdenv, tdb): if padSize: # do we care about pad size? if not rare.station.checkPadSize(padSize): continue + if planetary: # do we care about planetary? + if not rare.station.checkPlanetary(planetary): + continue if noPlanet and rare.station.planetary != 'N': continue rareSys = rare.station.system @@ -243,7 +250,7 @@ def render(results, cmdenv, tdb): rowFmt.addColumn("Pad", '>', '3', key=lambda row: TradeDB.padSizes[row.rare.station.maxPadSize]) rowFmt.addColumn("Plt", '>', '3', - key=lambda row: TradeDB.marketStates[row.rare.station.planetary]) + key=lambda row: TradeDB.planetStates[row.rare.station.planetary]) # Print a heading summary if the user didn't use '-q' if not cmdenv.quiet: diff --git a/commands/run_cmd.py b/commands/run_cmd.py index 180a162b..2b354ff8 100644 --- a/commands/run_cmd.py +++ b/commands/run_cmd.py @@ -132,7 +132,10 @@ dest='maxAge', ), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), BlackMarketSwitch(), ParseArgument('--ls-penalty', '--lsp', help="Penalty per 1kls stations are from their stars.", @@ -578,6 +581,18 @@ def checkStationSuitability(cmdenv, calc, station, src=None): TradeDB.padSizesExt[station.maxPadSize], )) return False + pla = cmdenv.planetary + if pla and not station.checkPlanetary(pla): + if src: + raise CommandLineError( + "{} station {} does not meet planetary requirement.\n" + "You specified: {}, Current data for station: {} ({})\n" + "You can use \"trade.py station\" to correct this.".format( + src, station.name(), + pla, station.planetary, + TradeDB.planetStatesExt[station.planetary], + )) + return False np = cmdenv.noPlanet if np and station.planetary != 'N': if src and src != "--from": diff --git a/commands/sell_cmd.py b/commands/sell_cmd.py index 42c90900..2c4dc5df 100644 --- a/commands/sell_cmd.py +++ b/commands/sell_cmd.py @@ -35,7 +35,10 @@ ), AvoidPlacesArgument(), PadSizeArgument(), - NoPlanetSwitch(), + MutuallyExclusiveGroup( + NoPlanetSwitch(), + PlanetaryArgument(), + ), BlackMarketSwitch(), ParseArgument('--limit', help='Maximum number of results to list.', @@ -134,6 +137,7 @@ def run(results, cmdenv, tdb): stationByID = tdb.stationByID padSize = cmdenv.padSize + planetary = cmdenv.planetary wantNoPlanet = cmdenv.noPlanet wantBlackMarket = cmdenv.blackMarket @@ -141,6 +145,8 @@ def run(results, cmdenv, tdb): station = stationByID[stationID] if padSize and not station.checkPadSize(padSize): continue + if planetary and not station.checkPlanetary(planetary): + continue if wantNoPlanet and station.planetary != 'N': continue if wantBlackMarket and station.blackMarket != 'Y': @@ -209,7 +215,7 @@ def render(results, cmdenv, tdb): stnRowFmt.addColumn("Pad", '>', '3', key=lambda row: TradeDB.padSizes[row.station.maxPadSize]) stnRowFmt.addColumn("Plt", '>', '3', - key=lambda row: TradeDB.marketStates[row.station.planetary]) + key=lambda row: TradeDB.planetStates[row.station.planetary]) if not cmdenv.quiet: heading, underline = stnRowFmt.heading() diff --git a/scripts/td-completion.bash b/scripts/td-completion.bash index 75039b74..e6bba134 100644 --- a/scripts/td-completion.bash +++ b/scripts/td-completion.bash @@ -3,6 +3,7 @@ common_opts="--help --debug --detail --quiet --db --cwd --link-ly" pad_opts="? l l? m m? ml ml? s s? sl sm sm? sml sml?" +pla_opts="? y y? n n? yn yn?" ynq_opts="y n ?" _td_file_list() @@ -65,9 +66,13 @@ _td_buy() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--quantity --near --ly --limit --pad-size --black-market --one-stop --price-sort --supply-sort --gt --lt --no-planet ${common_opts}" + opts="--quantity --near --ly --limit --pad-size --black-market --one-stop --price-sort --supply-sort --gt --lt --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -150,9 +155,13 @@ _td_local() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--ly --pad-size --stations --trading --black-market --shipyard --outfitting --rearm --refuel --repair --no-planet ${common_opts}" + opts="--ly --pad-size --stations --trading --black-market --shipyard --outfitting --rearm --refuel --repair --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -189,9 +198,13 @@ _td_nav() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--ly-per --avoid --via --stations --refuel-jumps --no-planet ${common_opts}" + opts="--ly-per --avoid --via --stations --refuel-jumps --pad-size --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -231,9 +244,13 @@ _td_rares() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--ly --limit --price-sort --reverse --pad-size --away --from --no-planet ${common_opts}" + opts="--ly --limit --price-sort --reverse --pad-size --away --from --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -254,9 +271,13 @@ _td_run() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--capacity --credits --ly-per --from --to --via --avoid --hops --jumps-per --empty-ly --start-jumps --end-jumps --limit --age --max-days-old --ls-penalty --unique --margin --insurance --routes --checklist --x52-pro --towards --loop --direct --pad-size --black-market --ls-max --gain-per-ton --gpt --max-gain-per-ton --mgpt --max-routes --prune-score --prune-hops --progress --supply --summary --loop-interval --shorten --no-planet ${common_opts}" + opts="--capacity --credits --ly-per --from --to --via --avoid --hops --jumps-per --empty-ly --start-jumps --end-jumps --limit --age --max-days-old --ls-penalty --unique --margin --insurance --routes --checklist --x52-pro --towards --loop --direct --pad-size --black-market --ls-max --gain-per-ton --gpt --max-gain-per-ton --mgpt --max-routes --prune-score --prune-hops --progress --supply --summary --loop-interval --shorten --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -277,9 +298,13 @@ _td_sell() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 - opts="--near --ly-per --limit --price-sort --pad-size --black-market --gt --lt --no-planet ${common_opts}" + opts="--near --ly-per --limit --price-sort --pad-size --black-market --gt --lt --no-planet --planetary ${common_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; esac @@ -320,6 +345,10 @@ _td_station() opts="${pad_opts}" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) ;; + --planetary) + opts="${pla_opts}" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + ;; *) _td_common && return 0 opts="--ls-from-star --black-market --market --shipyard --pad-size --outfitting --rearm --refuel --repair --confirm --add --remove --update --no-export --planetary ${common_opts}" diff --git a/tradecalc.py b/tradecalc.py index 1319809a..2893ec12 100644 --- a/tradecalc.py +++ b/tradecalc.py @@ -758,6 +758,7 @@ def getBestHops(self, routes, restrictTo=None): maxJumpsPer = tdenv.maxJumpsPer maxLyPer = tdenv.maxLyPer maxPadSize = tdenv.padSize + planetary = tdenv.planetary noPlanet = tdenv.noPlanet maxLsFromStar = tdenv.maxLs or float('inf') reqBlackMarket = getattr(tdenv, 'blackMarket', False) or False @@ -821,6 +822,7 @@ def station_iterator(srcStation): maxPadSize=maxPadSize, maxLsFromStar=maxLsFromStar, noPlanet=noPlanet, + planetary=planetary, ) prog = pbar.Progress(len(routes), 25) diff --git a/tradedb.py b/tradedb.py index b1d7f7bd..07534e81 100644 --- a/tradedb.py +++ b/tradedb.py @@ -351,6 +351,35 @@ def checkPadSize(self, maxPadSize): """ return (not maxPadSize or self.maxPadSize in maxPadSize) + def checkPlanetary(self, planetary): + """ + Tests if the Station's planetary matches one of the + values in 'planetary'. + + Args: + askPlanetary + A string of one or more planetary values that + you want to match against. + + Returns: + True + If self.planetary is None or empty, or matches a + member of planetary + False + If planetary was not empty but self.planetary + did not match it. + + Examples: + # Require a planetary station + station.checkPlanetary("Y") + # Require planetary or unknown + station.checkPadSize("Y?") + # Require no planetary station + station.checkPadSize("N") + + """ + return (not planetary or self.planetary in planetary) + def distFromStar(self, addSuffix=False): """ Returns a textual description of the distance from this @@ -588,8 +617,8 @@ class TradeDB(object): ) # Translation matrixes for attributes -> common presentation - marketStates = {'?': '?', 'Y': 'Yes', 'N': 'No'} - marketStatesExt = {'?': 'Unk', 'Y': 'Yes', 'N': 'No'} + marketStates = planetStates = {'?': '?', 'Y': 'Yes', 'N': 'No'} + marketStatesExt = planetStatesExt = {'?': 'Unk', 'Y': 'Yes', 'N': 'No'} padSizes = {'?': '?', 'S': 'Sml', 'M': 'Med', 'L': 'Lrg'} padSizesExt = {'?': 'Unk', 'S': 'Sml', 'M': 'Med', 'L': 'Lrg'} @@ -1660,6 +1689,7 @@ def getDestinations( maxPadSize=None, maxLsFromStar=0, noPlanet=False, + planetary=None, ): """ Gets a list of the Station destinations that can be reached @@ -1756,6 +1786,11 @@ def path_iter_fn(): (node, station) for (node, station) in path_iter if station.checkPadSize(maxPadSize) ) + if planetary: + path_iter = iter( + (node, station) for (node, station) in path_iter + if station.checkPlanetary(planetary) + ) if maxLsFromStar: path_iter = iter( (node, stn) for (node, stn) in path_iter