From cd9a8c5a384124999e15626d9623b48f2687deba Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Mon, 13 Dec 2021 23:22:03 -0500 Subject: Decomped CanTarget() --- src/dungeon_ai_1.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/dungeon_ai_1.c (limited to 'src/dungeon_ai_1.c') 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]; +} -- cgit v1.2.3