Skip to content

Commit

Permalink
[Gen 4] Bug Catching Contest (partial #1) (#233)
Browse files Browse the repository at this point in the history
* Added basic gen4 BCC generation

* Added gen4 BCC encounter slots

* Added correct BCC generation in gen4 generator

* Force user to set at least one flawless IV in BCC Searcher

* Add bug encounter data

* Requested change to bcc warning message

* Fixed locations in HGSS BCC encounters file

* Initial loading of bug contest data

* Add level to bug contest

* Add level to bug contest searcher

* Attempt cute charm fix for bug contest

* Remove unnecessary if clause

* Renamed BCC location

* Refactor to remove duplicate lines

* Whitespace and version check

* Remove unused, additions for encounter lookup

* Added National Dex checkBox to Gen4 profile editor

* Add profile defaults

* Requested changes

* Small tweaks

* Create template for difference in bug contest generation

* Show bcc days in the correct order

* Forgot to show bcc days in the correct order in searcher too

* Requested changes

Return bool from createPokemon
Completely skip loop on successful cute charm
Move common state calculations back to main function
Remove unnecessary variables and checks

* Missing breaks

* Tweak early exit from loop

* Fix missing PID calculations

Simplify switch statement within loop

* Add missing nature filter check

* Revert "Add missing nature filter check"

This reverts commit 0fd8dcf.

* Re-Add filter check after loop

* Move filter checks to proper positions

* Re-Add if to skip loop when not necessary

* Remove some duplication

* Nit changes

* Added national dex in wild4 window inside the profile section

Co-authored-by: Admiral-Fish <admiralfish420@gmail.com>
Co-authored-by: Steve Cook <steviecook210@gmail.com>
  • Loading branch information
3 people committed Mar 15, 2022
1 parent 8aff189 commit ae59637
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 153 deletions.
57 changes: 53 additions & 4 deletions Source/Core/Gen4/Encounters4.cpp
Expand Up @@ -81,6 +81,23 @@ namespace Encounters4
return encounters;
}

std::vector<std::vector<u8>> getBugCatchingContestData(bool dex)
{
const u8 *data = heartgold_bug.data();
size_t size = dex ? heartgold_bug.size() : 41;
int offset = 41;

std::vector<std::vector<u8>> encounters;
for (size_t i = dex ? 41 : 0; i < size; i += offset)
{
std::vector<u8> entry(offset);
std::memcpy(entry.data(), data + i, offset);
encounters.emplace_back(entry);
}

return encounters;
}

u16 getValue(const std::vector<u8> &data, int offset)
{
return static_cast<u16>(data[offset] << 8) | data[offset + 1];
Expand Down Expand Up @@ -235,6 +252,25 @@ namespace Encounters4
}
}

std::vector<EncounterArea4> getBugCatchingContest(const std::vector<u8> &data, const PersonalInfo *info)
{
std::vector<EncounterArea4> encounters;
u8 location = data[0];

std::vector<Slot> bcc;
for (int i = 0; i < 10; i++)
{
u8 minLevel = data[1 + i * 4];
u8 maxLevel = data[2 + i * 4];
u16 specie = getValue(data, 3 + i * 4);
bcc.emplace_back(specie, minLevel, maxLevel, info[specie]);
}

encounters.emplace_back(location, Encounter::BugCatchingContest, bcc);

return encounters;
}

std::vector<EncounterArea4> getHGSS(const std::vector<u8> &data, const Profile4 &profile, const PersonalInfo *info,
Encounter encounter, int time)
{
Expand Down Expand Up @@ -401,11 +437,24 @@ namespace Encounters4
auto *info = PersonalLoader::getPersonal(version);

std::vector<EncounterArea4> encounters;
for (const auto &data : getData(version))

if ((version & Game::HGSS) != Game::None && encounter == Encounter::BugCatchingContest)
{
auto areas = (version & Game::HGSS) != Game::None ? getHGSS(data, profile, info, encounter, time) : getDPPt(data, profile, info, time);
std::copy_if(areas.begin(), areas.end(), std::back_inserter(encounters),
[&encounter](const EncounterArea4 &area) { return area.getEncounter() == encounter; });
for (const auto &data : getBugCatchingContestData(profile.getNationalDex()))
{
auto areas = getBugCatchingContest(data, info);
std::copy(areas.begin(), areas.end(), std::back_inserter(encounters));
}
}
else
{
for (const auto &data : getData(version))
{
auto areas = (version & Game::HGSS) != Game::None ? getHGSS(data, profile, info, encounter, time)
: getDPPt(data, profile, info, time);
std::copy_if(areas.begin(), areas.end(), std::back_inserter(encounters),
[&encounter](const EncounterArea4 &area) { return area.getEncounter() == encounter; });
}
}

return encounters;
Expand Down

0 comments on commit ae59637

Please sign in to comment.