Skip to content

Commit 3798214

Browse files
authored
Autostory updates (#659)
* Catch only OperationFailedException, instead of all Exceptions * Change Segment number format. Update Start/End Segment logging. * Increment segment number at the beginning of the segment, instead of at the end. * Throw error if start segment is greater than end segment.
1 parent c82db11 commit 3798214

26 files changed

+159
-143
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, ProController
711711
NOTIFICATION_STATUS_UPDATE
712712
};
713713

714+
if (get_start_segment_index() > get_end_segment_index()){
715+
throw UserSetupError(env.logger(), "The start segment cannot be later than the end segment.");
716+
}
717+
714718
for (size_t segment_index = get_start_segment_index(); segment_index <= get_end_segment_index(); segment_index++){
715719
ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->run_segment(env, context, options);
716720
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void AutoStory_Segment_00::run_segment(
3939
ProControllerContext& context,
4040
AutoStoryOptions options
4141
) const{
42-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
42+
// AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4343

4444
context.wait_for_all_requests();
4545
env.console.log("Start Segment 00: Intro Cutscene", COLOR_ORANGE);
@@ -48,8 +48,6 @@ void AutoStory_Segment_00::run_segment(
4848

4949
context.wait_for_all_requests();
5050
env.console.log("End Segment 00: Intro Cutscene", COLOR_GREEN);
51-
stats.m_segment++;
52-
env.update_stats();
5351
}
5452

5553

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void AutoStory_Segment_01::run_segment(
5353
) const{
5454
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
5555

56+
stats.m_segment++;
57+
env.update_stats();
5658
context.wait_for_all_requests();
5759
env.console.log("Start Segment 01: Pick Starter", COLOR_ORANGE);
5860

@@ -62,8 +64,6 @@ void AutoStory_Segment_01::run_segment(
6264

6365
context.wait_for_all_requests();
6466
env.console.log("End Segment 01: Pick Starter", COLOR_GREEN);
65-
stats.m_segment++;
66-
env.update_stats();
6767

6868
}
6969

@@ -93,7 +93,7 @@ AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
9393
context.wait_for_all_requests();
9494

9595
break;
96-
}catch(...){
96+
}catch(OperationFailedException&){
9797
// (void)e;
9898
first_attempt = false;
9999
context.wait_for_all_requests();
@@ -185,7 +185,7 @@ void checkpoint_02(
185185
leave_phone_to_overworld(env.program_info(), env.console, context);
186186

187187
break;
188-
}catch(...){
188+
}catch(OperationFailedException&){
189189
context.wait_for_all_requests();
190190
env.console.log("Resetting from checkpoint.");
191191
reset_game(env.program_info(), env.console, context);
@@ -278,7 +278,7 @@ void checkpoint_03(
278278
leave_box_system_to_overworld(env.program_info(), env.console, context);
279279

280280
break;
281-
}catch(...){
281+
}catch(OperationFailedException&){
282282
context.wait_for_all_requests();
283283
env.console.log("Resetting from checkpoint.");
284284
reset_game(env.program_info(), env.console, context);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
89
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
910
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
@@ -48,15 +49,15 @@ void AutoStory_Segment_02::run_segment(
4849
) const{
4950
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
5051

52+
stats.m_segment++;
53+
env.update_stats();
5154
context.wait_for_all_requests();
5255
env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);
5356

5457
checkpoint_04(env, context, options.notif_status_update);
5558

5659
context.wait_for_all_requests();
57-
env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN);
58-
stats.m_segment++;
59-
env.update_stats();
60+
env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN);
6061

6162
}
6263

@@ -93,7 +94,7 @@ void checkpoint_04(
9394
env.console.log("Finished battle.");
9495

9596
break;
96-
}catch(...){
97+
}catch(OperationFailedException&){
9798
context.wait_for_all_requests();
9899
env.console.log("Resetting from checkpoint.");
99100
reset_game(env.program_info(), env.console, context);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
89
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
910
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
@@ -43,6 +44,8 @@ std::string AutoStory_Segment_03::end_text() const{
4344
void AutoStory_Segment_03::run_segment(SingleSwitchProgramEnvironment& env, ProControllerContext& context, AutoStoryOptions options) const{
4445
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4546

47+
stats.m_segment++;
48+
env.update_stats();
4649
context.wait_for_all_requests();
4750
env.console.log("Start Segment 03: Catch Tutorial", COLOR_ORANGE);
4851

@@ -52,8 +55,6 @@ void AutoStory_Segment_03::run_segment(SingleSwitchProgramEnvironment& env, ProC
5255

5356
context.wait_for_all_requests();
5457
env.console.log("End Segment 03: Catch Tutorial", COLOR_GREEN);
55-
stats.m_segment++;
56-
env.update_stats();
5758

5859
}
5960

@@ -84,7 +85,7 @@ void checkpoint_05(
8485
env.console.overlay().add_log("Get mom's sandwich", COLOR_WHITE);
8586
mash_button_till_overworld(env.console, context);
8687
break;
87-
}catch(...){
88+
}catch(OperationFailedException&){
8889
context.wait_for_all_requests();
8990
env.console.log("Resetting from checkpoint.");
9091
reset_game(env.program_info(), env.console, context);
@@ -134,7 +135,7 @@ void checkpoint_06(
134135
env.console.overlay().add_log("Finished catch tutorial", COLOR_WHITE);
135136

136137
break;
137-
}catch(...){
138+
}catch(OperationFailedException&){
138139
context.wait_for_all_requests();
139140
env.console.log("Resetting from checkpoint.");
140141
reset_game(env.program_info(), env.console, context);
@@ -188,7 +189,7 @@ void checkpoint_07(
188189
env.console.overlay().add_log("Mystery cry", COLOR_WHITE);
189190

190191
break;
191-
}catch(...){
192+
}catch(OperationFailedException&){
192193
context.wait_for_all_requests();
193194
env.console.log("Resetting from checkpoint.");
194195
reset_game(env.program_info(), env.console, context);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ void AutoStory_Segment_04::run_segment(
4949
) const{
5050
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
5151

52+
stats.m_segment++;
53+
env.update_stats();
5254
context.wait_for_all_requests();
5355
env.console.log("Start Segment 04: Rescue Legendary", COLOR_ORANGE);
5456

5557
checkpoint_08(env, context, options.notif_status_update);
5658

5759
context.wait_for_all_requests();
5860
env.console.log("End Segment 04: Rescue Legendary", COLOR_GREEN);
59-
stats.m_segment++;
60-
env.update_stats();
6161

6262
}
6363

@@ -193,7 +193,7 @@ void checkpoint_08(
193193
mash_button_till_overworld(env.console, context, BUTTON_A);
194194

195195
break;
196-
}catch(...){
196+
}catch(OperationFailedException&){
197197
context.wait_for_all_requests();
198198
env.console.log("Resetting from checkpoint.");
199199
reset_game(env.program_info(), env.console, context);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
89
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
910
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
@@ -47,6 +48,8 @@ void AutoStory_Segment_05::run_segment(
4748
) const{
4849
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4950

51+
stats.m_segment++;
52+
env.update_stats();
5053
context.wait_for_all_requests();
5154
env.console.log("Start Segment 05: First Arven Battle", COLOR_ORANGE);
5255

@@ -55,8 +58,6 @@ void AutoStory_Segment_05::run_segment(
5558

5659
context.wait_for_all_requests();
5760
env.console.log("End Segment 05: First Arven Battle", COLOR_GREEN);
58-
stats.m_segment++;
59-
env.update_stats();
6061

6162
}
6263

@@ -101,7 +102,7 @@ void checkpoint_09(
101102
env.console.overlay().add_log("Receive legendary ball", COLOR_WHITE);
102103

103104
break;
104-
}catch(...){
105+
}catch(OperationFailedException&){
105106
context.wait_for_all_requests();
106107
env.console.log("Resetting from checkpoint.");
107108
reset_game(env.program_info(), env.console, context);
@@ -143,7 +144,7 @@ void checkpoint_10(
143144
mash_button_till_overworld(env.console, context, BUTTON_A);
144145

145146
break;
146-
}catch(...){
147+
}catch(OperationFailedException&){
147148
context.wait_for_all_requests();
148149
env.console.log("Resetting from checkpoint.");
149150
reset_game(env.program_info(), env.console, context);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
89
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
910
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
@@ -46,15 +47,15 @@ void AutoStory_Segment_06::run_segment(
4647
) const{
4748
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4849

50+
stats.m_segment++;
51+
env.update_stats();
4952
context.wait_for_all_requests();
5053
env.console.log("Start Segment 06: Go to Los Platos", COLOR_ORANGE);
5154

5255
checkpoint_11(env, context, options.notif_status_update);
5356

5457
context.wait_for_all_requests();
5558
env.console.log("End Segment 06: Go to Los Platos", COLOR_GREEN);
56-
stats.m_segment++;
57-
env.update_stats();
5859

5960
}
6061

@@ -109,7 +110,7 @@ void checkpoint_11(
109110
env.console.overlay().add_log("Reached Los Platos", COLOR_WHITE);
110111

111112
break;
112-
}catch(...){
113+
}catch(OperationFailedException&){
113114
context.wait_for_all_requests();
114115
env.console.log("Resetting from checkpoint.");
115116
reset_game(env.program_info(), env.console, context);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
89
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
910
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
@@ -46,6 +47,8 @@ void AutoStory_Segment_07::run_segment(
4647
) const{
4748
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4849

50+
stats.m_segment++;
51+
env.update_stats();
4952
context.wait_for_all_requests();
5053
env.console.log("Start Segment 07: Go to Mesagoza South", COLOR_ORANGE);
5154

@@ -63,8 +66,6 @@ void AutoStory_Segment_07::run_segment(
6366

6467
context.wait_for_all_requests();
6568
env.console.log("End Segment 07: Go to Mesagoza South", COLOR_GREEN);
66-
stats.m_segment++;
67-
env.update_stats();
6869

6970
}
7071

@@ -120,7 +121,7 @@ void checkpoint_12(
120121
env.console.log("Reached Mesagoza (South) Pokecenter.");
121122

122123
break;
123-
}catch(...){
124+
}catch(OperationFailedException&){
124125
context.wait_for_all_requests();
125126
env.console.log("Resetting from checkpoint.");
126127
reset_game(env.program_info(), env.console, context);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
89
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
910
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
@@ -44,6 +45,8 @@ void AutoStory_Segment_08::run_segment(
4445
) const{
4546
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4647

48+
stats.m_segment++;
49+
env.update_stats();
4750
context.wait_for_all_requests();
4851
env.console.log("Start Segment 08: Beat Team Star and arrive at School", COLOR_ORANGE);
4952

@@ -54,8 +57,6 @@ void AutoStory_Segment_08::run_segment(
5457

5558
context.wait_for_all_requests();
5659
env.console.log("End Segment 08: Beat Team Star and arrive at School", COLOR_GREEN);
57-
stats.m_segment++;
58-
env.update_stats();
5960

6061
}
6162

@@ -100,7 +101,7 @@ void checkpoint_13(
100101

101102

102103
break;
103-
}catch(...){
104+
}catch(OperationFailedException&){
104105
context.wait_for_all_requests();
105106
env.console.log("Resetting from checkpoint.");
106107
reset_game(env.program_info(), env.console, context);
@@ -158,7 +159,7 @@ void checkpoint_14(
158159
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD});
159160

160161
break;
161-
}catch(...){
162+
}catch(OperationFailedException&){
162163
context.wait_for_all_requests();
163164
env.console.log("Resetting from checkpoint.");
164165
reset_game(env.program_info(), env.console, context);
@@ -201,7 +202,7 @@ void checkpoint_15(
201202
{CallbackEnum::PROMPT_DIALOG, CallbackEnum::OVERWORLD});
202203

203204
break;
204-
}catch(...){
205+
}catch(OperationFailedException&){
205206
context.wait_for_all_requests();
206207
env.console.log("Resetting from checkpoint.");
207208
reset_game(env.program_info(), env.console, context);

0 commit comments

Comments
 (0)