Skip to content

Commit b9ca8fb

Browse files
jw098Developer-Butters
authored andcommitted
Material Farmer: fix ability to monitor for battles while unlocking minimap to change direction (PokemonAutomation#1331)
1 parent af8cbc2 commit b9ca8fb

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_MaterialFarmerTools.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,33 @@ void do_action_and_run_from_battle(
474474
VideoStream& stream,
475475
ProControllerContext& context)
476476
>&& action
477+
){
478+
size_t max_attempts = 5;
479+
for (size_t i = 0; i < max_attempts; i++){
480+
try{
481+
do_action_and_monitor_for_battles(info, stream, context,
482+
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
483+
action(info, stream, context);
484+
}
485+
);
486+
break;
487+
}catch (UnexpectedBattleException&){
488+
stream.log("Detected battle. Now running away.", COLOR_PURPLE);
489+
run_from_battle(stream, context);
490+
}
491+
}
492+
493+
}
494+
495+
void do_action_and_run_from_battle2(
496+
const ProgramInfo& info,
497+
VideoStream& stream,
498+
ProControllerContext& context,
499+
std::function<
500+
void(const ProgramInfo& info,
501+
VideoStream& stream,
502+
ProControllerContext& context)
503+
>&& action
477504
){
478505
size_t max_attempts = 5;
479506
for (size_t i = 0; i < max_attempts; i++){

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_MaterialFarmerTools.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ void do_action_and_run_from_battle(
123123
>&& action
124124
);
125125

126+
// same as do_action_and_run_from_battle, but will
127+
// stop the action once the overworld disappears
128+
void do_action_and_run_from_battle2(
129+
const ProgramInfo& info,
130+
VideoStream& stream,
131+
ProControllerContext& context,
132+
std::function<
133+
void(const ProgramInfo& info,
134+
VideoStream& stream,
135+
ProControllerContext& context)
136+
>&& action
137+
);
138+
126139
void move_to_start_position_for_letsgo0(VideoStream& stream, ProControllerContext& context);
127140

128141
void move_to_start_position_for_letsgo1(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context);

0 commit comments

Comments
 (0)