summaryrefslogtreecommitdiff
path: root/src/battle_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/battle_main.c')
-rw-r--r--src/battle_main.c153
1 files changed, 75 insertions, 78 deletions
diff --git a/src/battle_main.c b/src/battle_main.c
index 0421ed6b6..c171c6a56 100644
--- a/src/battle_main.c
+++ b/src/battle_main.c
@@ -81,8 +81,8 @@ static void TryCorrectShedinjaLanguage(struct Pokemon *mon);
static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 firstTrainer);
static void BattleMainCB1(void);
static void sub_8038538(struct Sprite *sprite);
-static void sub_8038F14(void);
-static void sub_8038F34(void);
+static void CB2_EndLinkBattle(void);
+static void EndLinkBattleInSteps(void);
static void sub_80392A8(void);
static void sub_803937C(void);
static void sub_803939C(void);
@@ -248,7 +248,7 @@ void (*gBattlerControllerFuncs[MAX_BATTLERS_COUNT])(void);
u8 gHealthboxSpriteIds[MAX_BATTLERS_COUNT];
u8 gMultiUsePlayerCursor;
u8 gNumberOfMovesToChoose;
-u8 gUnknown_03005D7C[MAX_BATTLERS_COUNT];
+u8 gBattleControllerData[MAX_BATTLERS_COUNT]; // Used by the battle controllers to store misc sprite/task IDs for each battler
// rom const data
static const struct ScanlineEffectParams sIntroScanlineParams16Bit =
@@ -2080,8 +2080,8 @@ static void sub_8038B04(struct Sprite *sprite)
if (sprite->affineAnimEnded)
{
- FreeSpriteTilesByTag(0x2710);
- FreeSpritePaletteByTag(0x2710);
+ FreeSpriteTilesByTag(ANIM_SPRITES_START);
+ FreeSpritePaletteByTag(ANIM_SPRITES_START);
FreeSpriteOamMatrix(sprite);
DestroySprite(sprite);
}
@@ -2094,86 +2094,75 @@ void sub_8038B74(struct Sprite *sprite)
PlaySE(SE_MUGSHOT);
}
-static void sub_8038B94(u8 taskId)
+#define BUFFER_PARTY_VS_SCREEN_STATUS(party, flags, i) \
+ for ((i) = 0; (i) < PARTY_SIZE; (i)++) \
+ { \
+ u16 species = GetMonData(&(party)[(i)], MON_DATA_SPECIES2); \
+ u16 hp = GetMonData(&(party)[(i)], MON_DATA_HP); \
+ u32 status = GetMonData(&(party)[(i)], MON_DATA_STATUS); \
+ \
+ if (species == SPECIES_NONE) \
+ continue; \
+ \
+ /* Is healthy mon? */ \
+ if (species != SPECIES_EGG && hp != 0 && status == 0) \
+ (flags) |= 1 << (i) * 2; \
+ \
+ if (species == SPECIES_NONE) /* Redundant */ \
+ continue; \
+ \
+ /* Is Egg or statused? */ \
+ if (hp != 0 && (species == SPECIES_EGG || status != 0)) \
+ (flags) |= 2 << (i) * 2; \
+ \
+ if (species == SPECIES_NONE) /* Redundant */ \
+ continue; \
+ \
+ /* Is fainted? */ \
+ if (species != SPECIES_EGG && hp == 0) \
+ (flags) |= 3 << (i) * 2; \
+ }
+
+static void LoadPartyDataForLinkVsScreen(u8 taskId)
{
- struct Pokemon *sp4 = NULL;
- struct Pokemon *sp8 = NULL;
- u8 r2 = gBattleScripting.multiplayerId;
- u32 r7;
+ struct Pokemon *party1 = NULL;
+ struct Pokemon *party2 = NULL;
+ u8 multiplayerId = gBattleScripting.multiplayerId;
+ u32 statusFlags;
s32 i;
if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
{
- switch (gLinkPlayers[r2].id)
+ switch (gLinkPlayers[multiplayerId].id)
{
case 0:
case 2:
- sp4 = gPlayerParty;
- sp8 = gEnemyParty;
+ party1 = gPlayerParty;
+ party2 = gEnemyParty;
break;
case 1:
case 3:
- sp4 = gEnemyParty;
- sp8 = gPlayerParty;
+ party1 = gEnemyParty;
+ party2 = gPlayerParty;
break;
}
}
else
{
- sp4 = gPlayerParty;
- sp8 = gEnemyParty;
+ party1 = gPlayerParty;
+ party2 = gEnemyParty;
}
- r7 = 0;
- for (i = 0; i < PARTY_SIZE; i++)
- {
- u16 species = GetMonData(&sp4[i], MON_DATA_SPECIES2);
- u16 hp = GetMonData(&sp4[i], MON_DATA_HP);
- u32 status = GetMonData(&sp4[i], MON_DATA_STATUS);
-
- if (species == SPECIES_NONE)
- continue;
- if (species != SPECIES_EGG && hp != 0 && status == 0)
- r7 |= 1 << i * 2;
-
- if (species == SPECIES_NONE)
- continue;
- if (hp != 0 && (species == SPECIES_EGG || status != 0))
- r7 |= 2 << i * 2;
-
- if (species == SPECIES_NONE)
- continue;
- if (species != SPECIES_EGG && hp == 0)
- r7 |= 3 << i * 2;
- }
- gTasks[taskId].data[3] = r7;
-
- r7 = 0;
- for (i = 0; i < PARTY_SIZE; i++)
- {
- u16 species = GetMonData(&sp8[i], MON_DATA_SPECIES2);
- u16 hp = GetMonData(&sp8[i], MON_DATA_HP);
- u32 status = GetMonData(&sp8[i], MON_DATA_STATUS);
-
- if (species == SPECIES_NONE)
- continue;
- if (species != SPECIES_EGG && hp != 0 && status == 0)
- r7 |= 1 << i * 2;
-
- if (species == SPECIES_NONE)
- continue;
- if (hp != 0 && (species == SPECIES_EGG || status != 0))
- r7 |= 2 << i * 2;
+ statusFlags = 0;
+ BUFFER_PARTY_VS_SCREEN_STATUS(party1, statusFlags, i);
+ gTasks[taskId].data[3] = statusFlags;
- if (species == SPECIES_NONE)
- continue;
- if (species != SPECIES_EGG && hp == 0)
- r7 |= 3 << i * 2;
- }
- gTasks[taskId].data[4] = r7;
+ statusFlags = 0;
+ BUFFER_PARTY_VS_SCREEN_STATUS(party2, statusFlags, i);
+ gTasks[taskId].data[4] = statusFlags;
}
-void sub_8038D64(void)
+void CB2_InitEndLinkBattle(void)
{
s32 i;
u8 taskId;
@@ -2193,12 +2182,12 @@ void sub_8038D64(void)
{
CpuFill32(0, (void*)(VRAM), VRAM_SIZE);
SetGpuReg(REG_OFFSET_MOSAIC, 0);
- SetGpuReg(REG_OFFSET_WIN0H, 0xF0);
- SetGpuReg(REG_OFFSET_WIN0V, 0x5051);
+ SetGpuReg(REG_OFFSET_WIN0H, DISPLAY_WIDTH);
+ SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(DISPLAY_HEIGHT / 2, DISPLAY_HEIGHT / 2 + 1));
SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0);
- gBattle_WIN0H = 0xF0;
- gBattle_WIN0V = 0x5051;
+ gBattle_WIN0H = DISPLAY_WIDTH;
+ gBattle_WIN0V = WIN_RANGE(DISPLAY_HEIGHT / 2, DISPLAY_HEIGHT / 2 + 1);
ScanlineEffect_Clear();
i = 0;
@@ -2233,24 +2222,26 @@ void sub_8038D64(void)
ResetSpriteData();
ResetTasks();
DrawBattleEntryBackground();
- SetGpuReg(REG_OFFSET_WINOUT, 0x37);
+ SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_BG1 | WINOUT_WIN01_BG2 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR);
FreeAllSpritePalettes();
gReservedSpritePaletteCount = 4;
SetVBlankCallback(VBlankCB_Battle);
+ // Show end Vs screen with battle results
taskId = CreateTask(InitLinkBattleVsScreen, 0);
gTasks[taskId].data[1] = 0x10E;
gTasks[taskId].data[2] = 0x5A;
gTasks[taskId].data[5] = 1;
- sub_8038B94(taskId);
- SetMainCallback2(sub_8038F14);
+ LoadPartyDataForLinkVsScreen(taskId);
+
+ SetMainCallback2(CB2_EndLinkBattle);
gBattleCommunication[MULTIUSE_STATE] = 0;
}
}
-static void sub_8038F14(void)
+static void CB2_EndLinkBattle(void)
{
- sub_8038F34();
+ EndLinkBattleInSteps();
AnimateSprites();
BuildOamBuffer();
RunTextPrinters();
@@ -2258,7 +2249,7 @@ static void sub_8038F14(void)
RunTasks();
}
-static void sub_8038F34(void)
+static void EndLinkBattleInSteps(void)
{
s32 i;
@@ -2658,7 +2649,7 @@ static void SpriteCb_WildMonShowHealthbox(struct Sprite *sprite)
{
if (sprite->animEnded)
{
- sub_8076918(sprite->sBattler);
+ StartHealthboxSlideIn(sprite->sBattler);
SetHealthboxSpriteVisible(gHealthboxSpriteIds[sprite->sBattler]);
sprite->callback = SpriteCb_WildMonAnimate;
StartSpriteAnimIfDifferent(sprite, 0);
@@ -2839,15 +2830,21 @@ static void SpriteCallbackDummy_3(struct Sprite *sprite)
{
}
-void sub_8039C00(struct Sprite *sprite)
+#define sSpeedX data[1]
+#define sSpeedY data[2]
+
+void SpriteCB_FaintSlideAnim(struct Sprite *sprite)
{
if (!(gIntroSlideFlags & 1))
{
- sprite->pos2.x += sprite->data[1];
- sprite->pos2.y += sprite->data[2];
+ sprite->pos2.x += sprite->sSpeedX;
+ sprite->pos2.y += sprite->sSpeedY;
}
}
+#undef sSpeedX
+#undef sSpeedY
+
#define sSinIndex data[0]
#define sDelta data[1]
#define sAmplitude data[2]