Skip to content

Commit fe49516

Browse files
committed
BerryTree2 rumble experiment.
1 parent cbf3312 commit fe49516

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

SerialPrograms/Source/PokemonSwSh/Programs/DateSpamFarmers/PokemonSwSh_DateSpam-BerryFarmer2.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1212
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1313
#include "CommonTools/Async/InferenceRoutines.h"
14+
#include "Controllers/RumbleListener.h"
1415
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1516
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1617
#include "Pokemon/Pokemon_Strings.h"
@@ -110,11 +111,13 @@ BerryFarmer2::BerryFarmer2()
110111
LockMode::UNLOCK_WHILE_RUNNING,
111112
"3200 ms"
112113
)
114+
#if 0
113115
, SECONDARY_ATTEMPT_MASH_TIME0(
114116
"<b>Secondary attempt mash time:</b><br>Mash ZL this many ticks for secondary fetch attempts.",
115117
LockMode::UNLOCK_WHILE_RUNNING,
116118
"1920 ms"
117119
)
120+
#endif
118121
, SOUND_THRESHOLD(
119122
"<b>Maximum Sound Error Coefficient",
120123
LockMode::UNLOCK_WHILE_RUNNING,
@@ -135,7 +138,7 @@ BerryFarmer2::BerryFarmer2()
135138
// PA_ADD_OPTION(START_BATTLE_TIMEOUT);
136139
PA_ADD_OPTION(RUSTLING_INTERVAL);
137140
PA_ADD_OPTION(RUSTLING_TIMEOUT0);
138-
PA_ADD_OPTION(SECONDARY_ATTEMPT_MASH_TIME0);
141+
// PA_ADD_OPTION(SECONDARY_ATTEMPT_MASH_TIME0);
139142
PA_ADD_OPTION(SOUND_THRESHOLD);
140143
}
141144

@@ -147,6 +150,7 @@ BerryFarmer2::Rustling BerryFarmer2::check_rustling(SingleSwitchProgramEnvironme
147150
pbf_wait(context, 640ms);
148151
context.wait_for_all_requests();
149152

153+
RumbleWatcher<ProController> initial_rumble_detector(context);
150154
BerryTreeRustlingSoundDetector initial_rustling_detector(
151155
env.console, [&](float error_coefficient) -> bool {
152156
// Warning: This callback will be run from a different thread than this function.
@@ -155,6 +159,7 @@ BerryFarmer2::Rustling BerryFarmer2::check_rustling(SingleSwitchProgramEnvironme
155159
(float)SOUND_THRESHOLD
156160
);
157161

162+
RumbleWatcher<ProController> secondary_rumble_detector(context);
158163
BerryTreeRustlingSoundDetector secondary_rustling_detector(
159164
env.console, [&](float error_coefficient) -> bool {
160165
// Warning: This callback will be run from a different thread than this function.
@@ -173,10 +178,16 @@ BerryFarmer2::Rustling BerryFarmer2::check_rustling(SingleSwitchProgramEnvironme
173178
pbf_wait(context, RUSTLING_TIMEOUT0);
174179
context.wait_for_all_requests();
175180
},
176-
{ {initial_rustling_detector}, {battle_menu_detector}, {start_battle_detector} }
181+
{
182+
initial_rumble_detector,
183+
initial_rustling_detector,
184+
battle_menu_detector,
185+
start_battle_detector,
186+
}
177187
);
178188
switch (ret){
179-
case 0:{
189+
case 0:
190+
case 1:{
180191
env.console.log("BerryFarmer: Initial Rustling detected.");
181192
WallClock initial_rustling_time = current_time();
182193
result = Rustling::Slow;
@@ -187,10 +198,13 @@ BerryFarmer2::Rustling BerryFarmer2::check_rustling(SingleSwitchProgramEnvironme
187198
pbf_wait(context, RUSTLING_TIMEOUT0);
188199
context.wait_for_all_requests();
189200
},
190-
{ {secondary_rustling_detector} }
201+
{
202+
secondary_rumble_detector,
203+
secondary_rustling_detector,
204+
}
191205
);
192206

193-
if (ret1 == 0){
207+
if (ret1 >= 0){
194208
env.console.log("BerryFarmer: Secondary Rustling detected.");
195209
WallClock secondary_rustling_time = current_time();
196210
if (std::chrono::duration_cast<Milliseconds>(secondary_rustling_time - initial_rustling_time).count() <= RUSTLING_INTERVAL){
@@ -199,15 +213,15 @@ BerryFarmer2::Rustling BerryFarmer2::check_rustling(SingleSwitchProgramEnvironme
199213
}
200214
break;
201215
}
202-
case 1:
216+
case 2:
203217
env.log("Unexpected battle menu.", COLOR_RED);
204218
stats.add_error();
205219
env.update_stats();
206220
pbf_mash_button(context, BUTTON_B, 1000ms);
207221
run_away(env.console, context, EXIT_BATTLE_TIMEOUT0);
208222
result = Rustling::Battle;
209223
break;
210-
case 2:{
224+
case 3:{
211225
env.console.log("BerryFarmer: Battle Start detected.");
212226
// wait_until(env.console, context, std::chrono::seconds(START_BATTLE_TIMEOUT), { battle_menu_detector });
213227

@@ -265,6 +279,7 @@ uint16_t BerryFarmer2::do_secondary_attempts(SingleSwitchProgramEnvironment& env
265279
if (no_rustling >= 3){
266280
return attempts;
267281
}
282+
#if 0
268283
if (current_rustling == Rustling::Fast){
269284
// this is the last tree interaction for this time skip
270285
pbf_mash_button(context, BUTTON_ZL, SECONDARY_ATTEMPT_MASH_TIME0);
@@ -273,6 +288,7 @@ uint16_t BerryFarmer2::do_secondary_attempts(SingleSwitchProgramEnvironment& env
273288
stats.shakes++;
274289
current_rustling = check_rustling(env, context);
275290
}
291+
#endif
276292
if (current_rustling == Rustling::Battle){
277293
pbf_mash_button(context, BUTTON_B, 1000ms);
278294
env.console.log("Clearing dialog boxes...");

SerialPrograms/Source/PokemonSwSh/Programs/DateSpamFarmers/PokemonSwSh_DateSpam-BerryFarmer2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BerryFarmer2 : public SingleSwitchProgramInstance{
6868
// SimpleIntegerOption<uint16_t> START_BATTLE_TIMEOUT;
6969
SimpleIntegerOption<uint16_t> RUSTLING_INTERVAL;
7070
MillisecondsOption RUSTLING_TIMEOUT0;
71-
MillisecondsOption SECONDARY_ATTEMPT_MASH_TIME0;
71+
// MillisecondsOption SECONDARY_ATTEMPT_MASH_TIME0;
7272
FloatingPointOption SOUND_THRESHOLD;
7373
};
7474

0 commit comments

Comments
 (0)