Clean up trainer_pokemon_sprites

This commit is contained in:
GriffinR 2021-10-18 01:39:07 -04:00
parent db8ce5d7f9
commit 46dd10c87b
5 changed files with 45 additions and 67 deletions

View File

@ -1,8 +1,14 @@
#ifndef GUARD_TRAINER_POKEMON_SPRITES_H
#define GUARD_TRAINER_POKEMON_SPRITES_H
// For the flags argument of CreateMonPicSprite_Affine
#define MON_PIC_AFFINE_BACK 0
#define MON_PIC_AFFINE_FRONT 1
#define MON_PIC_AFFINE_NONE 3
#define F_MON_PIC_NO_AFFINE (1 << 7)
bool16 ResetAllPicSprites(void);
u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 CreateMonPicSprite_Affine(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 CreateMonPicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 FreeAndDestroyMonPicSprite(u16 spriteId);
u16 CreateTrainerPicSprite(u16 species, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);

View File

@ -588,7 +588,7 @@ static void Task_Hof_DisplayMon(u8 taskId)
if (currMon->species == SPECIES_EGG)
destY += 10;
spriteId = CreatePicSprite2(currMon->species, currMon->tid, currMon->personality, 1, startX, startY, currMonId, TAG_NONE);
spriteId = CreateMonPicSprite_Affine(currMon->species, currMon->tid, currMon->personality, MON_PIC_AFFINE_FRONT, startX, startY, currMonId, TAG_NONE);
gSprites[spriteId].tDestinationX = destX;
gSprites[spriteId].tDestinationY = destY;
gSprites[spriteId].data[0] = 0;

View File

@ -1871,9 +1871,9 @@ static void SpriteCB_MovePlayerDownWhileShrinking(struct Sprite *sprite)
sprite->data[0] = y;
}
static u8 NewGameBirchSpeech_CreateLotadSprite(u8 a, u8 b)
static u8 NewGameBirchSpeech_CreateLotadSprite(u8 x, u8 y)
{
return CreatePicSprite2(SPECIES_LOTAD, SHINY_ODDS, 0, 1, a, b, 14, -1);
return CreateMonPicSprite_Affine(SPECIES_LOTAD, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE);
}
static void AddBirchSpeechObjects(u8 taskId)

View File

@ -635,7 +635,7 @@ static u8 CreatePokemonFrontSprite(u16 species, u8 x, u8 y)
{
u8 spriteId;
spriteId = CreatePicSprite2(species, SHINY_ODDS, 0, 1, x, y, 0xE, TAG_NONE);
spriteId = CreateMonPicSprite_Affine(species, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE);
gSprites[spriteId].oam.priority = 0;
return spriteId;
}

View File

@ -9,8 +9,6 @@
#include "pokemon.h"
#include "constants/trainers.h"
// Static type declarations
struct PicData
{
u8 *frames;
@ -20,33 +18,26 @@ struct PicData
u8 active;
};
// Static RAM declarations
#define PICS_COUNT 8
static EWRAM_DATA struct SpriteTemplate sCreatingSpriteTemplate = {};
static EWRAM_DATA struct PicData sSpritePics[PICS_COUNT] = {};
// Static ROM declarations
// .rodata
static const struct PicData sDummyPicData = {};
static const struct OamData gUnknown_0860B064 =
static const struct OamData sOamData_Normal =
{
.shape = SPRITE_SHAPE(64x64),
.size = SPRITE_SIZE(64x64)
};
static const struct OamData gUnknown_0860B06C =
static const struct OamData sOamData_Affine =
{
.affineMode = ST_OAM_AFFINE_NORMAL,
.shape = SPRITE_SHAPE(64x64),
.size = SPRITE_SIZE(64x64)
};
// .text
static void DummyPicSpriteCallback(struct Sprite *sprite)
{
@ -153,19 +144,15 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront
for (i = 0; i < PICS_COUNT; i ++)
{
if (!sSpritePics[i].active)
{
break;
}
}
if (i == PICS_COUNT)
{
return 0xFFFF;
}
framePics = Alloc(4 * 0x800);
if (!framePics)
{
return 0xFFFF;
}
images = Alloc(4 * sizeof(struct SpriteFrameImage));
if (!images)
{
@ -183,7 +170,7 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront
images[j].size = 0x800;
}
sCreatingSpriteTemplate.tileTag = TAG_NONE;
sCreatingSpriteTemplate.oam = &gUnknown_0860B064;
sCreatingSpriteTemplate.oam = &sOamData_Normal;
AssignSpriteAnimsTable(isTrainer);
sCreatingSpriteTemplate.images = images;
sCreatingSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
@ -191,9 +178,7 @@ static u16 CreatePicSprite(u16 species, u32 otId, u32 personality, bool8 isFront
LoadPicPaletteByTagOrSlot(species, otId, personality, paletteSlot, paletteTag, isTrainer);
spriteId = CreateSprite(&sCreatingSpriteTemplate, x, y, 0);
if (paletteTag == TAG_NONE)
{
gSprites[spriteId].oam.paletteNum = paletteSlot;
}
sSpritePics[i].frames = framePics;
sSpritePics[i].images = images;
sSpritePics[i].paletteTag = paletteTag;
@ -207,39 +192,35 @@ static u16 CreatePicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality,
return CreatePicSprite(species, otId, personality, isFrontPic, x, y, paletteSlot, paletteTag, isTrainer, FALSE);
}
u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag)
u16 CreateMonPicSprite_Affine(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;
u8 type;
for (i = 0; i < PICS_COUNT; i ++)
for (i = 0; i < PICS_COUNT; i++)
{
if (!sSpritePics[i].active)
{
break;
}
}
if (i == PICS_COUNT)
{
return 0xFFFF;
}
framePics = Alloc(4 * 0x800);
framePics = Alloc(4 * MON_PIC_SIZE);
if (!framePics)
{
return 0xFFFF;
}
if (flags & 0x80)
if (flags & F_MON_PIC_NO_AFFINE)
{
flags &= 0x7F;
flags2 = 3;
flags &= ~F_MON_PIC_NO_AFFINE;
type = MON_PIC_AFFINE_NONE;
}
else
{
flags2 = flags;
type = flags;
}
images = Alloc(4 * sizeof(struct SpriteFrameImage));
if (!images)
@ -254,34 +235,32 @@ u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s1
}
for (j = 0; j < 4; j ++)
{
images[j].data = framePics + 0x800 * j;
images[j].size = 0x800;
images[j].data = framePics + MON_PIC_SIZE * j;
images[j].size = MON_PIC_SIZE;
}
sCreatingSpriteTemplate.tileTag = TAG_NONE;
sCreatingSpriteTemplate.anims = gMonFrontAnimsPtrTable[species];
sCreatingSpriteTemplate.images = images;
if (flags2 == 0x01)
if (type == MON_PIC_AFFINE_FRONT)
{
sCreatingSpriteTemplate.affineAnims = gAffineAnims_BattleSpriteOpponentSide;
sCreatingSpriteTemplate.oam = &gUnknown_0860B06C;
sCreatingSpriteTemplate.oam = &sOamData_Affine;
}
else if (flags2 == 0x00)
else if (type == MON_PIC_AFFINE_BACK)
{
sCreatingSpriteTemplate.affineAnims = gAffineAnims_BattleSpritePlayerSide;
sCreatingSpriteTemplate.oam = &gUnknown_0860B06C;
sCreatingSpriteTemplate.oam = &sOamData_Affine;
}
else
else // MON_PIC_AFFINE_NONE
{
sCreatingSpriteTemplate.oam = &gUnknown_0860B064;
sCreatingSpriteTemplate.oam = &sOamData_Normal;
sCreatingSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
}
sCreatingSpriteTemplate.callback = DummyPicSpriteCallback;
LoadPicPaletteByTagOrSlot(species, otId, personality, paletteSlot, paletteTag, FALSE);
spriteId = CreateSprite(&sCreatingSpriteTemplate, x, y, 0);
if (paletteTag == TAG_NONE)
{
gSprites[spriteId].oam.paletteNum = paletteSlot;
}
sSpritePics[i].frames = framePics;
sSpritePics[i].images = images;
sSpritePics[i].paletteTag = paletteTag;
@ -299,20 +278,15 @@ static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId)
for (i = 0; i < PICS_COUNT; i ++)
{
if (sSpritePics[i].spriteId == spriteId)
{
break;
}
}
if (i == PICS_COUNT)
{
return 0xFFFF;
}
framePics = sSpritePics[i].frames;
images = sSpritePics[i].images;
if (sSpritePics[i].paletteTag != TAG_NONE)
{
FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(gSprites[spriteId].oam.paletteNum));
}
DestroySprite(&gSprites[spriteId]);
Free(framePics);
Free(images);
@ -320,12 +294,11 @@ static u16 FreeAndDestroyPicSpriteInternal(u16 spriteId)
return 0;
}
static u16 sub_818D65C(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId, bool8 isTrainer)
static u16 LoadPicSpriteInWindow(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId, bool8 isTrainer)
{
if (DecompressPic_HandleDeoxys(species, personality, isFrontPic, (u8 *)GetWindowAttribute(windowId, WINDOW_TILE_DATA), FALSE))
{
return 0xFFFF;
}
LoadPicPaletteBySlot(species, otId, personality, paletteSlot, isTrainer);
return 0;
}
@ -360,9 +333,10 @@ u16 FreeAndDestroyMonPicSprite(u16 spriteId)
return FreeAndDestroyPicSpriteInternal(spriteId);
}
u16 sub_818D834(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId)
// Unused
static u16 LoadMonPicInWindow(u16 species, u32 otId, u32 personality, bool8 isFrontPic, u8 paletteSlot, u8 windowId)
{
return sub_818D65C(species, otId, personality, isFrontPic, paletteSlot, windowId, FALSE);
return LoadPicSpriteInWindow(species, otId, personality, isFrontPic, paletteSlot, windowId, FALSE);
}
// Unused, FRLG only
@ -381,9 +355,10 @@ u16 FreeAndDestroyTrainerPicSprite(u16 spriteId)
return FreeAndDestroyPicSpriteInternal(spriteId);
}
u16 sub_818D904(u16 species, bool8 isFrontPic, u8 paletteSlot, u8 windowId)
// Unused
static u16 LoadTrainerPicInWindow(u16 species, bool8 isFrontPic, u8 paletteSlot, u8 windowId)
{
return sub_818D65C(species, 0, 0, isFrontPic, paletteSlot, windowId, TRUE);
return LoadPicSpriteInWindow(species, 0, 0, isFrontPic, paletteSlot, windowId, TRUE);
}
u16 CreateTrainerCardTrainerPicSprite(u16 species, bool8 isFrontPic, u16 destX, u16 destY, u8 paletteSlot, u8 windowId)
@ -395,13 +370,10 @@ u16 PlayerGenderToFrontTrainerPicId_Debug(u8 gender, bool8 getClass)
{
if (getClass == TRUE)
{
switch (gender)
{
default:
if (gender != MALE)
return gFacilityClassToPicIndex[FACILITY_CLASS_MAY];
case MALE:
else
return gFacilityClassToPicIndex[FACILITY_CLASS_BRENDAN];
}
}
return gender;
}