summaryrefslogtreecommitdiff
path: root/src/dungeon_ai_1.c
diff options
context:
space:
mode:
authorAnonymousRandomPerson <chenghanngan.us@gmail.com>2021-12-13 23:22:03 -0500
committerAnonymousRandomPerson <chenghanngan.us@gmail.com>2021-12-14 22:54:03 -0500
commitcd9a8c5a384124999e15626d9623b48f2687deba (patch)
tree096eef1adbb2781332d71cce238d0d2614b9feee /src/dungeon_ai_1.c
parent087405b9d975b447ef7b17afd1e73e449cc7881b (diff)
Decomped CanTarget()
Diffstat (limited to 'src/dungeon_ai_1.c')
-rw-r--r--src/dungeon_ai_1.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/dungeon_ai_1.c b/src/dungeon_ai_1.c
new file mode 100644
index 0000000..7d45909
--- /dev/null
+++ b/src/dungeon_ai_1.c
@@ -0,0 +1,74 @@
+#include "global.h"
+#include "dungeon_ai_1.h"
+
+#include "constants/status.h"
+#include "constants/targeting.h"
+
+extern bool8 CanSeeInvisible(struct DungeonEntity*);
+extern bool8 gTargetingData[3][2][2][2];
+
+u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified)
+{
+ struct DungeonEntityData *pokemonData = pokemon->entityData;
+ struct DungeonEntityData *targetData = targetPokemon->entityData;
+ u8 targetingDecoy;
+ u8 pokemonTargetingDecoy;
+ bool8 pokemonIsEnemy;
+ bool8 targetIsEnemy;
+ bool8 targetIsDecoy;
+ if (pokemon == targetPokemon)
+ {
+ return TARGET_CAPABILITY_CANNOT_ATTACK;
+ }
+ if (pokemonData->shopkeeperMode == SHOPKEEPER_FRIENDLY ||
+ targetData->shopkeeperMode == SHOPKEEPER_FRIENDLY ||
+ pokemonData->clientType == CLIENT_TYPE_DONT_MOVE ||
+ targetData->clientType == CLIENT_TYPE_DONT_MOVE ||
+ pokemonData->clientType == CLIENT_TYPE_CLIENT ||
+ targetData->clientType == CLIENT_TYPE_CLIENT ||
+ (checkPetrified && !pokemonData->isEnemy && targetData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) ||
+ (!ignoreInvisible && targetData->transformStatus == TRANSFORM_STATUS_INVISIBLE && !CanSeeInvisible(pokemon)))
+ {
+ return TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET;
+ }
+ pokemonTargetingDecoy = pokemonData->targetingDecoy;
+ targetingDecoy = TARGETING_DECOY_NONE;
+ if (pokemonTargetingDecoy != TARGETING_DECOY_NONE)
+ {
+ targetingDecoy = TARGETING_DECOY_WILD;
+ if (pokemonTargetingDecoy == TARGETING_DECOY_TEAM)
+ {
+ targetingDecoy = TARGETING_DECOY_TEAM;
+ }
+ }
+ if (pokemonData->shopkeeperMode != SHOPKEEPER_NONE)
+ {
+ pokemonIsEnemy = FALSE;
+ if (pokemonData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER)
+ {
+ pokemonIsEnemy = TRUE;
+ }
+ }
+ else
+ {
+ pokemonIsEnemy = pokemonData->isEnemy ? TRUE : FALSE;
+ }
+ if (targetData->shopkeeperMode != SHOPKEEPER_NONE)
+ {
+ targetIsEnemy = FALSE;
+ if (targetData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER)
+ {
+ targetIsEnemy = TRUE;
+ }
+ }
+ else
+ {
+ targetIsEnemy = targetData->isEnemy ? TRUE : FALSE;
+ }
+ targetIsDecoy = FALSE;
+ if (targetData->waitingStatus == WAITING_STATUS_DECOY)
+ {
+ targetIsDecoy = TRUE;
+ }
+ return gTargetingData[targetingDecoy][pokemonIsEnemy][targetIsEnemy][targetIsDecoy];
+}