diff --git a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.cpp b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.cpp index d92dcaa0b..1d09eb068 100644 --- a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.cpp +++ b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.cpp @@ -198,6 +198,29 @@ bool BattleLearnDialogDetector::detect(const ImageViewRGB32& screen){ return false; } +BattleOutOfPpDetector::BattleOutOfPpDetector(Color color) + : m_box(0.692901, 0.758376, 0.275753, 0.085431) + , m_area_ratio_threshold(0.01) +{} +void BattleOutOfPpDetector::make_overlays(VideoOverlaySet& items) const{ + const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX; + items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_box)); +} +bool BattleOutOfPpDetector::detect(const ImageViewRGB32& screen){ + ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX); + const auto region = extract_box_reference(game_screen, m_box); + + // Retain only red pixels from region ( ~ RGB(225, 74, 27) ) + const bool replace_color_within_range = false; + const ImageRGB32 red_region = filter_rgb32_range( + region, + combine_rgb(150, 0, 0), combine_rgb(255, 150, 150), Color(0), replace_color_within_range + ); + const size_t num_red_pixels = image_stats(red_region).count; + const double threshold = region.width() * region.height() * m_area_ratio_threshold; + + return num_red_pixels > threshold; +} diff --git a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h index 8420d1bf7..f1610eedf 100644 --- a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h +++ b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h @@ -118,7 +118,25 @@ class BattleLearnDialogDetector : public StaticScreenDetector{ class BattleLearnDialogWatcher : public DetectorToFinder{ public: BattleLearnDialogWatcher(Color color) - : DetectorToFinder("BattleLearnDialogDetector", std::chrono::milliseconds(250), color) + : DetectorToFinder("BattleLearnDialogWatcher", std::chrono::milliseconds(250), color) + {} +}; + +class BattleOutOfPpDetector : public StaticScreenDetector{ +public: + BattleOutOfPpDetector(Color color); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + ImageFloatBox m_box; + double m_area_ratio_threshold; +}; +class BattleOutOfPpWatcher : public DetectorToFinder{ +public: + BattleOutOfPpWatcher(Color color) + : DetectorToFinder("BattleOutOfPpWatcher", std::chrono::milliseconds(250), color) {} };