Skip to content

Commit

Permalink
Merge branch 'PokemonAutomation:main' into flyingtrailfarmer
Browse files Browse the repository at this point in the history
  • Loading branch information
NympheaR authored Dec 29, 2023
2 parents 2190c02 + 88c6fee commit cf705b1
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace Pokemon;



SinglesAIOption::SinglesAIOption()
SinglesAIOption::SinglesAIOption(bool trainer_battle)
: GroupOption(
"Battle AI",
LockMode::UNLOCK_WHILE_RUNNING,
Expand All @@ -32,12 +32,12 @@ SinglesAIOption::SinglesAIOption()
)
, MOVE_TABLES(6)
{
MOVE_TABLES.emplace_back("<b>1st " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>2nd " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>3rd " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>4th " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>5th " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>6th " + STRING_POKEMON + " Move Table:</b>");
MOVE_TABLES.emplace_back("<b>1st " + STRING_POKEMON + " Move Table:</b>", trainer_battle);
MOVE_TABLES.emplace_back("<b>2nd " + STRING_POKEMON + " Move Table:</b>", trainer_battle);
MOVE_TABLES.emplace_back("<b>3rd " + STRING_POKEMON + " Move Table:</b>", trainer_battle);
MOVE_TABLES.emplace_back("<b>4th " + STRING_POKEMON + " Move Table:</b>", trainer_battle);
MOVE_TABLES.emplace_back("<b>5th " + STRING_POKEMON + " Move Table:</b>", trainer_battle);
MOVE_TABLES.emplace_back("<b>6th " + STRING_POKEMON + " Move Table:</b>", trainer_battle);

PA_ADD_STATIC(description);
size_t c = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace PokemonSV{

class SinglesAIOption : public GroupOption{
public:
SinglesAIOption();
SinglesAIOption(bool trainer_battle);

public:
StaticTextOption description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace NintendoSwitch{
namespace PokemonSV{


const EnumDatabase<SinglesMoveType>& singles_move_enum_database(){
const EnumDatabase<SinglesMoveType>& singles_move_enum_database_wild(){
static EnumDatabase<SinglesMoveType> database{
{SinglesMoveType::Move1, "move1", "Move 1"},
{SinglesMoveType::Move2, "move2", "Move 2"},
Expand All @@ -21,6 +21,15 @@ const EnumDatabase<SinglesMoveType>& singles_move_enum_database(){
};
return database;
}
const EnumDatabase<SinglesMoveType>& singles_move_enum_database_trainer(){
static EnumDatabase<SinglesMoveType> 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){
Expand All @@ -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)")
{
Expand All @@ -60,7 +73,7 @@ SinglesMoveTableRow::SinglesMoveTableRow()
type.add_listener(*this);
}
std::unique_ptr<EditableTableRow> SinglesMoveTableRow::clone() const{
std::unique_ptr<SinglesMoveTableRow> ret(new SinglesMoveTableRow());
std::unique_ptr<SinglesMoveTableRow> ret(new SinglesMoveTableRow(trainer_battle));
ret->type.set(type);
ret->terastallize = (bool)terastallize;
ret->notes.set(notes);
Expand All @@ -77,7 +90,7 @@ void SinglesMoveTableRow::value_changed(){



SinglesMoveTable::SinglesMoveTable(std::string label)
SinglesMoveTable::SinglesMoveTable(std::string label, bool trainer_battle)
: EditableTableOption_t<SinglesMoveTableRow>(
std::move(label),
#if 0
Expand All @@ -87,7 +100,7 @@ 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)
)
{}

Expand All @@ -101,9 +114,9 @@ std::vector<std::string> SinglesMoveTable::make_header() const{
"Notes",
};
}
std::vector<std::unique_ptr<EditableTableRow>> SinglesMoveTable::make_defaults(){
std::vector<std::unique_ptr<EditableTableRow>> SinglesMoveTable::make_defaults(bool trainer_battle){
std::vector<std::unique_ptr<EditableTableRow>> ret;
ret.emplace_back(new SinglesMoveTableRow());
ret.emplace_back(new SinglesMoveTableRow(trainer_battle));
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum class SinglesMoveType{
Move4,
Run,
};
const EnumDatabase<SinglesMoveType>& singles_move_enum_database();
const EnumDatabase<SinglesMoveType>& singles_move_enum_database_wild();
const EnumDatabase<SinglesMoveType>& singles_move_enum_database_trainer();


struct SinglesMoveEntry{
Expand All @@ -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<EditableTableRow> clone() const override;

SinglesMoveEntry snapshot() const;
Expand All @@ -47,6 +48,7 @@ class SinglesMoveTableRow : public EditableTableRow, public ConfigOption::Listen
virtual void value_changed() override;

private:
bool trainer_battle;
EnumDropdownCell<SinglesMoveType> type;
BooleanCheckBoxCell terastallize;
StringCell notes;
Expand All @@ -55,14 +57,13 @@ class SinglesMoveTableRow : public EditableTableRow, public ConfigOption::Listen

class SinglesMoveTable : public EditableTableOption_t<SinglesMoveTableRow>{
public:
SinglesMoveTable(std::string label);
SinglesMoveTable(std::string label, bool trainer_battle);

std::vector<SinglesMoveEntry> snapshot();

virtual std::vector<std::string> make_header() const;

static std::vector<std::unique_ptr<EditableTableRow>> make_defaults();

static std::vector<std::unique_ptr<EditableTableRow>> make_defaults(bool trainer_battle);
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -103,6 +104,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({
Expand Down Expand Up @@ -145,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<TournamentFarmer2_Descriptor::Stats>();
Expand Down Expand Up @@ -264,6 +267,10 @@ void TournamentFarmer2::program(SingleSwitchProgramEnvironment& env, BotBaseCont
}


if (battle_lost){
return_to_academy_after_loss(env, context);
break;
}
}

// Tournament won
Expand Down

0 comments on commit cf705b1

Please sign in to comment.