Esempio n. 1
0
def run(results, cmdenv, tdb):
    cmdenv = results.cmdenv
    tdb = cmdenv.tdb
    srcSystem = cmdenv.nearSystem

    ly = cmdenv.maxLyPer
    if ly is None:
        ly = tdb.maxSystemLinkLy

    results.summary = ResultRow()
    results.summary.near = srcSystem
    results.summary.ly = ly
    results.summary.stations = 0

    distances = {srcSystem: 0.0}

    # Calculate the bounding dimensions
    for destSys, dist in tdb.genSystemsInRange(srcSystem, ly):
        distances[destSys] = dist

    showStations = cmdenv.detail
    wantStations = cmdenv.stations
    padSize = cmdenv.padSize
    planetary = cmdenv.planetary
    wantNoPlanet = cmdenv.noPlanet
    wantTrading = cmdenv.trading
    wantShipYard = cmdenv.shipyard
    wantBlackMarket = cmdenv.blackMarket
    wantOutfitting = cmdenv.outfitting
    wantRearm = cmdenv.rearm
    wantRefuel = cmdenv.refuel
    wantRepair = cmdenv.repair

    def station_filter(stations):
        for station in stations:
            if wantNoPlanet and station.planetary != 'N':
                continue
            if wantTrading and not station.isTrading:
                continue
            if wantBlackMarket and station.blackMarket != 'Y':
                continue
            if wantShipYard and station.shipyard != 'Y':
                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':
                continue
            if wantRefuel and station.refuel != 'Y':
                continue
            if wantRepair and station.repair != 'Y':
                continue
            yield station

    for (system, dist) in sorted(distances.items(), key=lambda x: x[1]):
        if showStations or wantStations:
            stations = []
            for (station) in station_filter(system.stations):
                stations.append(
                    ResultRow(
                        station=station,
                        age=station.itemDataAgeStr,
                    ))
            if not stations and wantStations:
                continue

        row = ResultRow()
        row.system = system
        row.dist = dist
        row.stations = stations if showStations else []
        results.rows.append(row)
        results.summary.stations += len(row.stations)

    return results
Esempio n. 2
0
def run(results, cmdenv, tdb):
    from commands.commandenv import ResultRow

    srcSystem, dstSystem = cmdenv.origPlace, cmdenv.destPlace
    if isinstance(srcSystem, Station):
        srcSystem = srcSystem.system
    if isinstance(dstSystem, Station):
        dstSystem = dstSystem.system

    maxLyPer = cmdenv.maxLyPer or tdb.maxSystemLinkLy

    cmdenv.DEBUG0("Route from {} to {} with max {}ly per jump.",
                  srcSystem.name(), dstSystem.name(), maxLyPer)

    # Build a list of src->dst pairs
    hops = [[srcSystem, None]]
    if cmdenv.viaPlaces:
        for hop in cmdenv.viaPlaces:
            hops[-1][1] = hop
            hops.append([hop, None])
    hops[-1][1] = dstSystem

    avoiding = [
        avoid for avoid in cmdenv.avoidPlaces if isinstance(avoid, System)
    ]

    route = []
    stationInterval = cmdenv.stationInterval
    for hop in hops:
        hopRoute = tdb.getRoute(
            hop[0],
            hop[1],
            maxLyPer,
            avoiding,
            stationInterval=stationInterval,
        )
        if not hopRoute:
            raise NoRouteError("No route found between {} and {} "
                               "with a max {}ly/jump limit.".format(
                                   hop[0].name(),
                                   hop[1].name(),
                                   maxLyPer,
                               ))
        route = route[:-1] + hopRoute

    results.summary = ResultRow(
        fromSys=srcSystem,
        toSys=dstSystem,
        maxLy=maxLyPer,
    )

    lastSys, totalLy, dirLy = srcSystem, 0.00, 0.00
    maxPadSize = cmdenv.padSize
    planetary = cmdenv.planetary
    noPlanet = cmdenv.noPlanet

    for (jumpSys, dist) in route:
        jumpLy = lastSys.distanceTo(jumpSys)
        totalLy += jumpLy
        if cmdenv.detail:
            dirLy = jumpSys.distanceTo(dstSystem)
        row = ResultRow(
            action='Via',
            system=jumpSys,
            jumpLy=jumpLy,
            totalLy=totalLy,
            dirLy=dirLy,
        )
        row.stations = []
        if cmdenv.stations:
            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(
                    station=station,
                    age=station.itemDataAgeStr,
                )
                row.stations.append(rr)
        results.rows.append(row)
        lastSys = jumpSys
    results.rows[0].action = 'Depart'
    results.rows[-1].action = 'Arrive'

    return results
Esempio n. 3
0
def run(results, cmdenv, tdb):
    from commands.commandenv import ResultRow

    srcSystem, dstSystem = cmdenv.origPlace, cmdenv.destPlace
    if isinstance(srcSystem, Station):
        srcSystem = srcSystem.system
    if isinstance(dstSystem, Station):
        dstSystem = dstSystem.system

    maxLyPer = cmdenv.maxLyPer or tdb.maxSystemLinkLy

    cmdenv.DEBUG0("Route from {} to {} with max {}ly per jump.",
                    srcSystem.name(), dstSystem.name(), maxLyPer)

    # Build a list of src->dst pairs
    hops = [ [ srcSystem, None ] ]
    if cmdenv.viaPlaces:
        for hop in cmdenv.viaPlaces:
            hops[-1][1] = hop
            hops.append([hop, None])
    hops[-1][1] = dstSystem

    avoiding = [
        avoid for avoid in cmdenv.avoidPlaces
        if isinstance(avoid, System)
    ]

    route = [ ]
    stationInterval = cmdenv.stationInterval
    for hop in hops:
        hopRoute = tdb.getRoute(
                hop[0], hop[1],
                maxLyPer,
                avoiding,
                stationInterval=stationInterval,
                )
        if not hopRoute:
            raise NoRouteError(
                    "No route found between {} and {} "
                    "with a max {}ly/jump limit.".format(
                        hop[0].name(), hop[1].name(),
                        maxLyPer,
            ))
        route = route[:-1] + hopRoute

    results.summary = ResultRow(
                fromSys=srcSystem,
                toSys=dstSystem,
                maxLy=maxLyPer,
            )

    lastSys, totalLy, dirLy = srcSystem, 0.00, 0.00
    maxPadSize = cmdenv.padSize

    for (jumpSys, dist) in route:
        jumpLy = lastSys.distanceTo(jumpSys)
        totalLy += jumpLy
        if cmdenv.detail:
            dirLy = jumpSys.distanceTo(dstSystem)
        row = ResultRow(
            action='Via',
            system=jumpSys,
            jumpLy=jumpLy,
            totalLy=totalLy,
            dirLy=dirLy,
            )
        row.stations = []
        if cmdenv.stations:
            for (station) in jumpSys.stations:
                if maxPadSize and not station.checkPadSize(maxPadSize):
                    continue
                rr = ResultRow(
                    station=station,
                    age=station.itemDataAgeStr,
                )
                row.stations.append(rr)
        results.rows.append(row)
        lastSys = jumpSys
    results.rows[0].action='Depart'
    results.rows[-1].action='Arrive'

    return results
Esempio n. 4
0
def run(results, cmdenv, tdb):
    cmdenv = results.cmdenv
    tdb = cmdenv.tdb
    srcSystem = cmdenv.nearSystem

    ly = cmdenv.maxLyPer
    if ly is None:
        ly = tdb.maxSystemLinkLy

    results.summary = ResultRow()
    results.summary.near = srcSystem
    results.summary.ly = ly
    results.summary.stations = 0

    distances = { srcSystem: 0.0 }

    # Calculate the bounding dimensions
    for destSys, dist in tdb.genSystemsInRange(srcSystem, ly):
        distances[destSys] = dist

    showStations = cmdenv.detail
    wantStations = cmdenv.stations
    padSize = cmdenv.padSize
    wantTrading = cmdenv.trading
    wantShipYard = cmdenv.shipyard
    wantBlackMarket = cmdenv.blackMarket
    wantOutfitting = cmdenv.outfitting
    wantRearm = cmdenv.rearm
    wantRefuel = cmdenv.refuel
    wantRepair = cmdenv.repair

    def station_filter(stations):
        for station in stations:
            if wantTrading and not station.isTrading:
                continue
            if wantBlackMarket and station.blackMarket != 'Y':
                continue
            if wantShipYard and station.shipyard != 'Y':
                continue
            if padSize and not station.checkPadSize(padSize):
                continue
            if wantOutfitting and station.outfitting != 'Y':
                continue
            if wantRearm and station.rearm != 'Y':
                continue
            if wantRefuel and station.refuel != 'Y':
                continue
            if wantRepair and station.repair != 'Y':
                continue
            yield station

    for (system, dist) in sorted(distances.items(), key=lambda x: x[1]):
        if showStations or wantStations:
            stations = []
            for (station) in station_filter(system.stations):
                stations.append(
                    ResultRow(
                        station=station,
                        age=station.itemDataAgeStr,
                    )
                )
            if not stations and wantStations:
                continue

        row = ResultRow()
        row.system = system
        row.dist = dist
        row.stations = stations if showStations else []
        results.rows.append(row)
        results.summary.stations += len(row.stations)

    return results