1818#include " PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
1919#include " PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h"
2020#include " PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
21+ #include " PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
2122#include " PokemonLZA/Programs/PokemonLZA_GameEntry.h"
2223#include " PokemonLZA/Programs/PokemonLZA_MenuNavigation.h"
2324#include " NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
@@ -96,6 +97,12 @@ AutoFossil::AutoFossil()
9697 LockMode::LOCK_WHILE_RUNNING,
9798 0
9899 )
100+ , CONTINUE_AFTER_FIND(
101+ " <b>Continue after finding a match:</b><br>"
102+ " After finding a match, the program will go to the next box, save and continue hunting. Beware, it will use a lot of fossils so start the program with a lot of them and enough empty boxes." ,
103+ LockMode::LOCK_WHILE_RUNNING,
104+ false
105+ )
99106 , TAKE_VIDEO(
100107 " Take a video When Found:" ,
101108 LockMode::UNLOCK_WHILE_RUNNING,
@@ -121,6 +128,7 @@ AutoFossil::AutoFossil()
121128 PA_ADD_OPTION (NUM_FOSSILS);
122129 PA_ADD_OPTION (WHICH_FOSSIL);
123130 PA_ADD_OPTION (STOP_ON);
131+ PA_ADD_OPTION (CONTINUE_AFTER_FIND);
124132 PA_ADD_OPTION (TAKE_VIDEO);
125133 PA_ADD_OPTION (GO_HOME_WHEN_DONE);
126134 PA_ADD_OPTION (NOTIFICATIONS);
@@ -148,22 +156,28 @@ void AutoFossil::program(SingleSwitchProgramEnvironment& env, ProControllerConte
148156 }
149157
150158 overworld_to_box_system (env.console , context);
159+ bool found_match = false ;
151160 for (uint8_t i = 0 ; i < num_boxes; i++){
152161 size_t num_fossils_in_box = (i == num_boxes - 1 ? num_fossils_to_revive - i*30 : 30 );
153- bool found_match = check_fossils_in_one_box (env, context, i*30 , num_fossils_in_box);
154- if (found_match){
162+ found_match = check_fossils_in_one_box (env, context, i*30 , num_fossils_in_box);
163+ if (found_match && !CONTINUE_AFTER_FIND ){
155164 send_program_finished_notification (env, NOTIFICATION_STATUS);
156165 return ;
157166 }
158- if (i != num_boxes - 1 ){
159- // go to next page
160- pbf_press_button (context, BUTTON_R, 200ms, 200ms);
161- }
167+ // go to next page
168+ pbf_press_button (context, BUTTON_R, 200ms, 200ms);
162169 }
163- // checked all boxes, no match
164- go_home (env.console , context);
165- reset_game_from_home (env, env.console , context);
166-
170+ if (found_match){
171+ // We didn't return early so we must be continuing after finding a match
172+ box_system_to_overworld (env.console , context);
173+ save_game_to_menu (env.console , context);
174+ pbf_mash_button (context, BUTTON_B, 2000ms);
175+ }else {
176+ // checked all boxes, no match
177+ go_home (env.console , context);
178+ reset_game_from_home (env, env.console , context);
179+ }
180+
167181 send_program_status_notification (env, NOTIFICATION_STATUS);
168182 }
169183}
@@ -259,6 +273,7 @@ bool AutoFossil::check_fossils_in_one_box(
259273
260274 uint8_t box_row = 1 , box_col = 0 ;
261275 bool next_cell_right = true ;
276+ bool found_match = false ;
262277 BoxDetector box_detector (COLOR_RED, &env.console .overlay ());
263278 BoxPageInfoWatcher info_watcher (&env.console .overlay ());
264279 for (size_t i = 0 ; i < num_fossils_in_box; i++){
@@ -318,11 +333,14 @@ bool AutoFossil::check_fossils_in_one_box(
318333 pbf_press_button (context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0 );
319334 context.wait_for_all_requests ();
320335 }
321- GO_HOME_WHEN_DONE.run_end_of_program (context);
322- return true ;
336+ if (CONTINUE_AFTER_FIND){
337+ found_match = true ;
338+ }else {
339+ GO_HOME_WHEN_DONE.run_end_of_program (context);
340+ return true ;
341+ }
323342 }
324343
325-
326344 if (next_cell_right){
327345 if (box_col == 5 ){
328346 box_row++;
@@ -347,7 +365,7 @@ bool AutoFossil::check_fossils_in_one_box(
347365 }
348366 }
349367 }
350- return false ;
368+ return found_match ;
351369}
352370
353371}
0 commit comments