Cleaned up party data access GetPartyBattlerData (#6172)

This commit is contained in:
Eduardo Quezada 2025-02-03 16:34:15 -03:00 committed by GitHub
parent 14178edfe3
commit e9c14e35ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 56 additions and 203 deletions

View File

@ -2699,19 +2699,9 @@ static bool32 AnyUsefulStatIsRaised(u32 battler)
return FALSE;
}
struct Pokemon *GetPartyBattlerPartyData(u32 battlerId, u32 switchBattler)
{
struct Pokemon *mon;
if (GetBattlerSide(battlerId) == B_SIDE_PLAYER)
mon = &gPlayerParty[switchBattler];
else
mon = &gEnemyParty[switchBattler];
return mon;
}
static bool32 PartyBattlerShouldAvoidHazards(u32 currBattler, u32 switchBattler)
{
struct Pokemon *mon = GetPartyBattlerPartyData(currBattler, switchBattler);
struct Pokemon *mon = &GetBattlerParty(currBattler)[switchBattler];
u32 ability = GetMonAbility(mon); // we know our own party data
u32 holdEffect;
u32 species = GetMonData(mon, MON_DATA_SPECIES);

View File

@ -370,12 +370,7 @@ void LaunchBattleAnimation(u32 animType, u32 animId)
InitPrioritiesForVisibleBattlers();
UpdateOamPriorityInAllHealthboxes(0, sAnimHideHpBoxes);
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
{
if (GetBattlerSide(i) != B_SIDE_PLAYER)
gAnimBattlerSpecies[i] = GetMonData(&gEnemyParty[gBattlerPartyIndexes[i]], MON_DATA_SPECIES);
else
gAnimBattlerSpecies[i] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[i]], MON_DATA_SPECIES);
}
gAnimBattlerSpecies[i] = GetMonData(GetPartyBattlerData(i), MON_DATA_SPECIES);
}
else
{

View File

@ -932,16 +932,9 @@ void AnimTask_MetallicShine(u8 taskId)
}
if (IsContest())
{
species = gContestResources->moveAnim->species;
}
else
{
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
else
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
}
species = GetMonData(GetPartyBattlerData(gBattleAnimAttacker), MON_DATA_SPECIES);
spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER);
newSpriteId = CreateInvisibleSpriteCopy(gBattleAnimAttacker, spriteId, species);

View File

@ -3417,51 +3417,24 @@ void AnimTask_RolePlaySilhouette(u8 taskId)
isShiny = gContestResources->moveAnim->targetIsShiny;
species = gContestResources->moveAnim->targetSpecies;
xOffset = 20;
priority = GetBattlerSpriteBGPriority(gBattleAnimAttacker);
}
else
{
struct Pokemon *mon = GetPartyBattlerData(gBattleAnimTarget);
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
{
isBackPic = FALSE;
personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_PERSONALITY);
isShiny = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies == SPECIES_NONE)
{
if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER)
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_SPECIES);
else
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_SPECIES);
}
else
{
species = gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies;
}
xOffset = 20;
priority = GetBattlerSpriteBGPriority(gBattleAnimAttacker);
}
else
{
isBackPic = TRUE;
personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_PERSONALITY);
isShiny = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies == SPECIES_NONE)
{
if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER)
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_SPECIES);
else
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimTarget]], MON_DATA_SPECIES);
}
else
{
species = gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies;
}
personality = GetMonData(mon, MON_DATA_PERSONALITY);
isShiny = GetMonData(mon, MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies == SPECIES_NONE)
species = GetMonData(mon, MON_DATA_SPECIES);
else
species = gBattleSpritesDataPtr->battlerData[gBattleAnimTarget].transformSpecies;
xOffset = -20;
priority = GetBattlerSpriteBGPriority(gBattleAnimAttacker);
}
xOffset = -20;
}
priority = GetBattlerSpriteBGPriority(gBattleAnimAttacker);
coord1 = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X);
coord2 = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y);
@ -5331,28 +5304,22 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId)
}
else
{
struct Pokemon *mon = GetPartyBattlerData(gBattleAnimAttacker);
personality = GetMonData(mon, MON_DATA_PERSONALITY);
isShiny = GetMonData(mon, MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE)
species = GetMonData(mon, MON_DATA_SPECIES);
else
species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies;
if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER)
{
personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY);
isShiny = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE)
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
else
species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies;
subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1;
isBackPic = FALSE;
x = DISPLAY_WIDTH + 32;
}
else
{
personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY);
isShiny = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_IS_SHINY);
if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
else
species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies;
subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1;
isBackPic = TRUE;
x = -32;

View File

@ -143,28 +143,16 @@ u8 GetBattlerYDelta(u8 battlerId, u16 species)
u8 ret;
species = SanitizeSpeciesId(species);
if (GetBattlerSide(battlerId) == B_SIDE_PLAYER || IsContest())
if (IsContest())
{
if (species == SPECIES_UNOWN)
{
if (IsContest())
{
if (gContestResources->moveAnim->hasTargetAnim)
personality = gContestResources->moveAnim->targetPersonality;
else
personality = gContestResources->moveAnim->personality;
}
if (gContestResources->moveAnim->hasTargetAnim)
personality = gContestResources->moveAnim->targetPersonality;
else
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_PERSONALITY);
else
personality = gTransformedPersonalities[battlerId];
}
personality = gContestResources->moveAnim->personality;
species = GetUnownSpeciesId(personality);
}
ret = gSpeciesInfo[species].backPicYOffset;
}
else
{
@ -172,14 +160,17 @@ u8 GetBattlerYDelta(u8 battlerId, u16 species)
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_PERSONALITY);
personality = GetMonData(GetPartyBattlerData(battlerId), MON_DATA_PERSONALITY);
else
personality = gTransformedPersonalities[battlerId];
species = GetUnownSpeciesId(personality);
}
ret = gSpeciesInfo[species].frontPicYOffset;
}
if (GetBattlerSide(battlerId) == B_SIDE_PLAYER || IsContest())
ret = gSpeciesInfo[species].backPicYOffset;
else
ret = gSpeciesInfo[species].frontPicYOffset;
return ret;
}
@ -279,22 +270,13 @@ u8 GetBattlerYCoordWithElevation(u8 battlerId)
y = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y);
if (!IsContest())
{
if (GetBattlerSide(battlerId) != B_SIDE_PLAYER)
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
else
species = spriteInfo[battlerId].transformSpecies;
}
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(GetPartyBattlerData(battlerId), MON_DATA_SPECIES);
else
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);
else
species = spriteInfo[battlerId].transformSpecies;
}
species = spriteInfo[battlerId].transformSpecies;
if (GetBattlerSide(battlerId) != B_SIDE_PLAYER)
y -= GetBattlerElevation(battlerId, species);
}
@ -845,19 +827,8 @@ bool8 IsBattlerSpritePresent(u8 battlerId)
if (GetBattlerPosition(battlerId) == 0xff)
return FALSE;
if (!gBattleStruct->spriteIgnore0Hp)
{
if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT)
{
if (GetMonData(&gEnemyParty[gBattlerPartyIndexes[battlerId]], MON_DATA_HP) == 0)
return FALSE;
}
else
{
if (GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_HP) == 0)
return FALSE;
}
}
if (!gBattleStruct->spriteIgnore0Hp && GetMonData(GetPartyBattlerData(battlerId), MON_DATA_HP) == 0)
return FALSE;
return TRUE;
}
}
@ -1874,26 +1845,16 @@ static u16 GetBattlerYDeltaFromSpriteId(u8 spriteId)
}
else
{
if (GetBattlerSide(i) == B_SIDE_PLAYER)
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[i]], MON_DATA_SPECIES);
else
species = spriteInfo[battlerId].transformSpecies;
return gSpeciesInfo[species].backPicYOffset;
}
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(GetPartyBattlerData(i), MON_DATA_SPECIES);
else
{
spriteInfo = gBattleSpritesDataPtr->battlerData;
if (!spriteInfo[battlerId].transformSpecies)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[i]], MON_DATA_SPECIES);
else
species = spriteInfo[battlerId].transformSpecies;
species = spriteInfo[battlerId].transformSpecies;
if (GetBattlerSide(i) == B_SIDE_PLAYER)
return gSpeciesInfo[species].backPicYOffset;
else
return gSpeciesInfo[species].frontPicYOffset;
}
}
}
}

View File

@ -908,10 +908,7 @@ void AnimTask_SwitchOutBallEffect(u8 taskId)
u32 selectedPalettes;
spriteId = gBattlerSpriteIds[gBattleAnimAttacker];
if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER)
ballId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_POKEBALL);
else
ballId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_POKEBALL);
ballId = GetMonData(GetPartyBattlerData(gBattleAnimAttacker), MON_DATA_POKEBALL);
switch (gTasks[taskId].data[0])
{

View File

@ -316,16 +316,9 @@ void AnimTask_DrawFallingWhiteLinesOnAttacker(u8 taskId)
}
if (IsContest())
{
species = gContestResources->moveAnim->species;
}
else
{
if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
else
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES);
}
species = GetMonData(GetPartyBattlerData(gBattleAnimAttacker), MON_DATA_SPECIES);
spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER);
newSpriteId = CreateInvisibleSpriteCopy(gBattleAnimAttacker, spriteId, species);
@ -458,16 +451,9 @@ static void StatsChangeAnimation_Step1(u8 taskId)
}
if (IsContest())
{
sAnimStatsChangeData->species = gContestResources->moveAnim->species;
}
else
{
if (GetBattlerSide(sAnimStatsChangeData->battler1) != B_SIDE_PLAYER)
sAnimStatsChangeData->species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[sAnimStatsChangeData->battler1]], MON_DATA_SPECIES);
else
sAnimStatsChangeData->species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[sAnimStatsChangeData->battler1]], MON_DATA_SPECIES);
}
sAnimStatsChangeData->species = GetMonData(GetPartyBattlerData(sAnimStatsChangeData->battler1), MON_DATA_SPECIES);
gTasks[taskId].func = StatsChangeAnimation_Step2;
}
@ -840,16 +826,9 @@ void StartMonScrollingBgMask(u8 taskId, int UNUSED unused, u16 scrollSpeed, u8 b
SetGpuReg(REG_OFFSET_BG1CNT, bg1Cnt);
if (IsContest())
{
species = gContestResources->moveAnim->species;
}
else
{
if (GetBattlerSide(battler) != B_SIDE_PLAYER)
species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES);
else
species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES);
}
species = GetMonData(GetPartyBattlerData(battler), MON_DATA_SPECIES);
spriteId = CreateInvisibleSpriteCopy(battler, gBattlerSpriteIds[battler], species);
if (includePartner)

View File

@ -1349,25 +1349,11 @@ static u8 GetWaterSpoutPowerForAnim(void)
u8 i;
u16 hp;
u16 maxhp;
u16 partyIndex;
struct Pokemon *slot;
struct Pokemon *slot = GetPartyBattlerData(gBattleAnimAttacker);
if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER)
{
partyIndex = gBattlerPartyIndexes[gBattleAnimAttacker];
slot = &gPlayerParty[partyIndex];
maxhp = GetMonData(slot, MON_DATA_MAX_HP);
hp = GetMonData(slot, MON_DATA_HP);
maxhp /= 4;
}
else
{
partyIndex = gBattlerPartyIndexes[gBattleAnimAttacker];
slot = &gEnemyParty[partyIndex];
maxhp = GetMonData(slot, MON_DATA_MAX_HP);
hp = GetMonData(slot, MON_DATA_HP);
maxhp /= 4;
}
maxhp = GetMonData(slot, MON_DATA_MAX_HP);
hp = GetMonData(slot, MON_DATA_HP);
maxhp /= 4;
for (i = 0; i < 3; i++)
{
if (hp < maxhp * (i + 1))

View File

@ -197,13 +197,10 @@ void ActivateDynamax(u32 battler)
// Unsets the flags used for Dynamaxing and reverts max HP if needed.
void UndoDynamax(u32 battler)
{
u8 side = GetBattlerSide(battler);
u8 monId = gBattlerPartyIndexes[battler];
// Revert HP if battler is still Dynamaxed.
if (GetActiveGimmick(battler) == GIMMICK_DYNAMAX)
{
struct Pokemon *mon = (side == B_SIDE_PLAYER) ? &gPlayerParty[monId] : &gEnemyParty[monId];
struct Pokemon *mon = GetPartyBattlerData(battler);
uq4_12_t mult = GetDynamaxLevelHPMultiplier(GetMonData(mon, MON_DATA_DYNAMAX_LEVEL), TRUE);
gBattleMons[battler].hp = UQ_4_12_TO_INT((GetMonData(mon, MON_DATA_HP) * mult + 1) + UQ_4_12_ROUND); // round up
SetMonData(mon, MON_DATA_HP, &gBattleMons[battler].hp);

View File

@ -14755,16 +14755,9 @@ static void Cmd_trywish(void)
case 1: // heal effect
PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, gBattlerTarget, gWishFutureKnock.wishPartyId[gBattlerTarget])
if (B_WISH_HP_SOURCE >= GEN_5)
{
if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
gBattleStruct->moveDamage[gBattlerTarget] = max(1, GetMonData(&gPlayerParty[gWishFutureKnock.wishPartyId[gBattlerTarget]], MON_DATA_MAX_HP) / 2);
else
gBattleStruct->moveDamage[gBattlerTarget] = max(1, GetMonData(&gEnemyParty[gWishFutureKnock.wishPartyId[gBattlerTarget]], MON_DATA_MAX_HP) / 2);
}
gBattleStruct->moveDamage[gBattlerTarget] = max(1, GetMonData(&GetBattlerParty(gBattlerTarget)[gWishFutureKnock.wishPartyId[gBattlerTarget]], MON_DATA_MAX_HP) / 2);
else
{
gBattleStruct->moveDamage[gBattlerTarget] = max(1, GetNonDynamaxMaxHP(gBattlerAttacker) / 2);
}
gBattleStruct->moveDamage[gBattlerTarget] *= -1;
if (gBattleMons[gBattlerTarget].hp == gBattleMons[gBattlerTarget].maxHP)

View File

@ -993,16 +993,11 @@ static void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite)
u16 wantedCryCase;
u8 taskId;
mon = GetPartyBattlerData(battlerId);
if (GetBattlerSide(battlerId) != B_SIDE_PLAYER)
{
mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]];
pan = 25;
}
else
{
mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]];
pan = -25;
}
if ((battlerId == GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) || battlerId == GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT))
&& IsDoubleBattle() && gBattleSpritesDataPtr->animationData->introAnimActive)