예제 #1
0
파일: navigation.py 프로젝트: Drelzna/edcm
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 * '-')
예제 #2
0
파일: powerplay.py 프로젝트: Drelzna/edcm
def load(cargo_type="fort", fast_track=False):
    status = journal.get_ship_status()
    logger.info(json.dumps(status))
    cargo = int(status['cargo_count'])
    max_cargo = int(status['cargo_capacity'])
    space_available = max_cargo - cargo

    while space_available > 0:
        logger.info("cargo (used) = %f" % cargo)
        logger.info("cargo (capacity) = %f" % max_cargo)
        logger.info("cargo (free) = %f" % space_available)

        if str(cargo_type).endswith("ort"):
            get_forts(fast_track=fast_track)
        else:
            get_preps(fast_track=fast_track)

        status = journal.get_ship_status()
        cargo = int(status['cargo_count'])
        max_cargo = int(status['cargo_capacity'])
        space_available = max_cargo - cargo

        if not fast_track:
            menu.exit_to_main_menu()
            sleep(1800)  # 30 minutes
            menu.start_solo()
예제 #3
0
파일: navigation.py 프로젝트: Drelzna/edcm
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.")
예제 #4
0
파일: navigation.py 프로젝트: Drelzna/edcm
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")
예제 #5
0
파일: navigation.py 프로젝트: Drelzna/edcm
def supercruise():
    logging.info("edcm.navigation.supercruise()")
    ship_status = get_ship_status()
    logging.info("edcm.navigation.autopilot: ship_status = %s" % ship_status)
    while ship_status['status'] == 'in_supercruise':
        navigation_align()
        destination_align()
        ship_status = get_ship_status()
        logging.info("edcm.navigation.autopilot: ship_status = %s" %
                     ship_status)

    return None
예제 #6
0
파일: navigation.py 프로젝트: Drelzna/edcm
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
예제 #7
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()
예제 #8
0
파일: navigation.py 프로젝트: Drelzna/edcm
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'])
예제 #9
0
import os
import sys
import logging


logger = logging.getLogger(__name__)

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from edcm import journal

j = journal.get_latest_journal()
assert j is not None
logger.info("Current Player Journal: %s " % j)

ship_status = journal.get_ship_status()
assert ship_status is not None

logger.info("ship_status:\n"
            "time = %s\n"
            "type = %s\n"
            "cargo_count = %s\n"
            "cargo_capacity = %s\n"
            "location = %s\n"
            "star_class = %s\n"
            "target = %s\n"
            "fuel_capacity = %s\n"
            "fuel_level = %s\n"
            "fuel_percent = %s\n"
            "is_scooping = %s\n" %
            (ship_status['time'],
             ship_status['type'],
예제 #10
0
파일: navigation.py 프로젝트: Drelzna/edcm
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.")
예제 #11
0
파일: navigation.py 프로젝트: Drelzna/edcm
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