Skip to content

Commit

Permalink
ally switch fix elevation shadow and direction on opposing side (#4451)
Browse files Browse the repository at this point in the history
Co-authored-by: ghoulslash <[email protected]>
  • Loading branch information
ghoulslash and ghoulslash authored Apr 26, 2024
1 parent dd098ba commit 2648618
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/battle_gfx_sfx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void BattleStopLowHpSound(void);
u8 GetMonHPBarLevel(struct Pokemon *mon);
void HandleBattleLowHpMusicChange(void);
void SetBattlerSpriteAffineMode(u8 affineMode);
void CreateEnemyShadowSprite(u32 battler);
void LoadAndCreateEnemyShadowSprites(void);
void SpriteCB_SetInvisible(struct Sprite *sprite);
void SetBattlerShadowSpriteCallback(u8 battler, u16 species);
Expand Down
19 changes: 17 additions & 2 deletions src/battle_anim_effects_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6523,6 +6523,11 @@ void PrepareDoubleTeamAnim(u32 taskId, u32 animBattler, bool32 forAllySwitch)
gSprites[spriteId].sBattlerFlank = (animBattler != ANIM_ATTACKER);
else
gSprites[spriteId].sBattlerFlank = (animBattler == ANIM_ATTACKER);

// correct direction on opponent side
if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_OPPONENT)
gSprites[spriteId].sBattlerFlank ^= 1;

gSprites[spriteId].callback = AnimDoubleTeam;
task->tBlendSpritesCount++;
}
Expand All @@ -6548,11 +6553,21 @@ static inline void SwapStructData(void *s1, void *s2, void *data, u32 size)

static void ReloadBattlerSprites(u32 battler, struct Pokemon *party)
{
BattleLoadMonSpriteGfx(&party[gBattlerPartyIndexes[battler]], battler);
struct Pokemon *mon = &party[gBattlerPartyIndexes[battler]];
BattleLoadMonSpriteGfx(mon, battler);
CreateBattlerSprite(battler);
UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], &party[gBattlerPartyIndexes[battler]], HEALTHBOX_ALL);
UpdateHealthboxAttribute(gHealthboxSpriteIds[battler], mon, HEALTHBOX_ALL);
// If battler is mega evolved / primal reversed, hide the sprite until the move animation finishes.
MegaIndicator_SetVisibilities(gHealthboxSpriteIds[battler], TRUE);

// Try to recreate shadow sprite
if (gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId < MAX_SPRITES)
{
DestroySprite(&gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId]);
gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = MAX_SPRITES;
CreateEnemyShadowSprite(battler);
SetBattlerShadowSpriteCallback(battler, GetMonData(mon, MON_DATA_SPECIES));
}
}

static void AnimTask_AllySwitchDataSwap(u8 taskId)
Expand Down
33 changes: 22 additions & 11 deletions src/battle_gfx_sfx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,27 +1108,36 @@ void SetBattlerSpriteAffineMode(u8 affineMode)

#define tBattlerId data[0]

void CreateEnemyShadowSprite(u32 battler)
{
gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow,
GetBattlerSpriteCoord(battler, BATTLER_COORD_X),
GetBattlerSpriteCoord(battler, BATTLER_COORD_Y) + 29,
0xC8);
if (gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId < MAX_SPRITES)
gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].data[0] = battler;
}

void LoadAndCreateEnemyShadowSprites(void)
{
u8 battler;
u32 i;

LoadCompressedSpriteSheet(&gSpriteSheet_EnemyShadow);

// initialize shadow sprite ids
for (i = 0; i < gBattlersCount; i++)
{
gBattleSpritesDataPtr->healthBoxesData[i].shadowSpriteId = MAX_SPRITES;
}

battler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow,
GetBattlerSpriteCoord(battler, BATTLER_COORD_X),
GetBattlerSpriteCoord(battler, BATTLER_COORD_Y) + 29,
0xC8);
gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].data[0] = battler;

CreateEnemyShadowSprite(battler);

if (IsDoubleBattle())
{
battler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId = CreateSprite(&gSpriteTemplate_EnemyShadow,
GetBattlerSpriteCoord(battler, BATTLER_COORD_X),
GetBattlerSpriteCoord(battler, BATTLER_COORD_Y) + 29,
0xC8);
gSprites[gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId].data[0] = battler;
CreateEnemyShadowSprite(battler);
}
}

Expand Down Expand Up @@ -1169,6 +1178,8 @@ void SetBattlerShadowSpriteCallback(u8 battler, u16 species)
// The player's shadow is never seen.
if (GetBattlerSide(battler) == B_SIDE_PLAYER || gBattleScripting.monCaught)
return;
if (gBattleSpritesDataPtr->healthBoxesData[battler].shadowSpriteId >= MAX_SPRITES)
return;

if (gBattleSpritesDataPtr->battlerData[battler].transformSpecies != SPECIES_NONE)
species = gBattleSpritesDataPtr->battlerData[battler].transformSpecies;
Expand Down

0 comments on commit 2648618

Please sign in to comment.