From 64d4d7e570c85c00f653132c3ac27ffae126040a Mon Sep 17 00:00:00 2001 From: Rose Silicon Date: Thu, 19 Sep 2024 12:03:13 -0400 Subject: [PATCH] Simplify HP Logic (#5403) --- src/pokemon.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/pokemon.c b/src/pokemon.c index d76d1df58c..faa1a65aef 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -1800,29 +1800,19 @@ void CalculateMonStats(struct Pokemon *mon) CALC_STAT(baseSpAttack, spAttackIV, spAttackEV, STAT_SPATK, MON_DATA_SPATK) CALC_STAT(baseSpDefense, spDefenseIV, spDefenseEV, STAT_SPDEF, MON_DATA_SPDEF) - if (species == SPECIES_SHEDINJA) - { - if (currentHP != 0 || oldMaxHP == 0) - currentHP = 1; - else - return; - } - else - { - if (currentHP == 0 && oldMaxHP == 0) - currentHP = newMaxHP; - else if (currentHP != 0) - { - if (newMaxHP > oldMaxHP) - currentHP += newMaxHP - oldMaxHP; - if (currentHP <= 0) - currentHP = 1; - if (currentHP > newMaxHP) - currentHP = newMaxHP; - } - else - return; - } + // Since a pokemon's maxHP data could either not have + // been initialized at this point or this pokemon is + // just fainted, the check for oldMaxHP is important. + if (currentHP == 0 && oldMaxHP != 0) + return; + + // Only add to currentHP if newMaxHP went up. + if (newMaxHP > oldMaxHP) + currentHP += newMaxHP - oldMaxHP; + + // Ensure currentHP does not surpass newMaxHP. + if (currentHP > newMaxHP) + currentHP = newMaxHP; SetMonData(mon, MON_DATA_HP, ¤tHP); }