From c4a6d08bbb351336974f2202949726e856850400 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 10 Jul 2024 23:10:39 -0700 Subject: [PATCH 01/10] First proof of concept works --- include/config/battle.h | 1 + src/pokeball.c | 84 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/include/config/battle.h b/include/config/battle.h index e8981831c4bb..0ef888a219e3 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -267,5 +267,6 @@ #define B_NEW_MORNING_SUN_STAR_PARTICLE TRUE // If set to TRUE, it updates Morning Sun's star particles. #define B_NEW_IMPACT_PALETTE TRUE // If set to TRUE, it updates the basic 'hit' palette. #define B_NEW_SURF_PARTICLE_PALETTE TRUE // If set to TRUE, it updates Surf's wave palette. +#define B_OPPONENT_THROW_BALLS GEN_LATEST // In GEN_6+, opposing Trainers throw Pokeballs into battle instead of just dropping them. #endif // GUARD_CONFIG_BATTLE_H diff --git a/src/pokeball.c b/src/pokeball.c index f15d7663c786..541a86e779cd 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -16,9 +16,12 @@ #include "constants/songs.h" static void Task_DoPokeballSendOutAnim(u8 taskId); +static void *GetOpponentMonSendOutCallback(void); static void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite); static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite); static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite); +static void SpriteCB_OpponentMonSendOut_1(struct Sprite *sprite); +static void SpriteCB_OpponentMonSendOut_2(struct Sprite *sprite); static void SpriteCB_BallThrow(struct Sprite *sprite); static void SpriteCB_BallThrow_ReachMon(struct Sprite *sprite); static void SpriteCB_BallThrow_StartShrinkMon(struct Sprite *sprite); @@ -548,6 +551,8 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) { u32 throwCaseId, ballId, battlerId, ballSpriteId; bool32 notSendOut = FALSE; + u32 throwXoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? 24 : 0; + s32 throwYoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? -16 : 24; if (gTasks[taskId].tFrames == 0) { @@ -578,11 +583,11 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gSprites[ballSpriteId].callback = SpriteCB_PlayerMonSendOut_1; break; case POKEBALL_OPPONENT_SENDOUT: - gSprites[ballSpriteId].x = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X); - gSprites[ballSpriteId].y = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 24; + gSprites[ballSpriteId].x = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X) + throwXoffset; + gSprites[ballSpriteId].y = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + throwYoffset; gBattlerTarget = battlerId; gSprites[ballSpriteId].data[0] = 0; - gSprites[ballSpriteId].callback = SpriteCB_OpponentMonSendOut; + gSprites[ballSpriteId].callback = GetOpponentMonSendOutCallback(); break; default: gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); @@ -1179,8 +1184,6 @@ static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite) } } -#undef HIBYTE - static void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite) { if (sprite->data[0]++ > 24) @@ -1190,6 +1193,11 @@ static void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite) } } +static void *GetOpponentMonSendOutCallback(void) +{ + return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_OpponentMonSendOut_1 : SpriteCB_OpponentMonSendOut; +} + static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite) { sprite->data[0]++; @@ -1204,6 +1212,72 @@ static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite) } } +static void SpriteCB_OpponentMonSendOut_1(struct Sprite *sprite) +{ + sprite->data[0] = 25; + sprite->data[2] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_X); + sprite->data[4] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_Y) + 24; + sprite->data[5] = -30; + sprite->oam.affineParam = sprite->sBattler; + InitAnimArcTranslation(sprite); + sprite->callback = SpriteCB_OpponentMonSendOut_2; +} + +static void SpriteCB_OpponentMonSendOut_2(struct Sprite *sprite) +{ + u32 r6; + u32 r7; + + if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) + { + s16 r4; + + if ((sprite->oam.affineParam & 0xFF00) == 0) + { + r6 = sprite->data[1] & 1; + r7 = sprite->data[2] & 1; + sprite->data[1] = ((sprite->data[1] / 3) & ~1) | r6; + sprite->data[2] = ((sprite->data[2] / 3) & ~1) | r7; + StartSpriteAffineAnim(sprite, 4); + } + r4 = sprite->data[0]; + AnimTranslateLinear(sprite); + sprite->data[7] += sprite->sBattler / 3; + sprite->y2 += Sin(HIBYTE(sprite->data[7]), sprite->data[5]); + sprite->oam.affineParam += 0x100; + if ((sprite->oam.affineParam >> 8) % 3 != 0) + sprite->data[0] = r4; + else + sprite->data[0] = r4 - 1; + if (HIBYTE(sprite->data[7]) >= 80) + { + r6 = sprite->data[1] & 1; + r7 = sprite->data[2] & 1; + sprite->data[1] = ((sprite->data[1] * 3) & ~1) | r6; + sprite->data[2] = ((sprite->data[2] * 3) & ~1) | r7; + } + } + else + { + if (TranslateAnimHorizontalArc(sprite)) + { + sprite->x += sprite->x2; + sprite->y += sprite->y2; + sprite->y2 = 0; + sprite->x2 = 0; + sprite->sBattler = sprite->oam.affineParam & 0xFF; + sprite->data[0] = 0; + + if (IsDoubleBattle() && gBattleSpritesDataPtr->animationData->introAnimActive + && sprite->sBattler == GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)) + sprite->callback = SpriteCB_ReleaseMon2FromBall; + else + sprite->callback = SpriteCB_ReleaseMonFromBall; + + StartSpriteAffineAnim(sprite, 0); + } + } +} #undef sBattler static u8 AnimateBallOpenParticlesForPokeball(u8 x, u8 y, u8 kindOfStars, u8 subpriority) From c2f5da01b9263b065b8393f7eccb417793696113 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 18:43:00 -0700 Subject: [PATCH 02/10] Added B_THROW_BALLS_SOUND --- include/config/battle.h | 1 + src/pokeball.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/config/battle.h b/include/config/battle.h index 0ef888a219e3..ccf97f92ae6e 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -268,5 +268,6 @@ #define B_NEW_IMPACT_PALETTE TRUE // If set to TRUE, it updates the basic 'hit' palette. #define B_NEW_SURF_PARTICLE_PALETTE TRUE // If set to TRUE, it updates Surf's wave palette. #define B_OPPONENT_THROW_BALLS GEN_LATEST // In GEN_6+, opposing Trainers throw Pokeballs into battle instead of just dropping them. +#define B_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, Trainers Pokeballs make a sound when thrown to send out a Pokemon. #endif // GUARD_CONFIG_BATTLE_H diff --git a/src/pokeball.c b/src/pokeball.c index 541a86e779cd..08d6c701fd26 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -16,6 +16,7 @@ #include "constants/songs.h" static void Task_DoPokeballSendOutAnim(u8 taskId); +static void DoPokeballSendOutSoundEffect(void); static void *GetOpponentMonSendOutCallback(void); static void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite); static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite); @@ -581,6 +582,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gSprites[ballSpriteId].x = 24; gSprites[ballSpriteId].y = 68; gSprites[ballSpriteId].callback = SpriteCB_PlayerMonSendOut_1; + DoPokeballSendOutSoundEffect(); break; case POKEBALL_OPPONENT_SENDOUT: gSprites[ballSpriteId].x = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X) + throwXoffset; @@ -588,6 +590,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gBattlerTarget = battlerId; gSprites[ballSpriteId].data[0] = 0; gSprites[ballSpriteId].callback = GetOpponentMonSendOutCallback(); + DoPokeballSendOutSoundEffect(); break; default: gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); @@ -614,6 +617,14 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) PlaySE(SE_BALL_THROW); } +static void DoPokeballSendOutSoundEffect(void) +{ + if (B_THROW_BALLS_SOUND < GEN_5) + return; + + PlaySE(SE_BALL_THROW); +} + // This sequence of functions is very similar to those that get run when // a Pokéball gets thrown at a wild Pokémon, starting at SpriteCB_Ball_Arc. // These do not seem to get run. From b16435698321af4293bba567d9d25aaa3b989f7a Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 19:26:35 -0700 Subject: [PATCH 03/10] Made generic MonSendOut --- src/pokeball.c | 108 ++++++++++++------------------------------------- 1 file changed, 26 insertions(+), 82 deletions(-) diff --git a/src/pokeball.c b/src/pokeball.c index 08d6c701fd26..d405a80b93de 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -18,11 +18,10 @@ static void Task_DoPokeballSendOutAnim(u8 taskId); static void DoPokeballSendOutSoundEffect(void); static void *GetOpponentMonSendOutCallback(void); -static void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite); -static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite); +static bool32 IsBattlerPlayer(u32 battler); +static void SpriteCB_MonSendOut_1(struct Sprite *sprite); +static void SpriteCB_MonSendOut_2(struct Sprite *sprite); static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite); -static void SpriteCB_OpponentMonSendOut_1(struct Sprite *sprite); -static void SpriteCB_OpponentMonSendOut_2(struct Sprite *sprite); static void SpriteCB_BallThrow(struct Sprite *sprite); static void SpriteCB_BallThrow_ReachMon(struct Sprite *sprite); static void SpriteCB_BallThrow_StartShrinkMon(struct Sprite *sprite); @@ -581,7 +580,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gBattlerTarget = battlerId; gSprites[ballSpriteId].x = 24; gSprites[ballSpriteId].y = 68; - gSprites[ballSpriteId].callback = SpriteCB_PlayerMonSendOut_1; + gSprites[ballSpriteId].callback = SpriteCB_MonSendOut_1; DoPokeballSendOutSoundEffect(); break; case POKEBALL_OPPONENT_SENDOUT: @@ -625,6 +624,11 @@ static void DoPokeballSendOutSoundEffect(void) PlaySE(SE_BALL_THROW); } +static void *GetOpponentMonSendOutCallback(void) +{ + return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_MonSendOut_1 : SpriteCB_OpponentMonSendOut; +} + // This sequence of functions is very similar to those that get run when // a Pokéball gets thrown at a wild Pokémon, starting at SpriteCB_Ball_Arc. // These do not seem to get run. @@ -1126,23 +1130,34 @@ static void SpriteCB_BallThrow_CaptureMon(struct Sprite *sprite) } } -static void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite) +static bool32 IsBattlerPlayer(u32 battler) { + return (battler % 2) ? FALSE : TRUE; +} + +static void SpriteCB_MonSendOut_1(struct Sprite *sprite) +{ + bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); + u32 coordX = (isPlayer) ? BATTLER_COORD_X_2 : BATTLER_COORD_X; + u32 coordY = (isPlayer) ? BATTLER_COORD_Y_PIC_OFFSET : BATTLER_COORD_Y; + sprite->data[0] = 25; - sprite->data[2] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_X_2); - sprite->data[4] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_Y_PIC_OFFSET) + 24; + sprite->data[2] = GetBattlerSpriteCoord(sprite->sBattler, coordX); + sprite->data[4] = GetBattlerSpriteCoord(sprite->sBattler, coordY) + 24; sprite->data[5] = -30; sprite->oam.affineParam = sprite->sBattler; InitAnimArcTranslation(sprite); - sprite->callback = SpriteCB_PlayerMonSendOut_2; + sprite->callback = SpriteCB_MonSendOut_2; } #define HIBYTE(x) (((x) >> 8) & 0xFF) -static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite) +static void SpriteCB_MonSendOut_2(struct Sprite *sprite) { u32 r6; u32 r7; + bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); + bool32 rightPosition = (isPlayer) ? B_POSITION_PLAYER_RIGHT : B_POSITION_OPPONENT_RIGHT; if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) { @@ -1185,7 +1200,7 @@ static void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite) sprite->data[0] = 0; if (IsDoubleBattle() && gBattleSpritesDataPtr->animationData->introAnimActive - && sprite->sBattler == GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT)) + && sprite->sBattler == GetBattlerAtPosition(rightPosition)) sprite->callback = SpriteCB_ReleaseMon2FromBall; else sprite->callback = SpriteCB_ReleaseMonFromBall; @@ -1204,11 +1219,6 @@ static void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite) } } -static void *GetOpponentMonSendOutCallback(void) -{ - return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_OpponentMonSendOut_1 : SpriteCB_OpponentMonSendOut; -} - static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite) { sprite->data[0]++; @@ -1223,72 +1233,6 @@ static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite) } } -static void SpriteCB_OpponentMonSendOut_1(struct Sprite *sprite) -{ - sprite->data[0] = 25; - sprite->data[2] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_X); - sprite->data[4] = GetBattlerSpriteCoord(sprite->sBattler, BATTLER_COORD_Y) + 24; - sprite->data[5] = -30; - sprite->oam.affineParam = sprite->sBattler; - InitAnimArcTranslation(sprite); - sprite->callback = SpriteCB_OpponentMonSendOut_2; -} - -static void SpriteCB_OpponentMonSendOut_2(struct Sprite *sprite) -{ - u32 r6; - u32 r7; - - if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) - { - s16 r4; - - if ((sprite->oam.affineParam & 0xFF00) == 0) - { - r6 = sprite->data[1] & 1; - r7 = sprite->data[2] & 1; - sprite->data[1] = ((sprite->data[1] / 3) & ~1) | r6; - sprite->data[2] = ((sprite->data[2] / 3) & ~1) | r7; - StartSpriteAffineAnim(sprite, 4); - } - r4 = sprite->data[0]; - AnimTranslateLinear(sprite); - sprite->data[7] += sprite->sBattler / 3; - sprite->y2 += Sin(HIBYTE(sprite->data[7]), sprite->data[5]); - sprite->oam.affineParam += 0x100; - if ((sprite->oam.affineParam >> 8) % 3 != 0) - sprite->data[0] = r4; - else - sprite->data[0] = r4 - 1; - if (HIBYTE(sprite->data[7]) >= 80) - { - r6 = sprite->data[1] & 1; - r7 = sprite->data[2] & 1; - sprite->data[1] = ((sprite->data[1] * 3) & ~1) | r6; - sprite->data[2] = ((sprite->data[2] * 3) & ~1) | r7; - } - } - else - { - if (TranslateAnimHorizontalArc(sprite)) - { - sprite->x += sprite->x2; - sprite->y += sprite->y2; - sprite->y2 = 0; - sprite->x2 = 0; - sprite->sBattler = sprite->oam.affineParam & 0xFF; - sprite->data[0] = 0; - - if (IsDoubleBattle() && gBattleSpritesDataPtr->animationData->introAnimActive - && sprite->sBattler == GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)) - sprite->callback = SpriteCB_ReleaseMon2FromBall; - else - sprite->callback = SpriteCB_ReleaseMonFromBall; - - StartSpriteAffineAnim(sprite, 0); - } - } -} #undef sBattler static u8 AnimateBallOpenParticlesForPokeball(u8 x, u8 y, u8 kindOfStars, u8 subpriority) From 5dfbcaa433c9b639f48fe5d5250d7c485979c963 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 19:52:42 -0700 Subject: [PATCH 04/10] Changed magic number to constant --- src/pokeball.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pokeball.c b/src/pokeball.c index d405a80b93de..b585873e50ae 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1132,7 +1132,7 @@ static void SpriteCB_BallThrow_CaptureMon(struct Sprite *sprite) static bool32 IsBattlerPlayer(u32 battler) { - return (battler % 2) ? FALSE : TRUE; + return (battler % B_POSITION_PLAYER_RIGHT) ? FALSE : TRUE; } static void SpriteCB_MonSendOut_1(struct Sprite *sprite) From 475297099076f0d0ace2ead2a8b2242038a3438f Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 21:00:50 -0700 Subject: [PATCH 05/10] added acute e and changed to GEN_LATEST --- include/config/battle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/config/battle.h b/include/config/battle.h index ccf97f92ae6e..1d00f052b048 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -267,7 +267,7 @@ #define B_NEW_MORNING_SUN_STAR_PARTICLE TRUE // If set to TRUE, it updates Morning Sun's star particles. #define B_NEW_IMPACT_PALETTE TRUE // If set to TRUE, it updates the basic 'hit' palette. #define B_NEW_SURF_PARTICLE_PALETTE TRUE // If set to TRUE, it updates Surf's wave palette. -#define B_OPPONENT_THROW_BALLS GEN_LATEST // In GEN_6+, opposing Trainers throw Pokeballs into battle instead of just dropping them. -#define B_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, Trainers Pokeballs make a sound when thrown to send out a Pokemon. +#define B_OPPONENT_THROW_BALLS GEN_LATEST // In GEN_6+, opposing Trainers throw PokéBalls into battle instead of just dropping them. +#define B_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, Trainers PokéBalls make a sound when thrown to send out a Pokémon. #endif // GUARD_CONFIG_BATTLE_H From cbbe9176bd8d7650b91b538c61f4b82aae2af614 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 21:03:21 -0700 Subject: [PATCH 06/10] Removed tabs --- src/pokeball.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pokeball.c b/src/pokeball.c index b585873e50ae..8b3a42bea8c0 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -551,8 +551,8 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) { u32 throwCaseId, ballId, battlerId, ballSpriteId; bool32 notSendOut = FALSE; - u32 throwXoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? 24 : 0; - s32 throwYoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? -16 : 24; + u32 throwXoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? 24 : 0; + s32 throwYoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? -16 : 24; if (gTasks[taskId].tFrames == 0) { @@ -581,7 +581,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gSprites[ballSpriteId].x = 24; gSprites[ballSpriteId].y = 68; gSprites[ballSpriteId].callback = SpriteCB_MonSendOut_1; - DoPokeballSendOutSoundEffect(); + DoPokeballSendOutSoundEffect(); break; case POKEBALL_OPPONENT_SENDOUT: gSprites[ballSpriteId].x = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X) + throwXoffset; @@ -589,7 +589,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gBattlerTarget = battlerId; gSprites[ballSpriteId].data[0] = 0; gSprites[ballSpriteId].callback = GetOpponentMonSendOutCallback(); - DoPokeballSendOutSoundEffect(); + DoPokeballSendOutSoundEffect(); break; default: gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); @@ -618,15 +618,15 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) static void DoPokeballSendOutSoundEffect(void) { - if (B_THROW_BALLS_SOUND < GEN_5) - return; + if (B_THROW_BALLS_SOUND < GEN_5) + return; - PlaySE(SE_BALL_THROW); + PlaySE(SE_BALL_THROW); } static void *GetOpponentMonSendOutCallback(void) { - return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_MonSendOut_1 : SpriteCB_OpponentMonSendOut; + return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_MonSendOut_1 : SpriteCB_OpponentMonSendOut; } // This sequence of functions is very similar to those that get run when @@ -1137,9 +1137,9 @@ static bool32 IsBattlerPlayer(u32 battler) static void SpriteCB_MonSendOut_1(struct Sprite *sprite) { - bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); - u32 coordX = (isPlayer) ? BATTLER_COORD_X_2 : BATTLER_COORD_X; - u32 coordY = (isPlayer) ? BATTLER_COORD_Y_PIC_OFFSET : BATTLER_COORD_Y; + bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); + u32 coordX = (isPlayer) ? BATTLER_COORD_X_2 : BATTLER_COORD_X; + u32 coordY = (isPlayer) ? BATTLER_COORD_Y_PIC_OFFSET : BATTLER_COORD_Y; sprite->data[0] = 25; sprite->data[2] = GetBattlerSpriteCoord(sprite->sBattler, coordX); @@ -1156,8 +1156,8 @@ static void SpriteCB_MonSendOut_2(struct Sprite *sprite) { u32 r6; u32 r7; - bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); - bool32 rightPosition = (isPlayer) ? B_POSITION_PLAYER_RIGHT : B_POSITION_OPPONENT_RIGHT; + bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); + bool32 rightPosition = (isPlayer) ? B_POSITION_PLAYER_RIGHT : B_POSITION_OPPONENT_RIGHT; if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) { From 9b66584e59df941b17e7c31802380d8efa6eaeda Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 11 Jul 2024 21:07:54 -0700 Subject: [PATCH 07/10] Undef'd HIBYTE and removed extra bool32 --- src/pokeball.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pokeball.c b/src/pokeball.c index 8b3a42bea8c0..82a71f9473ad 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1156,8 +1156,7 @@ static void SpriteCB_MonSendOut_2(struct Sprite *sprite) { u32 r6; u32 r7; - bool32 isPlayer = IsBattlerPlayer(sprite->sBattler); - bool32 rightPosition = (isPlayer) ? B_POSITION_PLAYER_RIGHT : B_POSITION_OPPONENT_RIGHT; + bool32 rightPosition = (IsBattlerPlayer(sprite->sBattler)) ? B_POSITION_PLAYER_RIGHT : B_POSITION_OPPONENT_RIGHT; if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) { @@ -1210,6 +1209,8 @@ static void SpriteCB_MonSendOut_2(struct Sprite *sprite) } } +#undef HIBYTE + static void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite) { if (sprite->data[0]++ > 24) From e0ca4216422eea32754478da82fdc8831b966ebb Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 13 Jul 2024 09:35:53 -0700 Subject: [PATCH 08/10] Made functions inline per https://github.com/rh-hideout/pokeemerald-expansion/pull/4953/files\#r1675397114 Split into B_THROW_BALLS_SOUND B_PLAYER_THROW_BALLS_SOUND and B_ENEMY_THROW_BALLS_SOUND per https://github.com/rh-hideout/pokeemerald-expansion/pull/4953/files\#r1676143761 --- data/scripts/debug.inc | 12 ++++++++++++ include/config/battle.h | 7 +++++-- src/pokeball.c | 29 +++++++++++++++++------------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 02a93a4d9c7b..12944645f8e9 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -138,14 +138,26 @@ Debug_EventScript_Text_DefensiveIVs: .string "HP IVs: {STR_VAR_1}, DEF IVs: {STR_VAR_2}, SPDEF IVs: {STR_VAR_3}$" Debug_EventScript_Script_1:: + setflag FLAG_BADGE01_GET + setflag FLAG_BADGE02_GET + setflag FLAG_BADGE03_GET + setflag FLAG_BADGE04_GET + setflag FLAG_BADGE05_GET + setflag FLAG_BADGE06_GET + setflag FLAG_BADGE07_GET + setflag FLAG_BADGE08_GET + givemon SPECIES_ARCEUS, 100, ITEM_EARTH_PLATE, ball=ITEM_POKE_BALL + givemon SPECIES_ARCEUS, 100, ITEM_PIXIE_PLATE, ball=ITEM_GREAT_BALL release end Debug_EventScript_Script_2:: + trainerbattle_double TRAINER_GINA_AND_MIA_1, Route104_Text_GinaIntro, Route104_Text_GinaDefeat, Route104_Text_GinaNotEnoughMons release end Debug_EventScript_Script_3:: + trainerbattle_single TRAINER_CINDY_1, Route104_Text_CindyIntro, Route104_Text_CindyDefeat, Route104_EventScript_TryRegisterCindyAfterBattle release end diff --git a/include/config/battle.h b/include/config/battle.h index 1d00f052b048..881e8a27156d 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -267,7 +267,10 @@ #define B_NEW_MORNING_SUN_STAR_PARTICLE TRUE // If set to TRUE, it updates Morning Sun's star particles. #define B_NEW_IMPACT_PALETTE TRUE // If set to TRUE, it updates the basic 'hit' palette. #define B_NEW_SURF_PARTICLE_PALETTE TRUE // If set to TRUE, it updates Surf's wave palette. -#define B_OPPONENT_THROW_BALLS GEN_LATEST // In GEN_6+, opposing Trainers throw PokéBalls into battle instead of just dropping them. -#define B_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, Trainers PokéBalls make a sound when thrown to send out a Pokémon. + +// Poké Ball animation and sounds +#define B_ENEMY_THROW_BALLS GEN_LATEST // In GEN_6+, enemy Trainers throw Poké Balls into battle instead of them just appearing on the ground and opening. +#define B_ENEMY_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, enemy Trainer's Poké Balls make a sound when thrown to send out a Pokémon. This can only be used when B_ENEMY_THROW_BALLS is set to GEN_6 or later. +#define B_PLAYER_THROW_BALLS_SOUND GEN_LATEST // In GEN_5+, the player's Poké Balls make a sound when thrown to send out a Pokémon. #endif // GUARD_CONFIG_BATTLE_H diff --git a/src/pokeball.c b/src/pokeball.c index 82a71f9473ad..4a96c1c9650d 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -16,9 +16,9 @@ #include "constants/songs.h" static void Task_DoPokeballSendOutAnim(u8 taskId); -static void DoPokeballSendOutSoundEffect(void); -static void *GetOpponentMonSendOutCallback(void); -static bool32 IsBattlerPlayer(u32 battler); +static inline void DoPokeballSendOutSoundEffect(u32 battler); +static inline void *GetOpponentMonSendOutCallback(void); +static inline bool32 IsBattlerPlayer(u32 battler); static void SpriteCB_MonSendOut_1(struct Sprite *sprite); static void SpriteCB_MonSendOut_2(struct Sprite *sprite); static void SpriteCB_OpponentMonSendOut(struct Sprite *sprite); @@ -551,8 +551,8 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) { u32 throwCaseId, ballId, battlerId, ballSpriteId; bool32 notSendOut = FALSE; - u32 throwXoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? 24 : 0; - s32 throwYoffset = (B_OPPONENT_THROW_BALLS >= GEN_6) ? -16 : 24; + u32 throwXoffset = (B_ENEMY_THROW_BALLS >= GEN_6) ? 24 : 0; + s32 throwYoffset = (B_ENEMY_THROW_BALLS >= GEN_6) ? -16 : 24; if (gTasks[taskId].tFrames == 0) { @@ -581,7 +581,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gSprites[ballSpriteId].x = 24; gSprites[ballSpriteId].y = 68; gSprites[ballSpriteId].callback = SpriteCB_MonSendOut_1; - DoPokeballSendOutSoundEffect(); + DoPokeballSendOutSoundEffect(battlerId); break; case POKEBALL_OPPONENT_SENDOUT: gSprites[ballSpriteId].x = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X) + throwXoffset; @@ -589,7 +589,7 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) gBattlerTarget = battlerId; gSprites[ballSpriteId].data[0] = 0; gSprites[ballSpriteId].callback = GetOpponentMonSendOutCallback(); - DoPokeballSendOutSoundEffect(); + DoPokeballSendOutSoundEffect(battlerId); break; default: gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); @@ -616,17 +616,22 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) PlaySE(SE_BALL_THROW); } -static void DoPokeballSendOutSoundEffect(void) +STATIC_ASSERT(B_ENEMY_THROW_BALLS_SOUND < GEN_5 || B_ENEMY_THROW_BALLS >= GEN_6,OpponentThrowBallAndSoundMustBeOnTogether) + +static inline void DoPokeballSendOutSoundEffect(u32 battler) { - if (B_THROW_BALLS_SOUND < GEN_5) + if (IsBattlerPlayer(battler) && B_PLAYER_THROW_BALLS_SOUND < GEN_5) + return; + + if (!IsBattlerPlayer(battler) && B_ENEMY_THROW_BALLS_SOUND < GEN_5) return; PlaySE(SE_BALL_THROW); } -static void *GetOpponentMonSendOutCallback(void) +static inline void *GetOpponentMonSendOutCallback(void) { - return (B_OPPONENT_THROW_BALLS >= GEN_6) ? SpriteCB_MonSendOut_1 : SpriteCB_OpponentMonSendOut; + return (B_ENEMY_THROW_BALLS >= GEN_6) ? SpriteCB_MonSendOut_1 : SpriteCB_OpponentMonSendOut; } // This sequence of functions is very similar to those that get run when @@ -1130,7 +1135,7 @@ static void SpriteCB_BallThrow_CaptureMon(struct Sprite *sprite) } } -static bool32 IsBattlerPlayer(u32 battler) +static inline bool32 IsBattlerPlayer(u32 battler) { return (battler % B_POSITION_PLAYER_RIGHT) ? FALSE : TRUE; } From 3d51dbab32bcb0a3ea6c82a7d591e02d95ab9a44 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 13 Jul 2024 19:03:38 -0700 Subject: [PATCH 09/10] Reset debug script --- data/scripts/debug.inc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 12944645f8e9..02a93a4d9c7b 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -138,26 +138,14 @@ Debug_EventScript_Text_DefensiveIVs: .string "HP IVs: {STR_VAR_1}, DEF IVs: {STR_VAR_2}, SPDEF IVs: {STR_VAR_3}$" Debug_EventScript_Script_1:: - setflag FLAG_BADGE01_GET - setflag FLAG_BADGE02_GET - setflag FLAG_BADGE03_GET - setflag FLAG_BADGE04_GET - setflag FLAG_BADGE05_GET - setflag FLAG_BADGE06_GET - setflag FLAG_BADGE07_GET - setflag FLAG_BADGE08_GET - givemon SPECIES_ARCEUS, 100, ITEM_EARTH_PLATE, ball=ITEM_POKE_BALL - givemon SPECIES_ARCEUS, 100, ITEM_PIXIE_PLATE, ball=ITEM_GREAT_BALL release end Debug_EventScript_Script_2:: - trainerbattle_double TRAINER_GINA_AND_MIA_1, Route104_Text_GinaIntro, Route104_Text_GinaDefeat, Route104_Text_GinaNotEnoughMons release end Debug_EventScript_Script_3:: - trainerbattle_single TRAINER_CINDY_1, Route104_Text_CindyIntro, Route104_Text_CindyDefeat, Route104_EventScript_TryRegisterCindyAfterBattle release end From 88f8ddf89e07869f7842b48a1cbe3ec8296a652e Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 13 Jul 2024 23:04:53 -0700 Subject: [PATCH 10/10] Removed static assert per Discord conversation with Alex --- src/pokeball.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pokeball.c b/src/pokeball.c index 4a96c1c9650d..914455af5a83 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -616,8 +616,6 @@ static void Task_DoPokeballSendOutAnim(u8 taskId) PlaySE(SE_BALL_THROW); } -STATIC_ASSERT(B_ENEMY_THROW_BALLS_SOUND < GEN_5 || B_ENEMY_THROW_BALLS >= GEN_6,OpponentThrowBallAndSoundMustBeOnTogether) - static inline void DoPokeballSendOutSoundEffect(u32 battler) { if (IsBattlerPlayer(battler) && B_PLAYER_THROW_BALLS_SOUND < GEN_5)