Skip to content

Commit bfa5836

Browse files
committed
BattleMenu->Arrow
1 parent d29f3c9 commit bfa5836

File tree

7 files changed

+129
-112
lines changed

7 files changed

+129
-112
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,8 @@ file(GLOB MAIN_SOURCES
13751375
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
13761376
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp
13771377
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h
1378-
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.cpp
1379-
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h
1378+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp
1379+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h
13801380
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp
13811381
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h
13821382
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ SOURCES += \
674674
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
675675
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
676676
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp \
677-
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.cpp \
677+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp \
678678
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp \
679679
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
680680
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
@@ -1873,7 +1873,7 @@ HEADERS += \
18731873
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
18741874
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
18751875
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h \
1876-
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h \
1876+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h \
18771877
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h \
18781878
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
18791879
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Battle Arrow Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
8+
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
9+
#include "CommonFramework/Globals.h"
10+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
11+
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
12+
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
13+
#include "PokemonLGPE_BattleArrowDetector.h"
14+
15+
//#include <iostream>
16+
//using std::cout;
17+
//using std::endl;
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonLGPE{
22+
23+
const ImageMatch::ExactImageMatcher& BATTLE_ARROW(){
24+
static ImageMatch::ExactImageMatcher matcher(RESOURCE_PATH() + "PokemonLGPE/BattleArrow.png");
25+
return matcher;
26+
}
27+
28+
BattleArrowDetector::BattleArrowDetector(Color color, const ImageFloatBox& box)
29+
: m_color(color)
30+
, m_box(box)
31+
{}
32+
void BattleArrowDetector::make_overlays(VideoOverlaySet& items) const{
33+
items.add(m_color, m_box);
34+
}
35+
bool BattleArrowDetector::detect(const ImageViewRGB32& screen) const{
36+
using namespace Kernels::Waterfill;
37+
38+
ImageViewRGB32 region = extract_box_reference(screen, m_box);
39+
40+
const ImageMatch::ExactImageMatcher& matcher = BATTLE_ARROW();
41+
42+
auto matrix = compress_rgb32_to_binary_range(region, 0xffc0c0c0, 0xffffffff);
43+
auto session = make_WaterfillSession(matrix);
44+
auto iter = session->make_iterator(100);
45+
WaterfillObject object;
46+
47+
//static int c = 0;
48+
while (iter->find_next(object, false)){
49+
double aspect_ratio = object.aspect_ratio();
50+
if (aspect_ratio < 1.0 || aspect_ratio > 1.3){
51+
continue;
52+
}
53+
ImageViewRGB32 cropped = extract_box_reference(region, object);
54+
//cropped.save("test-object-" + std::to_string(c++) + ".png");
55+
double rmsd = matcher.rmsd(cropped);
56+
//cout << rmsd << endl;
57+
if (rmsd < 110){
58+
return true;
59+
}
60+
}
61+
62+
return false;
63+
}
64+
65+
66+
67+
}
68+
}
69+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Battle Arrow Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_BattleArrowDetector_H
8+
#define PokemonAutomation_PokemonLGPE_BattleArrowDetector_H
9+
10+
#include <chrono>
11+
#include <atomic>
12+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13+
#include "Common/Cpp/Color.h"
14+
#include "CommonFramework/ImageTools/ImageBoxes.h"
15+
#include "CommonTools/VisualDetector.h"
16+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
17+
18+
namespace PokemonAutomation{
19+
namespace NintendoSwitch{
20+
namespace PokemonLGPE{
21+
22+
class BattleArrowDetector : public StaticScreenDetector{
23+
public:
24+
/*
25+
|Fight|Pokemon|Bag|Run| for wild battle
26+
|---|Fight|Pokemon|Bag| for trainer battle
27+
(align right)
28+
Don't know what changes for a double battle.
29+
*/
30+
//Arrow bounces back and forth.
31+
BattleArrowDetector(Color color, const ImageFloatBox& box = {0.546, 0.863, 0.045, 0.068}); //Wild battle.
32+
33+
virtual void make_overlays(VideoOverlaySet& items) const override;
34+
virtual bool detect(const ImageViewRGB32& screen) const override;
35+
36+
protected:
37+
Color m_color;
38+
ImageFloatBox m_box;
39+
};
40+
class BattleArrowWatcher : public DetectorToFinder<BattleArrowDetector>{
41+
public:
42+
BattleArrowWatcher(Color color = COLOR_RED)
43+
: DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color)
44+
{}
45+
};
46+
47+
48+
49+
}
50+
}
51+
}
52+
53+
#endif

SerialPrograms/Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

SerialPrograms/Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

SerialPrograms/Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1616
#include "Pokemon/Pokemon_Strings.h"
1717
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
18-
#include "PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h"
18+
#include "PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h"
1919
#include "PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h"
2020
#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h"
2121
#include "PokemonLGPE_LegendaryReset.h"
@@ -87,7 +87,7 @@ bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconConte
8787
shiny_coefficient = error_coefficient;
8888
return true;
8989
});
90-
BattleMenuWatcher battle_started(COLOR_YELLOW);
90+
BattleArrowWatcher battle_started(COLOR_YELLOW);
9191

9292
env.log("Starting battle.");
9393
switch (TARGET) {
@@ -98,7 +98,7 @@ bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconConte
9898
pbf_mash_button(context, BUTTON_A, 15000ms);
9999
break;
100100
case Target::snorlax2:
101-
pbf_mash_button(context, BUTTON_A, 25000ms); //can't test
101+
pbf_mash_button(context, BUTTON_A, 25000ms); //can't test, not really worth it
102102
break;
103103
}
104104
context.wait_for_all_requests();
@@ -120,7 +120,6 @@ bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconConte
120120
env.console
121121
);
122122
}
123-
pbf_wait(context, 1000ms);
124123
context.wait_for_all_requests();
125124
},
126125
{{shiny_detector}}

0 commit comments

Comments
 (0)