diff --git a/INSTALL.md b/INSTALL.md index e74706d6aa30..af2e844677aa 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -150,9 +150,9 @@ Note that in msys2, Copy is Ctrl+Insert and Paste is Shift+Insert.
Notes... - > Note 1: While not shown, msys uses forward slashes `/` instead of backwards slashes `\` as the directory separator. - > Note 2: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Downloads/My Downloads"`. - > Note 3: Windows path names are case-insensitive so adhering to capitalization isn’t needed. + > Note 1: While not shown, msys uses forward slashes `/` instead of backwards slashes `\` as the directory separator. + > Note 2: If the path has spaces, then the path must be wrapped with quotations, e.g. `cd "Downloads/My Downloads"`. + > Note 3: Windows path names are case-insensitive so adhering to capitalization isn’t needed. > Note 4: If libpng was saved elsewhere, you will need to specify the full path to where libpng was downloaded, e.g. `cd c:/devkitpro/msys2` if it was saved there.
diff --git a/src/battle_factory.c b/src/battle_factory.c index 5d7a199dc300..4543bfbad46e 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -741,8 +741,15 @@ u8 GetFactoryMonFixedIV(u8 challengeNum, bool8 isLastBattle) u8 ivSet; bool8 useHigherIV = isLastBattle ? TRUE : FALSE; - if (challengeNum > 8) - ivSet = 7; +// The Factory has an out-of-bounds access when generating the rental draft for round 9 (challengeNum==8), +// or the "elevated" rentals from round 8 (challengeNum+1==8) +// This happens to land on a number higher than 31, which is interpreted as "random IVs" +#ifdef BUGFIX + if (challengeNum >= ARRAY_COUNT(sFixedIVTable)) +#else + if (challengeNum > ARRAY_COUNT(sFixedIVTable)) +#endif + ivSet = ARRAY_COUNT(sFixedIVTable) - 1; else ivSet = challengeNum; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 29969b1f6b0b..cdd72d668c3e 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1325,7 +1325,7 @@ u8 Unref_TryInitLocalObjectEvent(u8 localId) if (InBattlePyramid()) objectEventCount = GetNumBattlePyramidObjectEvents(); else if (InTrainerHill()) - objectEventCount = 2; + objectEventCount = HILL_TRAINERS_PER_FLOOR; else objectEventCount = gMapHeader.events->objectEventCount; @@ -1641,7 +1641,7 @@ void TrySpawnObjectEvents(s16 cameraX, s16 cameraY) if (InBattlePyramid()) objectCount = GetNumBattlePyramidObjectEvents(); else if (InTrainerHill()) - objectCount = 2; + objectCount = HILL_TRAINERS_PER_FLOOR; else objectCount = gMapHeader.events->objectEventCount; diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 386c3c76b27b..ac4dac3ecb0f 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 UNUSED *graphicsInfo; - 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 UNUSED *graphicsInfo = GetObjectEventGraphicsInfo(objectEvent->graphicsId); + 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/map_name_popup.c b/src/map_name_popup.c index 9c9c85cf595e..75e70dafc136 100644 --- a/src/map_name_popup.c +++ b/src/map_name_popup.c @@ -205,22 +205,45 @@ static bool8 UNUSED StartMenu_ShowMapNamePopup(void) return TRUE; } +// States and data defines for Task_MapNamePopUpWindow +enum { + STATE_SLIDE_IN, + STATE_WAIT, + STATE_SLIDE_OUT, + STATE_UNUSED, + STATE_ERASE, + STATE_END, + STATE_PRINT, // For some reason the first state is numerically last. +}; + +#define POPUP_OFFSCREEN_Y 40 +#define POPUP_SLIDE_SPEED 2 + +#define tState data[0] +#define tOnscreenTimer data[1] +#define tYOffset data[2] +#define tIncomingPopUp data[3] +#define tPrintTimer data[4] + void ShowMapNamePopup(void) { if (FlagGet(FLAG_HIDE_MAP_NAME_POPUP) != TRUE) { if (!FuncIsActiveTask(Task_MapNamePopUpWindow)) { + // New pop up window sPopupTaskId = CreateTask(Task_MapNamePopUpWindow, 90); - SetGpuReg(REG_OFFSET_BG0VOFS, 40); - gTasks[sPopupTaskId].data[0] = 6; - gTasks[sPopupTaskId].data[2] = 40; + SetGpuReg(REG_OFFSET_BG0VOFS, POPUP_OFFSCREEN_Y); + gTasks[sPopupTaskId].tState = STATE_PRINT; + gTasks[sPopupTaskId].tYOffset = POPUP_OFFSCREEN_Y; } else { - if (gTasks[sPopupTaskId].data[0] != 2) - gTasks[sPopupTaskId].data[0] = 2; - gTasks[sPopupTaskId].data[3] = 1; + // There's already a pop up window running. + // Hurry the old pop up offscreen so the new one can appear. + if (gTasks[sPopupTaskId].tState != STATE_SLIDE_OUT) + gTasks[sPopupTaskId].tState = STATE_SLIDE_OUT; + gTasks[sPopupTaskId].tIncomingPopUp = TRUE; } } } @@ -229,61 +252,65 @@ static void Task_MapNamePopUpWindow(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { - case 6: - task->data[4]++; - if (task->data[4] > 30) + case STATE_PRINT: + // Wait, then create and print the pop up window + if (++task->tPrintTimer > 30) { - task->data[0] = 0; - task->data[4] = 0; + task->tState = STATE_SLIDE_IN; + task->tPrintTimer = 0; ShowMapNamePopUpWindow(); } break; - case 0: - task->data[2] -= 2; - if (task->data[2] <= 0 ) + case STATE_SLIDE_IN: + // Slide the window onscreen. + task->tYOffset -= POPUP_SLIDE_SPEED; + if (task->tYOffset <= 0 ) { - task->data[2] = 0; - task->data[0] = 1; + task->tYOffset = 0; + task->tState = STATE_WAIT; gTasks[sPopupTaskId].data[1] = 0; } break; - case 1: - task->data[1]++; - if (task->data[1] > 120 ) + case STATE_WAIT: + // Wait while the window is fully onscreen. + if (++task->tOnscreenTimer > 120) { - task->data[1] = 0; - task->data[0] = 2; + task->tOnscreenTimer = 0; + task->tState = STATE_SLIDE_OUT; } break; - case 2: - task->data[2] += 2; - if (task->data[2] > 39) + case STATE_SLIDE_OUT: + // Slide the window offscreen. + task->tYOffset += POPUP_SLIDE_SPEED; + if (task->tYOffset >= POPUP_OFFSCREEN_Y) { - task->data[2] = 40; - if (task->data[3]) + task->tYOffset = POPUP_OFFSCREEN_Y; + if (task->tIncomingPopUp) { - task->data[0] = 6; - task->data[4] = 0; - task->data[3] = 0; + // A new pop up window is incoming, + // return to the first state to show it. + task->tState = STATE_PRINT; + task->tPrintTimer = 0; + task->tIncomingPopUp = FALSE; } else { - task->data[0] = 4; + task->tState = STATE_ERASE; return; } } break; - case 4: + case STATE_ERASE: ClearStdWindowAndFrame(GetMapNamePopUpWindowId(), TRUE); - task->data[0] = 5; + task->tState = STATE_END; break; - case 5: + case STATE_END: HideMapNamePopUpWindow(); return; } - SetGpuReg(REG_OFFSET_BG0VOFS, task->data[2]); + SetGpuReg(REG_OFFSET_BG0VOFS, task->tYOffset); } void HideMapNamePopUpWindow(void) diff --git a/src/menu_specialized.c b/src/menu_specialized.c index 456845e868dc..df3685ecfde8 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -588,7 +588,7 @@ static void ConditionGraph_CalcRightHalf(struct ConditionGraph *graph) // No need for conditional, positions on the Beauty line are always above the Cute line ConditionGraph_CalcLine(graph, graph->scanlineRight[0], &graph->curPositions[GRAPH_BEAUTY], &graph->curPositions[GRAPH_CUTE], TRUE, NULL); - // Calculate Cute -> Tough line (includes left scanline because this crosses the halfway point) + // Calculate Cute -> Smart line (includes left scanline because this crosses the halfway point) i = (graph->curPositions[GRAPH_CUTE].y <= graph->curPositions[GRAPH_SMART].y); ConditionGraph_CalcLine(graph, graph->scanlineRight[0], &graph->curPositions[GRAPH_CUTE], &graph->curPositions[GRAPH_SMART], i, graph->scanlineLeft[0]); diff --git a/src/mini_printf.c b/src/mini_printf.c index 9fb4ecfac9e5..2a8c6e5cb780 100644 --- a/src/mini_printf.c +++ b/src/mini_printf.c @@ -328,7 +328,7 @@ s32 mini_vpprintf(void* buf, const char *fmt, va_list va) break; case 'S' : // preproc encoded string handler ptr = va_arg(va, char*); - len = StringLength(ptr); + len = StringLength((u8*)ptr); if (pad_to > 0) { len = mini_pad(ptr, len, pad_char, pad_to, bf); diff --git a/src/player_pc.c b/src/player_pc.c index 07cc2dba7c43..a10cb2ac2be1 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -222,7 +222,7 @@ static const struct MenuAction sItemStorage_MenuActions[] = [MENU_EXIT] = { gText_Cancel, {ItemStorage_Exit} } }; -static const struct ItemSlot sNewGamePCItems[] = +static const u16 sNewGamePCItems[][2] = { { ITEM_POTION, 1 }, { ITEM_NONE, 0 } @@ -355,16 +355,20 @@ static const struct WindowTemplate sWindowTemplates_ItemStorage[ITEMPC_WIN_COUNT static const u8 sSwapArrowTextColors[] = {TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY, TEXT_COLOR_DARK_GRAY}; -// Macro below is likely a fakematch, equivalent to sNewGamePCItems[i].quantity -#define GET_QUANTITY(i) ((u16)((u16 *)sNewGamePCItems + 1)[i * 2]) void NewGameInitPCItems(void) { u8 i = 0; ClearItemSlots(gSaveBlock1Ptr->pcItems, PC_ITEMS_COUNT); - for(; sNewGamePCItems[i].itemId != ITEM_NONE && GET_QUANTITY(i) && - AddPCItem(sNewGamePCItems[i].itemId, GET_QUANTITY(i)) == TRUE; i++); + + while (TRUE) + { + if (sNewGamePCItems[i][0] == ITEM_NONE || sNewGamePCItems[i][1] == 0) + break; + if (AddPCItem(sNewGamePCItems[i][0], sNewGamePCItems[i][1]) != TRUE) + break; + i++; + } } -#undef GET_QUANTITY void BedroomPC(void) { diff --git a/src/title_screen.c b/src/title_screen.c index 87bf0d970ea5..12015b8bd8aa 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -23,6 +23,12 @@ #include "constants/rgb.h" #include "constants/songs.h" +enum { + TAG_VERSION = 1000, + TAG_PRESS_START_COPYRIGHT, + TAG_LOGO_SHINE, +}; + #define VERSION_BANNER_RIGHT_TILEOFFSET 64 #define VERSION_BANNER_LEFT_X 98 #define VERSION_BANNER_RIGHT_X 162 @@ -158,8 +164,8 @@ static const union AnimCmd *const sVersionBannerRightAnimTable[] = static const struct SpriteTemplate sVersionBannerLeftSpriteTemplate = { - .tileTag = 1000, - .paletteTag = 1000, + .tileTag = TAG_VERSION, + .paletteTag = TAG_VERSION, .oam = &sVersionBannerLeftOamData, .anims = sVersionBannerLeftAnimTable, .images = NULL, @@ -169,8 +175,8 @@ static const struct SpriteTemplate sVersionBannerLeftSpriteTemplate = static const struct SpriteTemplate sVersionBannerRightSpriteTemplate = { - .tileTag = 1000, - .paletteTag = 1000, + .tileTag = TAG_VERSION, + .paletteTag = TAG_VERSION, .oam = &sVersionBannerRightOamData, .anims = sVersionBannerRightAnimTable, .images = NULL, @@ -183,7 +189,7 @@ static const struct CompressedSpriteSheet sSpriteSheet_EmeraldVersion[] = { .data = gTitleScreenEmeraldVersionGfx, .size = 0x1000, - .tag = 1000 + .tag = TAG_VERSION }, {}, }; @@ -205,75 +211,80 @@ static const struct OamData sOamData_CopyrightBanner = .affineParam = 0, }; -static const union AnimCmd sCopyrightBannerAnim0[] = +static const union AnimCmd sAnim_PressStart_0[] = { ANIMCMD_FRAME(1, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim1[] = +static const union AnimCmd sAnim_PressStart_1[] = { ANIMCMD_FRAME(5, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim2[] = +static const union AnimCmd sAnim_PressStart_2[] = { ANIMCMD_FRAME(9, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim3[] = +static const union AnimCmd sAnim_PressStart_3[] = { ANIMCMD_FRAME(13, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim4[] = +static const union AnimCmd sAnim_PressStart_4[] = { ANIMCMD_FRAME(17, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim5[] = +static const union AnimCmd sAnim_Copyright_0[] = { ANIMCMD_FRAME(21, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim6[] = +static const union AnimCmd sAnim_Copyright_1[] = { ANIMCMD_FRAME(25, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim7[] = +static const union AnimCmd sAnim_Copyright_2[] = { ANIMCMD_FRAME(29, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim8[] = +static const union AnimCmd sAnim_Copyright_3[] = { ANIMCMD_FRAME(33, 4), ANIMCMD_END, }; -static const union AnimCmd sCopyrightBannerAnim9[] = +static const union AnimCmd sAnim_Copyright_4[] = { ANIMCMD_FRAME(37, 4), ANIMCMD_END, }; -static const union AnimCmd *const sStartCopyrightBannerAnimTable[] = -{ - sCopyrightBannerAnim0, - sCopyrightBannerAnim1, - sCopyrightBannerAnim2, - sCopyrightBannerAnim3, - sCopyrightBannerAnim4, - sCopyrightBannerAnim5, - sCopyrightBannerAnim6, - sCopyrightBannerAnim7, - sCopyrightBannerAnim8, - sCopyrightBannerAnim9, +// The "Press Start" and copyright graphics are each 5 32x8 segments long +#define NUM_PRESS_START_FRAMES 5 +#define NUM_COPYRIGHT_FRAMES 5 + +static const union AnimCmd *const sStartCopyrightBannerAnimTable[NUM_PRESS_START_FRAMES + NUM_COPYRIGHT_FRAMES] = +{ + sAnim_PressStart_0, + sAnim_PressStart_1, + sAnim_PressStart_2, + sAnim_PressStart_3, + sAnim_PressStart_4, + [NUM_PRESS_START_FRAMES] = + sAnim_Copyright_0, + sAnim_Copyright_1, + sAnim_Copyright_2, + sAnim_Copyright_3, + sAnim_Copyright_4, }; static const struct SpriteTemplate sStartCopyrightBannerSpriteTemplate = { - .tileTag = 1001, - .paletteTag = 1001, + .tileTag = TAG_PRESS_START_COPYRIGHT, + .paletteTag = TAG_PRESS_START_COPYRIGHT, .oam = &sOamData_CopyrightBanner, .anims = sStartCopyrightBannerAnimTable, .images = NULL, @@ -286,7 +297,7 @@ static const struct CompressedSpriteSheet sSpriteSheet_PressStart[] = { .data = gTitleScreenPressStartGfx, .size = 0x520, - .tag = 1001 + .tag = TAG_PRESS_START_COPYRIGHT }, {}, }; @@ -295,7 +306,7 @@ static const struct SpritePalette sSpritePalette_PressStart[] = { { .data = gTitleScreenPressStartPal, - .tag = 1001 + .tag = TAG_PRESS_START_COPYRIGHT }, {}, }; @@ -330,8 +341,8 @@ static const union AnimCmd *const sPokemonLogoShineAnimTable[] = static const struct SpriteTemplate sPokemonLogoShineSpriteTemplate = { - .tileTag = 1002, - .paletteTag = 1001, + .tileTag = TAG_LOGO_SHINE, + .paletteTag = TAG_PRESS_START_COPYRIGHT, .oam = &sPokemonLogoShineOamData, .anims = sPokemonLogoShineAnimTable, .images = NULL, @@ -344,15 +355,25 @@ static const struct CompressedSpriteSheet sPokemonLogoShineSpriteSheet[] = { .data = sTitleScreenLogoShineGfx, .size = 0x800, - .tag = 1002 + .tag = TAG_LOGO_SHINE }, {}, }; -// code +// Task data for the main title screen tasks (Task_TitleScreenPhase#) +#define tCounter data[0] +#define tSkipToNext data[1] +#define tPointless data[2] // Incremented but never used to do anything. +#define tBg2Y data[3] +#define tBg1Y data[4] + +// Sprite data for sVersionBannerLeftSpriteTemplate / sVersionBannerRightSpriteTemplate +#define sAlphaBlendIdx data[0] +#define sParentTaskId data[1] + static void SpriteCB_VersionBannerLeft(struct Sprite *sprite) { - if (gTasks[sprite->data[1]].data[1] != 0) + if (gTasks[sprite->sParentTaskId].tSkipToNext) { sprite->oam.objMode = ST_OAM_OBJ_NORMAL; sprite->y = VERSION_BANNER_Y_GOAL; @@ -361,15 +382,15 @@ static void SpriteCB_VersionBannerLeft(struct Sprite *sprite) { if (sprite->y != VERSION_BANNER_Y_GOAL) sprite->y++; - if (sprite->data[0] != 0) - sprite->data[0]--; - SetGpuReg(REG_OFFSET_BLDALPHA, gTitleScreenAlphaBlend[sprite->data[0]]); + if (sprite->sAlphaBlendIdx != 0) + sprite->sAlphaBlendIdx--; + SetGpuReg(REG_OFFSET_BLDALPHA, gTitleScreenAlphaBlend[sprite->sAlphaBlendIdx]); } } static void SpriteCB_VersionBannerRight(struct Sprite *sprite) { - if (gTasks[sprite->data[1]].data[1] != 0) + if (gTasks[sprite->sParentTaskId].tSkipToNext) { sprite->oam.objMode = ST_OAM_OBJ_NORMAL; sprite->y = VERSION_BANNER_Y_GOAL; @@ -381,13 +402,16 @@ static void SpriteCB_VersionBannerRight(struct Sprite *sprite) } } +// Sprite data for SpriteCB_PressStartCopyrightBanner +#define sAnimate data[0] +#define sTimer data[1] + static void SpriteCB_PressStartCopyrightBanner(struct Sprite *sprite) { - if (sprite->data[0] == 1) + if (sprite->sAnimate == TRUE) { - sprite->data[1]++; // Alternate between hidden and shown every 16th frame - if (sprite->data[1] & 16) + if (++sprite->sTimer & 16) sprite->invisible = FALSE; else sprite->invisible = TRUE; @@ -404,11 +428,11 @@ static void CreatePressStartBanner(s16 x, s16 y) u8 spriteId; x -= 64; - for (i = 0; i < 5; i++, x += 32) + for (i = 0; i < NUM_PRESS_START_FRAMES; i++, x += 32) { spriteId = CreateSprite(&sStartCopyrightBannerSpriteTemplate, x, y, 0); StartSpriteAnim(&gSprites[spriteId], i); - gSprites[spriteId].data[0] = 1; + gSprites[spriteId].sAnimate = TRUE; } } @@ -418,93 +442,122 @@ static void CreateCopyrightBanner(s16 x, s16 y) u8 spriteId; x -= 64; - for (i = 0; i < 5; i++, x += 32) + for (i = 0; i < NUM_COPYRIGHT_FRAMES; i++, x += 32) { spriteId = CreateSprite(&sStartCopyrightBannerSpriteTemplate, x, y, 0); - StartSpriteAnim(&gSprites[spriteId], i + 5); + StartSpriteAnim(&gSprites[spriteId], i + NUM_PRESS_START_FRAMES); } } +#undef sAnimate +#undef sTimer + +// Defines for SpriteCB_PokemonLogoShine +enum { + SHINE_MODE_SINGLE_NO_BG_COLOR, + SHINE_MODE_DOUBLE, + SHINE_MODE_SINGLE, +}; + +#define SHINE_SPEED 4 + +#define sMode data[0] +#define sBgColor data[1] + static void SpriteCB_PokemonLogoShine(struct Sprite *sprite) { if (sprite->x < DISPLAY_WIDTH + 32) { - if (sprite->data[0]) // Flash background + // In any mode except SHINE_MODE_SINGLE_NO_BG_COLOR the background + // color will change, in addition to the shine sprite moving. + if (sprite->sMode != SHINE_MODE_SINGLE_NO_BG_COLOR) { u16 backgroundColor; if (sprite->x < DISPLAY_WIDTH / 2) { // Brighten background color - if (sprite->data[1] < 31) - sprite->data[1]++; - if (sprite->data[1] < 31) - sprite->data[1]++; + if (sprite->sBgColor < 31) + sprite->sBgColor++; + if (sprite->sBgColor < 31) + sprite->sBgColor++; } else { // Darken background color - if (sprite->data[1] != 0) - sprite->data[1]--; - if (sprite->data[1] != 0) - sprite->data[1]--; + if (sprite->sBgColor != 0) + sprite->sBgColor--; + if (sprite->sBgColor != 0) + sprite->sBgColor--; } - backgroundColor = _RGB(sprite->data[1], sprite->data[1], sprite->data[1]); - if (sprite->x == DISPLAY_WIDTH / 2 + 12 - || sprite->x == DISPLAY_WIDTH / 2 + 16 - || sprite->x == DISPLAY_WIDTH / 2 + 20 - || sprite->x == DISPLAY_WIDTH / 2 + 24) + backgroundColor = _RGB(sprite->sBgColor, sprite->sBgColor, sprite->sBgColor); + + // Flash the background green for 4 frames of movement. + // Otherwise use the updating color. + if (sprite->x == DISPLAY_WIDTH / 2 + (3 * SHINE_SPEED) + || sprite->x == DISPLAY_WIDTH / 2 + (4 * SHINE_SPEED) + || sprite->x == DISPLAY_WIDTH / 2 + (5 * SHINE_SPEED) + || sprite->x == DISPLAY_WIDTH / 2 + (6 * SHINE_SPEED)) gPlttBufferFaded[0] = RGB(24, 31, 12); else gPlttBufferFaded[0] = backgroundColor; } - sprite->x += 4; + + sprite->x += SHINE_SPEED; } else { + // Sprite has moved fully offscreen gPlttBufferFaded[0] = RGB_BLACK; DestroySprite(sprite); } } -static void SpriteCB_PokemonLogoShine2(struct Sprite *sprite) +static void SpriteCB_PokemonLogoShine_Fast(struct Sprite *sprite) { if (sprite->x < DISPLAY_WIDTH + 32) - sprite->x += 8; + sprite->x += SHINE_SPEED * 2; else DestroySprite(sprite); } -static void StartPokemonLogoShine(u8 flashBg) +static void StartPokemonLogoShine(u8 mode) { u8 spriteId; - switch (flashBg) + switch (mode) { - case 0: - case 2: + case SHINE_MODE_SINGLE_NO_BG_COLOR: + case SHINE_MODE_SINGLE: + // Create one regular shine sprite. + // If mode is SHINE_MODE_SINGLE it will also change the background color. spriteId = CreateSprite(&sPokemonLogoShineSpriteTemplate, 0, 68, 0); gSprites[spriteId].oam.objMode = ST_OAM_OBJ_WINDOW; - gSprites[spriteId].data[0] = flashBg; + gSprites[spriteId].sMode = mode; break; - case 1: + case SHINE_MODE_DOUBLE: + // Create an invisible sprite with mode set to update the background color spriteId = CreateSprite(&sPokemonLogoShineSpriteTemplate, 0, 68, 0); gSprites[spriteId].oam.objMode = ST_OAM_OBJ_WINDOW; - gSprites[spriteId].data[0] = flashBg; + gSprites[spriteId].sMode = mode; gSprites[spriteId].invisible = TRUE; + // Create two faster shine sprites spriteId = CreateSprite(&sPokemonLogoShineSpriteTemplate, 0, 68, 0); - gSprites[spriteId].callback = SpriteCB_PokemonLogoShine2; + gSprites[spriteId].callback = SpriteCB_PokemonLogoShine_Fast; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_WINDOW; spriteId = CreateSprite(&sPokemonLogoShineSpriteTemplate, -80, 68, 0); - gSprites[spriteId].callback = SpriteCB_PokemonLogoShine2; + gSprites[spriteId].callback = SpriteCB_PokemonLogoShine_Fast; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_WINDOW; break; } } +#undef sMode +#undef sBgColor + static void VBlankCB(void) { ScanlineEffect_InitHBlankDmaTransfer(); @@ -514,9 +567,6 @@ static void VBlankCB(void) SetGpuReg(REG_OFFSET_BG1VOFS, gBattle_BG1_Y); } -#define tCounter data[0] -#define tSkipToNext data[1] - void CB2_InitTitleScreen(void) { switch (gMain.state) @@ -573,13 +623,13 @@ void CB2_InitTitleScreen(void) gTasks[taskId].tCounter = 256; gTasks[taskId].tSkipToNext = FALSE; - gTasks[taskId].data[2] = -16; - gTasks[taskId].data[3] = -32; + gTasks[taskId].tPointless = -16; + gTasks[taskId].tBg2Y = -32; gMain.state = 3; break; } case 3: - BeginNormalPaletteFade(PALETTES_ALL, 1, 0x10, 0, RGB_WHITEALPHA); + BeginNormalPaletteFade(PALETTES_ALL, 1, 16, 0, RGB_WHITEALPHA); SetVBlankCallback(VBlankCB); gMain.state = 4; break; @@ -614,7 +664,7 @@ void CB2_InitTitleScreen(void) case 5: if (!UpdatePaletteFade()) { - StartPokemonLogoShine(0); + StartPokemonLogoShine(SHINE_MODE_SINGLE_NO_BG_COLOR); ScanlineEffect_InitWave(0, DISPLAY_HEIGHT, 4, 4, 0, SCANLINE_EFFECT_REG_BG1HOFS, TRUE); SetMainCallback2(MainCB2); } @@ -634,7 +684,7 @@ static void MainCB2(void) static void Task_TitleScreenPhase1(u8 taskId) { // Skip to next phase when A, B, Start, or Select is pressed - if (JOY_NEW(A_B_START_SELECT) || gTasks[taskId].data[1] != 0) + if (JOY_NEW(A_B_START_SELECT) || gTasks[taskId].tSkipToNext) { gTasks[taskId].tSkipToNext = TRUE; gTasks[taskId].tCounter = 0; @@ -644,9 +694,9 @@ static void Task_TitleScreenPhase1(u8 taskId) { u16 frameNum = gTasks[taskId].tCounter; if (frameNum == 176) - StartPokemonLogoShine(1); + StartPokemonLogoShine(SHINE_MODE_DOUBLE); else if (frameNum == 64) - StartPokemonLogoShine(2); + StartPokemonLogoShine(SHINE_MODE_SINGLE); gTasks[taskId].tCounter--; } @@ -663,18 +713,21 @@ static void Task_TitleScreenPhase1(u8 taskId) // Create left side of version banner spriteId = CreateSprite(&sVersionBannerLeftSpriteTemplate, VERSION_BANNER_LEFT_X, VERSION_BANNER_Y, 0); - gSprites[spriteId].data[0] = 64; - gSprites[spriteId].data[1] = taskId; + gSprites[spriteId].sAlphaBlendIdx = ARRAY_COUNT(gTitleScreenAlphaBlend); + gSprites[spriteId].sParentTaskId = taskId; // Create right side of version banner spriteId = CreateSprite(&sVersionBannerRightSpriteTemplate, VERSION_BANNER_RIGHT_X, VERSION_BANNER_Y, 0); - gSprites[spriteId].data[1] = taskId; + gSprites[spriteId].sParentTaskId = taskId; gTasks[taskId].tCounter = 144; gTasks[taskId].func = Task_TitleScreenPhase2; } } +#undef sParentTaskId +#undef sAlphaBlendIdx + // Create "Press Start" and copyright banners, and slide Pokemon logo up static void Task_TitleScreenPhase2(u8 taskId) { @@ -705,31 +758,31 @@ static void Task_TitleScreenPhase2(u8 taskId) | DISPCNT_OBJ_ON); CreatePressStartBanner(START_BANNER_X, 108); CreateCopyrightBanner(START_BANNER_X, 148); - gTasks[taskId].data[4] = 0; + gTasks[taskId].tBg1Y = 0; gTasks[taskId].func = Task_TitleScreenPhase3; } - if (!(gTasks[taskId].tCounter & 3) && gTasks[taskId].data[2] != 0) - gTasks[taskId].data[2]++; - if (!(gTasks[taskId].tCounter & 1) && gTasks[taskId].data[3] != 0) - gTasks[taskId].data[3]++; + if (!(gTasks[taskId].tCounter & 3) && gTasks[taskId].tPointless != 0) + gTasks[taskId].tPointless++; + if (!(gTasks[taskId].tCounter & 1) && gTasks[taskId].tBg2Y != 0) + gTasks[taskId].tBg2Y++; // Slide Pokemon logo up - yPos = gTasks[taskId].data[3] * 256; + yPos = gTasks[taskId].tBg2Y * 256; SetGpuReg(REG_OFFSET_BG2Y_L, yPos); SetGpuReg(REG_OFFSET_BG2Y_H, yPos / 0x10000); - gTasks[taskId].data[5] = 15; - gTasks[taskId].data[6] = 6; + gTasks[taskId].data[5] = 15; // Unused + gTasks[taskId].data[6] = 6; // Unused } // Show Rayquaza silhouette and process main title screen input static void Task_TitleScreenPhase3(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(START_BUTTON))) + if (JOY_NEW(A_BUTTON) || JOY_NEW(START_BUTTON)) { FadeOutBGM(4); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITEALPHA); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITEALPHA); SetMainCallback2(CB2_GoToMainMenu); } else if (JOY_HELD(CLEAR_SAVE_BUTTON_COMBO) == CLEAR_SAVE_BUTTON_COMBO) @@ -740,30 +793,29 @@ static void Task_TitleScreenPhase3(u8 taskId) && CanResetRTC() == TRUE) { FadeOutBGM(4); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); SetMainCallback2(CB2_GoToResetRtcScreen); } else if (JOY_HELD(BERRY_UPDATE_BUTTON_COMBO) == BERRY_UPDATE_BUTTON_COMBO) { FadeOutBGM(4); - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK); SetMainCallback2(CB2_GoToBerryFixScreen); } else { SetGpuReg(REG_OFFSET_BG2Y_L, 0); SetGpuReg(REG_OFFSET_BG2Y_H, 0); - gTasks[taskId].tCounter++; - if (gTasks[taskId].tCounter & 1) + if (++gTasks[taskId].tCounter & 1) { - gTasks[taskId].data[4]++; - gBattle_BG1_Y = gTasks[taskId].data[4] / 2; + gTasks[taskId].tBg1Y++; + gBattle_BG1_Y = gTasks[taskId].tBg1Y / 2; gBattle_BG1_X = 0; } UpdateLegendaryMarkingColor(gTasks[taskId].tCounter); if ((gMPlayInfo_BGM.status & 0xFFFF) == 0) { - BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITEALPHA); + BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_WHITEALPHA); SetMainCallback2(CB2_GoToCopyrightScreen); } } diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 78604f2f49cd..98f5578e30dd 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -650,7 +650,7 @@ void LoadTrainerHillObjectEventTemplates(void) eventTemplates[i].localId = i + 1; eventTemplates[i].graphicsId = FacilityClassToGraphicsId(sHillData->floors[floorId].trainers[i].facilityClass); eventTemplates[i].x = sHillData->floors[floorId].map.trainerCoords[i] & 0xF; - eventTemplates[i].y = ((sHillData->floors[floorId].map.trainerCoords[i] >> 4) & 0xF) + 5; + eventTemplates[i].y = ((sHillData->floors[floorId].map.trainerCoords[i] >> 4) & 0xF) + HILL_FLOOR_HEIGHT_MARGIN; bits = i << 2; eventTemplates[i].movementType = ((sHillData->floors[floorId].map.trainerDirections >> bits) & 0xF) + MOVEMENT_TYPE_FACE_UP; eventTemplates[i].trainerRange_berryTreeId = (sHillData->floors[floorId].map.trainerRanges >> bits) & 0xF; diff --git a/src/use_pokeblock.c b/src/use_pokeblock.c index 1defb73ea943..2aefdedf38e3 100644 --- a/src/use_pokeblock.c +++ b/src/use_pokeblock.c @@ -1115,7 +1115,7 @@ static u8 UNUSED GetPartyIdFromSelectionId_(u8 selectionId) static void LoadAndCreateUpDownSprites(void) { - u16 i, spriteId; + u16 i; LoadSpriteSheet(&sSpriteSheet_UpDown); LoadSpritePalette(&sSpritePalette_UpDown); @@ -1125,7 +1125,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 @@ -1136,20 +1136,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; @@ -1611,12 +1615,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; @@ -1625,9 +1632,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]; } @@ -1656,11 +1663,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; } }