summaryrefslogtreecommitdiff
path: root/src
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
parent087405b9d975b447ef7b17afd1e73e449cc7881b (diff)
Decomped CanTarget()
Diffstat (limited to 'src')
-rw-r--r--src/dungeon_ai_1.c74
-rw-r--r--src/dungeon_ai_items.c10
-rw-r--r--src/dungeon_movement.c1
-rw-r--r--src/dungeon_util_1.c4
4 files changed, 79 insertions, 10 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];
+}
diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c
index ce70182..94afb70 100644
--- a/src/dungeon_ai_items.c
+++ b/src/dungeon_ai_items.c
@@ -3,7 +3,9 @@
#include "constants/direction.h"
#include "constants/dungeon_action.h"
#include "constants/iq_skill.h"
+#include "constants/targeting.h"
#include "dungeon_action.h"
+#include "dungeon_ai_1.h"
#include "dungeon_ai_items.h"
#include "dungeon_capabilities.h"
#include "dungeon_capabilities_1.h"
@@ -26,19 +28,11 @@ enum ItemTargetFlag
ITEM_TARGET_ALLY = 1 << 1
};
-enum TargetCapability
-{
- TARGET_CAPABILITY_CANNOT_ATTACK,
- TARGET_CAPABILITY_CAN_TARGET,
- TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
-};
-
extern s32 CalculateFacingDir(struct Position*, struct Position*);
extern struct MapTile* GetMapTileAtPosition(s16, s16);
extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u8);
extern bool8 ToolboxEnabled(struct DungeonEntityData*);
extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *);
-extern bool8 CanTarget(struct DungeonEntity*, struct DungeonEntity*, bool8, bool8);
extern bool8 CanSee(struct DungeonEntity*, struct DungeonEntity*);
extern void TargetThrownItem(struct DungeonEntity*, struct DungeonEntity*, struct ItemSlot*, u8, bool8);
diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c
index 9ea894e..80bf2e5 100644
--- a/src/dungeon_movement.c
+++ b/src/dungeon_movement.c
@@ -5,6 +5,7 @@
#include "constants/direction.h"
#include "constants/iq_skill.h"
#include "constants/status.h"
+#include "constants/targeting.h"
#include "dungeon_ai_items.h"
#include "dungeon_capabilities_1.h"
#include "dungeon_global_data.h"
diff --git a/src/dungeon_util_1.c b/src/dungeon_util_1.c
index 32cc3ff..034bab6 100644
--- a/src/dungeon_util_1.c
+++ b/src/dungeon_util_1.c
@@ -128,7 +128,7 @@ bool8 IsMovingClient(struct DungeonEntity *pokemon)
switch (pokemonData->clientType)
{
case CLIENT_TYPE_CLIENT:
- case CLIENT_TYPE_DONT_MOVE:
+ case 0x3:
case 0x5:
case 0x6:
case 0x7:
@@ -161,7 +161,7 @@ bool8 IsMovingClient(struct DungeonEntity *pokemon)
return TRUE;
case CLIENT_TYPE_NONE:
case 0x2:
- case 0x4:
+ case CLIENT_TYPE_DONT_MOVE:
case 0xA:
case 0xB:
case 0xC: