Skip to content

Commit 4001a75

Browse files
committed
LZA: add program Shuttle Run
1 parent 3e02fa8 commit 4001a75

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h"
3333
#include "Programs/ShinyHunting/PokemonLZA_Zone11Alpha.h"
3434
#include "Programs/ShinyHunting/PokemonLZA_Zone19Runner.h"
35+
#include "Programs/ShinyHunting/PokemonLZA_ShuttleRun.h"
3536

3637
// Non-Shiny Hunting
3738
#include "Programs/NonShinyHunting/PokemonLZA_StatsReset.h"
@@ -81,6 +82,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
8182
if (IS_BETA_VERSION){
8283
ret.emplace_back(make_single_switch_program<ShinyHunt_Zone11Alpha_Descriptor, ShinyHunt_Zone11Alpha>());
8384
ret.emplace_back(make_single_switch_program<ShinyHunt_Zone19Runner_Descriptor, ShinyHunt_Zone19Runner>());
85+
ret.emplace_back(make_single_switch_program<ShinyHunt_ShuttleRun_Descriptor, ShinyHunt_ShuttleRun>());
8486
}
8587
if (PreloadSettings::instance().DEVELOPER_MODE){
8688
ret.emplace_back(make_single_switch_program<BeldumHunter_Descriptor, BeldumHunter>());
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* Shiny Hunt - Shuttle Run
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/ProgramStats/StatsTracking.h"
8+
#include "CommonFramework/Notifications/ProgramNotifications.h"
9+
#include "CommonTools/Async/InferenceRoutines.h"
10+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
11+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
12+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
13+
#include "Pokemon/Pokemon_Strings.h"
14+
#include "PokemonLZA_ShuttleRun.h"
15+
16+
namespace PokemonAutomation {
17+
namespace NintendoSwitch {
18+
namespace PokemonLZA {
19+
20+
using namespace Pokemon;
21+
22+
23+
ShinyHunt_ShuttleRun_Descriptor::ShinyHunt_ShuttleRun_Descriptor()
24+
: SingleSwitchProgramDescriptor(
25+
"PokemonLZA:ShinyHunt-ShuttleRun", STRING_POKEMON + " LZA",
26+
"Shuttle Run",
27+
"Programs/PokemonLZA/ShinyHunt-ShuttleRun.html",
28+
"Shiny hunt by repeatedly running back and forth between two points",
29+
ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED,
30+
AllowCommandsWhenRunning::DISABLE_COMMANDS, {}
31+
)
32+
{}
33+
class ShinyHunt_ShuttleRun_Descriptor::Stats : public StatsTracker{
34+
public:
35+
Stats()
36+
: resets(m_stats["Rounds"])
37+
, errors(m_stats["Errors"])
38+
{
39+
m_display_order.emplace_back("Rounds");
40+
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
41+
}
42+
43+
std::atomic<uint64_t>& resets;
44+
std::atomic<uint64_t>& errors;
45+
};
46+
std::unique_ptr<StatsTracker> ShinyHunt_ShuttleRun_Descriptor::make_stats() const{
47+
return std::unique_ptr<StatsTracker>(new Stats());
48+
}
49+
50+
51+
ShinyHunt_ShuttleRun::ShinyHunt_ShuttleRun()
52+
: DURATION("<b>Duration:</b><br>Run the program this long.", LockMode::LOCK_WHILE_RUNNING, "1 h")
53+
// , RUN_FORWARD_DURATION("<b>Run Forward Duration</b><br>"
54+
// "Run forward and backward for this long each round trip.", LockMode::LOCK_WHILE_RUNNING, "5000 ms")
55+
, NOTIFICATION_STATUS("Status Update", true, false, std::chrono::seconds(3600))
56+
, NOTIFICATIONS({
57+
&NOTIFICATION_STATUS,
58+
&NOTIFICATION_PROGRAM_FINISH,
59+
&NOTIFICATION_ERROR_RECOVERABLE,
60+
&NOTIFICATION_ERROR_FATAL,
61+
})
62+
{
63+
PA_ADD_OPTION(DURATION);
64+
// PA_ADD_OPTION(RUN_FORWARD_DURATION);
65+
PA_ADD_OPTION(NOTIFICATIONS);
66+
}
67+
68+
namespace {
69+
70+
void hunt_loop(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Milliseconds duration){
71+
context.wait_for_all_requests();
72+
ssf_press_button(context, BUTTON_B, 0ms, 500ms, 0ms);
73+
pbf_move_left_joystick(context, 128, 0, duration, 0ms);
74+
pbf_move_left_joystick(context, 255, 128, 1300ms, 0ms);
75+
pbf_press_button(context, BUTTON_L, 100ms, 500ms);
76+
pbf_press_button(context, BUTTON_PLUS, 240ms, 80ms); // open map
77+
context.wait_for_all_requests();
78+
pbf_wait(context, 500ms);
79+
pbf_press_button(context, BUTTON_Y, 100ms, 100ms); // select fly point
80+
pbf_mash_button(context, BUTTON_A, 1000ms);
81+
context.wait_for(std::chrono::milliseconds(4000));
82+
}
83+
} // namespace
84+
85+
void ShinyHunt_ShuttleRun::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
86+
ShinyHunt_ShuttleRun_Descriptor::Stats& stats =
87+
env.current_stats<ShinyHunt_ShuttleRun_Descriptor::Stats>();
88+
WallClock deadline = current_time() + DURATION.get();
89+
Milliseconds duration = 8500ms;
90+
pbf_press_button(context, BUTTON_L, 100ms, 100ms); // connect
91+
do{
92+
send_program_status_notification(env, NOTIFICATION_STATUS);
93+
stats.resets++;
94+
hunt_loop(env, context, duration);
95+
env.update_stats();
96+
}while (current_time() < deadline);
97+
98+
go_home(env.console, context);
99+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
100+
}
101+
102+
103+
} // namespace PokemonLZA
104+
} // namespace NintendoSwitch
105+
} // namespace PokemonAutomation
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Shiny Hunt - Shuttle Run
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_Shuttle_Run_H
8+
#define PokemonAutomation_PokemonLZA_Shuttle_Run_H
9+
10+
#include "Common/Cpp/Options/TimeDurationOption.h"
11+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
12+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
13+
14+
namespace PokemonAutomation {
15+
namespace NintendoSwitch {
16+
namespace PokemonLZA {
17+
18+
19+
class ShinyHunt_ShuttleRun_Descriptor : public SingleSwitchProgramDescriptor {
20+
public:
21+
ShinyHunt_ShuttleRun_Descriptor();
22+
23+
class Stats;
24+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
25+
};
26+
27+
28+
class ShinyHunt_ShuttleRun : public SingleSwitchProgramInstance {
29+
public:
30+
ShinyHunt_ShuttleRun();
31+
32+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
33+
34+
private:
35+
MillisecondsOption DURATION;
36+
// MillisecondsOption RUN_FORWARD_DURATION;
37+
EventNotificationOption NOTIFICATION_STATUS;
38+
EventNotificationsOption NOTIFICATIONS;
39+
};
40+
41+
42+
} // namespace PokemonLZA
43+
} // namespace NintendoSwitch
44+
} // namespace PokemonAutomation
45+
#endif

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,8 @@ file(GLOB LIBRARY_SOURCES
16311631
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone11Alpha.h
16321632
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone19Runner.cpp
16331633
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone19Runner.h
1634+
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_ShuttleRun.h
1635+
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_ShuttleRun.cpp
16341636
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.cpp
16351637
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h
16361638
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_OverworldWatcher.cpp

0 commit comments

Comments
 (0)