pokeemerald/src/battle_dome_cards.c

350 lines
9.4 KiB
C
Raw Normal View History

2017-09-19 01:39:20 +02:00
// Includes
#include "global.h"
2017-09-19 02:00:46 +02:00
#include "sprite.h"
2017-09-19 14:22:43 +02:00
#include "window.h"
2017-09-19 04:23:13 +02:00
#include "malloc.h"
2017-09-19 02:00:46 +02:00
#include "species.h"
2017-09-19 03:26:11 +02:00
#include "palette.h"
2017-09-19 02:00:46 +02:00
#include "decompress.h"
extern const struct CompressedSpriteSheet gMonFrontPicTable[NUM_SPECIES];
extern const struct CompressedSpriteSheet gMonBackPicTable[NUM_SPECIES];
extern const struct CompressedSpriteSheet gTrainerFrontPicTable[];
extern const struct CompressedSpriteSheet gTrainerBackPicTable[];
2017-09-19 03:26:11 +02:00
extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[];
extern const union AffineAnimCmd *const gUnknown_082FF618[];
extern const union AffineAnimCmd *const gUnknown_082FF694[];
2017-09-19 03:31:28 +02:00
extern const union AnimCmd *const gUnknown_082FF70C[];
extern const union AnimCmd *const *const gUnknown_08309AAC[NUM_SPECIES];
2017-09-19 03:31:28 +02:00
extern const union AnimCmd *const *const gUnknown_0830536C[];
2017-09-19 04:23:13 +02:00
extern const struct OamData gUnknown_0860B064;
2017-09-19 04:41:54 +02:00
extern const struct OamData gUnknown_0860B06C;
2017-09-19 01:39:20 +02:00
// Static type declarations
struct BattleDomeCard {
2017-09-19 04:23:13 +02:00
u8 *frames;
2017-09-19 14:13:53 +02:00
struct SpriteFrameImage *images;
2017-09-19 04:23:13 +02:00
u16 paletteTag;
u8 spriteId;
u8 active;
2017-09-19 01:39:20 +02:00
};
// Static RAM declarations
static EWRAM_DATA struct SpriteTemplate gUnknown_0203CCEC = {};
EWRAM_DATA struct BattleDomeCard gUnknown_0203CD04[8] = {};
2017-09-19 01:39:20 +02:00
// Static ROM declarations
// .rodata
extern const struct BattleDomeCard gUnknown_0860B058;
// .text
2017-09-19 02:00:46 +02:00
void nullsub_122(struct Sprite *sprite)
2017-09-19 01:39:20 +02:00
{
}
2017-09-19 03:26:11 +02:00
bool16 dp13_810BB8C(void)
2017-09-19 01:39:20 +02:00
{
int i;
for (i = 0; i < 8; i ++)
{
gUnknown_0203CD04[i] = gUnknown_0860B058;
}
return FALSE;
}
2017-09-19 02:00:46 +02:00
2017-09-19 03:26:11 +02:00
bool16 load_pokemon_image_TODO(u16 species, u32 personality, bool8 isFrontPic, void *dest, bool8 isTrainer, bool8 ignoreDeoxys)
2017-09-19 02:00:46 +02:00
{
if (!isTrainer)
{
if (isFrontPic)
{
if (!ignoreDeoxys)
{
LoadSpecialPokePic(&gMonFrontPicTable[species], dest, species, personality, isFrontPic);
}
else
{
LoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], dest, species, personality, isFrontPic);
}
}
else
{
if (!ignoreDeoxys)
{
LoadSpecialPokePic(&gMonBackPicTable[species], dest, species, personality, isFrontPic);
}
else
{
LoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], dest, species, personality, isFrontPic);
}
}
}
else
{
if (isFrontPic)
{
DecompressPicFromTable(&gTrainerFrontPicTable[species], dest, species);
}
else
{
DecompressPicFromTable(&gTrainerBackPicTable[species], dest, species);
}
}
return FALSE;
}
2017-09-19 03:26:11 +02:00
bool16 sub_818D09C(u16 species, u32 personality, bool8 isFrontPic, void *dest, bool8 isTrainer)
{
return load_pokemon_image_TODO(species, personality, isFrontPic, dest, isTrainer, FALSE);
}
void sub_818D0C4(u16 species, u32 otId, u32 personality, u8 paletteSlot, u16 paletteTag, bool8 isTrainer)
{
if (!isTrainer)
{
if (paletteTag == 0xFFFF)
{
gUnknown_0203CCEC.paletteTag |= 0xFFFF;
LoadCompressedPalette(species_and_otid_get_pal(species, otId, personality), 0x100 + paletteSlot * 0x10, 0x20);
}
else
{
gUnknown_0203CCEC.paletteTag = paletteTag;
LoadCompressedObjectPalette(sub_806E7CC(species, otId, personality));
}
}
else
{
if (paletteTag == 0xFFFF)
{
gUnknown_0203CCEC.paletteTag |= 0xFFFF;
LoadCompressedPalette(gTrainerFrontPicPaletteTable[species].data, 0x100 + paletteSlot * 0x10, 0x20);
}
else
{
gUnknown_0203CCEC.paletteTag = paletteTag;
LoadCompressedObjectPalette(&gTrainerFrontPicPaletteTable[species]);
}
}
}
2017-09-19 03:28:28 +02:00
void sub_818D180(u16 species, u32 otId, u32 personality, u8 paletteSlot, bool8 isTrainer)
{
if (!isTrainer)
{
LoadCompressedPalette(species_and_otid_get_pal(species, otId, personality), paletteSlot * 0x10, 0x20);
}
else
{
LoadCompressedPalette(gTrainerFrontPicPaletteTable[species].data, paletteSlot * 0x10, 0x20);
}
}
2017-09-19 03:31:28 +02:00
void uns_builder_assign_animtable1(bool8 isTrainer)
{
if (!isTrainer)
{
gUnknown_0203CCEC.anims = gUnknown_082FF70C;
}
else
{
gUnknown_0203CCEC.anims = gUnknown_0830536C[0];
}
}
2017-09-19 04:23:13 +02:00
u16 oamt_spawn_poke_or_trainer_picture(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag, bool8 isTrainer, bool8 ignoreDeoxys)
{
u8 i;
u8 *framePics;
struct SpriteFrameImage *images;
int j;
u8 spriteId;
for (i = 0; i < 8; i ++)
{
if (!gUnknown_0203CD04[i].active)
{
break;
}
}
if (i == 8)
{
return 0xFFFF;
}
framePics = Alloc(4 * 0x800);
if (!framePics)
{
return 0xFFFF;
}
images = Alloc(4 * sizeof(struct SpriteFrameImage));
if (!images)
{
Free(framePics);
return 0xFFFF;
}
if (load_pokemon_image_TODO(species, personality, isFrontPic, framePics, isTrainer, ignoreDeoxys))
{
// debug trap?
return 0xFFFF;
}
for (j = 0; j < 4; j ++)
{
images[j].data = framePics + 0x800 * j;
images[j].size = 0x800;
}
gUnknown_0203CCEC.tileTag = 0xFFFF;
gUnknown_0203CCEC.oam = &gUnknown_0860B064;
uns_builder_assign_animtable1(isTrainer);
gUnknown_0203CCEC.images = images;
gUnknown_0203CCEC.affineAnims = gDummySpriteAffineAnimTable;
gUnknown_0203CCEC.callback = nullsub_122;
sub_818D0C4(species, otId, personality, paletteSlot, paletteTag, isTrainer);
spriteId = CreateSprite(&gUnknown_0203CCEC, x, y, 0);
if (paletteTag == 0xFFFF)
{
gSprites[spriteId].oam.paletteNum = paletteSlot;
}
gUnknown_0203CD04[i].frames = framePics;
gUnknown_0203CD04[i].images = images;
gUnknown_0203CD04[i].paletteTag = paletteTag;
gUnknown_0203CD04[i].spriteId = spriteId;
gUnknown_0203CD04[i].active = TRUE;
return spriteId;
}
2017-09-19 04:41:54 +02:00
u16 sub_818D384(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag, bool8 isTrainer)
{
return oamt_spawn_poke_or_trainer_picture(species, otId, personality, isFrontPic, x, y, paletteSlot, paletteTag, isTrainer, FALSE);
}
u16 sub_818D3E4(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag)
{
u8 *framePics;
struct SpriteFrameImage *images;
int j;
u8 i;
u8 spriteId;
u8 flags2;
for (i = 0; i < 8; i ++)
{
if (!gUnknown_0203CD04[i].active)
{
break;
}
}
if (i == 8)
{
return 0xFFFF;
}
framePics = Alloc(4 * 0x800);
if (!framePics)
{
return 0xFFFF;
}
if (flags & 0x80)
{
flags &= 0x7F;
flags2 = 3;
}
else
{
flags2 = flags;
}
images = Alloc(4 * sizeof(struct SpriteFrameImage));
if (!images)
{
Free(framePics);
return 0xFFFF;
}
if (load_pokemon_image_TODO(species, personality, flags, framePics, FALSE, FALSE))
{
// debug trap?
return 0xFFFF;
}
for (j = 0; j < 4; j ++)
{
images[j].data = framePics + 0x800 * j;
images[j].size = 0x800;
}
gUnknown_0203CCEC.tileTag = 0xFFFF;
gUnknown_0203CCEC.anims = gUnknown_08309AAC[species];
gUnknown_0203CCEC.images = images;
if (flags2 == 0x01)
{
gUnknown_0203CCEC.affineAnims = gUnknown_082FF694;
gUnknown_0203CCEC.oam = &gUnknown_0860B06C;
}
else if (flags2 == 0x00)
{
gUnknown_0203CCEC.affineAnims = gUnknown_082FF618;
gUnknown_0203CCEC.oam = &gUnknown_0860B06C;
}
else
{
gUnknown_0203CCEC.oam = &gUnknown_0860B064;
gUnknown_0203CCEC.affineAnims = gDummySpriteAffineAnimTable;
}
gUnknown_0203CCEC.callback = nullsub_122;
sub_818D0C4(species, otId, personality, paletteSlot, paletteTag, FALSE);
spriteId = CreateSprite(&gUnknown_0203CCEC, x, y, 0);
if (paletteTag == 0xFFFF)
{
gSprites[spriteId].oam.paletteNum = paletteSlot;
}
gUnknown_0203CD04[i].frames = framePics;
gUnknown_0203CD04[i].images = images;
gUnknown_0203CD04[i].paletteTag = paletteTag;
gUnknown_0203CD04[i].spriteId = spriteId;
gUnknown_0203CD04[i].active = TRUE;
return spriteId;
}
2017-09-19 14:13:53 +02:00
u16 sub_818D5B0(u16 spriteId)
{
u8 i;
u8 *framePics;
struct SpriteFrameImage *images;
for (i = 0; i < 8; i ++)
{
if (gUnknown_0203CD04[i].spriteId == spriteId)
{
break;
}
}
if (i == 8)
{
return 0xFFFF;
}
framePics = gUnknown_0203CD04[i].frames;
images = gUnknown_0203CD04[i].images;
if (gUnknown_0203CD04[i].paletteTag != 0xFFFF)
{
FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(gSprites[spriteId].oam.paletteNum));
}
DestroySprite(&gSprites[spriteId]);
Free(framePics);
Free(images);
gUnknown_0203CD04[i] = gUnknown_0860B058;
return 0;
}
2017-09-19 14:22:43 +02:00
u16 sub_818D65C(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId, bool8 isTrainer)
{
if (sub_818D09C(species, personality, isFrontPic, (void *)GetWindowAttribute(windowId, WINDOW_TILE_DATA), FALSE))
{
return 0xFFFF;
}
sub_818D180(species, otId, personality, paletteSlot, isTrainer);
return 0;
}