Skip to content

Commit 27f5242

Browse files
committed
run_battle_press_A: split into two functions, one for trainers, one for wild battles.
1 parent 65d872c commit 27f5242

13 files changed

+87
-38
lines changed

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ 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,
@@ -63,7 +64,7 @@ void run_battle_press_A(
6364
std::vector<PeriodicInferenceCallback> callbacks;
6465
std::vector<CallbackEnum> enum_all_callbacks;
6566
// mandatory callbacks: Battle, Overworld, Advance Dialog, Swap menu, Move select
66-
// optional callbacks: ADVANCE_DIALOG, DIALOG_ARROW, NEXT_POKEMON
67+
// optional callbacks: DIALOG_ARROW, NEXT_POKEMON
6768

6869
// merge the mandatory and optional callbacks as a set, to avoid duplicates. then convert to vector
6970
std::unordered_set<CallbackEnum> enum_all_callbacks_set{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
@@ -182,6 +183,27 @@ void run_battle_press_A(
182183
}
183184
}
184185

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+
185207
void select_top_move(VideoStream& stream, ProControllerContext& context, size_t consecutive_move_select){
186208
if (consecutive_move_select > 3){
187209
// to handle case where move is disabled/out of PP/taunted
@@ -477,7 +499,7 @@ void overworld_navigation(
477499
return;
478500
}
479501

480-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
502+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
481503
if (auto_heal){
482504
auto_heal_from_menu_or_overworld(info, stream, context, 0, true);
483505
}
@@ -749,7 +771,7 @@ void handle_unexpected_battles(
749771
action(info, stream, context);
750772
return;
751773
}catch (UnexpectedBattleException&){
752-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
774+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
753775
}
754776
}
755777
}
@@ -949,7 +971,7 @@ bool is_ride_active(const ProgramInfo& info, VideoStream& stream, ProControllerC
949971
return is_ride_active;
950972

951973
}catch(UnexpectedBattleException&){
952-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
974+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
953975
}
954976
}
955977

@@ -1078,7 +1100,7 @@ void realign_player_from_landmark(
10781100
return;
10791101

10801102
}catch (UnexpectedBattleException&){
1081-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
1103+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
10821104
}catch (OperationFailedException&){
10831105
// reset to overworld if failed to center on the pokecenter, and re-try
10841106
leave_phone_to_overworld(info, stream, context);
@@ -1160,7 +1182,7 @@ void move_cursor_towards_flypoint_and_go_there(
11601182
return;
11611183

11621184
}catch (UnexpectedBattleException&){
1163-
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
1185+
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
11641186
}catch (OperationFailedException&){
11651187
// reset to overworld if failed to center on the pokecenter, and re-try
11661188
leave_phone_to_overworld(info, stream, context);

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,25 @@ class AutoStory_Segment {
118118
AutoStoryOptions options) const = 0;
119119
};
120120

121-
// spam A button to choose the first move
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.
122123
// throw exception if wipeout or if your lead faints.
123-
void run_battle_press_A(
124+
void run_trainer_battle_press_A(
124125
VideoStream& stream,
125126
ProControllerContext& context,
126127
BattleStopCondition stop_condition,
127-
std::unordered_set<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 = {},
128140
bool detect_wipeout = false
129141
);
130142

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, {CallbackEnum::NEXT_POKEMON});
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); // enemy only has 1 Pokemon, so no need to detect "Next Pokemon" prompt
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); // enemy only has 1 Pokemon, so no need to detect "Next Pokemon" prompt
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::NEXT_POKEMON}, 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::NEXT_POKEMON});
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::NEXT_POKEMON}, 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)