From 00eb5b5d246b0c41b32dae5f9b88e4559a254162 Mon Sep 17 00:00:00 2001 From: Mysticial Date: Fri, 22 Sep 2023 15:40:13 -0700 Subject: [PATCH] Enforce herb compatibility. --- .../Options/PokemonSV_SandwichMakerOption.cpp | 91 +++++++++++++++++-- .../Options/PokemonSV_SandwichMakerOption.h | 6 +- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.cpp b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.cpp index 57a88036c..c8c64f137 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.cpp +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.cpp @@ -284,6 +284,9 @@ SandwichRecipe SandwichMakerOption::get_premade_sandwich_recipe(BaseRecipe base, } SandwichMakerOption::~SandwichMakerOption() { + HERBA_TWO.remove_listener(*this); + HERBA_ONE.remove_listener(*this); + TYPE.remove_listener(*this); BASE_RECIPE.remove_listener(*this); } @@ -419,6 +422,7 @@ SandwichMakerOption::SandwichMakerOption(OCR::LanguageOCROption* language_option LockWhileRunning::LOCKED, HerbaSelection::salty_herba_mystica ) + , HERB_INCOMPATIBILITY_WARNING("") , SANDWICH_INGREDIENTS("Custom Sandwich:
Make a sandwich from the selected ingredients.
You must have at least one ingredient and one condiment, and no more than six ingredients and four condiments.") { if (m_language_owner){ @@ -429,36 +433,109 @@ SandwichMakerOption::SandwichMakerOption(OCR::LanguageOCROption* language_option PA_ADD_OPTION(PARADOX); PA_ADD_OPTION(HERBA_ONE); PA_ADD_OPTION(HERBA_TWO); + PA_ADD_OPTION(HERB_INCOMPATIBILITY_WARNING); PA_ADD_OPTION(SANDWICH_INGREDIENTS); + HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN); + SandwichMakerOption::value_changed(); BASE_RECIPE.add_listener(*this); - + TYPE.add_listener(*this); + HERBA_ONE.add_listener(*this); + HERBA_TWO.add_listener(*this); } -void SandwichMakerOption::value_changed() { - if (BASE_RECIPE == BaseRecipe::custom) { +void SandwichMakerOption::value_changed(){ + if (BASE_RECIPE == BaseRecipe::custom){ SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::ENABLED); HERBA_ONE.set_visibility(ConfigOptionState::DISABLED); HERBA_TWO.set_visibility(ConfigOptionState::DISABLED); + HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN); TYPE.set_visibility(ConfigOptionState::DISABLED); //to prevent the options moving around PARADOX.set_visibility(ConfigOptionState::HIDDEN); - } - else if (two_herba_required(BASE_RECIPE)) { //shiny, huge, tiny + }else if (two_herba_required(BASE_RECIPE)){ //shiny, huge, tiny SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::DISABLED); HERBA_ONE.set_visibility(ConfigOptionState::ENABLED); HERBA_TWO.set_visibility(ConfigOptionState::ENABLED); + + std::string herb_error; + do{ + if (BASE_RECIPE != BaseRecipe::shiny){ + break; + } + herb_error = check_herb_compatibility(HERBA_ONE, HERBA_TWO, TYPE); + }while (false); + + if (herb_error.empty()){ + HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN); + }else{ + HERB_INCOMPATIBILITY_WARNING.set_text("" + herb_error + ""); + HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::ENABLED); + } TYPE.set_visibility(ConfigOptionState::ENABLED); PARADOX.set_visibility(ConfigOptionState::HIDDEN); - } - else { //other + }else{ //other SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::DISABLED); HERBA_ONE.set_visibility(ConfigOptionState::DISABLED); HERBA_TWO.set_visibility(ConfigOptionState::DISABLED); TYPE.set_visibility(ConfigOptionState::HIDDEN); + HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN); PARADOX.set_visibility(ConfigOptionState::ENABLED); } } +std::string SandwichMakerOption::check_validity() const{ + if (!two_herba_required(BASE_RECIPE)){ + return ""; + } + if (BASE_RECIPE != BaseRecipe::shiny){ + return ""; + } + return check_herb_compatibility(HERBA_ONE, HERBA_TWO, TYPE); +} + +std::string SandwichMakerOption::check_herb_compatibility(HerbaSelection herb1, HerbaSelection herb2, PokemonType type) const{ + if ((herb1 == HerbaSelection::sweet_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) || + (herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::sweet_herba_mystica) + ){ + return "1x Sweet and 1x Sour herb are incompatible for all types."; + } + if (herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica){ + return "2x Sour herbs are incompatible for all types."; + } + if (herb1 == HerbaSelection::sweet_herba_mystica && herb2 == HerbaSelection::sweet_herba_mystica && + type == PokemonType::bug + ){ + return "2x Sweet herbs are incompatible with bug type."; + } + if ((herb1 == HerbaSelection::salty_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) || + (herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::salty_herba_mystica) + ){ + static const std::set TYPES{ + PokemonType::flying, + PokemonType::ground, + PokemonType::rock, + PokemonType::ice, + }; + if (TYPES.contains(type)){ + return "1x Salty and 1x Sour herb are incompatible with flying, ground, rock, and ice."; + } + } + if ((herb1 == HerbaSelection::bitter_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) || + (herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::bitter_herba_mystica) + ){ + static const std::set TYPES{ + PokemonType::fighting, + PokemonType::bug, + PokemonType::fairy, + }; + if (TYPES.contains(type)){ + return "1x Sour and 1x Bitter herb are incompatible with fighting, bug, and fairy."; + } + } + + return ""; +} + } diff --git a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.h b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.h index bbd0027ae..739109937 100644 --- a/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.h +++ b/SerialPrograms/Source/PokemonSV/Options/PokemonSV_SandwichMakerOption.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_PokemonSV_SandwichMakerOption_H #define PokemonAutomation_PokemonSV_SandwichMakerOption_H +#include "Common/Cpp/Options/StaticTextOption.h" #include "Common/Cpp/Options/GroupOption.h" #include "Common/Cpp/Options/EnumDropdownOption.h" //#include "PokemonSV/Resources/PokemonSV_Ingredients.h" @@ -245,12 +246,15 @@ class SandwichMakerOption : public GroupOption, private ConfigOption::Listener { EnumDropdownOption PARADOX; EnumDropdownOption HERBA_ONE; EnumDropdownOption HERBA_TWO; + StaticTextOption HERB_INCOMPATIBILITY_WARNING; SandwichIngredientsTable SANDWICH_INGREDIENTS; private: SandwichMakerOption(OCR::LanguageOCROption* language_option); - virtual void value_changed(); + virtual void value_changed() override; + virtual std::string check_validity() const override; + std::string check_herb_compatibility(HerbaSelection herb1, HerbaSelection herb2, PokemonType type) const; }; }