Skip to content

Commit 3d411ca

Browse files
authored
Add continue option to auto fossil (#879)
1 parent b4ad7d7 commit 3d411ca

File tree

5 files changed

+86
-14
lines changed

5 files changed

+86
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ __pycache__
6161
# Jupyter Notebooks
6262
*.ipynb
6363

64+
vcpkg/
65+
6466
CLAUDE.md

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_MenuNavigation.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,51 @@ void overworld_to_box_system(ConsoleHandle& console, ProControllerContext& conte
115115
);
116116
}
117117

118+
void box_system_to_overworld(ConsoleHandle& console, ProControllerContext& context){
119+
WallClock deadline = current_time() + std::chrono::seconds(120);
120+
while (current_time() < deadline){
121+
OverworldPartySelectionWatcher overworld(COLOR_RED, &console.overlay());
122+
MainMenuWatcher main_menu(COLOR_GREEN, &console.overlay());
123+
BoxWatcher box(COLOR_BLUE, &console.overlay());
124+
context.wait_for_all_requests();
125+
int ret = wait_until(
126+
console, context,
127+
std::chrono::seconds(30),
128+
{
129+
overworld,
130+
main_menu,
131+
box,
132+
}
133+
);
134+
context.wait_for(std::chrono::milliseconds(100));
135+
switch (ret){
136+
case 0:
137+
console.log("Detected Overworld...");
138+
return;
139+
case 1:
140+
console.log("Detected Main Menu...");
141+
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
142+
continue;
143+
case 2:
144+
console.log("Detected Box System...");
145+
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
146+
continue;
147+
default:
148+
OperationFailedException::fire(
149+
ErrorReport::SEND_ERROR_REPORT,
150+
"overworld_to_box_system(): No state detected after 30 seconds.",
151+
console
152+
);
153+
}
154+
}
155+
156+
OperationFailedException::fire(
157+
ErrorReport::SEND_ERROR_REPORT,
158+
"overworld_to_box_system(): Failed to exit box system after 2 minutes.",
159+
console
160+
);
161+
}
162+
118163

119164
}
120165
}

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_MenuNavigation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ void overworld_to_box_system(
2929
ConsoleHandle& console, ProControllerContext& context
3030
);
3131

32+
// From box system, press B until overworld is reached
33+
void box_system_to_overworld(
34+
ConsoleHandle& console, ProControllerContext& context
35+
);
36+
37+
3238

3339
}
3440
}

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_AutoFossil.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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
}

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_AutoFossil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class AutoFossil : public SingleSwitchProgramInstance{
5050
SimpleIntegerOption<uint32_t> NUM_FOSSILS;
5151
IntegerEnumDropdownOption WHICH_FOSSIL;
5252
PokemonLA::StopOnOption STOP_ON;
53+
BooleanCheckBoxOption CONTINUE_AFTER_FIND;
5354

5455
BooleanCheckBoxOption TAKE_VIDEO;
5556
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;

0 commit comments

Comments
 (0)