pokeemerald/src/battle_anim_smokescreen.c

218 lines
5.8 KiB
C
Raw Normal View History

2018-02-12 12:14:04 +01:00
#include "global.h"
2020-02-11 19:54:23 +01:00
#include "battle_gfx_sfx_util.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
2018-02-12 12:14:04 +01:00
#include "decompress.h"
2020-02-11 19:54:23 +01:00
#include "graphics.h"
2018-02-12 12:14:04 +01:00
#include "sprite.h"
#include "util.h"
2020-02-11 19:54:23 +01:00
#include "constants/pokemon.h"
2018-02-12 12:14:04 +01:00
2019-11-23 11:57:39 +01:00
static void SmokescreenImpact_Callback(struct Sprite *);
2020-02-11 19:54:23 +01:00
static void SpriteCB_DestroySprite(struct Sprite *sprite);
2018-02-12 12:14:04 +01:00
2020-02-11 19:54:23 +01:00
// The below data for smokescreen starts and ends with some data that belongs to battle_gfx_sfx_util.c
const u8 gUnknown_0831C604[] =
{
[NATURE_HARDY] = 0,
[NATURE_LONELY] = 0,
[NATURE_BRAVE] = 1,
[NATURE_ADAMANT] = 0,
[NATURE_NAUGHTY] = 1,
[NATURE_BOLD] = 1,
[NATURE_DOCILE] = 2,
[NATURE_RELAXED] = 0,
[NATURE_IMPISH] = 0,
[NATURE_LAX] = 0,
[NATURE_TIMID] = 1,
[NATURE_HASTY] = 1,
[NATURE_SERIOUS] = 1,
[NATURE_JOLLY] = 0,
[NATURE_NAIVE] = 2,
[NATURE_MODEST] = 1,
[NATURE_MILD] = 0,
[NATURE_QUIET] = 1,
[NATURE_BASHFUL] = 1,
[NATURE_RASH] = 0,
[NATURE_CALM] = 0,
[NATURE_GENTLE] = 0,
[NATURE_SASSY] = 1,
[NATURE_CAREFUL] = 1,
[NATURE_QUIRKY] = 0,
};
static const struct CompressedSpriteSheet sSmokescreenImpactSpriteSheet =
2020-02-11 19:54:23 +01:00
{
.data = gSmokescreenImpactTiles, .size = 0x180, .tag = 55019
};
static const struct CompressedSpritePalette sSmokescreenImpactSpritePalette =
2020-02-11 19:54:23 +01:00
{
.data = gSmokescreenImpactPalette, .tag = 55019
};
static const struct OamData sOamData_SmokescreenImpact =
2020-02-11 19:54:23 +01:00
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(16x16),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(16x16),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0
};
static const union AnimCmd sAnim_SmokescreenImpact_0[] =
2020-02-11 19:54:23 +01:00
{
ANIMCMD_FRAME(0, 4),
ANIMCMD_FRAME(4, 4),
ANIMCMD_FRAME(8, 4),
ANIMCMD_END
};
static const union AnimCmd sAnim_SmokescreenImpact_1[] =
2020-02-11 19:54:23 +01:00
{
ANIMCMD_FRAME(0, 4, .hFlip = TRUE),
ANIMCMD_FRAME(4, 4, .hFlip = TRUE),
ANIMCMD_FRAME(8, 4, .hFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_SmokescreenImpact_2[] =
2020-02-11 19:54:23 +01:00
{
ANIMCMD_FRAME(0, 4, .vFlip = TRUE),
ANIMCMD_FRAME(4, 4, .vFlip = TRUE),
ANIMCMD_FRAME(8, 4, .vFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd sAnim_SmokescreenImpact_3[] =
2020-02-11 19:54:23 +01:00
{
ANIMCMD_FRAME(0, 4, .hFlip = TRUE, .vFlip = TRUE),
ANIMCMD_FRAME(4, 4, .hFlip = TRUE, .vFlip = TRUE),
ANIMCMD_FRAME(8, 4, .hFlip = TRUE, .vFlip = TRUE),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_SmokescreenImpact[] =
2020-02-11 19:54:23 +01:00
{
sAnim_SmokescreenImpact_0,
sAnim_SmokescreenImpact_1,
sAnim_SmokescreenImpact_2,
sAnim_SmokescreenImpact_3,
2020-02-11 19:54:23 +01:00
};
static const struct SpriteTemplate sSmokescreenImpactSpriteTemplate =
2020-02-11 19:54:23 +01:00
{
.tileTag = 55019,
.paletteTag = 55019,
.oam = &sOamData_SmokescreenImpact,
.anims = sAnims_SmokescreenImpact,
2020-02-11 19:54:23 +01:00
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_DestroySprite
};
const struct CompressedSpriteSheet gSpriteSheet_EnemyShadow =
{
.data = gEnemyMonShadow_Gfx, .size = 0x80, .tag = 55129
};
static const struct OamData gUnknown_0831C6A8 =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(32x8),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(32x8),
.tileNum = 0,
.priority = 3,
.paletteNum = 0,
.affineParam = 0
};
const struct SpriteTemplate gSpriteTemplate_EnemyShadow =
{
.tileTag = 55129,
.paletteTag = 55039,
.oam = &gUnknown_0831C6A8,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_SetInvisible
};
2019-04-04 23:53:06 +02:00
2019-11-23 11:57:39 +01:00
u8 SmokescreenImpact(s16 x, s16 y, u8 a3)
2018-02-12 12:14:04 +01:00
{
u8 mainSpriteId;
u8 spriteId1, spriteId2, spriteId3, spriteId4;
struct Sprite *mainSprite;
if (GetSpriteTileStartByTag(sSmokescreenImpactSpriteSheet.tag) == 0xFFFF)
2018-02-12 12:14:04 +01:00
{
LoadCompressedSpriteSheetUsingHeap(&sSmokescreenImpactSpriteSheet);
LoadCompressedSpritePaletteUsingHeap(&sSmokescreenImpactSpritePalette);
2018-02-12 12:14:04 +01:00
}
2019-11-23 11:57:39 +01:00
mainSpriteId = CreateInvisibleSpriteWithCallback(SmokescreenImpact_Callback);
2018-02-12 12:14:04 +01:00
mainSprite = &gSprites[mainSpriteId];
mainSprite->data[1] = a3;
spriteId1 = CreateSprite(&sSmokescreenImpactSpriteTemplate, x - 16, y - 16, 2);
2018-02-12 12:14:04 +01:00
gSprites[spriteId1].data[0] = mainSpriteId;
mainSprite->data[0]++;
AnimateSprite(&gSprites[spriteId1]);
spriteId2 = CreateSprite(&sSmokescreenImpactSpriteTemplate, x, y - 16, 2);
2018-02-12 12:14:04 +01:00
gSprites[spriteId2].data[0] = mainSpriteId;
mainSprite->data[0]++;
StartSpriteAnim(&gSprites[spriteId2], 1);
AnimateSprite(&gSprites[spriteId2]);
spriteId3 = CreateSprite(&sSmokescreenImpactSpriteTemplate, x - 16, y, 2);
2018-02-12 12:14:04 +01:00
gSprites[spriteId3].data[0] = mainSpriteId;
mainSprite->data[0]++;
StartSpriteAnim(&gSprites[spriteId3], 2);
AnimateSprite(&gSprites[spriteId3]);
spriteId4 = CreateSprite(&sSmokescreenImpactSpriteTemplate, x, y, 2);
2018-02-12 12:14:04 +01:00
gSprites[spriteId4].data[0] = mainSpriteId;
mainSprite->data[0]++;
StartSpriteAnim(&gSprites[spriteId4], 3);
AnimateSprite(&gSprites[spriteId4]);
return mainSpriteId;
}
2019-11-23 11:57:39 +01:00
static void SmokescreenImpact_Callback(struct Sprite *sprite)
2018-02-12 12:14:04 +01:00
{
if (!sprite->data[0])
{
FreeSpriteTilesByTag(sSmokescreenImpactSpriteSheet.tag);
FreeSpritePaletteByTag(sSmokescreenImpactSpritePalette.tag);
2018-02-12 12:14:04 +01:00
if (!sprite->data[1])
DestroySprite(sprite);
else
sprite->callback = SpriteCallbackDummy;
}
}
2020-02-11 19:54:23 +01:00
static void SpriteCB_DestroySprite(struct Sprite *sprite)
2018-02-12 12:14:04 +01:00
{
if (sprite->animEnded)
{
gSprites[sprite->data[0]].data[0]--;
DestroySprite(sprite);
}
}