|
| 1 | +/* Collected Pokemon Info |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "Common/Cpp/Exceptions.h" |
| 8 | +#include "Pokemon/Pokemon_Strings.h" |
| 9 | +#include "Pokemon/Resources/Pokemon_PokemonNames.h" |
| 10 | +#include "Pokemon/Resources/Pokemon_PokemonSlugs.h" |
| 11 | +#include "Pokemon_CollectedPokemonInfo.h" |
| 12 | + |
| 13 | +namespace PokemonAutomation{ |
| 14 | +namespace Pokemon{ |
| 15 | + |
| 16 | + |
| 17 | +bool operator==(const CollectedPokemonInfo& lhs, const CollectedPokemonInfo& rhs){ |
| 18 | + // NOTE edit when adding new struct members |
| 19 | + return lhs.national_dex_number == rhs.national_dex_number && |
| 20 | + lhs.shiny == rhs.shiny && |
| 21 | + lhs.gmax == rhs.gmax && |
| 22 | + lhs.alpha == rhs.alpha && |
| 23 | + lhs.ball_slug == rhs.ball_slug && |
| 24 | + lhs.gender == rhs.gender && |
| 25 | + lhs.ot_id == rhs.ot_id; |
| 26 | +} |
| 27 | + |
| 28 | +// Sort two pokemon slot. "Smaller" pokemon is placed closer to front. |
| 29 | +// If a slot is empty, it is always larger than non-empty slot so all the empty slots are at end after sorting. |
| 30 | +// For two pokemon, check each preference rule. If we cannot determine the order based on the first rule, go |
| 31 | +// to the second rule, and so on. |
| 32 | +// Available rules: |
| 33 | +// - National dex number: smaller ID should be at front. |
| 34 | +// - Shiny: shiny pokemon should be at front. |
| 35 | +// - Gigantamax: Gigantamax pokemon should be at front. |
| 36 | +// - Alpha: Alpha pokemon should be at front. |
| 37 | +// - Ball slug: pokemon with a ball slug that's smaller in the alphabetical order should be at front. |
| 38 | +// - Gender: Male should be at front, then comes female, and genderless is last |
| 39 | +// Each rule type also has a "reverse" which if true, reverses above ordering for that rule type. |
| 40 | +// If user does not give a preference ruleset, sort by national dex number. |
| 41 | +bool operator<(const std::optional<CollectedPokemonInfo>& lhs, const std::optional<CollectedPokemonInfo>& rhs){ |
| 42 | + if (!lhs.has_value()){ // lhs is empty |
| 43 | + return false; |
| 44 | + } |
| 45 | + if (!rhs.has_value()){ // lhs not empty but rhs is empty |
| 46 | + return true; |
| 47 | + } |
| 48 | + // both sides are not empty: |
| 49 | + for (const SortingRule& preference : *lhs->preferences){ |
| 50 | + switch(preference.sort_type){ |
| 51 | + // NOTE edit when adding new struct members |
| 52 | + case SortingRuleType::NationalDexNo: |
| 53 | + if (lhs->national_dex_number != rhs->national_dex_number){ |
| 54 | + // we use (boolean != reverse) to apply the reverse effect |
| 55 | + return (lhs->national_dex_number < rhs->national_dex_number) != preference.reverse; |
| 56 | + } |
| 57 | + break; |
| 58 | + case SortingRuleType::Shiny: |
| 59 | + if (lhs->shiny != rhs->shiny){ |
| 60 | + return lhs->shiny != preference.reverse; |
| 61 | + } |
| 62 | + break; |
| 63 | + case SortingRuleType::Gigantamax: |
| 64 | + if (lhs->gmax != rhs->gmax){ |
| 65 | + return lhs->gmax != preference.reverse; |
| 66 | + } |
| 67 | + break; |
| 68 | + case SortingRuleType::Alpha: |
| 69 | + if (lhs->alpha != rhs->alpha){ |
| 70 | + return lhs->gmax != preference.reverse; |
| 71 | + } |
| 72 | + break; |
| 73 | + case SortingRuleType::Ball_Slug: |
| 74 | + if (lhs->ball_slug != rhs->ball_slug){ |
| 75 | + return (lhs->ball_slug < rhs->ball_slug) != preference.reverse; |
| 76 | + } |
| 77 | + break; |
| 78 | + case SortingRuleType::Gender: |
| 79 | + if (lhs->gender != rhs->gender){ |
| 80 | + return (lhs->gender < rhs->gender) != preference.reverse; |
| 81 | + } |
| 82 | + break; |
| 83 | + default: |
| 84 | + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "unknown SortingRuleType"); |
| 85 | + } // end switch |
| 86 | + } // end for preference |
| 87 | + |
| 88 | + // Default to sort by national dex number |
| 89 | + return lhs->national_dex_number < rhs->national_dex_number; |
| 90 | +} |
| 91 | + |
| 92 | +std::ostream& operator<<(std::ostream& os, const std::optional<CollectedPokemonInfo>& pokemon) |
| 93 | +{ |
| 94 | + if (pokemon.has_value()){ |
| 95 | + // NOTE edit when adding new struct members |
| 96 | + os << "("; |
| 97 | + os << "national_dex_number:" << pokemon->national_dex_number << " "; |
| 98 | + os << "shiny:" << (pokemon->shiny ? "true" : "false") << " "; |
| 99 | + os << "gmax:" << (pokemon->gmax ? "true" : "false") << " "; |
| 100 | + os << "alpha:" << (pokemon->alpha ? "true" : "false") << " "; |
| 101 | + os << "ball_slug:" << pokemon->ball_slug << " "; |
| 102 | + os << "gender:" << gender_to_string(pokemon->gender) << " "; |
| 103 | + os << "ot_id:" << pokemon->ot_id << " "; |
| 104 | + os << ")"; |
| 105 | + }else{ |
| 106 | + os << "(empty)"; |
| 107 | + } |
| 108 | + return os; |
| 109 | +} |
| 110 | + |
| 111 | +std::string create_overlay_info(const CollectedPokemonInfo& pokemon){ |
| 112 | + const std::string& species_slug = NATIONAL_DEX_SLUGS()[pokemon.national_dex_number-1]; |
| 113 | + const std::string& display_name = get_pokemon_name(species_slug).display_name(); |
| 114 | + std::string overlay_log = display_name; |
| 115 | + if(pokemon.gender == StatsHuntGenderFilter::Male){ |
| 116 | + overlay_log += " " + UNICODE_MALE; |
| 117 | + } else if (pokemon.gender == StatsHuntGenderFilter::Female){ |
| 118 | + overlay_log += " " + UNICODE_FEMALE; |
| 119 | + } |
| 120 | + if (pokemon.shiny){ |
| 121 | + overlay_log += " *"; |
| 122 | + } |
| 123 | + if (pokemon.gmax){ |
| 124 | + overlay_log += " G"; |
| 125 | + } |
| 126 | + if (pokemon.alpha){ |
| 127 | + overlay_log += " " + UNICODE_ALPHA; |
| 128 | + } |
| 129 | + return overlay_log; |
| 130 | +} |
| 131 | + |
| 132 | + |
| 133 | +} |
| 134 | +} |
0 commit comments