Merge pull request #1995 from Jaizu/adjust_friendship

Make AdjustFriendship more readable
This commit is contained in:
GriffinR 2024-05-21 12:01:53 -04:00 committed by GitHub
commit aa4fa925c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 36 additions and 24 deletions

View File

@ -5877,16 +5877,11 @@ u16 ModifyStatByNature(u8 nature, u16 stat, u8 statIndex)
return retVal;
}
#define IS_LEAGUE_BATTLE \
((gBattleTypeFlags & BATTLE_TYPE_TRAINER) \
&& (gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_ELITE_FOUR \
|| gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_LEADER \
|| gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_CHAMPION)) \
void AdjustFriendship(struct Pokemon *mon, u8 event)
{
u16 species, heldItem;
u8 holdEffect;
s8 mod;
if (ShouldSkipFriendshipChange())
return;
@ -5916,26 +5911,43 @@ void AdjustFriendship(struct Pokemon *mon, u8 event)
if (friendship > 199)
friendshipLevel++;
if ((event != FRIENDSHIP_EVENT_WALKING || !(Random() & 1))
&& (event != FRIENDSHIP_EVENT_LEAGUE_BATTLE || IS_LEAGUE_BATTLE))
if (event == FRIENDSHIP_EVENT_WALKING)
{
s8 mod = sFriendshipEventModifiers[event][friendshipLevel];
if (mod > 0 && holdEffect == HOLD_EFFECT_FRIENDSHIP_UP)
mod = (150 * mod) / 100;
friendship += mod;
if (mod > 0)
{
if (GetMonData(mon, MON_DATA_POKEBALL, 0) == ITEM_LUXURY_BALL)
friendship++;
if (GetMonData(mon, MON_DATA_MET_LOCATION, 0) == GetCurrentRegionMapSectionId())
friendship++;
}
if (friendship < 0)
friendship = 0;
if (friendship > MAX_FRIENDSHIP)
friendship = MAX_FRIENDSHIP;
SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship);
// 50% chance every 128 steps
if (Random() & 1)
return;
}
if (event == FRIENDSHIP_EVENT_LEAGUE_BATTLE)
{
// Only if it's a trainer battle with league progression significance
if (!(gBattleTypeFlags & BATTLE_TYPE_TRAINER))
return;
if (!(gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_LEADER
|| gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_ELITE_FOUR
|| gTrainers[gTrainerBattleOpponent_A].trainerClass == TRAINER_CLASS_CHAMPION))
return;
}
mod = sFriendshipEventModifiers[event][friendshipLevel];
if (mod > 0 && holdEffect == HOLD_EFFECT_FRIENDSHIP_UP)
// 50% increase, rounding down
mod = (150 * mod) / 100;
friendship += mod;
if (mod > 0)
{
if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == ITEM_LUXURY_BALL)
friendship++;
if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == GetCurrentRegionMapSectionId())
friendship++;
}
if (friendship < 0)
friendship = 0;
if (friendship > MAX_FRIENDSHIP)
friendship = MAX_FRIENDSHIP;
SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship);
}
}