Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Magnet Pull and Static apply to correct encounter types in Gen 3 #399

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make Magnet Pull and Static apply to correct encounter types
  • Loading branch information
c-poole committed Jun 13, 2024
commit ff0b97a7c6e82cc9636b313c845753ba38629921
9 changes: 6 additions & 3 deletions Source/Core/Gen3/Generators/WildGenerator3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ std::vector<WildGeneratorState> WildGenerator3::generate(u32 seed) const

auto modifiedSlots = area.getSlots(lead);
u16 rate = area.getRate() * 16;
bool rock = (profile.getVersion() & Game::RSE) != Game::None && area.getEncounter() == Encounter::RockSmash;
Encounter encounter = area.getEncounter();
bool rock = (profile.getVersion() & Game::RSE) != Game::None && encounter == Encounter::RockSmash;
bool checkMagnetPull = lead == Lead::MagnetPull && encounter == Encounter::Grass;
bool checkStatic = lead == Lead::Static && (encounter == Encounter::Grass || encounter == Encounter::Surfing);
bool feebas = area.feebasLocation(profile.getVersion());
bool safari = area.safariZone(profile.getVersion());
bool tanoby = area.tanobyChamber(profile.getVersion());
Expand Down Expand Up @@ -89,13 +92,13 @@ std::vector<WildGeneratorState> WildGenerator3::generate(u32 seed) const
}
else
{
if ((lead == Lead::MagnetPull || lead == Lead::Static) && go.nextUShort(2) == 0 && !modifiedSlots.empty())
if ((checkMagnetPull || checkStatic) && go.nextUShort(2) == 0 && !modifiedSlots.empty())
{
encounterSlot = modifiedSlots[go.nextUShort()];
}
else
{
encounterSlot = EncounterSlot::hSlot(go.nextUShort(100), area.getEncounter());
encounterSlot = EncounterSlot::hSlot(go.nextUShort(100), encounter);
}
}

Expand Down
13 changes: 9 additions & 4 deletions Source/Core/Gen3/Searchers/WildSearcher3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ WildSearcher3::WildSearcher3(Method method, Lead lead, bool feebasTile, const En
{
if ((profile.getVersion() & Game::RSE) != Game::None && area.getEncounter() == Encounter::RockSmash)
{
rate = area.getRate() * 16;
rate = area.getRate() * 16 ;
}
}

Expand All @@ -81,6 +81,8 @@ void WildSearcher3::startSearch(const std::array<u8, 6> &min, const std::array<u
|| area.getEncounter() == Encounter::SuperRod);
bool safari = area.safariZone(profile.getVersion());
bool tanoby = area.tanobyChamber(profile.getVersion());
bool ignoreLead = (lead == Lead::MagnetPull && !(area.getEncounter() == Encounter::Grass))
|| (lead == Lead::Static && !(area.getEncounter() == Encounter::Grass || area.getEncounter() == Encounter::Surfing));

for (u8 hp = min[0]; hp <= max[0]; hp++)
{
Expand All @@ -99,7 +101,7 @@ void WildSearcher3::startSearch(const std::array<u8, 6> &min, const std::array<u
return;
}

auto states = search(hp, atk, def, spa, spd, spe, feebas, safari, tanoby);
auto states = search(hp, atk, def, spa, spd, spe, feebas, safari, tanoby, ignoreLead);

std::lock_guard<std::mutex> guard(mutex);
results.insert(results.end(), states.begin(), states.end());
Expand All @@ -113,13 +115,16 @@ void WildSearcher3::startSearch(const std::array<u8, 6> &min, const std::array<u
}

std::vector<WildSearcherState> WildSearcher3::search(u8 hp, u8 atk, u8 def, u8 spa, u8 spd, u8 spe, bool feebas, bool safari,
bool tanoby) const
bool tanoby, bool ignoreLead) const
{
std::vector<WildSearcherState> states;
std::array<u8, 6> ivs = { hp, atk, def, spa, spd, spe };

u32 seeds[6];
int size = LCRNGReverse::recoverPokeRNGIV(hp, atk, def, spa, spd, spe, seeds, method);
Lead effectiveLead = ignoreLead ? Lead::None: lead;


for (int i = 0; i < size; i++)
{
PokeRNGR rng(seeds[i]);
Expand Down Expand Up @@ -161,7 +166,7 @@ std::vector<WildSearcherState> WildSearcher3::search(u8 hp, u8 atk, u8 def, u8 s
PokeRNGR test[4] = { rng, rng, rng, rng };
bool valid[4] = { false, false, false, false };

switch (lead)
switch (effectiveLead)
{
case Lead::None:
if (tanoby)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Gen3/Searchers/WildSearcher3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ class WildSearcher3 : public WildSearcher<EncounterArea3, Profile3, WildStateFil
* @param feebas Whether the encounter location contains Feebas
* @param safari Whether the encounter location is the Safari Zone in RSE
* @param tanoby Whether the encounter location is Tanoby Ruins in FRLG
* @param ignoreLead Whether the lead was identified to be irrelevant to the RNG pattern
*
* @return Vector of computed states
*/
std::vector<WildSearcherState> search(u8 hp, u8 atk, u8 def, u8 spa, u8 spd, u8 spe, bool feebas, bool safari, bool tanoby) const;
std::vector<WildSearcherState> search(u8 hp, u8 atk, u8 def, u8 spa, u8 spd, u8 spe, bool feebas, bool safari, bool tanoby, bool ignoreLead) const;
};

#endif // WILDSEARCHER3_HPP