Decomped InSameRoom_2()

This commit is contained in:
AnonymousRandomPerson 2021-12-14 23:36:22 -05:00
parent da8fcb2ac8
commit b1fc911965
13 changed files with 1973 additions and 1984 deletions

File diff suppressed because it is too large Load Diff

1879
asm/code_808333C.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
#define GUARD_DUNGEON_AI_ITEMS_H
#include "dungeon_entity.h"
#include "map.h"
#include "position.h"
// 0x73658
void DecideUseItem(struct DungeonEntity *pokemon);

View File

@ -3,7 +3,7 @@
#include "constants/move.h"
#include "item.h"
#include "map.h"
#include "position.h"
struct DungeonActionContainer
{

View File

@ -5,6 +5,7 @@
#include "dungeon_entity.h"
#include "global.h"
#include "map.h"
#include "position.h"
#define DUNGEON_MAX_SIZE_X 55
#define DUNGEON_MAX_SIZE_Y 31
@ -69,7 +70,9 @@ struct DungeonGlobalData
/* 0xE278 */ u8 waterSportTurnsLeft;
u8 fillE279[0xE8C0 - 0xE279];
/* 0xE8C0 */ u32 mapEntityPointers[DUNGEON_MAX_SIZE_X * DUNGEON_MAX_SIZE_Y];
u8 fill10364[0x10844 - 0x10364];
u8 fill10364[0x104C4 - 0x10364];
/* 0x104C4 */ struct MapRoom roomData[MAX_ROOM_COUNT];
u8 fill10604[0x10844 - 0x10764];
/* 0x10844 */ u16 numRoomExits[MAX_ROOM_COUNT];
u8 fill10874[0x10884 - 0x10874];
/* 0x10884 */ struct Position roomExits[MAX_ROOM_COUNT][32]; // Arrays of room exits for each room.

View File

@ -1,7 +1,7 @@
#ifndef GUARD_DUNGEON_POKEMON_SPRITES_H
#define GUARD_DUNGEON_POKEMON_SPRITES_H
#include "map.h"
#include "position.h"
struct DungeonPokemonStatusSprite
{

9
include/dungeon_range.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef GUARD_DUNGEON_RANGE_H
#define GUARD_DUNGEON_RANGE_H
#include "position.h"
// 0x83294
bool8 InSameRoom_2(struct Position *pos1, struct Position *pos2);
#endif

View File

@ -2,8 +2,10 @@
#define GUARD_MAP_H
#include "dungeon_entity.h"
#include "position.h"
#define MAX_ROOM_COUNT 24 // Empirical max, not sure if the code supports any more.
#define CORRIDOR_ROOM_INDEX 0xFF
struct MapTile
{
@ -25,25 +27,16 @@ struct MapTile
/* 0x14 */ struct DungeonEntity *mapObject; // Item or trap on the tile.
};
struct Position
{
s16 x;
s16 y;
};
struct Position32
{
s32 x;
s32 y;
};
struct MapRoom
{
u8 fill0[0x2 - 0x0];
// All coordinates are inclusive.
/* 0x2 */ struct Position start;
/* 0x6 */ struct Position end;
u8 fillA[0x1C - 0xA];
// These are not aligned properly to use the Position struct.
/* 0x2 */ s16 startX;
/* 0x4 */ s16 startY;
/* 0x6 */ s16 endX;
/* 0x8 */ s16 endY;
u8 fillA[0x1A - 0xA];
};
enum TileType

16
include/position.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef GUARD_POSITION_H
#define GUARD_POSITION_H
struct Position
{
s16 x;
s16 y;
};
struct Position32
{
s32 x;
s32 y;
};
#endif

View File

@ -219,6 +219,8 @@ SECTIONS {
asm/code_8073B78.o(.text);
src/dungeon_movement.o(.text);
asm/code_8075BA4.o(.text);
src/dungeon_range.o(.text);
asm/code_808333C.o(.text);
src/dungeon_random.o(.text);
asm/code_808411C.o(.text);
src/dungeon_random_1.o(.text);

View File

@ -17,6 +17,7 @@
#include "dungeon_util.h"
#include "dungeon_visibility.h"
#include "item.h"
#include "position.h"
#include "team_inventory.h"
#define NUM_POTENTIAL_ROCK_TARGETS 20

50
src/dungeon_range.c Normal file
View File

@ -0,0 +1,50 @@
#include "global.h"
#include "dungeon_range.h"
#include "dungeon_global_data.h"
#include "map.h"
extern struct DungeonGlobalData *gDungeonGlobalData;
extern struct MapTile* GetMapTileAtPosition(s16, s16);
bool8 InSameRoom_2(struct Position *pos1, struct Position *pos2)
{
u8 pos1RoomIndex;
u8 visibility = gDungeonGlobalData->visibility;
struct MapTile *tile1;
if (visibility == 0)
{
visibility = 2;
}
tile1 = GetMapTileAtPosition(pos1->x, pos1->y);
pos1RoomIndex = tile1->roomIndex;
if (pos1RoomIndex == CORRIDOR_ROOM_INDEX)
{
s32 xDiff = pos1->x - pos2->x;
s32 yDiff;
xDiff = xDiff < 0 ? -xDiff : xDiff;
if (xDiff > visibility)
{
return FALSE;
}
yDiff = pos1->y - pos2->y;
yDiff = yDiff < 0 ? -yDiff : yDiff;
if (yDiff > visibility)
{
return FALSE;
}
returnTrue:
return TRUE;
}
else
{
struct MapRoom *pos1Room = &gDungeonGlobalData->roomData[pos1RoomIndex];
if (pos1Room->startX - 1 > pos2->x || pos1Room->startY - 1 > pos2->y ||
pos1Room->endX + 1 <= pos2->x || pos1Room->endY + 1 <= pos2->y)
{
return FALSE;
}
goto returnTrue;
}
}

View File

@ -3,10 +3,9 @@
#include "constants/status.h"
#include "dungeon_pokemon_attributes_1.h"
#include "dungeon_range.h"
#include "dungeon_util.h"
extern bool8 InSameRoom_2(struct Position*, struct Position*);
bool8 CanSee(struct DungeonEntity *entity, struct DungeonEntity *targetEntity)
{
if (!EntityExists(entity) || !EntityExists(targetEntity) || !targetEntity->visible)