Beispiel #1
0
def start_open():
    logger.info("start_open")
    sleep(5)
    send(keymap['UI_Select'])
    send(keymap['UI_Select'])
    sleep(35)
    logger.debug("completed start_open()")
Beispiel #2
0
def autopilot():
    logging.info("edcm.navigation.autopilot()")
    logging.info('\n' + 200 * '-' + '\n' + '---- AUTOPILOT START ' +
                 179 * '-' + '\n' + 200 * '-')
    ship_status = get_ship_status()
    logging.info("edcm.navigation.autopilot: ship_status = %s" % ship_status)
    while ship_status['target']:
        if get_ship_status()['status'] == 'in_space' or get_ship_status(
        )['status'] == 'in_supercruise':
            logging.info('\n' + 200 * '-' + '\n' + '---- navigation_align() ' +
                         179 * '-' + '\n' + 200 * '-')
            navigation_align()
            logging.info('\n' + 200 * '-' + '\n' +
                         '---- destination_align() ' + 179 * '-' + '\n' +
                         200 * '-')
            destination_align()
            logging.info('\n' + 200 * '-' + '\n' + '---- jump() ' + 180 * '-' +
                         '\n' + 200 * '-')
            jump()
            logging.info('\n' + 200 * '-' + '\n' + '---- refuel() ' +
                         178 * '-' + '\n' + 200 * '-')
            refueled = refuel()
            logging.info('\n' + 200 * '-' + '\n' + '---- position() ' +
                         179 * '-' + '\n' + 200 * '-')
            if refueled:
                position(refueled_multiplier=4)
            else:
                position(refueled_multiplier=1)
        logging.info("edcm.navigation.autopilot: ship_status = %s" %
                     ship_status)
        ship_status = get_ship_status()
    logging.info("edcm.navigation.autopilot: target destination reached")
    send(keymap['SetSpeedZero'])
    logging.info('\n' + 200 * '-' + '\n' + '---- AUTOPILOT END ' + 181 * '-' +
                 '\n' + 200 * '-')
Beispiel #3
0
def auto_launch():
    logging.info("edcm.navigation.auto_launch()")
    ship_status = get_ship_status()['status']
    logger.info("ship_status = %s" % json.dumps(ship_status))
    if ship_status == 'in_station':
        send(keymap['UI_Down'], repeat=2)  # UI move down to AUTO LAUNCH
        send(keymap['UI_Select'])
        logger.info("edcm.navigation.auto_launch: AUTO LAUNCH in progress")
        t0 = time()
        t1 = time()
        last = t0
        # wait til ship status change
        while ship_status in ('in_station', 'in_docking', 'docking',
                              'in_undocking'):
            sleep(.2)  # cpu friendly spin
            t1 = time()
            ship_status = get_ship_status()['status']
            if last - t1 > 5:
                last = t1
                logger.info("t- %.2f, ship_status = %s" %
                            ((t1 - t0), get_ship_status()['status']))
        logger.info(
            "edcm.navigation.auto_launch: AUTO LAUNCH completed in %.2f seconds"
            % (t1 - t0))
        # boost 3x away
        for i in range(3):
            logger.info("edcm.navigation.auto_launch: boost")
            send(keymap['UseBoostJuice'])
            logger.info("edcm.navigation.auto_launch: power to engines")
            send(keymap['IncreaseEnginesPower'], repeat=3, repeat_delay=.1)
            sleep(7)
            logger.info(
                "edcm.navigation.auto_launch: reset power distribution")
            send(keymap['ResetPowerDistribution'])
    logger.info("edcm.navigation.auto_launch() completed.")
Beispiel #4
0
def refuel(refuel_threshold=33):
    logging.info("edcm.navigation.refuel(refuel_threshold=%s)" %
                 refuel_threshold)

    if get_ship_status()['status'] != 'in_supercruise':
        logging.error('refuel=err1')
        return False

    if get_ship_status(
    )['fuel_percent'] < refuel_threshold and get_ship_status(
    )['star_class'] in FUEL_STARS:
        logging.info("edcm.navigation.refuel: begin refueling ")
        send(keymap['SetSpeed100'])
        #     while not get_ship_status()['is_scooping']:
        #         sleep(1)
        sleep(
            4
        )  # crude but effective, on arrival move toward star for 4 seconds
        logging.info("edcm.navigation.refuel: wait for refuel")
        send(keymap['SetSpeedZero'], repeat=3
             )  # we don't need to repeat 3x, but we do anyway .. for emphasis
        while not get_ship_status()['fuel_percent'] == 100:
            sleep(1)
        logging.info("edcm.navigation.refuel: fuel_percent == 100")
        return True
    elif get_ship_status()['fuel_percent'] >= refuel_threshold:
        logging.info("edcm.navigation.refuel: not needed")
        return False
    elif get_ship_status()['star_class'] not in FUEL_STARS:
        logging.info("edcm.navigation.refuel: not a refueling star")
        return False
    else:
        return False
Beispiel #5
0
def start_solo():
    logger.info("start_solo")
    sleep(5)
    send(keymap['UI_Select'])
    send(keymap['UI_Right'])
    send(keymap['UI_Right'])
    send(keymap['UI_Select'])
    sleep(35)
    logger.debug("completed start_solo()")
Beispiel #6
0
def jump():
    logging.info("edcm.navigation.jump()")
    tries = 3
    for i in range(tries):
        logging.info("edcm.navigation.jump: try# %s" % i)
        if not (get_ship_status()['status'] == 'in_supercruise'
                or get_ship_status()['status'] == 'in_space'):
            logging.error('jump=err1')
            raise Exception('not ready to jump')
        sleep(0.5)
        logging.info("edcm.navigation.jump: start fsd")
        send(keymap['HyperSuperCombination'], hold=1)
        sleep(16)
        if get_ship_status()['status'] != 'starting_hyperspace':
            logging.info("edcm.navigation.jump: misaligned, stop fsd")
            send(keymap['HyperSuperCombination'], hold=1)
            sleep(2)
            align()
        else:
            logging.info("edcm.navigation.jump: jumping")
            while get_ship_status()['status'] != 'in_supercruise':
                sleep(1)
            logging.info("edcm.navigation.jump: SetSpeedZer0")
            send(keymap['SetSpeedZero'])
            logging.info("edcm.navigation.jump() Completed")
            return True
    logging.error("edcm.navigation.jump: error, exceeded %s attempts" % tries)
    raise Exception("edcm.navigation.jump() failure")
Beispiel #7
0
def reverse_direction():
    logging.info("edcm.navigation.reverse_direction()")

    facing_forward = False

    handling = 2 + (2 * SHIP_FACTOR)
    if get_ship_status()['status'] == 'in_space':
        handling = handling * .5

    while not facing_forward:
        logger.info("edcm.navigation.reverse_direction: not facing_forward")
        logger.info("edcm.navigation.reverse_direction: SetSpeed50 ")
        send(keymap['SetSpeed50'])
        logger.info("edcm.navigation.reverse_direction: PitchUp (on)")
        send(keymap['PitchUpButton'], state=1)
        logger.info("edcm.navigation.reverse_direction: sleep(%.2f)" %
                    handling)
        sleep(handling)
        logger.info("edcm.navigation.reverse_direction: PitchUp (off)")
        send(keymap['PitchUpButton'], state=0)
        compass_image, compass_width, compass_height = get_compass_image()
        if not check_reverse(compass_image, testing=False):
            facing_forward = True
        send(keymap['SetSpeed100'])
Beispiel #8
0
def exit_to_main_menu(wait=None):
    logger.info("exit_to_main_menu()")
    send(keymap['ESC'])
    send(keymap['UI_Down'])
    send(keymap['UI_Down'])
    send(keymap['UI_Down'])
    send(keymap['UI_Down'])
    send(keymap['UI_Down'])  # 2019-09-19 'BUY ARX'
    send(keymap['UI_Select'])
    sleep(5)
    if wait:
        sleep(15)  # 15 second logout timer
    send(keymap['UI_Right'])
    send(keymap['UI_Select'])
    sleep(35)
    logger.debug("completed exit_to_main()")
Beispiel #9
0
def get_preps(fast_track=False):
    # start at docked station menu
    # TODO: from edcm import text.get_screen_text
    #       if screen_text matches 'STARPORT SERVICES'
    logger.info("get_forts() starting")
    logger.debug("UI_select on 'STARPORT SERVICES'")
    send(keymap['UI_Select'])  # select 'STARPORT SERVICES'
    sleep(2.7)

    # move up to contacts
    send(keymap['UI_Up'], repeat=3, repeat_delay=.5)  # move to CONTACTS
    logger.debug("UI_select on 'CONTACTS'")
    send(keymap['UI_Select'])  # select 'CONTACTS'
    sleep(1.3)

    send(keymap['UI_Right'], repeat=2, repeat_delay=.5)  # move to COMBAT BOND CONTACT
    send(keymap['UI_Down'], repeat=2, repeat_delay=.5)  # move to POWER CONTACT
    send(keymap['UI_Select'])  # select 'POWER CONTACT'
    sleep(1.3)

    # customize for the specific power play panel
    # hudson, down 1, 'collect hudson garrison supplies'
    send(keymap['UI_Down'], repeat=2, repeat_delay=.5)  # move to collect

    # hold down UI_Right for 30 seconds
    if fast_track:
        send(keymap['UI_Select'])  # FAST TRACK QUOTA FOR CREDITS
        sleep(5.1)

    logger.info("hold 'collect' for 15 seconds")
    send(keymap['UI_Right'], hold=10)  # move to collect
    send(keymap['UI_Select'])  # CONFIRM
    sleep(1.3)

    send(keymap['UI_Select'])  # BACK TO MAIN PAGE

    send(keymap['UI_Left'])  # move to collect
    send(keymap['UI_Select'])  # BACK
    sleep(.3)

    send(keymap['UI_Left'])  # move to collect
    send(keymap['UI_Select'])  # BACK
    sleep(.3)

    send(keymap['UI_Up'])  # move to EXIT
    send(keymap['UI_Select'])  # EXIT STARPORT SERVICES
    sleep(2.3)

    logger.info("get_preps() completed.")
Beispiel #10
0
def set_destination(destination_system="Sol"):
    logger.info("set_destination(desination_system=%s)" % destination_system)
    ship_status = get_ship_status()
    logging.info("edcm.navigation.autopilot: ship_status = %s" % ship_status)
    if not ship_status['target']:
        logger.debug("destination system not set")
        open_galaxy_map()
        sleep(5)

        # select current location
        send(keymap['CycleNextPanel'])
        send(keymap['UI_Left'])
        send(keymap['UI_Down'])
        send(keymap['UI_Select'])

        # select search box
        send(keymap['UI_Left'])
        send(keymap['UI_Up'])
        send(keymap['UI_Select'])  # select SEARCH Box

        # type destination string in search box followed by return
        for c in destination_system:
            logger.debug(
                "destination_system: %s, character %s, ascii value: %s",
                destination_system, c, ord(c))
            if c.isspace() or ord(c) == 32:
                direct_key = {'key': SCANCODE["DIK_SPACE"]}
            elif ord(c) == 45:
                direct_key = {'key': SCANCODE["DIK_MINUS"]}
            else:
                direct_key = {'key': SCANCODE["DIK_" + c.upper()]}
            send(direct_key)
        send(keymap['RET'])

        sleep(3)  # estimate plotting route time, should be a screen read loop

        # select route
        send(keymap['UI_Select'])
        send(keymap['UI_Right'])
        send(keymap['UI_Select'])

        sleep(1)
        close_galaxy_map()
Beispiel #11
0
def open_galaxy_map():
    logger.info("open_galaxy_map()")
    send(keymap['GalaxyMapOpen'])
Beispiel #12
0
def align():
    logger.info("edcm.navigation.align()")

    center = {'x': 0, 'y': 0}

    ship_status = get_ship_status()['status']

    if not (ship_status == 'in_supercruise' or ship_status == 'in_space'):
        logger.error('align=err1')
        raise Exception('align error 1')

    while sun_percent() > 5:
        send(keymap['PitchUpButton'], state=1)
    send(keymap['PitchUpButton'], state=0)

    logging.info("edcm.navigation.align: SetSpeed100")
    send(keymap['SetSpeed100'])

    logging.info("edcm.navigation.align: move away from main star")
    sleep(10)
    send(keymap['SetSpeed50'])

    compass_image, compass_width, compass_height = get_compass_image()
    if check_reverse(compass_image):
        logger.warning("Matched NavCircle, must turn around")
        reverse_direction()

    close = 3
    close_a = 18
    hold_pitch = 0.350 * SHIP_FACTOR
    hold_roll = 0.170 * SHIP_FACTOR

    if ship_status == 'in_space':
        # adjust hold time for nor normal space
        hold_pitch = hold_pitch * .5
        hold_roll = hold_roll * .5

    logging.info("edcm.navigation.align: compass align")
    offset = get_navpoint_offset()
    direction = compare_coordinates(center, offset, close)
    logger.info("compare_coordinates = %s" % direction)

    logging.info("edcm.navigation.align: navpoint_offset = %s " % offset)
    angle = x_angle(offset)
    logging.info("edcm.navigation.align: x_angle = %s " % angle)

    logger.info(
        "edcm.navigation.align: if offset[x] > close and angle > close_a | %s > %s and %s > %s"
        % (offset['x'], close, angle, close_a))

    logger.info(
        "edcm.navigation.align: or offset[x] < -close and angle < -close_a | %s < -%s and %s < -%s"
        % (offset['x'], close, angle, close_a))

    logger.info(
        "edcm.navigation.align: or offset[y] > close or offset[y] <- close | %s > %s and %s > %s"
        % (offset['x'], close, angle, close_a))

    while (offset['x'] > close and angle > close_a) or \
            (offset['x'] < -close and angle < -close_a) or \
            (offset['y'] > close) or \
            (offset['y'] < -close):

        # Roll Into Position
        logger.info("edcm.navigation.align: roll alignment starting")
        while (offset['x'] > close
               and angle > close_a) or (offset['x'] < -close
                                        and angle < -close_a):
            if offset['x'] > close and angle > close:
                logger.info("offset[X] (%.2f) is not close enough (%.2f)" %
                            (offset['x'], close))
                logger.info("send(RollRight) for %.2f s" % hold_roll)
                send(keymap['RollRightButton'], hold=hold_roll)
            if offset['x'] < -close and angle < -close:
                logger.info("offset[X] (%.2f) is not close enough (%.2f)" %
                            (offset['x'], close))
                logger.info("send(RollRight) for %.2f s" % hold_roll)
                send(keymap['RollLeftButton'], hold=hold_roll)
            if get_ship_status()['status'] == 'starting_hyperspace':
                return
            offset = get_navpoint_offset()
            angle = x_angle(offset)
        logger.info("edcm.navigation.align: roll alignment completed")

        # Pitch Into Position
        logger.info("edcm.navigation.align: pitch alignment starting")
        while ((offset['y'] > close) or (offset['y'] < -close)) or \
                ((offset['y'] > close) or (offset['y'] < -close)):
            if offset['y'] > close:
                logger.info("offset[y] (%.2f) is not close enough (%.2f)" %
                            (offset['y'], close))
                logger.info("send(PitchUpButton) for %.2f s" % hold_pitch)
                send(keymap['PitchUpButton'], hold=hold_pitch)
            if offset['y'] < -close:
                logger.info("offset[y] (%.2f) is not close enough (%.2f)" %
                            (offset['y'], close))
                logger.info("send(PitchDownButton) for %.2f s" % hold_pitch)
                send(keymap['PitchDownButton'], hold=hold_pitch)
            if get_ship_status()['status'] == 'starting_hyperspace':
                return
            offset = get_navpoint_offset()
        logger.info("edcm.navigation.align: pitch alignment completed")

        offset = get_navpoint_offset()
        angle = x_angle(offset)

    sleep(0.5)
    close = 50
    hold_pitch = 0.200 * SHIP_FACTOR
    hold_yaw = 0.400 * SHIP_FACTOR

    logging.info('edcm.navigation.align: destination align')
    while (offset['x'] > close) or (offset['x'] < -close) or (
            offset['y'] > close) or (offset['y'] < -close):

        if offset['x'] > close:
            send(keymap['YawRightButton'], hold=hold_yaw)
        if offset['x'] < -close:
            send(keymap['YawLeftButton'], hold=hold_yaw)
        if offset['y'] > close:
            send(keymap['PitchUpButton'], hold=hold_pitch)
        if offset['y'] < -close:
            send(keymap['PitchDownButton'], hold=hold_pitch)

        if get_ship_status()['status'] == 'starting_hyperspace':
            return

        offset = get_destination_offset()

    logging.info("edcm.navigation.align: full speed ahead")
    send(keymap['SetSpeed100'])

    logging.info("edcm.navigation.align() Completed.")
Beispiel #13
0
def destination_align():
    logger.info("edcm.navigation.align()")

    center = {'x': 0, 'y': 0}

    ship_status = get_ship_status()['status']

    if not (ship_status == 'in_supercruise' or ship_status == 'in_space'):
        logger.error('align=err1')
        raise Exception('align error 1')

    while sun_percent() > 5:
        send(keymap['PitchUpButton'], state=1)
    send(keymap['PitchUpButton'], state=0)

    logging.info("edcm.navigation.align: set speed for maneuvering")
    send(keymap['SetSpeed50'])

    aligned = False
    x_axis_aligned = False
    x_offset = 0
    pitch_rate = 0.25
    y_axis_aligned = False
    y_offset = 0
    yaw_rate = 0.25

    while not aligned:

        offset = get_destination_offset()
        direction = compare_coordinates(center, offset, threshold=25)

        logger.info("compare_coordinates(center vs offset) ( %s vs %s ) = %s" %
                    (center, offset, direction))

        if direction[0]:
            logger.info("direction[0] == %s" % direction[0])
            if direction[0] != "ON":
                logger.info("x_axis direction = %s" % direction[0])
                if x_offset != 0:
                    logger.info("previous heading = %.f" % x_offset)
                if str(direction[0]).startswith("LEFT"):
                    logger.info("Yaw Left")
                    last_offset = x_offset
                    try:
                        x_offset = float(str(direction[1]))
                    except ValueError:
                        logger.error(
                            "compare_coordinates.direction did not parse (%s vs %s) = %s"
                            % (center, direction[2], direction[3]))
                    if x_offset >= last_offset:
                        send(keymap['YawLeftButton'], hold=yaw_rate)
                elif str(direction[0]).startswith("RIGHT"):
                    logger.info("Rotate Right")
                    last_offset = x_offset
                    try:
                        x_offset = float(str(direction[1]))
                    except ValueError:
                        logger.error(
                            "compare_coordinates.direction did not parse (%s vs %s) = %s"
                            % (center, direction[2], direction[3]))
                    if x_offset >= last_offset:
                        send(keymap['YawRightButton'], hold=yaw_rate)
            else:
                x_axis_aligned = True
                x_offset = 0

        if direction[2]:
            logger.info("direction[1] == %s" % direction[1])
            if direction[1] != "ON":
                logger.info("y_axis direction = %s" % direction[1])
            if y_offset != 0:
                logger.info("previous heading = %.f" % y_offset)
            if str(direction[2]).startswith("UP"):
                logger.info("Pitch Up")
                last_offset = y_offset
                try:
                    y_offset = float(str(direction[3]))
                except ValueError:
                    logger.error(
                        "compare_coordinates.direction did not parse (%s vs %s) = %s"
                        % (center, direction[2], direction[3]))
                if y_offset >= last_offset:
                    send(keymap['PitchUpButton'], hold=pitch_rate)
            elif str(direction[2]).startswith("DOWN"):
                logger.info("Pitch Down")
                last_offset = y_offset
                try:
                    y_offset = float(str(direction[3]))
                except ValueError:
                    logger.error(
                        "compare_coordinates.direction did not parse (%s vs %s) = %s"
                        % (center, direction[2], direction[3]))
                if y_offset >= last_offset:
                    send(keymap['PitchDownButton'], hold=pitch_rate)
            else:
                y_axis_aligned = True
                y_offset = 0

        if x_axis_aligned and y_axis_aligned:
            aligned = True

        if aligned:
            break

    return True
Beispiel #14
0
def position(refueled_multiplier=1):
    logging.info("edcm.navigation.position(refueled_multiplier=%s)" %
                 refueled_multiplier)
    logging.info("edcm.navigation.position: discovery scanner (hold)")
    logging.info("edcm.navigation.position: Pitch Up (hold)")
    send(keymap[get_scanner()], state=1)
    send(keymap['PitchUpButton'], state=1)
    sleep(5)
    logging.info("edcm.navigation.position: SetSpeed100")
    send(keymap['PitchUpButton'], state=0)
    send(keymap['SetSpeed100'])
    logging.info("edcm.navigation.position: PitchUp (release)")
    send(keymap['PitchUpButton'], state=1)
    logging.info("edcm.navigation.position: move to safe position")
    while sun_percent() > 3:
        sleep(.2)
    sleep(5)
    send(keymap['PitchUpButton'], state=0)
    sleep(5 * refueled_multiplier)
    logging.info("edcm.navigation.position: discovery scanner (release)")
    send(keymap[get_scanner()], state=0)
    logging.info("edcm.navigation.position() Completed.")
    return True
Beispiel #15
0
def reset():
    logging.info("edcm.navigation.reset()")
    logging.info("edcm.navigation.reset: resetting to safe position")

    logging.info("edcm.navigation.reset: 1) go to safe position")
    position()

    logging.info("edcm.navigation.reset: 2) pith up and rotate to reset")
    send(keymap['SetSpeed100'])
    send(keymap['RollRightButton'], state=1)
    send(keymap['PitchUpButton'], state=1)
    duration = 1 + SHIP_FACTOR
    sleep(duration)
    send(keymap['PitchUpButton'], state=0)
    send(keymap['RollRightButton'], state=0)
    send(keymap['SetSpeed100'])