Document summary screen sprite manager

This commit is contained in:
GriffinR 2021-10-02 23:47:59 -04:00
parent 001a25e49c
commit 739e7d3c31
16 changed files with 243 additions and 204 deletions

View File

@ -37,8 +37,6 @@
#define B_ACTION_NOTHING_FAINTED 13 // when choosing an action
#define B_ACTION_NONE 0xFF
#define MAX_TRAINER_ITEMS 4
// array entries for battle communication
#define MULTIUSE_STATE 0
#define CURSOR_POSITION 1
@ -594,16 +592,15 @@ struct BattleSpriteData
struct MonSpritesGfx
{
void* firstDecompressed; // ptr to the decompressed sprite of the first pokemon
union
{
void* ptr[4];
u8* byte[4];
union {
void* ptr[MAX_BATTLERS_COUNT];
u8* byte[MAX_BATTLERS_COUNT];
} sprites;
struct SpriteTemplate templates[4];
struct SpriteFrameImage field_74[4][4];
u8 field_F4[0x80];
struct SpriteTemplate templates[MAX_BATTLERS_COUNT];
struct SpriteFrameImage frameImages[MAX_BATTLERS_COUNT][4];
u8 unusedArr[0x80];
u8 *barFontGfx;
void *field_178;
void *unusedPtr;
u16 *buffer;
};

View File

@ -5,6 +5,8 @@
#define SPECIES_SHINY_TAG 500
#define MAX_TRAINER_ITEMS 4
enum {
BATTLER_AFFINE_NORMAL,
BATTLER_AFFINE_EMERGE,
@ -66,7 +68,7 @@ struct Trainer
/*0x02*/ u8 encounterMusic_gender; // last bit is gender
/*0x03*/ u8 trainerPic;
/*0x04*/ u8 trainerName[12];
/*0x10*/ u16 items[4];
/*0x10*/ u16 items[MAX_TRAINER_ITEMS];
/*0x18*/ bool8 doubleBattle;
/*0x1C*/ u32 aiFlags;
/*0x20*/ u8 partySize;

View File

@ -122,20 +122,32 @@ struct Pokemon
u16 spDefense;
};
struct Unknown_806F160_Struct
struct MonSpritesGfxManager
{
u32 field_0_0:4;
u32 field_0_1:4;
u32 field_1:8;
u16 magic:8;
u32 field_3_0:4;
u32 field_3_1:4;
void *bytes;
u8 **byteArrays;
u32 numSprites:4;
u32 numSprites2:4; // Never read
u32 numFrames:8;
u32 active:8;
u32 dataSize:4;
u32 mode:4; // MON_SPR_GFX_MODE_*
void *spriteBuffer;
u8 **spritePointers;
struct SpriteTemplate *templates;
struct SpriteFrameImage *frameImages;
};
enum {
MON_SPR_GFX_MODE_NORMAL,
MON_SPR_GFX_MODE_BATTLE,
MON_SPR_GFX_MODE_FULL_PARTY,
};
enum {
MON_SPR_GFX_MANAGER_A,
MON_SPR_GFX_MANAGER_B, // Nothing ever sets up this manager.
MON_SPR_GFX_MANAGERS_COUNT
};
struct BattlePokemon
{
/*0x00*/ u16 species;
@ -422,8 +434,8 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality);
const u8 *GetTrainerClassNameFromId(u16 trainerId);
const u8 *GetTrainerNameFromId(u16 trainerId);
bool8 HasTwoFramesAnimation(u16 species);
struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1);
void sub_806F47C(u8 id);
u8 *sub_806F4F8(u8 id, u8 arg1);
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode);
void DestroyMonSpritesGfxManager(u8 managerId);
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum);
#endif // GUARD_POKEMON_H

View File

@ -2,6 +2,7 @@
#include "battle.h"
#include "battle_anim.h"
#include "battle_controllers.h"
#include "data.h"
#include "pokemon.h"
#include "random.h"
#include "util.h"

View File

@ -2286,7 +2286,7 @@ void AnimTask_TransformMon(u8 taskId)
sub_80A6BFC(&animBg, gBattleAnimAttacker);
if (IsContest())
position = 0;
position = B_POSITION_PLAYER_LEFT;
else
position = GetBattlerPosition(gBattleAnimAttacker);

View File

@ -924,13 +924,13 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform
if (IsContest())
{
position = 0;
position = B_POSITION_PLAYER_LEFT;
targetSpecies = gContestResources->moveAnim->targetSpecies;
personalityValue = gContestResources->moveAnim->personality;
otId = gContestResources->moveAnim->otId;
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[targetSpecies],
gMonSpritesGfxPtr->sprites.ptr[0],
gMonSpritesGfxPtr->sprites.ptr[position],
targetSpecies,
gContestResources->moveAnim->targetPersonality);
}
@ -1001,7 +1001,7 @@ void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite)
if (!loadMonSprite)
{
if (IsContest())
position = 0;
position = B_POSITION_PLAYER_LEFT;
else
position = GetBattlerPosition(battlerId);
@ -1260,11 +1260,11 @@ void AllocateMonSpritesGfx(void)
for (j = 0; j < 4; j++)
{
gMonSpritesGfxPtr->field_74[i][j].data = gMonSpritesGfxPtr->sprites.ptr[i] + (j * MON_PIC_SIZE);
gMonSpritesGfxPtr->field_74[i][j].size = MON_PIC_SIZE;
gMonSpritesGfxPtr->frameImages[i][j].data = gMonSpritesGfxPtr->sprites.ptr[i] + (j * MON_PIC_SIZE);
gMonSpritesGfxPtr->frameImages[i][j].size = MON_PIC_SIZE;
}
gMonSpritesGfxPtr->templates[i].images = gMonSpritesGfxPtr->field_74[i];
gMonSpritesGfxPtr->templates[i].images = gMonSpritesGfxPtr->frameImages[i];
}
gMonSpritesGfxPtr->barFontGfx = AllocZeroed(0x1000);
@ -1275,17 +1275,14 @@ void FreeMonSpritesGfx(void)
if (gMonSpritesGfxPtr == NULL)
return;
if (gMonSpritesGfxPtr->buffer != NULL)
FREE_AND_SET_NULL(gMonSpritesGfxPtr->buffer);
if (gMonSpritesGfxPtr->field_178 != NULL)
FREE_AND_SET_NULL(gMonSpritesGfxPtr->field_178);
TRY_FREE_AND_SET_NULL(gMonSpritesGfxPtr->buffer);
TRY_FREE_AND_SET_NULL(gMonSpritesGfxPtr->unusedPtr);
FREE_AND_SET_NULL(gMonSpritesGfxPtr->barFontGfx);
FREE_AND_SET_NULL(gMonSpritesGfxPtr->firstDecompressed);
gMonSpritesGfxPtr->sprites.ptr[0] = NULL;
gMonSpritesGfxPtr->sprites.ptr[1] = NULL;
gMonSpritesGfxPtr->sprites.ptr[2] = NULL;
gMonSpritesGfxPtr->sprites.ptr[3] = NULL;
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT] = NULL;
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT] = NULL;
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_RIGHT] = NULL;
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT] = NULL;
FREE_AND_SET_NULL(gMonSpritesGfxPtr);
}

View File

@ -3122,12 +3122,12 @@ static u8 CreateContestantSprite(u16 species, u32 otId, u32 personality, u32 ind
species = SanitizeSpecies(species);
if (index == gContestPlayerMonIndex)
HandleLoadSpecialPokePic_2(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[0], species, personality);
HandleLoadSpecialPokePic_2(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT], species, personality);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[0], species, personality);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonBackPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT], species, personality);
LoadCompressedPalette(GetMonSpritePalFromSpeciesAndPersonality(species, otId, personality), 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(species, 0);
SetMultiuseSpriteTemplateToPokemon(species, B_POSITION_PLAYER_LEFT);
spriteId = CreateSprite(&gMultiuseSpriteTemplate, 0x70, GetBattlerSpriteFinal_Y(2, species, FALSE), 30);
gSprites[spriteId].oam.paletteNum = 2;

View File

@ -361,27 +361,27 @@ static void VBlankCB_ContestPainting(void)
TransferPlttBuffer();
}
static void InitContestMonPixels(u16 species, u8 whichSprite)
static void InitContestMonPixels(u16 species, bool8 backPic)
{
const void *pal = GetMonSpritePalFromSpeciesAndPersonality(species, gContestPaintingWinner->trainerId, gContestPaintingWinner->personality);
LZDecompressVram(pal, gContestPaintingMonPalette);
if (whichSprite == 0)
if (!backPic)
{
HandleLoadSpecialPokePic_DontHandleDeoxys(
&gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[1],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
species,
gContestPaintingWinner->personality);
_InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[1], gContestPaintingMonPalette, (void *)gContestMonPixels);
_InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], gContestPaintingMonPalette, (void *)gContestMonPixels);
}
else
{
HandleLoadSpecialPokePic_DontHandleDeoxys(
&gMonBackPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[0],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT],
species,
gContestPaintingWinner->personality);
_InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[0], gContestPaintingMonPalette, (void *)gContestMonPixels);
_InitContestMonPixels(gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT], gContestPaintingMonPalette, (void *)gContestMonPixels);
}
}
@ -592,7 +592,7 @@ static void DoContestPaintingImageProcessing(u8 imageEffect)
static void CreateContestPaintingPicture(u8 contestWinnerId, bool8 isForArtist)
{
AllocPaintingResources();
InitContestMonPixels(gContestPaintingWinner->species, 0);
InitContestMonPixels(gContestPaintingWinner->species, FALSE);
DoContestPaintingImageProcessing(GetImageEffectForContestWinner(contestWinnerId));
InitPaintingMonOamData(contestWinnerId);
LoadContestPaintingFrame(contestWinnerId, isForArtist);

View File

@ -893,7 +893,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId)
{
HandleLoadSpecialPokePic_2(
&gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[1],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
species,
personality);
}
@ -901,7 +901,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId)
{
HandleLoadSpecialPokePic_DontHandleDeoxys(
&gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[1],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
species,
personality);
}
@ -2581,13 +2581,13 @@ void ShowContestEntryMonPic(void)
gTasks[taskId].data[0] = 0;
gTasks[taskId].data[1] = species;
if (gSpecialVar_0x8006 == gContestPlayerMonIndex)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], species, personality);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], species, personality);
palette = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality);
LoadCompressedSpritePalette(palette);
SetMultiuseSpriteTemplateToPokemon(species, 1);
SetMultiuseSpriteTemplateToPokemon(species, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.paletteTag = palette->tag;
spriteId = CreateSprite(&gMultiuseSpriteTemplate, (left + 1) * 8 + 32, (top * 8) + 40, 0);

View File

@ -411,21 +411,22 @@ bool8 CheckDaycareMonReceivedMail(void)
return _CheckDaycareMonReceivedMail(&gSaveBlock1Ptr->daycare, gSpecialVar_0x8004);
}
static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID, u16* speciesLoc)
static u8 EggHatchCreateMonSprite(u8 useAlt, u8 switchID, u8 pokeID, u16* speciesLoc)
{
u8 r5 = 0;
u8 position = 0;
u8 spriteID = 0;
struct Pokemon* mon = NULL;
if (a0 == 0)
if (useAlt == FALSE)
{
mon = &gPlayerParty[pokeID];
r5 = 1;
position = B_POSITION_OPPONENT_LEFT;
}
if (a0 == 1)
if (useAlt == TRUE)
{
// Alternate sprite allocation position. Never reached.
mon = &gPlayerParty[pokeID];
r5 = 3;
position = B_POSITION_OPPONENT_RIGHT;
}
switch (switchID)
{
@ -434,14 +435,14 @@ static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID, u16* speciesLoc
u16 species = GetMonData(mon, MON_DATA_SPECIES);
u32 pid = GetMonData(mon, MON_DATA_PERSONALITY);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr [(a0 * 2) + 1],
gMonSpritesGfxPtr->sprites.ptr[(useAlt * 2) + B_POSITION_OPPONENT_LEFT],
species, pid);
LoadCompressedSpritePalette(GetMonSpritePalStruct(mon));
*speciesLoc = species;
}
break;
case 1:
SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, r5);
SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, position);
spriteID = CreateSprite(&gMultiuseSpriteTemplate, 120, 75, 6);
gSprites[spriteID].invisible = TRUE;
gSprites[spriteID].callback = SpriteCallbackDummy;
@ -535,11 +536,11 @@ static void CB2_EggHatch_0(void)
gMain.state++;
break;
case 5:
EggHatchCreateMonSprite(0, 0, sEggHatchData->eggPartyID, &sEggHatchData->species);
EggHatchCreateMonSprite(FALSE, 0, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++;
break;
case 6:
sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, sEggHatchData->eggPartyID, &sEggHatchData->species);
sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(FALSE, 1, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++;
break;
case 7:

View File

@ -260,12 +260,12 @@ void EvolutionScene(struct Pokemon* mon, u16 postEvoSpecies, bool8 canStopEvo, u
trainerId = GetMonData(mon, MON_DATA_OT_ID);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
DecompressPicFromTable_2(&gMonFrontPicTable[currSpecies],
gMonSpritesGfxPtr->sprites.ptr[1],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
currSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(currSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x110, 0x20);
SetMultiuseSpriteTemplateToPokemon(currSpecies, 1);
SetMultiuseSpriteTemplateToPokemon(currSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->preEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
@ -275,12 +275,12 @@ void EvolutionScene(struct Pokemon* mon, u16 postEvoSpecies, bool8 canStopEvo, u
// postEvo sprite
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 3);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_RIGHT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
gSprites[ID].callback = SpriteCallbackDummy_2;
@ -352,13 +352,13 @@ static void CB2_EvolutionSceneLoadGraphics(void)
gReservedSpritePaletteCount = 4;
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 3);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_RIGHT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
@ -424,7 +424,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void)
u32 trainerId = GetMonData(mon, MON_DATA_OT_ID);
u32 personality = GetMonData(mon, MON_DATA_PERSONALITY);
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20);
@ -435,7 +435,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void)
{
u8 ID;
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 1);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
@ -488,13 +488,13 @@ void TradeEvolutionScene(struct Pokemon* mon, u16 postEvoSpecies, u8 preEvoSprit
sEvoStructPtr->preEvoSpriteId = preEvoSpriteId;
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[1],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 1);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);

View File

@ -161,10 +161,7 @@
* - Destroys itself when done.
*/
// These two defines are used with the sCurrItemAndOptionsMenuCheck,
// to distinguish between its two parts.
#define OPTION_MENU_FLAG 0x8000
#define CURRENT_ITEM_MASK 0x7FFF
#define OPTION_MENU_FLAG (1 << 15)
// Static type declarations
@ -685,7 +682,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId)
break;
}
}
sCurrItemAndOptionMenuCheck &= CURRENT_ITEM_MASK; // turn off the "returning from options menu" flag
sCurrItemAndOptionMenuCheck &= ~OPTION_MENU_FLAG; // turn off the "returning from options menu" flag
tCurrItem = sCurrItemAndOptionMenuCheck;
tItemCount = tMenuType + 2;
}

View File

@ -731,7 +731,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
// Load mon gfx
species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], species, personality);
sPokeblockFeed->loadGfxState++;
break;
case 1:
@ -742,7 +742,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality);
LoadCompressedSpritePalette(palette);
SetMultiuseSpriteTemplateToPokemon(palette->tag, 1);
SetMultiuseSpriteTemplateToPokemon(palette->tag, B_POSITION_OPPONENT_LEFT);
sPokeblockFeed->loadGfxState++;
break;
case 2:

View File

@ -69,7 +69,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0;
EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0};
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0};
EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL};
EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManagers[MON_SPR_GFX_MANAGERS_COUNT] = {NULL};
// const rom data
#include "data/battle_moves.h"
@ -2084,7 +2084,7 @@ static const struct SpeciesItem sAlteringCaveWildMonHeldItems[] =
{SPECIES_SMEARGLE, ITEM_SALAC_BERRY},
};
static const struct OamData sOamData_8329F20 =
static const struct OamData sOamData_64x64 =
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
@ -2101,11 +2101,11 @@ static const struct OamData sOamData_8329F20 =
.affineParam = 0
};
static const struct SpriteTemplate gUnknown_08329F28 =
static const struct SpriteTemplate sSpriteTemplate_64x64 =
{
.tileTag = TAG_NONE,
.paletteTag = TAG_NONE,
.oam = &sOamData_8329F20,
.oam = &sOamData_64x64,
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
@ -3425,10 +3425,10 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition)
{
if (gMonSpritesGfxPtr != NULL)
gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition];
else if (gUnknown_020249B4[0])
gMultiuseSpriteTemplate = gUnknown_020249B4[0]->templates[battlerPosition];
else if (gUnknown_020249B4[1])
gMultiuseSpriteTemplate = gUnknown_020249B4[1]->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A]->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B]->templates[battlerPosition];
else
gMultiuseSpriteTemplate = gBattlerSpriteTemplates[battlerPosition];
@ -5655,11 +5655,13 @@ u16 SpeciesToCryId(u16 species)
} \
}
// Same as DrawSpindaSpots but attempts to discern for itself whether or
// not it's the front pic.
static void DrawSpindaSpotsUnused(u16 species, u32 personality, u8 *dest)
{
if (species == SPECIES_SPINDA
&& dest != gMonSpritesGfxPtr->sprites.ptr[0]
&& dest != gMonSpritesGfxPtr->sprites.ptr[2])
&& dest != gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT]
&& dest != gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_RIGHT])
DRAW_SPINDA_SPOTS;
}
@ -6788,9 +6790,9 @@ const u8 *GetTrainerNameFromId(u16 trainerId)
bool8 HasTwoFramesAnimation(u16 species)
{
return (species != SPECIES_CASTFORM
&& species != SPECIES_DEOXYS
&& species != SPECIES_SPINDA
&& species != SPECIES_UNOWN);
&& species != SPECIES_DEOXYS
&& species != SPECIES_SPINDA
&& species != SPECIES_UNOWN);
}
static bool8 ShouldSkipFriendshipChange(void)
@ -6802,174 +6804,186 @@ static bool8 ShouldSkipFriendshipChange(void)
return FALSE;
}
static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
// The below functions are for the 'MonSpritesGfxManager', a method of allocating
// space for Pokémon sprites. These are only used for the summary screen Pokémon
// sprites (unless gMonSpritesGfxPtr is in use), but were set up for more general use.
// Only the 'default' mode (MON_SPR_GFX_MODE_NORMAL) is used, which is set
// up to allocate 4 sprites using the battler sprite templates (gBattlerSpriteTemplates).
// MON_SPR_GFX_MODE_BATTLE is identical but never used.
// MON_SPR_GFX_MODE_FULL_PARTY is set up to allocate 7 sprites (party + trainer?)
// using a generic 64x64 template, and is also never used.
// Between the unnecessarily large sizes below, a mistake allocating the spritePointers
// field, and the fact that ultimately only 1 of the 4 sprite positions is used, this
// system wastes a good deal of memory.
#define ALLOC_FAIL_BUFFER (1 << 0)
#define ALLOC_FAIL_STRUCT (1 << 1)
#define GFX_MANAGER_ACTIVE 0xA3 // Arbitrary value
#define GFX_MANAGER_SPR_SIZE (MON_PIC_SIZE * 4) // * 4 is unnecessary, MON_PIC_SIZE is sufficient
#define GFX_MANAGER_NUM_FRAMES 4 // Only 2 frames are needed
static void InitMonSpritesGfx_Battle(struct MonSpritesGfxManager* gfx)
{
u16 i, j;
for (i = 0; i < structPtr->field_0_0; i++)
for (i = 0; i < gfx->numSprites; i++)
{
structPtr->templates[i] = gBattlerSpriteTemplates[i];
for (j = 0; j < structPtr->field_1; j++)
{
structPtr->frameImages[i * structPtr->field_1 + j].data = &structPtr->byteArrays[i][j * 0x800];
}
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_1];
gfx->templates[i] = gBattlerSpriteTemplates[i];
for (j = 0; j < gfx->numFrames; j++)
gfx->frameImages[i * gfx->numFrames + j].data = &gfx->spritePointers[i][j * MON_PIC_SIZE];
gfx->templates[i].images = &gfx->frameImages[i * gfx->numFrames];
}
}
static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr)
static void InitMonSpritesGfx_FullParty(struct MonSpritesGfxManager* gfx)
{
u16 i, j;
for (i = 0; i < structPtr->field_0_0; i++)
for (i = 0; i < gfx->numSprites; i++)
{
structPtr->templates[i] = gUnknown_08329F28;
for (j = 0; j < structPtr->field_1; j++)
{
structPtr->frameImages[i * structPtr->field_0_0 + j].data = &structPtr->byteArrays[i][j * 0x800];
}
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_0_0];
structPtr->templates[i].anims = gAnims_MonPic;
structPtr->templates[i].paletteTag = i;
gfx->templates[i] = sSpriteTemplate_64x64;
for (j = 0; j < gfx->numFrames; j++)
gfx->frameImages[i * gfx->numSprites + j].data = &gfx->spritePointers[i][j * MON_PIC_SIZE];
gfx->templates[i].images = &gfx->frameImages[i * gfx->numSprites];
gfx->templates[i].anims = gAnims_MonPic;
gfx->templates[i].paletteTag = i;
}
}
struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
{
u8 i;
u8 flags;
struct Unknown_806F160_Struct *structPtr;
u8 failureFlags;
struct MonSpritesGfxManager *gfx;
flags = 0;
id %= 2;
structPtr = AllocZeroed(sizeof(*structPtr));
if (structPtr == NULL)
failureFlags = 0;
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = AllocZeroed(sizeof(*gfx));
if (gfx == NULL)
return NULL;
switch (arg1)
switch (mode)
{
case 2:
structPtr->field_0_0 = 7;
structPtr->field_0_1 = 7;
structPtr->field_1 = 4;
structPtr->field_3_0 = 1;
structPtr->field_3_1 = 2;
case MON_SPR_GFX_MODE_FULL_PARTY:
gfx->numSprites = PARTY_SIZE + 1;
gfx->numSprites2 = PARTY_SIZE + 1;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_FULL_PARTY;
break;
case 0:
// case MON_SPR_GFX_MODE_BATTLE:
case MON_SPR_GFX_MODE_NORMAL:
default:
structPtr->field_0_0 = 4;
structPtr->field_0_1 = 4;
structPtr->field_1 = 4;
structPtr->field_3_0 = 1;
structPtr->field_3_1 = 0;
gfx->numSprites = MAX_BATTLERS_COUNT;
gfx->numSprites2 = MAX_BATTLERS_COUNT;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_NORMAL;
break;
}
structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0);
structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32);
if (structPtr->bytes == NULL || structPtr->byteArrays == NULL)
// Set up sprite / sprite pointer buffers
gfx->spriteBuffer = AllocZeroed(gfx->dataSize * GFX_MANAGER_SPR_SIZE * gfx->numSprites);
gfx->spritePointers = AllocZeroed(gfx->numSprites * 32); // ? Only * 4 is necessary, perhaps they were thinking bits.
if (gfx->spriteBuffer == NULL || gfx->spritePointers == NULL)
{
flags |= 1;
failureFlags |= ALLOC_FAIL_BUFFER;
}
else
{
for (i = 0; i < structPtr->field_0_0; i++)
structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 13));
for (i = 0; i < gfx->numSprites; i++)
gfx->spritePointers[i] = gfx->spriteBuffer + (gfx->dataSize * GFX_MANAGER_SPR_SIZE * i);
}
structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0);
structPtr->frameImages = AllocZeroed(sizeof(struct SpriteFrameImage) * structPtr->field_0_0 * structPtr->field_1);
if (structPtr->templates == NULL || structPtr->frameImages == NULL)
// Set up sprite structs
gfx->templates = AllocZeroed(sizeof(struct SpriteTemplate) * gfx->numSprites);
gfx->frameImages = AllocZeroed(sizeof(struct SpriteFrameImage) * gfx->numSprites * gfx->numFrames);
if (gfx->templates == NULL || gfx->frameImages == NULL)
{
flags |= 2;
failureFlags |= ALLOC_FAIL_STRUCT;
}
else
{
for (i = 0; i < structPtr->field_1 * structPtr->field_0_0; i++)
structPtr->frameImages[i].size = 0x800;
for (i = 0; i < gfx->numFrames * gfx->numSprites; i++)
gfx->frameImages[i].size = MON_PIC_SIZE;
switch (structPtr->field_3_1)
switch (gfx->mode)
{
case 2:
sub_806F1FC(structPtr);
case MON_SPR_GFX_MODE_FULL_PARTY:
InitMonSpritesGfx_FullParty(gfx);
break;
case 0:
case 1:
case MON_SPR_GFX_MODE_NORMAL:
case MON_SPR_GFX_MODE_BATTLE:
default:
sub_806F160(structPtr);
InitMonSpritesGfx_Battle(gfx);
break;
}
}
if (flags & 2)
// If either of the allocations failed free their respective members
if (failureFlags & ALLOC_FAIL_STRUCT)
{
if (structPtr->frameImages != NULL)
FREE_AND_SET_NULL(structPtr->frameImages);
if (structPtr->templates != NULL)
FREE_AND_SET_NULL(structPtr->templates);
TRY_FREE_AND_SET_NULL(gfx->frameImages);
TRY_FREE_AND_SET_NULL(gfx->templates);
}
if (flags & 1)
if (failureFlags & ALLOC_FAIL_BUFFER)
{
if (structPtr->byteArrays != NULL)
FREE_AND_SET_NULL(structPtr->byteArrays);
if (structPtr->bytes != NULL)
FREE_AND_SET_NULL(structPtr->bytes);
TRY_FREE_AND_SET_NULL(gfx->spritePointers);
TRY_FREE_AND_SET_NULL(gfx->spriteBuffer);
}
if (flags)
if (failureFlags)
{
memset(structPtr, 0, sizeof(*structPtr));
Free(structPtr);
// Clear, something failed to allocate
memset(gfx, 0, sizeof(*gfx));
Free(gfx);
}
else
{
structPtr->magic = 0xA3;
gUnknown_020249B4[id] = structPtr;
gfx->active = GFX_MANAGER_ACTIVE;
sMonSpritesGfxManagers[managerId] = gfx;
}
return gUnknown_020249B4[id];
return sMonSpritesGfxManagers[managerId];
}
void sub_806F47C(u8 id)
void DestroyMonSpritesGfxManager(u8 managerId)
{
struct Unknown_806F160_Struct *structPtr;
struct MonSpritesGfxManager *gfx;
id %= 2;
structPtr = gUnknown_020249B4[id];
if (structPtr == NULL)
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = sMonSpritesGfxManagers[managerId];
if (gfx == NULL)
return;
if (structPtr->magic != 0xA3)
if (gfx->active != GFX_MANAGER_ACTIVE)
{
memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct));
memset(gfx, 0, sizeof(*gfx));
}
else
{
if (structPtr->frameImages != NULL)
FREE_AND_SET_NULL(structPtr->frameImages);
if (structPtr->templates != NULL)
FREE_AND_SET_NULL(structPtr->templates);
if (structPtr->byteArrays != NULL)
FREE_AND_SET_NULL(structPtr->byteArrays);
if (structPtr->bytes != NULL)
FREE_AND_SET_NULL(structPtr->bytes);
memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct));
Free(structPtr);
TRY_FREE_AND_SET_NULL(gfx->frameImages);
TRY_FREE_AND_SET_NULL(gfx->templates);
TRY_FREE_AND_SET_NULL(gfx->spritePointers);
TRY_FREE_AND_SET_NULL(gfx->spriteBuffer);
memset(gfx, 0, sizeof(*gfx));
Free(gfx);
}
}
u8 *sub_806F4F8(u8 id, u8 arg1)
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum)
{
struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2];
if (structPtr->magic != 0xA3)
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManagers[managerId % MON_SPR_GFX_MANAGERS_COUNT];
if (gfx->active != GFX_MANAGER_ACTIVE)
{
return NULL;
}
else
{
if (arg1 >= structPtr->field_0_0)
arg1 = 0;
if (spriteNum >= gfx->numSprites)
spriteNum = 0;
return structPtr->byteArrays[arg1];
return gfx->spritePointers[spriteNum];
}
}

View File

@ -1111,7 +1111,7 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex,
SummaryScreen_SetAnimDelayTaskId(TASK_NONE);
if (gMonSpritesGfxPtr == NULL)
sub_806F2AC(0, 0);
CreateMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A, MON_SPR_GFX_MODE_NORMAL);
SetMainCallback2(CB2_InitSummaryScreen);
}
@ -1500,7 +1500,7 @@ static void CloseSummaryScreen(u8 taskId)
StopCryAndClearCrySongs();
m4aMPlayVolumeControl(&gMPlayInfo_BGM, 0xFFFF, 0x100);
if (gMonSpritesGfxPtr == NULL)
sub_806F47C(0);
DestroyMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A);
FreeSummaryScreen();
DestroyTask(taskId);
}
@ -3873,25 +3873,43 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
if (gMain.inBattle)
{
if (ShouldIgnoreDeoxysForm(3, sMonSummaryScreen->curMonIndex))
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
summary->species2,
summary->pid);
else
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
summary->species2,
summary->pid);
}
else
{
if (gMonSpritesGfxPtr != NULL)
{
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
summary->species2,
summary->pid);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites.ptr[1], summary->species2, summary->pid);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
summary->species2,
summary->pid);
}
else
{
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
}
}
(*state)++;
@ -3899,7 +3917,7 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
case 1:
pal = GetMonSpritePalStructFromOtIdPersonality(summary->species2, summary->OTID, summary->pid);
LoadCompressedSpritePalette(pal);
SetMultiuseSpriteTemplateToPokemon(pal->tag, 1);
SetMultiuseSpriteTemplateToPokemon(pal->tag, B_POSITION_OPPONENT_LEFT);
(*state)++;
return 0xFF;
}

View File

@ -2770,9 +2770,9 @@ static void LoadTradeMonPic(u8 whichParty, u8 state)
personality = GetMonData(mon, MON_DATA_PERSONALITY);
if (whichParty == TRADE_PLAYER)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[1], species, personality);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT], species, personality);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[whichParty * 2 + 1], species, personality);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites.ptr[whichParty * 2 + B_POSITION_OPPONENT_LEFT], species, personality);
LoadCompressedSpritePalette(GetMonSpritePalStruct(mon));
sTradeData->monSpecies[whichParty] = species;
@ -3767,7 +3767,7 @@ static bool8 AnimateTradeSequenceCable(void)
case TS_STATE_POKEBALL_ARRIVE_WAIT:
if (gSprites[sTradeData->bouncingPokeballSpriteId].callback == SpriteCallbackDummy)
{
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[3], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]);
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT], sTradeData->monSpecies[TRADE_PARTNER], sTradeData->monPersonalities[TRADE_PARTNER]);
sTradeData->state++;
}
break;
@ -4265,7 +4265,7 @@ static bool8 AnimateTradeSequenceWireless(void)
if (gSprites[sTradeData->bouncingPokeballSpriteId].callback == SpriteCallbackDummy)
{
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[sTradeData->monSpecies[TRADE_PARTNER]],
gMonSpritesGfxPtr->sprites.ptr[3],
gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
sTradeData->monSpecies[TRADE_PARTNER],
sTradeData->monPersonalities[TRADE_PARTNER]);
sTradeData->state++;