Skip to content

Commit ad6e45b

Browse files
committed
Fix double-battle shiny detection when your lead is shiny. Clear out some BDSP programs for SBB
1 parent 899bf79 commit ad6e45b

File tree

9 files changed

+53
-34
lines changed

9 files changed

+53
-34
lines changed

SerialPrograms/Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "PokemonBDSP/Inference/Sounds/PokemonBDSP_ShinySoundDetector.h"
1818
#include "PokemonBDSP_ShinyEncounterDetector.h"
1919

20+
//#include <iostream>
21+
//using std::cout;
22+
//using std::endl;
23+
2024
namespace PokemonAutomation{
2125
namespace NintendoSwitch{
2226
namespace PokemonBDSP{
@@ -48,6 +52,8 @@ ShinyEncounterTracker::ShinyEncounterTracker(
4852
// , m_overlay(overlay)
4953
, m_battle_menu(battle_type)
5054
, m_dialog_tracker(logger, m_dialog_detector)
55+
, m_wild_animation_end_timestamp(WallClock::min())
56+
, m_your_animation_start_timestamp(WallClock::min())
5157
, m_box_wild_left(0.40, 0.02, 0.20, 0.48)
5258
, m_box_wild_right(0.70, 0.02, 0.20, 0.48)
5359
, m_sparkle_tracker_wild(logger, overlay, m_sparkles_wild, {0.4, 0.02, 0.60, 0.93})
@@ -94,7 +100,7 @@ bool ShinyEncounterTracker::process_frame(const VideoSnapshot& frame){
94100
case EncounterState::BEFORE_ANYTHING:
95101
break;
96102
case EncounterState::WILD_ANIMATION:{
97-
// Update the timestamp that records the end of wild animation
103+
// Update the timestamp that records the end of wild animation
98104
m_wild_animation_end_timestamp = frame.timestamp;
99105

100106
m_sparkle_tracker_wild.process_frame(frame);
@@ -120,8 +126,10 @@ bool ShinyEncounterTracker::process_frame(const VideoSnapshot& frame){
120126
break;
121127
}
122128
case EncounterState::YOUR_ANIMATION:
123-
// Update the timestamp that records the end of player pokemon animation
124-
m_your_animation_end_timestamp = frame.timestamp;
129+
// Update the timestamp that records the start of player pokemon animation
130+
if (m_your_animation_start_timestamp == WallClock::min()){
131+
m_your_animation_start_timestamp = frame.timestamp;
132+
}
125133

126134
m_sparkle_tracker_wild.clear_boxes();
127135
m_sparkle_tracker_own.process_frame(frame);
@@ -167,28 +175,27 @@ void determine_shiny_status(
167175
alpha_wild_overall += DIALOG_ALPHA;
168176
}
169177
}
178+
179+
#if 0
180+
cout << "Wild End: " << std::chrono::duration_cast<Milliseconds>(tracker.wild_animation_end_timestmap() - tracker.m_start_time) << endl; // REMOVE
181+
cout << "Your Start: " << std::chrono::duration_cast<Milliseconds>(tracker.your_animation_start_timestamp() - tracker.m_start_time) << endl; // REMOVE
182+
for (WallClock time : shiny_sound_timestamps){
183+
cout << "Shiny Sound: " << std::chrono::duration_cast<Milliseconds>(time - tracker.m_start_time) << endl; // REMOVE
184+
}
185+
#endif
170186

171187
bool wild_shiny_sound_detected = false;
172188
bool own_shiny_sound_detected = false;
173-
for(const WallClock& timestamp: shiny_sound_timestamps){
174-
const WallClock& wild_end = tracker.wild_animtion_end_timestmap();
175-
const WallClock& own_end = tracker.your_animation_end_timestamp();
176-
177-
auto get_timestamp_distance = [](const WallClock& t0, const WallClock& t1) -> std::chrono::milliseconds{
178-
if (t0 > t1){
179-
return std::chrono::duration_cast<std::chrono::milliseconds>(t0 - t1);
180-
}else{
181-
return std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0);
182-
}
183-
};
184-
185-
const auto dist_to_wild = get_timestamp_distance(timestamp, wild_end);
186-
const auto dist_to_own = get_timestamp_distance(timestamp, own_end);
187-
if (dist_to_wild < dist_to_own){
188-
wild_shiny_sound_detected = true;
189-
}else if (dist_to_own < dist_to_wild){
190-
own_shiny_sound_detected = true;
191-
}else{
189+
for (const WallClock& timestamp: shiny_sound_timestamps){
190+
const WallClock& wild_end = tracker.wild_animation_end_timestmap();
191+
const WallClock& own_start = tracker.your_animation_start_timestamp();
192+
193+
bool wild_shiny = timestamp < wild_end + Milliseconds(500);
194+
bool own_shiny = timestamp >= own_start;
195+
196+
wild_shiny_sound_detected |= wild_shiny;
197+
own_shiny_sound_detected |= own_shiny;
198+
if (!wild_shiny && !own_shiny){
192199
throw_and_log<OperationFailedException>(
193200
env.logger(), ErrorReport::SEND_ERROR_REPORT,
194201
"Wrong shiny sound timing found."

SerialPrograms/Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinyEncounterDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class ShinyEncounterTracker : public VisualInferenceCallback{
6161
const ShinySparkleAggregator& sparkles_wild_right() const{ return m_best_wild_right; }
6262
const ShinySparkleAggregator& sparkles_own() const{ return m_best_own; }
6363

64-
const WallClock& wild_animtion_end_timestmap() const { return m_wild_animation_end_timestamp; }
65-
const WallClock& your_animation_end_timestamp() const { return m_your_animation_end_timestamp; }
64+
const WallClock& wild_animation_end_timestmap() const { return m_wild_animation_end_timestamp; }
65+
const WallClock& your_animation_start_timestamp() const { return m_your_animation_start_timestamp; }
6666

6767
virtual void make_overlays(VideoOverlaySet& items) const override;
6868
virtual bool process_frame(const VideoSnapshot& frame) override;
@@ -79,7 +79,7 @@ class ShinyEncounterTracker : public VisualInferenceCallback{
7979
BattleDialogDetector m_dialog_detector;
8080
EncounterDialogTracker m_dialog_tracker;
8181
WallClock m_wild_animation_end_timestamp;
82-
WallClock m_your_animation_end_timestamp;
82+
WallClock m_your_animation_start_timestamp;
8383

8484
ImageFloatBox m_box_wild_left;
8585
ImageFloatBox m_box_wild_right;

SerialPrograms/Source/PokemonBDSP/Programs/Farming/PokemonBDSP_DoublesLeveling.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ DoublesLeveling_Descriptor::DoublesLeveling_Descriptor()
3030
"Level up your party by spamming spread moves in a double battle with a partner that heals you forever.",
3131
FeedbackType::REQUIRED,
3232
AllowCommandsWhenRunning::DISABLE_COMMANDS,
33-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
33+
{ControllerFeature::NintendoSwitch_ProController},
34+
FasterIfTickPrecise::NOT_FASTER
3435
)
3536
{}
3637
struct DoublesLeveling_Descriptor::Stats : public PokemonSwSh::ShinyHuntTracker{

SerialPrograms/Source/PokemonBDSP/Programs/Farming/PokemonBDSP_MoneyFarmerRoute210.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
namespace PokemonAutomation{
2222
namespace NintendoSwitch{
2323
namespace PokemonBDSP{
24-
using namespace Pokemon;
24+
25+
using namespace Pokemon;
2526

2627

2728
MoneyFarmerRoute210_Descriptor::MoneyFarmerRoute210_Descriptor()
@@ -32,7 +33,10 @@ MoneyFarmerRoute210_Descriptor::MoneyFarmerRoute210_Descriptor()
3233
"Farm money by using VS Seeker to rebattle the Ace Trainer couple on Route 210.",
3334
FeedbackType::REQUIRED,
3435
AllowCommandsWhenRunning::DISABLE_COMMANDS,
35-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
36+
{
37+
ControllerFeature::TickPrecise,
38+
ControllerFeature::NintendoSwitch_ProController,
39+
}
3640
)
3741
{}
3842
struct MoneyFarmerRoute210_Descriptor::Stats : public StatsTracker{

SerialPrograms/Source/PokemonBDSP/Programs/Farming/PokemonBDSP_MoneyFarmerRoute212.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ MoneyFarmerRoute212_Descriptor::MoneyFarmerRoute212_Descriptor()
3333
"Farm money by using VS Seeker to rebattle the rich couple on Route 212.",
3434
FeedbackType::REQUIRED,
3535
AllowCommandsWhenRunning::DISABLE_COMMANDS,
36-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
36+
{
37+
ControllerFeature::TickPrecise,
38+
ControllerFeature::NintendoSwitch_ProController,
39+
}
3740
)
3841
{}
3942
struct MoneyFarmerRoute212_Descriptor::Stats : public StatsTracker{
@@ -224,7 +227,7 @@ void MoneyFarmerRoute212::heal_at_center_and_return(VideoStream& stream, ProCont
224227
pbf_move_left_joystick(context, 255, 128, 380, 0);
225228
pbf_move_left_joystick(context, 128, 255, 300, 0);
226229
pbf_move_left_joystick(context, 0, 128, 600, 0);
227-
pbf_move_left_joystick(context, 255, 128, 70, 0);
230+
pbf_move_left_joystick(context, 255, 128, 75, 0);
228231
pbf_move_left_joystick(context, 128, 255, 1375, 0);
229232
pbf_move_left_joystick(context, 255, 128, 125, 0);
230233
pbf_move_left_joystick(context, 128, 255, 200, 0);

SerialPrograms/Source/PokemonBDSP/Programs/General/PokemonBDSP_MassRelease.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ MassRelease_Descriptor::MassRelease_Descriptor()
2626
"Mass release boxes of " + STRING_POKEMON + ".",
2727
FeedbackType::NONE,
2828
AllowCommandsWhenRunning::DISABLE_COMMANDS,
29-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
29+
{ControllerFeature::NintendoSwitch_ProController},
30+
FasterIfTickPrecise::NOT_FASTER
3031
)
3132
{}
3233
struct MassRelease_Descriptor::Stats : public StatsTracker{

SerialPrograms/Source/PokemonBDSP/Programs/ShinyHunting/PokemonBDSP_LegendaryReset.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ LegendaryReset_Descriptor::LegendaryReset_Descriptor()
3030
"Shiny hunt a standing legendary " + STRING_POKEMON + ".",
3131
FeedbackType::REQUIRED,
3232
AllowCommandsWhenRunning::DISABLE_COMMANDS,
33-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
33+
{ControllerFeature::NintendoSwitch_ProController},
34+
FasterIfTickPrecise::NOT_FASTER
3435
)
3536
{}
3637
std::unique_ptr<StatsTracker> LegendaryReset_Descriptor::make_stats() const{

SerialPrograms/Source/PokemonBDSP/Programs/ShinyHunting/PokemonBDSP_ShinyHunt-Overworld.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ ShinyHuntOverworld_Descriptor::ShinyHuntOverworld_Descriptor()
2828
"Shiny hunt overworld " + STRING_POKEMON + ".",
2929
FeedbackType::REQUIRED,
3030
AllowCommandsWhenRunning::DISABLE_COMMANDS,
31-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
31+
{ControllerFeature::NintendoSwitch_ProController},
32+
FasterIfTickPrecise::NOT_FASTER
3233
)
3334
{}
3435
struct ShinyHuntOverworld_Descriptor::Stats : public PokemonSwSh::ShinyHuntTracker{

SerialPrograms/Source/PokemonBDSP/Programs/ShinyHunting/PokemonBDSP_StarterReset.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ StarterReset_Descriptor::StarterReset_Descriptor()
3434
"Shiny hunt your starter " + STRING_POKEMON + ".",
3535
FeedbackType::REQUIRED,
3636
AllowCommandsWhenRunning::DISABLE_COMMANDS,
37-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
37+
{ControllerFeature::NintendoSwitch_ProController},
38+
FasterIfTickPrecise::NOT_FASTER
3839
)
3940
{}
4041
struct StarterReset_Descriptor::Stats : public PokemonSwSh::ShinyHuntTracker{

0 commit comments

Comments
 (0)