Skip to content

Commit

Permalink
Added "--planetary" argument to to buy, local, nav, rares, run and sell
Browse files Browse the repository at this point in the history
command. The "--no-planet" and "--planetary" arguments are mutually
exclusive.
  • Loading branch information
bgol committed Jul 2, 2016
1 parent b84678a commit 32f2d9c
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 34 deletions.
70 changes: 60 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand All @@ -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,
Expand All @@ -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,

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 …]

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
),
AvoidPlacesArgument(),
PadSizeArgument(),
NoPlanetSwitch(),
MutuallyExclusiveGroup(
NoPlanetSwitch(),
PlanetaryArgument(),
),
BlackMarketSwitch(),
MutuallyExclusiveGroup(
ParseArgument(
Expand Down Expand Up @@ -253,6 +256,7 @@ def run(results, cmdenv, tdb):

oneStopMode = cmdenv.oneStop
padSize = cmdenv.padSize
planetary = cmdenv.planetary
wantNoPlanet = cmdenv.noPlanet
wantBlackMarket = cmdenv.blackMarket

Expand All @@ -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':
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 16 additions & 1 deletion commands/commandenv.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
14 changes: 13 additions & 1 deletion commands/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
10 changes: 8 additions & 2 deletions commands/local_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
default=None,
),
PadSizeArgument(),
NoPlanetSwitch(),
MutuallyExclusiveGroup(
NoPlanetSwitch(),
PlanetaryArgument(),
),
ParseArgument('--stations',
help='Limit to systems which have stations.',
action='store_true',
Expand Down Expand Up @@ -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
Expand All @@ -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':
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions commands/nav_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
dest='stationInterval',
),
PadSizeArgument(),
NoPlanetSwitch(),
MutuallyExclusiveGroup(
NoPlanetSwitch(),
PlanetaryArgument(),
),
]

######################################################################
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 30 additions & 2 deletions commands/parsing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 32f2d9c

Please sign in to comment.