From 56ff4ce998225b7ff0f99db466022e29f8097aba Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 20 Aug 2023 01:35:51 -0400 Subject: [PATCH] Add defines for field effect sprite data, misc task data --- src/field_effect_helpers.c | 686 +++++++++++++++++++------------------ src/use_pokeblock.c | 37 +- 2 files changed, 369 insertions(+), 354 deletions(-) diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 9421aaf27a..237e543dee 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -32,8 +32,12 @@ static void UpdateBobbingEffect(struct ObjectEvent *, struct Sprite *, struct Sp static void SpriteCB_UnderwaterSurfBlob(struct Sprite *); static u32 ShowDisguiseFieldEffect(u8, u8, u8); -// Used by several field effects to determine which of a group it is -#define sFldEff data[1] +// Data used by all the field effects that share UpdateJumpImpactEffect +#define sJumpElevation data[0] +#define sJumpFldEff data[1] + +// Data used by all the field effects that share WaitFieldEffectSpriteAnim +#define sWaitFldEff data[0] #define sReflectionObjEventId data[0] #define sReflectionObjEventLocalId data[1] @@ -44,7 +48,7 @@ void SetUpReflection(struct ObjectEvent *objectEvent, struct Sprite *sprite, boo { struct Sprite *reflectionSprite; - reflectionSprite = &gSprites[CreateCopySpriteAt(sprite, sprite->x, sprite->y, 0x98)]; + reflectionSprite = &gSprites[CreateCopySpriteAt(sprite, sprite->x, sprite->y, 152)]; reflectionSprite->callback = UpdateObjectReflectionSprite; reflectionSprite->oam.priority = 3; reflectionSprite->oam.paletteNum = gReflectionEffectPaletteMap[reflectionSprite->oam.paletteNum]; @@ -92,9 +96,7 @@ static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct static void LoadObjectRegularReflectionPalette(struct ObjectEvent *objectEvent, u8 paletteIndex) { - const struct ObjectEventGraphicsInfo *graphicsInfo; - - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); if (graphicsInfo->reflectionPaletteTag != OBJ_EVENT_PAL_TAG_NONE) { if (graphicsInfo->paletteSlot == PALSLOT_PLAYER) @@ -111,9 +113,7 @@ static void LoadObjectRegularReflectionPalette(struct ObjectEvent *objectEvent, // This is so the sprite blends in with the dark water metatile underneath the bridge. static void LoadObjectHighBridgeReflectionPalette(struct ObjectEvent *objectEvent, u8 paletteNum) { - const struct ObjectEventGraphicsInfo *graphicsInfo; - - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); if (graphicsInfo->reflectionPaletteTag != OBJ_EVENT_PAL_TAG_NONE) { PatchObjectPalette(graphicsInfo->reflectionPaletteTag, paletteNum); @@ -123,11 +123,8 @@ static void LoadObjectHighBridgeReflectionPalette(struct ObjectEvent *objectEven static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite) { - struct ObjectEvent *objectEvent; - struct Sprite *mainSprite; - - objectEvent = &gObjectEvents[reflectionSprite->sReflectionObjEventId]; - mainSprite = &gSprites[objectEvent->spriteId]; + struct ObjectEvent *objectEvent = &gObjectEvents[reflectionSprite->sReflectionObjEventId]; + struct Sprite *mainSprite = &gSprites[objectEvent->spriteId]; if (!objectEvent->active || !objectEvent->hasReflection || objectEvent->localId != reflectionSprite->sReflectionObjEventLocalId) { reflectionSprite->inUse = FALSE; @@ -172,15 +169,15 @@ static void UpdateObjectReflectionSprite(struct Sprite *reflectionSprite) extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; +#define sPrevX data[0] +#define sPrevY data[1] + u8 CreateWarpArrowSprite(void) { - u8 spriteId; - struct Sprite *sprite; - - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_ARROW], 0, 0, 0x52); + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_ARROW], 0, 0, 82); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->oam.priority = 1; sprite->coordOffsetEnabled = TRUE; sprite->invisible = TRUE; @@ -195,24 +192,24 @@ void SetSpriteInvisible(u8 spriteId) void ShowWarpArrowSprite(u8 spriteId, u8 direction, s16 x, s16 y) { - s16 x2; - s16 y2; - struct Sprite *sprite; - - sprite = &gSprites[spriteId]; - if (sprite->invisible || sprite->data[0] != x || sprite->data[1] != y) + struct Sprite *sprite = &gSprites[spriteId]; + if (sprite->invisible || sprite->sPrevX != x || sprite->sPrevY != y) { + s16 x2, y2; SetSpritePosToMapCoords(x, y, &x2, &y2); sprite = &gSprites[spriteId]; sprite->x = x2 + 8; sprite->y = y2 + 8; sprite->invisible = FALSE; - sprite->data[0] = x; - sprite->data[1] = y; + sprite->sPrevX = x; + sprite->sPrevY = y; StartSpriteAnim(sprite, direction - 1); } } +#undef sPrevX +#undef sPrevY + static const u8 sShadowEffectTemplateIds[] = { FLDEFFOBJ_SHADOW_S, FLDEFFOBJ_SHADOW_M, @@ -227,22 +224,24 @@ const u16 gShadowVerticalOffsets[] = { 16 }; +// Sprite data for FLDEFF_SHADOW +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] +#define sYOffset data[3] + u32 FldEff_Shadow(void) { - u8 objectEventId; - const struct ObjectEventGraphicsInfo *graphicsInfo; - u8 spriteId; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[sShadowEffectTemplateIds[graphicsInfo->shadowSize]], 0, 0, 0x94); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[sShadowEffectTemplateIds[graphicsInfo->shadowSize]], 0, 0, 148); if (spriteId != MAX_SPRITES) { gSprites[spriteId].coordOffsetEnabled = TRUE; - gSprites[spriteId].data[0] = gFieldEffectArguments[0]; - gSprites[spriteId].data[1] = gFieldEffectArguments[1]; - gSprites[spriteId].data[2] = gFieldEffectArguments[2]; - gSprites[spriteId].data[3] = (graphicsInfo->height >> 1) - gShadowVerticalOffsets[graphicsInfo->shadowSize]; + gSprites[spriteId].sLocalId = gFieldEffectArguments[0]; + gSprites[spriteId].sMapNum = gFieldEffectArguments[1]; + gSprites[spriteId].sMapGroup = gFieldEffectArguments[2]; + gSprites[spriteId].sYOffset = (graphicsInfo->height >> 1) - gShadowVerticalOffsets[graphicsInfo->shadowSize]; } return 0; } @@ -250,20 +249,18 @@ u32 FldEff_Shadow(void) void UpdateShadowFieldEffect(struct Sprite *sprite) { u8 objectEventId; - struct ObjectEvent *objectEvent; - struct Sprite *linkedSprite; - if (TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId)) + if (TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId)) { FieldEffectStop(sprite, FLDEFF_SHADOW); } else { - objectEvent = &gObjectEvents[objectEventId]; - linkedSprite = &gSprites[objectEvent->spriteId]; + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + struct Sprite *linkedSprite = &gSprites[objectEvent->spriteId]; sprite->oam.priority = linkedSprite->oam.priority; sprite->x = linkedSprite->x; - sprite->y = linkedSprite->y + sprite->data[3]; + sprite->y = linkedSprite->y + sprite->sYOffset; if (!objectEvent->active || !objectEvent->hasShadow || MetatileBehavior_IsPokeGrass(objectEvent->currentMetatileBehavior) || MetatileBehavior_IsSurfableWaterOrUnderwater(objectEvent->currentMetatileBehavior) @@ -276,6 +273,11 @@ void UpdateShadowFieldEffect(struct Sprite *sprite) } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup +#undef sYOffset + // Sprite data for FLDEFF_TALL_GRASS and FLDEFF_LONG_GRASS #define sElevation data[0] #define sX data[1] @@ -288,18 +290,14 @@ void UpdateShadowFieldEffect(struct Sprite *sprite) u32 FldEff_TallGrass(void) { - s16 x; - s16 y; u8 spriteId; - struct Sprite *sprite; - - x = gFieldEffectArguments[0]; - y = gFieldEffectArguments[1]; + s16 x = gFieldEffectArguments[0]; + s16 y = gFieldEffectArguments[1]; SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_TALL_GRASS], x, y, 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; sprite->sElevation = gFieldEffectArguments[2]; @@ -317,15 +315,12 @@ u32 FldEff_TallGrass(void) void UpdateTallGrassFieldEffect(struct Sprite *sprite) { - u8 mapNum; - u8 mapGroup; u8 metatileBehavior; u8 localId; u8 objectEventId; - struct ObjectEvent *objectEvent; + u8 mapNum = sprite->sCurrentMap >> 8; + u8 mapGroup = sprite->sCurrentMap; - mapNum = sprite->sCurrentMap >> 8; - mapGroup = sprite->sCurrentMap; if (gCamera.active && (gSaveBlock1Ptr->location.mapNum != mapNum || gSaveBlock1Ptr->location.mapGroup != mapGroup)) { sprite->sX -= gCamera.x; @@ -346,11 +341,9 @@ void UpdateTallGrassFieldEffect(struct Sprite *sprite) else { // Check if the object that triggered the effect has moved away - objectEvent = &gObjectEvents[objectEventId]; - if ((objectEvent->currentCoords.x != sprite->sX - || objectEvent->currentCoords.y != sprite->sY) - && (objectEvent->previousCoords.x != sprite->sX - || objectEvent->previousCoords.y != sprite->sY)) + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + if ((objectEvent->currentCoords.x != sprite->sX || objectEvent->currentCoords.y != sprite->sY) + && (objectEvent->previousCoords.x != sprite->sX || objectEvent->previousCoords.y != sprite->sY)) sprite->sObjectMoved = TRUE; // Metatile behavior var re-used as subpriority @@ -366,31 +359,28 @@ void UpdateTallGrassFieldEffect(struct Sprite *sprite) u32 FldEff_JumpTallGrass(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_JUMP_TALL_GRASS], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->sElevation = gFieldEffectArguments[2]; - sprite->sFldEff = FLDEFF_JUMP_TALL_GRASS; + sprite->sJumpElevation = gFieldEffectArguments[2]; + sprite->sJumpFldEff = FLDEFF_JUMP_TALL_GRASS; } return 0; } u8 FindTallGrassFieldEffectSpriteId(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y) { - struct Sprite *sprite; u8 i; - for (i = 0; i < MAX_SPRITES; i ++) { if (gSprites[i].inUse) { - sprite = &gSprites[i]; + struct Sprite *sprite = &gSprites[i]; if (sprite->callback == UpdateTallGrassFieldEffect && (x == sprite->sX && y == sprite->sY) && localId == (u8)(sprite->sLocalId) @@ -404,18 +394,14 @@ u8 FindTallGrassFieldEffectSpriteId(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s u32 FldEff_LongGrass(void) { - s16 x; - s16 y; u8 spriteId; - struct Sprite *sprite; - - x = gFieldEffectArguments[0]; - y = gFieldEffectArguments[1]; + s16 x = gFieldEffectArguments[0]; + s16 y = gFieldEffectArguments[1]; SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_LONG_GRASS], x, y, 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = ElevationToPriority(gFieldEffectArguments[2]); sprite->sElevation = gFieldEffectArguments[2]; @@ -433,15 +419,12 @@ u32 FldEff_LongGrass(void) void UpdateLongGrassFieldEffect(struct Sprite *sprite) { - u8 mapNum; - u8 mapGroup; u8 metatileBehavior; u8 localId; u8 objectEventId; - struct ObjectEvent *objectEvent; + u8 mapNum = sprite->sCurrentMap >> 8; + u8 mapGroup = sprite->sCurrentMap; - mapNum = sprite->sCurrentMap >> 8; - mapGroup = sprite->sCurrentMap; if (gCamera.active && (gSaveBlock1Ptr->location.mapNum != mapNum || gSaveBlock1Ptr->location.mapGroup != mapGroup)) { sprite->sX -= gCamera.x; @@ -451,7 +434,7 @@ void UpdateLongGrassFieldEffect(struct Sprite *sprite) localId = sprite->sLocalId; mapNum = sprite->sMapNum; mapGroup = sprite->sMapGroup; - metatileBehavior = MapGridGetMetatileBehaviorAt(sprite->data[1], sprite->data[2]); + metatileBehavior = MapGridGetMetatileBehaviorAt(sprite->sX, sprite->sY); if (TryGetObjectEventIdByLocalIdAndMap(localId, mapNum, mapGroup, &objectEventId) || !MetatileBehavior_IsLongGrass(metatileBehavior) || (sprite->sObjectMoved && sprite->animEnded)) @@ -461,11 +444,9 @@ void UpdateLongGrassFieldEffect(struct Sprite *sprite) else { // Check if the object that triggered the effect has moved away - objectEvent = &gObjectEvents[objectEventId]; - if ((objectEvent->currentCoords.x != sprite->data[1] - || objectEvent->currentCoords.y != sprite->data[2]) - && (objectEvent->previousCoords.x != sprite->data[1] - || objectEvent->previousCoords.y != sprite->data[2])) + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + if ((objectEvent->currentCoords.x != sprite->sX || objectEvent->currentCoords.y != sprite->sY) + && (objectEvent->previousCoords.x != sprite->sX || objectEvent->previousCoords.y != sprite->sY)) sprite->sObjectMoved = TRUE; UpdateObjectEventSpriteInvisibility(sprite, FALSE); @@ -473,6 +454,7 @@ void UpdateLongGrassFieldEffect(struct Sprite *sprite) } } +#undef sElevation #undef sX #undef sY #undef sMapNum @@ -486,41 +468,42 @@ void UpdateLongGrassFieldEffect(struct Sprite *sprite) u32 FldEff_JumpLongGrass(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_JUMP_LONG_GRASS], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->sElevation = gFieldEffectArguments[2]; - sprite->sFldEff = FLDEFF_JUMP_LONG_GRASS; + sprite->sJumpElevation = gFieldEffectArguments[2]; + sprite->sJumpFldEff = FLDEFF_JUMP_LONG_GRASS; } return 0; } +// Sprite data for FLDEFF_SHORT_GRASS +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] +#define sPrevX data[3] +#define sPrevY data[4] + u32 FldEff_ShortGrass(void) { - u8 objectEventId; - struct ObjectEvent *objectEvent; - u8 spriteId; - struct Sprite *sprite; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - objectEvent = &gObjectEvents[objectEventId]; - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SHORT_GRASS], 0, 0, 0); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SHORT_GRASS], 0, 0, 0); if (spriteId != MAX_SPRITES) { - sprite = &(gSprites[spriteId]); + struct Sprite *sprite = &(gSprites[spriteId]); sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gSprites[objectEvent->spriteId].oam.priority; - sprite->data[0] = gFieldEffectArguments[0]; - sprite->data[1] = gFieldEffectArguments[1]; - sprite->data[2] = gFieldEffectArguments[2]; - sprite->data[3] = gSprites[objectEvent->spriteId].x; - sprite->data[4] = gSprites[objectEvent->spriteId].y; + sprite->sLocalId = gFieldEffectArguments[0]; + sprite->sMapNum = gFieldEffectArguments[1]; + sprite->sMapGroup = gFieldEffectArguments[2]; + sprite->sPrevX = gSprites[objectEvent->spriteId].x; + sprite->sPrevY = gSprites[objectEvent->spriteId].y; } return 0; } @@ -528,32 +511,28 @@ u32 FldEff_ShortGrass(void) void UpdateShortGrassFieldEffect(struct Sprite *sprite) { u8 objectEventId; - s16 x; - s16 y; - const struct ObjectEventGraphicsInfo *graphicsInfo; - struct Sprite *linkedSprite; - if (TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId) || !gObjectEvents[objectEventId].inShortGrass) + if (TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId) || !gObjectEvents[objectEventId].inShortGrass) { FieldEffectStop(sprite, FLDEFF_SHORT_GRASS); } else { - graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); - linkedSprite = &gSprites[gObjectEvents[objectEventId].spriteId]; - y = linkedSprite->y; - x = linkedSprite->x; - if (x != sprite->data[3] || y != sprite->data[4]) + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); + struct Sprite *linkedSprite = &gSprites[gObjectEvents[objectEventId].spriteId]; + s16 parentY = linkedSprite->y; + s16 parentX = linkedSprite->x; + if (parentX != sprite->sPrevX || parentY != sprite->sPrevY) { - sprite->data[3] = x; - sprite->data[4] = y; + // Parent sprite moved, try to restart the animation + sprite->sPrevX = parentX; + sprite->sPrevY = parentY; if (sprite->animEnded) - { StartSpriteAnim(sprite, 0); - } } - sprite->x = x; - sprite->y = y; + sprite->x = parentX; + sprite->y = parentY; + // Offset the grass sprite halfway down the parent sprite. sprite->y2 = (graphicsInfo->height >> 1) - 8; sprite->subpriority = linkedSprite->subpriority - 1; sprite->oam.priority = linkedSprite->oam.priority; @@ -561,19 +540,29 @@ void UpdateShortGrassFieldEffect(struct Sprite *sprite) } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup +#undef sPrevX +#undef sPrevY + +// Sprite data for FLDEFF_SAND_FOOTPRINTS, FLDEFF_DEEP_SAND_FOOTPRINTS, and FLDEFF_BIKE_TIRE_TRACKS +#define sState data[0] +#define sTimer data[1] +#define sFldEff data[7] + u32 FldEff_SandFootprints(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SAND_FOOTPRINTS], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[7] = FLDEFF_SAND_FOOTPRINTS; + sprite->sFldEff = FLDEFF_SAND_FOOTPRINTS; StartSpriteAnim(sprite, gFieldEffectArguments[4]); } return 0; @@ -582,16 +571,15 @@ u32 FldEff_SandFootprints(void) u32 FldEff_DeepSandFootprints(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_DEEP_SAND_FOOTPRINTS], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[7] = FLDEFF_DEEP_SAND_FOOTPRINTS; + sprite->sFldEff = FLDEFF_DEEP_SAND_FOOTPRINTS; StartSpriteAnim(sprite, gFieldEffectArguments[4]); } return spriteId; @@ -600,16 +588,15 @@ u32 FldEff_DeepSandFootprints(void) u32 FldEff_BikeTireTracks(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BIKE_TIRE_TRACKS], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[7] = FLDEFF_BIKE_TIRE_TRACKS; + sprite->sFldEff = FLDEFF_BIKE_TIRE_TRACKS; StartSpriteAnim(sprite, gFieldEffectArguments[4]); } return spriteId; @@ -622,14 +609,14 @@ void (*const gFadeFootprintsTireTracksFuncs[])(struct Sprite *) = { void UpdateFootprintsTireTracksFieldEffect(struct Sprite *sprite) { - gFadeFootprintsTireTracksFuncs[sprite->data[0]](sprite); + gFadeFootprintsTireTracksFuncs[sprite->sState](sprite); } static void FadeFootprintsTireTracks_Step0(struct Sprite *sprite) { // Wait 40 frames before the flickering starts. - if (++sprite->data[1] > 40) - sprite->data[0] = 1; + if (++sprite->sTimer > 40) + sprite->sState = 1; UpdateObjectEventSpriteInvisibility(sprite, FALSE); } @@ -637,36 +624,37 @@ static void FadeFootprintsTireTracks_Step0(struct Sprite *sprite) static void FadeFootprintsTireTracks_Step1(struct Sprite *sprite) { sprite->invisible ^= 1; - sprite->data[1]++; + sprite->sTimer++; UpdateObjectEventSpriteInvisibility(sprite, sprite->invisible); - if (sprite->data[1] > 56) - { - FieldEffectStop(sprite, sprite->data[7]); - } + if (sprite->sTimer > 56) + FieldEffectStop(sprite, sprite->sFldEff); } +#undef sState +#undef sTimer +#undef sFldEff + +// Sprite data for FLDEFF_SPLASH +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] + u32 FldEff_Splash(void) { - u8 objectEventId; - struct ObjectEvent *objectEvent; - u8 spriteId; - struct Sprite *sprite; - const struct ObjectEventGraphicsInfo *graphicsInfo; - struct Sprite *linkedSprite; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - objectEvent = &gObjectEvents[objectEventId]; - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SPLASH], 0, 0, 0); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SPLASH], 0, 0, 0); if (spriteId != MAX_SPRITES) { - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); - sprite = &gSprites[spriteId]; + struct Sprite *linkedSprite; + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; linkedSprite = &gSprites[objectEvent->spriteId]; sprite->oam.priority = linkedSprite->oam.priority; - sprite->data[0] = gFieldEffectArguments[0]; - sprite->data[1] = gFieldEffectArguments[1]; - sprite->data[2] = gFieldEffectArguments[2]; + sprite->sLocalId = gFieldEffectArguments[0]; + sprite->sMapNum = gFieldEffectArguments[1]; + sprite->sMapGroup = gFieldEffectArguments[2]; sprite->y2 = (graphicsInfo->height >> 1) - 4; PlaySE(SE_PUDDLE); } @@ -677,7 +665,7 @@ void UpdateSplashFieldEffect(struct Sprite *sprite) { u8 objectEventId; - if (sprite->animEnded || TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId)) + if (sprite->animEnded || TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId)) { FieldEffectStop(sprite, FLDEFF_SPLASH); } @@ -689,20 +677,23 @@ void UpdateSplashFieldEffect(struct Sprite *sprite) } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup + u32 FldEff_JumpSmallSplash(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_JUMP_SMALL_SPLASH], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = gFieldEffectArguments[2]; - sprite->data[1] = FLDEFF_JUMP_SMALL_SPLASH; + sprite->sJumpElevation = gFieldEffectArguments[2]; + sprite->sJumpFldEff = FLDEFF_JUMP_SMALL_SPLASH; } return 0; } @@ -710,44 +701,44 @@ u32 FldEff_JumpSmallSplash(void) u32 FldEff_JumpBigSplash(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_JUMP_BIG_SPLASH], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = gFieldEffectArguments[2]; - sprite->data[1] = FLDEFF_JUMP_BIG_SPLASH; + sprite->sJumpElevation = gFieldEffectArguments[2]; + sprite->sJumpFldEff = FLDEFF_JUMP_BIG_SPLASH; } return 0; } +// Sprite data for FLDEFF_FEET_IN_FLOWING_WATER +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] +#define sPrevX data[3] +#define sPrevY data[4] + u32 FldEff_FeetInFlowingWater(void) { - u8 objectEventId; - struct ObjectEvent *objectEvent; - u8 spriteId; - struct Sprite *sprite; - const struct ObjectEventGraphicsInfo *graphicsInfo; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - objectEvent = &gObjectEvents[objectEventId]; - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SPLASH], 0, 0, 0); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SPLASH], 0, 0, 0); if (spriteId != MAX_SPRITES) { - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); - sprite = &gSprites[spriteId]; + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + struct Sprite *sprite = &gSprites[spriteId]; sprite->callback = UpdateFeetInFlowingWaterFieldEffect; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gSprites[objectEvent->spriteId].oam.priority; - sprite->data[0] = gFieldEffectArguments[0]; - sprite->data[1] = gFieldEffectArguments[1]; - sprite->data[2] = gFieldEffectArguments[2]; - sprite->data[3] = -1; - sprite->data[4] = -1; + sprite->sLocalId = gFieldEffectArguments[0]; + sprite->sMapNum = gFieldEffectArguments[1]; + sprite->sMapGroup = gFieldEffectArguments[2]; + sprite->sPrevX = -1; + sprite->sPrevY = -1; sprite->y2 = (graphicsInfo->height >> 1) - 4; StartSpriteAnim(sprite, 1); } @@ -757,69 +748,70 @@ u32 FldEff_FeetInFlowingWater(void) static void UpdateFeetInFlowingWaterFieldEffect(struct Sprite *sprite) { u8 objectEventId; - struct Sprite *linkedSprite; - struct ObjectEvent *objectEvent; - if (TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId) || !gObjectEvents[objectEventId].inShallowFlowingWater) + if (TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId) || !gObjectEvents[objectEventId].inShallowFlowingWater) { FieldEffectStop(sprite, FLDEFF_FEET_IN_FLOWING_WATER); } else { - objectEvent = &gObjectEvents[objectEventId]; - linkedSprite = &gSprites[objectEvent->spriteId]; + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + struct Sprite *linkedSprite = &gSprites[objectEvent->spriteId]; sprite->x = linkedSprite->x; sprite->y = linkedSprite->y; sprite->subpriority = linkedSprite->subpriority; UpdateObjectEventSpriteInvisibility(sprite, FALSE); - if (objectEvent->currentCoords.x != sprite->data[3] || objectEvent->currentCoords.y != sprite->data[4]) + if (objectEvent->currentCoords.x != sprite->sPrevX || objectEvent->currentCoords.y != sprite->sPrevY) { - sprite->data[3] = objectEvent->currentCoords.x; - sprite->data[4] = objectEvent->currentCoords.y; + sprite->sPrevX = objectEvent->currentCoords.x; + sprite->sPrevY = objectEvent->currentCoords.y; if (!sprite->invisible) - { PlaySE(SE_PUDDLE); - } } } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup +#undef sPrevX +#undef sPrevY + u32 FldEff_Ripple(void) { - u8 spriteId; - struct Sprite *sprite; - - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_RIPPLE], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_RIPPLE], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = FLDEFF_RIPPLE; + sprite->sWaitFldEff = FLDEFF_RIPPLE; } return 0; } +// Sprite data for FLDEFF_HOT_SPRINGS_WATER +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] +#define sPrevX data[3] +#define sPrevY data[4] + u32 FldEff_HotSpringsWater(void) { - u8 objectEventId; - struct ObjectEvent *objectEvent; - u8 spriteId; - struct Sprite *sprite; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - objectEvent = &gObjectEvents[objectEventId]; - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_HOT_SPRINGS_WATER], 0, 0, 0); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_HOT_SPRINGS_WATER], 0, 0, 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gSprites[objectEvent->spriteId].oam.priority; - sprite->data[0] = gFieldEffectArguments[0]; - sprite->data[1] = gFieldEffectArguments[1]; - sprite->data[2] = gFieldEffectArguments[2]; - sprite->data[3] = gSprites[objectEvent->spriteId].x; - sprite->data[4] = gSprites[objectEvent->spriteId].y; + sprite->sLocalId = gFieldEffectArguments[0]; + sprite->sMapNum = gFieldEffectArguments[1]; + sprite->sMapGroup = gFieldEffectArguments[2]; + sprite->sPrevX = gSprites[objectEvent->spriteId].x; // Unused + sprite->sPrevY = gSprites[objectEvent->spriteId].y; // Unused } return 0; } @@ -827,17 +819,15 @@ u32 FldEff_HotSpringsWater(void) void UpdateHotSpringsWaterFieldEffect(struct Sprite *sprite) { u8 objectEventId; - const struct ObjectEventGraphicsInfo *graphicsInfo; - struct Sprite *linkedSprite; - if (TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId) || !gObjectEvents[objectEventId].inHotSprings) + if (TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId) || !gObjectEvents[objectEventId].inHotSprings) { FieldEffectStop(sprite, FLDEFF_HOT_SPRINGS_WATER); } else { - graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); - linkedSprite = &gSprites[gObjectEvents[objectEventId].spriteId]; + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); + struct Sprite *linkedSprite = &gSprites[gObjectEvents[objectEventId].spriteId]; sprite->x = linkedSprite->x; sprite->y = (graphicsInfo->height >> 1) + linkedSprite->y - 8; sprite->subpriority = linkedSprite->subpriority - 1; @@ -845,19 +835,24 @@ void UpdateHotSpringsWaterFieldEffect(struct Sprite *sprite) } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup +#undef sPrevX +#undef sPrevY + u32 FldEff_UnusedGrass(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_UNUSED_GRASS], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = FLDEFF_UNUSED_GRASS; + sprite->sWaitFldEff = FLDEFF_UNUSED_GRASS; } return 0; } @@ -865,16 +860,15 @@ u32 FldEff_UnusedGrass(void) u32 FldEff_UnusedGrass2(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_UNUSED_GRASS_2], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = FLDEFF_UNUSED_GRASS_2; + sprite->sWaitFldEff = FLDEFF_UNUSED_GRASS_2; } return 0; } @@ -882,16 +876,15 @@ u32 FldEff_UnusedGrass2(void) u32 FldEff_UnusedSand(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_UNUSED_SAND], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = FLDEFF_UNUSED_SAND; + sprite->sWaitFldEff = FLDEFF_UNUSED_SAND; } return 0; } @@ -899,16 +892,15 @@ u32 FldEff_UnusedSand(void) u32 FldEff_WaterSurfacing(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_WATER_SURFACING], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = FLDEFF_WATER_SURFACING; + sprite->sWaitFldEff = FLDEFF_WATER_SURFACING; } return 0; } @@ -933,18 +925,15 @@ void StartAshFieldEffect(s16 x, s16 y, u16 metatileId, s16 delay) u32 FldEff_Ash(void) { - s16 x; - s16 y; u8 spriteId; - struct Sprite *sprite; - x = gFieldEffectArguments[0]; - y = gFieldEffectArguments[1]; + s16 x = gFieldEffectArguments[0]; + s16 y = gFieldEffectArguments[1]; SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_ASH], x, y, gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; sprite->sX = gFieldEffectArguments[0]; @@ -998,27 +987,30 @@ static void UpdateAshFieldEffect_End(struct Sprite *sprite) #undef sDelay // Sprite data for FLDEFF_SURF_BLOB -#define tBitfield data[0] -#define tPlayerOffset data[1] -#define tPlayerObjId data[2] - +#define sBitfield data[0] +#define sPlayerOffset data[1] +#define sPlayerObjId data[2] +#define sVelocity data[3] +#define sTimer data[4] +#define sIntervalIdx data[5] +#define sPrevX data[6] +#define sPrevY data[7] u32 FldEff_SurfBlob(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SURF_BLOB], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x96); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SURF_BLOB], gFieldEffectArguments[0], gFieldEffectArguments[1], 150); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.paletteNum = 0; - sprite->tPlayerObjId = gFieldEffectArguments[2]; - sprite->data[3] = -1; - sprite->data[6] = -1; - sprite->data[7] = -1; + sprite->sPlayerObjId = gFieldEffectArguments[2]; + sprite->sVelocity = -1; + sprite->sPrevX = -1; + sprite->sPrevY = -1; } FieldEffectActiveListRemove(FLDEFF_SURF_BLOB); return spriteId; @@ -1027,43 +1019,40 @@ u32 FldEff_SurfBlob(void) void SetSurfBlob_BobState(u8 spriteId, u8 state) { - gSprites[spriteId].data[0] = (gSprites[spriteId].data[0] & ~0xF) | (state & 0xF); + gSprites[spriteId].sBitfield = (gSprites[spriteId].sBitfield & ~0xF) | (state & 0xF); } void SetSurfBlob_DontSyncAnim(u8 spriteId, bool8 dontSync) { - gSprites[spriteId].data[0] = (gSprites[spriteId].data[0] & ~0xF0) | ((dontSync & 0xF) << 4); + gSprites[spriteId].sBitfield = (gSprites[spriteId].sBitfield & ~0xF0) | ((dontSync & 0xF) << 4); } void SetSurfBlob_PlayerOffset(u8 spriteId, bool8 hasOffset, s16 offset) { - gSprites[spriteId].data[0] = (gSprites[spriteId].data[0] & ~0xF00) | ((hasOffset & 0xF) << 8); - gSprites[spriteId].tPlayerOffset = offset; + gSprites[spriteId].sBitfield = (gSprites[spriteId].sBitfield & ~0xF00) | ((hasOffset & 0xF) << 8); + gSprites[spriteId].sPlayerOffset = offset; } static u8 GetSurfBlob_BobState(struct Sprite *sprite) { - return sprite->data[0] & 0xF; + return sprite->sBitfield & 0xF; } // Never TRUE static u8 GetSurfBlob_DontSyncAnim(struct Sprite *sprite) { - return (sprite->data[0] & 0xF0) >> 4; + return (sprite->sBitfield & 0xF0) >> 4; } static u8 GetSurfBlob_HasPlayerOffset(struct Sprite *sprite) { - return (sprite->data[0] & 0xF00) >> 8; + return (sprite->sBitfield & 0xF00) >> 8; } void UpdateSurfBlobFieldEffect(struct Sprite *sprite) { - struct ObjectEvent *playerObj; - struct Sprite *playerSprite; - - playerObj = &gObjectEvents[sprite->tPlayerObjId]; - playerSprite = &gSprites[playerObj->spriteId]; + struct ObjectEvent *playerObj = &gObjectEvents[sprite->sPlayerObjId]; + struct Sprite *playerSprite = &gSprites[playerObj->spriteId]; SynchroniseSurfAnim(playerObj, sprite); SynchroniseSurfPosition(playerObj, sprite); UpdateBobbingEffect(playerObj, playerSprite, sprite); @@ -1096,17 +1085,19 @@ void SynchroniseSurfPosition(struct ObjectEvent *playerObj, struct Sprite *sprit s16 y = playerObj->currentCoords.y; s32 spriteY = sprite->y2; - if (spriteY == 0 && (x != sprite->data[6] || y != sprite->data[7])) + if (spriteY == 0 && (x != sprite->sPrevX || y != sprite->sPrevY)) { - sprite->data[5] = spriteY; - sprite->data[6] = x; - sprite->data[7] = y; - for (i = DIR_SOUTH; i <= DIR_EAST; i++, x = sprite->data[6], y = sprite->data[7]) + // Player is moving while surfing, update position. + sprite->sIntervalIdx = 0; + sprite->sPrevX = x; + sprite->sPrevY = y; + for (i = DIR_SOUTH; i <= DIR_EAST; i++, x = sprite->sPrevX, y = sprite->sPrevY) { MoveCoords(i, &x, &y); if (MapGridGetElevationAt(x, y) == 3) { - sprite->data[5]++; + // While dismounting the surf blob bobs at a slower rate + sprite->sIntervalIdx++; break; } } @@ -1115,46 +1106,54 @@ void SynchroniseSurfPosition(struct ObjectEvent *playerObj, struct Sprite *sprit static void UpdateBobbingEffect(struct ObjectEvent *playerObj, struct Sprite *playerSprite, struct Sprite *sprite) { - u16 intervals[] = {3, 7}; + // The frame interval at which to update the blob's y movement. + // Normally every 4th frame, but every 8th frame while dismounting. + u16 intervals[] = {0x3, 0x7}; + u8 bobState = GetSurfBlob_BobState(sprite); if (bobState != BOB_NONE) { - // Update bobbing position of surf blob - if (((u16)(++sprite->data[4]) & intervals[sprite->data[5]]) == 0) - { - sprite->y2 += sprite->data[3]; - } - if ((sprite->data[4] & 15) == 0) - { - sprite->data[3] = -sprite->data[3]; - } + // Update vertical position of surf blob + if (((u16)(++sprite->sTimer) & intervals[sprite->sIntervalIdx]) == 0) + sprite->y2 += sprite->sVelocity; + + // Reverse bob direction + if ((sprite->sTimer & 15) == 0) + sprite->sVelocity = -sprite->sVelocity; + if (bobState != BOB_JUST_MON) { - // Update bobbing position of player + // Update vertical position of player if (!GetSurfBlob_HasPlayerOffset(sprite)) playerSprite->y2 = sprite->y2; else - playerSprite->y2 = sprite->tPlayerOffset + sprite->y2; + playerSprite->y2 = sprite->sPlayerOffset + sprite->y2; sprite->x = playerSprite->x; sprite->y = playerSprite->y + 8; } } } +#undef sBitfield +#undef sPlayerOffset +#undef sPlayerObjId +#undef sVelocity +#undef sTimer +#undef sIntervalIdx +#undef sPrevX +#undef sPrevY + #define sSpriteId data[0] #define sBobY data[1] #define sTimer data[2] u8 StartUnderwaterSurfBlobBobbing(u8 blobSpriteId) { - u8 spriteId; - struct Sprite *sprite; - // Create a dummy sprite with its own callback // that tracks the actual surf blob sprite and // makes it bob up and down underwater - spriteId = CreateSpriteAtEnd(&gDummySpriteTemplate, 0, 0, -1); - sprite = &gSprites[spriteId]; + u8 spriteId = CreateSpriteAtEnd(&gDummySpriteTemplate, 0, 0, -1); + struct Sprite *sprite = &gSprites[spriteId]; sprite->callback = SpriteCB_UnderwaterSurfBlob; sprite->invisible = TRUE; sprite->sSpriteId = blobSpriteId; @@ -1164,17 +1163,14 @@ u8 StartUnderwaterSurfBlobBobbing(u8 blobSpriteId) static void SpriteCB_UnderwaterSurfBlob(struct Sprite *sprite) { - struct Sprite *blobSprite; + struct Sprite *blobSprite = &gSprites[sprite->sSpriteId]; - blobSprite = &gSprites[sprite->sSpriteId]; + // Update vertical position of surf blob if (((sprite->sTimer++) & 3) == 0) - { blobSprite->y2 += sprite->sBobY; - } + // Reverse direction if ((sprite->sTimer & 15) == 0) - { sprite->sBobY = -sprite->sBobY; - } } #undef sSpriteId @@ -1184,43 +1180,43 @@ static void SpriteCB_UnderwaterSurfBlob(struct Sprite *sprite) u32 FldEff_Dust(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 12); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_GROUND_IMPACT_DUST], gFieldEffectArguments[0], gFieldEffectArguments[1], 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->data[0] = gFieldEffectArguments[2]; - sprite->data[1] = FLDEFF_DUST; + sprite->sJumpElevation = gFieldEffectArguments[2]; + sprite->sJumpFldEff = FLDEFF_DUST; } return 0; } +// Sprite data for FLDEFF_SAND_PILE +#define sLocalId data[0] +#define sMapNum data[1] +#define sMapGroup data[2] +#define sPrevX data[3] +#define sPrevY data[4] + u32 FldEff_SandPile(void) { - u8 objectEventId; - struct ObjectEvent *objectEvent; - u8 spriteId; - struct Sprite *sprite; - const struct ObjectEventGraphicsInfo *graphicsInfo; - - objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - objectEvent = &gObjectEvents[objectEventId]; - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SAND_PILE], 0, 0, 0); + u8 objectEventId = GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + struct ObjectEvent *objectEvent = &gObjectEvents[objectEventId]; + u8 spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SAND_PILE], 0, 0, 0); if (spriteId != MAX_SPRITES) { - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); - sprite = &gSprites[spriteId]; + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gSprites[objectEvent->spriteId].oam.priority; - sprite->data[0] = gFieldEffectArguments[0]; - sprite->data[1] = gFieldEffectArguments[1]; - sprite->data[2] = gFieldEffectArguments[2]; - sprite->data[3] = gSprites[objectEvent->spriteId].x; - sprite->data[4] = gSprites[objectEvent->spriteId].y; + sprite->sLocalId = gFieldEffectArguments[0]; + sprite->sMapNum = gFieldEffectArguments[1]; + sprite->sMapGroup = gFieldEffectArguments[2]; + sprite->sPrevX = gSprites[objectEvent->spriteId].x; + sprite->sPrevY = gSprites[objectEvent->spriteId].y; sprite->y2 = (graphicsInfo->height >> 1) - 2; SeekSpriteAnim(sprite, 2); } @@ -1230,81 +1226,85 @@ u32 FldEff_SandPile(void) void UpdateSandPileFieldEffect(struct Sprite *sprite) { u8 objectEventId; - s16 x; - s16 y; - if (TryGetObjectEventIdByLocalIdAndMap(sprite->data[0], sprite->data[1], sprite->data[2], &objectEventId) || !gObjectEvents[objectEventId].inSandPile) + if (TryGetObjectEventIdByLocalIdAndMap(sprite->sLocalId, sprite->sMapNum, sprite->sMapGroup, &objectEventId) || !gObjectEvents[objectEventId].inSandPile) { FieldEffectStop(sprite, FLDEFF_SAND_PILE); } else { - y = gSprites[gObjectEvents[objectEventId].spriteId].y; - x = gSprites[gObjectEvents[objectEventId].spriteId].x; - if (x != sprite->data[3] || y != sprite->data[4]) + s16 parentY = gSprites[gObjectEvents[objectEventId].spriteId].y; + s16 parentX = gSprites[gObjectEvents[objectEventId].spriteId].x; + if (parentX != sprite->sPrevX || parentY != sprite->sPrevY) { - sprite->data[3] = x; - sprite->data[4] = y; + sprite->sPrevX = parentX; + sprite->sPrevY = parentY; if (sprite->animEnded) - { StartSpriteAnim(sprite, 0); - } } - sprite->x = x; - sprite->y = y; + sprite->x = parentX; + sprite->y = parentY; sprite->subpriority = gSprites[gObjectEvents[objectEventId].spriteId].subpriority; UpdateObjectEventSpriteInvisibility(sprite, FALSE); } } +#undef sLocalId +#undef sMapNum +#undef sMapGroup +#undef sPrevX +#undef sPrevY + u32 FldEff_Bubbles(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 0); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BUBBLES], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x52); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BUBBLES], gFieldEffectArguments[0], gFieldEffectArguments[1], 82); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = 1; } return 0; } +#define sY data[0] + void UpdateBubblesFieldEffect(struct Sprite *sprite) { - sprite->data[0] += 0x80; - sprite->data[0] &= 0x100; - sprite->y -= sprite->data[0] >> 8; + // Move up 1 every other frame. + sprite->sY += ((1 << 8) / 2); + sprite->sY &= (1 << 8); + sprite->y -= sprite->sY >> 8; UpdateObjectEventSpriteInvisibility(sprite, FALSE); if (sprite->invisible || sprite->animEnded) - { FieldEffectStop(sprite, FLDEFF_BUBBLES); - } } +#undef sY + u32 FldEff_BerryTreeGrowthSparkle(void) { u8 spriteId; - struct Sprite *sprite; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 4); spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SPARKLE], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; sprite->oam.paletteNum = 5; - sprite->data[0] = FLDEFF_BERRY_TREE_GROWTH_SPARKLE; + sprite->sWaitFldEff = FLDEFF_BERRY_TREE_GROWTH_SPARKLE; } return 0; } // Sprite data for FLDEFF_TREE_DISGUISE / FLDEFF_MOUNTAIN_DISGUISE / FLDEFF_SAND_DISGUISE #define sState data[0] +#define sFldEff data[1] #define sLocalId data[2] #define sMapNum data[3] #define sMapGroup data[4] @@ -1328,7 +1328,6 @@ u32 ShowSandDisguiseFieldEffect(void) static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 fldEffObj, u8 paletteNum) { u8 spriteId; - struct Sprite *sprite; if (TryGetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2], &spriteId)) { @@ -1338,7 +1337,7 @@ static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 fldEffObj, u8 paletteNum) spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[fldEffObj], 0, 0, 0); if (spriteId != MAX_SPRITES) { - sprite = &gSprites[spriteId]; + struct Sprite *sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled ++; sprite->oam.paletteNum = paletteNum; sprite->sFldEff = fldEff; @@ -1405,6 +1404,7 @@ bool8 UpdateRevealDisguise(struct ObjectEvent *objectEvent) } #undef sState +#undef sFldEff #undef sLocalId #undef sMapNum #undef sMapGroup @@ -1421,7 +1421,7 @@ u32 FldEff_Sparkle(void) gFieldEffectArguments[0] += MAP_OFFSET; gFieldEffectArguments[1] += MAP_OFFSET; SetSpritePosToOffsetMapCoords((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SMALL_SPARKLE], gFieldEffectArguments[0], gFieldEffectArguments[1], 0x52); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_SMALL_SPARKLE], gFieldEffectArguments[0], gFieldEffectArguments[1], 82); if (spriteId != MAX_SPRITES) { gSprites[spriteId].oam.priority = gFieldEffectArguments[2]; @@ -1449,7 +1449,9 @@ void UpdateSparkleFieldEffect(struct Sprite *sprite) #undef sEndTimer #define sTimer data[0] +#define sMoveTimer data[1] #define sState data[2] +#define sVelocity data[3] #define sStartY data[4] #define sCounter data[5] #define sAnimCounter data[6] @@ -1615,41 +1617,44 @@ void UpdateRayquazaSpotlightEffect(struct Sprite *sprite) if (sprite->sState == 1) { - if ((sprite->data[1] & 7) == 0) - sprite->y2 += sprite->data[3]; - if ((sprite->data[1] & 15) == 0) - sprite->data[3] = -sprite->data[3]; - sprite->data[1]++; + // Update movement + if ((sprite->sMoveTimer & 7) == 0) + sprite->y2 += sprite->sVelocity; + // Reverse direction + if ((sprite->sMoveTimer & 15) == 0) + sprite->sVelocity = -sprite->sVelocity; + sprite->sMoveTimer++; } sprite->sTimer++; } #undef sTimer +#undef sMoveTimer #undef sState #undef sStartY +#undef sVelocity #undef sCounter #undef sAnimCounter #undef sAnimState -// Used by FLDEFF_JUMP_TALL_GRASS and FLDEFF_JUMP_LONG_GRASS void UpdateJumpImpactEffect(struct Sprite *sprite) { if (sprite->animEnded) { - FieldEffectStop(sprite, sprite->sFldEff); + FieldEffectStop(sprite, sprite->sJumpFldEff); } else { UpdateObjectEventSpriteInvisibility(sprite, FALSE); - SetObjectSubpriorityByElevation(sprite->sElevation, sprite, 0); + SetObjectSubpriorityByElevation(sprite->sJumpElevation, sprite, 0); } } void WaitFieldEffectSpriteAnim(struct Sprite *sprite) { if (sprite->animEnded) - FieldEffectStop(sprite, sprite->data[0]); + FieldEffectStop(sprite, sprite->sWaitFldEff); else UpdateObjectEventSpriteInvisibility(sprite, FALSE); } @@ -1658,8 +1663,6 @@ static void UpdateGrassFieldEffectSubpriority(struct Sprite *sprite, u8 elevatio { u8 i; s16 var, xhi, lyhi, yhi, ylo; - const struct ObjectEventGraphicsInfo *graphicsInfo; // Unused Variable - struct Sprite *linkedSprite; SetObjectSubpriorityByElevation(elevation, sprite, subpriority); for (i = 0; i < OBJECT_EVENTS_COUNT; i ++) @@ -1667,8 +1670,9 @@ static void UpdateGrassFieldEffectSubpriority(struct Sprite *sprite, u8 elevatio struct ObjectEvent *objectEvent = &gObjectEvents[i]; if (objectEvent->active) { - graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); - linkedSprite = &gSprites[objectEvent->spriteId]; + const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); // Unused + struct Sprite *linkedSprite = &gSprites[objectEvent->spriteId]; + xhi = sprite->x + sprite->centerToCornerVecX; var = sprite->x - sprite->centerToCornerVecX; if (xhi < linkedSprite->x && var > linkedSprite->x) diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index 06df5d0a33..b01427ebdf 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -1116,7 +1116,7 @@ static u8 GetPartyIdFromSelectionId_(u8 selectionId) static void LoadAndCreateUpDownSprites(void) { - u16 i, spriteId; + u16 i; LoadSpriteSheet(&sSpriteSheet_UpDown); LoadSpritePalette(&sSpritePalette_UpDown); @@ -1126,7 +1126,7 @@ static void LoadAndCreateUpDownSprites(void) { if (sInfo->enhancements[i] != 0) { - spriteId = CreateSprite(&sSpriteTemplate_UpDown, sUpDownCoordsOnGraph[i][0], sUpDownCoordsOnGraph[i][1], 0); + u16 spriteId = CreateSprite(&sSpriteTemplate_UpDown, sUpDownCoordsOnGraph[i][0], sUpDownCoordsOnGraph[i][1], 0); if (spriteId != MAX_SPRITES) { if (sInfo->enhancements[i] != 0) // Always true here @@ -1137,20 +1137,24 @@ static void LoadAndCreateUpDownSprites(void) } } +#define tTimer data[0] + static void SpriteCB_UpDown(struct Sprite *sprite) { - if (sprite->data[0] < 6) + if (sprite->tTimer < 6) sprite->y2 -= 2; - else if (sprite->data[0] < 12) + else if (sprite->tTimer < 12) sprite->y2 += 2; - if (++sprite->data[0] > 60) + if (++sprite->tTimer > 60) { DestroySprite(sprite); sInfo->numEnhancements--; } } +#undef tTimer + static void LoadPartyInfo(void) { u16 i; @@ -1612,12 +1616,15 @@ static void LoadConditionGfx(void) LoadSpritePalette(&spritePalette); } +#define sSpeed data[0] +#define sTargetX data[1] + static void CreateConditionSprite(void) { u16 i; s16 xDiff, xStart; int yStart = 17; - int var = 8; + int speed = 8; struct Sprite **sprites = sMenu->condition; const struct SpriteTemplate *template = &sSpriteTemplate_Condition; @@ -1626,9 +1633,9 @@ static void CreateConditionSprite(void) u8 spriteId = CreateSprite(template, i * xDiff + xStart, yStart, 0); if (spriteId != MAX_SPRITES) { - gSprites[spriteId].data[0] = var; - gSprites[spriteId].data[1] = (i * xDiff) | 0x20; - gSprites[spriteId].data[2] = i; + gSprites[spriteId].sSpeed = speed; + gSprites[spriteId].sTargetX = (i * xDiff) | 0x20; + gSprites[spriteId].data[2] = i; // Unused StartSpriteAnim(&gSprites[spriteId], i); sprites[i] = &gSprites[spriteId]; } @@ -1657,11 +1664,15 @@ static void SpriteCB_Condition(struct Sprite *sprite) { s16 prevX = sprite->x; - sprite->x += sprite->data[0]; - if ((prevX <= sprite->data[1] && sprite->x >= sprite->data[1]) - || (prevX >= sprite->data[1] && sprite->x <= sprite->data[1])) + // Slide onscreen + sprite->x += sprite->sSpeed; + + // Check if target position has been reached/surpassed + if ((prevX <= sprite->sTargetX && sprite->x >= sprite->sTargetX) + || (prevX >= sprite->sTargetX && sprite->x <= sprite->sTargetX)) { - sprite->x = sprite->data[1]; + // End slide onscreen, become static sprite. + sprite->x = sprite->sTargetX; sprite->callback = SpriteCallbackDummy; } }