Skip to content

Commit 7411c60

Browse files
committed
more autostory refactoring
1 parent 7ac814a commit 7411c60

24 files changed

+189
-739
lines changed

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,24 +1225,17 @@ void checkpoint_reattempt_loop(
12251225
ProControllerContext& context,
12261226
EventNotificationOption& notif_status_update,
12271227
AutoStoryStats& stats,
1228-
std::function<void()>&& action
1228+
std::function<void(size_t attempt_number)>&& action
12291229
){
12301230
size_t max_attempts = 100;
1231-
bool first_attempt = true;
12321231
for (size_t i = 0;;i++){
12331232
try{
1234-
if (first_attempt){
1233+
if (i==0){
12351234
checkpoint_save(env, context, notif_status_update, stats);
1236-
first_attempt = false;
1237-
}else{
1238-
enter_menu_from_overworld(env.program_info(), env.console, context, -1);
1239-
// we wait 10 seconds then save, so that the initial conditions are slightly different on each reset.
1240-
env.log("Wait 10 seconds.");
1241-
context.wait_for(Milliseconds(10 * 1000));
1242-
save_game_from_overworld(env.program_info(), env.console, context);
12431235
}
12441236

1245-
action();
1237+
context.wait_for_all_requests();
1238+
action(i);
12461239

12471240
break;
12481241
}catch(OperationFailedException&){
@@ -1265,6 +1258,37 @@ void checkpoint_reattempt_loop(
12651258

12661259
}
12671260

1261+
void checkpoint_reattempt_loop_tutorial(
1262+
SingleSwitchProgramEnvironment& env,
1263+
ProControllerContext& context,
1264+
EventNotificationOption& notif_status_update,
1265+
AutoStoryStats& stats,
1266+
std::function<void(size_t attempt_number)>&& action
1267+
){
1268+
1269+
for (size_t i = 0;;i++){
1270+
try{
1271+
if(i==0){
1272+
save_game_tutorial(env.program_info(), env.console, context);
1273+
stats.m_checkpoint++;
1274+
env.update_stats();
1275+
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
1276+
}
1277+
1278+
context.wait_for_all_requests();
1279+
action(i);
1280+
1281+
break;
1282+
}catch(OperationFailedException&){
1283+
context.wait_for_all_requests();
1284+
env.console.log("Resetting from checkpoint.");
1285+
reset_game(env.program_info(), env.console, context);
1286+
stats.m_reset++;
1287+
env.update_stats();
1288+
}
1289+
}
1290+
}
1291+
12681292

12691293

12701294

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,23 @@ void move_cursor_towards_flypoint_and_go_there(
337337

338338
void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int expected_number);
339339

340+
// run given action, with max_attempts number of attempts
341+
// save prior to first attempt
342+
// throw exception if we try to exceed max_attempts.
340343
void checkpoint_reattempt_loop(
341344
SingleSwitchProgramEnvironment& env,
342345
ProControllerContext& context,
343346
EventNotificationOption& notif_status_update,
344347
AutoStoryStats& stats,
345-
std::function<void()>&& action
348+
std::function<void(size_t attempt_number)>&& action
349+
);
350+
351+
void checkpoint_reattempt_loop_tutorial(
352+
SingleSwitchProgramEnvironment& env,
353+
ProControllerContext& context,
354+
EventNotificationOption& notif_status_update,
355+
AutoStoryStats& stats,
356+
std::function<void(size_t attempt_number)>&& action
346357
);
347358

348359

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,17 @@ void checkpoint_01(
7575
AutoStoryStats& stats,
7676
Language language
7777
){
78-
bool first_attempt = true;
79-
while (true){
80-
try{
81-
if(first_attempt){
82-
save_game_tutorial(env.program_info(), env.console, context);
83-
stats.m_checkpoint++;
84-
env.update_stats();
85-
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
86-
}
78+
checkpoint_reattempt_loop_tutorial(env, context, notif_status_update, stats,
79+
[&](size_t attempt_number){
8780

8881
context.wait_for_all_requests();
8982
// set settings
9083
enter_menu_from_overworld(env.program_info(), env.console, context, 0, MenuSide::RIGHT, false);
91-
change_settings(env, context, language, first_attempt);
84+
change_settings(env, context, language, attempt_number==0);
9285
pbf_mash_button(context, BUTTON_B, 2 * TICKS_PER_SECOND);
9386
context.wait_for_all_requests();
9487

95-
break;
96-
}catch(OperationFailedException&){
97-
// (void)e;
98-
first_attempt = false;
99-
context.wait_for_all_requests();
100-
env.console.log("Resetting from checkpoint.");
101-
reset_game(env.program_info(), env.console, context);
102-
stats.m_reset++;
103-
env.update_stats();
104-
}
105-
}
88+
});
10689
}
10790

10891
void checkpoint_02(
@@ -111,16 +94,8 @@ void checkpoint_02(
11194
EventNotificationOption& notif_status_update,
11295
AutoStoryStats& stats
11396
){
114-
bool first_attempt = true;
115-
while (true){
116-
try{
117-
if(first_attempt){
118-
save_game_tutorial(env.program_info(), env.console, context);
119-
stats.m_checkpoint++;
120-
env.update_stats();
121-
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
122-
first_attempt = false;
123-
}
97+
checkpoint_reattempt_loop_tutorial(env, context, notif_status_update, stats,
98+
[&](size_t attempt_number){
12499

125100
context.wait_for_all_requests();
126101
env.console.log("Go downstairs, get stopped by Skwovet");
@@ -184,15 +159,7 @@ void checkpoint_02(
184159
open_map_from_overworld(env.program_info(), env.console, context, true);
185160
leave_phone_to_overworld(env.program_info(), env.console, context);
186161

187-
break;
188-
}catch(OperationFailedException&){
189-
context.wait_for_all_requests();
190-
env.console.log("Resetting from checkpoint.");
191-
reset_game(env.program_info(), env.console, context);
192-
stats.m_reset++;
193-
env.update_stats();
194-
}
195-
}
162+
});
196163
}
197164

198165
void checkpoint_03(
@@ -204,7 +171,7 @@ void checkpoint_03(
204171
StarterChoice starter_choice
205172
){
206173
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
207-
[&](){
174+
[&](size_t attempt_number){
208175

209176
context.wait_for_all_requests();
210177
DirectionDetector direction;

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void checkpoint_04(
6868
AutoStoryStats& stats
6969
){
7070
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
71-
[&](){
71+
[&](size_t attempt_number){
7272
context.wait_for_all_requests();
7373

7474
DirectionDetector direction;

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void checkpoint_05(
6565
AutoStoryStats& stats
6666
){
6767
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
68-
[&](){
68+
[&](size_t attempt_number){
6969
context.wait_for_all_requests();
7070

7171
DirectionDetector direction;
@@ -89,7 +89,7 @@ void checkpoint_06(
8989
AutoStoryStats& stats
9090
){
9191
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
92-
[&](){
92+
[&](size_t attempt_number){
9393

9494
context.wait_for_all_requests();
9595

@@ -127,7 +127,7 @@ void checkpoint_07(
127127
AutoStoryStats& stats
128128
){
129129
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
130-
[&](){
130+
[&](size_t attempt_number){
131131

132132
context.wait_for_all_requests();
133133
env.console.log("Move to cliff");

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void checkpoint_08(
6868
AutoStoryStats& stats
6969
){
7070
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
71-
[&](){
71+
[&](size_t attempt_number){
7272

7373
context.wait_for_all_requests();
7474

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_05.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void checkpoint_09(
6969
AutoStoryStats& stats
7070
){
7171
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
72-
[&](){
72+
[&](size_t attempt_number){
7373

7474
context.wait_for_all_requests();
7575

@@ -108,7 +108,7 @@ void checkpoint_10(
108108
AutoStoryStats& stats
109109
){
110110
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
111-
[&](){
111+
[&](size_t attempt_number){
112112

113113
context.wait_for_all_requests();
114114
env.console.log("Lighthouse view");

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_06.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void checkpoint_11(
6868
AutoStoryStats& stats
6969
){
7070
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
71-
[&](){
71+
[&](size_t attempt_number){
7272

7373
context.wait_for_all_requests();
7474
do_action_and_monitor_for_battles(env.program_info(), env.console, context,

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_07.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void checkpoint_12(
7171
// or when lead pokemon not strong enough to clear them with Let's go
7272

7373
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
74-
[&](){
74+
[&](size_t attempt_number){
7575

7676
fly_to_overlapping_flypoint(env.program_info(), env.console, context);
7777
context.wait_for_all_requests();

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_08.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void checkpoint_13(
7171
// reset rate: 0%. 0 resets out of 70.
7272

7373
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
74-
[&](){
74+
[&](size_t attempt_number){
7575
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
7676
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
7777

@@ -108,7 +108,7 @@ void checkpoint_14(
108108
){
109109

110110
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
111-
[&](){
111+
[&](size_t attempt_number){
112112

113113
context.wait_for_all_requests();
114114
// realign diagonally to the left
@@ -155,7 +155,7 @@ void checkpoint_15(
155155
){
156156

157157
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
158-
[&](){
158+
[&](size_t attempt_number){
159159

160160
context.wait_for_all_requests();
161161
// realign diagonally to the right

0 commit comments

Comments
 (0)