diff --git a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp index 6f737aa97f..0ac19fdbfb 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp @@ -195,6 +195,42 @@ int8_t ItemPrinterMaterialDetector::find_happiny_dust_row_index( } + +int16_t ItemPrinterMaterialDetector::find_highest_quantity_of_value_68(VideoStream& stream, ProControllerContext& context) const{ + int16_t highest_quantity_of_value_68 = 0; + bool seen_material_value_68 = false; + for (size_t c = 0; c < 30; c++){ + context.wait_for_all_requests(); + VideoSnapshot snapshot = stream.video().snapshot(); + + std::vector value_68_row_indexes = find_material_value_row_index(stream, context, 68); + if (!value_68_row_indexes.empty()){ + seen_material_value_68 = true; + } + + for (int8_t row_index : value_68_row_indexes){ + int16_t quantity = detect_material_quantity(stream, snapshot, context, row_index); + if (quantity > highest_quantity_of_value_68){ + highest_quantity_of_value_68 = quantity; + } + } + + // keep searching for highest quantity of value 68. + pbf_press_dpad(context, DPAD_RIGHT, 20, 30); + } + + if (!seen_material_value_68){ + OperationFailedException::fire( + ErrorReport::SEND_ERROR_REPORT, + "find_highest_quantity_of_value_68: Failed to find any material with value of 68, after multiple attempts.", + stream + ); + } + + return highest_quantity_of_value_68; + +} + std::string ItemPrinterMaterialDetector::detect_material_name( VideoStream& stream, const ImageViewRGB32& screen, diff --git a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.h b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.h index a6d1e14f3a..5bbf093d9d 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.h +++ b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.h @@ -52,6 +52,9 @@ class ItemPrinterMaterialDetector{ VideoStream& stream, ProControllerContext& context ) const; + // find the quantity of all materials with a value of 68. return the highest quantity. + int16_t find_highest_quantity_of_value_68(VideoStream& stream, ProControllerContext& context) const; + std::vector find_material_value_row_index( VideoStream& stream, ProControllerContext& context, diff --git a/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.cpp b/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.cpp index 143372d527..c944e551c5 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.cpp @@ -117,11 +117,11 @@ ItemPrinterRNG::ItemPrinterRNG() , MODE( "Item Printer mode:
", { - {ItemPrinterMode::STANDARD_MODE, "standard", "Standard Mode: Manually select exactly what is being printed for each print job."}, {ItemPrinterMode::AUTO_MODE, "auto", "Auto Mode: Select your desired item and its quantity, and items will be automatically printed."}, + {ItemPrinterMode::STANDARD_MODE, "standard", "Standard Mode: Manually select exactly what is being printed for each print job."}, }, LockMode::LOCK_WHILE_RUNNING, - ItemPrinterMode::STANDARD_MODE + ItemPrinterMode::AUTO_MODE ) , DESIRED_ITEM_TABLE( "Item Table:
" @@ -191,6 +191,15 @@ ItemPrinterRNG::ItemPrinterRNG() LockMode::UNLOCK_WHILE_RUNNING, true ) + , AVOID_STRING_OCR( + "Avoid using OCR on strings:
" + "Only use this if you're having issues (particularly with Asian languages). " + "This will detect all materials with a value of 68%, and the highest quantity of this is assumed to be your Happiny Dust quantity. " + "i.e. This only detects numbers, therefore sidestepping the issue of poor OCR with Asian languages. " + "If you enable this, I recommend ensuring that your quantity of Happiny Dust is greater than the other materials with a value of 68% (Beldum Claw, Ditto Goo, Magby Hair).", + LockMode::UNLOCK_WHILE_RUNNING, + false + ) , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) , NOTIFICATIONS({ &NOTIFICATION_STATUS_UPDATE, @@ -214,6 +223,7 @@ ItemPrinterRNG::ItemPrinterRNG() PA_ADD_OPTION(MATERIAL_FARMER_FIXED_NUM_JOBS); PA_ADD_OPTION(MIN_HAPPINY_DUST); PA_ADD_OPTION(MATERIAL_FARMER_OPTIONS); + PA_ADD_OPTION(AVOID_STRING_OCR); if (PreloadSettings::instance().DEVELOPER_MODE){ PA_ADD_OPTION(ENABLE_SEED_CALC); } @@ -988,19 +998,25 @@ uint32_t ItemPrinterRNG::check_num_happiny_dust( case 3:{ env.log("Detected material selection."); ItemPrinterMaterialDetector detector(COLOR_RED, LANGUAGE); + if (AVOID_STRING_OCR){ + uint32_t highest_quantity_of_value_68 = detector.find_highest_quantity_of_value_68(env.console, context); + return highest_quantity_of_value_68; + + }else{ + int8_t happiny_dust_row_num = detector.find_happiny_dust_row_index( + env.console, context + ); + + context.wait_for_all_requests(); + VideoSnapshot snapshot = env.console.video().snapshot(); + num_happiny_dust = detector.detect_material_quantity( + env.console, snapshot, context, + happiny_dust_row_num + ); + pbf_mash_button(context, BUTTON_B, 100); + return num_happiny_dust; + } - int8_t happiny_dust_row_num = detector.find_happiny_dust_row_index( - env.console, context - ); - - context.wait_for_all_requests(); - VideoSnapshot snapshot = env.console.video().snapshot(); - num_happiny_dust = detector.detect_material_quantity( - env.console, snapshot, context, - happiny_dust_row_num - ); - pbf_mash_button(context, BUTTON_B, 100); - return num_happiny_dust; } default: stats.errors++; diff --git a/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.h b/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.h index 3b68b2fc79..1c6f838c39 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.h +++ b/SerialPrograms/Source/PokemonSV/Programs/ItemPrinter/PokemonSV_ItemPrinterRNG.h @@ -137,6 +137,8 @@ class ItemPrinterRNG : public SingleSwitchProgramInstance, public ConfigOption:: BooleanCheckBoxOption ENABLE_SEED_CALC; + BooleanCheckBoxOption AVOID_STRING_OCR; + EventNotificationOption NOTIFICATION_STATUS_UPDATE; EventNotificationsOption NOTIFICATIONS; };