diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 7d66072a76..701a47f409 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -106,6 +106,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l u8 SpawnSpecialObjectEvent(struct ObjectEventTemplate *); void SetSpritePosToMapCoords(s16, s16, s16 *, s16 *); void CameraObjectReset1(void); +u8 LoadObjectEventPalette(u16); u8 UpdateSpritePaletteByTemplate(const struct SpriteTemplate *, struct Sprite *); void ObjectEventSetGraphicsId(struct ObjectEvent *, u8 graphicsId); void ObjectEventTurn(struct ObjectEvent *, u8); diff --git a/src/event_object_movement.c b/src/event_object_movement.c index b8494bfa02..c2056d1b3e 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -130,7 +130,6 @@ static void UpdateObjectEventVisibility(struct ObjectEvent *, struct Sprite *); static void MakeObjectTemplateFromObjectEventTemplate(struct ObjectEventTemplate *, struct SpriteTemplate *, const struct SubspriteTable **); static void GetObjectEventMovingCameraOffset(s16 *, s16 *); static struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8, u8, u8); -static void LoadObjectEventPalette(u16); static void RemoveObjectEventIfOutsideView(struct ObjectEvent *); static void SpawnObjectEventOnReturnToField(u8, s16, s16); static void SetPlayerAvatarObjectEventIdAndObjectId(u8, u8); @@ -2431,12 +2430,12 @@ void FreeAndReserveObjectSpritePalettes(void) gReservedSpritePaletteCount = 12; } -static void LoadObjectEventPalette(u16 paletteTag) +u8 LoadObjectEventPalette(u16 paletteTag) { u16 i = FindObjectEventPaletteIndexByTag(paletteTag); - - if (i != OBJ_EVENT_PAL_TAG_NONE) // always true - LoadSpritePaletteIfTagExists(&sObjectEventSpritePalettes[i]); + if (i == 0xFF) + return i; + return LoadSpritePaletteIfTagExists(&sObjectEventSpritePalettes[i]); } // Unused @@ -2448,13 +2447,15 @@ static void LoadObjectEventPaletteSet(u16 *paletteTags) LoadObjectEventPalette(paletteTags[i]); } +// Really just loads the palette and applies weather fade static u8 LoadSpritePaletteIfTagExists(const struct SpritePalette *spritePalette) { - u8 paletteNum; - if (IndexOfSpritePaletteTag(spritePalette->tag) != 0xFF) - return 0xFF; + u8 paletteNum = IndexOfSpritePaletteTag(spritePalette->tag); + if (paletteNum != 0xFF) // don't load twice; return + return paletteNum; paletteNum = LoadSpritePalette(spritePalette); - UpdateSpritePaletteWithWeather(paletteNum, FALSE); + if (paletteNum != 0xFF) + UpdateSpritePaletteWithWeather(paletteNum, FALSE); return paletteNum; } diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index 14330bd661..e263ebe23e 100755 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -255,6 +255,8 @@ u8 CreateWarpArrowSprite(void) if (spriteId != MAX_SPRITES) { sprite = &gSprites[spriteId]; + // OBJ_EVENT_PAL_TAG_MAY : OBJ_EVENT_PAL_TAG_BRENDAN + sprite->oam.paletteNum = LoadObjectEventPalette(gSaveBlock2Ptr->playerGender ? 0x1110 : 0x1100); sprite->oam.priority = 1; sprite->coordOffsetEnabled = TRUE; sprite->invisible = TRUE; @@ -1421,7 +1423,7 @@ static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 fldEffObj, u8 paletteNum) if (spriteId != MAX_SPRITES) { sprite = &gSprites[spriteId]; - UpdateSpritePaletteByTemplate(gFieldEffectObjectTemplatePointers[fldEffObj], sprite); + sprite->oam.paletteNum = LoadObjectEventPalette(gFieldEffectObjectTemplatePointers[fldEffObj]->paletteTag); sprite->coordOffsetEnabled ++; sprite->sFldEff = fldEff; sprite->sLocalId = gFieldEffectArguments[0]; diff --git a/src/field_weather.c b/src/field_weather.c index 205b4f7f22..137a167a4e 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -165,7 +165,7 @@ void StartWeather(void) CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32); BuildGammaShiftTables(); gWeatherPtr->altGammaSpritePalIndex = index; - gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2); + gWeatherPtr->weatherPicSpritePalIndex = 0xFF; // defer allocation until needed gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->curRainSpriteIndex = 0; gWeatherPtr->cloudSpritesCreated = 0; @@ -899,6 +899,9 @@ static bool8 IsFirstFrameOfWeatherFadeIn(void) void LoadCustomWeatherSpritePalette(const u16 *palette) { + if (gWeatherPtr->weatherPicSpritePalIndex > 16) // haven't allocated palette yet + if ((gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2)) > 16) + return; LoadPalette(palette, 0x100 + gWeatherPtr->weatherPicSpritePalIndex * 16, 32); UpdateSpritePaletteWithWeather(gWeatherPtr->weatherPicSpritePalIndex, TRUE); }