pokeemerald/src/reshow_battle_screen.c

330 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"
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 u16 gBattle_BG0_X;
extern u16 gBattle_BG0_Y;
extern u16 gBattle_BG1_X;
extern u16 gBattle_BG1_Y;
extern u16 gBattle_BG2_X;
extern u16 gBattle_BG2_Y;
extern u16 gBattle_BG3_X;
extern u16 gBattle_BG3_Y;
extern const union AnimCmd * const * const gMonAnimationsSpriteAnimsPtrTable[];
2018-02-28 23:57:08 +01:00
extern void sub_806A068(u16 species, u8 battlerPosition);
extern void sub_806A12C(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();
2017-12-17 20:10:57 +01:00
sub_8035658();
2017-10-09 18:18:40 +02:00
SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0);
SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0);
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 opponentBank;
u16 species;
LoadAndCreateEnemyShadowSprites();
2018-02-06 02:46:59 +01:00
opponentBank = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
2018-02-06 20:48:02 +01:00
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBank]], MON_DATA_SPECIES);
SetBattlerShadowSpriteCallback(opponentBank, species);
2017-10-09 18:18:40 +02:00
if (IsDoubleBattle())
{
2018-02-06 02:46:59 +01:00
opponentBank = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
2018-02-06 20:48:02 +01:00
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[opponentBank]], MON_DATA_SPECIES);
SetBattlerShadowSpriteCallback(opponentBank, 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
}
2018-02-06 23:09:39 +01:00
else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0)
DecompressTrainerBackPic(gSaveBlock2Ptr->playerGender, battler);
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0)
DecompressTrainerBackPic(BACK_PIC_WALLY, battler);
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;
2018-02-06 23:09:39 +01:00
sub_806A068(GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler));
gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler));
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
}
2018-02-06 23:09:39 +01:00
else if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0)
2017-10-09 18:18:40 +02:00
{
2018-02-06 02:46:59 +01:00
sub_806A12C(gSaveBlock2Ptr->playerGender, GetBattlerPosition(B_POSITION_PLAYER_LEFT));
2018-02-06 23:09:39 +01:00
gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50,
2017-10-09 18:18:40 +02:00
(8 - gTrainerBackPicCoords[gSaveBlock2Ptr->playerGender].coords) * 4 + 80,
sub_80A82E4(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
}
2018-02-06 23:09:39 +01:00
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0)
2017-10-09 18:18:40 +02:00
{
2018-02-06 02:46:59 +01:00
sub_806A12C(BACK_PIC_WALLY, GetBattlerPosition(0));
2018-02-06 23:09:39 +01:00
gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, 0x50,
2017-10-09 18:18:40 +02:00
(8 - gTrainerBackPicCoords[BACK_PIC_WALLY].coords) * 4 + 80,
sub_80A82E4(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;
2018-02-06 23:09:39 +01:00
sub_806A068(GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES), GetBattlerPosition(battler));
gBattlerSpriteIds[battler] = CreateSprite(&gUnknown_0202499C, GetBattlerSpriteCoord(battler, 2), posY, sub_80A82E4(battler));
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;
2018-02-06 23:09:39 +01:00
if (gBattleTypeFlags & BATTLE_TYPE_SAFARI && battler == 0)
2017-10-09 18:18:40 +02:00
healthboxSpriteId = CreateSafariPlayerHealthboxSprites();
2018-02-06 23:09:39 +01:00
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL && battler == 0)
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);
}
}
}