From a9daef337faad7341869e0ce6c27408eb40637e5 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 5 Nov 2024 11:58:44 +0100 Subject: [PATCH] decompile code_806E8B0 --- src/code_806E8B0.c | 214 ++++++++++++++++++++------------------------- src/dungeon_move.c | 6 +- src/move_actions.c | 8 +- 3 files changed, 103 insertions(+), 125 deletions(-) diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index ca1870596..b69effc7b 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -21,122 +21,10 @@ #include "dungeon_items.h" #include "structs/str_damage.h" -extern u8 *gUnknown_80FEE04[]; -extern u8 *gUnknown_80FEE2C[]; -extern u8 *gUnknown_80FEE54[]; - void sub_8042940(Entity *r0); void sub_80428B0(Entity *r0); void sub_80428C4(Entity *r0); -void sub_806E8B0(Entity * pokemon, Entity * target, u8 param_3, s32 *param_4, s32 *param_5, s32 param_6) -{ - bool8 hasNegStatus_pokemon; - bool8 visFlags_pokemon_1; - bool8 visFlags_pokemon_2; - bool8 hasNegStatus_target; - bool8 visFlags_target; - s32 iVar3; - bool32 isNotEnemy; - EntityInfo * entityInfo; - EntityInfo * entityInfo_1; - s32 r7; - s32 r8; - s32 r10; - s32 sp_0x4; - s32 sp_0x8; - - r7 = 1; - r8 = 1; - sp_0x4 = 1; - sp_0x8 = 1; - r10 = IsTypePhysical(param_3) == 0; - - - if (HasAbility(pokemon, ABILITY_GUTS)) { - entityInfo = GetEntInfo(pokemon); - hasNegStatus_pokemon = HasNegativeStatus(pokemon); - visFlags_pokemon_1 = SetVisualFlags(entityInfo,1,hasNegStatus_pokemon); - if (hasNegStatus_pokemon) { - r7 = 2; - } - if (visFlags_pokemon_1) { - sub_80428B0(pokemon); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FEE04); // Guts boosted its power - } - } - - if ((HasAbility(pokemon, ABILITY_HUGE_POWER)) || (HasAbility(pokemon, ABILITY_PURE_POWER))) { - entityInfo_1 = GetEntInfo(pokemon); - iVar3 = 0; - if ((param_6 < 0x21) && (!r10)) { - iVar3 = 1; - } - visFlags_pokemon_2 = SetVisualFlags(entityInfo_1,0x100,iVar3); - if (iVar3 != 0) { - r7 *= 3; - r8 <<= 1; - } - if (visFlags_pokemon_2) { - sub_80428C4(pokemon); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FEE2C); // It's special ability boosted Attack - } - } - - if ((HasAbility(pokemon, ABILITY_HUSTLE)) && (!r10)) { - r7 *= 3; - r8 <<= 1; - } - - if(GetEntInfo(pokemon)->isNotTeamMember) - { - isNotEnemy = FALSE; - } - else - { - isNotEnemy = TRUE; - } - - if ((HasAbility(pokemon, ABILITY_PLUS)) && (r10 == 1) && gDungeon->minusIsActive[isNotEnemy]) { - r7 *= 15; - r8 *= 10; - } - - // ABILITY_MINUS - if ((HasAbility(pokemon, ABILITY_MINUS)) && (r10 == 1) && gDungeon->plusIsActive[isNotEnemy]) { - r7 *= 15; - r8 *= 10; - } - - if (HasAbility(target, ABILITY_INTIMIDATE) && (!r10)) { - r7 <<= 2; - r8 *= 5; - } - - if ((HasAbility(target, ABILITY_MARVEL_SCALE)) && (!r10)) { - entityInfo = GetEntInfo(target); - hasNegStatus_target = HasNegativeStatus(target); - visFlags_target = SetVisualFlags(entityInfo, 8, hasNegStatus_target); - if (hasNegStatus_target) { - sp_0x4 *= 3; - sp_0x8 <<= 1; - } - if (visFlags_target) { - sub_8042940(target); - TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FEE54); // Its special ability quickened attacks! - } - } - - *param_4 *= r7; - *param_5 *= sp_0x4; - if (r8 != 1) { - *param_4 = *param_4 / r8; - } - if (sp_0x8 != 1) { - *param_5 = *param_5 / sp_0x8; - } -} - extern void sub_806F500(void); extern void sub_800A020(struct unkStruct_80943A8 *param_1, u32 param_2); extern void sub_800A3F0(struct unkStruct_80943A8 *param_1, struct unkStruct_80943A8 *param_2, struct unkStruct_80943A8 *); @@ -152,6 +40,7 @@ extern void sub_8041B5C(Entity *pokemon); extern void HandleDealingDamage(Entity *attacker, Entity *target, struct DamageStruct *dmgStruct, bool32 isFalseSwipe, bool32 giveExp, s16 arg4, bool32 arg8, s32 argC); extern void sub_80457DC(Entity *); +extern const s32 gUnknown_80F54B4[NUM_EFFECTIVENESS][NUM_EFFECTIVENESS]; extern const s32 gUnknown_80F504C[]; extern const s32 gUnknown_80F50A0[]; extern const s16 gUnknown_810AC60; @@ -168,6 +57,98 @@ extern const struct unkStruct_80943A8 gUnknown_8106F1C; extern const struct unkStruct_80943A8 gUnknown_8106F14; extern const u8 *const gUnknown_80FAE00; extern const u8 *const gUnknown_80FADD8; +extern const u8 *const gUnknown_80FEE04; +extern const u8 *const gUnknown_80FEE2C; +extern const u8 *const gUnknown_80FEE54; + +static void ApplyAtkDefStatBoosts(Entity *attacker, Entity *target, u8 moveType, s32 *atkStat, s32 *defStat, s32 rand) +{ + bool32 isNotEnemy; + s32 atkMultiplier = 1; + s32 atkDivisor = 1; + s32 defMultiplier = 1; + s32 defDivisor = 1; + s32 splitIndex = (!IsTypePhysical(moveType)) ? 1 : 0; + + if (HasAbility(attacker, ABILITY_GUTS)) { + EntityInfo *entInfo = GetEntInfo(attacker); + bool8 gutsBoost = HasNegativeStatus(attacker); + bool8 visFlags_attacker_1 = SetVisualFlags(entInfo,1,gutsBoost); + + if (gutsBoost) { + atkMultiplier = 2; + } + if (visFlags_attacker_1) { + sub_80428B0(attacker); + TryDisplayDungeonLoggableMessage3(attacker,target, gUnknown_80FEE04); // Guts boosted its power + } + } + + if ((HasAbility(attacker, ABILITY_HUGE_POWER)) || (HasAbility(attacker, ABILITY_PURE_POWER))) { + EntityInfo *entInfo = GetEntInfo(attacker); + bool32 hugePowerBoost = (rand < 33 && splitIndex == 0); + bool8 visFlags_attacker_2 = SetVisualFlags(entInfo,0x100,hugePowerBoost); + + if (hugePowerBoost) { + atkMultiplier *= 3; + atkDivisor *= 2; + } + if (visFlags_attacker_2) { + sub_80428C4(attacker); + TryDisplayDungeonLoggableMessage3(attacker,target, gUnknown_80FEE2C); // It's special ability boosted Attack + } + } + + if ((HasAbility(attacker, ABILITY_HUSTLE)) && (splitIndex == 0)) { + atkMultiplier *= 3; + atkDivisor *= 2; + } + + if (GetEntInfo(attacker)->isNotTeamMember) { + isNotEnemy = FALSE; + } + else { + isNotEnemy = TRUE; + } + + if ((HasAbility(attacker, ABILITY_PLUS)) && (splitIndex == 1) && gDungeon->minusIsActive[isNotEnemy]) { + atkMultiplier *= 15; + atkDivisor *= 10; + } + if ((HasAbility(attacker, ABILITY_MINUS)) && (splitIndex == 1) && gDungeon->plusIsActive[isNotEnemy]) { + atkMultiplier *= 15; + atkDivisor *= 10; + } + + if (HasAbility(target, ABILITY_INTIMIDATE) && (splitIndex == 0)) { + atkMultiplier *= 4; + atkDivisor *= 5; + } + + if ((HasAbility(target, ABILITY_MARVEL_SCALE)) && (splitIndex == 0)) { + EntityInfo *targetInfo = GetEntInfo(target); + bool8 hasNegStatus_target = HasNegativeStatus(target); + bool8 visFlags_target = SetVisualFlags(targetInfo, 8, hasNegStatus_target); + + if (hasNegStatus_target) { + defMultiplier *= 3; + defDivisor *= 2; + } + if (visFlags_target) { + sub_8042940(target); + TryDisplayDungeonLoggableMessage3(attacker,target, gUnknown_80FEE54); // Its special ability quickened attacks! + } + } + + *atkStat *= atkMultiplier; + *defStat *= defMultiplier; + if (atkDivisor != 1) { + *atkStat = *atkStat / atkDivisor; + } + if (defDivisor != 1) { + *defStat = *defStat / defDivisor; + } +} static inline void SetDamageOne(struct DamageStruct *dmgStruct, u8 moveType) { @@ -180,7 +161,7 @@ static inline void SetDamageOne(struct DamageStruct *dmgStruct, u8 moveType) dmgStruct->unkF = 0; } -void sub_806EAF4(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s32 critChance, struct DamageStruct *dmgStruct, s32 arg8, u16 moveId, bool8 arg_10) +void CalcDamage(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s32 critChance, struct DamageStruct *dmgStruct, s32 arg8, u16 moveId, bool8 arg_10) { EntityInfo *attackerInfo = GetEntInfo(attacker); EntityInfo *targetInfo = GetEntInfo(target); @@ -301,7 +282,7 @@ void sub_806EAF4(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s attackerInfo->previousVisualFlags &= ~(0x100); attackerInfo->visualFlags &= ~(0x100); - sub_806E8B0(attacker, target, moveType, &atkStat, &defStat, rand); + ApplyAtkDefStatBoosts(attacker, target, moveType, &atkStat, &defStat, rand); sub_800A020(&unkSp1, atkStat - defStat); sub_800A020(&unkSp2, 8); sub_800A3F0(&unkSp1, &unkSp1, &unkSp2); @@ -315,7 +296,7 @@ void sub_806EAF4(Entity *attacker, Entity *target, u8 moveType, s32 movePower, s else { s32 unkAtkStat2 = attackerInfo->atk[splitIndex]; s32 unkDefStat2 = 1; - sub_806E8B0(attacker, target, moveType, &unkAtkStat2, &unkDefStat2, rand); + ApplyAtkDefStatBoosts(attacker, target, moveType, &unkAtkStat2, &unkDefStat2, rand); sub_800A020(&unkSp2, unkAtkStat2); sub_800A020(&unkSp3, 3); sub_800A3F0(&unkSp2, &unkSp2, &unkSp3); @@ -478,8 +459,6 @@ void DealDamageToEntity(Entity *entity, s32 dmg, s32 r6, s16 r4) HandleDealingDamage(&spEntity, entity, &dmgStruct, FALSE, FALSE, r4_, FALSE, 0); } -extern const s32 gUnknown_80F54B4[NUM_EFFECTIVENESS][NUM_EFFECTIVENESS]; - void sub_806F370(Entity *pokemon, Entity *target, s32 dmg, s32 r9, u8 *arg_0, u8 moveType, s16 arg_8, s32 arg_C, s32 arg_10, s32 arg_14) { s32 i; @@ -520,4 +499,3 @@ void sub_806F370(Entity *pokemon, Entity *target, s32 dmg, s32 r9, u8 *arg_0, u8 *arg_0 = dmgStruct.unkF; } } -// diff --git a/src/dungeon_move.c b/src/dungeon_move.c index 59dda3312..21c5ad0e7 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -42,7 +42,7 @@ extern void sub_80429C8(Entity *r0); extern u8 sub_803F428(Position *); extern bool8 sub_8045888(Entity *r0); extern void HandleDealingDamage(Entity *attacker, Entity *target, struct DamageStruct *dmgStruct, bool32 isFalseSwipe, bool32 giveExp, s16 arg4, bool32 arg8, s32 argC); -extern void sub_806EAF4(Entity *, Entity *, u8, u32, u32, struct DamageStruct *dmgStruct, u32, u16, u32); +extern void CalcDamage(Entity *, Entity *, u8, u32, u32, struct DamageStruct *dmgStruct, u32, u16, u32); extern s16 sub_8057600(Move *move, s32 itemID); extern void sub_803ED30(s32, Entity *r0, u8, s32); extern void sub_8042238(Entity *pokemon, Entity *target); @@ -1666,7 +1666,7 @@ s32 HandleDamagingMove(Entity *attacker, Entity *target, Move *move, s32 r9, s32 s32 movePower = GetMovePower(attacker, move); s32 critChance = GetMoveCritChance(move); - sub_806EAF4(attacker, target, moveType, movePower, critChance, &dmgStruct, r9, move->id, 1); + CalcDamage(attacker, target, moveType, movePower, critChance, &dmgStruct, r9, move->id, 1); unk = sub_8057600(move, itemId); return TryHitTarget(attacker, target, move, &dmgStruct, unk); } @@ -1678,7 +1678,7 @@ s32 sub_80556BC(Entity *attacker, Entity *target, u8 moveType, Move *move, s32 r s32 movePower = GetMovePower(attacker, move); s32 critChance = GetMoveCritChance(move); - sub_806EAF4(attacker, target, moveType, movePower, critChance, &dmgStruct, r9, move->id, 1); + CalcDamage(attacker, target, moveType, movePower, critChance, &dmgStruct, r9, move->id, 1); unk = sub_8057600(move, itemId); return TryHitTarget(attacker, target, move, &dmgStruct, unk); } diff --git a/src/move_actions.c b/src/move_actions.c index 10e706752..ebe52f36a 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -184,11 +184,11 @@ extern u8 sub_803F428(Position *pos); extern void sub_807EC28(bool8); extern void sub_806F370(Entity *r0, Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); extern void sub_804652C(Entity *, Entity *, Item *, u32, Position *); -extern void sub_806EAF4(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); +extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); extern void sub_8045C28(Item *, u8 , u8); extern void sub_805A7D4(Entity *, Entity *, Item *, Position *); extern void MudWaterSportEffect(u32); -extern void sub_806EAF4(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); +extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); extern void sub_806A6E8(Entity *); extern void sub_806ABAC(Entity *, Entity *); @@ -2171,7 +2171,7 @@ bool8 sub_8059E54(Entity * pokemon,Entity * target,Move * move,u32 param_4,u8 pa moveType = GetMoveTypeForMonster(pokemon,move); movePower = GetMovePower(pokemon,move); moveCritChance = GetMoveCritChance(move); - sub_806EAF4(pokemon,target,moveType,movePower,moveCritChance,local_30,0x100,move->id,0); + CalcDamage(pokemon,target,moveType,movePower,moveCritChance,local_30,0x100,move->id,0); SetMessageArgument_2(gFormatBuffer_Monsters[0],GetEntInfo(pokemon),0); TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC7C8); local_30[0] = local_30[0] / 2; @@ -2221,7 +2221,7 @@ bool8 sub_8059FC8(Entity * pokemon,Entity * target,Move * move,u32 param_4,u8 pa moveType = GetMoveTypeForMonster(pokemon,move); movePower = GetMovePower(pokemon,move); moveCritChance = GetMoveCritChance(move); - sub_806EAF4(pokemon,target,moveType,movePower,moveCritChance,local_30,0x200,move->id,0); + CalcDamage(pokemon,target,moveType,movePower,moveCritChance,local_30,0x200,move->id,0); SetMessageArgument_2(gFormatBuffer_Monsters[0],GetEntInfo(pokemon),0); TryDisplayDungeonLoggableMessage3(pokemon,target,*gUnknown_80FC7C8); local_30[0] = local_30[0] / 2;