diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_main.c | 2 | ||||
-rw-r--r-- | src/battle_script_commands.c | 2 | ||||
-rw-r--r-- | src/battle_util2.c | 6 | ||||
-rw-r--r-- | src/field_poison.c | 2 | ||||
-rw-r--r-- | src/field_specials.c | 2 | ||||
-rw-r--r-- | src/party_menu.c | 6 | ||||
-rw-r--r-- | src/pokemon.c | 169 |
7 files changed, 100 insertions, 89 deletions
diff --git a/src/battle_main.c b/src/battle_main.c index d7f43ce75..3dd790fb9 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -701,7 +701,7 @@ static void CB2_InitBattleInternal(void) } gMain.inBattle = TRUE; for (i = 0; i < PARTY_SIZE; ++i) - AdjustFriendship(&gPlayerParty[i], 3); + AdjustFriendship(&gPlayerParty[i], FRIENDSHIP_EVENT_LEAGUE_BATTLE); gBattleCommunication[MULTIUSE_STATE] = 0; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 35328d6c1..30b8bda88 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3241,7 +3241,7 @@ static void atk23_getexp(void) gLeveledUpInBattle |= gBitTable[gBattleStruct->expGetterMonId]; gBattlescriptCurrInstr = BattleScript_LevelUp; gBattleMoveDamage = (gBattleBufferB[gActiveBattler][2] | (gBattleBufferB[gActiveBattler][3] << 8)); - AdjustFriendship(&gPlayerParty[gBattleStruct->expGetterMonId], 0); + AdjustFriendship(&gPlayerParty[gBattleStruct->expGetterMonId], FRIENDSHIP_EVENT_GROW_LEVEL); // update battle mon structure after level up if (gBattlerPartyIndexes[0] == gBattleStruct->expGetterMonId && gBattleMons[0].hp) { diff --git a/src/battle_util2.c b/src/battle_util2.c index b1036ef0b..e3fa1a6a7 100644 --- a/src/battle_util2.c +++ b/src/battle_util2.c @@ -85,12 +85,12 @@ void AdjustFriendshipOnBattleFaint(u8 battlerId) if (gBattleMons[opposingBattlerId].level > gBattleMons[battlerId].level) { if (gBattleMons[opposingBattlerId].level - gBattleMons[battlerId].level > 29) - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], 9); + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_LARGE); else - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], 7); + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL); } else { - AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], 7); + AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL); } } diff --git a/src/field_poison.c b/src/field_poison.c index d4ed5e45f..1e2a30c0c 100644 --- a/src/field_poison.c +++ b/src/field_poison.c @@ -33,7 +33,7 @@ static void FaintFromFieldPoison(u8 partyIdx) { struct Pokemon *pokemon = gPlayerParty + partyIdx; u32 status = STATUS1_NONE; - AdjustFriendship(pokemon, 8); + AdjustFriendship(pokemon, FRIENDSHIP_EVENT_FAINT_OUTSIDE_BATTLE); SetMonData(pokemon, MON_DATA_STATUS, &status); GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); StringGetEnd10(gStringVar1); diff --git a/src/field_specials.c b/src/field_specials.c index 8e5c79cb1..efa3451e0 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -2064,7 +2064,7 @@ void RunMassageCooldownStepCounter(void) void DaisyMassageServices(void) { - AdjustFriendship(&gPlayerParty[gSpecialVar_0x8004], 6); + AdjustFriendship(&gPlayerParty[gSpecialVar_0x8004], FRIENDSHIP_EVENT_MASSAGE); VarSet(VAR_MASSAGE_COOLDOWN_STEP_COUNTER, 0); } diff --git a/src/party_menu.c b/src/party_menu.c index 1acbc04ea..8dcc1d450 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -4315,7 +4315,7 @@ static void sub_8124E48(void) && PSA_IsCancelDisabled() == TRUE) { GiveMoveToMon(&gPlayerParty[gPartyMenu.slotId], ItemIdToBattleMoveId(gSpecialVar_ItemId)); - AdjustFriendship(&gPlayerParty[gPartyMenu.slotId], 4); + AdjustFriendship(&gPlayerParty[gPartyMenu.slotId], FRIENDSHIP_EVENT_LEARN_TMHM); if (gSpecialVar_ItemId <= ITEM_TM50) RemoveBagItem(gSpecialVar_ItemId, 1); SetMainCallback2(gPartyMenu.exitCallback); @@ -4336,7 +4336,7 @@ static void sub_8124EFC(void) RemoveMonPPBonus(mon, moveIdx); SetMonMoveSlot(mon, ItemIdToBattleMoveId(gSpecialVar_ItemId), moveIdx); - AdjustFriendship(mon, 4); + AdjustFriendship(mon, FRIENDSHIP_EVENT_LEARN_TMHM); ItemUse_SetQuestLogEvent(QL_EVENT_USED_ITEM, mon, gSpecialVar_ItemId, move); if (gSpecialVar_ItemId <= ITEM_TM50) RemoveBagItem(gSpecialVar_ItemId, 1); @@ -4837,7 +4837,7 @@ static void Task_LearnedMove(u8 taskId) if (move[1] == 0) { - AdjustFriendship(mon, 4); + AdjustFriendship(mon, FRIENDSHIP_EVENT_LEARN_TMHM); if (item < ITEM_HM01_CUT) RemoveBagItem(item, 1); } diff --git a/src/pokemon.c b/src/pokemon.c index f8c03ea02..f6511cbdc 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -1594,16 +1594,16 @@ static const u8 sStatsToRaise[] = static const s8 sFriendshipEventDeltas[][3] = { - { 5, 3, 2 }, - { 5, 3, 2 }, - { 1, 1, 0 }, - { 3, 2, 1 }, - { 1, 1, 0 }, - { 1, 1, 1 }, - { 3, 3, 3 }, - {-1, -1, -1 }, - {-5, -5, -10 }, - {-5, -5, -10 }, + [FRIENDSHIP_EVENT_GROW_LEVEL] = { 5, 3, 2 }, + [FRIENDSHIP_EVENT_VITAMIN] = { 5, 3, 2 }, + [FRIENDSHIP_EVENT_BATTLE_ITEM] = { 1, 1, 0 }, + [FRIENDSHIP_EVENT_LEAGUE_BATTLE] = { 3, 2, 1 }, + [FRIENDSHIP_EVENT_LEARN_TMHM] = { 1, 1, 0 }, + [FRIENDSHIP_EVENT_WALKING] = { 1, 1, 1 }, + [FRIENDSHIP_EVENT_MASSAGE] = { 3, 3, 3 }, + [FRIENDSHIP_EVENT_FAINT_SMALL] = {-1, -1, -1 }, + [FRIENDSHIP_EVENT_FAINT_OUTSIDE_BATTLE] = {-5, -5, -10 }, + [FRIENDSHIP_EVENT_FAINT_LARGE] = {-5, -5, -10 }, }; static const u16 sHMMoves[] = @@ -1622,7 +1622,7 @@ static const u16 sDeoxysBaseStats[] = 180, // Sp.Attack 20, // Sp.Defense }; -#elif defined LEAFGREEN +#elif defined(LEAFGREEN) static const u16 sDeoxysBaseStats[] = { 50, // Hp @@ -4410,7 +4410,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov static bool8 HealStatusConditions(struct Pokemon *mon, u32 unused, u32 healMask, u8 battleId) { - u32 status = GetMonData(mon, MON_DATA_STATUS, 0); + u32 status = GetMonData(mon, MON_DATA_STATUS, NULL); if (status & healMask) { @@ -4874,7 +4874,7 @@ const u8 *Battle_PrintStatBoosterEffectMessage(u16 itemId) u8 GetNature(struct Pokemon *mon) { - return GetMonData(mon, MON_DATA_PERSONALITY, 0) % 25; + return GetMonData(mon, MON_DATA_PERSONALITY, NULL) % 25; } static u8 GetNatureFromPersonality(u32 personality) @@ -4886,12 +4886,12 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) { int i; u16 targetSpecies = 0; - u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); - u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); - u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); u8 level; u16 friendship; - u8 beauty = GetMonData(mon, MON_DATA_BEAUTY, 0); + u8 beauty = GetMonData(mon, MON_DATA_BEAUTY, NULL); u16 upperPersonality = personality >> 16; u8 holdEffect; @@ -4906,8 +4906,8 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) switch (type) { case EVO_MODE_NORMAL: - level = GetMonData(mon, MON_DATA_LEVEL, 0); - friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); + level = GetMonData(mon, MON_DATA_LEVEL, NULL); + friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, NULL); for (i = 0; i < 5; i++) { @@ -4938,17 +4938,17 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) break; case EVO_LEVEL_ATK_GT_DEF: if (gEvolutionTable[species][i].param <= level) - if (GetMonData(mon, MON_DATA_ATK, 0) > GetMonData(mon, MON_DATA_DEF, 0)) + if (GetMonData(mon, MON_DATA_ATK, NULL) > GetMonData(mon, MON_DATA_DEF, NULL)) targetSpecies = gEvolutionTable[species][i].targetSpecies; break; case EVO_LEVEL_ATK_EQ_DEF: if (gEvolutionTable[species][i].param <= level) - if (GetMonData(mon, MON_DATA_ATK, 0) == GetMonData(mon, MON_DATA_DEF, 0)) + if (GetMonData(mon, MON_DATA_ATK, NULL) == GetMonData(mon, MON_DATA_DEF, NULL)) targetSpecies = gEvolutionTable[species][i].targetSpecies; break; case EVO_LEVEL_ATK_LT_DEF: if (gEvolutionTable[species][i].param <= level) - if (GetMonData(mon, MON_DATA_ATK, 0) < GetMonData(mon, MON_DATA_DEF, 0)) + if (GetMonData(mon, MON_DATA_ATK, NULL) < GetMonData(mon, MON_DATA_DEF, NULL)) targetSpecies = gEvolutionTable[species][i].targetSpecies; break; case EVO_LEVEL_SILCOON: @@ -5237,15 +5237,10 @@ static u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) return n; } -// TODO: Move these to constants/trainers.h -#define TRAINER_CLASS_ELITE_FOUR 0x54 -#define TRAINER_CLASS_LEADER 0x57 -#define TRAINER_CLASS_CHAMPION 0x5A - void AdjustFriendship(struct Pokemon *mon, u8 event) { - u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); - u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES2, NULL); + u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL); u8 holdEffect; if (heldItem == ITEM_ENIGMA_BERRY) @@ -5262,40 +5257,56 @@ void AdjustFriendship(struct Pokemon *mon, u8 event) if (species && species != SPECIES_EGG) { + s8 delta; + // Friendship level refers to the column in sFriendshipEventDeltas. + // 0-99: Level 0 (maximum increase, typically) + // 100-199: Level 1 + // 200-255: Level 2 u8 friendshipLevel = 0; - s16 friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); - if (friendship > 99) + s16 friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, NULL); + if (friendship >= 100) friendshipLevel++; - if (friendship > 199) + if (friendship >= 200) friendshipLevel++; - if ((event != FRIENDSHIP_EVENT_WALKING || !(Random() & 1)) - && (event != FRIENDSHIP_EVENT_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)))) + if (event == FRIENDSHIP_EVENT_WALKING) { - s8 delta = sFriendshipEventDeltas[event][friendshipLevel]; - if (delta > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) - delta = (150 * delta) / 100; - - friendship += delta; - if (delta > 0) - { - if (GetMonData(mon, MON_DATA_POKEBALL, 0) == ITEM_LUXURY_BALL) - friendship++; - if (GetMonData(mon, MON_DATA_MET_LOCATION, 0) == GetCurrentRegionMapSectionId()) - 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 == CLASS_LEADER_2 + || gTrainers[gTrainerBattleOpponent_A].trainerClass == CLASS_ELITE_FOUR_2 + || gTrainers[gTrainerBattleOpponent_A].trainerClass == CLASS_CHAMPION_2)) + return; + } - if (friendship < 0) - friendship = 0; - if (friendship > 255) - friendship = 255; + delta = sFriendshipEventDeltas[event][friendshipLevel]; + if (delta > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) + // 50% increase, rounding down + delta = (150 * delta) / 100; - SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); + friendship += delta; + if (delta > 0) + { + if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == ITEM_LUXURY_BALL) + friendship++; + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == GetCurrentRegionMapSectionId()) + friendship++; } + + // Clamp to u8 + if (friendship < 0) + friendship = 0; + if (friendship > 255) + friendship = 255; + + SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); } } @@ -5310,7 +5321,7 @@ void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies) for (i = 0; i < NUM_STATS; i++) { - evs[i] = GetMonData(mon, MON_DATA_HP_EV + i, 0); + evs[i] = GetMonData(mon, MON_DATA_HP_EV + i, NULL); totalEVs += evs[i]; } @@ -5351,7 +5362,7 @@ void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies) break; } - heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); + heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL); if (heldItem == ITEM_ENIGMA_BERRY) { @@ -5390,7 +5401,7 @@ u16 GetMonEVCount(struct Pokemon *mon) u16 count = 0; for (i = 0; i < NUM_STATS; i++) - count += GetMonData(mon, MON_DATA_HP_EV + i, 0); + count += GetMonData(mon, MON_DATA_HP_EV + i, NULL); return count; } @@ -5417,7 +5428,7 @@ u8 CheckPartyPokerus(struct Pokemon *party, u8 selection) { do { - if ((selection & 1) && (GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0) & 0xF)) + if ((selection & 1) && (GetMonData(&party[partyIndex], MON_DATA_POKERUS, NULL) & 0xF)) retVal |= curBit; partyIndex++; curBit <<= 1; @@ -5425,7 +5436,7 @@ u8 CheckPartyPokerus(struct Pokemon *party, u8 selection) } while (selection); } - else if (GetMonData(&party[0], MON_DATA_POKERUS, 0) & 0xF) + else if (GetMonData(&party[0], MON_DATA_POKERUS, NULL) & 0xF) { retVal = 1; } @@ -5445,7 +5456,7 @@ u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection) { do { - if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0)) + if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS, NULL)) retVal |= curBit; partyIndex++; curBit <<= 1; @@ -5453,7 +5464,7 @@ u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection) } while (selection); } - else if (GetMonData(&party[0], MON_DATA_POKERUS, 0)) + else if (GetMonData(&party[0], MON_DATA_POKERUS, NULL)) { retVal = 1; } @@ -5511,7 +5522,7 @@ bool8 TryIncrementMonLevel(struct Pokemon *mon) u32 CanMonLearnTMHM(struct Pokemon *mon, u8 tm) { - u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES2, NULL); if (species == SPECIES_EGG) { return 0; @@ -5532,12 +5543,12 @@ u8 GetMoveRelearnerMoves(struct Pokemon *mon, u16 *moves) { u16 learnedMoves[4]; u8 numMoves = 0; - u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); - u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 level = GetMonData(mon, MON_DATA_LEVEL, NULL); int i, j, k; for (i = 0; i < 4; i++) - learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); + learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, NULL); for (i = 0; i < 20; i++) { @@ -5583,15 +5594,15 @@ u8 GetNumberOfRelearnableMoves(struct Pokemon *mon) u16 learnedMoves[4]; u16 moves[20]; u8 numMoves = 0; - u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); - u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES2, NULL); + u8 level = GetMonData(mon, MON_DATA_LEVEL, NULL); int i, j, k; if (species == SPECIES_EGG) return 0; for (i = 0; i < 4; i++) - learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); + learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, NULL); for (i = 0; i < 20; i++) { @@ -5685,9 +5696,9 @@ void PlayMapChosenOrBattleBGM(u16 songId) const u32 *GetMonFrontSpritePal(struct Pokemon *mon) { - u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); - u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); - u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES2, NULL); + u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); return GetMonSpritePalFromSpeciesAndPersonality(species, otId, personality); } @@ -5707,9 +5718,9 @@ const u32 *GetMonSpritePalFromSpeciesAndPersonality(u16 species, u32 otId, u32 p const struct CompressedSpritePalette *GetMonSpritePalStruct(struct Pokemon *mon) { - u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); - u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); - u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + u16 species = GetMonData(mon, MON_DATA_SPECIES2, NULL); + u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); return GetMonSpritePalStructFromOtIdPersonality(species, otId, personality); } @@ -5757,7 +5768,7 @@ bool8 IsTradedMon(struct Pokemon *mon) u8 otName[PLAYER_NAME_LENGTH]; u32 otId; GetMonData(mon, MON_DATA_OT_NAME, otName); - otId = GetMonData(mon, MON_DATA_OT_ID, 0); + otId = GetMonData(mon, MON_DATA_OT_ID, NULL); return IsOtherTrainer(otId, otName); } @@ -5824,7 +5835,7 @@ void SetWildMonHeldItem(void) if (!(gBattleTypeFlags & (BATTLE_TYPE_POKEDUDE | BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_TRAINER))) { u16 rnd = Random() % 100; - u16 species = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, 0); + u16 species = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL); if (gBaseStats[species].item1 == gBaseStats[species].item2) { SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item1); @@ -5843,8 +5854,8 @@ void SetWildMonHeldItem(void) bool8 IsMonShiny(struct Pokemon *mon) { - u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); - u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + u32 otId = GetMonData(mon, MON_DATA_OT_ID, NULL); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, NULL); return IsShinyOtIdPersonality(otId, personality); } |