Skip to content

Commit 185ebd6

Browse files
jw098fyex
authored andcommitted
segment 02 to 04 (PokemonAutomation#492)
1 parent 19fcd30 commit 185ebd6

9 files changed

+688
-12
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,13 @@ file(GLOB MAIN_SOURCES
14311431
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp
14321432
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h
14331433
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp
1434-
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h
1434+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h
1435+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp
1436+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h
1437+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp
1438+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h
1439+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp
1440+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h
14351441
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp
14361442
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h
14371443
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ SOURCES += \
715715
Source/PokemonSV/PokemonSV_Settings.cpp \
716716
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp \
717717
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp \
718+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp \
719+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp \
720+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp \
718721
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \
719722
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \
720723
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \
@@ -1806,6 +1809,9 @@ HEADERS += \
18061809
Source/PokemonSV/PokemonSV_Settings.h \
18071810
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h \
18081811
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h \
1812+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h \
1813+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h \
1814+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h \
18091815
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \
18101816
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \
18111817
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
1818
#include "PokemonSV_AutoStory_Segment_00.h"
1919
#include "PokemonSV_AutoStory_Segment_01.h"
20-
// #include "PokemonSV_AutoStory_Segment_02.h"
21-
// #include "PokemonSV_AutoStory_Segment_03.h"
22-
// #include "PokemonSV_AutoStory_Segment_04.h"
20+
#include "PokemonSV_AutoStory_Segment_02.h"
21+
#include "PokemonSV_AutoStory_Segment_03.h"
22+
#include "PokemonSV_AutoStory_Segment_04.h"
2323
// #include "PokemonSV_AutoStory_Segment_05.h"
2424
// #include "PokemonSV_AutoStory_Segment_06.h"
2525
// #include "PokemonSV_AutoStory_Segment_07.h"
@@ -50,9 +50,9 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
5050
std::vector<std::unique_ptr<AutoStory_Segment>> segment_list;
5151
segment_list.emplace_back(std::make_unique<AutoStory_Segment_00>());
5252
segment_list.emplace_back(std::make_unique<AutoStory_Segment_01>());
53-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_02>());
54-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_03>());
55-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_04>());
53+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_02>());
54+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_03>());
55+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_04>());
5656
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_05>());
5757
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_06>());
5858
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_07>());
@@ -461,11 +461,11 @@ void AutoStory::test_checkpoints(
461461
checkpoint_list.push_back([&](){checkpoint_01(env, context, notif_status_update, language);});
462462
checkpoint_list.push_back([&](){checkpoint_02(env, context, notif_status_update);});
463463
checkpoint_list.push_back([&](){checkpoint_03(env, context, notif_status_update, language, starter_choice);});
464-
// checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);});
465-
// checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);});
466-
// checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);});
467-
// checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);});
468-
// checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);});
464+
checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);});
465+
checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);});
466+
checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);});
467+
checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);});
468+
checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);});
469469
// checkpoint_list.push_back([&](){checkpoint_09(env, context, notif_status_update);});
470470
// checkpoint_list.push_back([&](){checkpoint_10(env, context, notif_status_update);});
471471
// checkpoint_list.push_back([&](){checkpoint_11(env, context, notif_status_update);});
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* AutoStory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/GlobalSettingsPanel.h"
8+
#include "CommonFramework/Exceptions/FatalProgramException.h"
9+
#include "CommonFramework/Exceptions/OperationFailedException.h"
10+
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
11+
#include "CommonFramework/Notifications/ProgramNotifications.h"
12+
#include "CommonFramework/Tools/StatsTracking.h"
13+
#include "CommonFramework/Tools/VideoResolutionCheck.h"
14+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
15+
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
17+
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
18+
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
19+
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
20+
#include "PokemonSV_AutoStoryTools.h"
21+
#include "PokemonSV_AutoStory_Segment_02.h"
22+
23+
//#include <iostream>
24+
//using std::cout;
25+
//using std::endl;
26+
//#include <unordered_map>
27+
//#include <algorithm>
28+
29+
namespace PokemonAutomation{
30+
namespace NintendoSwitch{
31+
namespace PokemonSV{
32+
33+
using namespace Pokemon;
34+
35+
36+
37+
38+
std::string AutoStory_Segment_02::name() const{
39+
return "02: First Nemona Battle";
40+
}
41+
42+
std::string AutoStory_Segment_02::start_text() const{
43+
return "Start: Picked the starter.";
44+
}
45+
46+
std::string AutoStory_Segment_02::end_text() const{
47+
return "End: Battled Nemona on the beach.";
48+
}
49+
50+
void AutoStory_Segment_02::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{
51+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
52+
53+
context.wait_for_all_requests();
54+
env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);
55+
env.console.overlay().add_log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);
56+
57+
checkpoint_04(env, context, options.notif_status_update);
58+
59+
context.wait_for_all_requests();
60+
env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN);
61+
env.console.overlay().add_log("End Segment 02: First Nemona Battle", COLOR_GREEN);
62+
stats.m_segment++;
63+
env.update_stats();
64+
65+
}
66+
67+
68+
void checkpoint_04(
69+
SingleSwitchProgramEnvironment& env,
70+
BotBaseContext& context,
71+
EventNotificationOption& notif_status_update
72+
){
73+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
74+
bool first_attempt = true;
75+
while (true){
76+
try{
77+
if (first_attempt){
78+
checkpoint_save(env, context, notif_status_update);
79+
first_attempt = false;
80+
}
81+
context.wait_for_all_requests();
82+
83+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 220, 245, 50);
84+
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND);
85+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 128, 50);
86+
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND);
87+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 60, 50);
88+
pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND);
89+
env.console.log("overworld_navigation: Go to Nemona at the beach.");
90+
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_SPAM_A, 128, 0, 8);
91+
92+
context.wait_for_all_requests();
93+
env.console.overlay().add_log("Found Nemona", COLOR_WHITE);
94+
95+
context.wait_for_all_requests();
96+
env.console.log("Starting battle...");
97+
env.console.overlay().add_log("Starting battle...", COLOR_WHITE);
98+
// TODO: Battle start prompt detection
99+
// can lose this battle, and story will continue
100+
mash_button_till_overworld(env.console, context);
101+
context.wait_for_all_requests();
102+
env.console.log("Finished battle.");
103+
env.console.overlay().add_log("Finished battle.", COLOR_WHITE);
104+
105+
break;
106+
}catch(...){
107+
context.wait_for_all_requests();
108+
env.console.log("Resetting from checkpoint.");
109+
reset_game(env.program_info(), env.console, context);
110+
stats.m_reset++;
111+
env.update_stats();
112+
}
113+
}
114+
115+
}
116+
117+
118+
119+
120+
}
121+
}
122+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Autostory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_02_H
8+
#define PokemonAutomation_PokemonSV_AutoStory_Segment_02_H
9+
10+
#include <functional>
11+
#include "Common/Cpp/Options/EnumDropdownOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "CommonFramework/Options/LanguageOCROption.h"
14+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
15+
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
16+
#include "PokemonSV/Programs/PokemonSV_Navigation.h"
17+
#include "PokemonSV_AutoStoryTools.h"
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonSV{
22+
23+
class AutoStory_Segment_02 : public AutoStory_Segment{
24+
public:
25+
virtual std::string name() const override;
26+
virtual std::string start_text() const override;
27+
virtual std::string end_text() const override;
28+
virtual void run_segment(
29+
SingleSwitchProgramEnvironment& env,
30+
BotBaseContext& context,
31+
AutoStoryOptions options) const override;
32+
};
33+
34+
35+
// start: Received starter pokemon and changed move order. Cleared autoheal tutorial.
36+
// end: Battled Nemona on the beach.
37+
void checkpoint_04(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);
38+
39+
40+
}
41+
}
42+
}
43+
#endif

0 commit comments

Comments
 (0)