Modified getobjectxy to allow for custom destinations

This commit is contained in:
pkmnsnfrn 2024-09-14 07:48:24 -07:00
parent 1665423e52
commit 60fb0b34fd
4 changed files with 19 additions and 15 deletions

View file

@ -2345,23 +2345,29 @@
.2byte \itemId
.endm
@ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will take the object's template position.
.macro getobjectxy localId:req, posType:req
@ Stores the position of the given object in destX and destY. Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will take the object's template position.
.macro getobjectxy localId:req, posType:req, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm
.macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION
.macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm
.macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION
.macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm
@ Return TRUE to dest if there is an object at the position x and y.

View file

@ -33,7 +33,7 @@ void ResetFanClub(void);
bool8 ShouldShowBoxWasFullMessage(void);
void SetPCBoxToSendMon(u8 boxId);
void PreparePartyForSkyBattle(void);
void GetObjectPosition(u32, u32);
void GetObjectPosition(u16*, u16*, u32, u32);
bool32 CheckObjectAtXY(u32, u32);
bool32 CheckPartyHasSpecie(u32);

View file

@ -4278,26 +4278,23 @@ void PreparePartyForSkyBattle(void)
CompactPartySlots();
}
void GetObjectPosition(u32 localId, u32 useTemplate)
void GetObjectPosition(u16* xPointer, u16* yPointer, u32 localId, u32 useTemplate)
{
u32 objectId;
struct ObjectEvent* objEvent;
u16 *x = &gSpecialVar_0x8007;
u16 *y = &gSpecialVar_0x8008;
if (useTemplate)
{
const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount);
*x = objTemplate->x;
*y = objTemplate->y;
*xPointer = objTemplate->x;
*yPointer = objTemplate->y;
return;
}
objectId = GetObjectEventIdByLocalId(localId);
objEvent = &gObjectEvents[objectId];
*x = objEvent->currentCoords.x - 7;
*y = objEvent->currentCoords.y - 7;
*xPointer = objEvent->currentCoords.x - 7;
*yPointer = objEvent->currentCoords.y - 7;
}
bool32 CheckObjectAtXY(u32 x, u32 y)

View file

@ -2489,8 +2489,9 @@ bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx)
{
u32 localId = VarGet(ScriptReadHalfword(ctx));
u32 useTemplate = VarGet(ScriptReadHalfword(ctx));
GetObjectPosition(localId,useTemplate);
u16 *pX = GetVarPointer(ScriptReadHalfword(ctx));
u16 *pY = GetVarPointer(ScriptReadHalfword(ctx));
GetObjectPosition(pX,pY,localId,useTemplate);
return FALSE;
}