From 0784f9fa740f697ecf1ef32c809014304603a8a4 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 10 Aug 2024 21:40:57 -0700 Subject: [PATCH] Added checkobjectat --- asm/macros/event.inc | 7 +++++++ data/specials.inc | 1 + src/field_specials.c | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index c6e6e8847a..0fb6414f61 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2334,3 +2334,10 @@ setvar VAR_0x8001, \posType special GetObjectPosition .endm + + @ checks if there is any object at a given position + .macro checkobjectat x:req, y:req + setorcopyvar VAR_0x8005, \x + setorcopyvar VAR_0x8006, \y + specialvar VAR_RESULT, CheckObjectAtXY + .endm diff --git a/data/specials.inc b/data/specials.inc index 32f2f63308..aa994a31f6 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -555,3 +555,4 @@ gSpecials:: def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs def_special GetObjectPosition + def_special CheckObjectAtXY diff --git a/src/field_specials.c b/src/field_specials.c index 471d88132c..3014d48407 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4294,3 +4294,19 @@ void GetObjectPosition(void) *y = objTemplate->y; } } + +// special to check if there is any object at a given position +u16 CheckObjectAtXY(void) +{ + u16 x = gSpecialVar_0x8005 + 7; + u16 y = gSpecialVar_0x8006 + 7; + u32 i; + + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + { + if (gObjectEvents[i].active && gObjectEvents[i].currentCoords.x == x && gObjectEvents[i].currentCoords.y == y) + return TRUE; + } + return FALSE; +} +