Skip to content

Commit

Permalink
Allow omitting nature in IV calc (#259)
Browse files Browse the repository at this point in the history
Co-authored-by: Admiral-Fish <admiralfish420@gmail.com>
  • Loading branch information
Lincoln-LM and Admiral-Fish authored Sep 24, 2024
1 parent 183adbf commit 97d641c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
40 changes: 34 additions & 6 deletions Source/Core/Util/IVChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ namespace
{
for (u8 iv = 0; iv < 32; iv++)
{
u16 stat = Nature::computeStat(baseStats[i], iv, nature, level, i);
if (stat == stats[i])
u16 stat;
if (nature != 255)
{
minIVs[i] = std::min(iv, minIVs[i]);
maxIVs[i] = std::max(iv, maxIVs[i]);
stat = Nature::computeStat(baseStats[i], iv, nature, level, i);
if (stat == stats[i])
{
minIVs[i] = std::min(iv, minIVs[i]);
maxIVs[i] = std::max(iv, maxIVs[i]);
}
}
else
{
// Hard pass nature as Hardy to not modify the stat
stat = Nature::computeStat(baseStats[i], iv, 0, level, i);
if (stat == stats[i]
|| (i != 0 && (static_cast<u16>(stat * 0.9f) == stats[i] || static_cast<u16>(stat * 1.1f) == stats[i])))
{
minIVs[i] = std::min(iv, minIVs[i]);
maxIVs[i] = std::max(iv, maxIVs[i]);
}
}
}
}
Expand Down Expand Up @@ -203,8 +218,21 @@ std::array<u8, 6> IVChecker::nextLevel(const std::array<u8, 6> &baseStats, const
{
for (size_t j = 1; j < statIVs.size(); j++)
{
u16 previous = Nature::computeStat(baseStats[i], statIVs[j - 1], nature, l, i);
u16 current = Nature::computeStat(baseStats[i], statIVs[j], nature, l, i);
u16 previous;
u16 current;

if (nature != 255)
{
previous = Nature::computeStat(baseStats[i], statIVs[j - 1], nature, l, i);
current = Nature::computeStat(baseStats[i], statIVs[j], nature, l, i);
}
else
{
// Hard pass nature as Hardy to not modify the stat
previous = Nature::computeStat(baseStats[i], statIVs[j - 1], 0, l, i);
current = Nature::computeStat(baseStats[i], statIVs[j], 0, l, i);
}

if (previous < current)
{
levels[i] = l;
Expand Down
7 changes: 6 additions & 1 deletion Source/Form/Util/IVCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ IVCalculator::IVCalculator(QWidget *parent) : QWidget(parent), ui(new Ui::IVCalc
setAttribute(Qt::WA_QuitOnClose, false);
setAttribute(Qt::WA_DeleteOnClose);

ui->comboBoxNature->addItem(tr("None"));
for (const std::string &nature : Translator::getNatures())
{
ui->comboBoxNature->addItem(QString::fromStdString(nature));
}

for (const std::string &hiddenPower : Translator::getHiddenPowers())
{
ui->comboBoxHiddenPower->addItem(QString::fromStdString(hiddenPower));
}

for (const std::string &characteristic : Translator::getCharacteristics())
{
ui->comboBoxCharacteristic->addItem(QString::fromStdString(characteristic));
Expand All @@ -51,6 +54,8 @@ IVCalculator::IVCalculator(QWidget *parent) : QWidget(parent), ui(new Ui::IVCalc
ui->comboBoxGame->setup(
{ toInt(Game::Gen3), toInt(Game::Platinum), toInt(Game::HGSS), toInt(Game::BW2), toInt(Game::SwSh), toInt(Game::BDSP) });

ui->labelNextLevel->setToolTip(tr("Next level may not be completely accurate without specifying a nature"));

connect(ui->pushButtonAddRow, &QPushButton::clicked, this, &IVCalculator::addEntry);
connect(ui->pushButtonRemoveRow, &QPushButton::clicked, this, &IVCalculator::removeEntry);
connect(ui->pushButtonFindIVs, &QPushButton::clicked, this, &IVCalculator::findIVs);
Expand Down Expand Up @@ -198,7 +203,7 @@ void IVCalculator::findIVs()
stats.emplace_back(stat);
}

u8 nature = static_cast<u8>(ui->comboBoxNature->currentIndex());
u8 nature = static_cast<u8>(ui->comboBoxNature->currentIndex() - 1);
u8 hiddenPower = static_cast<u8>(ui->comboBoxHiddenPower->currentIndex() - 1);
u8 characteristic = static_cast<u8>(ui->comboBoxCharacteristic->currentIndex() - 1);

Expand Down

0 comments on commit 97d641c

Please sign in to comment.