Fixed bug so that field moves do not clear follower palettes.

This commit is contained in:
Ariel Antonitis 2021-03-03 00:06:30 -05:00
parent 9b25ce9e1f
commit d7697e1502
4 changed files with 17 additions and 8 deletions

View file

@ -1676,9 +1676,10 @@ void FreeSpritePaletteByTag(u16 tag)
{
u8 index = IndexOfSpritePaletteTag(tag);
u16 emptyPalette[16] = {0};
if (index != 0xFF)
sSpritePaletteTags[index] = 0xFFFF;
LoadPalette(emptyPalette, index * 16 + 0x100, 32); // TODO: For debugging only
if (index != 0xFF) {
sSpritePaletteTags[index] = 0xFFFF;
LoadPalette(emptyPalette, index * 16 + 0x100, 32); // TODO: For debugging only
}
}
void SetSubspriteTables(struct Sprite *sprite, const struct SubspriteTable *subspriteTables)

View file

@ -5,6 +5,7 @@ bool16 ResetAllPicSprites(void);
u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 CreateMonPicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 FreeAndDestroyMonPicSprite(u16 spriteId);
u16 FreeAndDestroyMonPicSpriteNoPalette(u16 spriteId);
u16 CreateTrainerPicSprite(u16 species, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 FreeAndDestroyTrainerPicSprite(u16 spriteId);
u16 CreateTrainerCardTrainerPicSprite(u16 species, bool8 isFrontPic, u16 destX, u16 destY, u8 paletteSlot, u8 windowId);

View file

@ -923,12 +923,14 @@ u8 CreateMonSprite_FieldMove(u16 species, u32 otId, u32 personality, s16 x, s16
void FreeResourcesAndDestroySprite(struct Sprite *sprite, u8 spriteId)
{
u8 paletteNum = sprite->oam.paletteNum;
ResetPreservedPalettesInWeather();
if (sprite->oam.affineMode != ST_OAM_AFFINE_OFF)
{
FreeOamMatrix(sprite->oam.matrixNum);
}
FreeAndDestroyMonPicSprite(spriteId);
FreeAndDestroyMonPicSpriteNoPalette(spriteId);
FieldEffectFreePaletteIfUnused(paletteNum); // Clear palette only if unused, in case follower is using it
}
// r, g, b are between 0 and 16

View file

@ -290,7 +290,7 @@ u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s1
return spriteId;
}
static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId)
static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId, bool8 clearPalette)
{
u8 i;
u8 *framePics;
@ -309,7 +309,7 @@ static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId)
}
framePics = sSpritePics[i].frames;
images = sSpritePics[i].images;
if (sSpritePics[i].paletteTag != 0xFFFF)
if (clearPalette && sSpritePics[i].paletteTag != 0xFFFF)
{
FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(gSprites[spriteId].oam.paletteNum));
}
@ -357,7 +357,12 @@ u16 CreateMonPicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, bool
u16 FreeAndDestroyMonPicSprite(u16 spriteId)
{
return FreeAndDestroyPicSpriteInternal(spriteId);
return FreeAndDestroyPicSpriteInternal(spriteId, TRUE);
}
u16 FreeAndDestroyMonPicSpriteNoPalette(u16 spriteId)
{
return FreeAndDestroyPicSpriteInternal(spriteId, FALSE);
}
u16 sub_818D834(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId)
@ -378,7 +383,7 @@ u16 CreateTrainerPicSprite(u16 species, bool8 isFrontPic, s16 x, s16 y, u8 palet
u16 FreeAndDestroyTrainerPicSprite(u16 spriteId)
{
return FreeAndDestroyPicSpriteInternal(spriteId);
return FreeAndDestroyPicSpriteInternal(spriteId, TRUE);
}
u16 sub_818D904(u16 species, bool8 isFrontPic, u8 paletteSlot, u8 windowId)