summaryrefslogtreecommitdiff
path: root/src/dungeon_range.c
diff options
context:
space:
mode:
authorSeth Barberee <seth.barberee@gmail.com>2021-12-19 16:38:51 -0600
committerGitHub <noreply@github.com>2021-12-19 16:38:51 -0600
commit8e1c66d8bd01807285b05d8333f36cd2d70e062c (patch)
treebb1bf94d56b770eca66780948ff9e05401967ed1 /src/dungeon_range.c
parent087405b9d975b447ef7b17afd1e73e449cc7881b (diff)
parent0369264407563b64d60c885f8bf79322b6f663c8 (diff)
Merge pull request #85 from AnonymousRandomPerson/master
More AI decomp
Diffstat (limited to 'src/dungeon_range.c')
-rw-r--r--src/dungeon_range.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/dungeon_range.c b/src/dungeon_range.c
new file mode 100644
index 0000000..facd71d
--- /dev/null
+++ b/src/dungeon_range.c
@@ -0,0 +1,48 @@
+#include "global.h"
+#include "dungeon_range.h"
+
+#include "dungeon_global_data.h"
+#include "dungeon_map_access.h"
+#include "map.h"
+
+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;
+ }
+}