summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/code_8071518.s197
-rw-r--r--asm/code_807167C.s76
-rw-r--r--data/data_80F4278.s25
-rw-r--r--include/constants/status.h4
-rw-r--r--include/constants/targeting.h12
-rw-r--r--include/dungeon_ai_1.h9
-rw-r--r--include/dungeon_entity.h9
-rwxr-xr-xld_script.txt2
-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
12 files changed, 205 insertions, 218 deletions
diff --git a/asm/code_8071518.s b/asm/code_8071518.s
index 2aac9db..4a5f226 100644
--- a/asm/code_8071518.s
+++ b/asm/code_8071518.s
@@ -51,199 +51,4 @@ _08071590:
bx r0
thumb_func_end CheckRunAwayVisualFlag
- thumb_func_start CanTarget
-CanTarget:
- push {r4-r6,lr}
- adds r6, r0, 0
- lsls r2, 24
- lsrs r2, 24
- lsls r3, 24
- lsrs r3, 24
- ldr r5, [r6, 0x70]
- ldr r4, [r1, 0x70]
- cmp r6, r1
- bne _080715B0
- movs r0, 0
- b _08071670
-_080715B0:
- ldrb r0, [r5, 0x8]
- cmp r0, 0x1
- beq _08071606
- ldrb r0, [r4, 0x8]
- cmp r0, 0x1
- beq _08071606
- adds r0, r5, 0
- adds r0, 0xA4
- ldrb r1, [r0]
- cmp r1, 0x4
- beq _08071606
- adds r0, r4, 0
- adds r0, 0xA4
- ldrb r0, [r0]
- cmp r0, 0x4
- beq _08071606
- cmp r1, 0x1
- beq _08071606
- cmp r0, 0x1
- beq _08071606
- cmp r3, 0
- beq _080715EC
- ldrb r0, [r5, 0x6]
- cmp r0, 0
- bne _080715EC
- adds r0, r4, 0
- adds r0, 0xB0
- ldrb r0, [r0]
- cmp r0, 0x6
- beq _08071606
-_080715EC:
- cmp r2, 0
- bne _0807160A
- adds r0, r4, 0
- adds r0, 0xE4
- ldrb r0, [r0]
- cmp r0, 0x1
- bne _0807160A
- adds r0, r6, 0
- bl CanSeeInvisible
- lsls r0, 24
- cmp r0, 0
- bne _0807160A
-_08071606:
- movs r0, 0x2
- b _08071670
-_0807160A:
- movs r1, 0x80
- lsls r1, 1
- adds r0, r5, r1
- ldrb r0, [r0]
- movs r6, 0
- cmp r0, 0
- beq _08071620
- movs r6, 0x2
- cmp r0, 0x1
- bne _08071620
- movs r6, 0x1
-_08071620:
- ldrb r0, [r5, 0x8]
- cmp r0, 0
- beq _08071630
- movs r5, 0
- cmp r0, 0x3
- bne _08071638
- movs r5, 0x1
- b _08071638
-_08071630:
- ldrb r1, [r5, 0x6]
- negs r0, r1
- orrs r0, r1
- lsrs r5, r0, 31
-_08071638:
- ldrb r0, [r4, 0x8]
- cmp r0, 0
- beq _08071648
- movs r1, 0
- cmp r0, 0x3
- bne _08071650
- movs r1, 0x1
- b _08071650
-_08071648:
- ldrb r1, [r4, 0x6]
- negs r0, r1
- orrs r0, r1
- lsrs r1, r0, 31
-_08071650:
- movs r3, 0
- adds r0, r4, 0
- adds r0, 0xC8
- ldrb r0, [r0]
- cmp r0, 0x2
- bne _0807165E
- movs r3, 0x1
-_0807165E:
- ldr r2, _08071678
- lsls r0, r1, 1
- adds r0, r3, r0
- lsls r1, r5, 2
- adds r0, r1
- lsls r1, r6, 3
- adds r0, r1
- adds r0, r2
- ldrb r0, [r0]
-_08071670:
- pop {r4-r6}
- pop {r1}
- bx r1
- .align 2, 0
-_08071678: .4byte gUnknown_8106FE5
- thumb_func_end CanTarget
-
- thumb_func_start sub_807167C
-sub_807167C:
- push {lr}
- ldr r2, [r0, 0x70]
- ldr r1, [r1, 0x70]
- adds r0, r2, 0
- adds r0, 0xA4
- ldrb r0, [r0]
- cmp r0, 0x1
- beq _080716D2
- adds r0, r2, 0
- adds r0, 0x40
- ldrb r0, [r0]
- cmp r0, 0x4A
- beq _0807169A
- cmp r0, 0x47
- bne _0807169E
-_0807169A:
- movs r0, 0x1
- b _080716A0
-_0807169E:
- movs r0, 0
-_080716A0:
- cmp r0, 0
- bne _080716D2
- ldrb r0, [r2, 0x8]
- cmp r0, 0
- bne _080716D2
- adds r0, r1, 0
- adds r0, 0xA4
- ldrb r0, [r0]
- cmp r0, 0x1
- beq _080716D2
- adds r0, r1, 0
- adds r0, 0x40
- ldrb r0, [r0]
- cmp r0, 0x4A
- beq _080716C2
- cmp r0, 0x47
- bne _080716C6
-_080716C2:
- movs r0, 0x1
- b _080716C8
-_080716C6:
- movs r0, 0
-_080716C8:
- cmp r0, 0
- bne _080716D2
- ldrb r0, [r1, 0x8]
- cmp r0, 0
- beq _080716D6
-_080716D2:
- movs r0, 0x2
- b _080716E4
-_080716D6:
- ldrb r0, [r2, 0x6]
- ldrb r1, [r1, 0x6]
- cmp r0, r1
- bne _080716E2
- movs r0, 0
- b _080716E4
-_080716E2:
- movs r0, 0x1
-_080716E4:
- pop {r1}
- bx r1
- thumb_func_end sub_807167C
-
- .align 2, 0
+ .align 2, 0 \ No newline at end of file
diff --git a/asm/code_807167C.s b/asm/code_807167C.s
new file mode 100644
index 0000000..acb27c6
--- /dev/null
+++ b/asm/code_807167C.s
@@ -0,0 +1,76 @@
+ .include "constants/gba_constants.inc"
+ .include "asm/macros.inc"
+
+ .syntax unified
+
+ .text
+
+ thumb_func_start sub_807167C
+sub_807167C:
+ push {lr}
+ ldr r2, [r0, 0x70]
+ ldr r1, [r1, 0x70]
+ adds r0, r2, 0
+ adds r0, 0xA4
+ ldrb r0, [r0]
+ cmp r0, 0x1
+ beq _080716D2
+ adds r0, r2, 0
+ adds r0, 0x40
+ ldrb r0, [r0]
+ cmp r0, 0x4A
+ beq _0807169A
+ cmp r0, 0x47
+ bne _0807169E
+_0807169A:
+ movs r0, 0x1
+ b _080716A0
+_0807169E:
+ movs r0, 0
+_080716A0:
+ cmp r0, 0
+ bne _080716D2
+ ldrb r0, [r2, 0x8]
+ cmp r0, 0
+ bne _080716D2
+ adds r0, r1, 0
+ adds r0, 0xA4
+ ldrb r0, [r0]
+ cmp r0, 0x1
+ beq _080716D2
+ adds r0, r1, 0
+ adds r0, 0x40
+ ldrb r0, [r0]
+ cmp r0, 0x4A
+ beq _080716C2
+ cmp r0, 0x47
+ bne _080716C6
+_080716C2:
+ movs r0, 0x1
+ b _080716C8
+_080716C6:
+ movs r0, 0
+_080716C8:
+ cmp r0, 0
+ bne _080716D2
+ ldrb r0, [r1, 0x8]
+ cmp r0, 0
+ beq _080716D6
+_080716D2:
+ movs r0, 0x2
+ b _080716E4
+_080716D6:
+ ldrb r0, [r2, 0x6]
+ ldrb r1, [r1, 0x6]
+ cmp r0, r1
+ bne _080716E2
+ movs r0, 0
+ b _080716E4
+_080716E2:
+ movs r0, 0x1
+_080716E4:
+ pop {r1}
+ bx r1
+ thumb_func_end sub_807167C
+
+ .align 2, 0
diff --git a/data/data_80F4278.s b/data/data_80F4278.s
index 036c63a..8487e01 100644
--- a/data/data_80F4278.s
+++ b/data/data_80F4278.s
@@ -1,4 +1,5 @@
-#include "constants/status.h"
+.include "include/constants/status.h"
+.include "include/constants/targeting.h"
.section .rodata
.global gUnknown_80F42D0
@@ -7840,9 +7841,25 @@ gDirectionBitMasks_3: @ 8106FDD
@ replacing .incbin "baserom.gba", 0x00106fdd, 0x8
.byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
- .global gUnknown_8106FE5
-gUnknown_8106FE5: @ 8106FE5
- .incbin "baserom.gba", 0x106FE5, 0x2B
+ .global gTargetingData
+gTargetingData: @ 8106FE5
+@ replacing .incbin "baserom.gba", 0x106FE5, 0x2B
+ .byte TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET
+ .byte TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET
+ .byte TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET
+ .byte TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET
+ .byte TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+ .byte TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET
+
+ .byte 0x00, 0x00, 0x00
+ .string "pksdir0\0"
+ .string "pksdir0\0"
.global gUnknown_8107010
gUnknown_8107010: @ 8107010
diff --git a/include/constants/status.h b/include/constants/status.h
index 19b860b..cf911c0 100644
--- a/include/constants/status.h
+++ b/include/constants/status.h
@@ -94,10 +94,6 @@
#define MUZZLED_STATUS_NONE 0
#define MUZZLED_STATUS_MUZZLED 1
-#define TARGETING_DECOY_NONE 0
-#define TARGETING_DECOY_TEAM 1
-#define TARGETING_DECOY_WILD 2
-
#define STATUS_SPRITE_SLEEPLESS (1 << 0)
#define STATUS_SPRITE_BURNED (1 << 1)
#define STATUS_SPRITE_POISONED (1 << 2)
diff --git a/include/constants/targeting.h b/include/constants/targeting.h
new file mode 100644
index 0000000..6140716
--- /dev/null
+++ b/include/constants/targeting.h
@@ -0,0 +1,12 @@
+#ifndef GUARD_CONSTANTS_TARGETING_H
+#define GUARD_CONSTANTS_TARGETING_H
+
+#define TARGETING_DECOY_NONE 0
+#define TARGETING_DECOY_TEAM 1
+#define TARGETING_DECOY_WILD 2
+
+#define TARGET_CAPABILITY_CANNOT_ATTACK 0
+#define TARGET_CAPABILITY_CAN_TARGET 1
+#define TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET 2
+
+#endif
diff --git a/include/dungeon_ai_1.h b/include/dungeon_ai_1.h
new file mode 100644
index 0000000..dace65a
--- /dev/null
+++ b/include/dungeon_ai_1.h
@@ -0,0 +1,9 @@
+#ifndef GUARD_DUNGEON_AI_1_H
+#define GUARD_DUNGEON_AI_1_H
+
+#include "dungeon_entity.h"
+
+// 0x71598
+u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified);
+
+#endif
diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h
index b894a2f..29e3112 100644
--- a/include/dungeon_entity.h
+++ b/include/dungeon_entity.h
@@ -287,10 +287,11 @@ enum MovementFlag
enum ShopkeeperMode
{
- SHOPKEEPER_FRIENDLY = 1,
+ SHOPKEEPER_NONE,
+ SHOPKEEPER_FRIENDLY,
// These two modes trigger if an explosion damages the shopkeeper. The shopkeeper attacks the side that damaged it.
- SHOPKEEPER_AGGRESSIVE_TO_WILD = 2,
- SHOPKEEPER_AGGRESSIVE_TO_PLAYER = 3
+ SHOPKEEPER_AGGRESSIVE_TO_WILD,
+ SHOPKEEPER_AGGRESSIVE_TO_PLAYER
};
enum MovementAction
@@ -308,7 +309,7 @@ enum ClientType
{
CLIENT_TYPE_NONE = 0,
CLIENT_TYPE_CLIENT = 1, // Used for mission clients that need rescuing.
- CLIENT_TYPE_DONT_MOVE = 3 // Used for Diglett in the Skarmory boss fight.
+ CLIENT_TYPE_DONT_MOVE = 4 // Used for Diglett in the Skarmory boss fight.
};
enum VisualFlag
diff --git a/ld_script.txt b/ld_script.txt
index 86511b9..e9a805b 100755
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -207,6 +207,8 @@ SECTIONS {
asm/code_8070D04.o(.text);
src/dungeon_ai.o(.text);
asm/code_8071518.o(.text);
+ src/dungeon_ai_1.o(.text);
+ asm/code_807167C.o(.text);
src/dungeon_pokemon_attributes.o(.text);
asm/code_8071858.o(.text);
src/dungeon_pokemon_attributes_1.o(.text);
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: