2018-12-25 18:02:41 +01:00
|
|
|
#include "global.h"
|
2019-09-09 03:07:54 +02:00
|
|
|
#include "malloc.h"
|
2018-12-25 18:02:41 +01:00
|
|
|
#include "bg.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "event_object_movement.h"
|
|
|
|
#include "field_camera.h"
|
|
|
|
#include "fieldmap.h"
|
|
|
|
#include "gpu_regs.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "random.h"
|
2020-08-05 01:24:36 +02:00
|
|
|
#include "palette_util.h"
|
2018-12-25 18:02:41 +01:00
|
|
|
#include "script.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "window.h"
|
2021-04-27 08:30:26 +02:00
|
|
|
#include "constants/event_objects.h"
|
2018-12-25 18:02:41 +01:00
|
|
|
#include "constants/rgb.h"
|
|
|
|
#include "constants/songs.h"
|
2019-06-12 05:19:25 +02:00
|
|
|
#include "constants/metatile_labels.h"
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-08-25 00:59:32 +02:00
|
|
|
struct MirageTowerPulseBlend
|
2021-04-27 08:30:26 +02:00
|
|
|
{
|
2018-12-25 18:02:41 +01:00
|
|
|
u8 taskId;
|
|
|
|
struct PulseBlend pulseBlend;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MetatileCoords
|
|
|
|
{
|
|
|
|
u8 x;
|
|
|
|
u8 y;
|
|
|
|
u16 metatileId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BgRegOffsets
|
|
|
|
{
|
|
|
|
u16 bgHOFS;
|
|
|
|
u16 bgVOFS;
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
struct FallAnim_Tower
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
u8 *disintegrateRand;
|
|
|
|
u8 disintegrateIdx;
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
struct FallAnim_Fossil
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
u8 *frameImageTiles;
|
2021-04-27 08:30:26 +02:00
|
|
|
struct SpriteFrameImage *frameImage;
|
2018-12-25 18:02:41 +01:00
|
|
|
u8 spriteId;
|
2021-04-27 08:30:26 +02:00
|
|
|
u16 *disintegrateRand;
|
|
|
|
u16 disintegrateIdx;
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
#define TAG_CEILING_CRUMBLE 4000
|
|
|
|
|
2018-12-25 18:02:41 +01:00
|
|
|
#define MIRAGE_TOWER_GFX_LENGTH (sizeof(sBlankTile_Gfx) + sizeof(sMirageTower_Gfx))
|
2021-04-27 08:30:26 +02:00
|
|
|
#define FOSSIL_DISINTEGRATE_LENGTH 0x100
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct SpriteSheet sCeilingCrumbleSpriteSheets[];
|
|
|
|
static const s16 sCeilingCrumblePositions[][3];
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static void PlayerDescendMirageTower(u8);
|
|
|
|
static void DoScreenShake(u8);
|
2018-12-25 18:02:41 +01:00
|
|
|
static void IncrementCeilingCrumbleFinishedCount(void);
|
2021-04-27 08:30:26 +02:00
|
|
|
static void WaitCeilingCrumble(u8);
|
|
|
|
static void FinishCeilingCrumbleTask(u8);
|
2018-12-25 18:02:41 +01:00
|
|
|
static void CreateCeilingCrumbleSprites(void);
|
2022-07-29 17:15:33 +02:00
|
|
|
static void SpriteCB_CeilingCrumble(struct Sprite *);
|
2021-04-27 08:30:26 +02:00
|
|
|
static void DoMirageTowerDisintegration(u8);
|
|
|
|
static void InitMirageTowerShake(u8);
|
|
|
|
static void Task_FossilFallAndSink(u8);
|
|
|
|
static void SpriteCB_FallingFossil(struct Sprite *);
|
2022-07-29 16:17:58 +02:00
|
|
|
static void UpdateDisintegrationEffect(u8 *, u16, u8, u8, u8);
|
2021-04-27 08:30:26 +02:00
|
|
|
|
2018-12-25 18:02:41 +01:00
|
|
|
static const u8 sBlankTile_Gfx[32] = {0};
|
|
|
|
static const u8 sMirageTower_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower.4bpp");
|
|
|
|
static const u16 sMirageTowerTilemap[] = INCBIN_U16("graphics/misc/mirage_tower.bin");
|
2021-04-27 08:30:26 +02:00
|
|
|
static const u16 sFossil_Pal[] = INCBIN_U16("graphics/object_events/pics/misc/fossil.gbapal"); // Unused
|
|
|
|
static const u8 sFossil_Gfx[] = INCBIN_U8("graphics/object_events/pics/misc/fossil.4bpp"); // Duplicate of gObjectEventPic_Fossil
|
2018-12-25 18:02:41 +01:00
|
|
|
static const u8 sMirageTowerCrumbles_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower_crumbles.4bpp");
|
|
|
|
static const u16 sMirageTowerCrumbles_Palette[] = INCBIN_U16("graphics/misc/mirage_tower_crumbles.gbapal");
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const s16 sCeilingCrumblePositions[][3] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
{ 0, 10, 65},
|
|
|
|
{ 17, 3, 50},
|
|
|
|
{-12, 0, 75},
|
|
|
|
{ 10, 15, 90},
|
|
|
|
{ 7, 8, 65},
|
|
|
|
{-18, 5, 75},
|
|
|
|
{ 22, -10, 55},
|
|
|
|
{-24, -4, 65},
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct SpriteSheet sCeilingCrumbleSpriteSheets[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2023-01-24 23:02:17 +01:00
|
|
|
{sMirageTowerCrumbles_Gfx, sizeof(sMirageTowerCrumbles_Gfx), TAG_CEILING_CRUMBLE},
|
2021-04-27 08:30:26 +02:00
|
|
|
{}
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct MetatileCoords sInvisibleMirageTowerMetatiles[] =
|
|
|
|
{
|
2020-07-02 06:17:14 +02:00
|
|
|
{18, 53, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{19, 53, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{20, 53, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{18, 54, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{19, 54, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{20, 54, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{18, 55, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{19, 55, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{20, 55, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{18, 56, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{19, 56, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{20, 56, METATILE_Mauville_DeepSand_Center},
|
|
|
|
{18, 57, METATILE_Mauville_DeepSand_BottomMid},
|
|
|
|
{19, 57, METATILE_Mauville_DeepSand_BottomMid},
|
|
|
|
{20, 57, METATILE_Mauville_DeepSand_BottomMid},
|
|
|
|
{18, 58, METATILE_General_SandPit_Center},
|
|
|
|
{19, 58, METATILE_General_SandPit_Center},
|
|
|
|
{20, 58, METATILE_General_SandPit_Center},
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd sAnim_FallingFossil[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 1),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct OamData sOamData_FallingFossil =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2022-07-30 03:27:39 +02:00
|
|
|
.mosaic = FALSE,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(16x16),
|
2018-12-25 18:02:41 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(16x16),
|
2018-12-25 18:02:41 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.paletteNum = 3,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd *const sAnims_FallingFossil[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
sAnim_FallingFossil,
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct SpriteTemplate sSpriteTemplate_FallingFossil =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-09-14 19:14:14 +02:00
|
|
|
.tileTag = TAG_NONE,
|
|
|
|
.paletteTag = TAG_NONE,
|
2021-04-27 08:30:26 +02:00
|
|
|
.oam = &sOamData_FallingFossil,
|
|
|
|
.anims = sAnims_FallingFossil,
|
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
|
|
|
.callback = SpriteCallbackDummy
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct PulseBlendSettings gMirageTowerPulseBlendSettings = {
|
|
|
|
.blendColor = RGB(27, 25, 16),
|
|
|
|
.paletteOffset = 0x61,
|
|
|
|
.numColors = 15,
|
|
|
|
.delay = 5,
|
|
|
|
.numFadeCycles = -1,
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
.maxBlendCoeff = 11,
|
2018-12-25 18:02:41 +01:00
|
|
|
.fadeType = 1,
|
|
|
|
.restorePaletteOnUnload = FALSE,
|
|
|
|
.unk7_7 = 1,
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd sAnim_CeilingCrumbleSmall[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 12),
|
|
|
|
ANIMCMD_JUMP(0),
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd *const sAnims_CeilingCrumbleSmall[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
sAnim_CeilingCrumbleSmall,
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct OamData sOamData_CeilingCrumbleSmall =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2022-07-30 03:27:39 +02:00
|
|
|
.mosaic = FALSE,
|
2018-12-25 18:02:41 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(8x8),
|
2018-12-25 18:02:41 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(8x8),
|
2018-12-25 18:02:41 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2022-08-27 08:07:58 +02:00
|
|
|
static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleSmall =
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
.tileTag = TAG_CEILING_CRUMBLE,
|
2021-09-14 19:14:14 +02:00
|
|
|
.paletteTag = TAG_NONE,
|
2021-04-27 08:30:26 +02:00
|
|
|
.oam = &sOamData_CeilingCrumbleSmall,
|
|
|
|
.anims = sAnims_CeilingCrumbleSmall,
|
2018-12-25 18:02:41 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2021-04-27 08:30:26 +02:00
|
|
|
.callback = SpriteCB_CeilingCrumble
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd sAnim_CeilingCrumbleLarge[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 12),
|
|
|
|
ANIMCMD_JUMP(0),
|
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const union AnimCmd *const sAnims_CeilingCrumbleLarge[] =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
sAnim_CeilingCrumbleLarge,
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static const struct OamData sOamData_CeilingCrumbleLarge =
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2022-07-30 03:27:39 +02:00
|
|
|
.mosaic = FALSE,
|
2018-12-25 18:02:41 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(16x16),
|
2018-12-25 18:02:41 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(16x16),
|
2018-12-25 18:02:41 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2022-08-27 08:07:58 +02:00
|
|
|
static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleLarge =
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
.tileTag = TAG_CEILING_CRUMBLE,
|
2021-09-14 19:14:14 +02:00
|
|
|
.paletteTag = TAG_NONE,
|
2021-04-27 08:30:26 +02:00
|
|
|
.oam = &sOamData_CeilingCrumbleLarge,
|
|
|
|
.anims = sAnims_CeilingCrumbleLarge,
|
2018-12-25 18:02:41 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2021-04-27 08:30:26 +02:00
|
|
|
.callback = SpriteCB_CeilingCrumble
|
2018-12-25 18:02:41 +01:00
|
|
|
};
|
|
|
|
|
2022-07-29 16:17:58 +02:00
|
|
|
EWRAM_DATA static u8 *sMirageTowerGfxBuffer = NULL;
|
|
|
|
EWRAM_DATA static u8 *sMirageTowerTilemapBuffer = NULL;
|
2021-04-27 08:30:26 +02:00
|
|
|
EWRAM_DATA static struct FallAnim_Fossil *sFallingFossil = NULL;
|
|
|
|
EWRAM_DATA static struct FallAnim_Tower *sFallingTower = NULL;
|
2018-12-25 18:02:41 +01:00
|
|
|
EWRAM_DATA static struct BgRegOffsets *sBgShakeOffsets = NULL;
|
2021-04-27 08:30:26 +02:00
|
|
|
EWRAM_DATA static struct MirageTowerPulseBlend *sMirageTowerPulseBlend = NULL;
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
// Holds data about the disintegration effect for Mirage Tower / the unchosen fossil.
|
|
|
|
// Never read, presumably for debugging
|
|
|
|
static u16 sDebug_DisintegrationData[8];
|
2018-12-25 18:02:41 +01:00
|
|
|
|
|
|
|
bool8 IsMirageTowerVisible(void)
|
|
|
|
{
|
|
|
|
if (!(gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111)))
|
|
|
|
return FALSE;
|
|
|
|
return FlagGet(FLAG_MIRAGE_TOWER_VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateMirageTowerPulseBlend(u8 taskId)
|
|
|
|
{
|
|
|
|
UpdatePulseBlend(&sMirageTowerPulseBlend->pulseBlend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMirageTowerPulseBlend(void)
|
|
|
|
{
|
|
|
|
sMirageTowerPulseBlend = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TryStartMirageTowerPulseBlendEffect(void)
|
|
|
|
{
|
|
|
|
if (sMirageTowerPulseBlend)
|
|
|
|
{
|
|
|
|
sMirageTowerPulseBlend = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111)
|
|
|
|
|| gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111)
|
|
|
|
|| !FlagGet(FLAG_MIRAGE_TOWER_VISIBLE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sMirageTowerPulseBlend = AllocZeroed(sizeof(*sMirageTowerPulseBlend));
|
|
|
|
InitPulseBlend(&sMirageTowerPulseBlend->pulseBlend);
|
|
|
|
InitPulseBlendPaletteSettings(&sMirageTowerPulseBlend->pulseBlend, &gMirageTowerPulseBlendSettings);
|
|
|
|
MarkUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE);
|
|
|
|
sMirageTowerPulseBlend->taskId = CreateTask(UpdateMirageTowerPulseBlend, 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMirageTowerPulseBlendEffect(void)
|
|
|
|
{
|
|
|
|
if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111)
|
|
|
|
|| gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111)
|
|
|
|
|| !FlagGet(FLAG_MIRAGE_TOWER_VISIBLE)
|
|
|
|
|| sMirageTowerPulseBlend == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (FuncIsActiveTask(UpdateMirageTowerPulseBlend))
|
|
|
|
DestroyTask(sMirageTowerPulseBlend->taskId);
|
|
|
|
|
|
|
|
UnmarkUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE);
|
|
|
|
UnloadUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE);
|
|
|
|
FREE_AND_SET_NULL(sMirageTowerPulseBlend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMirageTowerVisibility(void)
|
|
|
|
{
|
|
|
|
u16 rand;
|
|
|
|
bool8 visible;
|
|
|
|
|
2019-08-05 17:50:29 +02:00
|
|
|
if (VarGet(VAR_MIRAGE_TOWER_STATE))
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
// Mirage Tower event has already been completed, hide it
|
2018-12-25 18:02:41 +01:00
|
|
|
FlagClear(FLAG_MIRAGE_TOWER_VISIBLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rand = Random();
|
|
|
|
visible = rand & 1;
|
|
|
|
if (FlagGet(FLAG_FORCE_MIRAGE_TOWER_VISIBLE) == TRUE)
|
|
|
|
visible = TRUE;
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
FlagSet(FLAG_MIRAGE_TOWER_VISIBLE);
|
|
|
|
TryStartMirageTowerPulseBlendEffect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlagClear(FLAG_MIRAGE_TOWER_VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartPlayerDescendMirageTower(void)
|
|
|
|
{
|
|
|
|
CreateTask(PlayerDescendMirageTower, 8);
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
// As the tower disintegrates, a duplicate object event of the player
|
|
|
|
// is created at the top of the tower and moved down to show the player falling
|
2018-12-25 18:02:41 +01:00
|
|
|
static void PlayerDescendMirageTower(u8 taskId)
|
|
|
|
{
|
2019-11-21 04:55:44 +01:00
|
|
|
u8 objectEventId;
|
2021-04-27 08:30:26 +02:00
|
|
|
struct ObjectEvent *fallingPlayer;
|
|
|
|
struct ObjectEvent *player;
|
|
|
|
|
|
|
|
TryGetObjectEventIdByLocalIdAndMap(LOCALID_ROUTE111_PLAYER_FALLING, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectEventId);
|
|
|
|
fallingPlayer = &gObjectEvents[objectEventId];
|
2021-07-12 07:39:28 +02:00
|
|
|
gSprites[fallingPlayer->spriteId].y2 += 4;
|
2021-04-27 08:30:26 +02:00
|
|
|
player = &gObjectEvents[gPlayerAvatar.objectEventId];
|
2021-07-12 07:39:28 +02:00
|
|
|
if ((gSprites[fallingPlayer->spriteId].y + gSprites[fallingPlayer->spriteId].y2) >=
|
|
|
|
(gSprites[player->spriteId].y + gSprites[player->spriteId].y2))
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_Enable();
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
#define tXShakeOffset data[0]
|
|
|
|
#define tTimer data[1]
|
|
|
|
#define tNumShakes data[2]
|
|
|
|
#define tShakeDelay data[3]
|
|
|
|
#define tYShakeOffset data[4]
|
|
|
|
|
2018-12-25 18:02:41 +01:00
|
|
|
static void StartScreenShake(u8 yShakeOffset, u8 xShakeOffset, u8 numShakes, u8 shakeDelay)
|
|
|
|
{
|
|
|
|
u8 taskId = CreateTask(DoScreenShake, 9);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tXShakeOffset = xShakeOffset;
|
|
|
|
gTasks[taskId].tTimer = 0;
|
|
|
|
gTasks[taskId].tNumShakes = numShakes;
|
|
|
|
gTasks[taskId].tShakeDelay = shakeDelay;
|
|
|
|
gTasks[taskId].tYShakeOffset = yShakeOffset;
|
2018-12-25 18:02:41 +01:00
|
|
|
SetCameraPanningCallback(NULL);
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_M_STRENGTH);
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DoScreenShake(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data;
|
|
|
|
|
|
|
|
data = gTasks[taskId].data;
|
2021-04-27 08:30:26 +02:00
|
|
|
tTimer++;
|
|
|
|
if (tTimer % tShakeDelay == 0)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
tTimer = 0;
|
|
|
|
tNumShakes--;
|
|
|
|
tXShakeOffset = -tXShakeOffset;
|
|
|
|
tYShakeOffset = -tYShakeOffset;
|
|
|
|
SetCameraPanning(tXShakeOffset, tYShakeOffset);
|
|
|
|
if (tNumShakes == 0)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
IncrementCeilingCrumbleFinishedCount();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
InstallCameraPanAheadCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
#undef tXShakeOffset
|
|
|
|
#undef tTimer
|
|
|
|
#undef tNumShakes
|
|
|
|
#undef tShakeDelay
|
|
|
|
#undef tYShakeOffset
|
|
|
|
|
2018-12-25 18:02:41 +01:00
|
|
|
static void IncrementCeilingCrumbleFinishedCount(void)
|
|
|
|
{
|
|
|
|
u8 taskId = FindTaskIdByFunc(WaitCeilingCrumble);
|
2021-02-20 05:22:26 +01:00
|
|
|
if (taskId != TASK_NONE)
|
2018-12-25 18:02:41 +01:00
|
|
|
gTasks[taskId].data[0]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoMirageTowerCeilingCrumble(void)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
LoadSpriteSheets(sCeilingCrumbleSpriteSheets);
|
2018-12-25 18:02:41 +01:00
|
|
|
CreateCeilingCrumbleSprites();
|
|
|
|
CreateTask(WaitCeilingCrumble, 8);
|
|
|
|
StartScreenShake(2, 1, 16, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WaitCeilingCrumble(u8 taskId)
|
|
|
|
{
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
u16 *data = gTasks[taskId].data;
|
|
|
|
data[1]++;
|
2018-12-25 18:02:41 +01:00
|
|
|
// Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed.
|
Undo PokeCodec's PRs
This commit undoes most of PokeCodec's PRs after the debate in chat. Some
harmless or completely superseded PRs have been left alone, as there is not
much benefit in attempting to undo them.
Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136,
#1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179,
#1180, #1181, #1182 and #1183.
2020-09-13 09:22:50 +02:00
|
|
|
if (data[1] == 1000 || data[0] == 17)
|
2018-12-25 18:02:41 +01:00
|
|
|
gTasks[taskId].func = FinishCeilingCrumbleTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FinishCeilingCrumbleTask(u8 taskId)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
FreeSpriteTilesByTag(TAG_CEILING_CRUMBLE);
|
2018-12-25 18:02:41 +01:00
|
|
|
DestroyTask(taskId);
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_Enable();
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CreateCeilingCrumbleSprites(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
u8 spriteId;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
spriteId = CreateSprite(&sSpriteTemplate_CeilingCrumbleLarge, sCeilingCrumblePositions[i][0] + 120, sCeilingCrumblePositions[i][1], 8);
|
2018-12-25 18:02:41 +01:00
|
|
|
gSprites[spriteId].oam.priority = 0;
|
|
|
|
gSprites[spriteId].oam.paletteNum = 0;
|
|
|
|
gSprites[spriteId].data[0] = i;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
spriteId = CreateSprite(&sSpriteTemplate_CeilingCrumbleSmall, sCeilingCrumblePositions[i][0] + 115, sCeilingCrumblePositions[i][1] - 3, 8);
|
2018-12-25 18:02:41 +01:00
|
|
|
gSprites[spriteId].oam.priority = 0;
|
|
|
|
gSprites[spriteId].oam.paletteNum = 0;
|
|
|
|
gSprites[spriteId].data[0] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 17:15:33 +02:00
|
|
|
static void SpriteCB_CeilingCrumble(struct Sprite *sprite)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
sprite->data[1] += 2;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = sprite->data[1] / 2;
|
|
|
|
if(((sprite->y) + (sprite->y2)) > sCeilingCrumblePositions[sprite->data[0]][2])
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
DestroySprite(sprite);
|
|
|
|
IncrementCeilingCrumbleFinishedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetInvisibleMirageTowerMetatiles(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
for (i = 0; i < ARRAY_COUNT(sInvisibleMirageTowerMetatiles); i++)
|
2021-10-09 18:12:18 +02:00
|
|
|
MapGridSetMetatileIdAt(sInvisibleMirageTowerMetatiles[i].x + MAP_OFFSET,
|
|
|
|
sInvisibleMirageTowerMetatiles[i].y + MAP_OFFSET,
|
|
|
|
sInvisibleMirageTowerMetatiles[i].metatileId);
|
2018-12-25 18:02:41 +01:00
|
|
|
DrawWholeMapView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartMirageTowerDisintegration(void)
|
|
|
|
{
|
|
|
|
CreateTask(DoMirageTowerDisintegration, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartMirageTowerShake(void)
|
|
|
|
{
|
|
|
|
CreateTask(InitMirageTowerShake, 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartMirageTowerFossilFallAndSink(void)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
CreateTask(Task_FossilFallAndSink, 9);
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetBgShakeOffsets(void)
|
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_BG0HOFS, sBgShakeOffsets->bgHOFS);
|
|
|
|
SetGpuReg(REG_OFFSET_BG0VOFS, sBgShakeOffsets->bgVOFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateBgShake(u8 taskId)
|
|
|
|
{
|
|
|
|
if (!gTasks[taskId].data[0])
|
|
|
|
{
|
|
|
|
sBgShakeOffsets->bgHOFS = -sBgShakeOffsets->bgHOFS;
|
|
|
|
gTasks[taskId].data[0] = 2;
|
|
|
|
SetBgShakeOffsets();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gTasks[taskId].data[0]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
#define tState data[0]
|
|
|
|
|
2018-12-25 18:02:41 +01:00
|
|
|
static void InitMirageTowerShake(u8 taskId)
|
|
|
|
{
|
|
|
|
u8 zero;
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
FreeAllWindowBuffers();
|
2018-12-26 13:05:02 +01:00
|
|
|
SetBgAttribute(0, BG_ATTR_PRIORITY, 2);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sMirageTowerGfxBuffer = (u8 *)AllocZeroed(MIRAGE_TOWER_GFX_LENGTH);
|
|
|
|
sMirageTowerTilemapBuffer = (u8 *)AllocZeroed(BG_SCREEN_SIZE);
|
2021-11-04 04:02:06 +01:00
|
|
|
ChangeBgX(0, 0, BG_COORD_SET);
|
|
|
|
ChangeBgY(0, 0, BG_COORD_SET);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
CpuSet(sBlankTile_Gfx, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH / 2);
|
|
|
|
LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
SetBgTilemapBuffer(0, sMirageTowerTilemapBuffer);
|
|
|
|
CopyToBgTilemapBufferRect_ChangePalette(0, &sMirageTowerTilemap, 12, 29, 6, 12, 17);
|
|
|
|
CopyBgTilemapBufferToVram(0);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ShowBg(0);
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
SetInvisibleMirageTowerMetatiles();
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
sBgShakeOffsets = Alloc(sizeof(*sBgShakeOffsets));
|
|
|
|
zero = 0;
|
|
|
|
sBgShakeOffsets->bgHOFS = 2;
|
|
|
|
sBgShakeOffsets->bgVOFS = zero;
|
|
|
|
CreateTask(UpdateBgShake, 10);
|
|
|
|
DestroyTask(taskId);
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_Enable();
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OUTER_BUFFER_LENGTH 0x60
|
|
|
|
#define INNER_BUFFER_LENGTH 0x30
|
|
|
|
static void DoMirageTowerDisintegration(u8 taskId)
|
|
|
|
{
|
|
|
|
u8 bgShakeTaskId, j;
|
|
|
|
u16 i;
|
|
|
|
u8 index;
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
case 1:
|
2021-04-27 08:30:26 +02:00
|
|
|
sFallingTower = AllocZeroed(OUTER_BUFFER_LENGTH * sizeof(struct FallAnim_Tower));
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1))
|
|
|
|
{
|
|
|
|
if (gTasks[taskId].data[1] > 1)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
// Initialize disintegration pattern
|
2018-12-25 18:02:41 +01:00
|
|
|
index = gTasks[taskId].data[3];
|
2021-04-27 08:30:26 +02:00
|
|
|
sFallingTower[index].disintegrateRand = Alloc(INNER_BUFFER_LENGTH);
|
2018-12-25 18:02:41 +01:00
|
|
|
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
|
2021-04-27 08:30:26 +02:00
|
|
|
sFallingTower[index].disintegrateRand[i] = i;
|
|
|
|
|
|
|
|
// Randomize disintegration pattern
|
2018-12-25 18:02:41 +01:00
|
|
|
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
|
|
|
|
{
|
|
|
|
u16 rand1, rand2, temp;
|
2021-04-27 08:30:26 +02:00
|
|
|
rand1 = Random() % INNER_BUFFER_LENGTH;
|
|
|
|
rand2 = Random() % INNER_BUFFER_LENGTH;
|
|
|
|
SWAP(sFallingTower[index].disintegrateRand[rand2], sFallingTower[index].disintegrateRand[rand1], temp);
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1))
|
|
|
|
gTasks[taskId].data[3]++;
|
|
|
|
gTasks[taskId].data[1] = 0;
|
|
|
|
}
|
|
|
|
gTasks[taskId].data[1]++;
|
|
|
|
}
|
|
|
|
index = gTasks[taskId].data[3];
|
|
|
|
for (i = (u8)(gTasks[taskId].data[2]); i < index; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 1; j++)
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
UpdateDisintegrationEffect(sMirageTowerGfxBuffer,
|
|
|
|
(OUTER_BUFFER_LENGTH - 1 - i) * INNER_BUFFER_LENGTH + sFallingTower[i].disintegrateRand[sFallingTower[i].disintegrateIdx++],
|
2018-12-25 18:02:41 +01:00
|
|
|
0, INNER_BUFFER_LENGTH, 1);
|
|
|
|
}
|
2021-04-27 08:30:26 +02:00
|
|
|
if (sFallingTower[i].disintegrateIdx > (INNER_BUFFER_LENGTH - 1))
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
FREE_AND_SET_NULL(sFallingTower[i].disintegrateRand);
|
2018-12-25 18:02:41 +01:00
|
|
|
gTasks[taskId].data[2]++;
|
|
|
|
if ((i % 2) == 1)
|
|
|
|
sBgShakeOffsets->bgVOFS--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0);
|
2021-04-27 08:30:26 +02:00
|
|
|
if (sFallingTower[OUTER_BUFFER_LENGTH - 1].disintegrateIdx > INNER_BUFFER_LENGTH - 1)
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
UnsetBgTilemapBuffer(0);
|
|
|
|
bgShakeTaskId = FindTaskIdByFunc(UpdateBgShake);
|
2021-02-20 05:22:26 +01:00
|
|
|
if (bgShakeTaskId != TASK_NONE)
|
2018-12-25 18:02:41 +01:00
|
|
|
DestroyTask(bgShakeTaskId);
|
|
|
|
sBgShakeOffsets->bgVOFS = sBgShakeOffsets->bgHOFS = 0;
|
|
|
|
SetBgShakeOffsets();
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
FREE_AND_SET_NULL(sBgShakeOffsets);
|
2021-04-27 08:30:26 +02:00
|
|
|
FREE_AND_SET_NULL(sFallingTower);
|
2018-12-25 18:02:41 +01:00
|
|
|
FREE_AND_SET_NULL(sMirageTowerGfxBuffer);
|
|
|
|
FREE_AND_SET_NULL(sMirageTowerTilemapBuffer);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
SetGpuRegBits(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2));
|
|
|
|
SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0));
|
2018-12-26 13:05:02 +01:00
|
|
|
SetBgAttribute(0, BG_ATTR_PRIORITY, 0);
|
2018-12-27 23:30:47 +01:00
|
|
|
InitStandardTextBoxWindows();
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
ShowBg(0);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
DestroyTask(taskId);
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_Enable();
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static void Task_FossilFallAndSink(u8 taskId)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
u8 *buffer;
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
switch (gTasks[taskId].tState)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
case 1:
|
2021-04-27 08:30:26 +02:00
|
|
|
sFallingFossil = AllocZeroed(sizeof(*sFallingFossil));
|
|
|
|
sFallingFossil->frameImageTiles = AllocZeroed(sizeof(sFossil_Gfx));
|
|
|
|
sFallingFossil->frameImage = AllocZeroed(sizeof(*sFallingFossil->frameImage));
|
|
|
|
sFallingFossil->disintegrateRand = AllocZeroed(FOSSIL_DISINTEGRATE_LENGTH * sizeof(u16));
|
|
|
|
sFallingFossil->disintegrateIdx = 0;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-04-27 08:30:26 +02:00
|
|
|
buffer = sFallingFossil->frameImageTiles;
|
|
|
|
for (i = 0; i < sizeof(sFossil_Gfx); i++, buffer++)
|
|
|
|
*buffer = sFossil_Gfx[i];
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-04-27 08:30:26 +02:00
|
|
|
sFallingFossil->frameImage->data = sFallingFossil->frameImageTiles;
|
|
|
|
sFallingFossil->frameImage->size = sizeof(sFossil_Gfx);
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
struct SpriteTemplate fossilTemplate = sSpriteTemplate_FallingFossil;
|
|
|
|
fossilTemplate.images = sFallingFossil->frameImage;
|
|
|
|
sFallingFossil->spriteId = CreateSprite(&fossilTemplate, 128, -16, 1);
|
|
|
|
gSprites[sFallingFossil->spriteId].centerToCornerVecX = 0;
|
2021-07-12 07:39:28 +02:00
|
|
|
gSprites[sFallingFossil->spriteId].data[0] = gSprites[sFallingFossil->spriteId].x;
|
2021-04-27 08:30:26 +02:00
|
|
|
gSprites[sFallingFossil->spriteId].data[1] = 1;
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
case 5:
|
2021-04-27 08:30:26 +02:00
|
|
|
// Initialize disintegration pattern
|
|
|
|
for (i = 0; i < FOSSIL_DISINTEGRATE_LENGTH; i++)
|
|
|
|
sFallingFossil->disintegrateRand[i] = i;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2021-04-27 08:30:26 +02:00
|
|
|
// Randomize disintegration pattern
|
|
|
|
for (i = 0; i < FOSSIL_DISINTEGRATE_LENGTH * sizeof(u16); i++)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
|
|
|
u16 rand1, rand2, temp;
|
2021-04-27 08:30:26 +02:00
|
|
|
rand1 = Random() % FOSSIL_DISINTEGRATE_LENGTH;
|
|
|
|
rand2 = Random() % FOSSIL_DISINTEGRATE_LENGTH;
|
|
|
|
SWAP(sFallingFossil->disintegrateRand[rand2], sFallingFossil->disintegrateRand[rand1], temp);
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
2021-04-27 08:30:26 +02:00
|
|
|
gSprites[sFallingFossil->spriteId].callback = SpriteCB_FallingFossil;
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2021-04-27 08:30:26 +02:00
|
|
|
// Wait for fossil to finish falling / disintegrating
|
|
|
|
if (gSprites[sFallingFossil->spriteId].callback != SpriteCallbackDummy)
|
2018-12-25 18:02:41 +01:00
|
|
|
return;
|
2021-04-27 08:30:26 +02:00
|
|
|
DestroySprite(&gSprites[sFallingFossil->spriteId]);
|
|
|
|
FREE_AND_SET_NULL(sFallingFossil->disintegrateRand);;
|
|
|
|
FREE_AND_SET_NULL(sFallingFossil->frameImage);
|
|
|
|
FREE_AND_SET_NULL(sFallingFossil->frameImageTiles);
|
|
|
|
FREE_AND_SET_NULL(sFallingFossil);
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_Enable();
|
2018-12-25 18:02:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-04-27 08:30:26 +02:00
|
|
|
gTasks[taskId].tState++;
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
static void SpriteCB_FallingFossil(struct Sprite *sprite)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
if (sFallingFossil->disintegrateIdx >= FOSSIL_DISINTEGRATE_LENGTH)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
// End animation
|
2018-12-25 18:02:41 +01:00
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
2021-07-07 15:11:52 +02:00
|
|
|
else if (sprite->y >= 96)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
// Fossil has reached the ground, update disintegration animation
|
2018-12-25 18:02:41 +01:00
|
|
|
u8 i;
|
|
|
|
for (i = 0; i < 2; i++)
|
2021-04-27 08:30:26 +02:00
|
|
|
UpdateDisintegrationEffect(sFallingFossil->frameImageTiles, sFallingFossil->disintegrateRand[sFallingFossil->disintegrateIdx++], 0, 16, 0);
|
2018-12-25 18:02:41 +01:00
|
|
|
|
|
|
|
StartSpriteAnim(sprite, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
// Fossil is still falling
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y++;
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 16:17:58 +02:00
|
|
|
static void UpdateDisintegrationEffect(u8 *tiles, u16 randId, u8 c, u8 size, u8 offset)
|
2018-12-25 18:02:41 +01:00
|
|
|
{
|
2021-04-27 08:30:26 +02:00
|
|
|
u8 heightTiles, height, widthTiles, width;
|
|
|
|
u16 var, baseOffset;
|
|
|
|
u8 col, row;
|
|
|
|
u8 flag, tileMask;
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
height = randId / size;
|
|
|
|
sDebug_DisintegrationData[0] = height;
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
width = randId % size;
|
|
|
|
sDebug_DisintegrationData[1] = width;
|
2018-12-25 18:02:41 +01:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
row = height & 7;
|
|
|
|
col = width & 7;
|
|
|
|
sDebug_DisintegrationData[2] = height & 7;
|
|
|
|
sDebug_DisintegrationData[3] = width & 7;
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
widthTiles = width / 8;
|
|
|
|
heightTiles = height / 8;
|
|
|
|
sDebug_DisintegrationData[4] = width / 8;
|
|
|
|
sDebug_DisintegrationData[5] = height / 8;
|
2020-10-24 03:51:46 +02:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
var = (size / 8) * (heightTiles * 64) + (widthTiles * 64);
|
|
|
|
sDebug_DisintegrationData[6] = var;
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
baseOffset = var + ((row * 8) + col);
|
|
|
|
baseOffset /= 2;
|
|
|
|
sDebug_DisintegrationData[7] = var + ((row * 8) + col);
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2021-04-27 08:30:26 +02:00
|
|
|
flag = ((randId % 2) ^ 1);
|
|
|
|
tileMask = (c << (flag << 2)) | 15 << (((flag ^ 1) << 2));
|
|
|
|
tiles[baseOffset + (offset * 32)] &= tileMask;
|
2018-12-25 18:02:41 +01:00
|
|
|
}
|