Skip to content

Commit

Permalink
Fix vivillon program
Browse files Browse the repository at this point in the history
  • Loading branch information
Gin committed Sep 15, 2023
1 parent 831080d commit 83cb0d2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VideoOverlay{
// Asynchronously, add a log message to the screen. The older messages added via `add_log_text()`
// will be placed higher like in the logging window.
// Use `OverlayLogTextScope` to remove the log messages automatically.
virtual void add_log(std::string message, Color color) = 0;
virtual void add_log(std::string message, Color color = COLOR_WHITE) = 0;
// Remove all messages added by `add_log_text()`.
// Use `OverlayLogTextScope` to remove log messages automatically.
virtual void clear_log() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class VideoOverlaySession : public VideoOverlay{
virtual void add_text(const OverlayText& text) override;
virtual void remove_text(const OverlayText& text) override;

virtual void add_log(std::string message, Color color) override;
virtual void add_log(std::string message, Color color = COLOR_WHITE) override;
virtual void clear_log() override;

virtual void add_stat(OverlayStat& stat) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void EggAutonomous::program(SingleSwitchProgramEnvironment& env, BotBaseContext&
assert_16_9_720p_min(env.logger(), env.console);

// Connect the controller.
pbf_press_button(context, BUTTON_LCLICK, 10, 0);
pbf_press_button(context, BUTTON_L, 10, 0);

{
// reset_position_to_flying_spot(env, context);
Expand Down
40 changes: 28 additions & 12 deletions SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,9 @@ void leave_phone_to_overworld(const ProgramInfo& info, ConsoleHandle& console, B
}
}


void fly_to_closest_pokecenter_on_map(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
// Zoom in one level onto the map.
// If the player character icon or any wild pokemon icon overlaps with the PokeCenter icon, the code cannot
// detect it. So we zoom in as much as we can to prevent any icon overlap.
pbf_press_button(context, BUTTON_ZR, 20, 100);
// While in the current map zoom level, detect pokecenter icons and fly to the closest one.
// Return true if succeed. Return false if no visible pokcenter on map
bool fly_to_visible_closest_pokecenter_cur_zoom_level(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
context.wait_for_all_requests();
const auto snapshot_frame = console.video().snapshot().frame;
const size_t screen_width = snapshot_frame->width();
Expand All @@ -509,13 +506,11 @@ void fly_to_closest_pokecenter_on_map(const ProgramInfo& info, ConsoleHandle& co
const double center_x = 0.5 * screen_width, center_y = 0.5 * screen_height;
{
MapPokeCenterIconWatcher pokecenter_watcher(COLOR_RED, console.overlay(), MAP_READABLE_AREA);
int ret = wait_until(console, context, std::chrono::seconds(10), {pokecenter_watcher});
int ret = wait_until(console, context, std::chrono::seconds(2), {pokecenter_watcher});
if (ret != 0){
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"fly_to_closest_pokecenter_on_map(): Cannot detect PokeCenter icon after 10 seconds",
true
);
console.log("No visible pokecetner found on map");
console.overlay().add_log("No whole PokeCenter icon");
return false;
}
// Find the detected PokeCenter icon closest to the screen center (where player character is on the map).
for(const auto& box: pokecenter_watcher.found_locations()){
Expand All @@ -529,6 +524,7 @@ void fly_to_closest_pokecenter_on_map(const ProgramInfo& info, ConsoleHandle& co
}
}
console.log("Found closest pokecenter icon on map: (" + std::to_string(closest_icon_x) + ", " + std::to_string(closest_icon_y) + ").");
console.overlay().add_log("Detected PokeCenter icon");
}

// Convert the vector from center to the PokeCenter icon into a left joystick movement
Expand All @@ -547,6 +543,26 @@ void fly_to_closest_pokecenter_on_map(const ProgramInfo& info, ConsoleHandle& co
const uint16_t push_time = std::max(uint16_t(magnitude * scale + 0.5), uint16_t(3));
pbf_move_left_joystick(context, move_x, move_y, push_time, 30);
fly_to_overworld_from_map(info, console, context);
return true;
}


void fly_to_closest_pokecenter_on_map(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
// Zoom in one level onto the map.
// If the player character icon or any wild pokemon icon overlaps with the PokeCenter icon, the code cannot
// detect it. So we zoom in as much as we can to prevent any icon overlap.
pbf_press_button(context, BUTTON_ZR, 40, 100);

if (fly_to_visible_closest_pokecenter_cur_zoom_level(info, console, context) == false){
// Does not find any visible pokecenter. Probably the player character icon overlaps with the pokecenter.
// Zoom out to the max warpable level and try pressing on the player character.
console.log("Zoom to max level to fly without moving joystick");
console.overlay().add_log("Assume too close");
pbf_press_button(context, BUTTON_ZL, 40, 100);
pbf_press_button(context, BUTTON_ZL, 40, 100);

fly_to_overworld_from_map(info, console, context);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ ShinyHuntScatterbug::ShinyHuntScatterbug()
LockWhileRunning::LOCKED,
false
)
, DEBUG_WARP_TO_POKECENTER(
"<b>Whether to change the program to just warping to closest PokeCenter and stopping:</b><br>"
"This is for debugging the PokeCenter warping function.",
LockWhileRunning::LOCKED,
false
)
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
, NOTIFICATIONS({
&NOTIFICATION_STATUS_UPDATE,
Expand All @@ -114,6 +120,7 @@ ShinyHuntScatterbug::ShinyHuntScatterbug()
{
if (PreloadSettings::instance().DEVELOPER_MODE){
PA_ADD_OPTION(SAVE_DEBUG_VIDEO);
PA_ADD_OPTION(DEBUG_WARP_TO_POKECENTER);
}
PA_ADD_OPTION(LANGUAGE);
PA_ADD_OPTION(SANDWICH_OPTIONS);
Expand All @@ -128,10 +135,15 @@ void ShinyHuntScatterbug::program(SingleSwitchProgramEnvironment& env, BotBaseCo
ShinyHuntScatterbug_Descriptor::Stats& stats = env.current_stats<ShinyHuntScatterbug_Descriptor::Stats>();

// Connect the controller.
pbf_press_button(context, BUTTON_LCLICK, 10, 0);
pbf_press_button(context, BUTTON_L, 10, 0);

assert_16_9_720p_min(env.logger(), env.console);

if (DEBUG_WARP_TO_POKECENTER){
reset_to_pokecenter(env, context);
return;
}

m_iterations = 0;
m_consecutive_failures = 0;
m_pending_save = false;
Expand Down Expand Up @@ -189,7 +201,7 @@ void ShinyHuntScatterbug::run_one_sandwich_iteration(SingleSwitchProgramEnvironm
// to this location.
pbf_press_button(context, BUTTON_L, 50, 40);
// Move forward
pbf_move_left_joystick(context, 128, 0, 125, 0);
pbf_move_left_joystick(context, 128, 0, 180, 0);
picnic_from_overworld(env.program_info(), env.console, context);

pbf_move_left_joystick(context, 128, 0, 30, 40);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class ShinyHuntScatterbug : public SingleSwitchProgramInstance{

FloatingPointOption AUTO_HEAL_PERCENT;

// Debug options
BooleanCheckBoxOption SAVE_DEBUG_VIDEO;
BooleanCheckBoxOption DEBUG_WARP_TO_POKECENTER;

EventNotificationOption NOTIFICATION_STATUS_UPDATE;
EventNotificationsOption NOTIFICATIONS;
Expand Down

0 comments on commit 83cb0d2

Please sign in to comment.