From b1fc911965c584f5af6522849162527f41461b7c Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Tue, 14 Dec 2021 23:36:22 -0500 Subject: Decomped InSameRoom_2() --- src/dungeon_ai_items.c | 1 + src/dungeon_range.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ src/dungeon_visibility.c | 3 +-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/dungeon_range.c (limited to 'src') diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 18bcf42..f48edbd 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -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 diff --git a/src/dungeon_range.c b/src/dungeon_range.c new file mode 100644 index 0000000..d915677 --- /dev/null +++ b/src/dungeon_range.c @@ -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; + } +} diff --git a/src/dungeon_visibility.c b/src/dungeon_visibility.c index d258c99..862e1a0 100644 --- a/src/dungeon_visibility.c +++ b/src/dungeon_visibility.c @@ -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) -- cgit v1.2.3