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

View File

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

View File

@ -122,20 +122,32 @@ struct Pokemon
u16 spDefense; u16 spDefense;
}; };
struct Unknown_806F160_Struct struct MonSpritesGfxManager
{ {
u32 field_0_0:4; u32 numSprites:4;
u32 field_0_1:4; u32 numSprites2:4; // Never read
u32 field_1:8; u32 numFrames:8;
u16 magic:8; u32 active:8;
u32 field_3_0:4; u32 dataSize:4;
u32 field_3_1:4; u32 mode:4; // MON_SPR_GFX_MODE_*
void *bytes; void *spriteBuffer;
u8 **byteArrays; u8 **spritePointers;
struct SpriteTemplate *templates; struct SpriteTemplate *templates;
struct SpriteFrameImage *frameImages; 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 struct BattlePokemon
{ {
/*0x00*/ u16 species; /*0x00*/ u16 species;
@ -422,8 +434,8 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality);
const u8 *GetTrainerClassNameFromId(u16 trainerId); const u8 *GetTrainerClassNameFromId(u16 trainerId);
const u8 *GetTrainerNameFromId(u16 trainerId); const u8 *GetTrainerNameFromId(u16 trainerId);
bool8 HasTwoFramesAnimation(u16 species); bool8 HasTwoFramesAnimation(u16 species);
struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1); struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode);
void sub_806F47C(u8 id); void DestroyMonSpritesGfxManager(u8 managerId);
u8 *sub_806F4F8(u8 id, u8 arg1); u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum);
#endif // GUARD_POKEMON_H #endif // GUARD_POKEMON_H

View File

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

View File

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

View File

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

View File

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

View File

@ -893,7 +893,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId)
{ {
HandleLoadSpecialPokePic_2( HandleLoadSpecialPokePic_2(
&gMonFrontPicTable[species], &gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[1], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
species, species,
personality); personality);
} }
@ -901,7 +901,7 @@ static void Task_ShowWinnerMonBanner(u8 taskId)
{ {
HandleLoadSpecialPokePic_DontHandleDeoxys( HandleLoadSpecialPokePic_DontHandleDeoxys(
&gMonFrontPicTable[species], &gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr[1], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
species, species,
personality); personality);
} }
@ -2581,13 +2581,13 @@ void ShowContestEntryMonPic(void)
gTasks[taskId].data[0] = 0; gTasks[taskId].data[0] = 0;
gTasks[taskId].data[1] = species; gTasks[taskId].data[1] = species;
if (gSpecialVar_0x8006 == gContestPlayerMonIndex) 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 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); palette = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality);
LoadCompressedSpritePalette(palette); LoadCompressedSpritePalette(palette);
SetMultiuseSpriteTemplateToPokemon(species, 1); SetMultiuseSpriteTemplateToPokemon(species, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.paletteTag = palette->tag; gMultiuseSpriteTemplate.paletteTag = palette->tag;
spriteId = CreateSprite(&gMultiuseSpriteTemplate, (left + 1) * 8 + 32, (top * 8) + 40, 0); 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); 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; u8 spriteID = 0;
struct Pokemon* mon = NULL; struct Pokemon* mon = NULL;
if (a0 == 0) if (useAlt == FALSE)
{ {
mon = &gPlayerParty[pokeID]; 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]; mon = &gPlayerParty[pokeID];
r5 = 3; position = B_POSITION_OPPONENT_RIGHT;
} }
switch (switchID) switch (switchID)
{ {
@ -434,14 +435,14 @@ static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID, u16* speciesLoc
u16 species = GetMonData(mon, MON_DATA_SPECIES); u16 species = GetMonData(mon, MON_DATA_SPECIES);
u32 pid = GetMonData(mon, MON_DATA_PERSONALITY); u32 pid = GetMonData(mon, MON_DATA_PERSONALITY);
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species],
gMonSpritesGfxPtr->sprites.ptr [(a0 * 2) + 1], gMonSpritesGfxPtr->sprites.ptr[(useAlt * 2) + B_POSITION_OPPONENT_LEFT],
species, pid); species, pid);
LoadCompressedSpritePalette(GetMonSpritePalStruct(mon)); LoadCompressedSpritePalette(GetMonSpritePalStruct(mon));
*speciesLoc = species; *speciesLoc = species;
} }
break; break;
case 1: case 1:
SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, r5); SetMultiuseSpriteTemplateToPokemon(GetMonSpritePalStruct(mon)->tag, position);
spriteID = CreateSprite(&gMultiuseSpriteTemplate, 120, 75, 6); spriteID = CreateSprite(&gMultiuseSpriteTemplate, 120, 75, 6);
gSprites[spriteID].invisible = TRUE; gSprites[spriteID].invisible = TRUE;
gSprites[spriteID].callback = SpriteCallbackDummy; gSprites[spriteID].callback = SpriteCallbackDummy;
@ -535,11 +536,11 @@ static void CB2_EggHatch_0(void)
gMain.state++; gMain.state++;
break; break;
case 5: case 5:
EggHatchCreateMonSprite(0, 0, sEggHatchData->eggPartyID, &sEggHatchData->species); EggHatchCreateMonSprite(FALSE, 0, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++; gMain.state++;
break; break;
case 6: case 6:
sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, sEggHatchData->eggPartyID, &sEggHatchData->species); sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(FALSE, 1, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++; gMain.state++;
break; break;
case 7: 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); trainerId = GetMonData(mon, MON_DATA_OT_ID);
personality = GetMonData(mon, MON_DATA_PERSONALITY); personality = GetMonData(mon, MON_DATA_PERSONALITY);
DecompressPicFromTable_2(&gMonFrontPicTable[currSpecies], DecompressPicFromTable_2(&gMonFrontPicTable[currSpecies],
gMonSpritesGfxPtr->sprites.ptr[1], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
currSpecies); currSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(currSpecies, trainerId, personality); pokePal = GetMonSpritePalStructFromOtIdPersonality(currSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x110, 0x20); LoadCompressedPalette(pokePal->data, 0x110, 0x20);
SetMultiuseSpriteTemplateToPokemon(currSpecies, 1); SetMultiuseSpriteTemplateToPokemon(currSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->preEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); sEvoStructPtr->preEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
@ -275,12 +275,12 @@ void EvolutionScene(struct Pokemon* mon, u16 postEvoSpecies, bool8 canStopEvo, u
// postEvo sprite // postEvo sprite
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies); postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20); LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 3); SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_RIGHT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
gSprites[ID].callback = SpriteCallbackDummy_2; gSprites[ID].callback = SpriteCallbackDummy_2;
@ -352,13 +352,13 @@ static void CB2_EvolutionSceneLoadGraphics(void)
gReservedSpritePaletteCount = 4; gReservedSpritePaletteCount = 4;
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies); postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20); LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 3); SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_RIGHT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); 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 trainerId = GetMonData(mon, MON_DATA_OT_ID);
u32 personality = GetMonData(mon, MON_DATA_PERSONALITY); u32 personality = GetMonData(mon, MON_DATA_PERSONALITY);
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[3], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_RIGHT],
postEvoSpecies); postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20); LoadCompressedPalette(pokePal->data, 0x120, 0x20);
@ -435,7 +435,7 @@ static void CB2_TradeEvolutionSceneLoadGraphics(void)
{ {
u8 ID; u8 ID;
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 1); SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);
@ -488,13 +488,13 @@ void TradeEvolutionScene(struct Pokemon* mon, u16 postEvoSpecies, u8 preEvoSprit
sEvoStructPtr->preEvoSpriteId = preEvoSpriteId; sEvoStructPtr->preEvoSpriteId = preEvoSpriteId;
DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies], DecompressPicFromTable_2(&gMonFrontPicTable[postEvoSpecies],
gMonSpritesGfxPtr->sprites.ptr[1], gMonSpritesGfxPtr->sprites.ptr[B_POSITION_OPPONENT_LEFT],
postEvoSpecies); postEvoSpecies);
pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality); pokePal = GetMonSpritePalStructFromOtIdPersonality(postEvoSpecies, trainerId, personality);
LoadCompressedPalette(pokePal->data, 0x120, 0x20); LoadCompressedPalette(pokePal->data, 0x120, 0x20);
SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, 1); SetMultiuseSpriteTemplateToPokemon(postEvoSpecies, B_POSITION_OPPONENT_LEFT);
gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable; gMultiuseSpriteTemplate.affineAnims = gDummySpriteAffineAnimTable;
sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30); sEvoStructPtr->postEvoSpriteId = ID = CreateSprite(&gMultiuseSpriteTemplate, 120, 64, 30);

View File

@ -161,10 +161,7 @@
* - Destroys itself when done. * - Destroys itself when done.
*/ */
// These two defines are used with the sCurrItemAndOptionsMenuCheck, #define OPTION_MENU_FLAG (1 << 15)
// to distinguish between its two parts.
#define OPTION_MENU_FLAG 0x8000
#define CURRENT_ITEM_MASK 0x7FFF
// Static type declarations // Static type declarations
@ -685,7 +682,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId)
break; 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; tCurrItem = sCurrItemAndOptionMenuCheck;
tItemCount = tMenuType + 2; tItemCount = tMenuType + 2;
} }

View File

@ -731,7 +731,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
// Load mon gfx // Load mon gfx
species = GetMonData(mon, MON_DATA_SPECIES2); species = GetMonData(mon, MON_DATA_SPECIES2);
personality = GetMonData(mon, MON_DATA_PERSONALITY); 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++; sPokeblockFeed->loadGfxState++;
break; break;
case 1: case 1:
@ -742,7 +742,7 @@ static bool8 LoadMonAndSceneGfx(struct Pokemon *mon)
palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality); palette = GetMonSpritePalStructFromOtIdPersonality(species, trainerId, personality);
LoadCompressedSpritePalette(palette); LoadCompressedSpritePalette(palette);
SetMultiuseSpriteTemplateToPokemon(palette->tag, 1); SetMultiuseSpriteTemplateToPokemon(palette->tag, B_POSITION_OPPONENT_LEFT);
sPokeblockFeed->loadGfxState++; sPokeblockFeed->loadGfxState++;
break; break;
case 2: 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 gPlayerParty[PARTY_SIZE] = {0};
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0}; EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {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 // const rom data
#include "data/battle_moves.h" #include "data/battle_moves.h"
@ -2084,7 +2084,7 @@ static const struct SpeciesItem sAlteringCaveWildMonHeldItems[] =
{SPECIES_SMEARGLE, ITEM_SALAC_BERRY}, {SPECIES_SMEARGLE, ITEM_SALAC_BERRY},
}; };
static const struct OamData sOamData_8329F20 = static const struct OamData sOamData_64x64 =
{ {
.y = 0, .y = 0,
.affineMode = ST_OAM_AFFINE_OFF, .affineMode = ST_OAM_AFFINE_OFF,
@ -2101,11 +2101,11 @@ static const struct OamData sOamData_8329F20 =
.affineParam = 0 .affineParam = 0
}; };
static const struct SpriteTemplate gUnknown_08329F28 = static const struct SpriteTemplate sSpriteTemplate_64x64 =
{ {
.tileTag = TAG_NONE, .tileTag = TAG_NONE,
.paletteTag = TAG_NONE, .paletteTag = TAG_NONE,
.oam = &sOamData_8329F20, .oam = &sOamData_64x64,
.anims = gDummySpriteAnimTable, .anims = gDummySpriteAnimTable,
.images = NULL, .images = NULL,
.affineAnims = gDummySpriteAffineAnimTable, .affineAnims = gDummySpriteAffineAnimTable,
@ -3425,10 +3425,10 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition)
{ {
if (gMonSpritesGfxPtr != NULL) if (gMonSpritesGfxPtr != NULL)
gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition]; gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition];
else if (gUnknown_020249B4[0]) else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A])
gMultiuseSpriteTemplate = gUnknown_020249B4[0]->templates[battlerPosition]; gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A]->templates[battlerPosition];
else if (gUnknown_020249B4[1]) else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B])
gMultiuseSpriteTemplate = gUnknown_020249B4[1]->templates[battlerPosition]; gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B]->templates[battlerPosition];
else else
gMultiuseSpriteTemplate = gBattlerSpriteTemplates[battlerPosition]; 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) static void DrawSpindaSpotsUnused(u16 species, u32 personality, u8 *dest)
{ {
if (species == SPECIES_SPINDA if (species == SPECIES_SPINDA
&& dest != gMonSpritesGfxPtr->sprites.ptr[0] && dest != gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_LEFT]
&& dest != gMonSpritesGfxPtr->sprites.ptr[2]) && dest != gMonSpritesGfxPtr->sprites.ptr[B_POSITION_PLAYER_RIGHT])
DRAW_SPINDA_SPOTS; DRAW_SPINDA_SPOTS;
} }
@ -6788,9 +6790,9 @@ const u8 *GetTrainerNameFromId(u16 trainerId)
bool8 HasTwoFramesAnimation(u16 species) bool8 HasTwoFramesAnimation(u16 species)
{ {
return (species != SPECIES_CASTFORM return (species != SPECIES_CASTFORM
&& species != SPECIES_DEOXYS && species != SPECIES_DEOXYS
&& species != SPECIES_SPINDA && species != SPECIES_SPINDA
&& species != SPECIES_UNOWN); && species != SPECIES_UNOWN);
} }
static bool8 ShouldSkipFriendshipChange(void) static bool8 ShouldSkipFriendshipChange(void)
@ -6802,174 +6804,186 @@ static bool8 ShouldSkipFriendshipChange(void)
return FALSE; 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; u16 i, j;
for (i = 0; i < structPtr->field_0_0; i++) for (i = 0; i < gfx->numSprites; i++)
{ {
structPtr->templates[i] = gBattlerSpriteTemplates[i]; gfx->templates[i] = gBattlerSpriteTemplates[i];
for (j = 0; j < structPtr->field_1; j++) for (j = 0; j < gfx->numFrames; j++)
{ gfx->frameImages[i * gfx->numFrames + j].data = &gfx->spritePointers[i][j * MON_PIC_SIZE];
structPtr->frameImages[i * structPtr->field_1 + j].data = &structPtr->byteArrays[i][j * 0x800];
} gfx->templates[i].images = &gfx->frameImages[i * gfx->numFrames];
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_1];
} }
} }
static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr) static void InitMonSpritesGfx_FullParty(struct MonSpritesGfxManager* gfx)
{ {
u16 i, j; u16 i, j;
for (i = 0; i < structPtr->field_0_0; i++) for (i = 0; i < gfx->numSprites; i++)
{ {
structPtr->templates[i] = gUnknown_08329F28; gfx->templates[i] = sSpriteTemplate_64x64;
for (j = 0; j < structPtr->field_1; j++) for (j = 0; j < gfx->numFrames; j++)
{ gfx->frameImages[i * gfx->numSprites + j].data = &gfx->spritePointers[i][j * MON_PIC_SIZE];
structPtr->frameImages[i * structPtr->field_0_0 + j].data = &structPtr->byteArrays[i][j * 0x800];
} gfx->templates[i].images = &gfx->frameImages[i * gfx->numSprites];
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_0_0]; gfx->templates[i].anims = gAnims_MonPic;
structPtr->templates[i].anims = gAnims_MonPic; gfx->templates[i].paletteTag = i;
structPtr->templates[i].paletteTag = i;
} }
} }
struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
{ {
u8 i; u8 i;
u8 flags; u8 failureFlags;
struct Unknown_806F160_Struct *structPtr; struct MonSpritesGfxManager *gfx;
flags = 0; failureFlags = 0;
id %= 2; managerId %= MON_SPR_GFX_MANAGERS_COUNT;
structPtr = AllocZeroed(sizeof(*structPtr)); gfx = AllocZeroed(sizeof(*gfx));
if (structPtr == NULL) if (gfx == NULL)
return NULL; return NULL;
switch (arg1) switch (mode)
{ {
case 2: case MON_SPR_GFX_MODE_FULL_PARTY:
structPtr->field_0_0 = 7; gfx->numSprites = PARTY_SIZE + 1;
structPtr->field_0_1 = 7; gfx->numSprites2 = PARTY_SIZE + 1;
structPtr->field_1 = 4; gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
structPtr->field_3_0 = 1; gfx->dataSize = 1;
structPtr->field_3_1 = 2; gfx->mode = MON_SPR_GFX_MODE_FULL_PARTY;
break; break;
case 0: // case MON_SPR_GFX_MODE_BATTLE:
case MON_SPR_GFX_MODE_NORMAL:
default: default:
structPtr->field_0_0 = 4; gfx->numSprites = MAX_BATTLERS_COUNT;
structPtr->field_0_1 = 4; gfx->numSprites2 = MAX_BATTLERS_COUNT;
structPtr->field_1 = 4; gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
structPtr->field_3_0 = 1; gfx->dataSize = 1;
structPtr->field_3_1 = 0; gfx->mode = MON_SPR_GFX_MODE_NORMAL;
break; break;
} }
structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0); // Set up sprite / sprite pointer buffers
structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32); gfx->spriteBuffer = AllocZeroed(gfx->dataSize * GFX_MANAGER_SPR_SIZE * gfx->numSprites);
if (structPtr->bytes == NULL || structPtr->byteArrays == NULL) 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 else
{ {
for (i = 0; i < structPtr->field_0_0; i++) for (i = 0; i < gfx->numSprites; i++)
structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 13)); gfx->spritePointers[i] = gfx->spriteBuffer + (gfx->dataSize * GFX_MANAGER_SPR_SIZE * i);
} }
structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0); // Set up sprite structs
structPtr->frameImages = AllocZeroed(sizeof(struct SpriteFrameImage) * structPtr->field_0_0 * structPtr->field_1); gfx->templates = AllocZeroed(sizeof(struct SpriteTemplate) * gfx->numSprites);
if (structPtr->templates == NULL || structPtr->frameImages == NULL) gfx->frameImages = AllocZeroed(sizeof(struct SpriteFrameImage) * gfx->numSprites * gfx->numFrames);
if (gfx->templates == NULL || gfx->frameImages == NULL)
{ {
flags |= 2; failureFlags |= ALLOC_FAIL_STRUCT;
} }
else else
{ {
for (i = 0; i < structPtr->field_1 * structPtr->field_0_0; i++) for (i = 0; i < gfx->numFrames * gfx->numSprites; i++)
structPtr->frameImages[i].size = 0x800; gfx->frameImages[i].size = MON_PIC_SIZE;
switch (structPtr->field_3_1) switch (gfx->mode)
{ {
case 2: case MON_SPR_GFX_MODE_FULL_PARTY:
sub_806F1FC(structPtr); InitMonSpritesGfx_FullParty(gfx);
break; break;
case 0: case MON_SPR_GFX_MODE_NORMAL:
case 1: case MON_SPR_GFX_MODE_BATTLE:
default: default:
sub_806F160(structPtr); InitMonSpritesGfx_Battle(gfx);
break; break;
} }
} }
if (flags & 2) // If either of the allocations failed free their respective members
if (failureFlags & ALLOC_FAIL_STRUCT)
{ {
if (structPtr->frameImages != NULL) TRY_FREE_AND_SET_NULL(gfx->frameImages);
FREE_AND_SET_NULL(structPtr->frameImages); TRY_FREE_AND_SET_NULL(gfx->templates);
if (structPtr->templates != NULL)
FREE_AND_SET_NULL(structPtr->templates);
} }
if (flags & 1) if (failureFlags & ALLOC_FAIL_BUFFER)
{ {
if (structPtr->byteArrays != NULL) TRY_FREE_AND_SET_NULL(gfx->spritePointers);
FREE_AND_SET_NULL(structPtr->byteArrays); TRY_FREE_AND_SET_NULL(gfx->spriteBuffer);
if (structPtr->bytes != NULL)
FREE_AND_SET_NULL(structPtr->bytes);
} }
if (flags) if (failureFlags)
{ {
memset(structPtr, 0, sizeof(*structPtr)); // Clear, something failed to allocate
Free(structPtr); memset(gfx, 0, sizeof(*gfx));
Free(gfx);
} }
else else
{ {
structPtr->magic = 0xA3; gfx->active = GFX_MANAGER_ACTIVE;
gUnknown_020249B4[id] = structPtr; 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; managerId %= MON_SPR_GFX_MANAGERS_COUNT;
structPtr = gUnknown_020249B4[id]; gfx = sMonSpritesGfxManagers[managerId];
if (structPtr == NULL) if (gfx == NULL)
return; 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 else
{ {
TRY_FREE_AND_SET_NULL(gfx->frameImages);
if (structPtr->frameImages != NULL) TRY_FREE_AND_SET_NULL(gfx->templates);
FREE_AND_SET_NULL(structPtr->frameImages); TRY_FREE_AND_SET_NULL(gfx->spritePointers);
if (structPtr->templates != NULL) TRY_FREE_AND_SET_NULL(gfx->spriteBuffer);
FREE_AND_SET_NULL(structPtr->templates); memset(gfx, 0, sizeof(*gfx));
if (structPtr->byteArrays != NULL) Free(gfx);
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);
} }
} }
u8 *sub_806F4F8(u8 id, u8 arg1) u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum)
{ {
struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2]; struct MonSpritesGfxManager *gfx = sMonSpritesGfxManagers[managerId % MON_SPR_GFX_MANAGERS_COUNT];
if (structPtr->magic != 0xA3) if (gfx->active != GFX_MANAGER_ACTIVE)
{ {
return NULL; return NULL;
} }
else else
{ {
if (arg1 >= structPtr->field_0_0) if (spriteNum >= gfx->numSprites)
arg1 = 0; 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); SummaryScreen_SetAnimDelayTaskId(TASK_NONE);
if (gMonSpritesGfxPtr == NULL) if (gMonSpritesGfxPtr == NULL)
sub_806F2AC(0, 0); CreateMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A, MON_SPR_GFX_MODE_NORMAL);
SetMainCallback2(CB2_InitSummaryScreen); SetMainCallback2(CB2_InitSummaryScreen);
} }
@ -1500,7 +1500,7 @@ static void CloseSummaryScreen(u8 taskId)
StopCryAndClearCrySongs(); StopCryAndClearCrySongs();
m4aMPlayVolumeControl(&gMPlayInfo_BGM, 0xFFFF, 0x100); m4aMPlayVolumeControl(&gMPlayInfo_BGM, 0xFFFF, 0x100);
if (gMonSpritesGfxPtr == NULL) if (gMonSpritesGfxPtr == NULL)
sub_806F47C(0); DestroyMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A);
FreeSummaryScreen(); FreeSummaryScreen();
DestroyTask(taskId); DestroyTask(taskId);
} }
@ -3873,25 +3873,43 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
if (gMain.inBattle) if (gMain.inBattle)
{ {
if (ShouldIgnoreDeoxysForm(3, sMonSummaryScreen->curMonIndex)) 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 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 else
{ {
if (gMonSpritesGfxPtr != NULL) if (gMonSpritesGfxPtr != NULL)
{ {
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) 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 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 else
{ {
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) 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 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)++; (*state)++;
@ -3899,7 +3917,7 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
case 1: case 1:
pal = GetMonSpritePalStructFromOtIdPersonality(summary->species2, summary->OTID, summary->pid); pal = GetMonSpritePalStructFromOtIdPersonality(summary->species2, summary->OTID, summary->pid);
LoadCompressedSpritePalette(pal); LoadCompressedSpritePalette(pal);
SetMultiuseSpriteTemplateToPokemon(pal->tag, 1); SetMultiuseSpriteTemplateToPokemon(pal->tag, B_POSITION_OPPONENT_LEFT);
(*state)++; (*state)++;
return 0xFF; return 0xFF;
} }

View File

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