@@ -556,52 +556,47 @@ void config_option(ProControllerContext& context, int change_option_value){
556556 pbf_press_dpad (context, DPAD_DOWN, 15 , 20 );
557557}
558558
559- void swap_starter_moves (const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, Language language){
560- WallClock start = current_time ();
561- while (true ){
562- if (current_time () - start > std::chrono::minutes (3 )){
563- OperationFailedException::fire (
564- ErrorReport::SEND_ERROR_REPORT,
565- " swap_starter_moves(): Failed to swap the starter moves after 3 minutes." ,
566- stream
567- );
568- }
569- // start in the overworld
570- press_Bs_to_back_to_overworld (info, stream, context);
571-
572- // open menu, select your starter
573- enter_menu_from_overworld (info, stream, context, 0 , MenuSide::LEFT);
559+ void swap_starter_moves (SingleSwitchProgramEnvironment& env, ProControllerContext& context, Language language){
560+ const ProgramInfo& info = env.program_info ();
561+ VideoStream& stream = env.console ;
574562
575- // enter Pokemon summary screen
576- pbf_press_button (context, BUTTON_A, 20 , 5 * TICKS_PER_SECOND);
577- pbf_press_dpad (context, DPAD_RIGHT, 15 , 1 * TICKS_PER_SECOND);
578- pbf_press_button (context, BUTTON_Y, 20 , 40 );
563+ // start in the overworld
564+ press_Bs_to_back_to_overworld (info, stream, context);
579565
580- // select move 1
581- pbf_press_button (context, BUTTON_A, 20 , 40 );
582- pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
583- pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
584- // extra button presses to avoid drops
585- pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
586- pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
566+ // open menu, select your starter
567+ enter_menu_from_overworld (info, stream, context, 0 , MenuSide::LEFT);
587568
588- // select move 3. swap move 1 and move 3.
589- pbf_press_button (context, BUTTON_A, 20 , 40 );
569+ // enter Pokemon summary screen
570+ pbf_press_button (context, BUTTON_A, 20 , 5 * TICKS_PER_SECOND);
571+ pbf_press_dpad (context, DPAD_RIGHT, 15 , 1 * TICKS_PER_SECOND);
572+ pbf_press_button (context, BUTTON_Y, 20 , 40 );
590573
591- // confirm that Ember/Leafage/Water Gun is in slot 1
592- context.wait_for_all_requests ();
593- VideoSnapshot screen = stream.video ().snapshot ();
594- PokemonMovesReader reader (language);
595- std::string top_move = reader.read_move (stream.logger (), screen, 0 );
596- stream.log (" Current top move: " + top_move);
597- if (top_move != " ember" && top_move != " leafage" && top_move != " water-gun" ){
598- stream.log (" Failed to swap moves. Re-try." );
599- continue ;
600- }
574+ // select move 1
575+ pbf_press_button (context, BUTTON_A, 20 , 40 );
576+ pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
577+ pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
578+ // extra button presses to avoid drops
579+ pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
580+ pbf_press_dpad (context, DPAD_DOWN, 15 , 40 );
601581
582+ // select move 3. swap move 1 and move 3.
583+ pbf_press_button (context, BUTTON_A, 20 , 40 );
602584
603- break ;
604- }
585+ // confirm that Ember/Leafage/Water Gun is in slot 1
586+ context.wait_for_all_requests ();
587+ VideoSnapshot screen = stream.video ().snapshot ();
588+ PokemonMovesReader reader (language);
589+ std::string top_move = reader.read_move (stream.logger (), screen, 0 );
590+ stream.log (" Current top move: " + top_move);
591+ if (top_move != " ember" && top_move != " leafage" && top_move != " water-gun" ){
592+ stream.log (" Failed to swap moves." );
593+ OperationFailedException exception (
594+ ErrorReport::SEND_ERROR_REPORT,
595+ " swap_starter_moves: Failed to swap moves.\n " + language_warning (language),
596+ stream
597+ );
598+ exception.send_recoverable_notification (env);
599+ }
605600
606601}
607602
@@ -1220,6 +1215,85 @@ void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProController
12201215
12211216}
12221217
1218+ void checkpoint_reattempt_loop (
1219+ SingleSwitchProgramEnvironment& env,
1220+ ProControllerContext& context,
1221+ EventNotificationOption& notif_status_update,
1222+ AutoStoryStats& stats,
1223+ std::function<void (size_t attempt_number)>&& action
1224+ ){
1225+ size_t max_attempts = 100 ;
1226+ for (size_t i = 0 ;;i++){
1227+ try {
1228+ if (i==0 ){
1229+ checkpoint_save (env, context, notif_status_update, stats);
1230+ }
1231+
1232+ context.wait_for_all_requests ();
1233+ action (i);
1234+
1235+ break ;
1236+ }catch (OperationFailedException& e){
1237+ if (i > max_attempts){
1238+ OperationFailedException::fire (
1239+ ErrorReport::SEND_ERROR_REPORT,
1240+ " Autostory checkpoint failed " + std::to_string (max_attempts) + " times.\n "
1241+ " Make sure you selected the correct Start Point, and your character is in the exactly correct starting position."
1242+ " Also, make sure you have set the correct Language.\n " + e.message (),
1243+ env.console
1244+ );
1245+ }
1246+ context.wait_for_all_requests ();
1247+ env.console .log (" Resetting from checkpoint." );
1248+ reset_game (env.program_info (), env.console , context);
1249+ stats.m_reset ++;
1250+ env.update_stats ();
1251+ }
1252+ }
1253+
1254+ }
1255+
1256+ void checkpoint_reattempt_loop_tutorial (
1257+ SingleSwitchProgramEnvironment& env,
1258+ ProControllerContext& context,
1259+ EventNotificationOption& notif_status_update,
1260+ AutoStoryStats& stats,
1261+ std::function<void (size_t attempt_number)>&& action
1262+ ){
1263+ size_t max_attempts = 100 ;
1264+ for (size_t i = 0 ;;i++){
1265+ try {
1266+ if (i==0 ){
1267+ save_game_tutorial (env.program_info (), env.console , context);
1268+ stats.m_checkpoint ++;
1269+ env.update_stats ();
1270+ send_program_status_notification (env, notif_status_update, " Saved at checkpoint." );
1271+ }
1272+
1273+ context.wait_for_all_requests ();
1274+ action (i);
1275+
1276+ break ;
1277+ }catch (OperationFailedException& e){
1278+ if (i > max_attempts){
1279+ OperationFailedException::fire (
1280+ ErrorReport::SEND_ERROR_REPORT,
1281+ " Autostory checkpoint failed " + std::to_string (max_attempts) + " times.\n "
1282+ " Make sure you selected the correct Start Point, and your character is in the exactly correct starting position."
1283+ " Also, make sure you have set the correct Language.\n " + e.message (),
1284+ env.console
1285+ );
1286+ }
1287+ context.wait_for_all_requests ();
1288+ env.console .log (" Resetting from checkpoint." );
1289+ reset_game (env.program_info (), env.console , context);
1290+ stats.m_reset ++;
1291+ env.update_stats ();
1292+ }
1293+ }
1294+ }
1295+
1296+
12231297
12241298
12251299}
0 commit comments