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
24 changes: 12 additions & 12 deletions SerialPrograms/Source/Pokemon/Pokemon_AdvRng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace PokemonAutomation{
namespace Pokemon{

void level_up_observed_pokemon(AdvObservedPokemon& pokemon, StatReads& newstats, EVs& evyield){
void level_up_observed_pokemon(AdvObservedPokemon& pokemon, const StatReads& newstats, const EVs& evyield){
uint8_t newlevel = pokemon.level.back() + 1;
pokemon.level.emplace_back(newlevel);

Expand Down Expand Up @@ -69,7 +69,7 @@ uint8_t gender_value_from_pid(uint32_t& pid){
return pid & 0xff;
}

AdvGender gender_from_gender_value(uint8_t gender_value, uint8_t threshold){
AdvGender gender_from_gender_value(uint8_t gender_value, int16_t threshold){
return (gender_value <= threshold) ? AdvGender::Female : AdvGender::Male;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ AdvShinyType shiny_type_from_pid(uint32_t pid, uint16_t tid_xor_sid){
}


bool check_for_match(AdvPokemonResult res, AdvRngFilters target, uint16_t tid_xor_sid, uint8_t gender_threshold){
bool check_for_match(AdvPokemonResult res, AdvRngFilters target, int16_t gender_threshold, uint16_t tid_xor_sid){
return (target.nature == AdvNature::Any || res.nature == target.nature)
&& (target.ability == AdvAbility::Any || res.ability == target.ability)
&& (target.gender == AdvGender::Any || gender_from_gender_value(res.gender, gender_threshold) == target.gender)
Expand Down Expand Up @@ -192,8 +192,8 @@ void AdvRngSearcher::search_advance_range(
AdvRngFilters& target,
uint64_t min_advances,
uint64_t max_advances,
uint16_t tid_xor_sid,
uint8_t gender_threshold
int16_t gender_threshold,
uint16_t tid_xor_sid
){
for (uint8_t m=0; m<3; m++){
set_state_advances(min_advances);
Expand All @@ -220,7 +220,7 @@ void AdvRngSearcher::search_advance_range(

for (uint64_t a=min_advances; a<max_advances; a++){
AdvPokemonResult res = pokemon_from_state(state);
bool match = check_for_match(res, target, tid_xor_sid, gender_threshold);
bool match = check_for_match(res, target, gender_threshold, tid_xor_sid);
if (match){
hits[state] = res;
}
Expand All @@ -234,27 +234,27 @@ std::map<AdvRngState, AdvPokemonResult> AdvRngSearcher::search(
const std::vector<uint16_t>& seeds,
uint64_t min_advances,
uint64_t max_advances,
uint16_t tid_xor_sid,
uint8_t gender_threshold
int16_t gender_threshold,
uint16_t tid_xor_sid
){
std::map<AdvRngState, AdvPokemonResult> hits;
for (uint16_t seed : seeds){
set_seed(seed);
search_advance_range(hits, target, min_advances, max_advances, tid_xor_sid, gender_threshold);
search_advance_range(hits, target, min_advances, max_advances, gender_threshold, tid_xor_sid);
}
return hits;
}

void AdvRngSearcher::refine_search(
std::map<AdvRngState, AdvPokemonResult>& map,
AdvRngFilters& target,
uint16_t tid_xor_sid,
uint8_t gender_threshold
int16_t gender_threshold,
uint16_t tid_xor_sid
){
for (auto iter = map.begin(); iter != map.end(); ){
state = iter->first;
AdvPokemonResult res = pokemon_from_state(state);
if (!check_for_match(res, target, tid_xor_sid, gender_threshold)){
if (!check_for_match(res, target, gender_threshold, tid_xor_sid)){
iter = map.erase(iter);
}else{
iter++;
Expand Down
17 changes: 10 additions & 7 deletions SerialPrograms/Source/Pokemon/Pokemon_AdvRng.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ struct AdvRngFilters{
// updates the AdvObservedPokemon with info from leveling up
// assumes levels are earned sequentially
// input EVs are the ones earned since the last level up, not the total
void level_up_observed_pokemon(AdvObservedPokemon& pokemon, StatReads& newstats, EVs& evyield);
void level_up_observed_pokemon(AdvObservedPokemon& pokemon, const StatReads& newstats, const EVs& evyield);

// returns the appropriate NatureAdjustments for an AdvNature
Pokemon::NatureAdjustments nature_to_adjustment(AdvNature nature);

// returns search filters that correspond with observed stats
AdvRngFilters observation_to_filters(const AdvObservedPokemon& observation, const BaseStats& basestats, AdvRngMethod method = AdvRngMethod::Method1);
Expand All @@ -154,15 +157,15 @@ class AdvRngSearcher{
const std::vector<uint16_t>& seeds,
uint64_t min_advances,
uint64_t max_advances,
uint16_t tid_xor_sid = 0,
uint8_t gender_threshold = 126
int16_t gender_threshold = 126,
uint16_t tid_xor_sid = 0
);

void refine_search(
std::map<AdvRngState, AdvPokemonResult>& map,
AdvRngFilters& target,
uint16_t tid_xor_sid = 0,
uint8_t gender_threshold = 126
int16_t gender_threshold = 126,
uint16_t tid_xor_sid = 0
);

private:
Expand All @@ -171,8 +174,8 @@ class AdvRngSearcher{
AdvRngFilters& target,
uint64_t min_advances,
uint64_t max_advances,
uint16_t tid_xor_sid,
uint8_t gender_threshold
int16_t gender_threshold,
uint16_t tid_xor_sid
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ void check_timings(
);
}
return;
case PokemonFRLG_RngTarget::hitmonchan:
case PokemonFRLG_RngTarget::hitmonlee:
case PokemonFRLG_RngTarget::hitmon:
if (INGAME_DELAY < 4500){
OperationFailedException::fire(
Expand Down Expand Up @@ -419,6 +421,9 @@ void check_timings(
);
}
return;
case PokemonFRLG_RngTarget::omanyte:
case PokemonFRLG_RngTarget::kabuto:
case PokemonFRLG_RngTarget::aerodactyl:
case PokemonFRLG_RngTarget::fossils:
if (INGAME_DELAY < 6000){
OperationFailedException::fire(
Expand All @@ -431,6 +436,8 @@ void check_timings(
case PokemonFRLG_RngTarget::gamecornerabra:
case PokemonFRLG_RngTarget::gamecornerclefairy:
case PokemonFRLG_RngTarget::gamecornerdratini:
case PokemonFRLG_RngTarget::gamecornerscyther:
case PokemonFRLG_RngTarget::gamecornerpinsir:
case PokemonFRLG_RngTarget::gamecornerbug:
case PokemonFRLG_RngTarget::gamecornerporygon:
if (INGAME_DELAY < 8500){
Expand Down Expand Up @@ -608,6 +615,8 @@ void perform_blind_sequence(
case PokemonFRLG_RngTarget::magikarp:
collect_magikarp_after_delay(context, INGAME_DELAY);
return;
case PokemonFRLG_RngTarget::hitmonchan:
case PokemonFRLG_RngTarget::hitmonlee:
case PokemonFRLG_RngTarget::hitmon:
collect_hitmon_after_delay(context, INGAME_DELAY);
return;
Expand All @@ -617,6 +626,9 @@ void perform_blind_sequence(
case PokemonFRLG_RngTarget::lapras:
collect_lapras_after_delay(context, INGAME_DELAY);
return;
case PokemonFRLG_RngTarget::omanyte:
case PokemonFRLG_RngTarget::kabuto:
case PokemonFRLG_RngTarget::aerodactyl:
case PokemonFRLG_RngTarget::fossils:
collect_fossil_after_delay(context, INGAME_DELAY);
return;
Expand All @@ -629,6 +641,8 @@ void perform_blind_sequence(
case PokemonFRLG_RngTarget::gamecornerdratini:
collect_gamecorner_after_delay(context, INGAME_DELAY, 2);
return;
case PokemonFRLG_RngTarget::gamecornerscyther:
case PokemonFRLG_RngTarget::gamecornerpinsir:
case PokemonFRLG_RngTarget::gamecornerbug:
collect_gamecorner_after_delay(context, INGAME_DELAY, 3);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ namespace PokemonFRLG{
starters,
magikarp,
hitmon,
hitmonchan,
hitmonlee,
eevee,
lapras,
fossils,
omanyte,
kabuto,
aerodactyl,
gamecornerabra,
gamecornerclefairy,
gamecornerdratini,
gamecornerbug,
gamecornerscyther,
gamecornerpinsir,
gamecornerporygon,
togepi,
staticencounter,
Expand Down
Loading