mirror of
https://github.com/pret/pokeruby.git
synced 2024-12-11 14:54:06 +00:00
Merge pull request #394 from DizzyEggg/decompile_egg_hatch
decompile egg hatch
This commit is contained in:
commit
9109469175
1630
asm/egg_hatch.s
1630
asm/egg_hatch.s
File diff suppressed because it is too large
Load Diff
1
common_syms/egg_hatch.txt
Normal file
1
common_syms/egg_hatch.txt
Normal file
@ -0,0 +1 @@
|
||||
gEggHatchData
|
122
data/egg_hatch.s
122
data/egg_hatch.s
@ -1,122 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "constants/constants.inc"
|
||||
|
||||
.section .rodata
|
||||
|
||||
EggPalette:: @ 8209AD8
|
||||
.incbin "graphics/pokemon/egg/palette.gbapal"
|
||||
|
||||
EggHatchTiles:: @ 8209AF8
|
||||
.incbin "graphics/misc/egg_hatch.4bpp"
|
||||
|
||||
EggShardTiles:: @ 820A2F8
|
||||
.incbin "graphics/misc/egg_shard.4bpp"
|
||||
|
||||
.align 2
|
||||
gOamData_820A378:: @ 820A378
|
||||
.2byte 0x0000
|
||||
.2byte 0x8000
|
||||
.2byte 0x0400
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A380:: @ 820A380
|
||||
obj_image_anim_frame 0, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A388:: @ 820A388
|
||||
obj_image_anim_frame 16, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A390:: @ 820A390
|
||||
obj_image_anim_frame 32, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A398:: @ 820A398
|
||||
obj_image_anim_frame 48, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnimTable_820A3A0:: @ 820A3A0
|
||||
.4byte gSpriteAnim_820A380
|
||||
.4byte gSpriteAnim_820A388
|
||||
.4byte gSpriteAnim_820A390
|
||||
.4byte gSpriteAnim_820A398
|
||||
|
||||
.align 2
|
||||
gUnknown_0820A3B0:: @ 820A3B0
|
||||
obj_tiles EggHatchTiles, 2048, 12345
|
||||
|
||||
.align 2
|
||||
gUnknown_0820A3B8:: @ 820A3B8
|
||||
obj_tiles EggShardTiles, 128, 23456
|
||||
|
||||
.align 2
|
||||
gUnknown_0820A3C0:: @ 820A3C0
|
||||
obj_pal EggPalette, 54321
|
||||
|
||||
.align 2
|
||||
gSpriteTemplate_820A3C8:: @ 820A3C8
|
||||
spr_template 12345, 54321, gOamData_820A378, gSpriteAnimTable_820A3A0, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy
|
||||
|
||||
.align 2
|
||||
gOamData_820A3E0:: @ 820A3E0
|
||||
.2byte 0x0000
|
||||
.2byte 0x0000
|
||||
.2byte 0x0800
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A3E8:: @ 820A3E8
|
||||
obj_image_anim_frame 0, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A3F0:: @ 820A3F0
|
||||
obj_image_anim_frame 1, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A3F8:: @ 820A3F8
|
||||
obj_image_anim_frame 2, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnim_820A400:: @ 820A400
|
||||
obj_image_anim_frame 3, 5
|
||||
obj_image_anim_end
|
||||
|
||||
.align 2
|
||||
gSpriteAnimTable_820A408:: @ 820A408
|
||||
.4byte gSpriteAnim_820A3E8
|
||||
.4byte gSpriteAnim_820A3F0
|
||||
.4byte gSpriteAnim_820A3F8
|
||||
.4byte gSpriteAnim_820A400
|
||||
|
||||
.align 2
|
||||
gSpriteTemplate_820A418:: @ 820A418
|
||||
spr_template 23456, 54321, gOamData_820A3E0, gSpriteAnimTable_820A408, NULL, gDummySpriteAffineAnimTable, SpriteCB_EggShard
|
||||
|
||||
@ The values are Q8.8 fixed-point numbers.
|
||||
.align 1
|
||||
gEggShardVelocities:: @ 820A430
|
||||
.2byte 0xFE80, 0xFC40 @ (-1.5, -3.75)
|
||||
.2byte 0xFB00, 0xFD00 @ (-5, -3)
|
||||
.2byte 0x0380, 0xFD00 @ (3.5, -3)
|
||||
.2byte 0xFC00, 0xFC40 @ (-4, -3.75)
|
||||
.2byte 0x0200, 0xFE80 @ (2, -1.5)
|
||||
.2byte 0xFF80, 0xF940 @ (-0.5, -6.75)
|
||||
.2byte 0x0500, 0xFDC0 @ (5, -2.25)
|
||||
.2byte 0xFE80, 0xFC40 @ (-1.5, -3.75)
|
||||
.2byte 0x0480, 0xFE80 @ (4.5, -1.5)
|
||||
.2byte 0xFF00, 0xF940 @ (-1, -6.75)
|
||||
.2byte 0x0400, 0xFDC0 @ (4, -2.25)
|
||||
.2byte 0xFC80, 0xFC40 @ (-3.5, -3.75)
|
||||
.2byte 0x0100, 0xFE80 @ (1, -1.5)
|
||||
.2byte 0xFC7C, 0xF940 @ (-3.515625, -6.75)
|
||||
.2byte 0x0480, 0xFDC0 @ (4.5, -2.25)
|
||||
.2byte 0xFF80, 0xF880 @ (-0.5, -7.5)
|
||||
.2byte 0x0100, 0xFB80 @ (1, -4.5)
|
||||
.2byte 0xFD80, 0xFDC0 @ (-2.5, -2.25)
|
||||
.2byte 0x0280, 0xF880 @ (2.5, -7.5)
|
@ -10,7 +10,7 @@ void LoadCompressedObjectPicOverrideBuffer(const struct CompressedSpriteSheet *a
|
||||
void LoadCompressedObjectPalette(const struct CompressedSpritePalette *a);
|
||||
void LoadCompressedObjectPaletteOverrideBuffer(const struct CompressedSpritePalette *a, void *buffer);
|
||||
void DecompressPicFromTable_2(const struct CompressedSpriteSheet *a, u8 b, u8 c, void *d, void *e, s32 f);
|
||||
void HandleLoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 g);
|
||||
void HandleLoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 pid);
|
||||
void LoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 g, u32 h);
|
||||
void Unused_LZDecompressWramIndirect(const void **src, void *dest);
|
||||
|
||||
|
@ -204,14 +204,14 @@ struct Sprite
|
||||
/*0x3A*/ s16 data6;
|
||||
/*0x3C*/ s16 data7;
|
||||
|
||||
/*0x3E*/ u16 inUse:1;
|
||||
u16 coordOffsetEnabled:1;
|
||||
u16 invisible:1;
|
||||
u16 flags_3:1;
|
||||
u16 flags_4:1;
|
||||
u16 flags_5:1;
|
||||
u16 flags_6:1;
|
||||
u16 flags_7:1;
|
||||
/*0x3E*/ u16 inUse:1; //1
|
||||
u16 coordOffsetEnabled:1; //2
|
||||
u16 invisible:1; //4
|
||||
u16 flags_3:1; //8
|
||||
u16 flags_4:1; //0x10
|
||||
u16 flags_5:1; //0x20
|
||||
u16 flags_6:1; //0x40
|
||||
u16 flags_7:1; //0x80
|
||||
/*0x3F*/ u16 hFlip:1;
|
||||
u16 vFlip:1;
|
||||
u16 animBeginning:1;
|
||||
|
@ -74,7 +74,6 @@ SECTIONS {
|
||||
src/daycare.o(.text);
|
||||
asm/daycare.o(.text);
|
||||
src/egg_hatch.o(.text);
|
||||
asm/egg_hatch.o(.text);
|
||||
src/battle_interface.o(.text);
|
||||
src/smokescreen.o(.text);
|
||||
src/pokeball.o(.text);
|
||||
@ -338,7 +337,7 @@ SECTIONS {
|
||||
src/trig.o(.rodata);
|
||||
src/util.o(.rodata);
|
||||
data/daycare.o(.rodata);
|
||||
data/egg_hatch.o(.rodata);
|
||||
src/egg_hatch.o(.rodata);
|
||||
data/battle_interface.o(.rodata);
|
||||
src/pokeball.o(.rodata);
|
||||
data/trade.o(.rodata);
|
||||
|
814
src/egg_hatch.c
814
src/egg_hatch.c
@ -1,7 +1,226 @@
|
||||
#include "global.h"
|
||||
#include "pokemon.h"
|
||||
#include "items.h"
|
||||
#include "decompress.h"
|
||||
#include "data2.h"
|
||||
#include "task.h"
|
||||
#include "script.h"
|
||||
#include "palette.h"
|
||||
#include "rom4.h"
|
||||
#include "main.h"
|
||||
#include "event_data.h"
|
||||
#include "sound.h"
|
||||
#include "songs.h"
|
||||
#include "text.h"
|
||||
#include "text_window.h"
|
||||
#include "string_util.h"
|
||||
#include "strings2.h"
|
||||
#include "menu.h"
|
||||
#include "naming_screen.h"
|
||||
#include "trig.h"
|
||||
#include "rng.h"
|
||||
|
||||
void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) {
|
||||
extern u8 ewram[];
|
||||
extern struct SpriteTemplate gUnknown_02024E8C;
|
||||
|
||||
struct EggHatchData
|
||||
{
|
||||
u8 eggSpriteID;
|
||||
u8 pokeSpriteID;
|
||||
u8 CB2_state;
|
||||
u8 CB2_PalCounter;
|
||||
u8 eggPartyID;
|
||||
struct Window window;
|
||||
u8 tileDataStartOffset;
|
||||
u8 unused_39;
|
||||
u8 eggShardVelocityID;
|
||||
};
|
||||
|
||||
struct EggHatchData* gEggHatchData;
|
||||
|
||||
extern const u32 gUnknown_08D00000[];
|
||||
extern const u32 gUnknown_08D00524[];
|
||||
extern const u32 gUnknown_0820CA98[];
|
||||
extern const u32 gUnknown_0820F798[];
|
||||
extern const u16 gUnknown_08D004E0[]; //palette
|
||||
extern const u16 gUnknown_0820C9F8[]; //palette
|
||||
extern const struct SpriteSheet sUnknown_0820A3B0;
|
||||
extern const struct SpriteSheet sUnknown_0820A3B8;
|
||||
extern const struct SpritePalette sUnknown_0820A3C0;
|
||||
|
||||
bool8 GetNationalPokedexFlag(u16 nationalNum, u8 caseID);
|
||||
u8* GetMonNick(struct Pokemon* mon, u8* dst);
|
||||
u8 sav1_map_get_name(void);
|
||||
const struct CompressedSpritePalette* sub_8040990(struct Pokemon* mon); //gets pokemon palette address
|
||||
void sub_8080990(void);
|
||||
|
||||
static void Task_EggHatch(u8 taskID);
|
||||
static void CB2_EggHatch_0(void);
|
||||
static void CB2_EggHatch_1(void);
|
||||
static void SpriteCB_Egg_0(struct Sprite* sprite);
|
||||
static void SpriteCB_Egg_1(struct Sprite* sprite);
|
||||
static void SpriteCB_Egg_2(struct Sprite* sprite);
|
||||
static void SpriteCB_Egg_3(struct Sprite* sprite);
|
||||
static void SpriteCB_Egg_4(struct Sprite* sprite);
|
||||
static void SpriteCB_Egg_5(struct Sprite* sprite);
|
||||
static void SpriteCB_EggShard(struct Sprite* sprite);
|
||||
static void EggHatchPrintMessage2(u8* src);
|
||||
static void EggHatchPrintMessage1(u8* src);
|
||||
static bool8 EggHatchUpdateWindowText(void);
|
||||
static void CreateRandomEggShardSprite(void);
|
||||
static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex);
|
||||
|
||||
// graphics
|
||||
|
||||
static const u16 sEggPalette[] = INCBIN_U16("graphics/pokemon/egg/palette.gbapal");
|
||||
static const u8 sEggHatchTiles[] = INCBIN_U8("graphics/misc/egg_hatch.4bpp");
|
||||
static const u8 sEggShardTiles[] = INCBIN_U8("graphics/misc/egg_shard.4bpp");
|
||||
|
||||
static const struct OamData sOamData_820A378 =
|
||||
{
|
||||
.y = 0,
|
||||
.affineMode = 0,
|
||||
.objMode = 0,
|
||||
.mosaic = 0,
|
||||
.bpp = 0,
|
||||
.shape = 0,
|
||||
.x = 0,
|
||||
.matrixNum = 0,
|
||||
.size = 2,
|
||||
.tileNum = 0,
|
||||
.priority = 1,
|
||||
.paletteNum = 0,
|
||||
.affineParam = 0,
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A380[] =
|
||||
{
|
||||
ANIMCMD_FRAME(0, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A388[] =
|
||||
{
|
||||
ANIMCMD_FRAME(16, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A390[] =
|
||||
{
|
||||
ANIMCMD_FRAME(32, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A398[] =
|
||||
{
|
||||
ANIMCMD_FRAME(48, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd *const sSpriteAnimTable_820A3A0[] =
|
||||
{
|
||||
sSpriteAnim_820A380,
|
||||
sSpriteAnim_820A388,
|
||||
sSpriteAnim_820A390,
|
||||
sSpriteAnim_820A398,
|
||||
};
|
||||
|
||||
static const struct SpriteSheet sUnknown_0820A3B0 =
|
||||
{
|
||||
.data = sEggHatchTiles,
|
||||
.size = 2048,
|
||||
.tag = 12345,
|
||||
};
|
||||
|
||||
static const struct SpriteSheet sUnknown_0820A3B8 =
|
||||
{
|
||||
.data = sEggShardTiles,
|
||||
.size = 128,
|
||||
.tag = 23456,
|
||||
};
|
||||
|
||||
static const struct SpritePalette sUnknown_0820A3C0 =
|
||||
{
|
||||
.data = sEggPalette,
|
||||
.tag = 54321
|
||||
};
|
||||
|
||||
static const struct SpriteTemplate sSpriteTemplate_820A3C8 =
|
||||
{
|
||||
.tileTag = 12345,
|
||||
.paletteTag = 54321,
|
||||
.oam = &sOamData_820A378,
|
||||
.anims = sSpriteAnimTable_820A3A0,
|
||||
.images = NULL,
|
||||
.affineAnims = gDummySpriteAffineAnimTable,
|
||||
.callback = SpriteCallbackDummy
|
||||
};
|
||||
|
||||
|
||||
static const struct OamData sOamData_820A3E0 =
|
||||
{
|
||||
.y = 0,
|
||||
.affineMode = 0,
|
||||
.objMode = 0,
|
||||
.mosaic = 0,
|
||||
.bpp = 0,
|
||||
.shape = 0,
|
||||
.x = 0,
|
||||
.matrixNum = 0,
|
||||
.size = 0,
|
||||
.tileNum = 0,
|
||||
.priority = 2,
|
||||
.paletteNum = 0,
|
||||
.affineParam = 0,
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A3E8[] =
|
||||
{
|
||||
ANIMCMD_FRAME(0, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A3F0[] =
|
||||
{
|
||||
ANIMCMD_FRAME(1, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A3F8[] =
|
||||
{
|
||||
ANIMCMD_FRAME(2, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd sSpriteAnim_820A400[] =
|
||||
{
|
||||
ANIMCMD_FRAME(3, 5),
|
||||
ANIMCMD_END
|
||||
};
|
||||
|
||||
static const union AnimCmd *const sSpriteAnimTable_820A408[] =
|
||||
{
|
||||
sSpriteAnim_820A3E8,
|
||||
sSpriteAnim_820A3F0,
|
||||
sSpriteAnim_820A3F8,
|
||||
sSpriteAnim_820A400,
|
||||
};
|
||||
|
||||
static const struct SpriteTemplate sSpriteTemplate_820A418 =
|
||||
{
|
||||
.tileTag = 23456,
|
||||
.paletteTag = 54321,
|
||||
.oam = &sOamData_820A3E0,
|
||||
.anims = sSpriteAnimTable_820A408,
|
||||
.images = NULL,
|
||||
.affineAnims = gDummySpriteAffineAnimTable,
|
||||
.callback = SpriteCB_EggShard
|
||||
};
|
||||
|
||||
// actual code
|
||||
|
||||
static void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp)
|
||||
{
|
||||
u16 species;
|
||||
u32 personality, pokerus;
|
||||
u8 i, friendship, language, gameMet, markings;
|
||||
@ -50,3 +269,596 @@ void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) {
|
||||
|
||||
*egg = *temp;
|
||||
}
|
||||
|
||||
static void AddHatchedMonToParty(u8 id)
|
||||
{
|
||||
u8 isEgg;
|
||||
u16 pokeNum;
|
||||
u8 name[12];
|
||||
u16 ball;
|
||||
u16 caughtLvl;
|
||||
u8 mapNameID;
|
||||
struct Pokemon* mon = &gPlayerParty[id];
|
||||
|
||||
CreatedHatchedMon(mon, &gEnemyParty[0]);
|
||||
isEgg = 0;
|
||||
SetMonData(mon, MON_DATA_IS_EGG, &isEgg);
|
||||
|
||||
pokeNum = GetMonData(mon, MON_DATA_SPECIES);
|
||||
GetSpeciesName(name, pokeNum);
|
||||
SetMonData(mon, MON_DATA_NICKNAME, name);
|
||||
|
||||
pokeNum = SpeciesToNationalPokedexNum(pokeNum);
|
||||
GetNationalPokedexFlag(pokeNum, 2);
|
||||
GetNationalPokedexFlag(pokeNum, 3);
|
||||
|
||||
GetMonNick(mon, gStringVar1);
|
||||
|
||||
ball = ITEM_POKE_BALL;
|
||||
SetMonData(mon, MON_DATA_POKEBALL, (const u8*) &ball);
|
||||
|
||||
caughtLvl = 0;
|
||||
SetMonData(mon, MON_DATA_MET_LEVEL, (const u8*) &caughtLvl);
|
||||
|
||||
mapNameID = sav1_map_get_name();
|
||||
SetMonData(mon, MON_DATA_MET_LOCATION, &mapNameID);
|
||||
|
||||
MonRestorePP(mon);
|
||||
CalculateMonStats(mon);
|
||||
}
|
||||
|
||||
void ScriptHatchMon(void)
|
||||
{
|
||||
AddHatchedMonToParty(gSpecialVar_0x8004);
|
||||
}
|
||||
|
||||
#ifdef NONMATCHING
|
||||
static bool8 sub_8042ABC(void* a, u8 b)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
__attribute__((naked))
|
||||
static bool8 sub_8042ABC(void* a, u8 b)
|
||||
{
|
||||
asm(".syntax unified\n\
|
||||
push {r4-r6,lr}\n\
|
||||
sub sp, 0x20\n\
|
||||
adds r5, r0, 0\n\
|
||||
lsls r4, r1, 24\n\
|
||||
lsrs r4, 24\n\
|
||||
lsls r0, r4, 2\n\
|
||||
adds r0, r4\n\
|
||||
lsls r0, 4\n\
|
||||
adds r0, r5, r0\n\
|
||||
mov r1, sp\n\
|
||||
bl GetBoxMonNick\n\
|
||||
lsls r0, r4, 3\n\
|
||||
subs r0, r4\n\
|
||||
lsls r1, r0, 3\n\
|
||||
adds r0, r5, r1\n\
|
||||
adds r0, 0xC0\n\
|
||||
ldrh r0, [r0]\n\
|
||||
cmp r0, 0\n\
|
||||
beq _08042B40\n\
|
||||
adds r0, r1, 0\n\
|
||||
adds r0, 0xA0\n\
|
||||
adds r5, r0\n\
|
||||
adds r6, r5, 0\n\
|
||||
adds r6, 0x2C\n\
|
||||
mov r0, sp\n\
|
||||
adds r1, r6, 0\n\
|
||||
bl StringCompareWithoutExtCtrlCodes\n\
|
||||
cmp r0, 0\n\
|
||||
bne _08042B08\n\
|
||||
ldr r0, _08042B30 @ =gSaveBlock2\n\
|
||||
adds r1, r5, 0\n\
|
||||
adds r1, 0x24\n\
|
||||
bl StringCompareWithoutExtCtrlCodes\n\
|
||||
cmp r0, 0\n\
|
||||
beq _08042B40\n\
|
||||
_08042B08:\n\
|
||||
ldr r0, _08042B34 @ =gStringVar1\n\
|
||||
mov r1, sp\n\
|
||||
bl StringCopy\n\
|
||||
ldr r4, _08042B38 @ =gStringVar2\n\
|
||||
adds r1, r5, 0\n\
|
||||
adds r1, 0x24\n\
|
||||
adds r0, r4, 0\n\
|
||||
bl StringCopy\n\
|
||||
ldr r0, _08042B3C @ =gStringVar3\n\
|
||||
adds r1, r6, 0\n\
|
||||
bl StringCopy\n\
|
||||
adds r0, r4, 0\n\
|
||||
bl SanitizeNameString\n\
|
||||
movs r0, 0x1\n\
|
||||
b _08042B42\n\
|
||||
.align 2, 0\n\
|
||||
_08042B30: .4byte gSaveBlock2\n\
|
||||
_08042B34: .4byte gStringVar1\n\
|
||||
_08042B38: .4byte gStringVar2\n\
|
||||
_08042B3C: .4byte gStringVar3\n\
|
||||
_08042B40:\n\
|
||||
movs r0, 0\n\
|
||||
_08042B42:\n\
|
||||
add sp, 0x20\n\
|
||||
pop {r4-r6}\n\
|
||||
pop {r1}\n\
|
||||
bx r1\n\
|
||||
.syntax divided");
|
||||
}
|
||||
|
||||
#endif // NONMATCHING
|
||||
|
||||
bool8 sub_8042B4C(void)
|
||||
{
|
||||
return sub_8042ABC(&gSaveBlock1.daycareData, gSpecialVar_0x8004);
|
||||
}
|
||||
|
||||
static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID)
|
||||
{
|
||||
u8 r5 = 0;
|
||||
u8 spriteID = 0;
|
||||
struct Pokemon* mon = NULL;
|
||||
|
||||
if (a0 == 0)
|
||||
{
|
||||
mon = &gPlayerParty[pokeID];
|
||||
r5 = 1;
|
||||
}
|
||||
if (a0 == 1)
|
||||
{
|
||||
mon = &gPlayerParty[pokeID];
|
||||
r5 = 3;
|
||||
}
|
||||
switch (switchID)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
u16 species = GetMonData(mon, MON_DATA_SPECIES);
|
||||
u32 pid = GetMonData(mon, MON_DATA_PERSONALITY);
|
||||
HandleLoadSpecialPokePic(&gMonFrontPicTable[species], gMonFrontPicCoords[species].coords, gMonFrontPicCoords[species].y_offset,(u32)(&ewram[0]), gUnknown_081FAF4C[2 * a0 + 1], species, pid);
|
||||
LoadCompressedObjectPalette(sub_8040990(mon));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
GetMonSpriteTemplate_803C56C(sub_8040990(mon)->tag, r5);
|
||||
spriteID = CreateSprite(&gUnknown_02024E8C, 120, 70, 6);
|
||||
gSprites[spriteID].invisible = 1;
|
||||
gSprites[spriteID].callback = SpriteCallbackDummy;
|
||||
break;
|
||||
}
|
||||
return spriteID;
|
||||
}
|
||||
|
||||
static void VBlankCB_EggHatch(void)
|
||||
{
|
||||
LoadOam();
|
||||
ProcessSpriteCopyRequests();
|
||||
TransferPlttBuffer();
|
||||
}
|
||||
|
||||
void EggHatch(void)
|
||||
{
|
||||
ScriptContext2_Enable();
|
||||
CreateTask(Task_EggHatch, 10);
|
||||
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
|
||||
}
|
||||
|
||||
static void Task_EggHatch(u8 taskID)
|
||||
{
|
||||
if (!gPaletteFade.active)
|
||||
{
|
||||
SetMainCallback2(CB2_EggHatch_0);
|
||||
gFieldCallback = sub_8080990;
|
||||
DestroyTask(taskID);
|
||||
}
|
||||
}
|
||||
|
||||
static void CB2_EggHatch_0(void)
|
||||
{
|
||||
switch (gMain.state)
|
||||
{
|
||||
case 0:
|
||||
REG_DISPCNT = 0;
|
||||
gEggHatchData = (struct EggHatchData*)(&ewram[0x18000]);
|
||||
gEggHatchData->eggPartyID = gSpecialVar_0x8004;
|
||||
gEggHatchData->eggShardVelocityID = 0;
|
||||
ResetTasks();
|
||||
ResetSpriteData();
|
||||
FreeAllSpritePalettes();
|
||||
SetVBlankCallback(VBlankCB_EggHatch);
|
||||
gMain.state++;
|
||||
gSpecialVar_0x8005 = GetCurrentMapMusic();
|
||||
break;
|
||||
case 1:
|
||||
SetUpWindowConfig(&gWindowConfig_81E6F84);
|
||||
InitWindowFromConfig(&gEggHatchData->window, &gWindowConfig_81E6F84);
|
||||
gEggHatchData->tileDataStartOffset = SetTextWindowBaseTileNum(20);
|
||||
LoadTextWindowGraphics(&gEggHatchData->window);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 2:
|
||||
LZDecompressVram(&gUnknown_08D00000, (void*)(VRAM));
|
||||
CpuSet(&gUnknown_08D00524, &ewram[0], 0x800);
|
||||
DmaCopy16(3, &ewram[0], (void*)(VRAM + 0x2800), 0x500);
|
||||
LoadCompressedPalette(&gUnknown_08D004E0, 0, 0x20);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 3:
|
||||
LoadSpriteSheet(&sUnknown_0820A3B0);
|
||||
LoadSpriteSheet(&sUnknown_0820A3B8);
|
||||
LoadSpritePalette(&sUnknown_0820A3C0);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 4:
|
||||
gEggHatchData->eggSpriteID = CreateSprite(&sSpriteTemplate_820A3C8, 0x78, 0x4B, 5);
|
||||
AddHatchedMonToParty(gEggHatchData->eggPartyID);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 5:
|
||||
EggHatchCreateMonSprite(0, 0, gEggHatchData->eggPartyID);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 6:
|
||||
gEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, gEggHatchData->eggPartyID);
|
||||
gMain.state++;
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
u32 offsetRead, offsetWrite;
|
||||
u32 offsetRead2, offsetWrite2;
|
||||
u32 size;
|
||||
|
||||
REG_BG2CNT = 0x4C06;
|
||||
LoadPalette(&gUnknown_0820C9F8, 0x10, 0xA0);
|
||||
|
||||
offsetRead = (u32)(&gUnknown_0820CA98);
|
||||
offsetWrite = (VRAM + 0x4000);
|
||||
size = 0x1300;
|
||||
while (TRUE)
|
||||
{
|
||||
DmaCopy16(3, offsetRead, (void *) (offsetWrite), 0x1000);
|
||||
offsetRead += 0x1000;
|
||||
offsetWrite += 0x1000;
|
||||
size -= 0x1000;
|
||||
if (size <= 0x1000)
|
||||
{
|
||||
DmaCopy16(3, offsetRead, (void *) (offsetWrite), size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
offsetRead2 = (u32)(&gUnknown_0820F798);
|
||||
offsetWrite2 = (u32)(VRAM + 0x6000);
|
||||
DmaCopy16(3, offsetRead2, (void*)(offsetWrite2), 0x1000);
|
||||
gMain.state++;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
REG_BG1CNT = 0x501;
|
||||
|
||||
REG_BG0HOFS = 0;
|
||||
REG_BG0VOFS = 0;
|
||||
|
||||
REG_BG1HOFS = 0;
|
||||
REG_BG1VOFS = 0;
|
||||
|
||||
REG_BG2HOFS = 0;
|
||||
REG_BG2VOFS = 0;
|
||||
|
||||
SetMainCallback2(CB2_EggHatch_1);
|
||||
gEggHatchData->CB2_state = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void EggHatchSetMonNickname(void)
|
||||
{
|
||||
SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar3);
|
||||
SetMainCallback2(c2_exit_to_overworld_2_switch);
|
||||
}
|
||||
|
||||
static void Task_EggHatchPlayBGM(u8 taskID)
|
||||
{
|
||||
if (gTasks[taskID].data[0] == 0)
|
||||
StopMapMusic();
|
||||
if (gTasks[taskID].data[0] == 1)
|
||||
PlayBGM(376);
|
||||
if (gTasks[taskID].data[0] > 60)
|
||||
{
|
||||
PlayBGM(377);
|
||||
DestroyTask(taskID);
|
||||
//return; task is destroyed, yet you increment the value?
|
||||
}
|
||||
gTasks[taskID].data[0]++;
|
||||
}
|
||||
|
||||
static void CB2_EggHatch_1(void)
|
||||
{
|
||||
switch (gEggHatchData->CB2_state)
|
||||
{
|
||||
case 0:
|
||||
BeginNormalPaletteFade(-1, 0, 0x10, 0, 0);
|
||||
REG_DISPCNT = 0x1740;
|
||||
gEggHatchData->CB2_state++;
|
||||
CreateTask(Task_EggHatchPlayBGM, 5);
|
||||
break;
|
||||
case 1:
|
||||
if (!gPaletteFade.active)
|
||||
{
|
||||
gEggHatchData->CB2_PalCounter = 0;
|
||||
gEggHatchData->CB2_state++;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (++gEggHatchData->CB2_PalCounter > 30)
|
||||
{
|
||||
gEggHatchData->CB2_state++;
|
||||
gSprites[gEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (gSprites[gEggHatchData->eggSpriteID].callback == SpriteCallbackDummy)
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 4:
|
||||
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1);
|
||||
StringExpandPlaceholders(gStringVar4, gOtherText_HatchedFromEgg);
|
||||
EggHatchPrintMessage2(gStringVar4);
|
||||
PlayFanfare(371);
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 5:
|
||||
if (IsFanfareTaskInactive())
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 6:
|
||||
if (IsFanfareTaskInactive())
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 7:
|
||||
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1);
|
||||
StringExpandPlaceholders(gStringVar4, gOtherText_NickHatchPrompt);
|
||||
EggHatchPrintMessage1(gStringVar4);
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 8:
|
||||
if (EggHatchUpdateWindowText())
|
||||
{
|
||||
MenuDrawTextWindow(22, 8, 27, 13);
|
||||
InitYesNoMenu(22, 8, 4);
|
||||
gEggHatchData->CB2_state++;
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
s8 menuInput;
|
||||
if ((menuInput = ProcessMenuInputNoWrap_()) != -2)
|
||||
{
|
||||
if (menuInput != -1 && menuInput != 1)
|
||||
{
|
||||
u16 species;
|
||||
u8 gender;
|
||||
u32 personality;
|
||||
|
||||
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar3);
|
||||
species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES);
|
||||
gender = GetMonGender(&gPlayerParty[gEggHatchData->eggPartyID]);
|
||||
personality = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0);
|
||||
DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname);
|
||||
}
|
||||
else
|
||||
gEggHatchData->CB2_state++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
|
||||
gEggHatchData->CB2_state++;
|
||||
break;
|
||||
case 11:
|
||||
if (!gPaletteFade.active)
|
||||
SetMainCallback2(c2_exit_to_overworld_2_switch);
|
||||
break;
|
||||
}
|
||||
RunTasks();
|
||||
AnimateSprites();
|
||||
BuildOamBuffer();
|
||||
UpdatePaletteFade();
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_0(struct Sprite* sprite)
|
||||
{
|
||||
if (++sprite->data0 > 20)
|
||||
{
|
||||
sprite->callback = SpriteCB_Egg_1;
|
||||
sprite->data0 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->data1 = (sprite->data1 + 20) & 0xFF;
|
||||
sprite->pos2.x = Sin(sprite->data1, 1);
|
||||
if (sprite->data0 == 15)
|
||||
{
|
||||
PlaySE(SE_BOWA);
|
||||
StartSpriteAnim(sprite, 1);
|
||||
CreateRandomEggShardSprite();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_1(struct Sprite* sprite)
|
||||
{
|
||||
if (++sprite->data2 > 30)
|
||||
{
|
||||
if (++sprite->data0 > 20)
|
||||
{
|
||||
sprite->callback = SpriteCB_Egg_2;
|
||||
sprite->data0 = 0;
|
||||
sprite->data2 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->data1 = (sprite->data1 + 20) & 0xFF;
|
||||
sprite->pos2.x = Sin(sprite->data1, 2);
|
||||
if (sprite->data0 == 15)
|
||||
{
|
||||
PlaySE(SE_BOWA);
|
||||
StartSpriteAnim(sprite, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_2(struct Sprite* sprite)
|
||||
{
|
||||
if (++sprite->data2 > 30)
|
||||
{
|
||||
if (++sprite->data0 > 38)
|
||||
{
|
||||
u16 species;
|
||||
|
||||
sprite->callback = SpriteCB_Egg_3;
|
||||
sprite->data0 = 0;
|
||||
species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES);
|
||||
gSprites[gEggHatchData->pokeSpriteID].pos2.x = 0;
|
||||
gSprites[gEggHatchData->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->data1 = (sprite->data1 + 20) & 0xFF;
|
||||
sprite->pos2.x = Sin(sprite->data1, 2);
|
||||
if (sprite->data0 == 15)
|
||||
{
|
||||
PlaySE(SE_BOWA);
|
||||
StartSpriteAnim(sprite, 2);
|
||||
CreateRandomEggShardSprite();
|
||||
CreateRandomEggShardSprite();
|
||||
}
|
||||
if (sprite->data0 == 30)
|
||||
PlaySE(SE_BOWA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_3(struct Sprite* sprite)
|
||||
{
|
||||
if (++sprite->data0 > 50)
|
||||
{
|
||||
sprite->callback = SpriteCB_Egg_4;
|
||||
sprite->data0 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_4(struct Sprite* sprite)
|
||||
{
|
||||
s16 i;
|
||||
if (sprite->data0 == 0)
|
||||
BeginNormalPaletteFade(-1, -1, 0, 0x10, 0xFFFF);
|
||||
if (sprite->data0 < 4u)
|
||||
{
|
||||
for (i = 0; i <= 3; i++)
|
||||
CreateRandomEggShardSprite();
|
||||
}
|
||||
sprite->data0++;
|
||||
if (!gPaletteFade.active)
|
||||
{
|
||||
PlaySE(SE_TAMAGO);
|
||||
sprite->invisible = 1;
|
||||
sprite->callback = SpriteCB_Egg_5;
|
||||
sprite->data0 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteCB_Egg_5(struct Sprite* sprite)
|
||||
{
|
||||
if (sprite->data0 == 0)
|
||||
{
|
||||
gSprites[gEggHatchData->pokeSpriteID].invisible = 0;
|
||||
StartSpriteAffineAnim(&gSprites[gEggHatchData->pokeSpriteID], 1);
|
||||
}
|
||||
if (sprite->data0 == 8)
|
||||
BeginNormalPaletteFade(-1, -1, 0x10, 0, 0xFFFF);
|
||||
if (sprite->data0 <= 9)
|
||||
gSprites[gEggHatchData->pokeSpriteID].pos1.y -= 1;
|
||||
if (sprite->data0 > 40)
|
||||
sprite->callback = SpriteCallbackDummy;
|
||||
sprite->data0++;
|
||||
}
|
||||
|
||||
static void SpriteCB_EggShard(struct Sprite* sprite)
|
||||
{
|
||||
sprite->data4 += sprite->data1;
|
||||
sprite->data5 += sprite->data2;
|
||||
|
||||
sprite->pos2.x = sprite->data4 / 256;
|
||||
sprite->pos2.y = sprite->data5 / 256;
|
||||
|
||||
sprite->data2 += sprite->data3;
|
||||
|
||||
if (sprite->pos1.y + sprite->pos2.y > sprite->pos1.y + 20 && sprite->data2 > 0)
|
||||
DestroySprite(sprite);
|
||||
}
|
||||
|
||||
// Converts a number to Q8.8 fixed-point format
|
||||
#define Q_8_8(n) ((s16)((n) * 256))
|
||||
|
||||
static const s16 sEggShardVelocities[][2] =
|
||||
{
|
||||
{Q_8_8(-1.5), Q_8_8(-3.75)},
|
||||
{Q_8_8(-5), Q_8_8(-3)},
|
||||
{Q_8_8(3.5), Q_8_8(-3)},
|
||||
{Q_8_8(-4), Q_8_8(-3.75)},
|
||||
{Q_8_8(2), Q_8_8(-1.5)},
|
||||
{Q_8_8(-0.5), Q_8_8(-6.75)},
|
||||
{Q_8_8(5), Q_8_8(-2.25)},
|
||||
{Q_8_8(-1.5), Q_8_8(-3.75)},
|
||||
{Q_8_8(4.5), Q_8_8(-1.5)},
|
||||
{Q_8_8(-1), Q_8_8(-6.75)},
|
||||
{Q_8_8(4), Q_8_8(-2.25)},
|
||||
{Q_8_8(-3.5), Q_8_8(-3.75)},
|
||||
{Q_8_8(1), Q_8_8(-1.5)},
|
||||
{Q_8_8(-3.515625), Q_8_8(-6.75)},
|
||||
{Q_8_8(4.5), Q_8_8(-2.25)},
|
||||
{Q_8_8(-0.5), Q_8_8(-7.5)},
|
||||
{Q_8_8(1), Q_8_8(-4.5)},
|
||||
{Q_8_8(-2.5), Q_8_8(-2.25)},
|
||||
{Q_8_8(2.5), Q_8_8(-7.5)},
|
||||
};
|
||||
|
||||
static void CreateRandomEggShardSprite(void)
|
||||
{
|
||||
u16 spriteAnimIndex;
|
||||
|
||||
s16 velocity1 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][0];
|
||||
s16 velocity2 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][1];
|
||||
gEggHatchData->eggShardVelocityID++;
|
||||
spriteAnimIndex = Random() % 4;
|
||||
CreateEggShardSprite(120, 60, velocity1, velocity2, 100, spriteAnimIndex);
|
||||
}
|
||||
|
||||
static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex)
|
||||
{
|
||||
u8 spriteID = CreateSprite(&sSpriteTemplate_820A418, x, y, 4);
|
||||
gSprites[spriteID].data1 = data1;
|
||||
gSprites[spriteID].data2 = data2;
|
||||
gSprites[spriteID].data3 = data3;
|
||||
StartSpriteAnim(&gSprites[spriteID], spriteAnimIndex);
|
||||
}
|
||||
|
||||
static void EggHatchPrintMessage1(u8* src)
|
||||
{
|
||||
sub_8002EB0(&gEggHatchData->window, src, gEggHatchData->tileDataStartOffset, 3, 15);
|
||||
}
|
||||
|
||||
static void EggHatchPrintMessage2(u8* src)
|
||||
{
|
||||
sub_8003460(&gEggHatchData->window, src, gEggHatchData->tileDataStartOffset, 3, 15);
|
||||
}
|
||||
|
||||
static bool8 EggHatchUpdateWindowText(void)
|
||||
{
|
||||
return sub_80035AC(&gEggHatchData->window);
|
||||
}
|
||||
|
@ -106,13 +106,7 @@ gUnknown_0300434C: @ 300434C
|
||||
|
||||
.include "pokemon_1.o"
|
||||
.include "rng.o"
|
||||
|
||||
@ egg_hatch
|
||||
|
||||
.align 2
|
||||
gUnknown_0300481C: @ 300481C
|
||||
.space 0x4
|
||||
|
||||
.include "egg_hatch.o"
|
||||
.include "load_save.o"
|
||||
|
||||
@ trade
|
||||
|
Loading…
Reference in New Issue
Block a user