/
Waypoint_Navigation.py
88 lines (71 loc) · 3.55 KB
/
Waypoint_Navigation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from loguru import logger
import time
from AI_Pilot.Control_Functions.Monitors import get_screen
from AI_Pilot.Control_Functions.General import get_cords_with_offset
from AI_Pilot.Game_Functions.Common.Common import get_game_state
from AI_Pilot.Control_Functions.Mouse_Keyboard import perform_move_click, press_release_alt_f_key
def get_nav_options(ag, crop):
# region ----- get gav options
img = get_screen(ag)
img = img.crop(tuple(crop))
nav_result = ag.up.predict(img, 'nav_options')
logger.info(nav_result)
# endregion
return nav_result
def get_y_waypoint_nav_pos(ag):
# region ----- get waypoint y
img = get_screen(ag)
img_x = img.crop((0, 0, 500, 600))
route_y_large_vert_class_v2_result = ag.up.predict(img_x, 'route_y_large_vert_class_v4')
logger.info(route_y_large_vert_class_v2_result)
# endregion
return route_y_large_vert_class_v2_result
def navigate_one_waypoint(ag):
state_result = get_game_state(ag)
if state_result['class'] == 'in_flight':
route_y_large_vert_class_v2_result = get_y_waypoint_nav_pos(ag)
splits = route_y_large_vert_class_v2_result['class'].split('_')
#target_y = int(route_y_large_vert_class_v2_result['class'])
#nav_point_xy = get_cords_with_offset(ag, 136, target_y + 4)
nav_point_xy = get_cords_with_offset(ag, int(splits[0]) + 4, int(splits[1]) + 4)
perform_move_click(ag, pos=nav_point_xy, button='right', perform_offset=False)
# TODO Train a model to crop this?
template = [0, 0, 0, 0]
template[1] = int(splits[1]) + ag.static_screen_pos['next_waypoint_menu_box_dims_from_click'][0]
template[3] = template[1] + ag.static_screen_pos['next_waypoint_menu_box_dims_from_click'][1]
template[0] = int(splits[0]) + ag.static_screen_pos['next_waypoint_menu_box_dims_from_click'][2]
template[2] = template[0] + ag.static_screen_pos['next_waypoint_menu_box_dims_from_click'][3]
nav_result = get_nav_options(ag, template)
click_target = None
# TODO Train a model to pos this?
if nav_result['class'] == 'dock_now':
click_target = (nav_point_xy[0] + 50, nav_point_xy[1] + 75)
elif nav_result['class'] == 'jump_though_first':
click_target = (nav_point_xy[0] + 50, nav_point_xy[1] + 25)
elif nav_result['class'] == 'jump_through_second':
click_target = (nav_point_xy[0] + 50, nav_point_xy[1] + 50)
elif nav_result['class'] == 'warp_to_dock_3':
click_target = (nav_point_xy[0] + 50, nav_point_xy[1] + 75)
elif nav_result['class'] == 'warp_to_dock_4':
click_target = (nav_point_xy[0] + 50, nav_point_xy[1] + 100)
else:
logger.info('do nothing nav...')
if click_target is not None:
perform_move_click(ag, pos=click_target, button='left', perform_offset=False)
try:
if hasattr(ag, 'navigation'):
if 'navigation_use_warpdrive_fkey' in ag.navigation:
if ag.navigation['navigation_use_warpdrive_fkey'] is not None:
time.sleep(0.5)
press_release_alt_f_key(ag, ag.navigation['navigation_use_warpdrive_fkey'])
except Exception as e:
logger.exception(e)
return state_result
def navigate_waypoints_to_end(ag, allow_dock=True):
while True:
state_result = navigate_one_waypoint(ag)
# TODO, handle other states
if state_result['class'] != 'in_flight' or not allow_dock:
break
else:
time.sleep(10)