Skip to content

Commit a1b2d6c

Browse files
committed
UserSetupError if user didn't save at the Jubilife gate.
1 parent 664f215 commit a1b2d6c

23 files changed

+296
-86
lines changed

SerialPrograms/Source/PokemonLA/Programs/Farming/PokemonLA_LeapGrinder.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ LeapGrinder::LeapGrinder()
149149
}
150150

151151

152-
bool LeapGrinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
152+
bool LeapGrinder::run_iteration(
153+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
154+
bool fresh_from_reset
155+
){
153156

154157
LeapGrinder_Descriptor::Stats& stats = env.current_stats<LeapGrinder_Descriptor::Stats>();
155158
stats.attempts++;
@@ -183,7 +186,7 @@ bool LeapGrinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControll
183186
int ret = run_until<ProControllerContext>(
184187
env.console, context,
185188
[&](ProControllerContext& context){
186-
route(env, env.console, context, (LeapPokemon)POKEMON.index());
189+
route(env, env.console, context, (LeapPokemon)POKEMON.index(), fresh_from_reset);
187190
},
188191
{{shiny_detector}}
189192
);
@@ -301,19 +304,23 @@ void LeapGrinder::program(SingleSwitchProgramEnvironment& env, ProControllerCont
301304
// Connect the controller.
302305
pbf_press_button(context, BUTTON_LCLICK, 5, 5);
303306

307+
bool fresh_from_reset = false;
304308
while (true){
305309
env.update_stats();
306310
send_program_status_notification(env, NOTIFICATION_STATUS);
307311
try{
308-
if(run_iteration(env, context)){
312+
if(run_iteration(env, context, fresh_from_reset)){
309313
break;
310314
}
311315
}catch (OperationFailedException& e){
312316
stats.errors++;
313317
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);
314318

315319
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
316-
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
320+
fresh_from_reset = reset_game_from_home(
321+
env, env.console, context,
322+
ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST
323+
);
317324
// Switch from items to pokemons
318325
pbf_press_button(context, BUTTON_X, 20, 30);
319326
}

SerialPrograms/Source/PokemonLA/Programs/Farming/PokemonLA_LeapGrinder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class LeapGrinder : public SingleSwitchProgramInstance{
3333
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
3434

3535
private:
36-
bool run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
36+
bool run_iteration(
37+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
38+
bool fresh_from_reset
39+
);
3740
bool quick_check(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
3841

3942
private:

SerialPrograms/Source/PokemonLA/Programs/Farming/PokemonLA_NuggetFarmerHighlands.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,18 @@ NuggetFarmerHighlands::NuggetFarmerHighlands()
9292

9393

9494

95-
bool NuggetFarmerHighlands::run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
95+
bool NuggetFarmerHighlands::run_iteration(
96+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
97+
bool fresh_from_reset
98+
){
9699
NuggetFarmerHighlands_Descriptor::Stats& stats = env.current_stats<NuggetFarmerHighlands_Descriptor::Stats>();
97100

98101
// Go to Coronet Highlands Mountain camp.
99-
goto_camp_from_jubilife(env, env.console, context, TravelLocations::instance().Highlands_Mountain);
102+
goto_camp_from_jubilife(
103+
env, env.console, context,
104+
TravelLocations::instance().Highlands_Mountain,
105+
fresh_from_reset
106+
);
100107

101108
stats.attempts++;
102109

@@ -220,19 +227,23 @@ void NuggetFarmerHighlands::program(SingleSwitchProgramEnvironment& env, ProCont
220227
// Put a save here so that when the program reloads from error it won't break.
221228
save_game_from_overworld(env, env.console, context);
222229

230+
bool fresh_from_reset = false;
223231
while (true){
224232
env.update_stats();
225233
send_program_status_notification(env, NOTIFICATION_STATUS);
226234
try{
227-
if (run_iteration(env, context)){
235+
if (run_iteration(env, context, fresh_from_reset)){
228236
break;
229237
}
230238
}catch (OperationFailedException& e){
231239
stats.errors++;
232240
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);
233241

234242
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
235-
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
243+
fresh_from_reset = reset_game_from_home(
244+
env, env.console, context,
245+
ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST
246+
);
236247
}
237248
}
238249

SerialPrograms/Source/PokemonLA/Programs/Farming/PokemonLA_NuggetFarmerHighlands.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class NuggetFarmerHighlands : public SingleSwitchProgramInstance{
3131
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
3232

3333
private:
34-
bool run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
34+
bool run_iteration(
35+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
36+
bool fresh_from_reset
37+
);
3538

3639
private:
3740
class RunRoute;

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_MMORoutines.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ std::set<std::string> enter_region_and_read_MMO(
5252
const std::set<std::string>& desired_star_MMOs,
5353
bool debug_mode,
5454
int& num_mmo_pokemon_found,
55-
int& num_star_mmo_found
55+
int& num_star_mmo_found,
56+
bool fresh_from_reset
5657
){
5758
MapRegion region = MapRegion::NONE;
5859
TravelLocation location = TravelLocations::instance().Fieldlands_Fieldlands;
@@ -111,7 +112,7 @@ std::set<std::string> enter_region_and_read_MMO(
111112
}
112113

113114
env.log("Go to " + std::string(MAP_REGION_NAMES[int(region)]) + " to check MMO.");
114-
goto_camp_from_jubilife(env, env.console, context, location);
115+
goto_camp_from_jubilife(env, env.console, context, location, fresh_from_reset);
115116

116117
// Open map
117118
pbf_press_button(context, BUTTON_MINUS, 50, 100);

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_MMORoutines.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ std::set<std::string> enter_region_and_read_MMO(
4343
const std::set<std::string>& desired_star_MMOs,
4444
bool debug,
4545
int& num_mmo_found,
46-
int& num_star_mmo_found
46+
int& num_star_mmo_found,
47+
bool fresh_from_reset
4748
);
4849

4950

5051
}
5152
}
52-
}
53+
}

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_OutbreakFinder.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,18 @@ std::set<std::string> OutbreakFinder::read_travel_map_outbreaks(
308308
}
309309

310310

311-
void OutbreakFinder::goto_region_and_return(SingleSwitchProgramEnvironment& env, ProControllerContext& context,
312-
bool inside_travel_map
311+
void OutbreakFinder::goto_region_and_return(
312+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
313+
bool inside_travel_map,
314+
bool fresh_from_reset
313315
){
314316
env.log("Go to a random region and back to refresh outbreaks...");
315317
env.console.overlay().add_log("Refresh outbreaks");
316318
OutbreakFinder_Descriptor::Stats& stats = env.current_stats<OutbreakFinder_Descriptor::Stats>();
317319

318320
if (inside_travel_map == false){
319321
// Move to guard to open map
320-
open_travel_map_from_jubilife(env, env.console, context);
322+
open_travel_map_from_jubilife(env, env.console, context, fresh_from_reset);
321323
context.wait_for(std::chrono::milliseconds(500));
322324
}
323325

@@ -408,13 +410,14 @@ std::vector<std::string> OutbreakFinder::run_iteration(
408410
const std::set<std::string>& desired_hisui_map_events,
409411
const std::set<std::string>& desired_outbreaks,
410412
const std::set<std::string>& desired_MMOs,
411-
const std::set<std::string>& desired_star_MMOs
413+
const std::set<std::string>& desired_star_MMOs,
414+
bool& fresh_from_reset
412415
){
413416
OutbreakFinder_Descriptor::Stats& stats = env.current_stats<OutbreakFinder_Descriptor::Stats>();
414417

415418
// Enter map.
416419
try{
417-
open_travel_map_from_jubilife(env, env.console, context);
420+
open_travel_map_from_jubilife(env, env.console, context, fresh_from_reset);
418421
}catch (OperationFailedException&){
419422
stats.errors++;
420423
throw;
@@ -463,12 +466,19 @@ std::vector<std::string> OutbreakFinder::run_iteration(
463466
// To not waste them, save here so that we can reset to get berries back.
464467
save_game_from_overworld(env, env.console, context);
465468

466-
for(const auto& mmo_name: found_hisui_map_events){
469+
for (const auto& mmo_name: found_hisui_map_events){
467470
int num_new_mmo_pokemon_found = 0;
468471
int num_new_star_mmo_found = 0;
469472
std::set<std::string> found_pokemon = enter_region_and_read_MMO(
470-
env, context, mmo_name, desired_MMOs, desired_star_MMOs, DEBUG_MODE,
471-
num_new_mmo_pokemon_found, num_new_star_mmo_found);
473+
env, context,
474+
mmo_name,
475+
desired_MMOs,
476+
desired_star_MMOs,
477+
DEBUG_MODE,
478+
num_new_mmo_pokemon_found,
479+
num_new_star_mmo_found,
480+
fresh_from_reset
481+
);
472482
stats.mmo_pokemon += num_new_mmo_pokemon_found;
473483
stats.stars += num_new_star_mmo_found;
474484
env.update_stats();
@@ -488,15 +498,18 @@ std::vector<std::string> OutbreakFinder::run_iteration(
488498
env.log("No target MMO sprite found. Reset game...");
489499
env.console.overlay().add_log("No target MMO");
490500
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
491-
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
501+
fresh_from_reset = reset_game_from_home(
502+
env, env.console, context,
503+
ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST
504+
);
492505
}
493506
}
494507

495508
env.update_stats();
496509
send_program_status_notification(env, NOTIFICATION_STATUS);
497510

498511
// Go to an arbitrary region and return to refresh outbreaks.
499-
goto_region_and_return(env, context, inside_travel_map);
512+
goto_region_and_return(env, context, inside_travel_map, fresh_from_reset);
500513

501514
return std::vector<std::string>();
502515
}
@@ -514,16 +527,20 @@ void OutbreakFinder::program(SingleSwitchProgramEnvironment& env, ProControllerC
514527
// press a random button to let Switch register the wired controller
515528
pbf_press_button(context, BUTTON_ZL, 10ms, 30ms);
516529

530+
bool fresh_from_reset = false;
517531
if (RESET_GAME_AND_CONTINUE_SEARCHING){
518532
// the outbreak found by the last program run did not yield what the user wants.
519533
// so we reset the game now and skip the ongoing outbreaks
520534
env.log("Reset game and skip ongoing outbreaks");
521535
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
522-
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
536+
fresh_from_reset = reset_game_from_home(
537+
env, env.console, context,
538+
ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST
539+
);
523540

524541
// Go to region and return.
525542
bool inside_travel_map = false;
526-
goto_region_and_return(env, context, inside_travel_map);
543+
goto_region_and_return(env, context, inside_travel_map, fresh_from_reset);
527544
}
528545

529546
std::set<std::string> desired_outbreaks = to_set(DESIRED_MO_SLUGS);
@@ -581,8 +598,13 @@ void OutbreakFinder::program(SingleSwitchProgramEnvironment& env, ProControllerC
581598
std::vector<std::string> found_outbreaks;
582599
while (true){
583600
found_outbreaks = run_iteration(
584-
env, context, desired_hisui_map_events, desired_outbreaks, desired_MMO_pokemon,
585-
desired_star_MMO_pokemon);
601+
env, context,
602+
desired_hisui_map_events,
603+
desired_outbreaks,
604+
desired_MMO_pokemon,
605+
desired_star_MMO_pokemon,
606+
fresh_from_reset
607+
);
586608
if (found_outbreaks.size() > 0)
587609
{
588610
break;

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_OutbreakFinder.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class OutbreakFinder : public SingleSwitchProgramInstance{
5858
const std::set<std::string>& desired_hisui_map_events,
5959
const std::set<std::string>& desired_outbreaks,
6060
const std::set<std::string>& desired_MMO_pokemon,
61-
const std::set<std::string>& desired_star_MMO_pokemon);
61+
const std::set<std::string>& desired_star_MMO_pokemon,
62+
bool& fresh_from_reset
63+
);
6264

6365
// Read the travel map from Jublilife village to find any desired pokemon or MMO events.
6466
// Return true if program should stop (match found).
@@ -73,7 +75,8 @@ class OutbreakFinder : public SingleSwitchProgramInstance{
7375
// Otherwise, the function is called when the player character is standing at the program start location.
7476
void goto_region_and_return(
7577
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
76-
bool inside_map
78+
bool inside_map,
79+
bool fresh_from_reset
7780
);
7881

7982
static std::set<std::string> to_set(const StringSelectTableOption& option);

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_RamanasIslandCombee.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ void RamanasCombeeFinder::grouped_path(SingleSwitchProgramEnvironment& env, ProC
247247

248248
}
249249

250-
void RamanasCombeeFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
250+
void RamanasCombeeFinder::run_iteration(
251+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
252+
bool fresh_from_reset
253+
){
251254
RamanasCombeeFinder_Descriptor::Stats& stats = env.current_stats<RamanasCombeeFinder_Descriptor::Stats>();
252255
stats.attempts++;
253256
env.update_stats();
@@ -283,7 +286,11 @@ void RamanasCombeeFinder::run_iteration(SingleSwitchProgramEnvironment& env, Pro
283286

284287
BlackOutDetector black_out_detector(env.console, env.console);
285288

286-
goto_camp_from_jubilife(env, env.console, context, TravelLocations::instance().Fieldlands_Heights);
289+
goto_camp_from_jubilife(
290+
env, env.console, context,
291+
TravelLocations::instance().Fieldlands_Heights,
292+
fresh_from_reset
293+
);
287294

288295
int ret = run_until<ProControllerContext>(
289296
env.console, context,
@@ -324,17 +331,21 @@ void RamanasCombeeFinder::program(SingleSwitchProgramEnvironment& env, ProContro
324331
// Connect the controller.
325332
pbf_press_button(context, BUTTON_LCLICK, 5, 5);
326333

334+
bool fresh_from_reset = false;
327335
while (true){
328336
env.update_stats();
329337
send_program_status_notification(env, NOTIFICATION_STATUS);
330338
try{
331-
run_iteration(env, context);
339+
run_iteration(env, context, fresh_from_reset);
332340
}catch (OperationFailedException& e){
333341
stats.errors++;
334342
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);
335343

336344
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
337-
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
345+
fresh_from_reset = reset_game_from_home(
346+
env, env.console, context,
347+
ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST
348+
);
338349
}
339350
}
340351

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_RamanasIslandCombee.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class RamanasCombeeFinder: public SingleSwitchProgramInstance{
3333
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
3434

3535
private:
36-
void run_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
36+
void run_iteration(
37+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
38+
bool fresh_from_reset
39+
);
3740
void grouped_path(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
3841
void check_tree_no_stop(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
3942
bool check_tree(SingleSwitchProgramEnvironment& env, ProControllerContext& context);

0 commit comments

Comments
 (0)