mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-26 11:44:17 +01:00
Clean up mirage tower
This commit is contained in:
parent
265b49c47b
commit
10886a586b
@ -2,9 +2,10 @@
|
||||
.set LOCALID_VICTORIA, 2
|
||||
.set LOCALID_VIVI, 3
|
||||
.set LOCALID_VICKY, 4
|
||||
.set LOCALID_PLAYER_FALLING, 45
|
||||
.set LOCALID_ROCK_SMASH_MAN, 46
|
||||
|
||||
@ Note: LOCALID_ROUTE111_PLAYER_FALLING is used in mirage_tower.c, and is defined in event_objects.h
|
||||
|
||||
Route111_MapScripts:: @ 81F0CA7
|
||||
map_script MAP_SCRIPT_ON_LOAD, Route111_OnLoad
|
||||
map_script MAP_SCRIPT_ON_TRANSITION, Route111_OnTransition
|
||||
@ -127,11 +128,11 @@ Route111_EventScript_MirageTowerDisappear:: @ 81F0E60
|
||||
waitstate
|
||||
delay 24
|
||||
playse SE_FALL
|
||||
addobject LOCALID_PLAYER_FALLING
|
||||
addobject LOCALID_ROUTE111_PLAYER_FALLING
|
||||
special StartPlayerDescendMirageTower
|
||||
waitstate
|
||||
showobjectat OBJ_EVENT_ID_PLAYER, MAP_LITTLEROOT_TOWN
|
||||
removeobject LOCALID_PLAYER_FALLING
|
||||
removeobject LOCALID_ROUTE111_PLAYER_FALLING
|
||||
delay 16
|
||||
turnobject OBJ_EVENT_ID_PLAYER, DIR_NORTH
|
||||
delay 16
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 298 B |
@ -279,7 +279,11 @@
|
||||
|
||||
#define FIRST_DECORATION_SPRITE_GFX OBJ_EVENT_GFX_PICHU_DOLL
|
||||
|
||||
// Special object event local ids
|
||||
#define OBJ_EVENT_ID_PLAYER 0xFF
|
||||
#define OBJ_EVENT_ID_CAMERA 0x7F
|
||||
|
||||
// Object event local ids referenced in C files
|
||||
#define LOCALID_ROUTE111_PLAYER_FALLING 45
|
||||
|
||||
#endif // GUARD_CONSTANTS_EVENT_OBJECTS_H
|
||||
|
@ -14,12 +14,14 @@
|
||||
#include "sprite.h"
|
||||
#include "task.h"
|
||||
#include "window.h"
|
||||
#include "constants/event_objects.h"
|
||||
#include "constants/maps.h"
|
||||
#include "constants/rgb.h"
|
||||
#include "constants/songs.h"
|
||||
#include "constants/metatile_labels.h"
|
||||
|
||||
struct MirageTowerPulseBlend {
|
||||
struct MirageTowerPulseBlend
|
||||
{
|
||||
u8 taskId;
|
||||
struct PulseBlend pulseBlend;
|
||||
};
|
||||
@ -37,59 +39,51 @@ struct BgRegOffsets
|
||||
u16 bgVOFS;
|
||||
};
|
||||
|
||||
struct Struct203CF10
|
||||
struct FallAnim_Tower
|
||||
{
|
||||
u8 *buffer;
|
||||
u8 currIndex;
|
||||
u8 *disintegrateRand;
|
||||
u8 disintegrateIdx;
|
||||
};
|
||||
|
||||
struct DynamicSpriteFrameImage
|
||||
{
|
||||
u8 *data;
|
||||
u16 size;
|
||||
};
|
||||
|
||||
struct Struct203CF0C
|
||||
struct FallAnim_Fossil
|
||||
{
|
||||
u8 *frameImageTiles;
|
||||
struct DynamicSpriteFrameImage *frameImage;
|
||||
struct SpriteFrameImage *frameImage;
|
||||
u8 spriteId;
|
||||
u16 *unkC;
|
||||
u16 unk10;
|
||||
u16 *disintegrateRand;
|
||||
u16 disintegrateIdx;
|
||||
};
|
||||
|
||||
#define TAG_CEILING_CRUMBLE 4000
|
||||
|
||||
#define MIRAGE_TOWER_GFX_LENGTH (sizeof(sBlankTile_Gfx) + sizeof(sMirageTower_Gfx))
|
||||
#define ROOT_FOSSIL_GFX_LENGTH sizeof(sRootFossil_Gfx)
|
||||
#define ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH 0x100
|
||||
#define FOSSIL_DISINTEGRATE_LENGTH 0x100
|
||||
|
||||
// extern data
|
||||
extern const struct SpriteSheet gMirageTowerCeilingCrumbleSpriteSheets[];
|
||||
extern const s16 sCeilingCrumblePositions[][3];
|
||||
static const struct SpriteSheet sCeilingCrumbleSpriteSheets[];
|
||||
static const s16 sCeilingCrumblePositions[][3];
|
||||
|
||||
// static functions
|
||||
static void PlayerDescendMirageTower(u8 taskId);
|
||||
static void DoScreenShake(u8 taskId);
|
||||
static void PlayerDescendMirageTower(u8);
|
||||
static void DoScreenShake(u8);
|
||||
static void IncrementCeilingCrumbleFinishedCount(void);
|
||||
static void WaitCeilingCrumble(u8 taskId);
|
||||
static void FinishCeilingCrumbleTask(u8 taskId);
|
||||
static void WaitCeilingCrumble(u8);
|
||||
static void FinishCeilingCrumbleTask(u8);
|
||||
static void CreateCeilingCrumbleSprites(void);
|
||||
static void MoveCeilingCrumbleSprite(struct Sprite* sprite);
|
||||
static void DoMirageTowerDisintegration(u8 taskId);
|
||||
static void InitMirageTowerShake(u8 taskId);
|
||||
static void DoFossilFallAndSink(u8 taskId);
|
||||
static void sub_81BF248(struct Sprite *);
|
||||
static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e);
|
||||
static void SpriteCB_CeilingCrumble(struct Sprite*);
|
||||
static void DoMirageTowerDisintegration(u8);
|
||||
static void InitMirageTowerShake(u8);
|
||||
static void Task_FossilFallAndSink(u8);
|
||||
static void SpriteCB_FallingFossil(struct Sprite *);
|
||||
static void UpdateDisintegrationEffect(u8*, u16, u8, u8, u8);
|
||||
|
||||
// rodata
|
||||
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");
|
||||
static const u16 sRootFossil_Pal[] = INCBIN_U16("graphics/misc/fossil.gbapal");
|
||||
static const u8 sRootFossil_Gfx[] = INCBIN_U8("graphics/misc/fossil.4bpp");
|
||||
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
|
||||
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");
|
||||
|
||||
const s16 sCeilingCrumblePositions[][3] =
|
||||
static const s16 sCeilingCrumblePositions[][3] =
|
||||
{
|
||||
{ 0, 10, 65},
|
||||
{ 17, 3, 50},
|
||||
@ -101,10 +95,10 @@ const s16 sCeilingCrumblePositions[][3] =
|
||||
{-24, -4, 65},
|
||||
};
|
||||
|
||||
const struct SpriteSheet gMirageTowerCeilingCrumbleSpriteSheets[] =
|
||||
static const struct SpriteSheet sCeilingCrumbleSpriteSheets[] =
|
||||
{
|
||||
{sMirageTowerCrumbles_Gfx, 0x0080, 4000},
|
||||
{NULL}
|
||||
{sMirageTowerCrumbles_Gfx, 0x80, TAG_CEILING_CRUMBLE},
|
||||
{}
|
||||
};
|
||||
|
||||
static const struct MetatileCoords sInvisibleMirageTowerMetatiles[] =
|
||||
@ -129,13 +123,13 @@ static const struct MetatileCoords sInvisibleMirageTowerMetatiles[] =
|
||||
{20, 58, METATILE_General_SandPit_Center},
|
||||
};
|
||||
|
||||
static const union AnimCmd gSpriteAnim_8617DEC[] =
|
||||
static const union AnimCmd sAnim_FallingFossil[] =
|
||||
{
|
||||
ANIMCMD_FRAME(0, 1),
|
||||
ANIMCMD_END,
|
||||
};
|
||||
|
||||
static const struct OamData gOamData_8617DF4 =
|
||||
static const struct OamData sOamData_FallingFossil =
|
||||
{
|
||||
.y = 0,
|
||||
.affineMode = ST_OAM_AFFINE_OFF,
|
||||
@ -152,14 +146,20 @@ static const struct OamData gOamData_8617DF4 =
|
||||
.affineParam = 0,
|
||||
};
|
||||
|
||||
static const union AnimCmd *const gSpriteAnimTable_8617DFC[] =
|
||||
static const union AnimCmd *const sAnims_FallingFossil[] =
|
||||
{
|
||||
gSpriteAnim_8617DEC,
|
||||
sAnim_FallingFossil,
|
||||
};
|
||||
|
||||
static const struct SpriteTemplate gUnknown_08617E00 =
|
||||
static const struct SpriteTemplate sSpriteTemplate_FallingFossil =
|
||||
{
|
||||
0xFFFF, 0xFFFF, &gOamData_8617DF4, gSpriteAnimTable_8617DFC, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy
|
||||
.tileTag = 0xFFFF,
|
||||
.paletteTag = 0xFFFF,
|
||||
.oam = &sOamData_FallingFossil,
|
||||
.anims = sAnims_FallingFossil,
|
||||
.images = NULL,
|
||||
.affineAnims = gDummySpriteAffineAnimTable,
|
||||
.callback = SpriteCallbackDummy
|
||||
};
|
||||
|
||||
const struct PulseBlendSettings gMirageTowerPulseBlendSettings = {
|
||||
@ -174,18 +174,18 @@ const struct PulseBlendSettings gMirageTowerPulseBlendSettings = {
|
||||
.unk7_7 = 1,
|
||||
};
|
||||
|
||||
static const union AnimCmd sCeilingCrumble2AnimCmd[] =
|
||||
static const union AnimCmd sAnim_CeilingCrumbleSmall[] =
|
||||
{
|
||||
ANIMCMD_FRAME(0, 12),
|
||||
ANIMCMD_JUMP(0),
|
||||
};
|
||||
|
||||
static const union AnimCmd *const sCeilingCrumble2AnimCmds[] =
|
||||
static const union AnimCmd *const sAnims_CeilingCrumbleSmall[] =
|
||||
{
|
||||
sCeilingCrumble2AnimCmd,
|
||||
sAnim_CeilingCrumbleSmall,
|
||||
};
|
||||
|
||||
static const struct OamData sCeilingCrumble2OamData =
|
||||
static const struct OamData sOamData_CeilingCrumbleSmall =
|
||||
{
|
||||
.y = 0,
|
||||
.affineMode = ST_OAM_AFFINE_OFF,
|
||||
@ -202,28 +202,28 @@ static const struct OamData sCeilingCrumble2OamData =
|
||||
.affineParam = 0,
|
||||
};
|
||||
|
||||
static const struct SpriteTemplate sCeilingCrumbleSpriteTemplate2 = {
|
||||
.tileTag = 4000,
|
||||
static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleSmall = {
|
||||
.tileTag = TAG_CEILING_CRUMBLE,
|
||||
.paletteTag = 0xFFFF,
|
||||
.oam = &sCeilingCrumble2OamData,
|
||||
.anims = sCeilingCrumble2AnimCmds,
|
||||
.oam = &sOamData_CeilingCrumbleSmall,
|
||||
.anims = sAnims_CeilingCrumbleSmall,
|
||||
.images = NULL,
|
||||
.affineAnims = gDummySpriteAffineAnimTable,
|
||||
.callback = MoveCeilingCrumbleSprite
|
||||
.callback = SpriteCB_CeilingCrumble
|
||||
};
|
||||
|
||||
static const union AnimCmd sCeilingCrumble1AnimCmd[] =
|
||||
static const union AnimCmd sAnim_CeilingCrumbleLarge[] =
|
||||
{
|
||||
ANIMCMD_FRAME(0, 12),
|
||||
ANIMCMD_JUMP(0),
|
||||
};
|
||||
|
||||
static const union AnimCmd *const sCeilingCrumble1AnimCmds[] =
|
||||
static const union AnimCmd *const sAnims_CeilingCrumbleLarge[] =
|
||||
{
|
||||
sCeilingCrumble1AnimCmd,
|
||||
sAnim_CeilingCrumbleLarge,
|
||||
};
|
||||
|
||||
static const struct OamData sCeilingCrumble1OamData =
|
||||
static const struct OamData sOamData_CeilingCrumbleLarge =
|
||||
{
|
||||
.y = 0,
|
||||
.affineMode = ST_OAM_AFFINE_OFF,
|
||||
@ -240,24 +240,26 @@ static const struct OamData sCeilingCrumble1OamData =
|
||||
.affineParam = 0,
|
||||
};
|
||||
|
||||
static const struct SpriteTemplate sCeilingCrumbleSpriteTemplate1 = {
|
||||
.tileTag = 4000,
|
||||
static const struct SpriteTemplate sSpriteTemplate_CeilingCrumbleLarge = {
|
||||
.tileTag = TAG_CEILING_CRUMBLE,
|
||||
.paletteTag = 0xFFFF,
|
||||
.oam = &sCeilingCrumble1OamData,
|
||||
.anims = sCeilingCrumble1AnimCmds,
|
||||
.oam = &sOamData_CeilingCrumbleLarge,
|
||||
.anims = sAnims_CeilingCrumbleLarge,
|
||||
.images = NULL,
|
||||
.affineAnims = gDummySpriteAffineAnimTable,
|
||||
.callback = MoveCeilingCrumbleSprite
|
||||
.callback = SpriteCB_CeilingCrumble
|
||||
};
|
||||
|
||||
EWRAM_DATA static u8* sMirageTowerGfxBuffer = NULL;
|
||||
EWRAM_DATA static u8* sMirageTowerTilemapBuffer = NULL;
|
||||
EWRAM_DATA static struct Struct203CF0C *sUnknown_0203CF0C = NULL;
|
||||
EWRAM_DATA static struct Struct203CF10 *sUnknown_0203CF10 = NULL;
|
||||
EWRAM_DATA static struct FallAnim_Fossil *sFallingFossil = NULL;
|
||||
EWRAM_DATA static struct FallAnim_Tower *sFallingTower = NULL;
|
||||
EWRAM_DATA static struct BgRegOffsets *sBgShakeOffsets = NULL;
|
||||
EWRAM_DATA struct MirageTowerPulseBlend *sMirageTowerPulseBlend = NULL;
|
||||
EWRAM_DATA static struct MirageTowerPulseBlend *sMirageTowerPulseBlend = NULL;
|
||||
|
||||
static u16 gUnknown_030012A8[8];
|
||||
// Holds data about the disintegration effect for Mirage Tower / the unchosen fossil.
|
||||
// Never read, presumably for debugging
|
||||
static u16 sDebug_DisintegrationData[8];
|
||||
|
||||
bool8 IsMirageTowerVisible(void)
|
||||
{
|
||||
@ -319,6 +321,7 @@ void SetMirageTowerVisibility(void)
|
||||
|
||||
if (VarGet(VAR_MIRAGE_TOWER_STATE))
|
||||
{
|
||||
// Mirage Tower event has already been completed, hide it
|
||||
FlagClear(FLAG_MIRAGE_TOWER_VISIBLE);
|
||||
return;
|
||||
}
|
||||
@ -343,32 +346,40 @@ void StartPlayerDescendMirageTower(void)
|
||||
CreateTask(PlayerDescendMirageTower, 8);
|
||||
}
|
||||
|
||||
// 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
|
||||
static void PlayerDescendMirageTower(u8 taskId)
|
||||
{
|
||||
u8 objectEventId;
|
||||
struct ObjectEvent *fakePlayerObjectEvent;
|
||||
struct ObjectEvent *playerObjectEvent;
|
||||
struct ObjectEvent *fallingPlayer;
|
||||
struct ObjectEvent *player;
|
||||
|
||||
TryGetObjectEventIdByLocalIdAndMap(45, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectEventId);
|
||||
fakePlayerObjectEvent = &gObjectEvents[objectEventId];
|
||||
gSprites[fakePlayerObjectEvent->spriteId].pos2.y += 4;
|
||||
playerObjectEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
|
||||
if ((gSprites[fakePlayerObjectEvent->spriteId].pos1.y + gSprites[fakePlayerObjectEvent->spriteId].pos2.y) >=
|
||||
(gSprites[playerObjectEvent->spriteId].pos1.y + gSprites[playerObjectEvent->spriteId].pos2.y))
|
||||
TryGetObjectEventIdByLocalIdAndMap(LOCALID_ROUTE111_PLAYER_FALLING, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objectEventId);
|
||||
fallingPlayer = &gObjectEvents[objectEventId];
|
||||
gSprites[fallingPlayer->spriteId].pos2.y += 4;
|
||||
player = &gObjectEvents[gPlayerAvatar.objectEventId];
|
||||
if ((gSprites[fallingPlayer->spriteId].pos1.y + gSprites[fallingPlayer->spriteId].pos2.y) >=
|
||||
(gSprites[player->spriteId].pos1.y + gSprites[player->spriteId].pos2.y))
|
||||
{
|
||||
DestroyTask(taskId);
|
||||
EnableBothScriptContexts();
|
||||
}
|
||||
}
|
||||
|
||||
#define tXShakeOffset data[0]
|
||||
#define tTimer data[1]
|
||||
#define tNumShakes data[2]
|
||||
#define tShakeDelay data[3]
|
||||
#define tYShakeOffset data[4]
|
||||
|
||||
static void StartScreenShake(u8 yShakeOffset, u8 xShakeOffset, u8 numShakes, u8 shakeDelay)
|
||||
{
|
||||
u8 taskId = CreateTask(DoScreenShake, 9);
|
||||
gTasks[taskId].data[0] = xShakeOffset;
|
||||
gTasks[taskId].data[1] = 0;
|
||||
gTasks[taskId].data[2] = numShakes;
|
||||
gTasks[taskId].data[3] = shakeDelay;
|
||||
gTasks[taskId].data[4] = yShakeOffset;
|
||||
gTasks[taskId].tXShakeOffset = xShakeOffset;
|
||||
gTasks[taskId].tTimer = 0;
|
||||
gTasks[taskId].tNumShakes = numShakes;
|
||||
gTasks[taskId].tShakeDelay = shakeDelay;
|
||||
gTasks[taskId].tYShakeOffset = yShakeOffset;
|
||||
SetCameraPanningCallback(NULL);
|
||||
PlaySE(SE_M_STRENGTH);
|
||||
}
|
||||
@ -378,15 +389,15 @@ static void DoScreenShake(u8 taskId)
|
||||
s16 *data;
|
||||
|
||||
data = gTasks[taskId].data;
|
||||
data[1]++;
|
||||
if (data[1] % data[3] == 0)
|
||||
tTimer++;
|
||||
if (tTimer % tShakeDelay == 0)
|
||||
{
|
||||
data[1] = 0;
|
||||
data[2]--;
|
||||
data[0] = -data[0];
|
||||
data[4] = -data[4];
|
||||
SetCameraPanning(data[0], data[4]);
|
||||
if (data[2] == 0)
|
||||
tTimer = 0;
|
||||
tNumShakes--;
|
||||
tXShakeOffset = -tXShakeOffset;
|
||||
tYShakeOffset = -tYShakeOffset;
|
||||
SetCameraPanning(tXShakeOffset, tYShakeOffset);
|
||||
if (tNumShakes == 0)
|
||||
{
|
||||
IncrementCeilingCrumbleFinishedCount();
|
||||
DestroyTask(taskId);
|
||||
@ -395,6 +406,12 @@ static void DoScreenShake(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
#undef tXShakeOffset
|
||||
#undef tTimer
|
||||
#undef tNumShakes
|
||||
#undef tShakeDelay
|
||||
#undef tYShakeOffset
|
||||
|
||||
static void IncrementCeilingCrumbleFinishedCount(void)
|
||||
{
|
||||
u8 taskId = FindTaskIdByFunc(WaitCeilingCrumble);
|
||||
@ -404,7 +421,7 @@ static void IncrementCeilingCrumbleFinishedCount(void)
|
||||
|
||||
void DoMirageTowerCeilingCrumble(void)
|
||||
{
|
||||
LoadSpriteSheets(gMirageTowerCeilingCrumbleSpriteSheets);
|
||||
LoadSpriteSheets(sCeilingCrumbleSpriteSheets);
|
||||
CreateCeilingCrumbleSprites();
|
||||
CreateTask(WaitCeilingCrumble, 8);
|
||||
StartScreenShake(2, 1, 16, 3);
|
||||
@ -421,7 +438,7 @@ static void WaitCeilingCrumble(u8 taskId)
|
||||
|
||||
static void FinishCeilingCrumbleTask(u8 taskId)
|
||||
{
|
||||
FreeSpriteTilesByTag(4000);
|
||||
FreeSpriteTilesByTag(TAG_CEILING_CRUMBLE);
|
||||
DestroyTask(taskId);
|
||||
EnableBothScriptContexts();
|
||||
}
|
||||
@ -433,21 +450,21 @@ static void CreateCeilingCrumbleSprites(void)
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
spriteId = CreateSprite(&sCeilingCrumbleSpriteTemplate1, sCeilingCrumblePositions[i][0] + 120, sCeilingCrumblePositions[i][1], 8);
|
||||
spriteId = CreateSprite(&sSpriteTemplate_CeilingCrumbleLarge, sCeilingCrumblePositions[i][0] + 120, sCeilingCrumblePositions[i][1], 8);
|
||||
gSprites[spriteId].oam.priority = 0;
|
||||
gSprites[spriteId].oam.paletteNum = 0;
|
||||
gSprites[spriteId].data[0] = i;
|
||||
}
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
spriteId = CreateSprite(&sCeilingCrumbleSpriteTemplate2, sCeilingCrumblePositions[i][0] + 115, sCeilingCrumblePositions[i][1] - 3, 8);
|
||||
spriteId = CreateSprite(&sSpriteTemplate_CeilingCrumbleSmall, sCeilingCrumblePositions[i][0] + 115, sCeilingCrumblePositions[i][1] - 3, 8);
|
||||
gSprites[spriteId].oam.priority = 0;
|
||||
gSprites[spriteId].oam.paletteNum = 0;
|
||||
gSprites[spriteId].data[0] = i;
|
||||
}
|
||||
}
|
||||
|
||||
static void MoveCeilingCrumbleSprite(struct Sprite* sprite)
|
||||
static void SpriteCB_CeilingCrumble(struct Sprite* sprite)
|
||||
{
|
||||
sprite->data[1] += 2;
|
||||
sprite->pos2.y = sprite->data[1] / 2;
|
||||
@ -478,7 +495,7 @@ void StartMirageTowerShake(void)
|
||||
|
||||
void StartMirageTowerFossilFallAndSink(void)
|
||||
{
|
||||
CreateTask(DoFossilFallAndSink, 9);
|
||||
CreateTask(Task_FossilFallAndSink, 9);
|
||||
}
|
||||
|
||||
static void SetBgShakeOffsets(void)
|
||||
@ -501,42 +518,44 @@ static void UpdateBgShake(u8 taskId)
|
||||
}
|
||||
}
|
||||
|
||||
#define tState data[0]
|
||||
|
||||
static void InitMirageTowerShake(u8 taskId)
|
||||
{
|
||||
u8 zero;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
switch (gTasks[taskId].tState)
|
||||
{
|
||||
case 0:
|
||||
FreeAllWindowBuffers();
|
||||
SetBgAttribute(0, BG_ATTR_PRIORITY, 2);
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 1:
|
||||
sMirageTowerGfxBuffer = (u8 *)AllocZeroed(MIRAGE_TOWER_GFX_LENGTH);
|
||||
sMirageTowerTilemapBuffer = (u8 *)AllocZeroed(BG_SCREEN_SIZE);
|
||||
ChangeBgX(0, 0, 0);
|
||||
ChangeBgY(0, 0, 0);
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 2:
|
||||
CpuSet(sBlankTile_Gfx, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH / 2);
|
||||
LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0);
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 3:
|
||||
SetBgTilemapBuffer(0, sMirageTowerTilemapBuffer);
|
||||
CopyToBgTilemapBufferRect_ChangePalette(0, &sMirageTowerTilemap, 12, 29, 6, 12, 17);
|
||||
CopyBgTilemapBufferToVram(0);
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 4:
|
||||
ShowBg(0);
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 5:
|
||||
SetInvisibleMirageTowerMetatiles();
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
break;
|
||||
case 6:
|
||||
sBgShakeOffsets = Alloc(sizeof(*sBgShakeOffsets));
|
||||
@ -558,27 +577,29 @@ static void DoMirageTowerDisintegration(u8 taskId)
|
||||
u16 i;
|
||||
u8 index;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
switch (gTasks[taskId].tState)
|
||||
{
|
||||
case 1:
|
||||
sUnknown_0203CF10 = AllocZeroed(OUTER_BUFFER_LENGTH * sizeof(struct Struct203CF10));
|
||||
sFallingTower = AllocZeroed(OUTER_BUFFER_LENGTH * sizeof(struct FallAnim_Tower));
|
||||
break;
|
||||
case 3:
|
||||
if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1))
|
||||
{
|
||||
if (gTasks[taskId].data[1] > 1)
|
||||
{
|
||||
// Initialize disintegration pattern
|
||||
index = gTasks[taskId].data[3];
|
||||
sUnknown_0203CF10[index].buffer = Alloc(INNER_BUFFER_LENGTH);
|
||||
sFallingTower[index].disintegrateRand = Alloc(INNER_BUFFER_LENGTH);
|
||||
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
|
||||
sUnknown_0203CF10[index].buffer[i] = i;
|
||||
sFallingTower[index].disintegrateRand[i] = i;
|
||||
|
||||
// Randomize disintegration pattern
|
||||
for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++)
|
||||
{
|
||||
u16 rand1, rand2, temp;
|
||||
|
||||
rand1 = Random() % 0x30;
|
||||
rand2 = Random() % 0x30;
|
||||
SWAP(sUnknown_0203CF10[index].buffer[rand2], sUnknown_0203CF10[index].buffer[rand1], temp);
|
||||
rand1 = Random() % INNER_BUFFER_LENGTH;
|
||||
rand2 = Random() % INNER_BUFFER_LENGTH;
|
||||
SWAP(sFallingTower[index].disintegrateRand[rand2], sFallingTower[index].disintegrateRand[rand1], temp);
|
||||
}
|
||||
if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1))
|
||||
gTasks[taskId].data[3]++;
|
||||
@ -591,20 +612,20 @@ static void DoMirageTowerDisintegration(u8 taskId)
|
||||
{
|
||||
for (j = 0; j < 1; j++)
|
||||
{
|
||||
sub_81BF2B8(sMirageTowerGfxBuffer,
|
||||
((((OUTER_BUFFER_LENGTH - 1) - i) * INNER_BUFFER_LENGTH) + sUnknown_0203CF10[i].buffer[(sUnknown_0203CF10[i].currIndex)++]),
|
||||
UpdateDisintegrationEffect(sMirageTowerGfxBuffer,
|
||||
(OUTER_BUFFER_LENGTH - 1 - i) * INNER_BUFFER_LENGTH + sFallingTower[i].disintegrateRand[sFallingTower[i].disintegrateIdx++],
|
||||
0, INNER_BUFFER_LENGTH, 1);
|
||||
}
|
||||
if (sUnknown_0203CF10[i].currIndex > (INNER_BUFFER_LENGTH - 1))
|
||||
if (sFallingTower[i].disintegrateIdx > (INNER_BUFFER_LENGTH - 1))
|
||||
{
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF10[i].buffer);
|
||||
FREE_AND_SET_NULL(sFallingTower[i].disintegrateRand);
|
||||
gTasks[taskId].data[2]++;
|
||||
if ((i % 2) == 1)
|
||||
sBgShakeOffsets->bgVOFS--;
|
||||
}
|
||||
}
|
||||
LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0);
|
||||
if (sUnknown_0203CF10[OUTER_BUFFER_LENGTH - 1].currIndex > (INNER_BUFFER_LENGTH - 1))
|
||||
if (sFallingTower[OUTER_BUFFER_LENGTH - 1].disintegrateIdx > INNER_BUFFER_LENGTH - 1)
|
||||
break;
|
||||
return;
|
||||
case 4:
|
||||
@ -617,7 +638,7 @@ static void DoMirageTowerDisintegration(u8 taskId)
|
||||
break;
|
||||
case 5:
|
||||
FREE_AND_SET_NULL(sBgShakeOffsets);
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF10);
|
||||
FREE_AND_SET_NULL(sFallingTower);
|
||||
FREE_AND_SET_NULL(sMirageTowerGfxBuffer);
|
||||
FREE_AND_SET_NULL(sMirageTowerTilemapBuffer);
|
||||
break;
|
||||
@ -635,127 +656,128 @@ static void DoMirageTowerDisintegration(u8 taskId)
|
||||
EnableBothScriptContexts();
|
||||
break;
|
||||
}
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
}
|
||||
|
||||
static void DoFossilFallAndSink(u8 taskId)
|
||||
static void Task_FossilFallAndSink(u8 taskId)
|
||||
{
|
||||
u16 i;
|
||||
u8 *buffer;
|
||||
|
||||
switch (gTasks[taskId].data[0])
|
||||
switch (gTasks[taskId].tState)
|
||||
{
|
||||
case 1:
|
||||
sUnknown_0203CF0C = AllocZeroed(sizeof(*sUnknown_0203CF0C));
|
||||
sUnknown_0203CF0C->frameImageTiles = AllocZeroed(ROOT_FOSSIL_GFX_LENGTH);
|
||||
sUnknown_0203CF0C->frameImage = AllocZeroed(sizeof(*sUnknown_0203CF0C->frameImage));
|
||||
sUnknown_0203CF0C->unkC = AllocZeroed(ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16));
|
||||
sUnknown_0203CF0C->unk10 = 0;
|
||||
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;
|
||||
break;
|
||||
case 2:
|
||||
buffer = sUnknown_0203CF0C->frameImageTiles;
|
||||
for (i = 0; i < ROOT_FOSSIL_GFX_LENGTH; i++, buffer++)
|
||||
*buffer = sRootFossil_Gfx[i];
|
||||
buffer = sFallingFossil->frameImageTiles;
|
||||
for (i = 0; i < sizeof(sFossil_Gfx); i++, buffer++)
|
||||
*buffer = sFossil_Gfx[i];
|
||||
break;
|
||||
case 3:
|
||||
sUnknown_0203CF0C->frameImage->data = sUnknown_0203CF0C->frameImageTiles;
|
||||
sUnknown_0203CF0C->frameImage->size = ROOT_FOSSIL_GFX_LENGTH;
|
||||
sFallingFossil->frameImage->data = sFallingFossil->frameImageTiles;
|
||||
sFallingFossil->frameImage->size = sizeof(sFossil_Gfx);
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
struct SpriteTemplate fossilTemplate;
|
||||
|
||||
fossilTemplate = gUnknown_08617E00;
|
||||
fossilTemplate.images = (struct SpriteFrameImage *)(sUnknown_0203CF0C->frameImage);
|
||||
sUnknown_0203CF0C->spriteId = CreateSprite(&fossilTemplate, 128, -16, 1);
|
||||
gSprites[sUnknown_0203CF0C->spriteId].centerToCornerVecX = 0;
|
||||
gSprites[sUnknown_0203CF0C->spriteId].data[0] = gSprites[sUnknown_0203CF0C->spriteId].pos1.x;
|
||||
gSprites[sUnknown_0203CF0C->spriteId].data[1] = 1;
|
||||
struct SpriteTemplate fossilTemplate = sSpriteTemplate_FallingFossil;
|
||||
fossilTemplate.images = sFallingFossil->frameImage;
|
||||
sFallingFossil->spriteId = CreateSprite(&fossilTemplate, 128, -16, 1);
|
||||
gSprites[sFallingFossil->spriteId].centerToCornerVecX = 0;
|
||||
gSprites[sFallingFossil->spriteId].data[0] = gSprites[sFallingFossil->spriteId].pos1.x;
|
||||
gSprites[sFallingFossil->spriteId].data[1] = 1;
|
||||
}
|
||||
case 5:
|
||||
for (i = 0; i < ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH; i++)
|
||||
sUnknown_0203CF0C->unkC[i] = i;
|
||||
// Initialize disintegration pattern
|
||||
for (i = 0; i < FOSSIL_DISINTEGRATE_LENGTH; i++)
|
||||
sFallingFossil->disintegrateRand[i] = i;
|
||||
break;
|
||||
case 6:
|
||||
for (i = 0; i < (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); i++)
|
||||
// Randomize disintegration pattern
|
||||
for (i = 0; i < FOSSIL_DISINTEGRATE_LENGTH * sizeof(u16); i++)
|
||||
{
|
||||
u16 rand1, rand2, temp;
|
||||
|
||||
rand1 = Random() % 0x100;
|
||||
rand2 = Random() % 0x100;
|
||||
SWAP(sUnknown_0203CF0C->unkC[rand2], sUnknown_0203CF0C->unkC[rand1], temp);
|
||||
rand1 = Random() % FOSSIL_DISINTEGRATE_LENGTH;
|
||||
rand2 = Random() % FOSSIL_DISINTEGRATE_LENGTH;
|
||||
SWAP(sFallingFossil->disintegrateRand[rand2], sFallingFossil->disintegrateRand[rand1], temp);
|
||||
}
|
||||
gSprites[sUnknown_0203CF0C->spriteId].callback = sub_81BF248;
|
||||
gSprites[sFallingFossil->spriteId].callback = SpriteCB_FallingFossil;
|
||||
break;
|
||||
case 7:
|
||||
if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy)
|
||||
// Wait for fossil to finish falling / disintegrating
|
||||
if (gSprites[sFallingFossil->spriteId].callback != SpriteCallbackDummy)
|
||||
return;
|
||||
DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]);
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);;
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage);
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles);
|
||||
FREE_AND_SET_NULL(sUnknown_0203CF0C);
|
||||
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);
|
||||
break;
|
||||
case 8:
|
||||
EnableBothScriptContexts();
|
||||
break;
|
||||
}
|
||||
|
||||
gTasks[taskId].data[0]++;
|
||||
gTasks[taskId].tState++;
|
||||
}
|
||||
|
||||
static void sub_81BF248(struct Sprite *sprite)
|
||||
static void SpriteCB_FallingFossil(struct Sprite *sprite)
|
||||
{
|
||||
if (sUnknown_0203CF0C->unk10 >= (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH))
|
||||
if (sFallingFossil->disintegrateIdx >= FOSSIL_DISINTEGRATE_LENGTH)
|
||||
{
|
||||
// End animation
|
||||
sprite->callback = SpriteCallbackDummy;
|
||||
}
|
||||
else if (sprite->pos1.y >= 96)
|
||||
{
|
||||
// Fossil has reached the ground, update disintegration animation
|
||||
u8 i;
|
||||
for (i = 0; i < 2; i++)
|
||||
sub_81BF2B8(sUnknown_0203CF0C->frameImageTiles, sUnknown_0203CF0C->unkC[sUnknown_0203CF0C->unk10++], 0, 16, 0);
|
||||
UpdateDisintegrationEffect(sFallingFossil->frameImageTiles, sFallingFossil->disintegrateRand[sFallingFossil->disintegrateIdx++], 0, 16, 0);
|
||||
|
||||
StartSpriteAnim(sprite, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fossil is still falling
|
||||
sprite->pos1.y++;
|
||||
}
|
||||
}
|
||||
|
||||
static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e)
|
||||
static void UpdateDisintegrationEffect(u8* tiles, u16 randId, u8 c, u8 size, u8 offset)
|
||||
{
|
||||
u8 r5, r4, r0, r2;
|
||||
u16 var, var2;
|
||||
u8 r2_1, r4_1;
|
||||
u8 b2, c2;
|
||||
u8 heightTiles, height, widthTiles, width;
|
||||
u16 var, baseOffset;
|
||||
u8 col, row;
|
||||
u8 flag, tileMask;
|
||||
|
||||
r4 = b / d;
|
||||
gUnknown_030012A8[0] = r4;
|
||||
height = randId / size;
|
||||
sDebug_DisintegrationData[0] = height;
|
||||
|
||||
r2 = b % d;
|
||||
gUnknown_030012A8[1] = r2;
|
||||
width = randId % size;
|
||||
sDebug_DisintegrationData[1] = width;
|
||||
|
||||
r4_1 = r4 & 7;
|
||||
r2_1 = r2 & 7;
|
||||
gUnknown_030012A8[2] = r4 & 7; //should be using r4_1, but that doesn't match
|
||||
gUnknown_030012A8[3] = r2 & 7; //"
|
||||
row = height & 7;
|
||||
col = width & 7;
|
||||
sDebug_DisintegrationData[2] = height & 7;
|
||||
sDebug_DisintegrationData[3] = width & 7;
|
||||
|
||||
r0 = r2 / 8;
|
||||
r5 = r4 / 8;
|
||||
widthTiles = width / 8;
|
||||
heightTiles = height / 8;
|
||||
sDebug_DisintegrationData[4] = width / 8;
|
||||
sDebug_DisintegrationData[5] = height / 8;
|
||||
|
||||
gUnknown_030012A8[4] = r2 / 8; //should be using r0, but that doesn't match
|
||||
gUnknown_030012A8[5] = r4 / 8; //should be using r5, but that doesn't match
|
||||
var = (size / 8) * (heightTiles * 64) + (widthTiles * 64);
|
||||
sDebug_DisintegrationData[6] = var;
|
||||
|
||||
var = (d / 8) * (r5 * 64) + (r0 * 64);
|
||||
gUnknown_030012A8[6] = var;
|
||||
baseOffset = var + ((row * 8) + col);
|
||||
baseOffset /= 2;
|
||||
sDebug_DisintegrationData[7] = var + ((row * 8) + col);
|
||||
|
||||
var2 = var + ((r4_1 * 8) + r2_1);
|
||||
var2 /= 2;
|
||||
gUnknown_030012A8[7] = var + ((r4_1 * 8) + r2_1); //should be using var2 with var2 being divided afterwards, but that doesn't match
|
||||
|
||||
b2 = ((b % 2) ^ 1);
|
||||
c2 = (c << (b2 << 2)) | 15 << (((b2 ^ 1) << 2));
|
||||
a[var2 + (e * 32)] &= c2;
|
||||
flag = ((randId % 2) ^ 1);
|
||||
tileMask = (c << (flag << 2)) | 15 << (((flag ^ 1) << 2));
|
||||
tiles[baseOffset + (offset * 32)] &= tileMask;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user