Skip to content

Commit

Permalink
Add & document constant battle advances (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Real96 authored Jun 5, 2024
1 parent 12ce445 commit 50e086d
Show file tree
Hide file tree
Showing 2 changed files with 371 additions and 337 deletions.
42 changes: 38 additions & 4 deletions Source/Core/Gen4/Generators/WildGenerator4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "WildGenerator4.hpp"
#include <Core/Enum/Encounter.hpp>
#include <Core/Enum/Game.hpp>
#include <Core/Enum/Lead.hpp>
#include <Core/Enum/Method.hpp>
#include <Core/Gen4/States/WildState4.hpp>
Expand All @@ -28,6 +29,31 @@
#include <Core/Util/EncounterSlot.hpp>
#include <Core/Util/Utilities.hpp>

static u32 getBattleAdvances(const EncounterArea4 &area, Game version)
{
u32 advances = 0;

// Fishing uses an advance to determine the visual frames range in which you have to press A
if (area.getEncounter() == Encounter::OldRod || area.getEncounter() == Encounter::GoodRod || area.getEncounter() == Encounter::SuperRod)
{
advances += 1;
}

// DP uses 4 advances to create the information that determine if quick claw will proc
if ((version & Game::DP) != Game::None)
{
advances += 4;
}

// Advance used to determine the random ball position when thrown out
if (!area.greatMarsh(version) && !area.safariZone(version))
{
advances += 1;
}

return advances;
}

static u16 getItem(u8 rand, Lead lead, const PersonalInfo *info)
{
constexpr u8 ItemTableRange[2][2] = { { 45, 95 }, { 20, 80 } };
Expand Down Expand Up @@ -94,9 +120,11 @@ std::vector<WildGeneratorState4> WildGenerator4::generateMethodJ(u32 seed) const
PokeRNG rng(seed, initialAdvances);
auto jump = rng.getJump(delay);

u32 battleAdvancesConst = getBattleAdvances(area, profile.getVersion());

for (u32 cnt = 0; cnt <= maxAdvances; cnt++)
{
u32 battleAdvances = initialAdvances + cnt;
u32 battleAdvances = battleAdvancesConst + initialAdvances + cnt;
PokeRNG go(rng, jump);

// Fishing nibble check
Expand Down Expand Up @@ -254,9 +282,11 @@ std::vector<WildGeneratorState4> WildGenerator4::generateMethodK(u32 seed) const
PokeRNG rng(seed, initialAdvances);
auto jump = rng.getJump(delay);

u32 battleAdvancesConst = getBattleAdvances(area, profile.getVersion());

for (u32 cnt = 0; cnt <= maxAdvances; cnt++)
{
u32 battleAdvances = initialAdvances + cnt;
u32 battleAdvances = battleAdvancesConst + initialAdvances + cnt;
PokeRNG go(rng, jump);

// Rock smash/fishing nibble check
Expand Down Expand Up @@ -492,9 +522,11 @@ std::vector<WildGeneratorState4> WildGenerator4::generatePokeRadar(u32 seed, u8
PokeRNG rng(seed, initialAdvances);
auto jump = rng.getJump(delay);

u32 battleAdvancesConst = getBattleAdvances(area, profile.getVersion());

for (u32 cnt = 0; cnt <= maxAdvances; cnt++)
{
u32 battleAdvances = initialAdvances + cnt;
u32 battleAdvances = battleAdvancesConst + initialAdvances + cnt;
PokeRNG go(rng, jump);

u8 nature;
Expand Down Expand Up @@ -589,9 +621,11 @@ std::vector<WildGeneratorState4> WildGenerator4::generatePokeRadarShiny(u32 seed
PokeRNG rng(seed, initialAdvances);
auto jump = rng.getJump(delay);

u32 battleAdvancesConst = getBattleAdvances(area, profile.getVersion());

for (u32 cnt = 0; cnt <= maxAdvances; cnt++)
{
u32 battleAdvances = initialAdvances + cnt;
u32 battleAdvances = battleAdvancesConst + initialAdvances + cnt;
PokeRNG go(rng, jump);

u8 nature;
Expand Down
Loading

0 comments on commit 50e086d

Please sign in to comment.