From 8212db278b47d64f15aa5cb309437b74589f334a Mon Sep 17 00:00:00 2001 From: Mysticial Date: Thu, 28 Dec 2023 17:16:47 -0800 Subject: [PATCH 1/2] Remove option to run for trainer battles. --- .../DevPrograms/TestProgramSwitch.cpp | 4 +-- .../DevPrograms/TestProgramSwitch.h | 2 +- .../Options/PokemonSV_SinglesAIOption.cpp | 14 ++++----- .../Options/PokemonSV_SinglesAIOption.h | 2 +- .../Options/PokemonSV_SinglesMoveTable.cpp | 30 ++++++++++++++----- .../Options/PokemonSV_SinglesMoveTable.h | 12 +++++--- .../Farming/PokemonSV_TournamentFarmer2.cpp | 1 + 7 files changed, 42 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp index 4a620b181..4df1845d1 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp @@ -196,7 +196,7 @@ TestProgram::TestProgram() PA_ADD_OPTION(STATIC_TEXT); PA_ADD_OPTION(SELECT); PA_ADD_OPTION(PLAYER_LIST); - PA_ADD_OPTION(battle_AI); +// PA_ADD_OPTION(battle_AI); PA_ADD_OPTION(NOTIFICATIONS); BUTTON0.add_listener(*this); BUTTON1.add_listener(*this); @@ -243,7 +243,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope& // SinglesAIOption battle_AI; - run_singles_battle(env, console, context, battle_AI, false); +// run_singles_battle(env, console, context, battle_AI, false); #if 0 diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h index e276270a6..56179aa62 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h @@ -71,7 +71,7 @@ class TestProgram : public MultiSwitchProgramInstance, public ButtonListener{ PokemonSV::PlayerListTable PLAYER_LIST; - PokemonSV::SinglesAIOption battle_AI; +// PokemonSV::SinglesAIOption battle_AI; EventNotificationOption NOTIFICATION_TEST; EventNotificationsOption NOTIFICATIONS; diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.cpp b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.cpp index b07ba5f67..efe2b36c9 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.cpp +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.cpp @@ -16,7 +16,7 @@ using namespace Pokemon; -SinglesAIOption::SinglesAIOption() +SinglesAIOption::SinglesAIOption(bool trainer_battle) : GroupOption( "Battle AI", LockMode::UNLOCK_WHILE_RUNNING, @@ -32,12 +32,12 @@ SinglesAIOption::SinglesAIOption() ) , MOVE_TABLES(6) { - MOVE_TABLES.emplace_back("1st " + STRING_POKEMON + " Move Table:"); - MOVE_TABLES.emplace_back("2nd " + STRING_POKEMON + " Move Table:"); - MOVE_TABLES.emplace_back("3rd " + STRING_POKEMON + " Move Table:"); - MOVE_TABLES.emplace_back("4th " + STRING_POKEMON + " Move Table:"); - MOVE_TABLES.emplace_back("5th " + STRING_POKEMON + " Move Table:"); - MOVE_TABLES.emplace_back("6th " + STRING_POKEMON + " Move Table:"); + MOVE_TABLES.emplace_back("1st " + STRING_POKEMON + " Move Table:", trainer_battle); + MOVE_TABLES.emplace_back("2nd " + STRING_POKEMON + " Move Table:", trainer_battle); + MOVE_TABLES.emplace_back("3rd " + STRING_POKEMON + " Move Table:", trainer_battle); + MOVE_TABLES.emplace_back("4th " + STRING_POKEMON + " Move Table:", trainer_battle); + MOVE_TABLES.emplace_back("5th " + STRING_POKEMON + " Move Table:", trainer_battle); + MOVE_TABLES.emplace_back("6th " + STRING_POKEMON + " Move Table:", trainer_battle); PA_ADD_STATIC(description); size_t c = 0; diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.h b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.h index b9e0b499c..3b59abdaa 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.h +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesAIOption.h @@ -21,7 +21,7 @@ namespace PokemonSV{ class SinglesAIOption : public GroupOption{ public: - SinglesAIOption(); + SinglesAIOption(bool trainer_battle); public: StaticTextOption description; diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp index 0981dce99..b9fd8f7c6 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp @@ -11,7 +11,7 @@ namespace NintendoSwitch{ namespace PokemonSV{ -const EnumDatabase& singles_move_enum_database(){ +const EnumDatabase& singles_move_enum_database_wild(){ static EnumDatabase database{ {SinglesMoveType::Move1, "move1", "Move 1"}, {SinglesMoveType::Move2, "move2", "Move 2"}, @@ -21,6 +21,15 @@ const EnumDatabase& singles_move_enum_database(){ }; return database; } +const EnumDatabase& singles_move_enum_database_trainer(){ + static EnumDatabase database{ + {SinglesMoveType::Move1, "move1", "Move 1"}, + {SinglesMoveType::Move2, "move2", "Move 2"}, + {SinglesMoveType::Move3, "move3", "Move 3"}, + {SinglesMoveType::Move4, "move4", "Move 4"}, + }; + return database; +} std::string SinglesMoveEntry::to_str() const{ switch (type){ @@ -47,8 +56,12 @@ std::string SinglesMoveEntry::to_str() const{ SinglesMoveTableRow::~SinglesMoveTableRow(){ type.remove_listener(*this); } -SinglesMoveTableRow::SinglesMoveTableRow() - : type(singles_move_enum_database(), LockMode::UNLOCK_WHILE_RUNNING, SinglesMoveType::Move1) +SinglesMoveTableRow::SinglesMoveTableRow(bool p_trainer_battle) + : type( + p_trainer_battle ? singles_move_enum_database_trainer() : singles_move_enum_database_wild(), + LockMode::UNLOCK_WHILE_RUNNING, + SinglesMoveType::Move1 + ) , terastallize(LockMode::UNLOCK_WHILE_RUNNING, false) , notes(false, LockMode::UNLOCK_WHILE_RUNNING, "", "(e.g. Screech, Belly Drum)") { @@ -60,7 +73,7 @@ SinglesMoveTableRow::SinglesMoveTableRow() type.add_listener(*this); } std::unique_ptr SinglesMoveTableRow::clone() const{ - std::unique_ptr ret(new SinglesMoveTableRow()); + std::unique_ptr ret(new SinglesMoveTableRow(trainer_battle)); ret->type.set(type); ret->terastallize = (bool)terastallize; ret->notes.set(notes); @@ -77,7 +90,7 @@ void SinglesMoveTableRow::value_changed(){ -SinglesMoveTable::SinglesMoveTable(std::string label) +SinglesMoveTable::SinglesMoveTable(std::string label, bool trainer_battle) : EditableTableOption_t( std::move(label), #if 0 @@ -87,8 +100,9 @@ SinglesMoveTable::SinglesMoveTable(std::string label) "Changes to this table take effect on the next battle.", #endif LockMode::UNLOCK_WHILE_RUNNING, - make_defaults() + make_defaults(trainer_battle) ) + , m_trainer_battle(trainer_battle) {} std::vector SinglesMoveTable::snapshot(){ @@ -101,9 +115,9 @@ std::vector SinglesMoveTable::make_header() const{ "Notes", }; } -std::vector> SinglesMoveTable::make_defaults(){ +std::vector> SinglesMoveTable::make_defaults(bool trainer_battle){ std::vector> ret; - ret.emplace_back(new SinglesMoveTableRow()); + ret.emplace_back(new SinglesMoveTableRow(trainer_battle)); return ret; } diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h index c4033b66d..67b87867d 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h @@ -24,7 +24,8 @@ enum class SinglesMoveType{ Move4, Run, }; -const EnumDatabase& singles_move_enum_database(); +const EnumDatabase& singles_move_enum_database_wild(); +const EnumDatabase& singles_move_enum_database_trainer(); struct SinglesMoveEntry{ @@ -38,7 +39,7 @@ struct SinglesMoveEntry{ class SinglesMoveTableRow : public EditableTableRow, public ConfigOption::Listener{ public: ~SinglesMoveTableRow(); - SinglesMoveTableRow(); + SinglesMoveTableRow(bool p_trainer_battle); virtual std::unique_ptr clone() const override; SinglesMoveEntry snapshot() const; @@ -47,6 +48,7 @@ class SinglesMoveTableRow : public EditableTableRow, public ConfigOption::Listen virtual void value_changed() override; private: + bool trainer_battle; EnumDropdownCell type; BooleanCheckBoxCell terastallize; StringCell notes; @@ -55,14 +57,16 @@ class SinglesMoveTableRow : public EditableTableRow, public ConfigOption::Listen class SinglesMoveTable : public EditableTableOption_t{ public: - SinglesMoveTable(std::string label); + SinglesMoveTable(std::string label, bool trainer_battle); std::vector snapshot(); virtual std::vector make_header() const; - static std::vector> make_defaults(); + static std::vector> make_defaults(bool trainer_battle); +private: + bool m_trainer_battle; }; diff --git a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp index fe734b062..52e5bd111 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp @@ -103,6 +103,7 @@ TournamentFarmer2::TournamentFarmer2() LockMode::UNLOCK_WHILE_RUNNING, 1, 0 ) + , BATTLE_AI(true) , GO_HOME_WHEN_DONE(false) , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) , NOTIFICATIONS({ From 88c6fee36b0584b0e0985340c919123673a6f28b Mon Sep 17 00:00:00 2001 From: Mysticial Date: Thu, 28 Dec 2023 17:37:44 -0800 Subject: [PATCH 2/2] Fix build. Add untested loss recovery. --- .../Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp | 1 - .../Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h | 3 --- .../Programs/Farming/PokemonSV_TournamentFarmer.cpp | 2 +- .../PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h | 5 ++++- .../Programs/Farming/PokemonSV_TournamentFarmer2.cpp | 6 ++++++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp index b9fd8f7c6..d06c8a1ec 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.cpp @@ -102,7 +102,6 @@ SinglesMoveTable::SinglesMoveTable(std::string label, bool trainer_battle) LockMode::UNLOCK_WHILE_RUNNING, make_defaults(trainer_battle) ) - , m_trainer_battle(trainer_battle) {} std::vector SinglesMoveTable::snapshot(){ diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h index 67b87867d..a9ae6707a 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SinglesMoveTable.h @@ -64,9 +64,6 @@ class SinglesMoveTable : public EditableTableOption_t{ virtual std::vector make_header() const; static std::vector> make_defaults(bool trainer_battle); - -private: - bool m_trainer_battle; }; diff --git a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.cpp b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.cpp index e43967d88..63cc78766 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.cpp @@ -557,7 +557,7 @@ void TournamentFarmer::handle_end_of_tournament(SingleSwitchProgramEnvironment& //Fly to academy from west pokemon center after losing. -void TournamentFarmer::return_to_academy_after_loss(SingleSwitchProgramEnvironment& env, BotBaseContext& context) { +void return_to_academy_after_loss(SingleSwitchProgramEnvironment& env, BotBaseContext& context) { env.log("Tournament lost! Navigating back to academy."); open_map_from_overworld(env.program_info(), env.console, context); pbf_press_button(context, BUTTON_ZR, 50, 40); diff --git a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h index 70a9121c5..d2ccae97b 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h +++ b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer.h @@ -21,6 +21,10 @@ namespace NintendoSwitch{ namespace PokemonSV{ +void return_to_academy_after_loss(SingleSwitchProgramEnvironment& env, BotBaseContext& context); + + + class TournamentFarmer_Descriptor : public SingleSwitchProgramDescriptor{ public: TournamentFarmer_Descriptor(); @@ -64,7 +68,6 @@ class TournamentFarmer : public SingleSwitchProgramInstance, public ButtonListen void run_battle(SingleSwitchProgramEnvironment& env, BotBaseContext& context); void check_prize(SingleSwitchProgramEnvironment& env, BotBaseContext& context); void handle_end_of_tournament(SingleSwitchProgramEnvironment& env, BotBaseContext& context); - void return_to_academy_after_loss(SingleSwitchProgramEnvironment& env, BotBaseContext& context); }; } diff --git a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp index 52e5bd111..8e4f66d59 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_TournamentFarmer2.cpp @@ -17,6 +17,7 @@ #include "PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "PokemonSV/Programs/PokemonSV_SaveGame.h" #include "PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.h" +#include "PokemonSV_TournamentFarmer.h" #include "PokemonSV_TournamentFarmer2.h" namespace PokemonAutomation{ @@ -146,6 +147,7 @@ class TournamentFarmer2::ResetOnExit{ }; + void TournamentFarmer2::program(SingleSwitchProgramEnvironment& env, BotBaseContext& context) { assert_16_9_720p_min(env.logger(), env.console); TournamentFarmer2_Descriptor::Stats& stats = env.current_stats(); @@ -265,6 +267,10 @@ void TournamentFarmer2::program(SingleSwitchProgramEnvironment& env, BotBaseCont } + if (battle_lost){ + return_to_academy_after_loss(env, context); + break; + } } // Tournament won