@@ -70,7 +70,7 @@ bool should_navigate_down(
7070 return down_distance <= up_distance;
7171}
7272
73- bool navigate_to_destination_page_in_fast_travel_menu (
73+ bool navigate_to_destination_page_in_fast_travel_menu_routine (
7474 ConsoleHandle& console,
7575 ProControllerContext& context,
7676 Language language,
@@ -128,6 +128,26 @@ bool navigate_to_destination_page_in_fast_travel_menu(
128128 return false ;
129129}
130130
131+ bool navigate_to_destination_page_in_fast_travel_menu (
132+ ConsoleHandle& console,
133+ ProControllerContext& context,
134+ Language language,
135+ const LocationItem& target_destination
136+ ){
137+ WallClock deadline = current_time () + 30s;
138+ do {
139+ navigate_to_destination_page_in_fast_travel_menu_routine (console, context, language, target_destination);
140+
141+ pbf_wait (context, 1s); // Account for video lag by making confirmation
142+ context.wait_for_all_requests ();
143+
144+ bool found = navigate_to_destination_page_in_fast_travel_menu_routine (console, context, language, target_destination);
145+ if (found){
146+ return true ;
147+ }
148+ } while (current_time () < deadline);
149+ return false ;
150+ }
131151
132152int get_target_location_index_within_page (
133153 const LocationItem& target_destination,
@@ -141,7 +161,7 @@ int get_target_location_index_within_page(
141161 return -1 ;
142162}
143163
144- bool navigate_to_destination_within_page (
164+ bool navigate_to_destination_within_page_routine (
145165 ConsoleHandle& console,
146166 ProControllerContext& context,
147167 Language language,
@@ -177,6 +197,27 @@ bool navigate_to_destination_within_page(
177197 return false ;
178198}
179199
200+ bool navigate_to_destination_within_page (
201+ ConsoleHandle& console,
202+ ProControllerContext& context,
203+ Language language,
204+ const LocationItem& target_destination
205+ ){
206+ WallClock deadline = current_time () + 30s;
207+ do {
208+ navigate_to_destination_within_page_routine (console, context, language, target_destination);
209+
210+ pbf_wait (context, 1s); // Account for video lag by making confirmation
211+ context.wait_for_all_requests ();
212+
213+ bool found = navigate_to_destination_within_page_routine (console, context, language, target_destination);
214+ if (found){
215+ return true ;
216+ }
217+ } while (current_time () < deadline);
218+ return false ;
219+ }
220+
180221bool navigate_to_lumiose_sewers_location (
181222 ConsoleHandle& console,
182223 ProControllerContext& context,
@@ -203,7 +244,11 @@ bool navigate_to_lumiose_sewers_location(
203244 return false ;
204245 }
205246 if (current_selector_index == (LocationNameReader::PAGE_SIZE - 2 )){
206- break ;
247+ pbf_wait (context, 1s); // Account for video lag by making confirmation
248+ context.wait_for_all_requests ();
249+ if (current_selector_index == (LocationNameReader::PAGE_SIZE - 2 )){
250+ break ;
251+ }
207252 }
208253 // Only move down
209254 int delta = (LocationNameReader::PAGE_SIZE - 2 ) - current_selector_index;
@@ -228,22 +273,30 @@ bool navigate_to_lumiose_sewers_location(
228273 MapIconDetector cafe_woof_icon (COLOR_ORANGE, MapIconType::CafeFlyable, cafe_woof_box, &console.overlay ());
229274 // cafe woof icon detected means lumiose-sewers-1
230275 if (cafe_woof_icon.detect (console.video ().snapshot ()) && target_destination.location == Location::LUMIOSE_SEWERS_1){
231- console.log (" Lumiose Sewers 1 detected" );
232- for (int i = 0 ; i < 5 ; i++){
233- pbf_move_right_joystick (context, {0 , -1 }, 100ms, 300ms); // Zoom out
234- }
276+ pbf_wait (context, 1s); // Account for video lag by making confirmation
235277 context.wait_for_all_requests ();
236- return true ;
278+ if (cafe_woof_icon.detect (console.video ().snapshot ())){
279+ console.log (" Lumiose Sewers 1 detected" );
280+ for (int i = 0 ; i < 5 ; i++){
281+ pbf_move_right_joystick (context, {0 , -1 }, 100ms, 300ms); // Zoom out
282+ }
283+ context.wait_for_all_requests ();
284+ return true ;
285+ }
237286 }
238287 // cafe woof icon not detected means lumiose-sewers-2
239288 // there are no unobstructable icons near lumiose-sewers-2 to use for detection
240289 else if (!cafe_woof_icon.detect (console.video ().snapshot ()) && target_destination.location == Location::LUMIOSE_SEWERS_2){
241- console.log (" Lumiose Sewers 2 detected" );
242- for (int i = 0 ; i < 5 ; i++){
243- pbf_move_right_joystick (context, {0 , -1 }, 100ms, 300ms); // Zoom out
244- }
290+ pbf_wait (context, 1s); // Account for video lag by making confirmation
245291 context.wait_for_all_requests ();
246- return true ;
292+ if (!cafe_woof_icon.detect (console.video ().snapshot ())){
293+ console.log (" Lumiose Sewers 2 detected" );
294+ for (int i = 0 ; i < 5 ; i++){
295+ pbf_move_right_joystick (context, {0 , -1 }, 100ms, 300ms); // Zoom out
296+ }
297+ context.wait_for_all_requests ();
298+ return true ;
299+ }
247300 }
248301 }
249302 pbf_press_dpad (context, DPAD_DOWN, 100ms, 200ms);
@@ -276,10 +329,9 @@ bool navigate_to_destination_in_fast_travel_menu(
276329 return true ;
277330}
278331
279- void set_fast_travel_menu_filter (
332+ bool open_fast_travel_filters_menu (
280333 ConsoleHandle& console,
281- ProControllerContext& context,
282- FAST_TRAVEL_FILTER filter
334+ ProControllerContext& context
283335){
284336 SelectionArrowWatcher first_filter_arrow (
285337 COLOR_YELLOW,
@@ -297,32 +349,69 @@ void set_fast_travel_menu_filter(
297349 switch (ret){
298350 case 0 :
299351 console.log (" Fast travel filter menu opened." );
300- break ;
352+ return true ;
301353 default :
302- OperationFailedException::fire (
303- ErrorReport::SEND_ERROR_REPORT,
304- " set_fast_travel_menu_filter(): Unable to open fast travel filter menu." ,
305- console
306- );
354+ return false ;
307355 }
356+ }
308357
358+ bool set_fast_travel_menu_filter_routine (
359+ ConsoleHandle& console,
360+ ProControllerContext& context,
361+ FAST_TRAVEL_FILTER filter
362+ ){
309363 int target_filter_index = static_cast <int >(filter);
310364 WallClock deadline = current_time () + 30s;
311365 do {
312366 int selected_filter_index = get_current_selector_index (console, FAST_TRAVEL_FILTER_ARROW_BOXES ());
313367 if (selected_filter_index == -1 ){
314- OperationFailedException::fire (
315- ErrorReport::SEND_ERROR_REPORT,
316- " set_fast_travel_menu_filter(): Unable to read current fast travel filter selection." ,
317- console
318- );
368+ return false ;
319369 }
320370 if (selected_filter_index == target_filter_index){
371+ return true ;
372+ }
373+
374+ int delta = target_filter_index - selected_filter_index;
375+ for (; delta > 0 ; delta--){
376+ pbf_press_dpad (context, DPAD_DOWN, 100ms, 200ms);
377+ }
378+ for (; delta < 0 ; delta--){
379+ pbf_press_dpad (context, DPAD_UP, 100ms, 200ms);
380+ }
381+ context.wait_for_all_requests ();
382+ } while (current_time () < deadline);
383+ return false ;
384+ }
385+
386+ void set_fast_travel_menu_filter (
387+ ConsoleHandle& console,
388+ ProControllerContext& context,
389+ FAST_TRAVEL_FILTER filter
390+ ){
391+ WallClock deadline = current_time () + 30s;
392+
393+ bool filters_menu_opened = open_fast_travel_filters_menu (console, context);
394+ if (!filters_menu_opened){
395+ OperationFailedException::fire (
396+ ErrorReport::SEND_ERROR_REPORT,
397+ " set_fast_travel_menu_filter(): Unable to open fast travel filter menu." ,
398+ console
399+ );
400+ }
401+ do {
402+ set_fast_travel_menu_filter_routine (console, context, filter);
403+
404+ pbf_wait (context, 1s); // Account for video lag by making confirmation
405+ context.wait_for_all_requests ();
406+
407+ bool found = set_fast_travel_menu_filter_routine (console, context, filter);
408+ if (found){
409+ int target_arrow_index = static_cast <int >(filter);
321410 SelectionArrowDetector selector_arrow_on_target (
322411 COLOR_YELLOW,
323412 &console.overlay (),
324413 SelectionArrowType::RIGHT,
325- FAST_TRAVEL_FILTER_ARROW_BOXES ().at (target_filter_index )
414+ FAST_TRAVEL_FILTER_ARROW_BOXES ().at (target_arrow_index )
326415 );
327416 for (size_t i = 0 ; i < 4 ; i++){
328417 pbf_press_button (context, BUTTON_A, 100ms, 1000ms);
@@ -334,15 +423,6 @@ void set_fast_travel_menu_filter(
334423 }
335424 }
336425 }
337-
338- int delta = target_filter_index - selected_filter_index;
339- for (; delta > 0 ; delta--){
340- pbf_press_dpad (context, DPAD_DOWN, 100ms, 200ms);
341- }
342- for (; delta < 0 ; delta--){
343- pbf_press_dpad (context, DPAD_UP, 100ms, 200ms);
344- }
345- context.wait_for_all_requests ();
346426 } while (current_time () < deadline);
347427 OperationFailedException::fire (
348428 ErrorReport::SEND_ERROR_REPORT,
0 commit comments