Repository navigation
PLZA: shared ball throw helper for InPlaceCatcher and PostKillCatcher #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: upstream-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* Ball Throw | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include <stddef.h> | ||
| #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" | ||
| #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" | ||
| #include "PokemonLZA_BallThrow.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonLZA{ | ||
|
|
||
| using namespace std::chrono_literals; | ||
|
|
||
|
|
||
|
|
||
| namespace{ | ||
|
|
||
| // The D-pad presses that scroll `right_scrolls` balls: right when positive, | ||
| // left when negative. | ||
| struct BallScrolls{ | ||
| DpadPosition direction; | ||
| size_t count; | ||
| }; | ||
|
|
||
| BallScrolls ball_scrolls(int8_t right_scrolls){ | ||
| if (right_scrolls >= 0){ | ||
| return {DPAD_RIGHT, (size_t)right_scrolls}; | ||
| } | ||
| return {DPAD_LEFT, (size_t)(-(int)right_scrolls)}; | ||
| } | ||
|
|
||
| // How long ZL + ZR stay held: the aim plus every scroll. | ||
| Milliseconds throw_buttons_hold(const BallThrowOptions& options){ | ||
| const BallScrolls scrolls = ball_scrolls(options.right_scrolls); | ||
| return options.aim + (options.scroll_hold + options.scroll_release) * (Milliseconds::rep)scrolls.count; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
|
|
||
| void throw_ball(ProControllerContext& context, const BallThrowOptions& options){ | ||
| if (options.lock_on > 0ms){ | ||
| pbf_controller_state( | ||
| context, BUTTON_ZL, DPAD_NONE, | ||
| /*left_joystick=*/{0, 0}, /*right_joystick=*/{0, 0}, | ||
| /*duration=*/options.lock_on | ||
| ); | ||
| } | ||
|
|
||
| // The D-pad presses start once the aim is up, while ZL + ZR stay held. | ||
| ssf_press_button( | ||
| context, | ||
| BUTTON_ZL | BUTTON_ZR, | ||
| /*delay=*/options.aim, | ||
| /*hold=*/throw_buttons_hold(options), | ||
| /*cool=*/0ms | ||
| ); | ||
| const BallScrolls scrolls = ball_scrolls(options.right_scrolls); | ||
| for (size_t c = 0; c < scrolls.count; c++){ | ||
| pbf_press_dpad(context, scrolls.direction, options.scroll_hold, options.scroll_release); | ||
| } | ||
|
|
||
| if (options.after_throw > 0ms){ | ||
| pbf_wait(context, options.after_throw); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } // namespace PokemonLZA | ||
| } // namespace NintendoSwitch | ||
| } // namespace PokemonAutomation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* Ball Throw | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| * Throw a ball at the Pokemon the player faces: lock on with ZL, hold ZR | ||
| * with it to raise a ball, optionally scroll to another ball with the | ||
| * D-pad while both are held, then let go to throw. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonLZA_BallThrow_H | ||
| #define PokemonAutomation_PokemonLZA_BallThrow_H | ||
|
|
||
| #include <stdint.h> | ||
| #include "Common/Cpp/Time.h" | ||
| #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" | ||
| #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
|
|
||
| namespace NintendoSwitch{ | ||
| namespace PokemonLZA{ | ||
|
|
||
|
|
||
|
|
||
| // The presses and timings of one throw (throw_ball()). | ||
| struct BallThrowOptions{ | ||
| // ZL alone before ZR joins it, to lock on first. 0 presses both at once. | ||
| Milliseconds lock_on = Milliseconds(0); | ||
|
|
||
| // ZL + ZR held before the first scroll, or before the throw when there | ||
| // is no scroll. | ||
| Milliseconds aim = Milliseconds(500); | ||
|
|
||
| // Balls to scroll to the right while aiming. Negative scrolls left. | ||
| int8_t right_scrolls = 0; | ||
| Milliseconds scroll_hold = Milliseconds(120); | ||
| Milliseconds scroll_release = Milliseconds(80); | ||
|
|
||
| // Wait after letting go of ZL + ZR. | ||
| Milliseconds after_throw = Milliseconds(0); | ||
| }; | ||
|
|
||
|
|
||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hide
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: |
||
| // Lock on, aim, scroll and throw as `options` says, then wait | ||
| // `options.after_throw`. Presses only: the caller checks what the throw did. | ||
| void throw_ball(ProControllerContext& context, const BallThrowOptions& options); | ||
|
|
||
|
|
||
|
|
||
| } // namespace PokemonLZA | ||
| } // namespace NintendoSwitch | ||
| } // namespace PokemonAutomation | ||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this unit test for this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped in 2394ee3, with its registration in PokemonLZA_Tests.cpp.