Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ AdvAbility ability_from_pid(uint32_t pid){
return AdvAbility (pid % 2);
}

AdvAbility ability_slot_from_ability(
const std::string& observed_ability,
const std::vector<std::string>& species_abilities
){
if (observed_ability.empty()
|| species_abilities.size() < 2
|| species_abilities[0] == species_abilities[1]
){
return AdvAbility::Any;
}
if (observed_ability == species_abilities[0]){
return AdvAbility::Zero;
}
if (observed_ability == species_abilities[1]){
return AdvAbility::One;
}
return AdvAbility::Any;
}

uint8_t unown_form_from_pid(uint32_t pid){
return (((pid & 0x3000000) >> 18) | ((pid & 0x30000) >> 12) | ((pid & 0x300) >> 6) | (pid & 0x3)) % 0x1c;
// return (
Expand Down
7 changes: 7 additions & 0 deletions SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ std::string gender_to_string(const AdvGender& gender);

AdvGender gender_from_gender_value(uint8_t gender_value, int16_t threshold);

// Returns the ability slot of an observed ability, based on the species
// Returns AdvAbility::Any if the slot can't be determined
AdvAbility ability_slot_from_ability(
const std::string& observed_ability,
const std::vector<std::string>& species_abilities
);

// returns search filters that correspond with observed stats
AdvRngFilters observation_to_filters(const AdvObservedPokemon& observation, const BaseStats& basestats, AdvRngMethod method = AdvRngMethod::Method1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ EggRng::EggRng()
})
{
PA_ADD_OPTION(m_calibration_displays);
PA_ADD_OPTION(RNG_TARGET);
PA_ADD_STATIC(RNG_TARGET);
PA_ADD_OPTION(RNG_FILTERS);
PA_ADD_OPTION(HELD_CALIBRATION);
PA_ADD_OPTION(PICKUP_CALIBRATION);
Expand Down Expand Up @@ -356,7 +356,6 @@ bool EggRng::reset_and_check_seed(
const bool& previously_hit_held_frame,
Milliseconds& launch_delay,
const std::set<std::string>& SPECIES_LIST,
const RngStatsDatabase& STATS_DATA,
bool pickup_frame
){
RngCalibrations& calibrations = hist.calibrations;
Expand Down Expand Up @@ -443,13 +442,13 @@ bool EggRng::reset_and_check_seed(

// Step 3: Catch a wild encounter and use it to determine the current seed
AdvObservedPokemon pokemon;
RngStats species_stats;
const RngStats* species_stats = nullptr;
AdvRngFilters filters;
uint64_t wild_advances_estimate;
WildCatchOutcome catch_outcome = catch_wild_for_seed_id(
env, context, stats.errors, NOTIFICATION_ERROR_RECOVERABLE, LANGUAGE,
timestamp, advances, pickup_frame ? 2 : 0,
balls_left, SPECIES_LIST, STATS_DATA,
balls_left, SPECIES_LIST,
pokemon, species_stats, filters, wild_advances_estimate,
[&](const AdvRngFilters& f){ RNG_FILTERS.set(f); }
);
Expand All @@ -464,12 +463,12 @@ bool EggRng::reset_and_check_seed(
// For the wild step we only need to confirm the correct seed was hit; advance timing is
// irrelevant and wild_history is largely unused, so result_determined just checks same_seeds.
std::vector<AdvRngState> search_hits = refine_calibration_with_rare_candy(
env, context, LANGUAGE, pokemon, filters, species_stats.base_stats,
env, context, LANGUAGE, pokemon, filters, species_stats->base_stats,
wild_uncertain_history, wild_history, calibrations,
MAX_HISTORY_LENGTH, candies_left, AdvRngMethod::Any, false,
stats.errors, NOTIFICATION_ERROR_RECOVERABLE,
[&](AdvRngFilters& f){
return get_wild_search_results(env.console, wild_searcher, f, SEED_VALUES, wild_advances_estimate, WILD_ADVANCES_RADIUS, species_stats.gender_threshold);
return get_wild_search_results(env.console, wild_searcher, f, SEED_VALUES, wild_advances_estimate, WILD_ADVANCES_RADIUS, species_stats->gender_threshold);
},
[&](const std::vector<AdvRngState>& h){
if (pickup_frame){ PICKUP_CALIBRATION.set_hits(h); }else{ HELD_CALIBRATION.set_hits(h); }
Expand Down Expand Up @@ -727,21 +726,15 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&

home_black_border_check(env.console, context);

// prepare database of base stats and gender thresholds
RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json");

RngStats EGG_STATS;
try{
EGG_STATS = STATS_DATA.get_throw(EGG_SPECIES.slug());
}catch (const InternalProgramError& err){
env.log(err.message());
env.log(EGG_SPECIES.slug());
const RngStats* egg_stats = RngStatsDatabase::instance().get_nothrow(EGG_SPECIES.slug());
if (egg_stats == nullptr){
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
err.message(),
"Egg species not found in base stats database: " + EGG_SPECIES.slug(),
env.console
);
);
}
const RngStats& EGG_STATS = *egg_stats;

// get the relevant encounter slots
EncountersDatabase encounters_data(GAME_VERSION == GameVersion::firered ? "PokemonFRLG/EncounterSlotsFR.json" : "PokemonFRLG/EncounterSlotsLG.json");
Expand Down Expand Up @@ -801,8 +794,8 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
AdvIVs PARENT_B = { rowB.hp, rowB.atk, rowB.def, rowB.spa, rowB.spd, rowB.spe };

AdvPokemonResult target_result = egg_searcher.generate_pokemon(PARENT_A, PARENT_B);
RNG_TARGET.set_target(target_result, EGG_STATS.gender_threshold);
log_target_pokemon(env.console, target_result, true);
RNG_TARGET.set_target(target_result, EGG_SPECIES.slug(), 5);
log_target_pokemon(env.console, target_result, EGG_SPECIES.slug(), 5, true);

Milliseconds launch_delay = INITIAL_LAUNCH_DELAY;

Expand Down Expand Up @@ -935,7 +928,7 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
temp_balls_left, temp_candies_left, failed_searches,
times_not_held, shiny_found, previously_hit_held_frame,
launch_delay,
SPECIES_LIST, STATS_DATA,
SPECIES_LIST,
false
);

Expand Down Expand Up @@ -980,7 +973,7 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
temp_balls_left, temp_candies_left, failed_searches,
times_not_held, shiny_found, previously_hit_held_frame,
launch_delay,
SPECIES_LIST, STATS_DATA,
SPECIES_LIST,
true
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener
const bool& previously_hit_held_frame,
Milliseconds& launch_delay,
const std::set<std::string>& SPECIES_LIST,
const RngStatsDatabase& STATS_DATA,
bool pickup_frame
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Pokemon/Pokemon_Strings.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h"
#include "PokemonFRLG_RngNavigation.h"
#include "PokemonFRLG_RngStatsDatabase.h"
#include "PokemonFRLG_HardReset.h"
#include "PokemonFRLG_RngCalibration.h"
#include "PokemonFRLG_RngLoopRoutines.h"
Expand Down Expand Up @@ -194,7 +195,7 @@ GiftRng::GiftRng()
})
{
PA_ADD_OPTION(m_calibration_displays);
PA_ADD_OPTION(RNG_TARGET);
PA_ADD_STATIC(RNG_TARGET);
PA_ADD_OPTION(RNG_FILTERS);
PA_ADD_OPTION(RNG_CALIBRATION);
PA_ADD_OPTION(m_game_info);
Expand Down Expand Up @@ -253,86 +254,73 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode
+ ", column: " + seed_match.column_name);

BaseStats BASE_STATS;
int16_t GENDER_THRESHOLD = -1;
std::string SPECIES;
uint8_t LEVEL = 0;
switch (TARGET){
case PokemonFRLG_RngTarget::magikarp:
BASE_STATS = { 20, 10, 55, 15, 20, 80 };
GENDER_THRESHOLD = 126;
SPECIES = "magikarp";
LEVEL = 5;
break;
case PokemonFRLG_RngTarget::hitmonchan:
BASE_STATS = { 50, 105, 79, 35, 110, 76 };
GENDER_THRESHOLD = -1;
SPECIES = "hitmonchan";
LEVEL = 25;
break;
case PokemonFRLG_RngTarget::hitmonlee:
BASE_STATS = { 50, 120, 53, 35, 110, 87 };
GENDER_THRESHOLD = -1;
SPECIES = "hitmonlee";
LEVEL = 25;
break;
case PokemonFRLG_RngTarget::eevee:
BASE_STATS = { 55, 55, 50, 45, 65, 55 };
GENDER_THRESHOLD = 30;
SPECIES = "eevee";
LEVEL = 25;
break;
case PokemonFRLG_RngTarget::lapras:
BASE_STATS = { 130, 85, 80, 85, 95, 60 };
GENDER_THRESHOLD = 126;
SPECIES = "lapras";
LEVEL = 25;
break;
case PokemonFRLG_RngTarget::omanyte:
BASE_STATS = { 35, 40, 100, 90, 55, 35 };
GENDER_THRESHOLD = 30;
SPECIES = "omanyte";
LEVEL = 5;
break;
case PokemonFRLG_RngTarget::kabuto:
BASE_STATS = { 30, 80, 90, 55, 45, 55 };
GENDER_THRESHOLD = 30;
SPECIES = "kabuto";
LEVEL = 5;
break;
case PokemonFRLG_RngTarget::aerodactyl:
BASE_STATS = { 80, 105, 65, 60, 75, 130 };
GENDER_THRESHOLD = 30;
SPECIES = "aerodactyl";
LEVEL = 5;
break;
case PokemonFRLG_RngTarget::gamecornerabra:
BASE_STATS = { 25, 20, 15, 105, 55, 90 };
GENDER_THRESHOLD = 63;
SPECIES = "abra";
break;
case PokemonFRLG_RngTarget::gamecornerclefairy:
BASE_STATS = { 70, 45, 48, 60, 65, 35 };
GENDER_THRESHOLD = 190;
SPECIES = "clefairy";
break;
case PokemonFRLG_RngTarget::gamecornerdratinifr:
case PokemonFRLG_RngTarget::gamecornerdratinilg:
BASE_STATS = { 41, 64, 45, 50, 50, 50 };
GENDER_THRESHOLD = 126;
SPECIES = "dratini";
break;
case PokemonFRLG_RngTarget::gamecornerscyther:
BASE_STATS = { 70, 110, 80, 55, 80, 105 };
GENDER_THRESHOLD = 126;
SPECIES = "scyther";
LEVEL = 25;
break;
case PokemonFRLG_RngTarget::gamecornerpinsir:
BASE_STATS = { 65, 125, 100, 55, 70, 85 };
GENDER_THRESHOLD = 126;
SPECIES = "pinsir";
LEVEL = 18;
break;
case PokemonFRLG_RngTarget::gamecornerporygon:
BASE_STATS = { 65, 60, 70, 85, 75, 40 };
GENDER_THRESHOLD = -1;
SPECIES = "porygon";
break;
case PokemonFRLG_RngTarget::togepi:
case PokemonFRLG_RngTarget::togepifast:
BASE_STATS = { 35, 20, 65, 40, 65, 20 };
GENDER_THRESHOLD = 30;
SPECIES = "togepi";
LEVEL = 5;
break;
default:
break;
}
const RngStats& STATS = RngStatsDatabase::instance().get_throw(SPECIES);
const int16_t GENDER_THRESHOLD = STATS.gender_threshold;
const BaseStats& BASE_STATS = STATS.base_stats;

static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate

Expand All @@ -355,8 +343,8 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&

AdvRngSearcher searcher(TARGET_SEED, ADVANCES, AdvRngMethod::Method1);
AdvPokemonResult target_result = searcher.generate_pokemon();
RNG_TARGET.set_target(target_result, GENDER_THRESHOLD);
log_target_pokemon(env.console, target_result);
RNG_TARGET.set_target(target_result, SPECIES, LEVEL);
log_target_pokemon(env.console, target_result, SPECIES, LEVEL);

RngCalibrations calibrations = {
RNG_CALIBRATION.seed_calibration / FRLG_FRAME_DURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <algorithm>
#include <set>
#include "PokemonFRLG_BlindNavigation.h"
#include "PokemonFRLG_RngStatsDatabase.h"
#include "PokemonFRLG_RngCalibration.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -95,9 +96,22 @@ void apply_seed_bump(RngCalibrations& calibrations, const RngUncertainHistory& u
calibrations.seed_offset += seed_bump;
}

void log_target_pokemon(ConsoleHandle& console, const AdvPokemonResult& result, bool normal_method_note){
void log_target_pokemon(
ConsoleHandle& console,
const AdvPokemonResult& result,
const std::string& species,
uint8_t level,
bool normal_method_note
){
const RngStats* stats = RngStatsDatabase::instance().get_nothrow(species);
console.log("Target Species: " + species);
if (level > 0){
console.log("Target Level: " + std::to_string(level));
}
console.log("Target PID: " + to_hex_string(result.pid));
console.log("Target Gender: " + gender_name(stats, result.gender));
console.log("Target Nature: " + nature_to_string(result.nature));
console.log("Target Ability: " + ability_name(stats, result.ability));
console.log(normal_method_note ? "Target IVs (assuming Normal method):" : "Target IVs:");
console.log(" HP: " + std::to_string(result.ivs.hp));
console.log(" Atk: " + std::to_string(result.ivs.attack));
Expand All @@ -106,6 +120,11 @@ void log_target_pokemon(ConsoleHandle& console, const AdvPokemonResult& result,
console.log(" SpD: " + std::to_string(result.ivs.spdef));
console.log(" Spe: " + std::to_string(result.ivs.speed));
}
void log_target_pokemon(ConsoleHandle& console, const AdvWildPokemonResult& result){
console.log("Target Encounter Slot: " + std::to_string(result.slot));
AdvPokemonResult pokemon = { result.pid, result.gender, result.nature, result.ability, result.ivs };
log_target_pokemon(console, pokemon, result.species, result.level);
}

void log_calibrations(ConsoleHandle& console, const RngCalibrations& calibrations, bool initial){
std::string prefix = initial ? "Initial " : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ void update_failed_searches(uint16_t& failed_searches, const std::vector<HitType
}
}

// log the PID, nature, and IVs of a target pokemon result
void log_target_pokemon(ConsoleHandle& console, const AdvPokemonResult& result, bool normal_method_note = false);
// log the species, level, PID, gender, nature, ability, and IVs of a target pokemon result
// a level of 0 is not logged
void log_target_pokemon(
ConsoleHandle& console,
const AdvPokemonResult& result,
const std::string& species,
uint8_t level,
bool normal_method_note = false
);
// same as above, plus the encounter slot
void log_target_pokemon(ConsoleHandle& console, const AdvWildPokemonResult& result);

// log the three calibration offsets (seed/CSF/in-game), in frames
void log_calibrations(ConsoleHandle& console, const RngCalibrations& calibrations, bool initial = false);
Expand Down
Loading
Loading