Exemplo n.º 1
0
def activate_miners(module_num):
    """Activates mining modules based on the number passed to this function.
    If the module is out of range, script will try to wait until ship gets
    within range before activating any more modules."""
    for n in range(1, (module_num + 1)):
        key.keypress('f' + (str(n)))
        logging.debug('activating miner ' + (str(n)))
        out_of_range = lo.mlocate('./img/popups/miner_out_of_range.bmp',
                                  conf=0.90,
                                  grayscale=True)
        tries = 0
        while out_of_range == 1 and tries <= 25:
            tries += 1
            time.sleep(float(random.randint(15000, 30000)) / 1000)
            out_of_range = lo.mlocate('./img/popups/miner_out_of_range.bmp',
                                      conf=0.90,
                                      grayscale=True)
            if out_of_range == 0 and tries <= 25:
                time.sleep(float(random.randint(0, 3000)) / 1000)
                logging.debug('activating miner ' + (str(n)))
                key.keypress('f' + (str(n)))
        if out_of_range == 0 and tries <= 25:
            continue
        elif out_of_range == 1 and tries > 25:
            logging.error('timed out waiting for ship to get within '
                          'module range')
            return 0
    return 1
Exemplo n.º 2
0
def select_overview_tab(tab):
    """Switches to the specified overview tab. If the specified tab is already
    selected, this function does nothing. Assumes the default overview
    configuration."""
    logging.debug('focusing ' + (str(tab)) + ' tab')

    # Requires very high confidence since the overview tab buttons look only
    # slightly different when selected.
    selected = lo.mlocate('./img/overview/' + (str(tab)) +
                          '_overview_tab_selected.bmp',
                          conf=0.998,
                          grayscale=True)

    if selected != 0:
        logging.debug('tab ' + (str(tab)) + ' already selected')
        return 1

    elif selected == 0:
        unselected = lo.mlocate('./img/overview/' + (str(tab)) +
                                '_overview_tab.bmp',
                                loctype='co',
                                grayscale=True)

        if unselected != 0:
            (x, y) = unselected
            pag.moveTo((x + (random.randint(-12, 12))),
                       (y + (random.randint(-6, 6))), mouse.duration(),
                       mouse.path())
            mouse.click()
            return 1
        elif unselected == 0:
            logging.error('unable to find overview tabs')
            return 0
Exemplo n.º 3
0
def wait_for_jump():
    """Waits for a jump by looking for the cyan session-change icon in top left
    corner of the client window. Also checks if the 'low security system
    warning' window has appeared and is preventing the ship from jumping.
    Times out after about four minutes."""
    # Confidence must be lower than normal since icon is partially
    # transparent.
    for tries in range(1, 240):
        jumped = lo.mlocate('./img/indicators/session_change_cloaked.bmp',
                            conf=0.55)

        if jumped != 0:
            logging.debug('jump detected')
            time.sleep(float(random.randint(1000, 2000)) / 1000)
            return 1

        elif jumped == 0:
            losec = lo.mlocate('./img/warnings/low_security_system.bmp',
                               conf=0.9)
            if losec != 0:
                time.sleep(float(random.randint(2000, 5000)) / 1000)
                key.keypress('enter')
                continue

            logging.debug('waiting for jump ' + (str(tries)))
            time.sleep(float(random.randint(5, 20)) / 10)

    logging.error('timed out waiting for jump')
    emergency_terminate()
    traceback.print_stack()
    sys.exit()
Exemplo n.º 4
0
def set_dest():
    """Issues a 'set destination' command for the lowest-numbered bookmark that
    isn't blacklisted."""
    target_dest = 1
    dest = lo.mlocate('./img/dest/dest' + (str(target_dest)) + '.bmp',
                      conf=0.98,
                      loctype='c')

    while dest == 0:
        target_dest += 1
        logging.debug('looking for dest ' + (str(target_dest)))
        dest = lo.mlocate('./img/dest/dest' + (str(target_dest)) + '.bmp',
                          conf=0.98,
                          loctype='c')

    if dest != 0:
        logging.debug('setting destination waypoint')
        (x, y) = dest
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(20, 25))), mouse.duration(),
                    mouse.path())
        mouse.click()
        time.sleep(float(random.randint(1000, 2000)) / 1000)
        return
Exemplo n.º 5
0
def load_ship_bulk():
    """Load ship by selecting all item stacks and moving all stacks at once."""
    logging.debug('beginning bulk loading procedure')

    if lo.mlocate('./img/indicators/station_inv_0_items.bmp', conf=0.9) == 1:
        return 0

    else:
        focus_inv_window()
        key.hotkey('ctrl', 'a')
        drag_to_ship_inv()

        time.sleep(float(random.randint(1500, 3000)) / 1000)
        nospace = not_enough_space_warning()
        setquant = set_quant_warning()

        if nospace == 0 and setquant == 0:
            logging.debug('no warnings')
            return 2

        # If there isn't enough space in the main ship inventory,
        # check if it has a special inventory. Iterate through a
        # list of possible special inventory types.
        specinv_list = ['ore', 'fleet']
        if nospace == 1:
            for invtype in specinv_list:
                if look_for_specinv(invtype) == 1:
                    focus_inv_window()
                    key.hotkey('ctrl', 'a')
                    drag_to_ship_specinv(invtype)

                    time.sleep(float(random.randint(1500, 3000)) / 1000)
                    specinvwarning = specinv_warning()
                    nospace = not_enough_space_warning()
                    setquant = set_quant_warning()

                    # If no warnings appear, look for more item stacks,
                    # just to be sure the station is empty.
                    if specinvwarning == 0 and setquant == 0 and nospace == 0:
                        if lo.mlocate(
                                './img/indicators/station_inv_0_items.bmp',
                                conf=0.9) == 0:
                            logging.debug('more items remaining')
                            return 0
                        else:
                            logging.debug('station empty')
                            return 2

                    elif specinvwarning == 0 and setquant == 1 and nospace \
                            == 0:
                        logging.debug('cannot load in bulk')
                        return 1

                    else:
                        return 0
                else:
                    return 0
        else:
            return 0
Exemplo n.º 6
0
def is_home():
    """Checks if the ship is at its home station by looking for a
    gree bookmark starting with '000'."""
    if lo.mlocate('./img/dest/at_dest0.bmp') == 0:
        logging.debug('not at home station')
        return 0
    elif lo.mlocate('./img/dest/at_dest0.bmp') != 0:
        logging.debug('at home station')
        return 1
Exemplo n.º 7
0
def is_target_lockable():
    """Looks for a highlighted 'target this object' icon in the 'selected
    item' window, indicating the selected target is close enough in order to
    achieve a lock."""
    # High confidence required since greyed-out target lock icon looks
    # so similar to enabled icon.
    if lo.mlocate('./img/indicators/target_lock_available.bmp',
                  conf=0.9999) != 0:
        logging.debug('within targeting range')
        return 1
    elif lo.mlocate('./img/indicators/target_lock_available.bmp',
                    conf=0.9999) == 0:
        logging.debug('outside targeting range')
        return 0
Exemplo n.º 8
0
def recall_drones(drone_num):
    """Recalls drones and waits for them to return to the drone bay."""
    if drone_num != 0:
        time.sleep(float(random.randint(5, 500)) / 1000)
        key.hotkey('shift', 'r')
        time.sleep(float(random.randint(1000, 2000)) / 1000)

        # Wait for all drones to return to drone bay. Very sensitive to the
        # drones variable. Won't work unless the drones variable is correct.
        for tries in range(1, 30):
            drones_returned = lo.mlocate('./img/indicators/drones/' +
                                         (str(drone_num)) +
                                         '_drone_in_bay.bmp',
                                         grayscale=True)

            if drones_returned == 1:
                logging.debug('drones returned to bay')
                return 1

            elif drones_returned == 0:
                logging.info('waiting for drones to return to bay ' +
                             (str(tries)))
                time.sleep(float(random.randint(1000, 2000)) / 1000)
                return 0

        logging.warning('timed out waiting for drones to return')
        return 0
    elif drone_num == 0:
        return 0
Exemplo n.º 9
0
def look_for_specinv(invtype):
    """Looks for different kinds of special inventory icons on your ship."""
    if lo.mlocate('./img/buttons/spec_inv_' + invtype + '.bmp') != 0:
        logging.debug('found ' + (str(invtype)) + ' inventory')
        return 1
    else:
        return 0
Exemplo n.º 10
0
def is_jammed(detect_jam, haystack=0):
    """Checks for an ecm-jamming icon within an especially narrow section of
    the overview. If a haystack image is provided, search within that
    instead."""
    if detect_jam == 1 and haystack == 0:
        ox_jam = (originx + (windowx - (int(windowx / 8))))
        olx_jam = (int(windowx / 8))
        # Custom region in lo.locate is useful to reduce the
        # search-space as this function is called frequently.
        if pag.locateOnScreen('./img/overview/jammed_overview.bmp',
                              region=(ox_jam, originy, olx_jam, windowy)) is \
                not None:
            logging.info('ship has been jammed!')
            return 1
        else:
            logging.debug('no jamming detected')
            return 0

    elif detect_jam == 1 and haystack != 0:
        if lo.mlocate('./img/overview/jammed_overview.bmp',
                      haystack=haystack,
                      grayscale=True) != 0:
            logging.info('ship has been jammed!')
            return 1
        else:
            logging.debug('no jamming detected')
            return 0

    elif detect_jam == 0:
        return 0
Exemplo n.º 11
0
def load_ship():
    """Utilize both individual and bulk loading functions to load ship."""
    open_station_inv()
    noitems = lo.mlocate('./img/indicators/station_inv_0_items.bmp', conf=0.9)

    if noitems == 0:
        lsb = load_ship_bulk()
        if lsb == 2:
            logging.debug('ship loaded entire station inventory')
            return 2

        elif lsb == 1:
            logging.debug('ship is full and station inventory has more items')
            return 1

        elif lsb == 0:
            lsi = load_ship_individual()
            if lsi == 2:
                logging.debug('ship loaded entire station inventory')
                return 2

            elif lsi == 1:
                logging.debug('ship is full and station inventory has more  '
                              'items')
                return 1

    elif noitems == 1:
        return 0
Exemplo n.º 12
0
def unload_ship():
    """Unloads ship inventory and deposits it in the station's inventory."""
    logging.debug('began unloading procedure')
    open_ship_inv()
    noitems = lo.mlocate('./img/indicators/station_inv_0_items.bmp', conf=0.9)

    if noitems == 0:
        time.sleep(float(random.randint(0, 2000)) / 1000)
        focus_inv_window()
        time.sleep(float(random.randint(0, 2000)) / 1000)
        key.hotkey('ctrl', 'a')
        time.sleep(float(random.randint(0, 2000)) / 1000)
        drag_items_from_ship_inv()
        time.sleep(2)
        noitems = lo.mlocate('./img/indicators/station_inv_0_items.bmp',
                             conf=0.9)

    if noitems == 1:
        logging.debug('finished unloading main inventory')

        specinv_list = ['ore', 'fleet']
        for invtype in specinv_list:
            if look_for_specinv(invtype) == 1:
                time.sleep(float(random.randint(0, 2000)) / 1000)
                open_specinv(invtype)
                noitems = lo.mlocate(
                    './img/indicators/station_inv_0_items.bmp', conf=0.9)

                while noitems == 0:
                    time.sleep(float(random.randint(0, 2000)) / 1000)
                    focus_inv_window()
                    time.sleep(float(random.randint(0, 2000)) / 1000)
                    key.hotkey('ctrl', 'a')
                    time.sleep(float(random.randint(0, 2000)) / 1000)
                    drag_items_from_ship_inv()
                    time.sleep(float(random.randint(0, 2000)) / 1000)
                    logging.debug('finished unloading ' + (str(invtype)) +
                                  ' inventory')
                    return 1
                if noitems == 1:
                    logging.debug('finished unloading procedure')
                    return 1

            elif look_for_specinv(invtype) == 0:
                logging.debug('finished unloading procedure')
                return 1
Exemplo n.º 13
0
def drag_items_from_ship_inv():
    """Clicks and drags all items from ship inventory to station inventory."""
    (x1, y1) = lo.mlocate('./img/indicators/station_inv_name.bmp', loctype='c')
    (x2, y2) = lo.mlocate('./img/buttons/station_inv.bmp', loctype='c')

    pag.moveTo((x1 + (random.randint(-5, 250))),
               (y1 + (random.randint(10, 25))), mouse.duration(), mouse.path())
    time.sleep(float(random.randint(0, 1000)) / 1000)
    pag.mouseDown()
    time.sleep(float(random.randint(0, 1000)) / 1000)
    pag.moveTo(
        (x2 + (random.randint(-15, 60))), (y2 + (random.randint(-10, 10))),
        mouse.duration(), mouse.path())
    time.sleep(float(random.randint(0, 1000)) / 1000)
    pag.mouseUp()
    logging.debug('moved all item stacks from ship inventory')
    return
Exemplo n.º 14
0
def warp_to_local_bookmark(target_site_num):
    """Tries warping to the provided target bookmark, assuming the bookmark
    is in the current system. If the ship is already at or near the
    requested bookmark, return the function."""
    # Confidence must be >0.95 because script will confuse 6 with 0.
    target_site_bookmark = lo.mlocate('./img/dest/at_dest' +
                                      (str(target_site_num)) + '.bmp',
                                      conf=0.98,
                                      loctype='c')

    if target_site_bookmark != 0:
        (x, y) = target_site_bookmark
        pag.moveTo(
            (x + (random.randint(10, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        approach_location = lo.mlocate(
            './img/buttons/detect_warp_to_bookmark.bmp', conf=0.90)

        # If the 'approach location' option is found in the right-click
        # menu, the ship is already near the bookmark.
        if approach_location != 0:
            logging.debug('already at bookmark ' + (str(target_site_bookmark)))
            key.keypress('esc')  # Close right-click menu.
            return 0

        # If the 'approach location' option is not found, look for a 'warp
        # to' option and select it.
        elif approach_location == 0:
            warp_to_site = lo.mlocate('./img/buttons/warp_to_bookmark.bmp',
                                      conf=0.90,
                                      loctype='c')

            if warp_to_site != 0:
                logging.info('warping to bookmark ' +
                             (str(target_site_bookmark)))
                pag.moveRel((0 + (random.randint(10, 80))),
                            (0 + (random.randint(10, 15))), mouse.duration(),
                            mouse.path())
                mouse.click()
                time.sleep(float(random.randint(1500, 1800)) / 1000)
                return 1
            elif warp_to_site == 0:
                logging.error('unable to warp to target site, is ship docked?')
                return 0
Exemplo n.º 15
0
def is_docked():
    """Checks if the ship is currently docked by looking for the undock
     button."""
    if lo.mlocate('./img/buttons/undock.bmp') == 0:
        logging.debug('not docked')
        return 0
    else:
        logging.debug('docked')
        return 1
Exemplo n.º 16
0
def specinv_warning():
    """Look for a popup indicating the selected inventory items aren't
    compatible with the ship's special inventory. This warning is partially
    transparent so confidence rating must be slightly lower than normal."""
    if lo.mlocate('./img/popups/spec_inv.bmp', conf=0.8) != 0:
        logging.debug('detected special inventory warning')
        return 1
    else:
        logging.debug('no special inventory warning')
        return 0
Exemplo n.º 17
0
def warp_to_waypoint():
    """Clicks on the current waypoint and uses the warp hotkey to warp to
    waypoint. Currently only supports warping to stargate and station
    waypoints."""
    # TODO: add support for warping to citadels and engineering complexes
    logging.debug('looking for waypoints')
    # Speed up image searching by looking within overview only. This
    # obviously requires the user to place the overview on the right side of
    # the client window.

    for tries in range(1, 15):
        stargate = lo.mlocate('./img/overview/stargate_waypoint.bmp', conf=0.96)
        if stargate != 0:
            logging.debug('found stargate waypoint')
            (x, y) = stargate
            pag.moveTo((x + (random.randint(-8, 30)))), \
                      (y + (random.randint(-8, 8))), \
                mouse.duration(), mouse.path()
            mouse.click()
            key.keypress('d')  # 'dock / jump' hotkey.
            # Move mouse to the left side of the client to prevent
            # tooltips from interfering with image searches.
            mouse.move_to_neutral()
            return 2

        station = lo.mlocate('./img/overview/station_waypoint.bmp', conf=0.96)
        if station != 0:
            logging.debug('found station waypoint')
            (x, y) = station
            pag.moveTo((x + (random.randint(-8, 30))),
                       (y + (random.randint(-8, 8))),
                       mouse.duration(), mouse.path())
            mouse.click()
            key.keypress('d')
            mouse.move_to_neutral()
            return 2

        if stargate == 0 and station == 0:
            time.sleep(float(random.randint(500, 1500)) / 1000)
            logging.debug('looking for waypoints ' + (str(tries)))

    logging.error('no waypoints found')
    return 0
Exemplo n.º 18
0
def has_route():
    # TODO: fix this function, the detect_route image doesn't exist
    """Checks the top-left corner of the client window to see if a route has
     actually been set by the user."""
    return
    route_set_var = lo.mlocate('./img/indicators/detect_route.bmp', conf=0.85)
    if route_set_var == 0:
        logging.error('no route set!')
        sys.exit(0)
    else:
        return
Exemplo n.º 19
0
def wait_for_warp_to_complete():
    """Detects when a warp has started and been
    completed by watching the spedometer."""
    # TODO: force ship to wait a minimum period of time while beginning its
    # warp, similar to what tinyminer does to eliminate possible issues.

    # Wait for warp to begin by waiting until the speedometer is full. Ship
    # might be stuck on something so this could take an variable amount of
    # time.

    for duration in range(1, 300):
        warping = lo.mlocate('./img/indicators/warping2.bmp', conf=0.94)

        if warping != 0:
            logging.debug('warping')
            time.sleep(float(random.randint(1000, 3000)) / 1000)

            # Once warp begins, wait for warp to end by waiting for the
            # 'warping' text on the spedometer to disappear.
            for tries in range(1, 150):
                time.sleep(float(random.randint(1000, 3000)) / 1000)
                warping_done = lo.mlocate('./img/indicators/warping3.bmp',
                                          conf=0.9)

                if warping_done == 0:
                    logging.debug('warp completed')
                    return 1
                elif warping_done != 0:
                    logging.debug('waiting for warp to complete ' +
                                  (str(tries)))

            logging.error('timed out waiting for warp to complete')
            return 0

        elif warping == 0:
            logging.debug('waiting for warp to start ' + (str(duration)))
            time.sleep(float(random.randint(500, 1000)) / 1000)

    logging.error('timed out waiting for warp to start')
    return 0
Exemplo n.º 20
0
def not_enough_space_warning():
    """Checks if a 'not enough space' warning appears, indicating the item
    stacks selected will not fit into the ship's inventory, or inventory is
    already full."""
    if lo.mlocate('./img/warnings/not_enough_space.bmp') != 0:
        logging.debug('detected not enough space warning')
        time.sleep(float(random.randint(100, 800)) / 1000)
        pag.keyDown('enter')
        time.sleep(float(random.randint(5, 100)) / 1000)
        pag.keyUp('enter')
        return 1
    else:
        logging.debug('no not enough space warning')
        return 0
Exemplo n.º 21
0
def set_quant_warning():
    """Check if a 'set quantity' window appears, indicating there isn't enough
    space in the ship's inventory for a full item stack."""

    if lo.mlocate('./img/popups/set_quant.bmp', conf=0.85) != 0:
        logging.debug('detected set quantity warning')
        time.sleep(float(random.randint(100, 800)) / 1000)
        pag.keyDown('enter')
        time.sleep(float(random.randint(5, 100)) / 1000)
        pag.keyUp('enter')
        return 1
    else:
        logging.debug('no set quantity warning')
        return 0
Exemplo n.º 22
0
def detect_bookmark_location():
    """Checks if any bookmarks are green, indicating that the bookmark is in the
    ship's current system."""
    global n
    n = 0
    # Confidence must be higher than normal or script mistakes dest3 for dest2.
    at_dest = lo.mlocate('./img/dest/at_dest' + (str(n)) + '.bmp',
                         conf=0.98,
                         loctype='c')

    while at_dest == 0:
        n += 1
        logging.debug('looking if at destination ' + (str(n)))
        at_dest = lo.mlocate('./img/dest/at_dest' + (str(n)) + '.bmp',
                             conf=0.98,
                             loctype='c')

        if n == 9 and at_dest == 0:
            print('out of destinations to look for')
            return -1
    if at_dest != 0:
        logging.debug('at dest ' + (str(n)))
        return n
Exemplo n.º 23
0
def wait_for_undock():
    """Undock from the station with the default hotkey. The undock_loop has been
    completed once the script sees the cyan ship icon in the top left corner
    of the client window, indicating a session change has just ocurred."""
    logging.info('undocking')
    pag.keyDown('ctrl')
    time.sleep(float(random.randint(100, 800)) / 1000)
    key.keypress('u')
    time.sleep(float(random.randint(100, 800)) / 1000)
    pag.keyUp('ctrl')

    # Wait for the 'undock' button to change to 'undocking', indicating the
    # undock action has been confirmed.
    tries = 0

    while lo.mlocate('./img/buttons/undocking.bmp', conf=0.8, loctype='o') \
            == 0 and tries <= 250:
        tries += 1
        logging.debug('waiting for session change to begin ' + (str(tries)))
        time.sleep(int((random.randint(100, 200) / 1000)))

    if lo.mlocate('./img/buttons/undocking.bmp', conf=0.8, loctype='o') != 0 \
            and tries <= 250:
        logging.debug('session change underway ' + (str(tries)))

        # Now wait for the undock to complete by looking for the session
        # change indicator.
        tries = 0

        while lo.mlocate('./img/indicators/session_change_undocked.bmp',
                         conf=0.55) == 0 and tries <= 100:
            tries += 1
            time.sleep(int((random.randint(500, 2000) / 1000)))
            logging.debug('waiting for session change to complete ' +
                          (str(tries)))

        if lo.mlocate('./img/indicators/session_change_undocked.bmp',
                      conf=0.55) != 0 and tries <= 100:
            logging.debug('undock completed ' + (str(tries)))
            return 1

        # If script times out waiting for the session change icon, simply
        # look for the undock button instead since ship has likely completed
        # an undock, but at this point the session change icon is probably
        # gone.
        elif lo.mlocate('./img/indicators/session_change_undocked.bmp',
                        conf=0.55) == 0 and tries > 100:
            if is_docked() == 1:
                logging.error('cannot undock')
                sys.exit()
            elif is_docked() == 0:
                logging.warning('undock tentatively completed')
                return 1
    elif lo.mlocate('./img/buttons/undocking.bmp', conf=0.9) == 0 and \
            tries > 25:
        logging.error('timed out waiting for session change')
        sys.exit()
Exemplo n.º 24
0
def drag_to_ship_inv():
    """Click and drag the first item stack from station's inventory to ship's
    inventory. This function assumed the relevant window is already open."""
    logging.debug('moving item stack to ship inventory')

    station_inv = lo.mlocate('./img/indicators/station_inv_name.bmp',
                             loctype='c')
    if station_inv == 0:
        logging.critical("can't find name column")
        traceback.print_exc()
        traceback.print_stack()
        sys.exit()

    else:
        tries = 0
        ship_inv = lo.mlocate('./img/buttons/ship_inv.bmp', loctype='c')
        while ship_inv == 0 and tries <= 25:
            tries += 1
            logging.critical("can't find ship inventory")
            time.sleep(float(random.randint(1000, 2000)) / 1000)
            ship_inv = lo.mlocate('./img/buttons/ship_inv.bmp', loctype='c')

        if ship_inv != 0 and tries <= 25:
            (x, y) = station_inv
            (sx, sy) = ship_inv
            pag.moveTo((x + (random.randint(-5, 250))),
                       (y + (random.randint(10, 25))), mouse.duration(),
                       mouse.path())
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.mouseDown()
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.moveTo((sx + (random.randint(-5, 60))),
                       (sy + (random.randint(-8, 8))), mouse.duration(),
                       mouse.path())
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.mouseUp()
            return
Exemplo n.º 25
0
def drag_to_ship_specinv(invtype):
    """Drag item stack to ship's special inventory."""
    logging.debug('moving item stack to special inventory')

    station_inv = lo.mlocate('./img/indicators/station_inv_name.bmp',
                             loctype='c')
    if station_inv != 0:
        tries = 0
        spec_inv = lo.mlocate('./img/buttons/spec_inv_' + invtype + '.bmp',
                              loctype='c')
        while spec_inv == 0 and tries <= 25:
            tries += 1
            logging.critical("can't find ship inventory")
            time.sleep(float(random.randint(1000, 2000)) / 1000)
            spec_inv = lo.mlocate('./img/buttons/spec_inv_' + invtype + '.bmp',
                                  loctype='c')

        if spec_inv != 0 and tries <= 25:
            (x, y) = station_inv
            (sx, sy) = spec_inv
            pag.moveTo((x + (random.randint(-5, 250))),
                       (y + (random.randint(10, 25))), mouse.duration(),
                       mouse.path())
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.mouseDown()
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.moveTo((sx + (random.randint(-15, 40))),
                       (sy + (random.randint(-3, 3))), mouse.duration(),
                       mouse.path())
            time.sleep(float(random.randint(0, 1000)) / 1000)
            pag.mouseUp()
            return
    else:
        logging.critical("can't find name column")
        traceback.print_exc()
        traceback.print_stack()
        sys.exit()
Exemplo n.º 26
0
def focus_inv_window():
    """Clicks somewhere inside the station inventory window to focus it.
    Looks for the sorting buttons in top right corner
    of the inventory window and positions the mouse cursor relative to those
    buttons to click an inavtive area within the inventory window."""
    tries = 0
    window = lo.mlocate('./img/buttons/station_sorting.bmp', loctype='c')

    while window == 0 and tries <= 25:
        logging.error('cannot find sorting icon ' + (str(tries)))
        tries += 1
        time.sleep(float(random.randint(500, 2000)) / 1000)
        window = lo.mlocate('./img/buttons/station_sorting.bmp', loctype='c')

    if window != 0 and tries <= 25:
        (x, y) = window
        pag.moveTo((x - (random.randint(0, 250))),
                   (y + (random.randint(60, 300))), mouse.duration(),
                   mouse.path())
        mouse.click()
        return 1
    elif tries > 25:
        logging.error('timed out looking for sorting buttons')
        return 0
Exemplo n.º 27
0
def wait_for_dock():
    """Waits for a dock by looking for the undock button on the right half
    of the client window."""
    for tries in range(1, 180):
        docked = lo.mlocate('./img/buttons/undock.bmp', conf=0.91)

        if docked != 0:
            logging.debug('detected dock ' + (str(tries)))
            time.sleep(float(random.randint(1000, 3000)) / 1000)
            return 1

        elif docked == 0:
            logging.debug('waiting for dock ' + (str(tries)))
            time.sleep(float(random.randint(2000, 5000)) / 1000)

    logging.error('timed out waiting for dock')
    return 0
Exemplo n.º 28
0
def set_home():
    """Sets destination to the first bookmark beginning with '000'."""
    home = lo.mlocate('./img/dest/dest0.bmp', loctype='c')
    if home != 0:
        logging.debug('setting home waypoint')
        (x, y) = home
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(20, 25))), mouse.duration(),
                    mouse.path())
        mouse.click()
        return 1
    else:
        logging.error('could not find home waypoint!')
        return 0
Exemplo n.º 29
0
def dock_at_local_bookmark():
    """Docks at the first bookmark beginning with a '0' in its name,
    assuming it's in the same system as you and the bookmark is a station."""
    dock = lo.mlocate('./img/dest/at_dest0.bmp', loctype='c')
    if dock != 0:
        (x, y) = dock
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()

        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(35, 40))), mouse.duration(),
                    mouse.path())
        # Sleep used to fix bug in which client doesn't immediately
        # highlight 'dock' after opening right-click menu.
        # (see video 2019-07-06_13-26-14 at 33m50s for bug).
        time.sleep(float(random.randint(700, 1000)) / 1000)
        mouse.click()
        wait_for_dock()
Exemplo n.º 30
0
def open_ship_inv():
    """Clicks on the ship's inventory button within the inventory window.
    Assumes the ship is docked and the inventory window is already open."""
    logging.debug('opening ship inventory')
    for tries in range(1, 25):
        ship_inv = lo.mlocate('./img/buttons/ship_inv.bmp', loctype='c')
        if ship_inv != 0:
            (x, y) = ship_inv
            pag.moveTo((x + (random.randint(-4, 50))),
                       (y + (random.randint(-6, 6))), mouse.duration(),
                       mouse.path())
            mouse.click()
            return 1

        elif ship_inv == 0:
            logging.error('cannot find ship inventory ' + (str(tries)))
            time.sleep(float(random.randint(500, 2000)) / 1000)

    logging.error('timed out looking for ship inventory')
    return 0