Skip to content

Commit 1af2fb1

Browse files
authored
more Autostory updates (#660)
* Check for Next Pokemon prompt when battling Nemona at Mesagoza gate * run_battle_press_A: use sets to avoid duplicate callbacks * run_battle_press_A: split into two functions, one for trainers, one for wild battles.
1 parent e12176c commit 1af2fb1

13 files changed

+101
-45
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ namespace PokemonSV{
4141

4242

4343

44-
44+
// spam A button to choose the first move
45+
// throw exception if wipeout or if your lead faints.
4546
void run_battle_press_A(
4647
VideoStream& stream,
4748
ProControllerContext& context,
4849
BattleStopCondition stop_condition,
49-
std::vector<CallbackEnum> enum_optional_callbacks,
50+
std::unordered_set<CallbackEnum> enum_optional_callbacks,
5051
bool detect_wipeout
5152
){
5253
int16_t num_times_seen_overworld = 0;
@@ -61,9 +62,15 @@ void run_battle_press_A(
6162
MoveSelectWatcher move_select_menu(COLOR_YELLOW);
6263

6364
std::vector<PeriodicInferenceCallback> callbacks;
65+
std::vector<CallbackEnum> enum_all_callbacks;
6466
// mandatory callbacks: Battle, Overworld, Advance Dialog, Swap menu, Move select
65-
std::vector<CallbackEnum> enum_all_callbacks{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
66-
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+
// optional callbacks: DIALOG_ARROW, NEXT_POKEMON
68+
69+
// merge the mandatory and optional callbacks as a set, to avoid duplicates. then convert to vector
70+
std::unordered_set<CallbackEnum> enum_all_callbacks_set{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
71+
enum_all_callbacks_set.insert(enum_optional_callbacks.begin(), enum_optional_callbacks.end()); // append the mandatory and optional callback sets together
72+
enum_all_callbacks.assign(enum_all_callbacks_set.begin(), enum_all_callbacks_set.end());
73+
6774
for (const CallbackEnum& enum_callback : enum_all_callbacks){
6875
switch(enum_callback){
6976
case CallbackEnum::ADVANCE_DIALOG:
@@ -78,10 +85,10 @@ void run_battle_press_A(
7885
case CallbackEnum::BATTLE:
7986
callbacks.emplace_back(battle);
8087
break;
81-
case CallbackEnum::GRADIENT_ARROW:
88+
case CallbackEnum::NEXT_POKEMON: // to detect the "next pokemon" prompt.
8289
callbacks.emplace_back(next_pokemon);
8390
break;
84-
case CallbackEnum::SWAP_MENU:
91+
case CallbackEnum::SWAP_MENU: // detecting Swap Menu implies your lead fainted.
8592
callbacks.emplace_back(fainted);
8693
break;
8794
case CallbackEnum::MOVE_SELECT:
@@ -159,7 +166,7 @@ void run_battle_press_A(
159166
stream.log("run_battle_press_A: Detected dialog arrow.");
160167
pbf_press_button(context, BUTTON_A, 20, 105);
161168
break;
162-
case CallbackEnum::GRADIENT_ARROW:
169+
case CallbackEnum::NEXT_POKEMON:
163170
stream.log("run_battle_press_A: Detected prompt for bringing in next pokemon. Keep current pokemon.");
164171
pbf_mash_button(context, BUTTON_B, 100);
165172
break;
@@ -176,6 +183,27 @@ void run_battle_press_A(
176183
}
177184
}
178185

186+
void run_trainer_battle_press_A(
187+
VideoStream& stream,
188+
ProControllerContext& context,
189+
BattleStopCondition stop_condition,
190+
std::unordered_set<CallbackEnum> enum_optional_callbacks,
191+
bool detect_wipeout
192+
){
193+
enum_optional_callbacks.insert(CallbackEnum::NEXT_POKEMON); // always check for the "Next pokemon" prompt when in trainer battles
194+
run_battle_press_A(stream, context, stop_condition, enum_optional_callbacks, detect_wipeout);
195+
}
196+
197+
void run_wild_battle_press_A(
198+
VideoStream& stream,
199+
ProControllerContext& context,
200+
BattleStopCondition stop_condition,
201+
std::unordered_set<CallbackEnum> enum_optional_callbacks,
202+
bool detect_wipeout
203+
){
204+
run_battle_press_A(stream, context, stop_condition, enum_optional_callbacks, detect_wipeout);
205+
}
206+
179207
void select_top_move(VideoStream& stream, ProControllerContext& context, size_t consecutive_move_select){
180208
if (consecutive_move_select > 3){
181209
// to handle case where move is disabled/out of PP/taunted
@@ -471,7 +499,7 @@ void overworld_navigation(
471499
return;
472500
}
473501

474-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
502+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
475503
if (auto_heal){
476504
auto_heal_from_menu_or_overworld(info, stream, context, 0, true);
477505
}
@@ -743,7 +771,7 @@ void handle_unexpected_battles(
743771
action(info, stream, context);
744772
return;
745773
}catch (UnexpectedBattleException&){
746-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
774+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
747775
}
748776
}
749777
}
@@ -943,7 +971,7 @@ bool is_ride_active(const ProgramInfo& info, VideoStream& stream, ProControllerC
943971
return is_ride_active;
944972

945973
}catch(UnexpectedBattleException&){
946-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
974+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
947975
}
948976
}
949977

@@ -1072,7 +1100,7 @@ void realign_player_from_landmark(
10721100
return;
10731101

10741102
}catch (UnexpectedBattleException&){
1075-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
1103+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
10761104
}catch (OperationFailedException&){
10771105
// reset to overworld if failed to center on the pokecenter, and re-try
10781106
leave_phone_to_overworld(info, stream, context);
@@ -1154,7 +1182,7 @@ void move_cursor_towards_flypoint_and_go_there(
11541182
return;
11551183

11561184
}catch (UnexpectedBattleException&){
1157-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
1185+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
11581186
}catch (OperationFailedException&){
11591187
// reset to overworld if failed to center on the pokecenter, and re-try
11601188
leave_phone_to_overworld(info, stream, context);

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

Lines changed: 18 additions & 5 deletions
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"
@@ -58,7 +59,7 @@ enum class CallbackEnum{
5859
BATTLE,
5960
TUTORIAL,
6061
BLACK_DIALOG_BOX,
61-
GRADIENT_ARROW,
62+
NEXT_POKEMON,
6263
SWAP_MENU,
6364
MOVE_SELECT,
6465
};
@@ -117,13 +118,25 @@ class AutoStory_Segment {
117118
AutoStoryOptions options) const = 0;
118119
};
119120

120-
// spam A button to choose the first move
121-
// throw exception if wipeout.
122-
void run_battle_press_A(
121+
// spam A button to choose the first move for trainer battles
122+
// detect_wipeout: can be false if you have multiple pokemon in your party, since an exception will be thrown if your lead faints.
123+
// throw exception if wipeout or if your lead faints.
124+
void run_trainer_battle_press_A(
123125
VideoStream& stream,
124126
ProControllerContext& context,
125127
BattleStopCondition stop_condition,
126-
std::vector<CallbackEnum> optional_callbacks = {},
128+
std::unordered_set<CallbackEnum> enum_optional_callbacks = {},
129+
bool detect_wipeout = false
130+
);
131+
132+
// spam A button to choose the first move for wild battles
133+
// detect_wipeout: can be false if you have multiple pokemon in your party, since an exception will be thrown if your lead faints.
134+
// throw exception if wipeout or if your lead faints.
135+
void run_wild_battle_press_A(
136+
VideoStream& stream,
137+
ProControllerContext& context,
138+
BattleStopCondition stop_condition,
139+
std::unordered_set<CallbackEnum> enum_optional_callbacks = {},
127140
bool detect_wipeout = false
128141
);
129142

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ void checkpoint_06(
122122
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
123123
{CallbackEnum::WHITE_A_BUTTON, CallbackEnum::TUTORIAL, CallbackEnum::BATTLE});
124124

125-
// can die in catch tutorial, and the story will continue
126-
env.console.log("run_battle_press_A: Battle Lechonk in catch tutorial. Stop when detect dialog.");
127-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
125+
// can die in catch tutorial, and the story will continue. so need to detect wipeout
126+
env.console.log("Battle Lechonk in catch tutorial. Stop when detect dialog.");
127+
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
128128

129129
env.console.log("clear_dialog: Talk with Nemona to finish catch tutorial. Stop when detect overworld.");
130130
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void checkpoint_13(
9191
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
9292
{CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW, CallbackEnum::BATTLE});
9393

94-
env.console.log("run_battle_press_A: Battle with Nemona at Mesagoza gate. Stop when detect dialog.");
95-
// story continues even if you lose
96-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
94+
env.console.log("Battle with Nemona at Mesagoza gate. Stop when detect dialog.");
95+
// story continues even if you lose, no need to detect wipeout
96+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
9797

9898
env.console.log("clear_dialog: Talk with Nemona within Mesagoza. Stop when detect overworld.");
9999
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60,
@@ -146,15 +146,15 @@ void checkpoint_14(
146146
env.console.log("clear_dialog: Talk with Team Star at the top of the stairs. Stop when detect battle.");
147147
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::PROMPT_DIALOG, CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
148148
// run battle until dialog
149-
env.console.log("run_battle_press_A: Battle with Team Star grunt 1. Stop when detect dialog.");
150-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
149+
env.console.log("Battle with Team Star grunt 1. Stop when detect dialog.");
150+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true); // need to detect wipeouts, since you need to win, and you likely only have 1 pokemon
151151
// clear dialog until battle, with prompt, white button, tutorial, battle
152152
env.console.log("clear_dialog: Talk with Team Star and Nemona. Receive Tera orb. Stop when detect battle.");
153153
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
154154
{CallbackEnum::PROMPT_DIALOG, CallbackEnum::WHITE_A_BUTTON, CallbackEnum::TUTORIAL, CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
155155
// run battle until dialog
156-
env.console.log("run_battle_press_A: Battle with Team Star grunt 2. Stop when detect dialog.");
157-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
156+
env.console.log("Battle with Team Star grunt 2. Stop when detect dialog.");
157+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true); // need to detect wipeouts, since you need to win, and you likely only have 1 pokemon
158158
// clear dialog until overworld
159159
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD});
160160

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ void checkpoint_25(
181181
direction.change_direction(env.program_info(), env.console, context, 1.485);
182182
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10, 128, 20);
183183
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
184-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
184+
env.console.log("Battle Olive Roll NPC 1.");
185+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
185186
mash_button_till_overworld(env.console, context, BUTTON_A);
186187

187188
// section 6
@@ -200,7 +201,8 @@ void checkpoint_25(
200201
direction.change_direction(env.program_info(), env.console, context, 4.275);
201202
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10, 128, 20);
202203
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
203-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
204+
env.console.log("Battle Olive Roll NPC 2.");
205+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
204206
mash_button_till_overworld(env.console, context, BUTTON_A);
205207

206208
// section 10. leave Olive roll

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ void checkpoint_28(
120120
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
121121

122122
// battle Katy
123-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
123+
env.console.log("Battle Grass Gym.");
124+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
124125
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
125126

126127
// leave gym building

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ void checkpoint_30(
225225

226226
}
227227

228-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
228+
env.console.log("Battle Bombirdier Titan phase 1.");
229+
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
229230
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 30, {CallbackEnum::BATTLE});
230231
// round 2 of battle
231-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
232+
env.console.log("Battle Bombirdier Titan phase 2.");
233+
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
232234
// get ride upgrade
233235
mash_button_till_overworld(env.console, context, BUTTON_A);
234236

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void checkpoint_32(
127127

128128
// battle team star grunts
129129
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
130-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
130+
env.console.log("Battle Team star grunt.");
131+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
131132
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD, CallbackEnum::BLACK_DIALOG_BOX});
132133

133134

@@ -253,7 +254,8 @@ void checkpoint_33(
253254
);
254255
}
255256
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
256-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
257+
env.console.log("Battle the Team Star (Dark) boss.");
258+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
257259
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
258260

259261

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void checkpoint_37(
9898
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20);
9999

100100
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
101-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW});
101+
env.console.log("Battle Kofu's assistant.");
102+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
102103
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
103104

104105

@@ -170,7 +171,8 @@ void checkpoint_38(
170171
// talk to reception. Battle Kofu
171172
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
172173
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
173-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
174+
env.console.log("Battle Water Gym.");
175+
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
174176
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
175177

176178
break;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ void checkpoint_39(
200200

201201
// battle the titan phase 1
202202
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::BLACK_DIALOG_BOX});
203-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
203+
env.console.log("Battle Great Tusk/Iron Treads Titan phase 1.");
204+
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
204205

205206
// section 5
206207
realign_player_from_landmark(
@@ -225,7 +226,8 @@ void checkpoint_39(
225226

226227
// battle the titan phase 2
227228
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE});
228-
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
229+
env.console.log("Battle Great Tusk/Iron Treads Titan phase 2.");
230+
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
229231
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
230232

231233
break;

0 commit comments

Comments
 (0)