getdirectiontoface macro

This commit is contained in:
Eduardo Quezada 2024-05-29 15:52:21 -04:00
parent d1e2f620b8
commit 3d05961dd5
3 changed files with 16 additions and 11 deletions

View File

@ -2222,3 +2222,11 @@
callfunc ScrFunc_IsFollowerFieldMoveUser
.2byte \var
.endm
@ Saves the direction from where source object event would need to turn to to face the target into the specified var.
.macro getdirectiontoface var:req, sourceId:req, targetId:req
callfunc ScrFunc_GetDirectionToFace
.2byte \var
.byte \sourceId
.byte \targetId
.endm

View File

@ -95,10 +95,7 @@ EventScript_SmashRock:: @ fallthrough
end
EventScript_FollowerFieldMove:
callfunc ScrFunc_GetDirectionToFace
.2byte VAR_0x8005
.byte OBJ_EVENT_ID_FOLLOWER
.byte OBJ_EVENT_ID_PLAYER
getdirectiontoface VAR_0x8005, OBJ_EVENT_ID_FOLLOWER, OBJ_EVENT_ID_PLAYER
specialvar VAR_0x8006, GetPlayerFacingDirection
goto_if_eq VAR_0x8005, DIR_NONE, EventScript_FollowerFieldMoveEnd
@ Swap follower and player

View File

@ -5868,17 +5868,17 @@ u8 GetDirectionToFace(s16 x, s16 y, s16 targetX, s16 targetY)
bool8 ScrFunc_GetDirectionToFace(struct ScriptContext *ctx)
{
u16 *var = GetVarPointer(ScriptReadHalfword(ctx));
u8 id0 = GetObjectEventIdByLocalId(ScriptReadByte(ctx)); // source
u8 id1 = GetObjectEventIdByLocalId(ScriptReadByte(ctx)); // target
u8 sourceId = GetObjectEventIdByLocalId(ScriptReadByte(ctx));
u8 targetId = GetObjectEventIdByLocalId(ScriptReadByte(ctx));
if (var == NULL)
return FALSE;
if (id0 >= OBJECT_EVENTS_COUNT || id1 >= OBJECT_EVENTS_COUNT)
if (sourceId >= OBJECT_EVENTS_COUNT || targetId >= OBJECT_EVENTS_COUNT)
*var = DIR_NONE;
else
*var = GetDirectionToFace(gObjectEvents[id0].currentCoords.x,
gObjectEvents[id0].currentCoords.y,
gObjectEvents[id1].currentCoords.x,
gObjectEvents[id1].currentCoords.y);
*var = GetDirectionToFace(gObjectEvents[sourceId].currentCoords.x,
gObjectEvents[sourceId].currentCoords.y,
gObjectEvents[targetId].currentCoords.x,
gObjectEvents[targetId].currentCoords.y);
return FALSE;
}