From fda81d1e1cdec25d4d1bafaa8f642c2c12f52524 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 13 Oct 2024 14:35:12 +0200 Subject: [PATCH] fix some functions using static inlines --- include/moves.h | 15 +++++++++++++ src/friend_area.c | 2 -- src/move_util.c | 54 +++++++++++++++-------------------------------- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/include/moves.h b/include/moves.h index 95f69a5ae..c0d508cb3 100644 --- a/include/moves.h +++ b/include/moves.h @@ -94,4 +94,19 @@ static inline bool8 MoveFlagExists(Move *move) return (move->moveFlags & MOVE_FLAG_EXISTS); } +static inline bool8 MoveFlagLinkChain(Move *move) +{ + return (move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN); +} + +static inline bool8 MoveFlagDisabled(Move *move) +{ + return (move->moveFlags & MOVE_FLAG_DISABLED); +} + +static inline bool8 MoveFlagSealed(Move *move) +{ + return (move->moveFlags2 & MOVE_FLAG_SEALED); +} + #endif // GUARD_MOVES_H diff --git a/src/friend_area.c b/src/friend_area.c index b06830ad7..7f760f6fd 100644 --- a/src/friend_area.c +++ b/src/friend_area.c @@ -58,7 +58,6 @@ void sub_8092404(u8 r0, u16 *r1, bool8 allowLeader, bool8 allowPartner) count = 0; for (i = 0; i < NUM_MONSTERS; i++) { - if (PokemonFlag1(&gRecruitedPokemonRef->pokemon[i]) && (!IsMonTeamLeader(&gRecruitedPokemonRef->pokemon[i]) || allowLeader) && (!IsMonPartner(&gRecruitedPokemonRef->pokemon[i]) || allowPartner) @@ -69,7 +68,6 @@ void sub_8092404(u8 r0, u16 *r1, bool8 allowLeader, bool8 allowPartner) r1[count] = i; count++; } - } r1[count] = 0xFFFF; diff --git a/src/move_util.c b/src/move_util.c index a42e27534..5f6f1d790 100644 --- a/src/move_util.c +++ b/src/move_util.c @@ -97,7 +97,7 @@ bool8 sub_80571F0(Entity * pokemon, Move *move) bool8 sub_805727C(Entity * pokemon, Entity * target, s32 chance) { bool8 uVar2; - if (!sub_8044B28() && EntityExists(pokemon) && EntityExists(target) && + if (!sub_8044B28() && EntityExists(pokemon) && EntityExists(target) && (target->info->unk158 != 0) && (target->info->HP != 0)) { if (chance != 0) { @@ -140,45 +140,25 @@ bool8 sub_8057308(Entity *pokemon, s32 chance) bool8 CanAIUseMove(Entity *pokemon, s32 moveIndex, bool8 hasPPChecker) { - EntityInfo *pokemonInfo = pokemon->info; - Move *move = &pokemonInfo->moves.moves[moveIndex]; s32 i; - if (!(move->moveFlags & MOVE_FLAG_EXISTS)) - { + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + Move *move = &pokemonInfo->moves.moves[moveIndex]; + if (!MoveFlagExists(move)) return FALSE; - } - if (move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN) - { + if (MoveFlagLinkChain(move) || MoveFlagDisabled(move) || MoveFlagSealed(move)) return FALSE; + + for (i = 0; i < MAX_MON_MOVES; i++) { + if (CanMonsterUseMove(pokemon, move, hasPPChecker)) + return TRUE; + move++; + if (move >= &pokemonInfo->moves.moves[MAX_MON_MOVES]) + break; + if (!(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) + break; } - if (move->moveFlags & MOVE_FLAG_DISABLED || - move->moveFlags2 & MOVE_FLAG_SEALED) - { - return FALSE; - } - goto initMoveIndex; - returnTrue: - return TRUE; - initMoveIndex: - i = 0; - goto checkMoveUsable; - incMoveIndex: - i++; - checkMoveUsable: - if (i >= MAX_MON_MOVES) - { - return FALSE; - } - if (CanMonsterUseMove(pokemon, move, hasPPChecker)) - { - goto returnTrue; - } - move++; - if ((u32) move >= (u32) &pokemonInfo->moves.struggleMoveFlags || !(move->moveFlags & MOVE_FLAG_SUBSEQUENT_IN_LINK_CHAIN)) - { - return FALSE; - } - goto incMoveIndex; + + return FALSE; } bool8 CanMonsterUseMove(Entity *pokemon, Move *move, bool8 hasPPChecker) @@ -223,7 +203,7 @@ bool8 CanMonsterUseMove(Entity *pokemon, Move *move, bool8 hasPPChecker) bool8 sub_805744C(Entity * pokemon, Move *move, bool8 param_3) { EntityInfo *entityInfo; - + entityInfo = pokemon->info; if (move->id != MOVE_REGULAR_ATTACK) { if (((move->moveFlags & MOVE_FLAG_DISABLED)) || ((move->moveFlags2 & MOVE_FLAG_EXISTS))) {