From 71c6ec9a61af51d392f8fe73959ce453aadfe241 Mon Sep 17 00:00:00 2001 From: jw098 Date: Sun, 17 Nov 2024 15:24:10 -0800 Subject: [PATCH] Segment 14 and update Autostory dev mode UI --- SerialPrograms/CMakeLists.txt | 3 +- SerialPrograms/SerialPrograms.pro | 2 + .../AutoStory/PokemonSV_AutoStory.cpp | 245 ++++++++++--- .../Programs/AutoStory/PokemonSV_AutoStory.h | 13 +- .../PokemonSV_AutoStory_Segment_14.cpp | 322 ++++++++++++++++++ .../PokemonSV_AutoStory_Segment_14.h | 49 +++ 6 files changed, 581 insertions(+), 53 deletions(-) create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 52b9658a38..188f320fe2 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -691,7 +691,6 @@ file(GLOB MAIN_SOURCES Source/Kernels/ImageFilters/Kernels_ImageFilter_Basic_x64_AVX512.cpp Source/Kernels/ImageFilters/Kernels_ImageFilter_Basic_x64_SSE42.cpp Source/Kernels/ImageFilters/Kernels_ImageFilter_Green_Default.cpp - Source/Kernels/ImageFilters/Kernels_ImageFilter_Green_Default.h Source/Kernels/ImageScaleBrightness/Kernels_ImageScaleBrightness.cpp Source/Kernels/ImageScaleBrightness/Kernels_ImageScaleBrightness.h Source/Kernels/ImageScaleBrightness/Kernels_ImageScaleBrightness_Default.cpp @@ -1466,6 +1465,8 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index e16dc32cd1..25e11c8091 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -732,6 +732,7 @@ SOURCES += \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \ @@ -1838,6 +1839,7 @@ HEADERS += \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_12.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_13.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \ diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 2bf081f83a..f3ab5a4838 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -7,6 +7,8 @@ #include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/Exceptions/FatalProgramException.h" #include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Exceptions/UnexpectedBattleException.h" +#include "CommonFramework/Exceptions/OliveActionFailedException.h" #include "CommonFramework/InferenceInfra/InferenceRoutines.h" #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/Tools/StatsTracking.h" @@ -15,6 +17,9 @@ #include "Pokemon/Pokemon_Strings.h" #include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "PokemonSV/Programs/PokemonSV_GameEntry.h" +#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" +#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" +#include "PokemonSV/Inference/Overworld/PokemonSV_OliveDetector.h" #include "PokemonSV_AutoStory_Segment_00.h" #include "PokemonSV_AutoStory_Segment_01.h" #include "PokemonSV_AutoStory_Segment_02.h" @@ -29,13 +34,22 @@ #include "PokemonSV_AutoStory_Segment_11.h" #include "PokemonSV_AutoStory_Segment_12.h" #include "PokemonSV_AutoStory_Segment_13.h" -// #include "PokemonSV_AutoStory_Segment_14.h" +#include "PokemonSV_AutoStory_Segment_14.h" // #include "PokemonSV_AutoStory_Segment_15.h" +// #include "PokemonSV_AutoStory_Segment_16.h" +// #include "PokemonSV_AutoStory_Segment_17.h" +// #include "PokemonSV_AutoStory_Segment_18.h" +// #include "PokemonSV_AutoStory_Segment_19.h" +// #include "PokemonSV_AutoStory_Segment_20.h" +// #include "PokemonSV_AutoStory_Segment_21.h" +// #include "PokemonSV_AutoStory_Segment_22.h" +// #include "PokemonSV_AutoStory_Segment_23.h" +// #include "PokemonSV_AutoStory_Segment_24.h" #include "PokemonSV_AutoStory.h" -//#include -//using std::cout; -//using std::endl; +// #include +// using std::cout; +// using std::endl; //#include //#include @@ -64,7 +78,17 @@ std::vector> make_autoStory_segment_list(){ segment_list.emplace_back(std::make_unique()); segment_list.emplace_back(std::make_unique()); segment_list.emplace_back(std::make_unique()); - // segment_list.emplace_back(std::make_unique()); + segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); + // segment_list.emplace_back(std::make_unique()); return segment_list; }; @@ -218,6 +242,9 @@ AutoStory::AutoStory() , m_advanced_options( "Advanced Options: (developer only)" ) + , m_advanced_options_end( + "" + ) , CHANGE_SETTINGS( "Change settings at Program Start:
" "This is to ensure the program has the correct settings, particularly with Autosave turned off.", @@ -284,8 +311,8 @@ AutoStory::AutoStory() LockMode::UNLOCK_WHILE_RUNNING, 0 ) - , ENABLE_TEST_OVERWORLD_MOVE( - "TEST: walk_forward_while_clear_front_path():", + , ENABLE_MISC_TEST( + "TEST: Miscellaneous test code:", LockMode::UNLOCK_WHILE_RUNNING, false ) @@ -318,24 +345,69 @@ AutoStory::AutoStory() "--RELEASE_TICKS:", LockMode::UNLOCK_WHILE_RUNNING, 0 - ) + ) + , TEST_PBF_LEFT_JOYSTICK2( + "TEST2: pbf_move_left_joystick():", + LockMode::UNLOCK_WHILE_RUNNING, + false + ) + , X_MOVE2( + "--X_MOVE:
x = 0 : left, x = 128 : neutral, x = 255 : right.", + LockMode::UNLOCK_WHILE_RUNNING, + 128 + ) + , Y_MOVE2( + "--Y_MOVE:
y = 0 : up, y = 128 : neutral, y = 255 : down.", + LockMode::UNLOCK_WHILE_RUNNING, + 128 + ) + , HOLD_TICKS2( + "--HOLD_TICKS:", + LockMode::UNLOCK_WHILE_RUNNING, + 0 + ) + , RELEASE_TICKS2( + "--RELEASE_TICKS:", + LockMode::UNLOCK_WHILE_RUNNING, + 0 + ) + , TEST_CURRENT_DIRECTION( + "TEST: get_current_direction():", + LockMode::UNLOCK_WHILE_RUNNING, + false + ) + , TEST_CHANGE_DIRECTION( + "TEST: change_direction():", + LockMode::UNLOCK_WHILE_RUNNING, + false + ) + , DIR_RADIANS( + "direction in radians", + LockMode::UNLOCK_WHILE_RUNNING, + 0 + ) { - PA_ADD_OPTION(LANGUAGE); - PA_ADD_OPTION(STORY_SECTION); - PA_ADD_OPTION(STARTPOINT_TUTORIAL); - PA_ADD_OPTION(MAINSTORY_NOTE); - PA_ADD_OPTION(STARTPOINT_MAINSTORY); - PA_ADD_OPTION(START_DESCRIPTION); - PA_ADD_OPTION(ENDPOINT_TUTORIAL); - PA_ADD_OPTION(ENDPOINT_MAINSTORY); - PA_ADD_OPTION(END_DESCRIPTION); - PA_ADD_OPTION(STARTERCHOICE); - PA_ADD_OPTION(GO_HOME_WHEN_DONE); - PA_ADD_OPTION(NOTIFICATIONS); if (PreloadSettings::instance().DEVELOPER_MODE){ PA_ADD_OPTION(m_advanced_options); PA_ADD_OPTION(CHANGE_SETTINGS); + + PA_ADD_OPTION(TEST_CURRENT_DIRECTION); + PA_ADD_OPTION(TEST_CHANGE_DIRECTION); + PA_ADD_OPTION(DIR_RADIANS); + + PA_ADD_OPTION(TEST_PBF_LEFT_JOYSTICK); + PA_ADD_OPTION(X_MOVE); + PA_ADD_OPTION(Y_MOVE); + PA_ADD_OPTION(HOLD_TICKS); + PA_ADD_OPTION(RELEASE_TICKS); + + PA_ADD_OPTION(TEST_PBF_LEFT_JOYSTICK2); + PA_ADD_OPTION(X_MOVE2); + PA_ADD_OPTION(Y_MOVE2); + PA_ADD_OPTION(HOLD_TICKS2); + PA_ADD_OPTION(RELEASE_TICKS2); + PA_ADD_OPTION(ENABLE_TEST_CHECKPOINTS); PA_ADD_OPTION(START_CHECKPOINT); PA_ADD_OPTION(END_CHECKPOINT); @@ -343,22 +415,32 @@ AutoStory::AutoStory() PA_ADD_OPTION(START_LOOP); PA_ADD_OPTION(END_LOOP); - PA_ADD_OPTION(ENABLE_TEST_REALIGN); - PA_ADD_OPTION(REALIGN_MODE); - PA_ADD_OPTION(X_REALIGN); - PA_ADD_OPTION(Y_REALIGN); - PA_ADD_OPTION(REALIGN_DURATION); - - PA_ADD_OPTION(ENABLE_TEST_OVERWORLD_MOVE); - PA_ADD_OPTION(FORWARD_TICKS); + // PA_ADD_OPTION(ENABLE_TEST_REALIGN); + // PA_ADD_OPTION(REALIGN_MODE); + // PA_ADD_OPTION(X_REALIGN); + // PA_ADD_OPTION(Y_REALIGN); + // PA_ADD_OPTION(REALIGN_DURATION); - PA_ADD_OPTION(TEST_PBF_LEFT_JOYSTICK); - PA_ADD_OPTION(X_MOVE); - PA_ADD_OPTION(Y_MOVE); - PA_ADD_OPTION(HOLD_TICKS); - PA_ADD_OPTION(RELEASE_TICKS); + PA_ADD_OPTION(ENABLE_MISC_TEST); + // PA_ADD_OPTION(FORWARD_TICKS); + PA_ADD_OPTION(m_advanced_options_end); } + + PA_ADD_OPTION(LANGUAGE); + PA_ADD_OPTION(STORY_SECTION); + PA_ADD_OPTION(STARTPOINT_TUTORIAL); + PA_ADD_OPTION(MAINSTORY_NOTE); + PA_ADD_OPTION(STARTPOINT_MAINSTORY); + PA_ADD_OPTION(START_DESCRIPTION); + PA_ADD_OPTION(ENDPOINT_TUTORIAL); + PA_ADD_OPTION(ENDPOINT_MAINSTORY); + PA_ADD_OPTION(END_DESCRIPTION); + PA_ADD_OPTION(STARTERCHOICE); + PA_ADD_OPTION(GO_HOME_WHEN_DONE); + PA_ADD_OPTION(NOTIFICATIONS); + + AutoStory::value_changed(this); STORY_SECTION.add_listener(*this); @@ -368,8 +450,11 @@ AutoStory::AutoStory() ENDPOINT_MAINSTORY.add_listener(*this); ENABLE_TEST_CHECKPOINTS.add_listener(*this); ENABLE_TEST_REALIGN.add_listener(*this); - ENABLE_TEST_OVERWORLD_MOVE.add_listener(*this); + ENABLE_MISC_TEST.add_listener(*this); TEST_PBF_LEFT_JOYSTICK.add_listener(*this); + TEST_PBF_LEFT_JOYSTICK2.add_listener(*this); + TEST_CURRENT_DIRECTION.add_listener(*this); + TEST_CHANGE_DIRECTION.add_listener(*this); } void AutoStory::value_changed(void* object){ @@ -422,7 +507,7 @@ void AutoStory::value_changed(void* object){ REALIGN_DURATION.set_visibility(ConfigOptionState::DISABLED); } - if (ENABLE_TEST_OVERWORLD_MOVE){ + if (ENABLE_MISC_TEST){ FORWARD_TICKS.set_visibility(ConfigOptionState::ENABLED); }else{ FORWARD_TICKS.set_visibility(ConfigOptionState::DISABLED); @@ -438,7 +523,26 @@ void AutoStory::value_changed(void* object){ Y_MOVE.set_visibility(ConfigOptionState::DISABLED); HOLD_TICKS.set_visibility(ConfigOptionState::DISABLED); RELEASE_TICKS.set_visibility(ConfigOptionState::DISABLED); - } + } + + if (TEST_PBF_LEFT_JOYSTICK2){ + X_MOVE2.set_visibility(ConfigOptionState::ENABLED); + Y_MOVE2.set_visibility(ConfigOptionState::ENABLED); + HOLD_TICKS2.set_visibility(ConfigOptionState::ENABLED); + RELEASE_TICKS2.set_visibility(ConfigOptionState::ENABLED); + }else{ + X_MOVE2.set_visibility(ConfigOptionState::DISABLED); + Y_MOVE2.set_visibility(ConfigOptionState::DISABLED); + HOLD_TICKS2.set_visibility(ConfigOptionState::DISABLED); + RELEASE_TICKS2.set_visibility(ConfigOptionState::DISABLED); + } + + + if (TEST_CHANGE_DIRECTION){ + DIR_RADIANS.set_visibility(ConfigOptionState::ENABLED); + }else{ + DIR_RADIANS.set_visibility(ConfigOptionState::DISABLED); + } } @@ -494,6 +598,21 @@ void AutoStory::test_checkpoints( // checkpoint_list.push_back([&](){checkpoint_32(env, context, notif_status_update);}); // checkpoint_list.push_back([&](){checkpoint_33(env, context, notif_status_update);}); // checkpoint_list.push_back([&](){checkpoint_34(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_35(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_36(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_37(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_38(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_39(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_40(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_41(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_42(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_43(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_44(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_45(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_46(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_47(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_48(env, context, notif_status_update);}); + // checkpoint_list.push_back([&](){checkpoint_49(env, context, notif_status_update);}); for (int checkpoint = start; checkpoint <= end; checkpoint++){ if (checkpoint == 0){ @@ -511,6 +630,10 @@ void AutoStory::test_checkpoints( for (int i = 0; i < loop; i++){ if (i > 0){ reset_game(env.program_info(), console, context); + enter_menu_from_overworld(env.program_info(), env.console, context, -1); + // we wait 10 seconds then save, so that the initial conditions are slightly different on each reset. + env.log("Wait 10 seconds."); + context.wait_for(Milliseconds(10 * 1000)); } console.log("checkpoint_" + number + ": loop " + std::to_string(i)); checkpoint_list[checkpoint](); @@ -569,6 +692,31 @@ void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, BotBaseContex } void AutoStory::test_code(SingleSwitchProgramEnvironment& env, BotBaseContext& context){ + if (TEST_CURRENT_DIRECTION){ + DirectionDetector direction; + // direction.change_direction(env.program_info(), env.console, context, DIR_RADIANS); + VideoSnapshot snapshot = env.console.video().snapshot(); + env.console.log("current direction: " + std::to_string(direction.get_current_direction(env.console, snapshot))); + return; + } + + if (TEST_CHANGE_DIRECTION){ + DirectionDetector direction; + direction.change_direction(env.program_info(), env.console, context, DIR_RADIANS); + // VideoSnapshot snapshot = env.console.video().snapshot(); + // env.console.log("current direction: " + std::to_string(direction.get_current_direction(env.console, snapshot))); + return; + } + + if (TEST_PBF_LEFT_JOYSTICK){ + pbf_move_left_joystick(context, X_MOVE, Y_MOVE, HOLD_TICKS, RELEASE_TICKS); + return; + } + + if (TEST_PBF_LEFT_JOYSTICK2){ + pbf_move_left_joystick(context, X_MOVE2, Y_MOVE2, HOLD_TICKS2, RELEASE_TICKS2); + return; + } if (ENABLE_TEST_CHECKPOINTS){ // test individual checkpoints @@ -584,23 +732,17 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, BotBaseContext& c return; } - if (ENABLE_TEST_OVERWORLD_MOVE){ + if (ENABLE_MISC_TEST){ // walk_forward_while_clear_front_path(env.program_info(), env.console, context, FORWARD_TICKS); - overworld_navigation(env.program_info(), env.console, context, - NavigationStopCondition::STOP_MARKER, NavigationMovementMode::CLEAR_WITH_LETS_GO, - 128, 0, 60, 10, false); - // overworld_navigation(env.program_info(), env.console, context, - // NavigationStopCondition::STOP_TIME, NavigationMovementMode::CLEAR_WITH_LETS_GO, - // 128, 0, 25, 10, false); - return; - } + // NavigationStopCondition::STOP_MARKER, NavigationMovementMode::CLEAR_WITH_LETS_GO, + // 128, 0, 60, 10, false); + + DirectionDetector direction; - if (TEST_PBF_LEFT_JOYSTICK){ - pbf_move_left_joystick(context, X_MOVE, Y_MOVE, HOLD_TICKS, RELEASE_TICKS); return; - } + } // context.wait_for(Milliseconds(1000000)); @@ -611,15 +753,16 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, BotBaseContext& con assert_16_9_720p_min(env.logger(), env.console); // AutoStoryStats& stats = env.current_stats(); - // Connect controller - pbf_press_button(context, BUTTON_L, 20, 20); // test code - if (ENABLE_TEST_CHECKPOINTS || ENABLE_TEST_REALIGN || ENABLE_TEST_OVERWORLD_MOVE || TEST_PBF_LEFT_JOYSTICK){ + if (ENABLE_TEST_CHECKPOINTS || ENABLE_TEST_REALIGN || ENABLE_MISC_TEST || TEST_PBF_LEFT_JOYSTICK || TEST_PBF_LEFT_JOYSTICK2 || TEST_CHANGE_DIRECTION || TEST_CURRENT_DIRECTION){ test_code(env, context); return; } + // Connect controller + pbf_press_button(context, BUTTON_L, 20, 20); + // Set settings. to ensure autosave is off. if (CHANGE_SETTINGS){ change_settings_prior_to_autostory(env, context, STARTPOINT_TUTORIAL.index(), LANGUAGE); diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h index 50230698db..e09dea12c9 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h @@ -88,6 +88,7 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste EventNotificationsOption NOTIFICATIONS; SectionDividerOption m_advanced_options; + SectionDividerOption m_advanced_options_end; BooleanCheckBoxOption CHANGE_SETTINGS; BooleanCheckBoxOption ENABLE_TEST_CHECKPOINTS; @@ -103,7 +104,7 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste SimpleIntegerOption Y_REALIGN; SimpleIntegerOption REALIGN_DURATION; - BooleanCheckBoxOption ENABLE_TEST_OVERWORLD_MOVE; + BooleanCheckBoxOption ENABLE_MISC_TEST; SimpleIntegerOption FORWARD_TICKS; BooleanCheckBoxOption TEST_PBF_LEFT_JOYSTICK; @@ -111,6 +112,16 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste SimpleIntegerOption Y_MOVE; SimpleIntegerOption HOLD_TICKS; SimpleIntegerOption RELEASE_TICKS; + + BooleanCheckBoxOption TEST_PBF_LEFT_JOYSTICK2; + SimpleIntegerOption X_MOVE2; + SimpleIntegerOption Y_MOVE2; + SimpleIntegerOption HOLD_TICKS2; + SimpleIntegerOption RELEASE_TICKS2; + + BooleanCheckBoxOption TEST_CURRENT_DIRECTION; + BooleanCheckBoxOption TEST_CHANGE_DIRECTION; + FloatingPointOption DIR_RADIANS; }; diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp new file mode 100644 index 0000000000..ccb47b58a5 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp @@ -0,0 +1,322 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include "CommonFramework/GlobalSettingsPanel.h" +#include "CommonFramework/Exceptions/FatalProgramException.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/InferenceInfra/InferenceRoutines.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/Tools/StatsTracking.h" +#include "CommonFramework/Tools/VideoResolutionCheck.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" +#include "PokemonSV/Programs/PokemonSV_GameEntry.h" +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" +#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h" +#include "PokemonSV_AutoStoryTools.h" +#include "PokemonSV_AutoStory_Segment_14.h" + +//#include +//using std::cout; +//using std::endl; +//#include +//#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +using namespace Pokemon; + + + + +std::string AutoStory_Segment_14::name() const{ + return "11.2: Bombirdier Titan: Battle Bombirdier"; +} + +std::string AutoStory_Segment_14::start_text() const{ + return "Start: At West Province Area One Central Pokecenter"; +} + +std::string AutoStory_Segment_14::end_text() const{ + return "End: Defeated Bombirder. At West Province Area One North Pokecenter"; +} + +void AutoStory_Segment_14::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ + AutoStoryStats& stats = env.current_stats(); + + context.wait_for_all_requests(); + env.console.overlay().add_log("Start Segment 11.2: Bombirdier Titan: Battle Bombirdier", COLOR_ORANGE); + + checkpoint_30(env, context, options.notif_status_update); + checkpoint_31(env, context, options.notif_status_update); + + context.wait_for_all_requests(); + env.console.log("End Segment 11.2: Bombirdier Titan: Battle Bombirdier", COLOR_GREEN); + stats.m_segment++; + env.update_stats(); + +} + + + +void checkpoint_30( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + context.wait_for_all_requests(); + + // section 1 + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 128, 17); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + + // section 2 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 200, 200}, + {ZoomChange::KEEP_ZOOM, 0, 65, 220} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + // section 3 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 200, 200}, + {ZoomChange::KEEP_ZOOM, 0, 80, 235} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + // section 4. walk until Arven dialog + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 200, 200}, + {ZoomChange::KEEP_ZOOM, 0, 60, 280} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 30, {CallbackEnum::OVERWORLD, CallbackEnum::BLACK_DIALOG_BOX}); + + // after Arven dialog. section 5 + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 18, 6, false); + + // section 6 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 0, 0, 0}, + {ZoomChange::KEEP_ZOOM, 0, 20, 65} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + get_on_ride(env.program_info(), env.console, context); + + // section 7 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 0, 0, 0}, + {ZoomChange::KEEP_ZOOM, 0, 30, 80} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 20, 10, false); + + // section 8. enter left side of boulder field + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 255, 50}, + {ZoomChange::KEEP_ZOOM, 0, 40, 95} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 18, 6, false); + + // section 8.1. move up + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 0, 50); + pbf_move_left_joystick(context, 128, 0, 100, 100); + + // section 9. go to middle-right of boulder field + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 255, 50}, + {ZoomChange::KEEP_ZOOM, 0, 15, 110} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 5, false); + + // // section 9.1. go to right edge of boulder field + // realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 140, 0, 50); + // pbf_move_left_joystick(context, 128, 0, 200, 100); + + // section 10. walk up right edge + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 255, 80}, + {ZoomChange::KEEP_ZOOM, 0, 12, 130} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 5, false); + + // section 10.1 walk up right edge. until hit rock + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 15, 50); + + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_TIME, NavigationMovementMode::DIRECTIONAL_ONLY, + 140, 0, 10, 5, false); + + // section 10.2. move away from rock. + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 80, 255, 50); + pbf_move_left_joystick(context, 128, 0, 200, 100); + + // section 11 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 255, 100}, + {ZoomChange::KEEP_ZOOM, 0, 5, 150} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 5, false); + + // section 12. reach the top. battle Bombirdier + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 255, 100}, + {ZoomChange::KEEP_ZOOM, 50, 0, 170} + ); + try{ + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_BATTLE, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 5, false); + }catch (OperationFailedException& e){ + (void) e; + // likely attempted to open/close phone to realign, but failed + // likely already reached cutscene to battle Bombirdeier. + + // keep waiting until battle detected. + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_BATTLE, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 128, 30, 30, false); + + } + + run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG); + clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 30, {CallbackEnum::BATTLE}); + // round 2 of battle + run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW}); + // get ride upgrade + mash_button_till_overworld(env.console, context, BUTTON_A); + + + break; + }catch (...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } + +} + + +void checkpoint_31( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + context.wait_for_all_requests(); + // section 1. fall down the mountain + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 80, 180}, + {ZoomChange::KEEP_ZOOM, 0, 170, 120} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 50, 10, false); + // section 2 + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 80, 100}, + {ZoomChange::KEEP_ZOOM, 0, 255, 55} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 10, false); + // section 3. align to pokecenter + realign_player_from_landmark( + env.program_info(), env.console, context, + {ZoomChange::ZOOM_IN, 255, 0, 40}, + {ZoomChange::KEEP_ZOOM, 0, 0, 0} + ); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 0, 40, 10, false); + + // section 4. set marker past pokecenter + handle_unexpected_battles(env.program_info(), env.console, context, + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 60, 40); + }); + overworld_navigation(env.program_info(), env.console, context, + NavigationStopCondition::STOP_TIME, NavigationMovementMode::DIRECTIONAL_ONLY, + 128, 15, 12, 12, false); + + fly_to_overlapping_flypoint(env.program_info(), env.console, context); + + break; + }catch (...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } + +} + + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h new file mode 100644 index 0000000000..3c487b4628 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h @@ -0,0 +1,49 @@ +/* Autostory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_14_H +#define PokemonAutomation_PokemonSV_AutoStory_Segment_14_H + +#include +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonFramework/Options/LanguageOCROption.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h" +#include "PokemonSV/Programs/PokemonSV_Navigation.h" +#include "PokemonSV_AutoStoryTools.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +class AutoStory_Segment_14 : public AutoStory_Segment{ +public: + virtual std::string name() const override; + virtual std::string start_text() const override; + virtual std::string end_text() const override; + virtual void run_segment( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + AutoStoryOptions options) const override; +}; + + +// start: At West Province Area One Central Pokecenter +// end: Defeated Bombirdier +void checkpoint_30(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + +// start: Defeated Bombirdier +// end: At West Province Area One North Pokecenter +void checkpoint_31(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + + + + +} +} +} +#endif