From e7f66e663b3174056577c1e5609ab142e65d4dba Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Wed, 29 May 2024 19:25:51 -0400 Subject: [PATCH] Convert callfuncs to callnative --- asm/macros/event.inc | 12 +++++----- src/event_object_movement.c | 45 +++++++++++++------------------------ src/scrcmd.c | 6 ++--- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index ecd0df1158..c64ae3e463 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2194,7 +2194,7 @@ @ Saves species and forms of Daycare Pokémon to specific vars. Saves the amount of Daycare mon to VAR_RESULT. .macro getdaycaregfx varSpecies1:req varSpecies2:req varForm1:req varForm2:req - callfunc ScrFunc_getdaycaregfx + callnative GetDaycareGraphics .2byte \varSpecies1 .2byte \varSpecies2 .2byte \varForm1 @@ -2203,29 +2203,29 @@ @ Plays the cry of the first alive party member. .macro playfirstmoncry - callfunc ScrFunc_playfirstmoncry + callnative PlayFirstMonCry .endm @ Buffers the nickname of the first alive party member. .macro bufferlivemonnickname out:req - callfunc ScrFunc_bufferlivemonnickname + callnative BufferFirstLiveMonNickname .byte \out .endm @ Executes Follower actions .macro getfolloweraction - callfunc ScrFunc_getfolloweraction + callnative GetFollowerAction .endm @ Checks if Field move is being used by the current follower. .macro isfollowerfieldmoveuser var:req - callfunc ScrFunc_IsFollowerFieldMoveUser + callnative 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 + callnative GetDirectionToFaceScript .2byte \var .byte \sourceId .byte \targetId diff --git a/src/event_object_movement.c b/src/event_object_movement.c index edc4c788f4..874e8f661b 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -69,6 +69,13 @@ enum { JUMP_DISTANCE_FAR, }; +// Used for storing conditional emotes +struct SpecialEmote +{ + u16 index; + u8 emotion; +}; + // Sprite data used throughout #define sObjEventId data[0] #define sTypeFuncId data[1] // Index into corresponding gMovementTypeFuncs_* table @@ -2131,24 +2138,6 @@ static void ObjectEventEmote(struct ObjectEvent *objEvent, u8 emotion) FieldEffectStart(FLDEFF_EMOTE); } -// Script-accessible version of the above -bool8 ScrFunc_emote(struct ScriptContext *ctx) -{ - u8 localId = ScriptReadByte(ctx); - u8 emotion = ScriptReadByte(ctx) % FOLLOWER_EMOTION_LENGTH; - u8 i = GetObjectEventIdByLocalId(localId); - if (i < OBJECT_EVENTS_COUNT) - ObjectEventEmote(&gObjectEvents[i], emotion); - return FALSE; -} - -// Used for storing conditional emotes -struct SpecialEmote -{ - u16 index; - u8 emotion; -}; - // Find and return direction of metatile behavior within distance static u32 FindMetatileBehaviorWithinRange(s32 x, s32 y, u32 mb, u8 distance) { @@ -2264,7 +2253,7 @@ bool32 CheckMsgInfo(const struct FollowerMsgInfoExtended *info, struct Pokemon * } // Call an applicable follower message script -bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big switch for follower messages +void GetFollowerAction(struct ScriptContext *ctx) // Essentially a big switch for follower messages { u32 species; s32 multi; @@ -2290,7 +2279,7 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big if (mon == NULL) // failsafe { ScriptCall(ctx, EventScript_FollowerLovesYou); - return FALSE; + return; } // Set the script to the very end; we'll be calling another script dynamically ScriptJump(ctx, EventScript_FollowerEnd); @@ -2427,7 +2416,7 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big ctx->data[0] = i ? ((u32*)gFollowerConditionalMessages[multi].text)[Random() % i] : 0; } ScriptCall(ctx, gFollowerConditionalMessages[multi].script ? gFollowerConditionalMessages[multi].script : gFollowerBasicMessages[emotion].script); - return FALSE; + return; } // otherwise, a basic or C-based message was picked ObjectEventEmote(objEvent, emotion); @@ -2435,7 +2424,6 @@ bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big ScriptCall(ctx, gFollowerBasicMessages[emotion].messages[multi].script ? gFollowerBasicMessages[emotion].messages[multi].script : gFollowerBasicMessages[emotion].script); - return FALSE; } void TrySpawnObjectEvents(s16 cameraX, s16 cameraY) @@ -5865,13 +5853,13 @@ u8 GetDirectionToFace(s16 x, s16 y, s16 targetX, s16 targetY) } // Uses the above, but script accessible, and uses localIds -bool8 ScrFunc_GetDirectionToFace(struct ScriptContext *ctx) +void GetDirectionToFaceScript(struct ScriptContext *ctx) { u16 *var = GetVarPointer(ScriptReadHalfword(ctx)); u8 sourceId = GetObjectEventIdByLocalId(ScriptReadByte(ctx)); u8 targetId = GetObjectEventIdByLocalId(ScriptReadByte(ctx)); if (var == NULL) - return FALSE; + return; if (sourceId >= OBJECT_EVENTS_COUNT || targetId >= OBJECT_EVENTS_COUNT) *var = DIR_NONE; else @@ -5879,26 +5867,24 @@ bool8 ScrFunc_GetDirectionToFace(struct ScriptContext *ctx) gObjectEvents[sourceId].currentCoords.y, gObjectEvents[targetId].currentCoords.x, gObjectEvents[targetId].currentCoords.y); - return FALSE; } // Whether following pokemon is also the user of the field move // Intended to be called before the field effect itself -bool8 ScrFunc_IsFollowerFieldMoveUser(struct ScriptContext *ctx) +void IsFollowerFieldMoveUser(struct ScriptContext *ctx) { u16 *var = GetVarPointer(ScriptReadHalfword(ctx)); u16 userIndex = gFieldEffectArguments[0]; // field move user index struct Pokemon *follower = GetFirstLiveMon(); struct ObjectEvent *obj = GetFollowerObject(); if (var == NULL) - return FALSE; + return; *var = FALSE; if (follower && obj && !obj->invisible) { u16 followIndex = ((u32)follower - (u32)gPlayerParty) / sizeof(struct Pokemon); *var = userIndex == followIndex; } - return FALSE; } void SetTrainerMovementType(struct ObjectEvent *objectEvent, u8 movementType) @@ -10600,7 +10586,7 @@ bool8 MovementAction_EmoteDoubleExclamationMark_Step0(struct ObjectEvent *object } // Get gfx data from daycare pokemon and store it in vars -bool8 ScrFunc_getdaycaregfx(struct ScriptContext *ctx) +void GetDaycareGraphics(struct ScriptContext *ctx) { u16 varGfx[] = {ScriptReadHalfword(ctx), ScriptReadHalfword(ctx)}; u16 varForm[] = {ScriptReadHalfword(ctx), ScriptReadHalfword(ctx)}; @@ -10620,5 +10606,4 @@ bool8 ScrFunc_getdaycaregfx(struct ScriptContext *ctx) VarSet(varForm[i], form | (shiny << 5)); } gSpecialVar_Result = i; - return FALSE; } diff --git a/src/scrcmd.c b/src/scrcmd.c index 92c535aee2..c375696eae 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1716,13 +1716,12 @@ bool8 ScrCmd_bufferleadmonspeciesname(struct ScriptContext *ctx) return FALSE; } -bool8 ScrFunc_bufferlivemonnickname(struct ScriptContext *ctx) +void BufferFirstLiveMonNickname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); GetMonData(GetFirstLiveMon(), MON_DATA_NICKNAME, sScriptStringVars[stringVarIndex]); StringGet_Nickname(sScriptStringVars[stringVarIndex]); - return FALSE; } bool8 ScrCmd_bufferpartymonnick(struct ScriptContext *ctx) @@ -2189,10 +2188,9 @@ bool8 ScrCmd_playmoncry(struct ScriptContext *ctx) return FALSE; } -bool8 ScrFunc_playfirstmoncry(struct ScriptContext *ctx) +void PlayFirstMonCry(struct ScriptContext *ctx) { PlayCry_Script(GetMonData(GetFirstLiveMon(), MON_DATA_SPECIES), CRY_MODE_NORMAL); - return FALSE; } bool8 ScrCmd_waitmoncry(struct ScriptContext *ctx)