Skip to content

Commit acdb930

Browse files
authored
update autostory segments and DialogArrowDetector (#514)
1 parent 5a063bd commit acdb930

16 files changed

+232
-150
lines changed

SerialPrograms/Source/PokemonSV/Inference/Dialogs/PokemonSV_DialogArrowDetector.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include "CommonFramework/ImageMatch/ExactImageMatcher.h"
1717
#include "PokemonSV_DialogArrowDetector.h"
1818

19-
// #include <iostream>
20-
// using std::cout;
21-
// using std::endl;
19+
#include <iostream>
20+
using std::cout;
21+
using std::endl;
2222

2323
namespace PokemonAutomation{
2424
namespace NintendoSwitch{
@@ -188,19 +188,24 @@ void DialogArrowWatcher::make_overlays(VideoOverlaySet& items) const{
188188
// - every time the arrow is above top_line, increment m_num_oscillation_above_top_line.
189189
// - likewise for m_num_oscillation_below_bottom_line
190190
// - we alternate between looking for the arrow being above top_line vs below bottom_line
191-
// - reset counts whenever the dialog arrow is not detected
191+
// - reset counts whenever the dialog arrow has not been detected for 10 frames consecutively
192192
bool DialogArrowWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
193193
std::pair<double, double> arrow_location = m_detector.locate_dialog_arrow(frame);
194194
double y_location = arrow_location.second;
195195
// cout << std::to_string(y_location) << endl;
196196

197197
if (y_location < 0){ // dialog arrow not detected
198-
// reset oscillation counts
199-
m_num_oscillation_above_top_line = 0;
200-
m_num_oscillation_below_bottom_line = 0;
201-
return false;
198+
m_num_no_detection++;
199+
if (m_num_no_detection > 10){
200+
// reset oscillation counts
201+
m_num_oscillation_above_top_line = 0;
202+
m_num_oscillation_below_bottom_line = 0;
203+
}
204+
return false;
205+
}else{
206+
m_num_no_detection = 0;
202207
}
203-
208+
204209
if (m_num_oscillation_above_top_line >= 5 && m_num_oscillation_below_bottom_line >= 5){
205210
// we have had 5 oscillations above and below the top and bottom line respectively
206211
return true;

SerialPrograms/Source/PokemonSV/Inference/Dialogs/PokemonSV_DialogArrowDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class DialogArrowWatcher : public VisualInferenceCallback{
5555
double m_bottom_line;
5656
uint16_t m_num_oscillation_above_top_line;
5757
uint16_t m_num_oscillation_below_bottom_line;
58+
uint16_t m_num_no_detection;
5859
// FixedLimitVector<OverlayBoxScope> m_arrows;
5960

6061
};

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void DirectionDetector::change_direction(
215215
}
216216
is_minimap_definitely_unlocked = true;
217217

218-
if (abs_diff < 0.01){
218+
if (abs_diff < 0.0105){
219219
// return when we're close enough to the target
220220
return;
221221
}

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ void overworld_navigation(
489489
context.wait_for_all_requests();
490490
try {
491491
realign_player(info, console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
492-
if (!confirm_marker_present(info, console, context)){
493-
// if marker not present, don't keep walking forward.
492+
if (stop_condition == NavigationStopCondition::STOP_MARKER && !confirm_marker_present(info, console, context)){
493+
// if marker not present when using marker based navigation, don't keep walking forward.
494494
return;
495495
}
496496

@@ -632,7 +632,7 @@ void change_settings(SingleSwitchProgramEnvironment& env, BotBaseContext& contex
632632
{MenuOptionItemEnum::GIVE_NICKNAMES, {MenuOptionToggleEnum::OFF}},
633633
{MenuOptionItemEnum::VERTICAL_CAMERA_CONTROLS, {MenuOptionToggleEnum::REGULAR, MenuOptionToggleEnum::NORMAL}},
634634
{MenuOptionItemEnum::HORIZONTAL_CAMERA_CONTROLS, {MenuOptionToggleEnum::REGULAR, MenuOptionToggleEnum::NORMAL}},
635-
{MenuOptionItemEnum::CAMERA_SUPPORT, {MenuOptionToggleEnum::ON}},
635+
{MenuOptionItemEnum::CAMERA_SUPPORT, {MenuOptionToggleEnum::OFF}},
636636
{MenuOptionItemEnum::CAMERA_INTERPOLATION, {MenuOptionToggleEnum::NORMAL, MenuOptionToggleEnum::AVERAGE}},
637637
{MenuOptionItemEnum::CAMERA_DISTANCE, {MenuOptionToggleEnum::CLOSE}},
638638
{MenuOptionItemEnum::AUTOSAVE, {MenuOptionToggleEnum::OFF}},
@@ -650,7 +650,7 @@ void change_settings(SingleSwitchProgramEnvironment& env, BotBaseContext& contex
650650
config_option(context, 1); // Give Nicknames: Off
651651
config_option(context, 0); // Vertical Camera Controls: Regular
652652
config_option(context, 0); // Horiztontal Camera Controls: Regular
653-
config_option(context, 0); // Camera Support: On
653+
config_option(context, 1); // Camera Support: Off
654654
config_option(context, 0); // Camera Interpolation: Normal
655655
config_option(context, 0); // Camera Distance: Close
656656
config_option(context, 1); // Autosave: Off
@@ -853,7 +853,7 @@ void press_A_until_dialog(const ProgramInfo& info, ConsoleHandle& console, BotBa
853853
}
854854
}
855855

856-
bool check_ride_active(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
856+
bool is_ride_active(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
857857
while (true){
858858
try {
859859
// open main menu
@@ -879,14 +879,22 @@ bool check_ride_active(const ProgramInfo& info, ConsoleHandle& console, BotBaseC
879879
}
880880

881881
void get_on_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
882+
get_on_or_off_ride(info, console, context, true);
883+
}
884+
885+
void get_off_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
886+
get_on_or_off_ride(info, console, context, false);
887+
}
888+
889+
void get_on_or_off_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, bool get_on){
882890
pbf_press_button(context, BUTTON_PLUS, 20, 20);
883891

884892
WallClock start = current_time();
885-
while (!check_ride_active(info, console, context)){
893+
while (get_on != is_ride_active(info, console, context)){
886894
if (current_time() - start > std::chrono::minutes(3)){
887895
throw OperationFailedException(
888896
ErrorReport::SEND_ERROR_REPORT, console,
889-
"get_on_ride(): Failed to get on ride after 3 minutes.",
897+
"get_on_or_off_ride(): Failed to get on/off ride after 3 minutes.",
890898
true
891899
);
892900
}

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,15 @@ void wait_for_overworld(
230230

231231
void press_A_until_dialog(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, uint16_t seconds_between_button_presses);
232232

233-
bool check_ride_active(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context);
233+
// return true if ride is active. i.e. if you are on your ride
234+
bool is_ride_active(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context);
234235

235236
void get_on_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context);
236237

238+
void get_off_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context);
239+
240+
void get_on_or_off_ride(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, bool get_on);
241+
237242

238243
// change the settings prior to Autostory
239244
// Assumes that `current_segment` represents where we currently are in the story.

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
1818
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
1919
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
20+
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
2021
#include "PokemonSV_AutoStoryTools.h"
2122
#include "PokemonSV_AutoStory_Segment_01.h"
2223

@@ -83,14 +84,14 @@ AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
8384
stats.m_checkpoint++;
8485
env.update_stats();
8586
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
86-
first_attempt = false;
8787
}
8888

8989
context.wait_for_all_requests();
9090
// set settings
9191
enter_menu_from_overworld(env.program_info(), env.console, context, 0, MenuSide::RIGHT, false);
9292
change_settings(env, context, language, first_attempt);
9393
pbf_mash_button(context, BUTTON_B, 2 * TICKS_PER_SECOND);
94+
context.wait_for_all_requests();
9495

9596
break;
9697
}catch(...){
@@ -114,7 +115,7 @@ void checkpoint_02(
114115
bool first_attempt = true;
115116
while (true){
116117
try{
117-
if(!first_attempt){
118+
if(first_attempt){
118119
save_game_tutorial(env.program_info(), env.console, context);
119120
stats.m_checkpoint++;
120121
env.update_stats();
@@ -179,14 +180,8 @@ void checkpoint_02(
179180
env.console.log("clear_dialog: Talk with Clavell outside. Receive Rotom phone. Stop when detect overworld.");
180181
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD, CallbackEnum::WHITE_A_BUTTON});
181182

182-
context.wait_for_all_requests();
183-
env.console.log("Bump into power of science NPC");
184-
// console.overlay().add_log("Bump into power of science NPC", COLOR_WHITE);
185-
pbf_move_left_joystick(context, 128, 0, 33 * TICKS_PER_SECOND, 20);
186-
187183
context.wait_for_all_requests();
188184
env.console.log("Clear map tutorial");
189-
// console.overlay().add_log("Clear map tutorial", COLOR_WHITE);
190185
open_map_from_overworld(env.program_info(), env.console, context, true);
191186
leave_phone_to_overworld(env.program_info(), env.console, context);
192187

@@ -218,11 +213,13 @@ void checkpoint_03(
218213
}
219214

220215
context.wait_for_all_requests();
221-
222-
pbf_move_left_joystick(context, 255, 0, 1 * TICKS_PER_SECOND, 20);
223-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 156, 1 * TICKS_PER_SECOND);
224-
env.console.log("overworld_navigation(): Go to Nemona's house.");
225-
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0);
216+
DirectionDetector direction;
217+
direction.change_direction(env.program_info(), env.console, context, 4.62);
218+
pbf_move_left_joystick(context, 128, 0, 3600, 50);
219+
pbf_move_left_joystick(context, 0, 128, 30, 50);
220+
221+
direction.change_direction(env.program_info(), env.console, context, 4.62);
222+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20);
226223

227224
context.wait_for_all_requests();
228225
env.console.log("Entered Nemona's house");

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
1818
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
1919
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
20+
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
2021
#include "PokemonSV_AutoStoryTools.h"
2122
#include "PokemonSV_AutoStory_Segment_02.h"
2223

@@ -80,27 +81,21 @@ void checkpoint_04(
8081
}
8182
context.wait_for_all_requests();
8283

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);
84+
DirectionDetector direction;
85+
direction.change_direction(env.program_info(), env.console, context, 3.72);
86+
pbf_move_left_joystick(context, 128, 0, 400, 50);
87+
direction.change_direction(env.program_info(), env.console, context, 4.55);
88+
pbf_move_left_joystick(context, 128, 0, 600, 50);
89+
direction.change_direction(env.program_info(), env.console, context, 5.27);
90+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 20);
9491

9592
context.wait_for_all_requests();
9693
env.console.log("Starting battle...");
97-
env.console.overlay().add_log("Starting battle...", COLOR_WHITE);
9894
// TODO: Battle start prompt detection
9995
// can lose this battle, and story will continue
10096
mash_button_till_overworld(env.console, context);
10197
context.wait_for_all_requests();
10298
env.console.log("Finished battle.");
103-
env.console.overlay().add_log("Finished battle.", COLOR_WHITE);
10499

105100
break;
106101
}catch(...){

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
1717
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
1818
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
19-
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
19+
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
2020
#include "PokemonSV_AutoStoryTools.h"
2121
#include "PokemonSV_AutoStory_Segment_03.h"
2222

@@ -82,11 +82,11 @@ void checkpoint_05(
8282
}
8383
context.wait_for_all_requests();
8484

85-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 40, 160, 60);
86-
pbf_move_left_joystick(context, 128, 0, 7 * TICKS_PER_SECOND, 20);
87-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 40, 84, 60);
88-
env.console.log("overworld_navigation: Go to mom at the gate.");
89-
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 20);
85+
DirectionDetector direction;
86+
direction.change_direction(env.program_info(), env.console, context, 1.92);
87+
pbf_move_left_joystick(context, 128, 0, 7 * TICKS_PER_SECOND, 50);
88+
direction.change_direction(env.program_info(), env.console, context, 1.13);
89+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20);
9090

9191
context.wait_for_all_requests();
9292
env.console.log("Get mom's sandwich");
@@ -123,7 +123,7 @@ void checkpoint_06(
123123
pbf_move_left_joystick(context, 128, 0, 6 * TICKS_PER_SECOND, 20);
124124
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 110, 10, 60);
125125
env.console.log("overworld_navigation: Go to Nemona.");
126-
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 20);
126+
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 20, 20, true, true);
127127

128128
context.wait_for_all_requests();
129129
env.console.log("clear_dialog: Talk with Nemona to start catch tutorial. Stop when detect battle.");
@@ -171,11 +171,25 @@ void checkpoint_07(
171171
env.console.log("Move to cliff");
172172
env.console.overlay().add_log("Move to cliff", COLOR_WHITE);
173173

174-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 240, 60, 80);
174+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 70, 100);
175175
env.console.log("overworld_navigation: Go to cliff.");
176-
overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 116, 0, 72, 24, true, true);
176+
overworld_navigation(env.program_info(), env.console, context,
177+
NavigationStopCondition::STOP_TIME, NavigationMovementMode::DIRECTIONAL_ONLY,
178+
135, 0, 24, 12, true, true);
179+
180+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 128, 0, 80);
181+
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
182+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
183+
overworld_navigation(env.program_info(), env.console, context,
184+
NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY,
185+
128, 0, 24, 12, true, true);
186+
},
187+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
188+
pbf_move_left_joystick(context, 0, 128, 40, 50);
189+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
190+
}
191+
);
177192

178-
env.console.log("clear_dialog: Talk to Nemona at the cliff. Stop when detect overworld.");
179193
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD});
180194

181195
context.wait_for_all_requests();

0 commit comments

Comments
 (0)