summaryrefslogtreecommitdiff
path: root/src/dungeon_ai_targeting_1.c
diff options
context:
space:
mode:
authorSeth Barberee <seth.barberee@gmail.com>2022-02-27 08:43:59 -0800
committerGitHub <noreply@github.com>2022-02-27 08:43:59 -0800
commitea1aa9c0c5c3a4167912d1078fffdd5e69cbbe98 (patch)
tree1d3f29615f1683fae77ade7d8713e7bfe5a11c26 /src/dungeon_ai_targeting_1.c
parent0dd38993f6a4383d6d5743fd0ae0abc01210ae25 (diff)
parenta5296a2f994a0f8e4421c4afd6bac1cedcfb72be (diff)
Merge pull request #97 from AnonymousRandomPerson/master
More attack AI decomp
Diffstat (limited to 'src/dungeon_ai_targeting_1.c')
-rw-r--r--src/dungeon_ai_targeting_1.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/dungeon_ai_targeting_1.c b/src/dungeon_ai_targeting_1.c
new file mode 100644
index 0000000..5ff76b0
--- /dev/null
+++ b/src/dungeon_ai_targeting_1.c
@@ -0,0 +1,62 @@
+#include "global.h"
+#include "dungeon_ai_targeting_1.h"
+
+#include "constants/ability.h"
+#include "constants/tactic.h"
+#include "dungeon_pokemon_attributes.h"
+#include "dungeon_util.h"
+
+extern void CheckRunAwayVisualFlag(struct DungeonEntity *, bool8 showRunAwayEffect);
+
+bool8 ShouldAvoidFirstHit(struct DungeonEntity *pokemon, bool8 forceAvoid)
+{
+ if (!HasTactic(pokemon, TACTIC_AVOID_THE_FIRST_HIT))
+ return FALSE;
+ if (!forceAvoid)
+ return FALSE;
+ return TRUE;
+}
+
+bool8 ShouldAvoidEnemies(struct DungeonEntity *pokemon)
+{
+ if (!EntityExists(pokemon))
+ {
+ return FALSE;
+ }
+ else
+ {
+ struct DungeonEntityData *pokemonData = pokemon->entityData;
+ if (pokemonData->terrifiedTurnsLeft != 0)
+ {
+ return TRUE;
+ }
+ if (pokemonData->isLeader)
+ {
+ return FALSE;
+ }
+ if (HasAbility(pokemon, ABILITY_RUN_AWAY))
+ {
+ bool8 runAwayActive = pokemonData->HP < pokemonData->maxHP / 2;
+ if (runAwayActive)
+ {
+ return TRUE;
+ }
+ }
+ if (HasTactic(pokemon, TACTIC_GET_AWAY) ||
+ (HasTactic(pokemon, TACTIC_AVOID_TROUBLE) && pokemonData->HP <= pokemonData->maxHP / 2))
+ {
+ return TRUE;
+ }
+ return FALSE;
+ }
+}
+
+bool8 ShouldAvoidEnemiesAndShowEffect(struct DungeonEntity *pokemon, bool8 showRunAwayEffect)
+{
+ if (ShouldAvoidEnemies(pokemon))
+ {
+ CheckRunAwayVisualFlag(pokemon, showRunAwayEffect);
+ return TRUE;
+ }
+ return FALSE;
+}