summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/code_8057824.s4
-rw-r--r--asm/code_8070E3C.s (renamed from asm/code_8070D04.s)113
-rw-r--r--asm/code_80718D8.s2
-rw-r--r--data/data_8106A4C.s35
-rw-r--r--data/data_8106FB5.s31
-rw-r--r--include/dungeon_capabilities_1.h2
-rw-r--r--include/map.h48
-rwxr-xr-xld_script.txt4
-rw-r--r--src/dungeon_capabilities_1.c51
-rw-r--r--src/dungeon_util.c2
-rw-r--r--src/status_checks.c4
11 files changed, 120 insertions, 176 deletions
diff --git a/asm/code_8057824.s b/asm/code_8057824.s
index 84d3407..2856506 100644
--- a/asm/code_8057824.s
+++ b/asm/code_8057824.s
@@ -12949,7 +12949,7 @@ _0805E0C2:
mov r0, r10
adds r1, r5, 0
str r3, [sp, 0x20]
- bl CanMoveForward2
+ bl CanMoveInDirection
lsls r0, 24
ldr r3, [sp, 0x20]
cmp r0, 0
@@ -14878,7 +14878,7 @@ _0805EFF6:
bne _0805F008
mov r0, r8
adds r1, r4, 0
- bl CanMoveForward2
+ bl CanMoveInDirection
lsls r0, 24
cmp r0, 0
beq _0805F014
diff --git a/asm/code_8070D04.s b/asm/code_8070E3C.s
index ce9f343..7af381e 100644
--- a/asm/code_8070D04.s
+++ b/asm/code_8070E3C.s
@@ -1,115 +1,10 @@
#include "asm/constants/gba_constants.inc"
- #include "asm/macros.inc"
+ #include "asm/macros.inc"
- .syntax unified
-
- .text
-
- thumb_func_start CanMoveForward2
-CanMoveForward2:
- push {r4-r6,lr}
- adds r4, r0, 0
- adds r6, r1, 0
- ldr r0, [r4, 0x70]
- movs r1, 0x2
- ldrsh r0, [r0, r1]
- bl GetCrossableTerrain
- lsls r0, 24
- lsrs r5, r0, 24
- movs r2, 0x4
- ldrsh r0, [r4, r2]
- ldr r1, _08070DD8
- lsls r2, r6, 2
- adds r2, r1
- movs r3, 0
- ldrsh r1, [r2, r3]
- adds r0, r1
- movs r3, 0x6
- ldrsh r1, [r4, r3]
- movs r3, 0x2
- ldrsh r2, [r2, r3]
- adds r1, r2
- bl GetMapTileAtPosition
- adds r2, r0, 0
- ldrh r1, [r2]
- movs r0, 0x10
- ands r0, r1
- cmp r0, 0
- bne _08070E34
- ldr r0, [r2, 0x10]
- cmp r0, 0
- bne _08070E34
- bl IsFixedDungeon
- lsls r0, 24
- cmp r0, 0
- bne _08070E04
- ldr r0, [r4, 0x70]
- adds r0, 0xE4
- ldrb r0, [r0]
- cmp r0, 0x3
- beq _08070DD2
- adds r0, r4, 0
- movs r1, 0x9
- bl HasItem
- lsls r0, 24
- cmp r0, 0
- beq _08070DDC
-_08070DD2:
- movs r5, 0x3
- b _08070E04
- .align 2, 0
-_08070DD8: .4byte gAdjacentTileOffsets
-_08070DDC:
- adds r0, r4, 0
- movs r1, 0xC
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- bne _08070E02
- adds r0, r4, 0
- movs r1, 0xD
- bl HasIQSkill
- lsls r0, 24
- cmp r0, 0
- beq _08070E04
- movs r0, 0x1
- ands r0, r6
- movs r5, 0x3
- cmp r0, 0
- beq _08070E04
-_08070E02:
- movs r5, 0x2
-_08070E04:
- movs r1, 0x4
- ldrsh r0, [r4, r1]
- movs r2, 0x6
- ldrsh r1, [r4, r2]
- bl GetMapTileAtPosition
- adds r2, r0, 0
- adds r1, r2, 0
- adds r1, 0xA
- adds r1, r5
- ldr r2, _08070E30
- movs r0, 0x7
- ands r0, r6
- adds r0, r2
- ldrb r1, [r1]
- ldrb r0, [r0]
- ands r0, r1
- cmp r0, 0
- beq _08070E34
- movs r0, 0x1
- b _08070E36
- .align 2, 0
-_08070E30: .4byte gDirectionBitMasks
-_08070E34:
- movs r0, 0
-_08070E36:
- pop {r4-r6}
- pop {r1}
- bx r1
- thumb_func_end CanMoveForward2
+ .syntax unified
+ .text
+
thumb_func_start sub_8070E3C
sub_8070E3C:
push {r4-r7,lr}
diff --git a/asm/code_80718D8.s b/asm/code_80718D8.s
index 4ee7f09..030fd72 100644
--- a/asm/code_80718D8.s
+++ b/asm/code_80718D8.s
@@ -2652,7 +2652,7 @@ _08072F84:
bne _08072FCC
adds r0, r4, 0
adds r1, r3, 0
- bl CanMoveForward2
+ bl CanMoveInDirection
lsls r0, 24
cmp r0, 0
bne _08072FCC
diff --git a/data/data_8106A4C.s b/data/data_8106A4C.s
index 902cb73..d8e604b 100644
--- a/data/data_8106A4C.s
+++ b/data/data_8106A4C.s
@@ -362,38 +362,3 @@ gUnknown_8106F7C: @ 8106F7C
.global gUnknown_8106FA4
gUnknown_8106FA4: @ 8106FA4
.string "{COLOR_2}%c%s{END_COLOR_TEXT_2}\0"
-
- .global gDirectionBitMasks
-gDirectionBitMasks: @ 8106FAD
-@ replacing .incbin "baserom.gba", 0x00106fad, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gUnknown_8106FB5
-gUnknown_8106FB5: @ 8106FB5
-@ replacing .incbin "baserom.gba", 0x00106fb5, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gUnknown_8106FBD
-gUnknown_8106FBD: @ 8106FBD
-@ replacing .incbin "baserom.gba", 0x00106fbd, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gUnknown_8106FC5
-gUnknown_8106FC5: @ 8106FC5
-@ replacing .incbin "baserom.gba", 0x00106fc5, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gUnknown_8106FCD
-gUnknown_8106FCD: @ 8106FCD
-@ replacing .incbin "baserom.gba", 0x00106fcd, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gDirectionBitMasks_2
-gDirectionBitMasks_2: @ 8106FD5
-@ replacing .incbin "baserom.gba", 0x00106fd5, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-
- .global gDirectionBitMasks_3
-gDirectionBitMasks_3: @ 8106FDD
-@ replacing .incbin "baserom.gba", 0x00106fdd, 0x8
- .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
diff --git a/data/data_8106FB5.s b/data/data_8106FB5.s
new file mode 100644
index 0000000..dc32b18
--- /dev/null
+++ b/data/data_8106FB5.s
@@ -0,0 +1,31 @@
+ .section .rodata
+
+ .global gUnknown_8106FB5
+gUnknown_8106FB5: @ 8106FB5
+@ replacing .incbin "baserom.gba", 0x00106fb5, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+
+ .global gUnknown_8106FBD
+gUnknown_8106FBD: @ 8106FBD
+@ replacing .incbin "baserom.gba", 0x00106fbd, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+
+ .global gUnknown_8106FC5
+gUnknown_8106FC5: @ 8106FC5
+@ replacing .incbin "baserom.gba", 0x00106fc5, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+
+ .global gUnknown_8106FCD
+gUnknown_8106FCD: @ 8106FCD
+@ replacing .incbin "baserom.gba", 0x00106fcd, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+
+ .global gDirectionBitMasks_2
+gDirectionBitMasks_2: @ 8106FD5
+@ replacing .incbin "baserom.gba", 0x00106fd5, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+
+ .global gDirectionBitMasks_3
+gDirectionBitMasks_3: @ 8106FDD
+@ replacing .incbin "baserom.gba", 0x00106fdd, 0x8
+ .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
diff --git a/include/dungeon_capabilities_1.h b/include/dungeon_capabilities_1.h
index 1d10a0f..c19391b 100644
--- a/include/dungeon_capabilities_1.h
+++ b/include/dungeon_capabilities_1.h
@@ -7,5 +7,7 @@
bool8 CannotUseItems(struct DungeonEntity *pokemon);
// 0x70CD0
bool8 CannotAct(struct DungeonEntity *pokemon);
+// 0x70D6C
+bool8 CanMoveInDirection(struct DungeonEntity *pokemon, u32 facingDir);
#endif
diff --git a/include/map.h b/include/map.h
index bb991ff..9122f00 100644
--- a/include/map.h
+++ b/include/map.h
@@ -7,6 +7,27 @@
#define MAX_ROOM_COUNT 24 // Empirical max, not sure if the code supports any more.
#define CORRIDOR_ROOM_INDEX 0xFF
+enum TileType
+{
+ TILE_TYPE_FLOOR = 1 << 0,
+ TILE_TYPE_LIQUID = 1 << 1, // Water or lava depending on the dungeon.
+ TILE_TYPE_UNK_2 = 1 << 2,
+ TILE_TYPE_ROOM_EXIT = 1 << 3,
+ TILE_TYPE_MAP_EDGE = 1 << 4,
+ TILE_TYPE_SHOP = 1 << 5,
+ TILE_TYPE_MONSTER_HOUSE = 1 << 6,
+ TILE_TYPE_STAIRS = 1 << 9
+};
+
+enum CrossableTerrain
+{
+ CROSSABLE_TERRAIN_REGULAR = 0,
+ CROSSABLE_TERRAIN_LIQUID = 1,
+ CROSSABLE_TERRAIN_CREVICE = 2,
+ CROSSABLE_TERRAIN_WALL = 3,
+ NUM_CROSSABLE_TERRAIN
+};
+
struct MapTile
{
// Uses the TileType bit flags.
@@ -17,11 +38,8 @@ struct MapTile
u8 unk8;
/* 0x9 */ u8 roomIndex;
// Bitwise flags for whether Pokémon can move to an adjacent tile. Bits correspond to directions in direction.h.
- // Different sets of flags are used for Pokémon that can cross special terrain.
- /* 0xA */ u8 canMoveAdjacent;
- /* 0xB */ u8 canMoveAdjacentLiquid;
- /* 0xC */ u8 canMoveAdjacentCrevice;
- /* 0xD */ u8 canMoveAdjacentWall;
+ // Different sets of flags are used for Pokémon that can cross special terrain, corresponding to Cthe rossableTerrain enum.
+ /* 0xA */ u8 canMoveAdjacent[NUM_CROSSABLE_TERRAIN];
u8 fillE[0x10 - 0xE];
/* 0x10 */ struct DungeonEntity *pokemon; // Pokémon on the tile.
/* 0x14 */ struct DungeonEntity *mapObject; // Item or trap on the tile.
@@ -39,24 +57,4 @@ struct MapRoom
u8 fillA[0x1A - 0xA];
};
-enum TileType
-{
- TILE_TYPE_FLOOR = 1 << 0,
- TILE_TYPE_LIQUID = 1 << 1, // Water or lava depending on the dungeon.
- TILE_TYPE_UNK_2 = 1 << 2,
- TILE_TYPE_ROOM_EXIT = 1 << 3,
- TILE_TYPE_MAP_EDGE = 1 << 4,
- TILE_TYPE_SHOP = 1 << 5,
- TILE_TYPE_MONSTER_HOUSE = 1 << 6,
- TILE_TYPE_STAIRS = 1 << 9
-};
-
-enum CrossableTerrain
-{
- CROSSABLE_TERRAIN_REGULAR = 0,
- CROSSABLE_TERRAIN_LIQUID = 1,
- CROSSABLE_TERRAIN_CREVICE = 2,
- CROSSABLE_TERRAIN_WALL = 3,
-};
-
#endif
diff --git a/ld_script.txt b/ld_script.txt
index 23ea939..6562b0f 100755
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -214,7 +214,7 @@ SECTIONS {
src/dungeon_capabilities.o(.text);
asm/code_8070BC0.o(.text);
src/dungeon_capabilities_1.o(.text);
- asm/code_8070D04.o(.text);
+ asm/code_8070E3C.o(.text);
src/dungeon_ai.o(.text);
asm/code_8071518.o(.text);
src/dungeon_ai_1.o(.text);
@@ -400,6 +400,8 @@ SECTIONS {
data/data_80F59C8.o(.rodata);
src/charge_move.o(.rodata);
data/data_8106A4C.o(.rodata);
+ src/dungeon_capabilities_1.o(.rodata);
+ data/data_8106FB5.o(.rodata);
src/dungeon_ai_1.o(.rodata);
data/data_8107010.o(.rodata);
src/friend_area.o(.rodata);
diff --git a/src/dungeon_capabilities_1.c b/src/dungeon_capabilities_1.c
index 721bdcb..7ad12d8 100644
--- a/src/dungeon_capabilities_1.c
+++ b/src/dungeon_capabilities_1.c
@@ -2,10 +2,21 @@
#include "dungeon_capabilities_1.h"
#include "constants/dungeon.h"
+#include "constants/iq_skill.h"
#include "constants/status.h"
#include "charge_move.h"
#include "dungeon_ai.h"
#include "dungeon_capabilities.h"
+#include "dungeon_items.h"
+#include "dungeon_map_access.h"
+#include "dungeon_pokemon_attributes_1.h"
+#include "dungeon_util.h"
+#include "map.h"
+
+const u8 gDirectionBitMasks[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
+
+extern u8 GetCrossableTerrain(s16);
+extern bool8 IsFixedDungeon();
static inline bool8 JoinLocationCannotUseItems(struct DungeonEntityData *pokemonData)
{
@@ -75,3 +86,43 @@ bool8 CannotAttack(struct DungeonEntity *pokemon, bool8 skipSleep)
}
return TRUE;
}
+
+bool8 CanMoveInDirection(struct DungeonEntity *pokemon, u32 facingDir)
+{
+ u8 crossableTerrain = GetCrossableTerrain(pokemon->entityData->entityID);
+ struct MapTile *currentMapTile = GetMapTileAtPosition(pokemon->posWorld.x + gAdjacentTileOffsets[facingDir].x,
+ pokemon->posWorld.y + gAdjacentTileOffsets[facingDir].y);
+ if (currentMapTile->tileType & TILE_TYPE_MAP_EDGE || currentMapTile->pokemon != NULL)
+ {
+ return FALSE;
+ }
+ if (!IsFixedDungeon())
+ {
+ if (pokemon->entityData->transformStatus == TRANSFORM_STATUS_MOBILE || HasItem(pokemon, ITEM_ID_MOBILE_SCARF))
+ {
+ crossableTerrain = CROSSABLE_TERRAIN_WALL;
+ }
+ else if (HasIQSkill(pokemon, IQ_SKILL_ALL_TERRAIN_HIKER))
+ {
+ crossableTerrain = CROSSABLE_TERRAIN_CREVICE;
+ }
+ else if (HasIQSkill(pokemon, IQ_SKILL_SUPER_MOBILE))
+ {
+ if (facingDir & 1)
+ {
+ // Super Mobile can't break walls diagonally.
+ crossableTerrain = CROSSABLE_TERRAIN_CREVICE;
+ }
+ else
+ {
+ crossableTerrain = CROSSABLE_TERRAIN_WALL;
+ }
+ }
+ }
+ currentMapTile = GetMapTileAtPosition(pokemon->posWorld.x, pokemon->posWorld.y);
+ if (!(currentMapTile->canMoveAdjacent[crossableTerrain] & gDirectionBitMasks[facingDir & DIRECTION_MASK]))
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/src/dungeon_util.c b/src/dungeon_util.c
index 5b6bd5a..c5b5695 100644
--- a/src/dungeon_util.c
+++ b/src/dungeon_util.c
@@ -3,7 +3,7 @@
#include "dungeon_map_access.h"
-const struct Position gAdjacentTileOffsets[NUM_DIRECTIONS] = {
+const struct Position gAdjacentTileOffsets[] = {
{0, 1},
{1, 1},
{1, 0},
diff --git a/src/status_checks.c b/src/status_checks.c
index ed39e99..b371934 100644
--- a/src/status_checks.c
+++ b/src/status_checks.c
@@ -6,6 +6,7 @@
#include "constants/status.h"
#include "code_80521D0.h"
#include "dungeon_action.h"
+#include "dungeon_capabilities_1.h"
#include "dungeon_random.h"
extern char *gPtrFrozenMessage;
@@ -17,7 +18,6 @@ extern char *gPtrInfatuatedMessage;
extern char gAvailablePokemonNames[];
extern void SetMessageArgument(char[], struct DungeonEntity*, u32);
-extern bool8 CanMoveForward2(struct DungeonEntity*, u8);
extern void DecideAttack(struct DungeonEntity*);
bool8 HasStatusAffectingActions(struct DungeonEntity *pokemon)
@@ -74,7 +74,7 @@ bool8 HasStatusAffectingActions(struct DungeonEntity *pokemon)
}
if (pokemonData->eyesightStatus == EYESIGHT_STATUS_BLINKER)
{
- if (!CanMoveForward2(pokemon, pokemonData->action.facingDir))
+ if (!CanMoveInDirection(pokemon, pokemonData->action.facingDir))
{
if (DungeonRandomCapped(2) != 0)
{