pokeemerald/src/reshow_battle_screen.c

321 lines
12 KiB
C
Raw Normal View History

2017-10-09 18:18:40 +02:00
#include "global.h"
#include "reshow_battle_screen.h"
#include "battle.h"
#include "palette.h"
#include "main.h"
2018-01-29 17:47:12 +01:00
#include "scanline_effect.h"
2017-10-09 18:18:40 +02:00
#include "text.h"
#include "gpu_regs.h"
#include "bg.h"
#include "battle_controllers.h"
#include "link.h"
#include "sprite.h"
2017-12-11 19:27:51 +01:00
#include "constants/species.h"
#include "constants/trainers.h"
2017-10-09 18:18:40 +02:00
#include "battle_interface.h"
2018-02-08 00:00:25 +01:00
#include "battle_anim.h"
2018-02-28 23:57:08 +01:00
#include "data2.h"
2017-10-09 18:18:40 +02:00
extern const union AnimCmd * const * const gMonAnimationsSpriteAnimsPtrTable[];
extern void SetMultiuseSpriteTemplateToTrainerBack(u16 backPicId, u8 battlerPosition);
2017-10-09 18:18:40 +02:00
// this file's functions
static void CB2_ReshowBattleScreenAfterMenu(void);
2018-02-28 23:57:08 +01:00
static bool8 LoadBattlerSpriteGfx(u8 battlerId);
static void CreateBattlerSprite(u8 battlerId);
static void CreateHealthboxSprite(u8 battlerId);
2017-10-09 18:18:40 +02:00
static void sub_80A95F4(void);
void nullsub_35(void)
{
}
void ReshowBattleScreenAfterMenu(void)
{
gPaletteFade.bufferTransferDisabled = 1;
SetHBlankCallback(NULL);
SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_MOSAIC, 0);
gBattleScripting.reshowMainState = 0;
gBattleScripting.reshowHelperState = 0;
SetMainCallback2(CB2_ReshowBattleScreenAfterMenu);
}
static void CB2_ReshowBattleScreenAfterMenu(void)
{
switch (gBattleScripting.reshowMainState)
{
case 0:
2018-01-29 17:47:12 +01:00
ScanlineEffect_Clear();
2018-06-17 16:48:58 +02:00
BattleInitBgsAndWindows();
2018-12-26 13:05:02 +01:00
SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0);
SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0);
2017-10-09 18:18:40 +02:00
ShowBg(0);
ShowBg(1);
ShowBg(2);
ShowBg(3);
ResetPaletteFade();
gBattle_BG0_X = 0;
gBattle_BG0_Y = 0;
gBattle_BG1_X = 0;
gBattle_BG1_Y = 0;
gBattle_BG2_X = 0;
gBattle_BG2_Y = 0;
gBattle_BG3_X = 0;
gBattle_BG3_Y = 0;
break;
case 1:
CpuFastFill(0, (void*)(VRAM), VRAM_SIZE);
break;
case 2:
LoadBattleTextboxAndBackground();
break;
case 3:
ResetSpriteData();
break;
case 4:
FreeAllSpritePalettes();
gReservedSpritePaletteCount = 4;
break;
case 5:
2017-11-04 16:11:13 +01:00
ClearSpritesHealthboxAnimData();
2017-10-09 18:18:40 +02:00
break;
case 6:
if (BattleLoadAllHealthBoxesGfx(gBattleScripting.reshowHelperState))
{
gBattleScripting.reshowHelperState = 0;
}
else
{
gBattleScripting.reshowHelperState++;
gBattleScripting.reshowMainState--;
}
break;
case 7:
2018-02-06 23:09:39 +01:00
if (!LoadBattlerSpriteGfx(0))
2017-10-09 18:18:40 +02:00
gBattleScripting.reshowMainState--;
break;
case 8:
2018-02-06 23:09:39 +01:00
if (!LoadBattlerSpriteGfx(1))
2017-10-09 18:18:40 +02:00
gBattleScripting.reshowMainState--;
break;
case 9:
2018-02-06 23:09:39 +01:00
if (!LoadBattlerSpriteGfx(2))
2017-10-09 18:18:40 +02:00
gBattleScripting.reshowMainState--;
break;
case 10:
2018-02-06 23:09:39 +01:00
if (!LoadBattlerSpriteGfx(3))
2017-10-09 18:18:40 +02:00
gBattleScripting.reshowMainState--;
break;
case 11:
2018-02-06 23:09:39 +01:00
CreateBattlerSprite(0);
2017-10-09 18:18:40 +02:00
break;
case 12:
2018-02-06 23:09:39 +01:00
CreateBattlerSprite(1);
2017-10-09 18:18:40 +02:00
break;
case 13:
2018-02-06 23:09:39 +01:00
CreateBattlerSprite(2);
2017-10-09 18:18:40 +02:00
break;
case 14:
2018-02-06 23:09:39 +01:00
CreateBattlerSprite(3);
2017-10-09 18:18:40 +02:00
break;
case 15:
CreateHealthboxSprite(0);
break;
case 16:
CreateHealthboxSprite(1);
break;
case 17:
CreateHealthboxSprite(2);
break;
case 18:
CreateHealthboxSprite(3);
break;
case 19:
{
u8 opponentBattler;
2017-10-09 18:18:40 +02:00
u16 species;
LoadAndCreateEnemyShadowSprites();
opponentBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBattler]], MON_DATA_SPECIES);
SetBattlerShadowSpriteCallback(opponentBattler, species);
2017-10-09 18:18:40 +02:00
if (IsDoubleBattle())
{
opponentBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBattler]], MON_DATA_SPECIES);
SetBattlerShadowSpriteCallback(opponentBattler, species);
2017-10-09 18:18:40 +02:00
}
2018-02-07 22:53:40 +01:00
ActionSelectionCreateCursorAt(gActionSelectionCursor[gBattlerInMenuId], 0);
2017-10-09 18:18:40 +02:00
2017-11-13 05:58:05 +01:00
if (gWirelessCommType != 0 && gReceivedRemoteLinkPlayers != 0)
2017-10-09 18:18:40 +02:00
{
sub_800E0E8();
2017-12-04 04:01:06 +01:00
CreateWirelessStatusIndicatorSprite(0, 0);
2017-10-09 18:18:40 +02:00
}
}
break;
default:
SetVBlankCallback(VBlankCB_Battle);
sub_80A95F4();
BeginHardwarePaletteFade(0xFF, 0, 0x10, 0, 1);
gPaletteFade.bufferTransferDisabled = 0;
SetMainCallback2(BattleMainCB2);
sub_805EF14();
break;
}
gBattleScripting.reshowMainState++;
}
static void sub_80A95F4(void)
{
struct BGCntrlBitfield *regBgcnt1, *regBgcnt2;
regBgcnt1 = (struct BGCntrlBitfield *)(&REG_BG1CNT);
regBgcnt1->charBaseBlock = 0;
regBgcnt2 = (struct BGCntrlBitfield *)(&REG_BG2CNT);
regBgcnt2->charBaseBlock = 0;
}
2018-02-06 23:09:39 +01:00
static bool8 LoadBattlerSpriteGfx(u8 battler)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (battler < gBattlersCount)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (!gBattleSpritesDataPtr->battlerData[battler].behindSubstitute)
BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battler]], battler);
2017-10-09 18:18:40 +02:00
else
2018-02-06 23:09:39 +01:00
BattleLoadSubstituteOrMonSpriteGfx(battler, FALSE);
2017-10-09 18:18:40 +02:00
}
else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT) // Should be checking position, not battler.
2018-02-06 23:09:39 +01:00
DecompressTrainerBackPic(gSaveBlock2Ptr->playerGender, battler);
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT) // Should be checking position, not battler.
DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, battler);
2018-02-06 23:09:39 +01:00
else if (!gBattleSpritesDataPtr->battlerData[battler].behindSubstitute)
BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battler]], battler);
2017-10-09 18:18:40 +02:00
else
2018-02-06 23:09:39 +01:00
BattleLoadSubstituteOrMonSpriteGfx(battler, FALSE);
2017-10-09 18:18:40 +02:00
gBattleScripting.reshowHelperState = 0;
}
return TRUE;
}
2018-02-06 23:09:39 +01:00
static void CreateBattlerSprite(u8 battler)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (battler < gBattlersCount)
2017-10-09 18:18:40 +02:00
{
u8 posY;
2018-02-06 23:09:39 +01:00
if (gBattleSpritesDataPtr->battlerData[battler].behindSubstitute)
posY = GetSubstituteSpriteDefault_Y(battler);
2017-10-09 18:18:40 +02:00
else
2018-02-06 23:09:39 +01:00
posY = GetBattlerSpriteDefault_Y(battler);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0)
2017-10-09 18:18:40 +02:00
return;
SetMultiuseSpriteTemplateToPokemon(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler));
2018-12-18 05:08:08 +01:00
gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battler, 2), posY, GetBattlerSpriteSubpriority(battler));
2018-02-06 23:09:39 +01:00
gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler;
gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy;
gSprites[gBattlerSpriteIds[battler]].data[0] = battler;
gSprites[gBattlerSpriteIds[battler]].data[2] = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], gBattleMonForms[battler]);
if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies == SPECIES_CASTFORM)
gSprites[gBattlerSpriteIds[battler]].anims = gMonAnimationsSpriteAnimsPtrTable[SPECIES_CASTFORM];
2017-10-09 18:18:40 +02:00
}
else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT)
2017-10-09 18:18:40 +02:00
{
SetMultiuseSpriteTemplateToTrainerBack(gSaveBlock2Ptr->playerGender, GetBattlerPosition(B_POSITION_PLAYER_LEFT));
gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, 0x50,
(8 - gTrainerBackPicCoords[gSaveBlock2Ptr->playerGender].size) * 4 + 80,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority(0));
2018-02-06 23:09:39 +01:00
gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler;
gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy;
gSprites[gBattlerSpriteIds[battler]].data[0] = battler;
2017-10-09 18:18:40 +02:00
}
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT)
2017-10-09 18:18:40 +02:00
{
SetMultiuseSpriteTemplateToTrainerBack(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(0));
gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, 0x50,
(8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].size) * 4 + 80,
2018-12-18 05:08:08 +01:00
GetBattlerSpriteSubpriority(0));
2018-02-06 23:09:39 +01:00
gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler;
gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy;
gSprites[gBattlerSpriteIds[battler]].data[0] = battler;
2017-10-09 18:18:40 +02:00
}
else
{
2018-02-06 23:09:39 +01:00
if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0)
2017-10-09 18:18:40 +02:00
return;
SetMultiuseSpriteTemplateToPokemon(GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler));
2018-12-18 05:08:08 +01:00
gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, GetBattlerSpriteCoord(battler, 2), posY, GetBattlerSpriteSubpriority(battler));
2018-02-06 23:09:39 +01:00
gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler;
gSprites[gBattlerSpriteIds[battler]].callback = SpriteCallbackDummy;
gSprites[gBattlerSpriteIds[battler]].data[0] = battler;
gSprites[gBattlerSpriteIds[battler]].data[2] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], gBattleMonForms[battler]);
if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies == SPECIES_CASTFORM)
gSprites[gBattlerSpriteIds[battler]].anims = gMonAnimationsSpriteAnimsPtrTable[SPECIES_CASTFORM];
2017-10-09 18:18:40 +02:00
}
2018-02-06 23:09:39 +01:00
gSprites[gBattlerSpriteIds[battler]].invisible = gBattleSpritesDataPtr->battlerData[battler].invisible;
2017-10-09 18:18:40 +02:00
}
}
2018-02-06 23:09:39 +01:00
static void CreateHealthboxSprite(u8 battler)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (battler < gBattlersCount)
2017-10-09 18:18:40 +02:00
{
u8 healthboxSpriteId;
if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == B_POSITION_PLAYER_LEFT)
2017-10-09 18:18:40 +02:00
healthboxSpriteId = CreateSafariPlayerHealthboxSprites();
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == B_POSITION_PLAYER_LEFT)
2017-10-09 18:18:40 +02:00
return;
else
2018-02-06 23:09:39 +01:00
healthboxSpriteId = CreateBattlerHealthboxSprites(battler);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
gHealthboxSpriteIds[battler] = healthboxSpriteId;
InitBattlerHealthboxCoords(battler);
2017-10-09 18:18:40 +02:00
SetHealthboxSpriteVisible(healthboxSpriteId);
2018-02-06 23:09:39 +01:00
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], &gEnemyParty[gBattlerPartyIndexes[battler]], HEALTHBOX_ALL);
2017-10-09 18:18:40 +02:00
else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI)
2018-02-06 23:09:39 +01:00
UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], &gPlayerParty[gBattlerPartyIndexes[battler]], HEALTHBOX_SAFARI_ALL_TEXT);
2017-10-09 18:18:40 +02:00
else
2018-02-06 23:09:39 +01:00
UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], &gPlayerParty[gBattlerPartyIndexes[battler]], HEALTHBOX_ALL);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
if (GetBattlerPosition(battler) == B_POSITION_OPPONENT_RIGHT || GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT)
DummyBattleInterfaceFunc(gHealthboxSpriteIds[battler], TRUE);
2017-10-09 18:18:40 +02:00
else
2018-02-06 23:09:39 +01:00
DummyBattleInterfaceFunc(gHealthboxSpriteIds[battler], FALSE);
2017-10-09 18:18:40 +02:00
2018-02-06 23:09:39 +01:00
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
2017-10-09 18:18:40 +02:00
{
2018-02-06 23:09:39 +01:00
if (GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0)
2017-10-09 18:18:40 +02:00
SetHealthboxSpriteInvisible(healthboxSpriteId);
}
else if (!(gBattleTypeFlags & BATTLE_TYPE_SAFARI))
{
2018-02-06 23:09:39 +01:00
if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_HP) == 0)
2017-10-09 18:18:40 +02:00
SetHealthboxSpriteInvisible(healthboxSpriteId);
}
}
}