diff options
author | Seth Barberee <seth.barberee@gmail.com> | 2022-03-11 10:10:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 10:10:49 -0800 |
commit | 30fea2d6f303e0e57b62032f56da86c8223ef1f7 (patch) | |
tree | 9636ef46bb5f555874dc8ba16c82dc79bc563a12 /src/move_util.c | |
parent | ea1aa9c0c5c3a4167912d1078fffdd5e69cbbe98 (diff) | |
parent | cf492fd141b33c21f369dfa7aabebf3c52cb8ec1 (diff) |
Merge pull request #98 from AnonymousRandomPerson/master
Finished attack AI decomp
Diffstat (limited to 'src/move_util.c')
-rw-r--r-- | src/move_util.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/move_util.c b/src/move_util.c new file mode 100644 index 0000000..4487862 --- /dev/null +++ b/src/move_util.c @@ -0,0 +1,88 @@ +#include "global.h" +#include "move_util.h" + +#include "constants/move_id.h" +#include "constants/status.h" +#include "moves.h" + +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; +} + +bool8 IsMoveUsable(struct DungeonEntity *pokemon, struct PokemonMove *move, bool8 hasPPChecker) +{ + struct DungeonEntityData *pokemonData = pokemon->entityData; + if (move->moveID == MOVE_REGULAR_ATTACK) + { + return TRUE; + } + if (move->moveFlags & MOVE_FLAG_DISABLED || move->moveFlags2 & MOVE_FLAG_SEALED) + { + return FALSE; + } + if (hasPPChecker) + { + if (move->PP == 0) + { + return FALSE; + } + if (pokemonData->volatileStatus == VOLATILE_STATUS_TAUNTED && !MoveDealsDirectDamage(move)) + { + return FALSE; + } + if (pokemonData->volatileStatus == VOLATILE_STATUS_ENCORE) + { + if (move->moveID == MOVE_STRUGGLE) + { + if (!(pokemonData->struggleMoveFlags & MOVE_FLAG_LAST_USED)) + { + return FALSE; + } + } + else if (!(move->moveFlags & MOVE_FLAG_LAST_USED)) + { + return FALSE; + } + } + } + return TRUE; +} |