diff --git a/gflib/sprite.c b/gflib/sprite.c index a840a702fd..db1c7add24 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -607,7 +607,7 @@ u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y, if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK) InitSpriteAffineAnim(sprite); - if (template->paletteTag != 0xFFFF) + if (template->paletteTag != 0xFFFF) // TODO: Load sprite palette if tag not present sprite->oam.paletteNum = IndexOfSpritePaletteTag(template->paletteTag); return index; diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 4aaa066c63..f4667773d7 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -106,7 +106,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l u8 SpawnSpecialObjectEvent(struct ObjectEventTemplate *); void SetSpritePosToMapCoords(s16, s16, s16 *, s16 *); void CameraObjectReset1(void); -u8 UpdateSpritePalette(struct SpritePalette *, struct Sprite *); +u8 UpdateSpritePalette(const struct SpritePalette *, struct Sprite *); void ObjectEventSetGraphicsId(struct ObjectEvent *, u8 graphicsId); void ObjectEventTurn(struct ObjectEvent *, u8); void ObjectEventTurnByLocalIdAndMap(u8, u8, u8, u8); diff --git a/src/data/field_effects/field_effect_objects.h b/src/data/field_effects/field_effect_objects.h index 4fc3ecff69..1f2c354a78 100755 --- a/src/data/field_effects/field_effect_objects.h +++ b/src/data/field_effects/field_effect_objects.h @@ -28,45 +28,13 @@ static const struct SpriteFrameImage sPicTable_ShadowExtraLarge[] = { obj_frame_tiles(gFieldEffectObjectPic_ShadowExtraLarge), }; -const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowSmall = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_8x8, - .anims = sAnimTable_Shadow, - .images = sPicTable_ShadowSmall, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = UpdateShadowFieldEffect, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowSmall = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_8x8, gFieldEffectObjectImageAnimTable_Shadow, gFieldEffectObjectPicTable_ShadowSmall, gDummySpriteAffineAnimTable, UpdateShadowFieldEffect}; -const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowMedium = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_16x8, - .anims = sAnimTable_Shadow, - .images = sPicTable_ShadowMedium, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = UpdateShadowFieldEffect, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowMedium = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_16x8, gFieldEffectObjectImageAnimTable_Shadow, gFieldEffectObjectPicTable_ShadowMedium, gDummySpriteAffineAnimTable, UpdateShadowFieldEffect}; -const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowLarge = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_32x8, - .anims = sAnimTable_Shadow, - .images = sPicTable_ShadowLarge, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = UpdateShadowFieldEffect, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowLarge = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_32x8, gFieldEffectObjectImageAnimTable_Shadow, gFieldEffectObjectPicTable_ShadowLarge, gDummySpriteAffineAnimTable, UpdateShadowFieldEffect}; -const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowExtraLarge = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_64x32, - .anims = sAnimTable_Shadow, - .images = sPicTable_ShadowExtraLarge, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = UpdateShadowFieldEffect, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_ShadowExtraLarge = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_64x32, gFieldEffectObjectImageAnimTable_Shadow, gFieldEffectObjectPicTable_ShadowExtraLarge, gDummySpriteAffineAnimTable, UpdateShadowFieldEffect}; static const struct SpriteFrameImage sPicTable_TallGrass[] = { overworld_frame(gFieldEffectObjectPic_TallGrass, 2, 2, 0), @@ -208,15 +176,7 @@ static const union AnimCmd *const sAnimTable_SurfBlob[] = sSurfBlobAnim_FaceEast, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_SurfBlob = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_32x32, - .anims = sAnimTable_SurfBlob, - .images = sPicTable_SurfBlob, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = UpdateSurfBlobFieldEffect, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_SurfBlob = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_32x32, gFieldEffectObjectImageAnimTable_SurfBlob, gFieldEffectObjectPicTable_SurfBlob, gDummySpriteAffineAnimTable, UpdateSurfBlobFieldEffect}; static const struct SpriteFrameImage sPicTable_Arrow[] = { overworld_frame(gFieldEffectObjectPic_Arrow, 2, 2, 0), @@ -265,15 +225,7 @@ static const union AnimCmd *const sAnimTable_Arrow[] = sArrowAnim_East, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Arrow = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_16x16, - .anims = sAnimTable_Arrow, - .images = sPicTable_Arrow, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Arrow = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_16x16, gFieldEffectObjectImageAnimTable_Arrow, gFieldEffectObjectPicTable_Arrow, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; static const struct SpriteFrameImage sPicTable_GroundImpactDust[] = { overworld_frame(gFieldEffectObjectPic_GroundImpactDust, 2, 1, 0), @@ -1062,15 +1014,7 @@ static const union AnimCmd *const sAnimTable_Bird[] = sAnim_Bird, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_Bird = { - .tileTag = 0xFFFF, - .paletteTag = 0xFFFF, - .oam = &gObjectEventBaseOam_32x32, - .anims = sAnimTable_Bird, - .images = sPicTable_Bird, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = SpriteCallbackDummy, -}; +const struct SpriteTemplate gFieldEffectObjectTemplate_Bird = {0xFFFF, OBJ_EVENT_PAL_TAG_MAY, &gObjectEventBaseOam_32x32, gFieldEffectObjectImageAnimTable_Bird, gFieldEffectObjectPicTable_Bird, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; static const struct SpriteFrameImage sPicTable_ShortGrass[] = { overworld_frame(gFieldEffectObjectPic_ShortGrass, 2, 2, 0), @@ -1147,14 +1091,14 @@ static const union AnimCmd *const sAnimTable_AshPuff[] = sAnim_AshPuff, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_AshPuff = +const struct SpriteTemplate gFieldEffectObjectTemplate_AshPuff = { - .tileTag = 0xFFFF, - .paletteTag = FLDEFF_PAL_TAG_ASH, - .oam = &gObjectEventBaseOam_16x16, - .anims = sAnimTable_AshPuff, - .images = sPicTable_AshPuff, - .affineAnims = gDummySpriteAffineAnimTable, + .tileTag = 0xFFFF, + .paletteTag = FLDEFF_PAL_TAG_ASH, + .oam = &gObjectEventBaseOam_16x16, + .anims = sAnimTable_AshPuff, + .images = sPicTable_AshPuff, + .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_AshPuff }; @@ -1183,14 +1127,14 @@ static const union AnimCmd *const sAnimTable_AshLaunch[] = sAnim_AshLaunch, }; -const struct SpriteTemplate gFieldEffectObjectTemplate_AshLaunch = +const struct SpriteTemplate gFieldEffectObjectTemplate_AshLaunch = { - .tileTag = 0xFFFF, - .paletteTag = FLDEFF_PAL_TAG_ASH, - .oam = &gObjectEventBaseOam_16x16, - .anims = sAnimTable_AshLaunch, - .images = sPicTable_AshLaunch, - .affineAnims = gDummySpriteAffineAnimTable, + .tileTag = 0xFFFF, + .paletteTag = FLDEFF_PAL_TAG_ASH, + .oam = &gObjectEventBaseOam_16x16, + .anims = sAnimTable_AshLaunch, + .images = sPicTable_AshLaunch, + .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCB_AshLaunch }; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 7d20a466c6..c3024ee904 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -140,6 +140,7 @@ static bool8 AnimateSpriteInFigure8(struct Sprite *sprite); static void UpdateObjectEventSprite(struct Sprite *); static void UpdateObjectEventSpriteSubpriorityAndVisibility(struct Sprite *); u8 GetDirectionToFace(s16 x1, s16 y1, s16 x2, s16 y2); +static void ObjectEventSetGraphics(struct ObjectEvent *, const struct ObjectEventGraphicsInfo *); const u8 gReflectionEffectPaletteMap[] = {1, 1, 6, 7, 8, 9, 6, 7, 8, 9, 11, 11, 0, 0, 0, 0}; @@ -1642,27 +1643,9 @@ static const struct ObjectEventGraphicsInfo * SpeciesToGraphicsInfo(u16 species) // Set graphics & sprite for a follower object event by species TODO: Refactoring static void FollowerSetGraphics(struct ObjectEvent *objectEvent, u16 species) { - const struct ObjectEventGraphicsInfo *graphicsInfo = SpeciesToGraphicsInfo(species); - struct Sprite *sprite = &gSprites[objectEvent->spriteId]; - u16 i = FindObjectEventPaletteIndexByTag(graphicsInfo->paletteTag1); - u8 paletteNum = UpdateSpritePalette((struct SpritePalette *)&sObjectEventSpritePalettes[i], sprite); - sprite->oam.paletteNum = paletteNum; - sprite->oam.shape = graphicsInfo->oam->shape; - sprite->oam.size = graphicsInfo->oam->size; - sprite->images = graphicsInfo->images; - sprite->anims = graphicsInfo->anims; - sprite->subspriteTables = graphicsInfo->subspriteTables; - objectEvent->inanimate = graphicsInfo->inanimate; objectEvent->graphicsId = OBJ_EVENT_GFX_FOLLOWER; - SetSpritePosToMapCoords(objectEvent->currentCoords.x, objectEvent->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); - sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); - sprite->centerToCornerVecY = -(graphicsInfo->height >> 1); - sprite->pos1.x += 8; - sprite->pos1.y += 16 + sprite->centerToCornerVecY; - if (objectEvent->trackedByCamera) - { - CameraObjectReset1(); - } + ObjectEventSetGraphics(objectEvent, SpeciesToGraphicsInfo(species)); + objectEvent->graphicsId = OBJ_EVENT_GFX_FOLLOWER; } void UpdateFollowingPokemon(void) { // Update following pokemon if any @@ -1699,7 +1682,7 @@ static bool8 IsFollowerVisible(void) { // Determine whether follower *should* be return !TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING | PLAYER_AVATAR_FLAG_ACRO_BIKE | PLAYER_AVATAR_FLAG_MACH_BIKE); } -bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) +bool8 ScrFunc_getfolloweraction(struct ScriptContext *ctx) // Essentially a big switch for follower messages { u16 value; u16 species; @@ -1900,7 +1883,8 @@ static void SetPlayerAvatarObjectEventIdAndObjectId(u8 objectEventId, u8 spriteI } // Update sprite's palette, freeing old palette if necessary -u8 UpdateSpritePalette(struct SpritePalette * spritePalette, struct Sprite * sprite) { +// TODO: Should this be in sprite.c? +u8 UpdateSpritePalette(const struct SpritePalette * spritePalette, struct Sprite * sprite) { u8 paletteNum = sprite->oam.paletteNum; // Free palette if otherwise unused sprite->inUse = FALSE; @@ -1914,37 +1898,33 @@ u8 UpdateSpritePalette(struct SpritePalette * spritePalette, struct Sprite * spr return paletteNum; } +// Set graphics *by info* +static void ObjectEventSetGraphics(struct ObjectEvent *objectEvent, const struct ObjectEventGraphicsInfo *graphicsInfo) { + struct Sprite *sprite = &gSprites[objectEvent->spriteId]; + u16 i = FindObjectEventPaletteIndexByTag(graphicsInfo->paletteTag1); // TODO: What if this fails? + UpdateSpritePalette(&sObjectEventSpritePalettes[i], sprite); + sprite->oam.shape = graphicsInfo->oam->shape; + sprite->oam.size = graphicsInfo->oam->size; + sprite->images = graphicsInfo->images; + sprite->anims = graphicsInfo->anims; + sprite->subspriteTables = graphicsInfo->subspriteTables; + objectEvent->inanimate = graphicsInfo->inanimate; + SetSpritePosToMapCoords(objectEvent->currentCoords.x, objectEvent->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); + sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); + sprite->centerToCornerVecY = -(graphicsInfo->height >> 1); + sprite->pos1.x += 8; + sprite->pos1.y += 16 + sprite->centerToCornerVecY; + if (objectEvent->trackedByCamera) + { + CameraObjectReset1(); + } +} + void ObjectEventSetGraphicsId(struct ObjectEvent *objectEvent, u8 graphicsId) { - const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(graphicsId); - struct Sprite *sprite = &gSprites[objectEvent->spriteId]; - u16 i; - u8 paletteNum; - - if (graphicsInfo->paletteSlot == 0 && FALSE) { // Hack until I can fix this - PatchObjectPalette(graphicsInfo->paletteTag1, graphicsInfo->paletteSlot); - paletteNum = 0; - } else { - i = FindObjectEventPaletteIndexByTag(graphicsInfo->paletteTag1); - paletteNum = UpdateSpritePalette((struct SpritePalette *)&sObjectEventSpritePalettes[i], sprite); - } - sprite->oam.paletteNum = paletteNum; - sprite->oam.shape = graphicsInfo->oam->shape; - sprite->oam.size = graphicsInfo->oam->size; - sprite->images = graphicsInfo->images; - sprite->anims = graphicsInfo->anims; - sprite->subspriteTables = graphicsInfo->subspriteTables; - objectEvent->inanimate = graphicsInfo->inanimate; objectEvent->graphicsId = graphicsId; - SetSpritePosToMapCoords(objectEvent->currentCoords.x, objectEvent->currentCoords.y, &sprite->pos1.x, &sprite->pos1.y); - sprite->centerToCornerVecX = -(graphicsInfo->width >> 1); - sprite->centerToCornerVecY = -(graphicsInfo->height >> 1); - sprite->pos1.x += 8; - sprite->pos1.y += 16 + sprite->centerToCornerVecY; - if (objectEvent->trackedByCamera) - { - CameraObjectReset1(); - } + ObjectEventSetGraphics(objectEvent, GetObjectEventGraphicsInfo(graphicsId)); + objectEvent->graphicsId = graphicsId; } void ObjectEventSetGraphicsIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup, u8 graphicsId) @@ -1986,19 +1966,7 @@ static void SetBerryTreeGraphics(struct ObjectEvent *objectEvent, u8 berryId, u8 const u8 graphicsId = gBerryTreeObjectEventGraphicsIdTablePointers[berryId][berryStage]; const struct ObjectEventGraphicsInfo *graphicsInfo = GetObjectEventGraphicsInfo(graphicsId); struct Sprite *sprite = &gSprites[objectEvent->spriteId]; - u8 paletteNum = sprite->oam.paletteNum; - u16 paletteTag = sObjectEventSpritePalettes[gBerryTreePaletteSlotTablePointers[berryId][berryStage]-2].tag; - u16 i; - // Free old palette if otherwise unused - sprite->inUse = FALSE; - FieldEffectFreePaletteIfUnused(paletteNum); - sprite->inUse = TRUE; - i = FindObjectEventPaletteIndexByTag(paletteTag); - paletteNum = IndexOfSpritePaletteTag(sObjectEventSpritePalettes[i].tag); - if (paletteNum == 0xFF) { // Load palette - paletteNum = LoadSpritePalette(&sObjectEventSpritePalettes[i]); - } - sprite->oam.paletteNum = paletteNum; + UpdateSpritePalette(&sObjectEventSpritePalettes[gBerryTreePaletteSlotTablePointers[berryId][berryStage]-2], sprite); sprite->oam.shape = graphicsInfo->oam->shape; sprite->oam.size = graphicsInfo->oam->size; sprite->images = gBerryTreePicTablePointers[berryId]; diff --git a/src/field_effect.c b/src/field_effect.c index 8e2a3b067f..e734bd92c1 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -3071,7 +3071,7 @@ u8 FldEff_RayquazaSpotlight(void) struct Sprite *sprite = &gSprites[spriteId]; sprite->oam.priority = 1; - sprite->oam.paletteNum = 4; + sprite->oam.paletteNum = 4; // TODO: What palette should this Raquaza use? sprite->data[0] = 0; sprite->data[1] = 0; sprite->data[2] = 0; @@ -3106,7 +3106,6 @@ u8 FldEff_NPCFlyOut(void) u8 spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BIRD], 0x78, 0, 1); struct Sprite *sprite = &gSprites[spriteId]; - sprite->oam.paletteNum = 0; sprite->oam.priority = 1; sprite->callback = SpriteCB_NPCFlyOut; sprite->data[1] = gFieldEffectArguments[0]; @@ -3288,7 +3287,6 @@ static u8 CreateFlyBirdSprite(void) struct Sprite *sprite; spriteId = CreateSprite(gFieldEffectObjectTemplatePointers[FLDEFFOBJ_BIRD], 0xff, 0xb4, 0x1); sprite = &gSprites[spriteId]; - sprite->oam.paletteNum = 0; sprite->oam.priority = 1; sprite->callback = SpriteCB_FlyBirdLeaveBall; return spriteId; diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 0eb58bf31f..561254a3a7 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -994,7 +994,6 @@ u32 FldEff_SurfBlob(void) { sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; - sprite->oam.paletteNum = 0; sprite->data[2] = gFieldEffectArguments[2]; sprite->data[3] = -1; sprite->data[6] = -1; @@ -1262,7 +1261,7 @@ u32 FldEff_BerryTreeGrowthSparkle(void) sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled = TRUE; sprite->oam.priority = gFieldEffectArguments[3]; - sprite->oam.paletteNum = 5; + sprite->oam.paletteNum = 5; // TODO: What paletteTag does this use? sprite->data[0] = FLDEFF_BERRY_TREE_GROWTH_SPARKLE; } return 0; @@ -1298,7 +1297,7 @@ static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 fldEffObj, u8 paletteNum) { sprite = &gSprites[spriteId]; sprite->coordOffsetEnabled ++; - sprite->oam.paletteNum = paletteNum; + sprite->oam.paletteNum = paletteNum; // TODO: Fix paletteNum sprite->data[1] = fldEff; sprite->data[2] = gFieldEffectArguments[0]; sprite->data[3] = gFieldEffectArguments[1]; diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index b320f3eb00..ac01a9581a 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -1025,7 +1025,7 @@ void DoSecretBaseGlitterMatSparkle(void) { gSprites[spriteId].coordOffsetEnabled = TRUE; gSprites[spriteId].oam.priority = 1; - gSprites[spriteId].oam.paletteNum = 5; + gSprites[spriteId].oam.paletteNum = 5; // TODO: What palette should this use? gSprites[spriteId].callback = SpriteCB_GlitterMatSparkle; gSprites[spriteId].data[0] = 0; }