diff --git a/include/battle.h b/include/battle.h index 44aa063c9..2b72d4836 100644 --- a/include/battle.h +++ b/include/battle.h @@ -622,7 +622,7 @@ struct BattleStruct struct MegaEvolutionData mega; struct ZMoveData zmove; const u8 *trainerSlideMsg; - bool8 trainerSlideLowHpMsgDone:1; + bool8 trainerSlideLowHpMsgDone; u8 introState; u8 ateBerry[2]; // array id determined by side, each party pokemon as bit u8 stolenStats[NUM_BATTLE_STATS]; // hp byte is used for which stats to raise, other inform about by how many stages @@ -663,14 +663,14 @@ struct BattleStruct u8 storedHealingWish:4; // Each battler as a bit. u8 storedLunarDance:4; // Each battler as a bit. u16 supremeOverlordModifier[MAX_BATTLERS_COUNT]; - bool8 trainerSlideHalfHpMsgDone:1; + bool8 trainerSlideHalfHpMsgDone; u8 trainerSlideFirstCriticalHitMsgState:2; u8 trainerSlideFirstSuperEffectiveHitMsgState:2; u8 trainerSlideFirstSTABMoveMsgState:2; u8 trainerSlidePlayerMonUnaffectedMsgState:2; - bool8 trainerSlideMegaEvolutionMsgDone:1; - bool8 trainerSlideZMoveMsgDone:1; - bool8 trainerSlideBeforeFirstTurnMsgDone:1; + bool8 trainerSlideMegaEvolutionMsgDone; + bool8 trainerSlideZMoveMsgDone; + bool8 trainerSlideBeforeFirstTurnMsgDone; }; #define F_DYNAMIC_TYPE_1 (1 << 6) diff --git a/src/battle_message.c b/src/battle_message.c index fab65a46b..dd6390d28 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -3934,6 +3934,37 @@ static u32 GetEnemyMonCount(u32 firstId, u32 lastId, bool32 onlyAlive) return count; } +enum +{ + LESS_THAN, + EQUAL, + GREATER_THAN, + LESS_THAN_OR_EQUAL, + GREATER_THAN_OR_EQUAL, + NOT_EQUAL, +}; + +u32 BattlerHPPercentage(u32 battlerId, u32 operation, u32 threshold) +{ + switch (operation) + { + case LESS_THAN: + return gBattleMons[battlerId].hp < (gBattleMons[battlerId].maxHP / threshold); + case EQUAL: + return gBattleMons[battlerId].hp == (gBattleMons[battlerId].maxHP / threshold); + case GREATER_THAN: + return gBattleMons[battlerId].hp > (gBattleMons[battlerId].maxHP / threshold); + case LESS_THAN_OR_EQUAL: + return gBattleMons[battlerId].hp <= (gBattleMons[battlerId].maxHP / threshold); + case GREATER_THAN_OR_EQUAL: + return gBattleMons[battlerId].hp >= (gBattleMons[battlerId].maxHP / threshold); + case NOT_EQUAL: + return gBattleMons[battlerId].hp != (gBattleMons[battlerId].maxHP / threshold); + default: + break; + } +} + u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) { u32 i, firstId, lastId, trainerId, retValue = 1; @@ -3979,7 +4010,7 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) case TRAINER_SLIDE_LAST_LOW_HP: if (sTrainerSlides[i].msgLastLowHp != NULL && GetEnemyMonCount(firstId, lastId, TRUE) == 1 - && gBattleMons[battlerId].hp <= (gBattleMons[battlerId].maxHP / 4) + && BattlerHPPercentage(battlerId, GREATER_THAN_OR_EQUAL, 4) && !gBattleStruct->trainerSlideLowHpMsgDone) { gBattleStruct->trainerSlideLowHpMsgDone = TRUE; @@ -3997,7 +4028,7 @@ u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) case TRAINER_SLIDE_LAST_HALF_HP: if (sTrainerSlides[i].msgLastHalfHp != NULL && GetEnemyMonCount(firstId, lastId, TRUE) == GetEnemyMonCount(firstId, lastId, FALSE) - 1 - && (gBattleMons[battlerId].hp <= (gBattleMons[battlerId].maxHP / 2) && gBattleMons[battlerId].hp > (gBattleMons[battlerId].maxHP / 4)) + && BattlerHPPercentage(battlerId, LESS_THAN_OR_EQUAL, 2) && BattlerHPPercentage(battlerId, GREATER_THAN, 4) && !gBattleStruct->trainerSlideHalfHpMsgDone) { gBattleStruct->trainerSlideHalfHpMsgDone = TRUE;