Skip to content

Commit

Permalink
Add percentage option for length along Pill
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMackrill committed Oct 7, 2014
1 parent 8494eb6 commit 6551a28
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def lookupSystem(name, intent):
raise CommandLineError("Unknown {} system/station, '{}'".format(intent, name))


def lengthAlongPill(sc):
def distanceAlongPill(sc, percent):
"""
Estimate a distance along the Pill using 2 reference systems
"""
Expand All @@ -649,6 +649,8 @@ def lengthAlongPill(sc):
length = math.sqrt((sb.posX-sa.posX) * (sb.posX-sa.posX)
+ (sb.posY-sa.posY) * (sb.posY-sa.posY)
+ (sb.posZ-sa.posZ) * (sb.posZ-sa.posZ))
if percent:
return 100. * dotProduct / length / length

return dotProduct / length

Expand Down Expand Up @@ -679,16 +681,14 @@ def localCommand(args):
for (system, dist) in sorted(distances.items(), key=lambda x: x[1]):
pillLength = ""
if args.detail > 0:
pillLength = " [{:5.1f}]".format(lengthAlongPill(system))
pillLengthFormat = " [{:4.0f}%]" if args.percent else " [{:5.1f}]"
pillLength = pillLengthFormat.format(distanceAlongPill(system, args.percent))
print("{:5.2f}{} {}".format(dist, pillLength, system.str()))
if args.detail > 1:
for (station) in system.stations:
stationDistance = ""
if station.lsFromStar>0:
stationDistance = " {} ls".format(station.lsFromStar)
stationDistance = " {} ls".format(station.lsFromStar) if station.lsFromStar>0 else ""
print(" <{}>{}".format(station.str(), stationDistance))


def navCommand(args):
"""
Give player directions A->B
Expand Down Expand Up @@ -898,7 +898,8 @@ def main():
ParseArgument('--ship', help='Use the maximum jump distance of the specified ship (defaults to the empty value).', metavar='shiptype', type=str),
ParseArgument('--full', help='(With --ship) Limits the jump distance to that of a full ship.', action='store_true', default=False),
ParseArgument('--ly', help='Maximum light years to measure.', metavar='N.NN', type=float, dest='ly'),
]
ParseArgument('--percent', help='Show distance up pill as percent.', action='store_true', default=False),
]
)

# "run" calculates a trade run.
Expand Down

0 comments on commit 6551a28

Please sign in to comment.