Skip to content

Commit 1bfd14e

Browse files
committed
send_out_lead flag for handle_encounter
1 parent d828dca commit 1bfd14e

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CommonTools/Async/InferenceRoutines.h"
1111
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1212
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
13+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1314
#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
1415
#include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h"
1516
#include "PokemonRSE/PokemonRSE_Settings.h"
@@ -20,11 +21,11 @@ namespace NintendoSwitch{
2021
namespace PokemonRSE{
2122

2223

23-
void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
24+
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext& context){
2425
// A + B + Select + Start
2526
pbf_press_button(context, BUTTON_B | BUTTON_Y | BUTTON_MINUS | BUTTON_PLUS, 10, 180);
2627

27-
pbf_mash_button(context, BUTTON_PLUS, GameSettings::instance().START_BUTTON_MASH0);
28+
pbf_mash_button(context, BUTTON_PLUS, GameSettings::instance().START_BUTTON_MASH);
2829
context.wait_for_all_requests();
2930

3031
pbf_press_button(context, BUTTON_A, 20, 40);
@@ -33,8 +34,8 @@ void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerConte
3334
BlackScreenOverWatcher detector(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
3435
int ret = wait_until(
3536
stream, context,
36-
GameSettings::instance().ENTER_GAME_WAIT0,
37-
{detector}
37+
std::chrono::milliseconds(GameSettings::instance().ENTER_GAME_WAIT * (1000 / TICKS_PER_SECOND)),
38+
{{detector}}
3839
);
3940
if (ret == 0){
4041
stream.log("Entered game!");
@@ -49,7 +50,7 @@ void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerConte
4950
context.wait_for_all_requests();
5051
}
5152

52-
void flee_battle(VideoStream& stream, ProControllerContext& context) {
53+
void flee_battle(VideoStream& stream, SwitchControllerContext& context) {
5354
stream.log("Navigate to Run.");
5455
pbf_press_dpad(context, DPAD_RIGHT, 20, 20);
5556
pbf_press_dpad(context, DPAD_DOWN, 20, 20);
@@ -89,7 +90,7 @@ void flee_battle(VideoStream& stream, ProControllerContext& context) {
8990
}
9091
}
9192

92-
bool handle_encounter(VideoStream& stream, ProControllerContext& context) {
93+
bool handle_encounter(VideoStream& stream, SwitchControllerContext& context, bool send_out_lead) {
9394
float shiny_coefficient = 1.0;
9495
ShinySoundDetector shiny_detector(stream.logger(), [&](float error_coefficient) -> bool{
9596
shiny_coefficient = error_coefficient;
@@ -101,9 +102,9 @@ bool handle_encounter(VideoStream& stream, ProControllerContext& context) {
101102
pbf_mash_button(context, BUTTON_A, 540);
102103
context.wait_for_all_requests();
103104

104-
int res = run_until<ProControllerContext>(
105+
int res = run_until<SwitchControllerContext>(
105106
stream, context,
106-
[&](ProControllerContext& context) {
107+
[&](SwitchControllerContext& context) {
107108
int ret = wait_until(
108109
stream, context,
109110
std::chrono::seconds(30),
@@ -130,27 +131,30 @@ bool handle_encounter(VideoStream& stream, ProControllerContext& context) {
130131
}
131132
stream.log("Shiny not found.");
132133

133-
//Send out lead, no shiny detection needed.
134-
BattleMenuWatcher battle_menu(COLOR_RED);
135-
stream.log("Sending out lead Pokemon.");
136-
pbf_press_button(context, BUTTON_A, 40, 40);
134+
if (send_out_lead) {
135+
//Send out lead, no shiny detection needed.
136+
BattleMenuWatcher battle_menu(COLOR_RED);
137+
stream.log("Sending out lead Pokemon.");
138+
pbf_press_button(context, BUTTON_A, 40, 40);
137139

138-
int ret = wait_until(
139-
stream, context,
140-
std::chrono::seconds(15),
141-
{{battle_menu}}
142-
);
143-
if (ret == 0) {
144-
stream.log("Battle menu detecteed!");
145-
} else {
146-
OperationFailedException::fire(
147-
ErrorReport::SEND_ERROR_REPORT,
148-
"handle_encounter(): Did not detect battle menu.",
149-
stream
140+
int ret = wait_until(
141+
stream, context,
142+
std::chrono::seconds(15),
143+
{ {battle_menu} }
150144
);
145+
if (ret == 0) {
146+
stream.log("Battle menu detecteed!");
147+
}
148+
else {
149+
OperationFailedException::fire(
150+
ErrorReport::SEND_ERROR_REPORT,
151+
"handle_encounter(): Did not detect battle menu.",
152+
stream
153+
);
154+
}
155+
pbf_wait(context, 125);
156+
context.wait_for_all_requests();
151157
}
152-
pbf_wait(context, 125);
153-
context.wait_for_all_requests();
154158

155159
return false;
156160
}

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "CommonFramework/Tools/VideoStream.h"
1313
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
14-
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
14+
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
1515

1616
namespace PokemonAutomation{
1717
struct ProgramInfo;
@@ -20,14 +20,15 @@ namespace PokemonRSE{
2020

2121
// Press A+B+Select+Start at the same time to soft reset, then re-enters the game.
2222
// For now this assumes no dry battery.
23-
void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerContext &context);
23+
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext &context);
2424

2525
// Run from battle. Cursor must start on the FIGHT button. Assumes fleeing will always work. (Smoke Ball)
26-
void flee_battle(VideoStream& stream, ProControllerContext& context);
26+
void flee_battle(VideoStream& stream, SwitchControllerContext& context);
2727

2828
// After press A/walking up to enter a battle, run this handle the battle start and to check if opponent is shiny.
29-
// Use flee_battle or soft_reset after this, depending on game.
30-
bool handle_encounter(VideoStream& stream, ProControllerContext& context);
29+
// Set send_out_lead to true and then use flee_battle() after if game is Emerald.
30+
// For R/S, send_out_lead as false and then soft_reset() to save time.
31+
bool handle_encounter(VideoStream& stream, SwitchControllerContext& context, bool send_out_lead);
3132

3233

3334
}

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void ShinyHuntDeoxys::program(SingleSwitchProgramEnvironment& env, ProController
207207
//Start battle.
208208
pbf_press_button(context, BUTTON_A, 20, 40);
209209

210-
bool legendary_shiny = handle_encounter(env.console, context);
210+
bool legendary_shiny = handle_encounter(env.console, context, true);
211211
if (legendary_shiny) {
212212
stats.shinies++;
213213
env.update_stats();

0 commit comments

Comments
 (0)