Skip to content

Commit

Permalink
Refactor mugshots (rh-hideout#4000)
Browse files Browse the repository at this point in the history
* Refactor battle mugshots
The battle mugshot transitions have been merged into the one transition id and are now loaded depending on the trainer data.

Two new fields have been added to struct Trainer; mugshotEnabled and mugshotColor. mugshotEnabled is the toggle for loading the mugshot transition when set to TRUE and mugshotColor is the color of the mugshot for that particular trainer.

The Elite Four and Champion have been updated so their mugshots are correctly loaded when you battle them.

A bug has also been fixed where if the player starts on a tile that has an active field effect, the player's sprite will use the palette of the opponent's sprite.

* Added a new folder in src/data named battle_transitions.

The two look ups for the opponent rotation scaling and coords have been put into their own files and added into this new folder.

The coords look up has also been changed to use the  struct.

* Fixed errors with modern that were preventing compile

* Added mugshot coords to gTrainerSprites

* Added rotation scales to gTrainerSprites

* Replaced tabs with spaces

* Incorporated comments

* Added battle_transition include back to data.c

* Fixed alignment issues in Mugshots_CreateTrainerPics

---------

Co-authored-by: pkmnsnfrn <[email protected]>
Co-authored-by: Alex <[email protected]>
  • Loading branch information
3 people authored and Pawkkie committed May 16, 2024
1 parent cc3f437 commit 3662537
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 236 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 7 additions & 13 deletions include/battle_transition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ void GetBg0TilesDst(u16 **tilemap, u16 **tileset);
extern const struct SpritePalette gSpritePalette_Pokeball;

enum {
MUGSHOT_SIDNEY,
MUGSHOT_PHOEBE,
MUGSHOT_GLACIA,
MUGSHOT_DRAKE,
MUGSHOT_CHAMPION,
MUGSHOT_MAY,
MUGSHOTS_COUNT
MUGSHOT_COLOR_PURPLE,
MUGSHOT_COLOR_GREEN,
MUGSHOT_COLOR_PINK,
MUGSHOT_COLOR_BLUE,
MUGSHOT_COLOR_YELLOW,
MUGSHOT_COLOR_COUNT
};

enum {
Expand All @@ -33,12 +32,7 @@ enum {
B_TRANSITION_WHITE_BARS_FADE,
B_TRANSITION_GRID_SQUARES,
B_TRANSITION_ANGLED_WIPES,
B_TRANSITION_SIDNEY,
B_TRANSITION_PHOEBE,
B_TRANSITION_GLACIA,
B_TRANSITION_DRAKE,
B_TRANSITION_CHAMPION,
B_TRANSITION_MAY,
B_TRANSITION_MUGSHOT,
B_TRANSITION_AQUA, // Here below added in Emerald
B_TRANSITION_MAGMA,
B_TRANSITION_REGICE,
Expand Down
1 change: 1 addition & 0 deletions include/constants/trainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#define TRAINER_PIC_LEAF 90
#define TRAINER_PIC_RS_BRENDAN 91
#define TRAINER_PIC_RS_MAY 92
#define TRAINER_PIC_COUNT 93

// New front sprites
#define TRAINER_PIC_BREEDER_F_HGSS 93
Expand Down
8 changes: 6 additions & 2 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct TrainerSprite
struct CompressedSpriteSheet frontPic;
struct CompressedSpritePalette palette;
const union AnimCmd *const *const animation;
const struct Coords16 mugshotCoords;
s16 mugshotRotation;
};

struct TrainerBacksprite
Expand Down Expand Up @@ -82,8 +84,10 @@ struct Trainer
/*0x12*/ u8 trainerPic;
/*0x13*/ u8 trainerName[TRAINER_NAME_LENGTH + 1];
/*0x1E*/ bool8 doubleBattle:1;
u8 padding:7;
/*0x1F*/ u8 partySize;
bool8 mugshotEnabled:1;
u8 padding:6;
/*0x1F*/ u8 mugshotColor;
/*0x20*/ u8 partySize;
};

#define TRAINER_ENCOUNTER_MUSIC(trainer)((gTrainers[trainer].encounterMusic_gender & 0x7F))
Expand Down
22 changes: 2 additions & 20 deletions src/battle_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,26 +882,8 @@ u8 GetTrainerBattleTransition(void)
u8 enemyLevel;
u8 playerLevel;

if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE)
return B_TRANSITION_CHAMPION;

if (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_ELITE_FOUR)
{
if (gTrainerBattleOpponent_A == TRAINER_SIDNEY)
return B_TRANSITION_SIDNEY;
if (gTrainerBattleOpponent_A == TRAINER_PHOEBE)
return B_TRANSITION_PHOEBE;
if (gTrainerBattleOpponent_A == TRAINER_GLACIA)
return B_TRANSITION_GLACIA;
if (gTrainerBattleOpponent_A == TRAINER_DRAKE)
return B_TRANSITION_DRAKE;
return B_TRANSITION_CHAMPION;
}
if (gTrainerBattleOpponent_A == TRAINER_MAY_ROUTE_103_MUDKIP)
return B_TRANSITION_MAY;

if (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_CHAMPION)
return B_TRANSITION_CHAMPION;
if (gTrainers[gTrainerBattleOpponent_A].mugshotEnabled)
return B_TRANSITION_MUGSHOT;

if (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_TEAM_MAGMA
|| gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_MAGMA_LEADER
Expand Down
149 changes: 42 additions & 107 deletions src/battle_transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "task.h"
#include "trig.h"
#include "util.h"
#include "battle_setup.h"
#include "data.h"
#include "constants/field_effects.h"
#include "constants/songs.h"
#include "constants/trainers.h"
Expand Down Expand Up @@ -107,12 +109,7 @@ static void Task_Slice(u8);
static void Task_WhiteBarsFade(u8);
static void Task_GridSquares(u8);
static void Task_AngledWipes(u8);
static void Task_Sidney(u8);
static void Task_Phoebe(u8);
static void Task_Glacia(u8);
static void Task_Drake(u8);
static void Task_Champion(u8);
static void Task_May(u8);
static void Task_Mugshot(u8);
static void Task_Aqua(u8);
static void Task_Magma(u8);
static void Task_Regice(u8);
Expand Down Expand Up @@ -260,7 +257,6 @@ static bool8 Mugshot_GradualWhiteFade(struct Task *);
static bool8 Mugshot_InitFadeWhiteToBlack(struct Task *);
static bool8 Mugshot_FadeToBlack(struct Task *);
static bool8 Mugshot_End(struct Task *);
static void DoMugshotTransition(u8);
static void Mugshots_CreateTrainerPics(struct Task *);
static void VBlankCB_Mugshots(void);
static void VBlankCB_MugshotsFadeOut(void);
Expand Down Expand Up @@ -359,12 +355,7 @@ static const TaskFunc sTasks_Main[B_TRANSITION_COUNT] =
[B_TRANSITION_WHITE_BARS_FADE] = Task_WhiteBarsFade,
[B_TRANSITION_GRID_SQUARES] = Task_GridSquares,
[B_TRANSITION_ANGLED_WIPES] = Task_AngledWipes,
[B_TRANSITION_SIDNEY] = Task_Sidney,
[B_TRANSITION_PHOEBE] = Task_Phoebe,
[B_TRANSITION_GLACIA] = Task_Glacia,
[B_TRANSITION_DRAKE] = Task_Drake,
[B_TRANSITION_CHAMPION] = Task_Champion,
[B_TRANSITION_MAY] = Task_May,
[B_TRANSITION_MUGSHOT] = Task_Mugshot,
[B_TRANSITION_AQUA] = Task_Aqua,
[B_TRANSITION_MAGMA] = Task_Magma,
[B_TRANSITION_REGICE] = Task_Regice,
Expand Down Expand Up @@ -543,34 +534,6 @@ static const TransitionStateFunc sMugshot_Funcs[] =
Mugshot_End
};

static const u8 sMugshotsTrainerPicIDsTable[MUGSHOTS_COUNT] =
{
[MUGSHOT_SIDNEY] = TRAINER_PIC_ELITE_FOUR_SIDNEY,
[MUGSHOT_PHOEBE] = TRAINER_PIC_ELITE_FOUR_PHOEBE,
[MUGSHOT_GLACIA] = TRAINER_PIC_ELITE_FOUR_GLACIA,
[MUGSHOT_DRAKE] = TRAINER_PIC_ELITE_FOUR_DRAKE,
[MUGSHOT_CHAMPION] = TRAINER_PIC_CHAMPION_WALLACE,
[MUGSHOT_MAY] = TRAINER_PIC_MAY,
};
static const s16 sMugshotsOpponentRotationScales[MUGSHOTS_COUNT][2] =
{
[MUGSHOT_SIDNEY] = {0x200, 0x200},
[MUGSHOT_PHOEBE] = {0x200, 0x200},
[MUGSHOT_GLACIA] = {0x1B0, 0x1B0},
[MUGSHOT_DRAKE] = {0x1A0, 0x1A0},
[MUGSHOT_CHAMPION] = {0x188, 0x188},
[MUGSHOT_MAY] = {0x200, 0x200},
};
static const s16 sMugshotsOpponentCoords[MUGSHOTS_COUNT][2] =
{
[MUGSHOT_SIDNEY] = { 0, 0},
[MUGSHOT_PHOEBE] = { 0, 0},
[MUGSHOT_GLACIA] = {-4, 4},
[MUGSHOT_DRAKE] = { 0, 5},
[MUGSHOT_CHAMPION] = {-8, 7},
[MUGSHOT_MAY] = {0, 0},
};

static const TransitionSpriteCallback sMugshotTrainerPicFuncs[] =
{
MugshotTrainerPic_Pause,
Expand Down Expand Up @@ -891,22 +854,21 @@ static const u16 sFieldEffectPal_Pokeball[] = INCBIN_U16("graphics/field_effects

const struct SpritePalette gSpritePalette_Pokeball = {sFieldEffectPal_Pokeball, FLDEFF_PAL_TAG_POKEBALL_TRAIL};

static const u16 sMugshotPal_Sidney[] = INCBIN_U16("graphics/battle_transitions/sidney_bg.gbapal");
static const u16 sMugshotPal_Phoebe[] = INCBIN_U16("graphics/battle_transitions/phoebe_bg.gbapal");
static const u16 sMugshotPal_Glacia[] = INCBIN_U16("graphics/battle_transitions/glacia_bg.gbapal");
static const u16 sMugshotPal_Drake[] = INCBIN_U16("graphics/battle_transitions/drake_bg.gbapal");
static const u16 sMugshotPal_Champion[] = INCBIN_U16("graphics/battle_transitions/wallace_bg.gbapal");
static const u16 sMugshotPal_Purple[] = INCBIN_U16("graphics/battle_transitions/purple_bg.gbapal");
static const u16 sMugshotPal_Green[] = INCBIN_U16("graphics/battle_transitions/green_bg.gbapal");
static const u16 sMugshotPal_Pink[] = INCBIN_U16("graphics/battle_transitions/pink_bg.gbapal");
static const u16 sMugshotPal_Blue[] = INCBIN_U16("graphics/battle_transitions/blue_bg.gbapal");
static const u16 sMugshotPal_Yellow[] = INCBIN_U16("graphics/battle_transitions/yellow_bg.gbapal");
static const u16 sMugshotPal_Brendan[] = INCBIN_U16("graphics/battle_transitions/brendan_bg.gbapal");
static const u16 sMugshotPal_May[] = INCBIN_U16("graphics/battle_transitions/may_bg.gbapal");

static const u16 *const sOpponentMugshotsPals[MUGSHOTS_COUNT] =
static const u16 *const sOpponentMugshotsPals[MUGSHOT_COLOR_COUNT] =
{
[MUGSHOT_SIDNEY] = sMugshotPal_Sidney,
[MUGSHOT_PHOEBE] = sMugshotPal_Phoebe,
[MUGSHOT_GLACIA] = sMugshotPal_Glacia,
[MUGSHOT_DRAKE] = sMugshotPal_Drake,
[MUGSHOT_CHAMPION] = sMugshotPal_Champion,
[MUGSHOT_MAY] = sMugshotPal_Champion
[MUGSHOT_COLOR_PURPLE] = sMugshotPal_Purple,
[MUGSHOT_COLOR_GREEN] = sMugshotPal_Green,
[MUGSHOT_COLOR_PINK] = sMugshotPal_Pink,
[MUGSHOT_COLOR_BLUE] = sMugshotPal_Blue,
[MUGSHOT_COLOR_YELLOW] = sMugshotPal_Yellow
};

static const u16 *const sPlayerMugshotsPals[GENDER_COUNT] =
Expand Down Expand Up @@ -2241,13 +2203,11 @@ static void VBlankCB_Wave(void)
#undef tX
#undef tSinIndex

//----------------------------------------------------------------
// B_TRANSITION_SIDNEY, B_TRANSITION_PHOEBE, B_TRANSITION_GLACIA,
// B_TRANSITION_DRAKE, and B_TRANSITION_CHAMPION
//
// These are all the "mugshot" transitions, where a banner shows
// the trainer pic of the player and their opponent.
//----------------------------------------------------------------
//----------------------------------------------------
// B_TRANSITION_MUGSHOT
// Where a banner shows the trainer pic of the player
// and their opponent.
//----------------------------------------------------

#define tSinIndex data[1]
#define tTopBannerX data[2]
Expand All @@ -2256,7 +2216,6 @@ static void VBlankCB_Wave(void)
#define tFadeSpread data[4]
#define tOpponentSpriteId data[13]
#define tPlayerSpriteId data[14]
#define tMugshotId data[15]

// Sprite data for trainer sprites in mugshots
#define sState data[0]
Expand All @@ -2265,43 +2224,7 @@ static void VBlankCB_Wave(void)
#define sDone data[6]
#define sSlideDir data[7]

static void Task_Sidney(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_SIDNEY;
DoMugshotTransition(taskId);
}

static void Task_Phoebe(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_PHOEBE;
DoMugshotTransition(taskId);
}

static void Task_Glacia(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_GLACIA;
DoMugshotTransition(taskId);
}

static void Task_Drake(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_DRAKE;
DoMugshotTransition(taskId);
}

static void Task_Champion(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_CHAMPION;
DoMugshotTransition(taskId);
}

static void Task_May(u8 taskId)
{
gTasks[taskId].tMugshotId = MUGSHOT_MAY;
DoMugshotTransition(taskId);
}

static void DoMugshotTransition(u8 taskId)
static void Task_Mugshot(u8 taskId)
{
while (sMugshot_Funcs[gTasks[taskId].tState](&gTasks[taskId]));
}
Expand Down Expand Up @@ -2334,12 +2257,17 @@ static bool8 Mugshot_SetGfx(struct Task *task)
{
s16 i, j;
u16 *tilemap, *tileset;
const u16 *mugshotsMap;
const u16 *mugshotsMap = sMugshotsTilemap;
u8 mugshotColor = gTrainers[gTrainerBattleOpponent_A].mugshotColor;


mugshotsMap = sMugshotsTilemap;
GetBg0TilesDst(&tilemap, &tileset);
CpuSet(sEliteFour_Tileset, tileset, 0xF0);
LoadPalette(sOpponentMugshotsPals[task->tMugshotId], BG_PLTT_ID(15), PLTT_SIZE_4BPP);

if (mugshotColor >= ARRAY_COUNT(sOpponentMugshotsPals))
mugshotColor = MUGSHOT_COLOR_PURPLE;

LoadPalette(sOpponentMugshotsPals[mugshotColor], 0xF0, 0x20);
LoadPalette(sPlayerMugshotsPals[gSaveBlock2Ptr->playerGender], BG_PLTT_ID(15) + 10, PLTT_SIZEOF(6));

for (i = 0; i < 20; i++)
Expand Down Expand Up @@ -2590,11 +2518,16 @@ static void Mugshots_CreateTrainerPics(struct Task *task)
{
struct Sprite *opponentSprite, *playerSprite;

s16 mugshotId = task->tMugshotId;
task->tOpponentSpriteId = CreateTrainerSprite(sMugshotsTrainerPicIDsTable[mugshotId],
sMugshotsOpponentCoords[mugshotId][0] - 32,
sMugshotsOpponentCoords[mugshotId][1] + 42,
u8 trainerPicId = gTrainers[gTrainerBattleOpponent_A].trainerPic;
s16 opponentRotationScales = 0;

gReservedSpritePaletteCount = 10;
task->tOpponentSpriteId = CreateTrainerSprite(trainerPicId,
gTrainerSprites[trainerPicId].mugshotCoords.x - 32,
gTrainerSprites[trainerPicId].mugshotCoords.y + 42,
0, gDecompressionBuffer);
gReservedSpritePaletteCount = 12;

task->tPlayerSpriteId = CreateTrainerSprite(PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender),
DISPLAY_WIDTH + 32,
106,
Expand All @@ -2621,7 +2554,10 @@ static void Mugshots_CreateTrainerPics(struct Task *task)
CalcCenterToCornerVec(opponentSprite, SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), ST_OAM_AFFINE_DOUBLE);
CalcCenterToCornerVec(playerSprite, SPRITE_SHAPE(64x32), SPRITE_SIZE(64x32), ST_OAM_AFFINE_DOUBLE);

SetOamMatrixRotationScaling(opponentSprite->oam.matrixNum, sMugshotsOpponentRotationScales[mugshotId][0], sMugshotsOpponentRotationScales[mugshotId][1], 0);
opponentRotationScales = gTrainerSprites[trainerPicId].mugshotRotation;

SetOamMatrixRotationScaling(opponentSprite->oam.matrixNum, opponentRotationScales, opponentRotationScales, 0);

SetOamMatrixRotationScaling(playerSprite->oam.matrixNum, -512, 512, 0);
}

Expand Down Expand Up @@ -2718,7 +2654,6 @@ static s16 IsTrainerPicSlideDone(s16 spriteId)
#undef tFadeSpread
#undef tOpponentSpriteId
#undef tPlayerSpriteId
#undef tMugshotId

//--------------------
// B_TRANSITION_SLICE
Expand Down
1 change: 1 addition & 0 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "battle.h"
#include "data.h"
#include "graphics.h"
#include "battle_transition.h"
#include "constants/abilities.h"
#include "constants/items.h"
#include "constants/moves.h"
Expand Down
Loading

0 comments on commit 3662537

Please sign in to comment.