Skip to content

Commit 3b679ed

Browse files
committed
configurable button timings, test sound listener
1 parent c49b4f5 commit 3b679ed

File tree

9 files changed

+227
-102
lines changed

9 files changed

+227
-102
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ file(GLOB MAIN_SOURCES
12951295
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h
12961296
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
12971297
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
1298+
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp
1299+
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.h
12981300
Source/PokemonRSE/PokemonRSE_Navigation.cpp
12991301
Source/PokemonRSE/PokemonRSE_Navigation.h
13001302
Source/PokemonRSE/PokemonRSE_Panels.cpp

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1414
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
15+
#include "PokemonRSE/PokemonRSE_Settings.h"
1516
#include "PokemonRSE_Navigation.h"
1617

1718
namespace PokemonAutomation{
@@ -23,13 +24,13 @@ void soft_reset(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext&
2324
// A + B + Select + Start
2425
pbf_press_button(context, BUTTON_B | BUTTON_Y | BUTTON_MINUS | BUTTON_PLUS, 10, 180);
2526

26-
pbf_mash_button(context, BUTTON_PLUS, 500);
27+
pbf_mash_button(context, BUTTON_PLUS, GameSettings::instance().START_BUTTON_MASH);
2728
context.wait_for_all_requests();
2829

2930
pbf_press_button(context, BUTTON_A, 20, 40);
3031

3132
//Wait for game to load in
32-
pbf_wait(context, 300);
33+
pbf_wait(context, GameSettings::instance().ENTER_GAME_WAIT);
3334
context.wait_for_all_requests();
3435
}
3536

SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
*
55
*/
66

7+
#include "CommonFramework/GlobalSettingsPanel.h"
78
#include "Pokemon/Pokemon_Strings.h"
89
#include "PokemonRSE_Panels.h"
910

10-
//#include "PokemonSV_Settings.h"
11+
#include "PokemonRSE_Settings.h"
1112

1213
#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
14+
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"
1315

1416
namespace PokemonAutomation{
1517
namespace NintendoSwitch{
@@ -24,13 +26,21 @@ PanelListFactory::PanelListFactory()
2426
std::vector<PanelEntry> PanelListFactory::make_panels() const{
2527
std::vector<PanelEntry> ret;
2628

27-
// ret.emplace_back("---- Settings ----"); TODO: Add device selection?
28-
// ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());
29+
ret.emplace_back("---- Settings ----"); //TODO: Add device selection?
30+
ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());
2931

3032
//ret.emplace_back("---- General ----");
3133

32-
ret.emplace_back("---- Shiny Hunting ----");
33-
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>());
34+
//ret.emplace_back("---- Shiny Hunting ----");
35+
36+
37+
if (PreloadSettings::instance().DEVELOPER_MODE){
38+
ret.emplace("---- WIP: Shiny Hunting (Audio only) ----");
39+
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>());
40+
41+
ret.emplace_back("---- Developer Tools ----");
42+
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
43+
}
3444

3545
return ret;
3646
}

SerialPrograms/Source/PokemonRSE/PokemonRSE_Settings.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,20 @@ GameSettings::GameSettings()
2828
TICKS_PER_SECOND,
2929
"125"
3030
)
31-
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
32-
, START_GAME_MASH(
33-
"<b>1. Start Game Mash:</b><br>Mash A for this long to start the game.",
31+
, m_soft_reset_timings("<font size=4><b>Soft Reset Timings:</b></font>")
32+
, START_BUTTON_MASH(
33+
"<b>1. Start Button Mash:</b><br>Mash Start for this long after a soft reset to get to the main menu.",
3434
LockMode::LOCK_WHILE_RUNNING,
3535
TICKS_PER_SECOND,
36-
"2 * TICKS_PER_SECOND"
37-
)
38-
, START_GAME_WAIT(
39-
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
40-
LockMode::LOCK_WHILE_RUNNING,
41-
TICKS_PER_SECOND,
42-
"60 * TICKS_PER_SECOND"
43-
)
44-
, ENTER_GAME_MASH(
45-
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
46-
LockMode::LOCK_WHILE_RUNNING,
47-
TICKS_PER_SECOND,
48-
"5 * TICKS_PER_SECOND"
36+
"4 * TICKS_PER_SECOND"
4937
)
5038
, ENTER_GAME_WAIT(
51-
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
39+
"<b>2. Enter Game Wait:</b><br>Wait this long for the game to load.",
5240
LockMode::LOCK_WHILE_RUNNING,
5341
TICKS_PER_SECOND,
54-
"60 * TICKS_PER_SECOND"
42+
"3 * TICKS_PER_SECOND"
5543
)
44+
, m_shiny_audio_settings("<font size=4><b>Shiny Audio Settings:</b></font>")
5645
, SHINY_SOUND_THRESHOLD(
5746
"<b>Shiny Sound Threshold:</b><br>Maximum error coefficient to trigger a shiny detection.",
5847
LockMode::LOCK_WHILE_RUNNING,
@@ -64,11 +53,12 @@ GameSettings::GameSettings()
6453
5000, 0, 48000
6554
)
6655
{
67-
PA_ADD_STATIC(m_start_game_timings);
68-
PA_ADD_OPTION(START_GAME_MASH);
69-
PA_ADD_OPTION(START_GAME_WAIT);
70-
PA_ADD_OPTION(ENTER_GAME_MASH);
56+
PA_ADD_STATIC(m_soft_reset_timings);
57+
PA_ADD_OPTION(START_BUTTON_MASH);
7158
PA_ADD_OPTION(ENTER_GAME_WAIT);
59+
PA_ADD_STATIC(m_shiny_audio_settings);
60+
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
61+
PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY);
7262
}
7363

7464

@@ -79,7 +69,7 @@ GameSettings_Descriptor::GameSettings_Descriptor()
7969
: PanelDescriptor(
8070
Color(),
8171
"PokemonRSE:GlobalSettings",
82-
"Pokemon RSE", "Pokemon RSE Settings",
72+
"Pokemon RSE", "Pokemon Settings",
8373
"ComputerControl/blob/master/Wiki/Programs/PokemonRSE/RSESettings.md",
8474
"Global Pokemon RSE Settings"
8575
)

SerialPrograms/Source/PokemonRSE/PokemonRSE_Settings.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ class GameSettings : public BatchOption{
2626
SectionDividerOption m_menu_navigation;
2727
TimeExpressionOption<uint16_t> GAME_TO_HOME_DELAY;
2828

29-
SectionDividerOption m_start_game_timings;
30-
TimeExpressionOption<uint16_t> START_GAME_MASH;
31-
TimeExpressionOption<uint16_t> START_GAME_WAIT;
32-
TimeExpressionOption<uint16_t> ENTER_GAME_MASH;
29+
SectionDividerOption m_soft_reset_timings;
30+
TimeExpressionOption<uint16_t> START_BUTTON_MASH;
3331
TimeExpressionOption<uint16_t> ENTER_GAME_WAIT;
3432

33+
SectionDividerOption m_shiny_audio_settings;
3534
FloatingPointOption SHINY_SOUND_THRESHOLD;
3635
FloatingPointOption SHINY_SOUND_LOW_FREQUENCY;
3736

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp

Lines changed: 76 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ StarterReset_Descriptor::StarterReset_Descriptor()
2525
"PokemonRSE:StarterReset",
2626
"Pokemon RSE", "Starter Reset",
2727
"ComputerControl/blob/master/Wiki/Programs/PokemonRSE/StarterReset.md",
28-
"Soft reset for a shiny starter.",
28+
"(Audio only) Soft reset for a shiny starter. WIP, audio recognition does not work well.",
2929
//FeedbackType::VIDEO_AUDIO,
3030
FeedbackType::NONE,
3131
AllowCommandsWhenRunning::DISABLE_COMMANDS,
@@ -62,11 +62,34 @@ StarterReset::StarterReset()
6262
LockMode::LOCK_WHILE_RUNNING,
6363
Target::treecko
6464
)
65+
, POOCH_WAIT(
66+
"<b>Battle start wait:</b><br>Time for battle to start and for Poochyena to appear. Make sure to add extra time in case the Poochyena is shiny.",
67+
LockMode::LOCK_WHILE_RUNNING,
68+
TICKS_PER_SECOND,
69+
"6 * TICKS_PER_SECOND"
70+
)
71+
, STARTER_WAIT(
72+
"<b>Send out starter wait:</b><br>After pressing A to send out your selected starter, wait this long for the animation. Make sure to add extra time in case it is shiny.",
73+
LockMode::LOCK_WHILE_RUNNING,
74+
TICKS_PER_SECOND,
75+
"6 * TICKS_PER_SECOND"
76+
)
77+
, NOTIFICATION_SHINY_POOCH(
78+
"Shiny Poochyena",
79+
false, false,
80+
{"Notifs"}
81+
)
82+
, NOTIFICATION_SHINY_STARTER(
83+
"Shiny Starter",
84+
true, false,
85+
{"Notifs", "Showcase"}
86+
)
6587
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
6688
, NOTIFICATIONS({
89+
&NOTIFICATION_SHINY_POOCH,
90+
&NOTIFICATION_SHINY_STARTER,
6791
&NOTIFICATION_STATUS_UPDATE,
6892
&NOTIFICATION_PROGRAM_FINISH,
69-
// &NOTIFICATION_ERROR_FATAL,
7093
})
7194
{
7295
PA_ADD_OPTION(TARGET);
@@ -78,74 +101,51 @@ void StarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseContext&
78101
StarterReset_Descriptor::Stats& stats = env.current_stats<StarterReset_Descriptor::Stats>();
79102

80103
/*
81-
* Stand in front of birch's bag.
82-
*
83-
* text speed fast
104+
* Settings: Text Speed fast.
105+
* Setup: Stand in front of the Professor's bag and save the game.
84106
*
85-
* have to do the SR method instead of run away
107+
* Required to fight, so have to do the SR method instead of run away
108+
* Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue.
86109
*
87-
* ONLY FOR RS, emerald has rng anyway
88-
*
89-
* This assumes no dry battery. If you have a dry battery, just do RNG.
90-
*/
91-
92-
/*
93-
start at birch bag
94-
95-
starter selection
96-
97-
wild pooch appears, shiny check (audio?)
98-
99-
go starter
100-
101-
now shiny check
102-
103-
track starter shiny, zig shiny, number of attempts, errors
104-
105-
if not shiny, soft reset
106-
107-
soft reset checks for dry battery and returns true or false!
108-
110+
* This also assumes no dry battery.
109111
*/
110112

111113
bool shiny_starter = false;
112114
while (!shiny_starter) {
113115

114-
float shiny_coefficient = 1.0;
115116
ShinySoundDetector pooch_detector(env.console, [&](float error_coefficient) -> bool{
116-
// Warning: This callback will be run from a different thread than this function.
117-
shiny_coefficient = error_coefficient;
118117
return true;
119118
});
120119

120+
env.log("Opening bag and selecting starter.");
121+
pbf_press_button(context, BUTTON_A, 40, 180);
122+
123+
switch (TARGET) {
124+
case Target::treecko:
125+
pbf_press_dpad(context, DPAD_LEFT, 40, 100);
126+
break;
127+
case Target::torchic:
128+
//Default cursor position, do nothing.
129+
break;
130+
case Target::mudkip:
131+
pbf_press_dpad(context, DPAD_RIGHT, 40, 100);
132+
break;
133+
default:
134+
OperationFailedException::fire(
135+
env.console, ErrorReport::SEND_ERROR_REPORT,
136+
"StarterReset: Invalid target."
137+
);
138+
break;
139+
}
140+
pbf_mash_button(context, BUTTON_A, 540);
141+
env.log("Starter selected. Checking for shiny Poochyena.");
142+
143+
121144
int ret = run_until(
122145
env.console, context,
123146
[&](BotBaseContext& context){
124-
env.log("Opening bag and selecting starter.");
125-
pbf_press_button(context, BUTTON_A, 40, 180);
126-
127-
switch (TARGET) {
128-
case Target::treecko:
129-
pbf_press_dpad(context, DPAD_LEFT, 40, 100);
130-
break;
131-
case Target::torchic:
132-
//Default cursor position, do nothing.
133-
break;
134-
case Target::mudkip:
135-
pbf_press_dpad(context, DPAD_RIGHT, 40, 100);
136-
break;
137-
default:
138-
OperationFailedException::fire(
139-
env.console, ErrorReport::SEND_ERROR_REPORT,
140-
"StarterReset: Invalid target."
141-
);
142-
break;
143-
}
144-
pbf_mash_button(context, BUTTON_A, 540);
145-
env.log("Starter selected. Checking for shiny Poochyena.");
146-
147147
//Wait for battle to start and for Pooch battle cry
148-
pbf_wait(context, 400);
148+
pbf_wait(context, POOCH_WAIT);
149149

150150
context.wait_for_all_requests();
151151

@@ -156,33 +156,48 @@ void StarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseContext&
156156
if (ret == 0){
157157
env.log("Shiny Poochyena detected!");
158158
stats.poochyena++;
159+
send_program_status_notification(env, NOTIFICATION_SHINY_POOCH, "Shiny Poochyena found.");
160+
}
161+
else {
162+
env.log("Poochyena is not shiny.");
159163
}
160164

161165
ShinySoundDetector starter_detector(env.console, [&](float error_coefficient) -> bool{
162-
// Warning: This callback will be run from a different thread than this function.
163-
shiny_coefficient = error_coefficient;
164166
return true;
165167
});
166168

169+
//Press A to send out your selected starter
170+
env.log("Sending out selected starter.");
171+
pbf_press_button(context, BUTTON_A, 40, 40);
172+
167173
int ret2 = run_until(
168174
env.console, context,
169175
[&](BotBaseContext& context){
170-
env.log("Sending out selected starter.");
171-
//Press A to send out your selected starter
172-
pbf_press_button(context, BUTTON_A, 40, 400);
176+
env.log("Wait for starter to come out.");
177+
pbf_wait(context, STARTER_WAIT);
178+
context.wait_for_all_requests();
173179
},
174180
{{starter_detector}}
175181
);
176182
starter_detector.throw_if_no_sound();
177183
if (ret2 == 0){
178184
env.log("Shiny starter detected!");
179185
stats.shinystarter++;
186+
187+
send_program_status_notification(env, NOTIFICATION_SHINY_STARTER, "Shiny starter found!");
188+
180189
shiny_starter = true;
181190
break;
182-
191+
}
192+
else {
193+
env.log("Starter is not shiny.");
183194
}
184195

185196
env.log("Soft resetting.");
197+
send_program_status_notification(
198+
env, NOTIFICATION_STATUS_UPDATE,
199+
"Soft resetting."
200+
);
186201
soft_reset(env.program_info(), env.console, context);
187202
stats.resets++;
188203
}

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PokemonAutomation_PokemonRSE_StarterReset_H
99

1010
#include "Common/Cpp/Options/SimpleIntegerOption.h"
11+
#include "Common/Cpp/Options/TimeExpressionOption.h"
1112
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1213
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1314

@@ -35,6 +36,11 @@ class StarterReset : public SingleSwitchProgramInstance{
3536
};
3637
EnumDropdownOption<Target> TARGET;
3738

39+
TimeExpressionOption<uint16_t> POOCH_WAIT;
40+
TimeExpressionOption<uint16_t> STARTER_WAIT;
41+
42+
EventNotificationOption NOTIFICATION_SHINY_POOCH;
43+
EventNotificationOption NOTIFICATION_SHINY_STARTER;
3844
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
3945
EventNotificationsOption NOTIFICATIONS;
4046
};

0 commit comments

Comments
 (0)