summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/code_80494EC.s59
-rw-r--r--include/dungeon_ai_item_weight.h2
-rw-r--r--include/dungeon_util.h4
-rwxr-xr-xld_script.txt3
-rw-r--r--src/data/adjacent_tile_offsets.h17
-rw-r--r--src/dungeon_ai_attack.c2
-rw-r--r--src/dungeon_ai_item_weight.c21
-rw-r--r--src/dungeon_util.c11
8 files changed, 39 insertions, 80 deletions
diff --git a/asm/code_80494EC.s b/asm/code_80494EC.s
deleted file mode 100644
index a38b22b..0000000
--- a/asm/code_80494EC.s
+++ /dev/null
@@ -1,59 +0,0 @@
- #include "asm/constants/gba_constants.inc"
- #include "asm/macros.inc"
-
- .syntax unified
-
- .text
-
- thumb_func_start CanTargetAdjacentPokemon
-CanTargetAdjacentPokemon:
- push {r4-r6,lr}
- adds r5, r0, 0
- movs r6, 0
-_080494F2:
- movs r1, 0x4
- ldrsh r0, [r5, r1]
- ldr r1, _08049538
- lsls r2, r6, 2
- adds r2, r1
- movs r3, 0
- ldrsh r1, [r2, r3]
- adds r0, r1
- movs r3, 0x6
- ldrsh r1, [r5, r3]
- movs r3, 0x2
- ldrsh r2, [r2, r3]
- adds r1, r2
- bl GetMapTileAtPosition
- ldr r4, [r0, 0x10]
- cmp r4, 0
- beq _0804953C
- adds r0, r4, 0
- bl GetEntityType
- cmp r0, 0
- beq _0804953C
- adds r0, r5, 0
- adds r1, r4, 0
- movs r2, 0
- movs r3, 0x1
- bl CanTarget
- lsls r0, 24
- lsrs r0, 24
- cmp r0, 0x1
- bne _0804953C
- movs r0, 0x1
- b _08049544
- .align 2, 0
-_08049538: .4byte gAdjacentTileOffsets
-_0804953C:
- adds r6, 0x1
- cmp r6, 0x7
- ble _080494F2
- movs r0, 0
-_08049544:
- pop {r4-r6}
- pop {r1}
- bx r1
- thumb_func_end CanTargetAdjacentPokemon
-
- .align 2, 0 \ No newline at end of file
diff --git a/include/dungeon_ai_item_weight.h b/include/dungeon_ai_item_weight.h
index 705c0ca..a498744 100644
--- a/include/dungeon_ai_item_weight.h
+++ b/include/dungeon_ai_item_weight.h
@@ -5,5 +5,7 @@
// 0x48F28
u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 itemTargetFlags);
+// 0x494EC
+bool8 CanTargetAdjacentPokemon(struct DungeonEntity *pokemon);
#endif
diff --git a/include/dungeon_util.h b/include/dungeon_util.h
index 82d44ba..4d91b29 100644
--- a/include/dungeon_util.h
+++ b/include/dungeon_util.h
@@ -1,7 +1,11 @@
#ifndef GUARD_DUNGEON_UTIL_H
#define GUARD_DUNGEON_UTIL_H
+#include "constants/direction.h"
#include "dungeon_entity.h"
+#include "position.h"
+
+extern const struct Position gAdjacentTileOffsets[NUM_DIRECTIONS];
// 0x450E0
bool8 EntityExists(struct DungeonEntity *pokemon);
diff --git a/ld_script.txt b/ld_script.txt
index c3dd6af..46e4fa2 100755
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -197,7 +197,6 @@ SECTIONS {
src/code_8048480.o(.text);
asm/code_8048480.o(.text);
src/dungeon_ai_item_weight.o(.text);
- asm/code_80494EC.o(.text);
src/dungeon_map_access.o(.text);
asm/code_8049590.o(.text);
src/code_80521D0.o(.text);
@@ -392,7 +391,7 @@ SECTIONS {
data/personality_test.o(.rodata);
src/personality_test.o(.rodata);
data/data_80F4278.o(.rodata);
- src/dungeon_ai_attack.o(.rodata);
+ src/dungeon_util.o(.rodata);
data/data_80F4468.o(.rodata);
src/dungeon_pokemon_attributes_1.o(.rodata);
data/data_80F59C8.o(.rodata);
diff --git a/src/data/adjacent_tile_offsets.h b/src/data/adjacent_tile_offsets.h
deleted file mode 100644
index e96b771..0000000
--- a/src/data/adjacent_tile_offsets.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H
-#define GUARD_CONSTANTS_ADJACENT_TILE_OFFSETS_H
-
-#include "position.h"
-
-const struct Position gAdjacentTileOffsets[8] = {
- {0, 1},
- {1, 1},
- {1, 0},
- {1, -1},
- {0, -1},
- {-1, -1},
- {-1, 0},
- {-1, 1}
-};
-
-#endif \ No newline at end of file
diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c
index eaefbd9..5794038 100644
--- a/src/dungeon_ai_attack.c
+++ b/src/dungeon_ai_attack.c
@@ -2,10 +2,10 @@
#include "dungeon_ai_attack.h"
#include "constants/iq_skill.h"
-#include "data/adjacent_tile_offsets.h"
#include "dungeon_global_data.h"
#include "dungeon_map_access.h"
#include "dungeon_pokemon_attributes_1.h"
+#include "dungeon_util.h"
bool8 IsTargetStraightAhead(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, s32 facingDir, s32 maxRange)
{
diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c
index 175b0c2..2f497cc 100644
--- a/src/dungeon_ai_item_weight.c
+++ b/src/dungeon_ai_item_weight.c
@@ -2,11 +2,14 @@
#include "dungeon_ai_item_weight.h"
#include "constants/status.h"
+#include "constants/targeting.h"
+#include "dungeon_ai_1.h"
+#include "dungeon_map_access.h"
#include "dungeon_pokemon_attributes_1.h"
+#include "dungeon_util.h"
#include "moves.h"
#include "number_util.h"
-extern bool8 CanTargetAdjacentPokemon(struct DungeonEntity*);
extern bool8 HasNegativeStatus(struct DungeonEntity*);
u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32 itemTargetFlags)
@@ -440,3 +443,19 @@ u32 EvaluateItem(struct DungeonEntity *targetPokemon, struct ItemSlot *item, u32
}
return itemWeight;
}
+
+bool8 CanTargetAdjacentPokemon(struct DungeonEntity *pokemon)
+{
+ s32 facingDir;
+ for (facingDir = 0; facingDir < NUM_DIRECTIONS; facingDir++)
+ {
+ struct MapTile *mapTile = GetMapTileAtPosition(pokemon->posWorld.x + gAdjacentTileOffsets[facingDir].x, pokemon->posWorld.y + gAdjacentTileOffsets[facingDir].y);
+ struct DungeonEntity *adjacentPokemon = mapTile->pokemon;
+ if (adjacentPokemon != NULL && GetEntityType(adjacentPokemon) != ENTITY_NONE &&
+ CanTarget(pokemon, adjacentPokemon, FALSE, TRUE) == TARGET_CAPABILITY_CAN_TARGET)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
diff --git a/src/dungeon_util.c b/src/dungeon_util.c
index 3594274..5b6bd5a 100644
--- a/src/dungeon_util.c
+++ b/src/dungeon_util.c
@@ -3,6 +3,17 @@
#include "dungeon_map_access.h"
+const struct Position gAdjacentTileOffsets[NUM_DIRECTIONS] = {
+ {0, 1},
+ {1, 1},
+ {1, 0},
+ {1, -1},
+ {0, -1},
+ {-1, -1},
+ {-1, 0},
+ {-1, 1}
+};
+
extern struct MapTile* GetMapEntity(s16, s16);
bool8 EntityExists(struct DungeonEntity *entity)