pokeemerald/src/pokeblock_feed.c

1198 lines
38 KiB
C
Raw Normal View History

2017-12-09 21:23:40 +01:00
#include "global.h"
#include "malloc.h"
2019-04-04 23:53:06 +02:00
#include "battle.h"
2017-12-09 21:23:40 +01:00
#include "bg.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
2017-12-09 21:23:40 +01:00
#include "decompress.h"
#include "event_data.h"
2018-11-14 01:01:50 +01:00
#include "gpu_regs.h"
#include "graphics.h"
2019-04-04 23:53:06 +02:00
#include "item_menu.h"
2018-11-14 01:01:50 +01:00
#include "main.h"
#include "menu.h"
#include "menu_helpers.h"
2017-12-09 21:23:40 +01:00
#include "m4a.h"
2018-11-14 01:01:50 +01:00
#include "palette.h"
#include "party_menu.h"
#include "pokeblock.h"
#include "pokemon.h"
#include "sprite.h"
#include "string_util.h"
#include "strings.h"
2017-12-09 21:23:40 +01:00
#include "sound.h"
2018-11-14 01:01:50 +01:00
#include "task.h"
2018-07-16 20:23:05 +02:00
#include "text_window.h"
2018-11-14 01:01:50 +01:00
#include "trig.h"
#include "util.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2017-12-09 21:23:40 +01:00
2021-04-12 18:33:06 +02:00
enum {
ANIMDATA_ROT_IDX,
ANIMDATA_ROT_SPEED,
ANIMDATA_SIN_AMPLITUDE,
ANIMDATA_COS_AMPLITUDE,
ANIMDATA_TIME,
ANIMDATA_ROT_ACCEL,
ANIMDATA_TARGET_X,
ANIMDATA_TARGET_Y,
ANIMDATA_APPR_TIME,
ANIMDATA_IS_LAST,
NUM_ANIMDATA
};
enum {
AFFINE_NONE,
AFFINE_TURN_UP,
AFFINE_TURN_UP_AND_DOWN,
AFFINE_TURN_DOWN,
AFFINE_TURN_DOWN_SLOW,
AFFINE_TURN_DOWN_SLIGHT,
AFFINE_TURN_UP_HIGH,
AFFINE_UNUSED_1,
AFFINE_UNUSED_2,
AFFINE_UNUSED_3,
NUM_MON_AFFINES,
};
#define MON_X 48
#define MON_Y 80
// The animation the Pokémon does during the feeding scene depends on their nature.
// The below values are offsets into sMonPokeblockAnims of the animation data for that nature.
#define ANIM_HARDY 0
#define ANIM_LONELY (ANIM_HARDY + 3)
#define ANIM_BRAVE (ANIM_LONELY + 1)
#define ANIM_ADAMANT (ANIM_BRAVE + 1)
#define ANIM_NAUGHTY (ANIM_ADAMANT + 5)
#define ANIM_BOLD (ANIM_NAUGHTY + 3)
#define ANIM_DOCILE (ANIM_BOLD + 2)
#define ANIM_RELAXED (ANIM_DOCILE + 1)
#define ANIM_IMPISH (ANIM_RELAXED + 2)
#define ANIM_LAX (ANIM_IMPISH + 1)
#define ANIM_TIMID (ANIM_LAX + 1)
#define ANIM_HASTY (ANIM_TIMID + 5)
#define ANIM_SERIOUS (ANIM_HASTY + 2)
#define ANIM_JOLLY (ANIM_SERIOUS + 1)
#define ANIM_NAIVE (ANIM_JOLLY + 1)
#define ANIM_MODEST (ANIM_NAIVE + 4)
#define ANIM_MILD (ANIM_MODEST + 3)
#define ANIM_QUIET (ANIM_MILD + 1)
#define ANIM_BASHFUL (ANIM_QUIET + 2)
#define ANIM_RASH (ANIM_BASHFUL + 3)
#define ANIM_CALM (ANIM_RASH + 3)
#define ANIM_GENTLE (ANIM_CALM + 1)
#define ANIM_SASSY (ANIM_GENTLE + 1)
#define ANIM_CAREFUL (ANIM_SASSY + 1)
#define ANIM_QUIRKY (ANIM_CAREFUL + 5)
struct PokeblockFeed
2017-12-09 21:23:40 +01:00
{
2017-12-10 15:04:03 +01:00
struct Sprite *monSpritePtr;
struct Sprite savedMonSprite;
2021-04-12 18:33:06 +02:00
u8 tilemapBuffer[BG_SCREEN_SIZE];
u8 unused1[8];
s16 monAnimX[0x200];
s16 monAnimY[0x200];
u8 animRunState;
2017-12-10 15:04:03 +01:00
u8 animId;
2021-04-12 18:33:06 +02:00
u8 unused2;
2017-12-09 21:23:40 +01:00
bool8 noMonFlip;
u16 species;
2021-04-12 18:33:06 +02:00
u16 monAnimLength;
u16 timer;
2017-12-09 21:23:40 +01:00
u8 nature;
2021-04-12 18:33:06 +02:00
u8 monSpriteId_; // Duplicated unnecessarily
u8 unused3;
2017-12-09 21:23:40 +01:00
u8 monSpriteId;
u8 pokeblockCaseSpriteId;
u8 pokeblockSpriteId;
2021-04-12 18:33:06 +02:00
s16 animData[NUM_ANIMDATA];
s16 monInitX;
s16 monInitY;
s16 maxAnimStageTime;
s16 monX;
s16 monY;
2017-12-09 21:23:40 +01:00
s16 loadGfxState;
2021-04-12 18:33:06 +02:00
u8 unused4;
2017-12-09 21:23:40 +01:00
};
extern struct MusicPlayerInfo gMPlayInfo_BGM;
2017-12-09 21:23:40 +01:00
2017-12-10 15:04:03 +01:00
extern const u16 gUnknown_0860F074[];
2017-12-09 21:23:40 +01:00
static void HandleInitBackgrounds(void);
static void HandleInitWindows(void);
2017-12-10 15:04:03 +01:00
static void LaunchPokeblockFeedTask(void);
2017-12-09 21:23:40 +01:00
static void SetPokeblockSpritePal(u8 pokeblockCaseId);
2021-04-12 18:33:06 +02:00
static void CalculateMonAnimLength(void);
2017-12-10 15:04:03 +01:00
static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 arg1);
2021-04-12 18:33:06 +02:00
static void StartMonJumpForPokeblock(u8 spriteId);
static void Task_PrintAtePokeblockMessage(u8 taskId);
static void Task_FadeOutPokeblockFeed(u8 taskId);
static void UpdateMonAnim(void);
static void SpriteCB_MonJumpForPokeblock(struct Sprite *sprite);
static void CalculateMonAnimMovement(void);
static void CalculateMonAnimMovementEnd(void);
static bool8 InitMonAnimStage(void);
2017-12-10 15:04:03 +01:00
static bool8 FreeMonSpriteOamMatrix(void);
2021-04-12 18:33:06 +02:00
static bool8 DoMonAnimStep(void);
2017-12-10 15:04:03 +01:00
static bool8 LoadMonAndSceneGfx(struct Pokemon *mon);
static u8 CreatePokeblockSprite(void);
static u8 CreatePokeblockCaseSpriteForFeeding(void);
static u8 CreateMonSprite(struct Pokemon *mon);
static void SpriteCB_ThrownPokeblock(struct Sprite* sprite);
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
EWRAM_DATA static struct PokeblockFeed *sPokeblockFeed = NULL;
2017-12-10 15:04:03 +01:00
EWRAM_DATA static struct CompressedSpritePalette sPokeblockSpritePal = {0};
2017-12-09 21:23:40 +01:00
2020-07-17 02:12:12 +02:00
static const u8 sNatureToMonPokeblockAnim[NUM_NATURES][2] =
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
[NATURE_HARDY] = { ANIM_HARDY, AFFINE_NONE },
[NATURE_LONELY] = { ANIM_LONELY, AFFINE_NONE },
[NATURE_BRAVE] = { ANIM_BRAVE, AFFINE_TURN_UP },
[NATURE_ADAMANT] = { ANIM_ADAMANT, AFFINE_NONE },
[NATURE_NAUGHTY] = { ANIM_NAUGHTY, AFFINE_NONE },
[NATURE_BOLD] = { ANIM_BOLD, AFFINE_NONE },
[NATURE_DOCILE] = { ANIM_DOCILE, AFFINE_NONE },
[NATURE_RELAXED] = { ANIM_RELAXED, AFFINE_TURN_UP_AND_DOWN },
[NATURE_IMPISH] = { ANIM_IMPISH, AFFINE_NONE },
[NATURE_LAX] = { ANIM_LAX, AFFINE_NONE },
[NATURE_TIMID] = { ANIM_TIMID, AFFINE_NONE },
[NATURE_HASTY] = { ANIM_HASTY, AFFINE_NONE },
[NATURE_SERIOUS] = { ANIM_SERIOUS, AFFINE_TURN_DOWN },
[NATURE_JOLLY] = { ANIM_JOLLY, AFFINE_NONE },
[NATURE_NAIVE] = { ANIM_NAIVE, AFFINE_NONE },
[NATURE_MODEST] = { ANIM_MODEST, AFFINE_TURN_DOWN_SLOW },
[NATURE_MILD] = { ANIM_MILD, AFFINE_NONE },
[NATURE_QUIET] = { ANIM_QUIET, AFFINE_NONE },
[NATURE_BASHFUL] = { ANIM_BASHFUL, AFFINE_NONE },
[NATURE_RASH] = { ANIM_RASH, AFFINE_NONE },
[NATURE_CALM] = { ANIM_CALM, AFFINE_NONE },
[NATURE_GENTLE] = { ANIM_GENTLE, AFFINE_TURN_DOWN_SLIGHT },
[NATURE_SASSY] = { ANIM_SASSY, AFFINE_TURN_UP_HIGH },
[NATURE_CAREFUL] = { ANIM_CAREFUL, AFFINE_NONE },
[NATURE_QUIRKY] = { ANIM_QUIRKY, AFFINE_NONE },
2017-12-10 15:04:03 +01:00
};
2021-04-12 18:33:06 +02:00
// Data for the animation the Pokémon does while readying to jump for the Pokéblock
// Each nature can have up to 8 anim 'stages' it progresses through, and each stage has its own array of data.
// The elements in each array correspond in order to the following:
// - ANIMDATA_ROT_IDX : Index into sin/cos table for circular movement
// - ANIMDATA_ROT_SPEED : Circular movement speed
// - ANIMDATA_SIN_AMPLITUDE: How far on the x to move
// - ANIMDATA_COS_AMPLITUDE: How far on the y to move
// - ANIMDATA_TIME : How long in frames this part of the animation takes
// - ANIMDATA_ROT_ACCEL : How much to increase circular movement speed
// - ANIMDATA_TARGET_X : Target x coord offset from start position
// - ANIMDATA_TARGET_Y : Target y coord offset from start position
// - ANIMDATA_APPR_TIME : The time over which the target position should be approached
// - ANIMDATA_IS_LAST : TRUE if it's the last anim stage for this nature, FALSE otherwise
//
static const s16 sMonPokeblockAnims[][NUM_ANIMDATA] =
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
[ANIM_HARDY] =
{ 0, 4, 0, 8, 24, 0, 0, 0, 12, FALSE},
{ 0, 4, 0, 16, 24, 0, 0, 0, 12, FALSE},
{ 0, 4, 0, 32, 32, 0, 0, 0, 16, TRUE},
[ANIM_LONELY] =
{ 0, 3, 6, 0, 48, 0, 0, 0, 24, TRUE},
[ANIM_BRAVE] =
{ 64, 16, -24, 0, 32, 0, 0, 0, 0, TRUE},
[ANIM_ADAMANT] =
{ 0, 4, 8, 0, 16, 0, -8, 0, 0, FALSE},
{ 0, 0, 0, 0, 16, 0, 0, 0, 0, FALSE},
{ 0, 4, 8, 0, 16, 0, -8, 0, 0, FALSE},
{ 0, 0, 0, 0, 16, 0, 0, 0, 0, FALSE},
{ 0, 4, -16, 0, 4, 0, 16, 0, 0, TRUE},
[ANIM_NAUGHTY] =
{ 0, 3, 6, 0, 12, 0, 0, 0, 6, FALSE},
{ 0, 3, -6, 0, 12, 0, 0, 0, 6, FALSE},
{ 0, 16, 16, 0, 45, 1, 0, 0, 0, TRUE},
[ANIM_BOLD] =
{ 0, 16, 0, 24, 32, 0, 0, 0, 16, FALSE},
{ 0, 16, 0, 23, 32, 0, 0, 0, 16, TRUE},
[ANIM_DOCILE] =
{ 0, 0, 0, 0, 80, 0, 0, 0, 0, TRUE},
[ANIM_RELAXED] =
{ 0, 2, 8, 0, 32, 0, 0, 0, 0, FALSE},
{ 0, 2, -8, 0, 32, 0, 0, 0, 0, TRUE},
[ANIM_IMPISH] =
{ 0, 32, 2, 1, 48, 1, 0, 0, 24, TRUE},
[ANIM_LAX] =
{ 0, 2, 16, 16, 128, 0, 0, 0, 0, TRUE},
[ANIM_TIMID] =
{ 0, 2, -8, 0, 48, 0, -24, 0, 0, FALSE},
{ 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
{ 64, 32, 2, 0, 36, 0, 0, 0, 0, FALSE},
{ 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
{ 0, 2, 8, 0, 48, 0, 24, 0, 0, TRUE},
[ANIM_HASTY] =
{ 64, 24, 16, 0, 32, 0, 0, 0, 0, FALSE},
{ 0, 28, 2, 1, 32, 1, 0, 0, 16, TRUE},
[ANIM_SERIOUS] =
{ 0, 0, 0, 0, 32, 0, 0, 0, 0, TRUE},
[ANIM_JOLLY] =
{ 64, 16, -16, 2, 48, 0, 0, 0, 32, TRUE},
[ANIM_NAIVE] =
{ 0, 12, -8, 4, 24, 0, 8, 0, 12, FALSE},
{ 0, 12, 8, 8, 24, 0, -16, 0, 12, FALSE},
{ 0, 12, -8, 16, 24, 0, 16, 0, 12, FALSE},
{ 0, 12, 8, 28, 24, 0, -8, 0, 12, TRUE},
[ANIM_MODEST] =
{ 0, 0, 0, 0, 8, 0, 0, 0, 0, FALSE},
{ 64, 16, -4, 0, 32, 0, 0, 0, 0, FALSE},
{ 0, 0, 0, 0, 8, 0, 0, 0, 0, TRUE},
[ANIM_MILD] =
{ 128, 4, 0, 8, 64, 0, 0, 0, 0, TRUE},
[ANIM_QUIET] =
{ 0, 2, 16, 0, 48, 0, 0, 0, 0, FALSE},
{ 128, 2, 16, 0, 48, 0, 0, 0, 0, TRUE},
[ANIM_BASHFUL] =
{ 0, 2, -4, 0, 48, 0, -48, 0, 0, FALSE},
{ 0, 0, 0, 0, 80, 0, 0, 0, 0, FALSE},
{ 0, 2, 8, 0, 24, 0, 48, 0, 0, TRUE},
[ANIM_RASH] =
{ 64, 4, 64, 58, 52, 0, -88, 0, 0, FALSE},
{ 0, 0, 0, 0, 80, 0, 0, 0, 0, FALSE},
{ 0, 24, 80, 0, 32, 0, 88, 0, 0, TRUE},
[ANIM_CALM] =
{ 0, 2, 16, 4, 64, 0, 0, 0, 0, TRUE},
[ANIM_GENTLE] =
{ 0, 0, 0, 0, 32, 0, 0, 0, 0, TRUE},
[ANIM_SASSY] =
{ 0, 0, 0, 0, 42, 0, 0, 0, 0, TRUE},
[ANIM_CAREFUL] =
{ 0, 4, 0, 8, 24, 0, 0, 0, 12, FALSE},
{ 0, 0, 0, 0, 12, 0, 0, 0, 0, FALSE},
{ 0, 4, 0, 12, 24, 0, 0, 0, 12, FALSE},
{ 0, 0, 0, 0, 12, 0, 0, 0, 0, FALSE},
{ 0, 4, 0, 4, 24, 0, 0, 0, 12, TRUE},
[ANIM_QUIRKY] =
{ 0, 4, 16, 12, 64, 0, 0, 0, 0, FALSE},
{ 0, -4, 16, 12, 64, 0, 0, 0, 0, TRUE},
2017-12-10 15:04:03 +01:00
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_None[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUp[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0, 0, 12, 1),
AFFINEANIMCMD_FRAME(0, 0, 0, 30),
AFFINEANIMCMD_FRAME(0, 0, -12, 1),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUp_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0, 0, 12, 1),
AFFINEANIMCMD_FRAME(0, 0, 0, 28),
AFFINEANIMCMD_FRAME(0, 0, -4, 3),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUpAndDown[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 32),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUpAndDown_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 32),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 16),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDown[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDown_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlow[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 32),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlow_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 32),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 8),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlight[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 24),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 4),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnDownSlight_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -1, 4),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 24),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 4),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUpHigh[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, -12, 2),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Mon_TurnUpHigh_Flipped[] =
2017-12-10 15:04:03 +01:00
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 1, 24),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 16),
AFFINEANIMCMD_FRAME(0x0, 0x0, -12, 2),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd *const sAffineAnims_Mon[] =
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
// Animations for non-flipped mon sprites
[AFFINE_NONE] = sAffineAnim_Mon_None,
[AFFINE_TURN_UP] = sAffineAnim_Mon_TurnUp,
[AFFINE_TURN_UP_AND_DOWN] = sAffineAnim_Mon_TurnUpAndDown,
[AFFINE_TURN_DOWN] = sAffineAnim_Mon_TurnDown,
[AFFINE_TURN_DOWN_SLOW] = sAffineAnim_Mon_TurnDownSlow,
[AFFINE_TURN_DOWN_SLIGHT] = sAffineAnim_Mon_TurnDownSlight,
[AFFINE_TURN_UP_HIGH] = sAffineAnim_Mon_TurnUpHigh,
[AFFINE_UNUSED_1] = sAffineAnim_Mon_None,
[AFFINE_UNUSED_2] = sAffineAnim_Mon_None,
[AFFINE_UNUSED_3] = sAffineAnim_Mon_None,
// Animations for flipped mon sprites
[AFFINE_NONE + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
[AFFINE_TURN_UP + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUp_Flipped,
[AFFINE_TURN_UP_AND_DOWN + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUpAndDown_Flipped,
[AFFINE_TURN_DOWN + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDown_Flipped,
[AFFINE_TURN_DOWN_SLOW + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDownSlow_Flipped,
[AFFINE_TURN_DOWN_SLIGHT + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnDownSlight_Flipped,
[AFFINE_TURN_UP_HIGH + NUM_MON_AFFINES] = sAffineAnim_Mon_TurnUpHigh_Flipped,
[AFFINE_UNUSED_1 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
[AFFINE_UNUSED_2 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
[AFFINE_UNUSED_3 + NUM_MON_AFFINES] = sAffineAnim_Mon_None,
sAffineAnim_Mon_None, // ? Extra for some reason
2017-12-10 15:04:03 +01:00
};
static const struct BgTemplate sBackgroundTemplates[] =
{
{
.bg = 0,
.charBaseIndex = 0,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
},
{
.bg = 1,
.charBaseIndex = 2,
.mapBaseIndex = 30,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
}
};
static const struct WindowTemplate sWindowTemplates[] =
{
2021-04-12 18:33:06 +02:00
{
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 15,
.width = 28,
.height = 4,
.paletteNum = 15,
.baseBlock = 0xA
},
2017-12-10 15:04:03 +01:00
DUMMY_WIN_TEMPLATE
};
2020-08-24 20:52:33 +02:00
// - 1 excludes PBLOCK_CLR_NONE
2018-10-21 09:24:57 +02:00
static const u32* const sPokeblocksPals[] =
{
2020-08-24 20:52:33 +02:00
[PBLOCK_CLR_RED - 1] = gPokeblockRed_Pal,
[PBLOCK_CLR_BLUE - 1] = gPokeblockBlue_Pal,
[PBLOCK_CLR_PINK - 1] = gPokeblockPink_Pal,
[PBLOCK_CLR_GREEN - 1] = gPokeblockGreen_Pal,
[PBLOCK_CLR_YELLOW - 1] = gPokeblockYellow_Pal,
[PBLOCK_CLR_PURPLE - 1] = gPokeblockPurple_Pal,
[PBLOCK_CLR_INDIGO - 1] = gPokeblockIndigo_Pal,
[PBLOCK_CLR_BROWN - 1] = gPokeblockBrown_Pal,
[PBLOCK_CLR_LITE_BLUE - 1] = gPokeblockLiteBlue_Pal,
[PBLOCK_CLR_OLIVE - 1] = gPokeblockOlive_Pal,
[PBLOCK_CLR_GRAY - 1] = gPokeblockGray_Pal,
[PBLOCK_CLR_BLACK - 1] = gPokeblockBlack_Pal,
[PBLOCK_CLR_WHITE - 1] = gPokeblockWhite_Pal,
[PBLOCK_CLR_GOLD - 1] = gPokeblockGold_Pal
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Still[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
};
static const union AffineAnimCmd *const sSpriteAffineAnimTable_MonNoFlip[] =
{
2021-04-12 18:33:06 +02:00
sAffineAnim_Still
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_PokeblockCase_ThrowFromVertical[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, -8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 16, 1),
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_PokeblockCase_ThrowFromHorizontal[] =
{
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 8, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, 0, 8),
AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
AFFINEANIMCMD_FRAME(0x0, 0x0, -16, 1),
AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0),
AFFINEANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_Still[] =
{
2021-04-12 18:33:06 +02:00
sAffineAnim_Still
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_ThrowFromVertical[] =
{
2021-04-12 18:33:06 +02:00
sAffineAnim_PokeblockCase_ThrowFromVertical
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd *const sAffineAnims_PokeblockCase_ThrowFromHorizontal[] =
{
2021-04-12 18:33:06 +02:00
sAffineAnim_PokeblockCase_ThrowFromHorizontal
};
2021-04-12 18:33:06 +02:00
static const struct OamData sOamData_Pokeblock =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_DOUBLE,
.objMode = ST_OAM_OBJ_NORMAL,
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(8x8),
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(8x8),
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
2021-04-12 18:33:06 +02:00
static const union AnimCmd sAnim_Pokeblock[] =
{
ANIMCMD_FRAME(0, 0),
ANIMCMD_END
};
2021-04-12 18:33:06 +02:00
static const union AnimCmd *const sAnims_Pokeblock[] =
{
2021-04-12 18:33:06 +02:00
sAnim_Pokeblock,
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd sAffineAnim_Pokeblock[] =
{
AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0),
AFFINEANIMCMD_FRAME(-8, -8, 0, 1),
AFFINEANIMCMD_JUMP(1)
};
2021-04-12 18:33:06 +02:00
static const union AffineAnimCmd *const sAffineAnims_Pokeblock[] =
{
2021-04-12 18:33:06 +02:00
sAffineAnim_Pokeblock
};
2021-04-12 18:33:06 +02:00
static const struct CompressedSpriteSheet sSpriteSheet_Pokeblock =
{
2021-04-11 22:23:10 +02:00
gPokeblock_Gfx, 0x20, TAG_POKEBLOCK
};
2021-04-12 18:33:06 +02:00
static const struct SpriteTemplate sSpriteTemplate_Pokeblock =
{
2021-04-11 22:23:10 +02:00
.tileTag = TAG_POKEBLOCK,
.paletteTag = TAG_POKEBLOCK,
2021-04-12 18:33:06 +02:00
.oam = &sOamData_Pokeblock,
.anims = sAnims_Pokeblock,
.images = NULL,
2021-04-12 18:33:06 +02:00
.affineAnims = sAffineAnims_Pokeblock,
.callback = SpriteCB_ThrownPokeblock
};
2017-12-09 21:23:40 +01:00
static void CB2_PokeblockFeed(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
2017-12-09 21:23:40 +01:00
UpdatePaletteFade();
}
static void VBlankCB_PokeblockFeed(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
2021-04-12 18:33:06 +02:00
static bool8 LoadPokeblockFeedScene(void)
2017-12-09 21:23:40 +01:00
{
switch (gMain.state)
{
case 0:
sPokeblockFeed = AllocZeroed(sizeof(*sPokeblockFeed));
SetVBlankHBlankCallbacksToNull();
ClearScheduledBgCopiesToVram();
2017-12-09 21:23:40 +01:00
gMain.state++;
break;
case 1:
ResetPaletteFade();
2021-04-12 18:33:06 +02:00
gPaletteFade.bufferTransferDisabled = TRUE;
2017-12-09 21:23:40 +01:00
gMain.state++;
break;
case 2:
ResetSpriteData();
gMain.state++;
break;
case 3:
FreeAllSpritePalettes();
gMain.state++;
break;
case 4:
AllocateMonSpritesGfx();
gMain.state++;
break;
case 5:
HandleInitBackgrounds();
gMain.state++;
break;
case 6:
HandleInitWindows();
gMain.state++;
break;
case 7:
if (LoadMonAndSceneGfx(&gPlayerParty[gPokeblockMonId]))
gMain.state++;
break;
case 8:
sPokeblockFeed->pokeblockCaseSpriteId = CreatePokeblockCaseSpriteForFeeding();
gMain.state++;
break;
case 9:
sPokeblockFeed->monSpriteId = CreateMonSprite(&gPlayerParty[gPokeblockMonId]);
gMain.state++;
break;
case 10:
DrawStdFrameWithCustomTileAndPalette(0, 1, 1, 14);
2017-12-09 21:23:40 +01:00
gMain.state++;
break;
case 11:
LaunchPokeblockFeedTask();
gMain.state++;
break;
case 12:
2021-04-12 18:33:06 +02:00
BlendPalettes(PALETTES_ALL, 16, 0);
2017-12-09 21:23:40 +01:00
gMain.state++;
break;
case 13:
2021-04-12 18:33:06 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
gPaletteFade.bufferTransferDisabled = FALSE;
2017-12-09 21:23:40 +01:00
gMain.state++;
break;
default:
SetVBlankCallback(VBlankCB_PokeblockFeed);
SetMainCallback2(CB2_PokeblockFeed);
return TRUE;
}
return FALSE;
}
2021-04-12 18:33:06 +02:00
void PreparePokeblockFeedScene(void)
2017-12-09 21:23:40 +01:00
{
while (1)
{
2020-05-14 10:37:09 +02:00
if (MenuHelpers_CallLinkSomething() == TRUE)
2017-12-09 21:23:40 +01:00
break;
2021-04-12 18:33:06 +02:00
if (LoadPokeblockFeedScene() == TRUE)
2017-12-09 21:23:40 +01:00
break;
2020-05-14 10:37:09 +02:00
if (MenuHelpers_LinkSomething() == TRUE)
2017-12-09 21:23:40 +01:00
break;
}
}
static void HandleInitBackgrounds(void)
{
ResetVramOamAndBgCntRegs();
ResetBgsAndClearDma3BusyFlags(0);
2017-12-10 15:04:03 +01:00
InitBgsFromTemplates(0, sBackgroundTemplates, ARRAY_COUNT(sBackgroundTemplates));
2017-12-09 21:23:40 +01:00
SetBgTilemapBuffer(1, sPokeblockFeed->tilemapBuffer);
ResetAllBgsCoordinates();
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(1);
2017-12-09 21:23:40 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
ShowBg(1);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
}
static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
{
u16 species;
u32 personality, trainerId;
const struct CompressedSpritePalette *palette;
switch (sPokeblockFeed->loadGfxState)
{
case 0:
2021-04-12 18:33:06 +02:00
// Load mon gfx
2017-12-09 21:23:40 +01:00
species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 1:
2021-04-12 18:33:06 +02:00
// Load mon palette
2017-12-09 21:23:40 +01:00
species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
trainerId = GetMonData(mon, MON_DATA_OT_ID);
palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality);
2018-12-17 23:00:08 +01:00
LoadCompressedSpritePalette(palette);
SetMultiuseSpriteTemplateToPokemon(palette->tag, 1);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 2:
2018-12-17 23:00:08 +01:00
LoadCompressedSpriteSheet(&gPokeblockCase_SpriteSheet);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 3:
2018-12-17 23:00:08 +01:00
LoadCompressedSpritePalette(&gPokeblockCase_SpritePal);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 4:
2021-04-12 18:33:06 +02:00
LoadCompressedSpriteSheet(&sSpriteSheet_Pokeblock);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 5:
SetPokeblockSpritePal(gSpecialVar_ItemId);
2018-12-17 23:00:08 +01:00
LoadCompressedSpritePalette(&sPokeblockSpritePal);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 6:
2020-05-14 10:37:09 +02:00
ResetTempTileDataBuffers();
DecompressAndCopyTileDataToVram(1, gBattleTerrainTiles_Building, 0, 0, 0);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
break;
case 7:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible() != TRUE)
2017-12-09 21:23:40 +01:00
{
2021-04-12 18:33:06 +02:00
LZDecompressWram(gPokeblockFeedBg_Tilemap, sPokeblockFeed->tilemapBuffer);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->loadGfxState++;
}
break;
case 8:
LoadCompressedPalette(gBattleTerrainPalette_Frontier, 0x20, 0x60);
sPokeblockFeed->loadGfxState = 0;
return TRUE;
}
return FALSE;
}
static void HandleInitWindows(void)
{
2017-12-10 15:04:03 +01:00
InitWindows(sWindowTemplates);
2017-12-09 21:23:40 +01:00
DeactivateAllTextPrinters();
2018-07-15 13:23:38 +02:00
LoadUserWindowBorderGfx(0, 1, 0xE0);
2017-12-09 21:23:40 +01:00
LoadPalette(gUnknown_0860F074, 0xF0, 0x20);
FillWindowPixelBuffer(0, PIXEL_FILL(0));
2017-12-09 21:23:40 +01:00
PutWindowTilemap(0);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2017-12-09 21:23:40 +01:00
}
static void SetPokeblockSpritePal(u8 pokeblockCaseId)
{
u8 colorId = GetPokeblockData(&gSaveBlock1Ptr->pokeblocks[pokeblockCaseId], PBLOCK_COLOR);
sPokeblockSpritePal.data = sPokeblocksPals[colorId - 1];
2021-04-11 22:23:10 +02:00
sPokeblockSpritePal.tag = TAG_POKEBLOCK;
2017-12-09 21:23:40 +01:00
}
// defines for task data fields
2021-04-12 18:33:06 +02:00
#define tState data[0]
#define tHorizontalThrow data[1]
#define STATE_START_THROW 255 // If the length of the Pokémon's animation exceeds 255 the throw may happen twice
#define STATE_SPAWN_PBLOCK (STATE_START_THROW + 14)
#define STATE_START_JUMP (STATE_SPAWN_PBLOCK + 12)
#define STATE_PRINT_MSG (STATE_START_JUMP + 16)
2017-12-09 21:23:40 +01:00
2017-12-10 15:04:03 +01:00
static void Task_HandlePokeblockFeed(u8 taskId)
2017-12-09 21:23:40 +01:00
{
if (!gPaletteFade.active)
{
2021-04-12 18:33:06 +02:00
switch (gTasks[taskId].tState)
2017-12-09 21:23:40 +01:00
{
case 0:
2021-04-12 18:33:06 +02:00
sPokeblockFeed->animRunState = 0;
sPokeblockFeed->timer = 0;
CalculateMonAnimLength();
2017-12-09 21:23:40 +01:00
break;
2021-04-12 18:33:06 +02:00
case STATE_START_THROW:
DoPokeblockCaseThrowEffect(sPokeblockFeed->pokeblockCaseSpriteId, gTasks[taskId].tHorizontalThrow);
2017-12-09 21:23:40 +01:00
break;
2021-04-12 18:33:06 +02:00
case STATE_SPAWN_PBLOCK:
2017-12-09 21:23:40 +01:00
sPokeblockFeed->pokeblockSpriteId = CreatePokeblockSprite();
break;
2021-04-12 18:33:06 +02:00
case STATE_START_JUMP:
StartMonJumpForPokeblock(sPokeblockFeed->monSpriteId);
2017-12-09 21:23:40 +01:00
break;
2021-04-12 18:33:06 +02:00
case STATE_PRINT_MSG:
gTasks[taskId].func = Task_PrintAtePokeblockMessage;
2017-12-09 21:23:40 +01:00
return;
}
2021-04-12 18:33:06 +02:00
if (sPokeblockFeed->timer < sPokeblockFeed->monAnimLength)
UpdateMonAnim();
else if (sPokeblockFeed->timer == sPokeblockFeed->monAnimLength)
gTasks[taskId].tState = STATE_START_THROW - 1;
2017-12-09 21:23:40 +01:00
2021-04-12 18:33:06 +02:00
sPokeblockFeed->timer++;
gTasks[taskId].tState++;
2017-12-09 21:23:40 +01:00
}
}
2017-12-10 15:04:03 +01:00
static void LaunchPokeblockFeedTask(void)
2017-12-09 21:23:40 +01:00
{
u8 taskId = CreateTask(Task_HandlePokeblockFeed, 0);
2021-04-12 18:33:06 +02:00
gTasks[taskId].tState = 0;
gTasks[taskId].tHorizontalThrow = TRUE;
2017-12-09 21:23:40 +01:00
}
2021-04-12 18:33:06 +02:00
static void Task_WaitForAtePokeblockMessage(u8 taskId)
2017-12-09 21:23:40 +01:00
{
if (RunTextPrintersRetIsActive(0) != TRUE)
2021-04-12 18:33:06 +02:00
gTasks[taskId].func = Task_FadeOutPokeblockFeed;
2017-12-09 21:23:40 +01:00
}
2021-04-12 18:33:06 +02:00
static void Task_PrintAtePokeblockMessage(u8 taskId)
2017-12-09 21:23:40 +01:00
{
struct Pokemon *mon = &gPlayerParty[gPokeblockMonId];
struct Pokeblock *pokeblock = &gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId];
gPokeblockGain = PokeblockGetGain(GetNature(mon), pokeblock);
GetMonNickname(mon, gStringVar1);
PokeblockCopyName(pokeblock, gStringVar2);
if (gPokeblockGain == 0)
StringExpandPlaceholders(gStringVar4, gText_Var1AteTheVar2);
else if (gPokeblockGain > 0)
StringExpandPlaceholders(gStringVar4, gText_Var1HappilyAteVar2);
else
StringExpandPlaceholders(gStringVar4, gText_Var1DisdainfullyAteVar2);
2021-04-12 18:33:06 +02:00
gTextFlags.canABSpeedUpPrint = TRUE;
2018-11-06 18:30:21 +01:00
AddTextPrinterParameterized2(0, 1, gStringVar4, GetPlayerTextSpeedDelay(), NULL, 2, 1, 3);
2021-04-12 18:33:06 +02:00
gTasks[taskId].func = Task_WaitForAtePokeblockMessage;
2017-12-09 21:23:40 +01:00
}
2021-04-12 18:33:06 +02:00
static void Task_ExitPokeblockFeed(u8 taskId)
2017-12-09 21:23:40 +01:00
{
if (!gPaletteFade.active)
{
ResetSpriteData();
FreeAllSpritePalettes();
m4aMPlayVolumeControl(&gMPlayInfo_BGM, -1, 0x100);
2017-12-09 21:23:40 +01:00
SetMainCallback2(gMain.savedCallback);
DestroyTask(taskId);
FreeAllWindowBuffers();
Free(sPokeblockFeed);
FreeMonSpritesGfx();
}
}
2021-04-12 18:33:06 +02:00
static void Task_FadeOutPokeblockFeed(u8 taskId)
2017-12-09 21:23:40 +01:00
{
2021-04-12 18:33:06 +02:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_ExitPokeblockFeed;
2017-12-09 21:23:40 +01:00
}
2021-04-12 18:33:06 +02:00
#undef tState
#undef tHorizontalThrow
2021-04-12 18:33:06 +02:00
// Sprite data for Pokéblock and Pokémon
#define sSpeed data[0]
#define sAccel data[1]
#define sSpecies data[2]
2017-12-09 21:23:40 +01:00
static u8 CreateMonSprite(struct Pokemon* mon)
{
u16 species = GetMonData(mon, MON_DATA_SPECIES2);
2021-04-12 18:33:06 +02:00
u8 spriteId = CreateSprite(&gMultiuseSpriteTemplate, MON_X, MON_Y, 2);
2017-12-09 21:23:40 +01:00
sPokeblockFeed->species = species;
sPokeblockFeed->monSpriteId_ = spriteId;
sPokeblockFeed->nature = GetNature(mon);
2021-04-12 18:33:06 +02:00
gSprites[spriteId].sSpecies = species;
2017-12-09 21:23:40 +01:00
gSprites[spriteId].callback = SpriteCallbackDummy;
sPokeblockFeed->noMonFlip = TRUE;
2018-02-11 17:35:01 +01:00
if (!IsMonSpriteNotFlipped(species))
2017-12-09 21:23:40 +01:00
{
gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_MonNoFlip;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_DOUBLE;
2017-12-09 21:23:40 +01:00
CalcCenterToCornerVec(&gSprites[spriteId], gSprites[spriteId].oam.shape, gSprites[spriteId].oam.size, gSprites[spriteId].oam.affineMode);
sPokeblockFeed->noMonFlip = FALSE;
}
return spriteId;
}
2021-04-12 18:33:06 +02:00
static void StartMonJumpForPokeblock(u8 spriteId)
2017-12-09 21:23:40 +01:00
{
2021-04-12 18:33:06 +02:00
gSprites[spriteId].pos1.x = MON_X;
gSprites[spriteId].pos1.y = MON_Y;
gSprites[spriteId].sSpeed = -8;
gSprites[spriteId].sAccel = 1;
gSprites[spriteId].callback = SpriteCB_MonJumpForPokeblock;
2017-12-09 21:23:40 +01:00
}
2021-04-12 18:33:06 +02:00
static void SpriteCB_MonJumpForPokeblock(struct Sprite* sprite)
2017-12-09 21:23:40 +01:00
{
sprite->pos1.x += 4;
2021-04-12 18:33:06 +02:00
sprite->pos1.y += sprite->sSpeed;
sprite->sSpeed += sprite->sAccel;
2017-12-09 21:23:40 +01:00
2021-04-12 18:33:06 +02:00
// Play cry at jump peak
if (sprite->sSpeed == 0)
PlayCry1(sprite->sSpecies, 0);
if (sprite->sSpeed == 9)
2017-12-09 21:23:40 +01:00
sprite->callback = SpriteCallbackDummy;
}
2017-12-10 15:04:03 +01:00
static u8 CreatePokeblockCaseSpriteForFeeding(void)
2017-12-09 21:23:40 +01:00
{
u8 spriteId = CreatePokeblockCaseSprite(188, 100, 2);
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2021-04-12 18:33:06 +02:00
gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_Still;
2017-12-09 21:23:40 +01:00
gSprites[spriteId].callback = SpriteCallbackDummy;
InitSpriteAffineAnim(&gSprites[spriteId]);
return spriteId;
}
2021-04-12 18:33:06 +02:00
static void DoPokeblockCaseThrowEffect(u8 spriteId, bool8 horizontalThrow)
2017-12-09 21:23:40 +01:00
{
FreeOamMatrix(gSprites[spriteId].oam.matrixNum);
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_DOUBLE;
2017-12-09 21:23:40 +01:00
2021-04-12 18:33:06 +02:00
if (!horizontalThrow)
gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_ThrowFromVertical; // Never used, horizontalThrow always TRUE
2017-12-09 21:23:40 +01:00
else
2021-04-12 18:33:06 +02:00
gSprites[spriteId].affineAnims = sAffineAnims_PokeblockCase_ThrowFromHorizontal;
2017-12-09 21:23:40 +01:00
InitSpriteAffineAnim(&gSprites[spriteId]);
}
2017-12-10 15:04:03 +01:00
static u8 CreatePokeblockSprite(void)
2017-12-09 21:23:40 +01:00
{
2021-04-12 18:33:06 +02:00
u8 spriteId = CreateSprite(&sSpriteTemplate_Pokeblock, 174, 84, 1);
gSprites[spriteId].sSpeed = -12;
gSprites[spriteId].sAccel = 1;
2017-12-09 21:23:40 +01:00
return spriteId;
}
static void SpriteCB_ThrownPokeblock(struct Sprite* sprite)
{
sprite->pos1.x -= 4;
2021-04-12 18:33:06 +02:00
sprite->pos1.y += sprite->sSpeed;
sprite->sSpeed += sprite->sAccel;
if (sprite->sSpeed == 10)
2017-12-09 21:23:40 +01:00
DestroySprite(sprite);
}
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
static void CalculateMonAnimLength(void)
2017-12-10 15:04:03 +01:00
{
u8 animId, i;
2021-04-12 18:33:06 +02:00
struct PokeblockFeed *pokeblockFeed;
2017-12-10 15:04:03 +01:00
pokeblockFeed = sPokeblockFeed;
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimLength = 1;
2017-12-10 15:04:03 +01:00
animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
2021-04-12 18:33:06 +02:00
// Add up the time each stage of the animation will take
2017-12-10 15:04:03 +01:00
for (i = 0; i < 8; i++, animId++)
{
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimLength += sMonPokeblockAnims[animId][ANIMDATA_TIME];
if (sMonPokeblockAnims[animId][ANIMDATA_IS_LAST] == TRUE)
2017-12-10 15:04:03 +01:00
break;
}
}
2021-04-12 18:33:06 +02:00
static void UpdateMonAnim(void)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
switch (pokeblockFeed->animRunState)
2017-12-10 15:04:03 +01:00
{
case 0:
pokeblockFeed->animId = sNatureToMonPokeblockAnim[pokeblockFeed->nature][0];
pokeblockFeed->monSpritePtr = &gSprites[pokeblockFeed->monSpriteId_];
pokeblockFeed->savedMonSprite = *pokeblockFeed->monSpritePtr;
2021-04-12 18:33:06 +02:00
pokeblockFeed->animRunState = 10;
2017-12-10 15:04:03 +01:00
break;
case 1 ... 9:
break;
case 10:
2021-04-12 18:33:06 +02:00
InitMonAnimStage();
if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != AFFINE_NONE)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
// Initialize affine anim
pokeblockFeed->monSpritePtr->oam.affineMode = ST_OAM_AFFINE_DOUBLE;
2017-12-10 15:04:03 +01:00
pokeblockFeed->monSpritePtr->oam.matrixNum = 0;
2021-04-12 18:33:06 +02:00
pokeblockFeed->monSpritePtr->affineAnims = sAffineAnims_Mon;
2017-12-10 15:04:03 +01:00
InitSpriteAffineAnim(pokeblockFeed->monSpritePtr);
}
2021-04-12 18:33:06 +02:00
pokeblockFeed->animRunState = 50;
2017-12-10 15:04:03 +01:00
case 50:
2021-04-12 18:33:06 +02:00
if (sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] != AFFINE_NONE)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
// Start affine anim
2017-12-10 15:04:03 +01:00
if (!pokeblockFeed->noMonFlip) // double negation, so mon's sprite is flipped
2021-04-12 18:33:06 +02:00
StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1] + NUM_MON_AFFINES);
2017-12-10 15:04:03 +01:00
else
StartSpriteAffineAnim(pokeblockFeed->monSpritePtr, sNatureToMonPokeblockAnim[pokeblockFeed->nature][1]);
}
2021-04-12 18:33:06 +02:00
pokeblockFeed->animRunState = 60;
2017-12-10 15:04:03 +01:00
break;
case 60:
2021-04-12 18:33:06 +02:00
if (DoMonAnimStep() == TRUE)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
if (!pokeblockFeed->animData[ANIMDATA_IS_LAST])
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
// Continue to next stage of animation
2017-12-10 15:04:03 +01:00
pokeblockFeed->animId++;
2021-04-12 18:33:06 +02:00
InitMonAnimStage();
pokeblockFeed->animRunState = 60;
2017-12-10 15:04:03 +01:00
}
else
{
2021-04-12 18:33:06 +02:00
// End animation
2017-12-10 15:04:03 +01:00
FreeOamMatrix(pokeblockFeed->monSpritePtr->oam.matrixNum);
2021-04-12 18:33:06 +02:00
pokeblockFeed->animRunState = 70;
2017-12-10 15:04:03 +01:00
}
}
break;
case 70:
FreeMonSpriteOamMatrix();
pokeblockFeed->animId = 0;
2021-04-12 18:33:06 +02:00
pokeblockFeed->animRunState = 0;
2017-12-10 15:04:03 +01:00
break;
case 71 ... 90:
break;
}
}
2021-04-12 18:33:06 +02:00
static bool8 InitMonAnimStage(void)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
2017-12-10 15:04:03 +01:00
u8 i;
2021-04-12 18:33:06 +02:00
for (i = 0; i < NUM_ANIMDATA; i++)
pokeblockFeed->animData[i] = sMonPokeblockAnims[pokeblockFeed->animId][i];
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
if (pokeblockFeed->animData[ANIMDATA_TIME] == 0)
2017-12-10 15:04:03 +01:00
{
return TRUE;
}
else
{
2021-04-12 18:33:06 +02:00
pokeblockFeed->monInitX = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX], pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE]);
pokeblockFeed->monInitY = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX], pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE]);
pokeblockFeed->maxAnimStageTime = pokeblockFeed->animData[ANIMDATA_TIME];
pokeblockFeed->monX = pokeblockFeed->monSpritePtr->pos2.x;
pokeblockFeed->monY = pokeblockFeed->monSpritePtr->pos2.y;
// Calculate the positions to move to during the animation
// The time is counted down during this, so reset it afterwards
CalculateMonAnimMovement();
pokeblockFeed->animData[ANIMDATA_TIME] = pokeblockFeed->maxAnimStageTime;
CalculateMonAnimMovementEnd();
pokeblockFeed->animData[ANIMDATA_TIME] = pokeblockFeed->maxAnimStageTime; // Redundant
2017-12-10 15:04:03 +01:00
return FALSE;
}
}
2021-04-12 18:33:06 +02:00
static bool8 DoMonAnimStep(void)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
// Update mon's position
u16 time = sPokeblockFeed->maxAnimStageTime - sPokeblockFeed->animData[ANIMDATA_TIME];
sPokeblockFeed->monSpritePtr->pos2.x = sPokeblockFeed->monAnimX[time];
sPokeblockFeed->monSpritePtr->pos2.y = sPokeblockFeed->monAnimY[time];
// Count down time remaining in this stage
// Return TRUE if this stage is complete
if (--sPokeblockFeed->animData[ANIMDATA_TIME] == 0)
2017-12-10 15:04:03 +01:00
return TRUE;
else
return FALSE;
}
static bool8 FreeMonSpriteOamMatrix(void)
{
FreeSpriteOamMatrix(sPokeblockFeed->monSpritePtr);
return FALSE;
}
2021-04-12 18:33:06 +02:00
static void CalculateMonAnimMovementEnd(void)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
2017-12-10 15:04:03 +01:00
u16 i;
2021-04-12 18:33:06 +02:00
u16 approachTime = pokeblockFeed->animData[ANIMDATA_APPR_TIME];
u16 time = pokeblockFeed->maxAnimStageTime - approachTime;
s16 x = pokeblockFeed->monX + pokeblockFeed->animData[ANIMDATA_TARGET_X];
s16 y = pokeblockFeed->monY + pokeblockFeed->animData[ANIMDATA_TARGET_Y];
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
for (i = 0; i < time - 1; i++)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
s16 xOffset = pokeblockFeed->monAnimX[approachTime + i] - x;
s16 yOffset = pokeblockFeed->monAnimY[approachTime + i] - y;
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimX[approachTime + i] -= xOffset * (i + 1) / time;
pokeblockFeed->monAnimY[approachTime + i] -= yOffset * (i + 1) / time;
2017-12-10 15:04:03 +01:00
}
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimX[approachTime + time - 1] = x;
pokeblockFeed->monAnimY[approachTime + time - 1] = y;
2017-12-10 15:04:03 +01:00
}
2021-04-12 18:33:06 +02:00
static void CalculateMonAnimMovement(void)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
struct PokeblockFeed *pokeblockFeed = sPokeblockFeed;
bool8 negative = FALSE;
s16 x = pokeblockFeed->monX - pokeblockFeed->monInitX;
s16 y = pokeblockFeed->monY - pokeblockFeed->monInitY;
2017-12-10 15:04:03 +01:00
while (1)
{
2021-04-12 18:33:06 +02:00
u16 amplitude;
u16 time;
u16 acceleration;
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
acceleration = abs(pokeblockFeed->animData[ANIMDATA_ROT_ACCEL]);
amplitude = acceleration + pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE];
pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] = amplitude;
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
if (pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] < 0)
negative = TRUE;
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
time = pokeblockFeed->maxAnimStageTime - pokeblockFeed->animData[ANIMDATA_TIME];
2017-12-10 15:04:03 +01:00
2021-04-12 18:33:06 +02:00
if (pokeblockFeed->animData[ANIMDATA_TIME] == 0)
2017-12-10 15:04:03 +01:00
break;
2021-04-12 18:33:06 +02:00
if (!negative)
2017-12-10 15:04:03 +01:00
{
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimX[time] = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] + amplitude / 0x100) + x;
pokeblockFeed->monAnimY[time] = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] + amplitude / 0x100) + y;
2017-12-10 15:04:03 +01:00
}
else
{
2021-04-12 18:33:06 +02:00
pokeblockFeed->monAnimX[time] = Sin(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
pokeblockFeed->animData[ANIMDATA_SIN_AMPLITUDE] - amplitude / 0x100) + x;
pokeblockFeed->monAnimY[time] = Cos(pokeblockFeed->animData[ANIMDATA_ROT_IDX],
pokeblockFeed->animData[ANIMDATA_COS_AMPLITUDE] - amplitude / 0x100) + y;
2017-12-10 15:04:03 +01:00
}
2021-04-12 18:33:06 +02:00
pokeblockFeed->animData[ANIMDATA_ROT_IDX] += pokeblockFeed->animData[ANIMDATA_ROT_SPEED];
pokeblockFeed->animData[ANIMDATA_ROT_IDX] &= 0xFF;
pokeblockFeed->animData[ANIMDATA_TIME]--;
2017-12-10 15:04:03 +01:00
}
}