Skip to content

Commit 65d872c

Browse files
committed
run_battle_press_A: use sets to avoid duplicate callbacks
1 parent 0d628c1 commit 65d872c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void run_battle_press_A(
4646
VideoStream& stream,
4747
ProControllerContext& context,
4848
BattleStopCondition stop_condition,
49-
std::vector<CallbackEnum> enum_optional_callbacks,
49+
std::unordered_set<CallbackEnum> enum_optional_callbacks,
5050
bool detect_wipeout
5151
){
5252
int16_t num_times_seen_overworld = 0;
@@ -61,10 +61,15 @@ void run_battle_press_A(
6161
MoveSelectWatcher move_select_menu(COLOR_YELLOW);
6262

6363
std::vector<PeriodicInferenceCallback> callbacks;
64+
std::vector<CallbackEnum> enum_all_callbacks;
6465
// mandatory callbacks: Battle, Overworld, Advance Dialog, Swap menu, Move select
6566
// optional callbacks: ADVANCE_DIALOG, DIALOG_ARROW, NEXT_POKEMON
66-
std::vector<CallbackEnum> enum_all_callbacks{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
67-
enum_all_callbacks.insert(enum_all_callbacks.end(), enum_optional_callbacks.begin(), enum_optional_callbacks.end()); // append the mandatory and optional callback vectors together
67+
68+
// merge the mandatory and optional callbacks as a set, to avoid duplicates. then convert to vector
69+
std::unordered_set<CallbackEnum> enum_all_callbacks_set{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
70+
enum_all_callbacks_set.insert(enum_optional_callbacks.begin(), enum_optional_callbacks.end()); // append the mandatory and optional callback sets together
71+
enum_all_callbacks.assign(enum_all_callbacks_set.begin(), enum_all_callbacks_set.end());
72+
6873
for (const CallbackEnum& enum_callback : enum_all_callbacks){
6974
switch(enum_callback){
7075
case CallbackEnum::ADVANCE_DIALOG:

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PokemonAutomation_PokemonSV_AutoStoryTools_H
99

1010
#include <functional>
11+
#include <unordered_set>
1112
#include "CommonFramework/Language.h"
1213
#include "CommonFramework/ImageTools/ImageBoxes.h"
1314
#include "CommonFramework/ProgramStats/StatsTracking.h"
@@ -123,7 +124,7 @@ void run_battle_press_A(
123124
VideoStream& stream,
124125
ProControllerContext& context,
125126
BattleStopCondition stop_condition,
126-
std::vector<CallbackEnum> optional_callbacks = {},
127+
std::unordered_set<CallbackEnum> optional_callbacks = {},
127128
bool detect_wipeout = false
128129
);
129130

0 commit comments

Comments
 (0)