Skip to content

Commit

Permalink
segment 02 to 04 (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
jw098 authored Oct 16, 2024
1 parent cc66d57 commit f4b15ed
Show file tree
Hide file tree
Showing 9 changed files with 688 additions and 12 deletions.
8 changes: 7 additions & 1 deletion SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,13 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp
Expand Down
6 changes: 6 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ SOURCES += \
Source/PokemonSV/PokemonSV_Settings.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \
Expand Down Expand Up @@ -1804,6 +1807,9 @@ HEADERS += \
Source/PokemonSV/PokemonSV_Settings.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
#include "PokemonSV_AutoStory_Segment_00.h"
#include "PokemonSV_AutoStory_Segment_01.h"
// #include "PokemonSV_AutoStory_Segment_02.h"
// #include "PokemonSV_AutoStory_Segment_03.h"
// #include "PokemonSV_AutoStory_Segment_04.h"
#include "PokemonSV_AutoStory_Segment_02.h"
#include "PokemonSV_AutoStory_Segment_03.h"
#include "PokemonSV_AutoStory_Segment_04.h"
// #include "PokemonSV_AutoStory_Segment_05.h"
// #include "PokemonSV_AutoStory_Segment_06.h"
// #include "PokemonSV_AutoStory_Segment_07.h"
Expand Down Expand Up @@ -50,9 +50,9 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
std::vector<std::unique_ptr<AutoStory_Segment>> segment_list;
segment_list.emplace_back(std::make_unique<AutoStory_Segment_00>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_01>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_02>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_03>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_04>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_02>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_03>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_04>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_05>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_06>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_07>());
Expand Down Expand Up @@ -461,11 +461,11 @@ void AutoStory::test_checkpoints(
checkpoint_list.push_back([&](){checkpoint_01(env, context, notif_status_update, language);});
checkpoint_list.push_back([&](){checkpoint_02(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_03(env, context, notif_status_update, language, starter_choice);});
// checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);});
checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_09(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_10(env, context, notif_status_update);});
// checkpoint_list.push_back([&](){checkpoint_11(env, context, notif_status_update);});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* 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_02.h"

//#include <iostream>
//using std::cout;
//using std::endl;
//#include <unordered_map>
//#include <algorithm>

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

using namespace Pokemon;




std::string AutoStory_Segment_02::name() const{
return "02: First Nemona Battle";
}

std::string AutoStory_Segment_02::start_text() const{
return "Start: Picked the starter.";
}

std::string AutoStory_Segment_02::end_text() const{
return "End: Battled Nemona on the beach.";
}

void AutoStory_Segment_02::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();

context.wait_for_all_requests();
env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);
env.console.overlay().add_log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);

checkpoint_04(env, context, options.notif_status_update);

context.wait_for_all_requests();
env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN);
env.console.overlay().add_log("End Segment 02: First Nemona Battle", COLOR_GREEN);
stats.m_segment++;
env.update_stats();

}


void checkpoint_04(
SingleSwitchProgramEnvironment& env,
BotBaseContext& context,
EventNotificationOption& notif_status_update
){
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
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();

realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 220, 245, 50);
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND);
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 128, 50);
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND);
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 60, 50);
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND);
env.console.log("overworld_navigation: Go to Nemona at the beach.");
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_SPAM_A, 128, 0, 8);

context.wait_for_all_requests();
env.console.overlay().add_log("Found Nemona", COLOR_WHITE);

context.wait_for_all_requests();
env.console.log("Starting battle...");
env.console.overlay().add_log("Starting battle...", COLOR_WHITE);
// TODO: Battle start prompt detection
// can lose this battle, and story will continue
mash_button_till_overworld(env.console, context);
context.wait_for_all_requests();
env.console.log("Finished battle.");
env.console.overlay().add_log("Finished battle.", COLOR_WHITE);

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();
}
}

}




}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Autostory
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_02_H
#define PokemonAutomation_PokemonSV_AutoStory_Segment_02_H

#include <functional>
#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_02 : 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: Received starter pokemon and changed move order. Cleared autoheal tutorial.
// end: Battled Nemona on the beach.
void checkpoint_04(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);


}
}
}
#endif
Loading

0 comments on commit f4b15ed

Please sign in to comment.