From efdaa2564087cf69286c43092960f5dea2a460ae Mon Sep 17 00:00:00 2001 From: MandL27 Date: Wed, 21 Oct 2020 16:19:07 -0400 Subject: [PATCH] Add B_SCALED_EXP and B_SPLIT_EXP --- include/constants/battle_config.h | 4 +- src/battle_script_commands.c | 266 ++++++++++++++++++++++++++++-- 2 files changed, 254 insertions(+), 16 deletions(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index dd2fd4186e..dd0bb79a2f 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -62,9 +62,11 @@ #define B_CRIT_MULTIPLIER GEN_6 // In Gen6+, critical hits multiply damage by 1.5 instead of 2. #define B_EXP_CATCH GEN_6 // In Gen6+, Pokémon get experience from catching. #define B_TRAINER_EXP_MULTIPLIER GEN_6 // In Gen7+, trainer battles no longer give a 1.5 multiplier to exp gain. +#define B_SPLIT_EXP GEN_5 // In Gen6+, all participating mon get full experience. +#define B_SCALED_EXP GEN_6 // In Gen5 and Gen7+, experience is weighted by level difference. #define B_BURN_DAMAGE GEN_6 // In Gen7+, burn damage is 1/16th of max HP instead of 1/8th. #define B_PARALYSIS_SPEED GEN_6 // In Gen7+, speed is decreased by 50% instead of 75%. -#define B_TERRAIN_TYPE_BOOST GEN_6 // In Gen8+, speed is boosted by 30% instead of 50%. +#define B_TERRAIN_TYPE_BOOST GEN_6 // In Gen8+, damage is boosted by 30% instead of 50%. #define B_BINDING_DAMAGE GEN_6 // In Gen6+, binding damage is 1/8 of max HP instead of 1/16. (With Binding Band, 1/6 and 1/8 respectively.) #define B_CONFUSION_SELF_DMG_CHANCE GEN_6 // In Gen7+, confusion has a 33.3% of self-damage, instead of 50%. #define B_MULTI_HIT_CHANCE GEN_6 // In Gen5+, multi-hit moves have different %. See Cmd_setmultihitcounter for values. diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 28f38b9e68..54cf48317e 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -58,10 +58,226 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const u8* const gBattleScriptsForMoveEffects[]; -// this file's functions +// courtesy of doesnt +static const s32 sExperienceScalingFactors[] = +{ + 0, + 0, + 1, + 3, + 8, + 13, + 22, + 32, + 45, + 60, + 79, + 100, + 124, + 152, + 183, + 217, + 256, + 297, + 343, + 393, + 447, + 505, + 567, + 634, + 705, + 781, + 861, + 946, + 1037, + 1132, + 1232, + 1337, + 1448, + 1563, + 1685, + 1811, + 1944, + 2081, + 2225, + 2374, + 2529, + 2690, + 2858, + 3031, + 3210, + 3396, + 3587, + 3786, + 3990, + 4201, + 4419, + 4643, + 4874, + 5112, + 5357, + 5608, + 5866, + 6132, + 6404, + 6684, + 6971, + 7265, + 7566, + 7875, + 8192, + 8515, + 8847, + 9186, + 9532, + 9886, + 10249, + 10619, + 10996, + 11382, + 11776, + 12178, + 12588, + 13006, + 13433, + 13867, + 14310, + 14762, + 15222, + 15690, + 16167, + 16652, + 17146, + 17649, + 18161, + 18681, + 19210, + 19748, + 20295, + 20851, + 21417, + 21991, + 22574, + 23166, + 23768, + 24379, + 25000, + 25629, + 26268, + 26917, + 27575, + 28243, + 28920, + 29607, + 30303, + 31010, + 31726, + 32452, + 33188, + 33934, + 34689, + 35455, + 36231, + 37017, + 37813, + 38619, + 39436, + 40262, + 41099, + 41947, + 42804, + 43673, + 44551, + 45441, + 46340, + 47251, + 48172, + 49104, + 50046, + 50999, + 51963, + 52938, + 53924, + 54921, + 55929, + 56947, + 57977, + 59018, + 60070, + 61133, + 62208, + 63293, + 64390, + 65498, + 66618, + 67749, + 68891, + 70045, + 71211, + 72388, + 73576, + 74777, + 75989, + 77212, + 78448, + 79695, + 80954, + 82225, + 83507, + 84802, + 86109, + 87427, + 88758, + 90101, + 91456, + 92823, + 94202, + 95593, + 96997, + 98413, + 99841, + 101282, + 102735, + 104201, + 105679, + 107169, + 108672, + 110188, + 111716, + 113257, + 114811, + 116377, + 117956, + 119548, + 121153, + 122770, + 124401, + 126044, + 127700, + 129369, + 131052, + 132747, + 134456, + 136177, + 137912, + 139660, + 141421, + 143195, + 144983, + 146784, + 148598, + 150426, + 152267, + 154122, + 155990, + 157872, + 159767, +}; + #define STAT_CHANGE_WORKED 0 #define STAT_CHANGE_DIDNT_WORK 1 +// this file's functions static bool8 IsTwoTurnsMove(u16 move); static void TrySetDestinyBondToHappen(void); static u8 AttacksThisTurn(u8 battlerId, u16 move); // Note: returns 1 if it's a charging turn, otherwise 2. @@ -3434,25 +3650,37 @@ static void Cmd_getexp(void) if (holdEffect == HOLD_EFFECT_EXP_SHARE) viaExpShare++; } + if (B_SCALED_EXP == GEN_5) // I'm not sure if gens 7+ should use /5, but it felt too high in testing + calculatedExp = gBaseStats[gBattleMons[gBattlerFainted].species].expYield * gBattleMons[gBattlerFainted].level / 5; + else + calculatedExp = gBaseStats[gBattleMons[gBattlerFainted].species].expYield * gBattleMons[gBattlerFainted].level / 7; - calculatedExp = gBaseStats[gBattleMons[gBattlerFainted].species].expYield * gBattleMons[gBattlerFainted].level / 7; - - if (viaExpShare) // at least one mon is getting exp via exp share + if (B_SPLIT_EXP < GEN_6) { - *exp = calculatedExp / 2 / viaSentIn; - if (*exp == 0) - *exp = 1; + if (viaExpShare) // at least one mon is getting exp via exp share + { + *exp = calculatedExp / 2 / viaSentIn; + if (*exp == 0) + *exp = 1; - gExpShareExp = calculatedExp / 2 / viaExpShare; - if (gExpShareExp == 0) - gExpShareExp = 1; + gExpShareExp = calculatedExp / 2 / viaExpShare; + if (gExpShareExp == 0) + gExpShareExp = 1; + } + else + { + *exp = calculatedExp / viaSentIn; + if (*exp == 0) + *exp = 1; + gExpShareExp = 0; + } } else { - *exp = calculatedExp / viaSentIn; - if (*exp == 0) - *exp = 1; - gExpShareExp = 0; + *exp = calculatedExp; + gExpShareExp = calculatedExp / 2; + if (gExpShareExp == 0) + gExpShareExp = 1; } gBattleScripting.getexpState++; @@ -3503,12 +3731,20 @@ static void Cmd_getexp(void) else gBattleMoveDamage = 0; - if (holdEffect == HOLD_EFFECT_EXP_SHARE) + // only give exp share bonus in later gens if the mon wasn't sent out + if ((holdEffect == HOLD_EFFECT_EXP_SHARE) && ((gBattleMoveDamage == 0) || (B_SPLIT_EXP < GEN_6))) gBattleMoveDamage += gExpShareExp; if (holdEffect == HOLD_EFFECT_LUCKY_EGG) gBattleMoveDamage = (gBattleMoveDamage * 150) / 100; if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && B_TRAINER_EXP_MULTIPLIER <= GEN_7) gBattleMoveDamage = (gBattleMoveDamage * 150) / 100; + if ((B_SCALED_EXP >= GEN_5) && (B_SCALED_EXP != GEN_6)) + { + gBattleMoveDamage *= sExperienceScalingFactors[(gBattleMons[gBattlerFainted].level * 2) + 10]; + gBattleMoveDamage /= sExperienceScalingFactors[gBattleMons[gBattlerFainted].level + + GetMonData(&gPlayerParty[gBattleStruct->expGetterMonId], MON_DATA_LEVEL) + 10]; + gBattleMoveDamage++; + } if (IsTradedMon(&gPlayerParty[gBattleStruct->expGetterMonId])) {