From 951b01114ab85800db8ed7f4a1034e2bd303e712 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 9 Mar 2022 21:50:15 -0500 Subject: Decomped IsMoveIndexUsable --- src/dungeon_ai_attack.c | 4 ++-- src/move_util.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/move_util.c (limited to 'src') diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 3e2a9f3..f55c20d 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -23,6 +23,7 @@ #include "dungeon_random_1.h" #include "dungeon_util.h" #include "dungeon_visibility.h" +#include "move_util.h" #include "moves.h" #include "position_util.h" #include "status_checker.h" @@ -42,7 +43,6 @@ extern s32 gPotentialAttackTargetWeights[NUM_DIRECTIONS]; extern u8 gPotentialAttackTargetDirections[NUM_DIRECTIONS]; extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS]; -extern bool8 IsMoveUsable_1(struct DungeonEntity*, s32, bool8); extern bool8 TargetRegularAttack(struct DungeonEntity*, u32*, bool8); void DecideAttack(struct DungeonEntity *pokemon) @@ -182,7 +182,7 @@ void DecideAttack(struct DungeonEntity *pokemon) move = &pokemonData->moves[i]; if (move->moveFlags & MOVE_FLAG_EXISTS && willNotUnlinkMove[i] && - IsMoveUsable_1(pokemon, i, hasPPChecker) && + IsMoveIndexUsable(pokemon, i, hasPPChecker) && move->moveFlags & MOVE_FLAG_ENABLED) { moveTargetResults[i].moveUsable = TRUE; diff --git a/src/move_util.c b/src/move_util.c new file mode 100644 index 0000000..c5c87ad --- /dev/null +++ b/src/move_util.c @@ -0,0 +1,47 @@ +#include "global.h" +#include "move_util.h" + +extern bool8 IsMoveUsable(struct DungeonEntity *pokemon, struct PokemonMove *move, bool8 hasPPChecker); + +bool8 IsMoveIndexUsable(struct DungeonEntity *pokemon, s32 moveIndex, bool8 hasPPChecker) +{ + struct DungeonEntityData *pokemonData = pokemon->entityData; + struct PokemonMove *move = &pokemonData->moves[moveIndex]; + s32 i; + if (!(move->moveFlags & MOVE_FLAG_EXISTS)) + { + return FALSE; + } + if (move->moveFlags & MOVE_FLAG_LINKED) + { + return FALSE; + } + 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 (IsMoveUsable(pokemon, move, hasPPChecker)) + { + goto returnTrue; + } + move++; + if ((u32) move >= (u32) &pokemonData->struggleMoveFlags || !(move->moveFlags & MOVE_FLAG_LINKED)) + { + return FALSE; + } + goto incMoveIndex; +} -- cgit v1.2.3