forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Feature: Level Caps (rh-hideout#3632)
* New Feature: Level Caps * B_LEVEL_CAP_EXP_UP and fixes * 1 exp fix for hard level caps * remove 1 exp hack * Reviews applied * fix u8/u16 --------- Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
- Loading branch information
1 parent
98a5ce0
commit 2d55f68
Showing
8 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef GUARD_LEVEL_CAP_H | ||
#define GUARD_LEVEL_CAP_H | ||
|
||
// experience (soft-)caps | ||
|
||
#define EXP_CAP_NONE 0 // Regular behavior, no level caps are applied | ||
#define EXP_CAP_HARD 1 // Pokémon with a level >= the level cap cannot gain any experience | ||
#define EXP_CAP_SOFT 2 // Pokémon with a level >= the level cap will gain reduced experience | ||
|
||
#define LEVEL_CAP_NONE 0 // No level cap, only applicable if B_EXP_CAP_TYPE is EXP_CAP_NONE | ||
#define LEVEL_CAP_FLAG_LIST 1 // Level cap is chosen according to the first unset flag in `sLevelCapFlagMap` | ||
#define LEVEL_CAP_VARIABLE 2 // Level cap is chosen according to the contents of the event variable specified by B_LEVEL_CAP_VARIABLE | ||
|
||
#define B_EXP_CAP_TYPE EXP_CAP_NONE // [EXP_CAP_NONE, EXP_CAP_HARD, EXP_CAP_SOFT] choose the type of level cap to apply | ||
#define B_LEVEL_CAP_TYPE LEVEL_CAP_NONE // [LEVEL_CAP_NONE, LEVEL_CAP_FLAG_LIST, LEVEL_CAP_VARIABLE] choose the method to derive the level cap | ||
#define B_LEVEL_CAP_VARIABLE 0 // event variable used to derive level cap if B_LEVEL_CAP_TYPE is set to LEVEL_CAP_VARIABLE | ||
|
||
#define B_RARE_CANDY_CAP FALSE // If set to true, Rare Candies can't be used to go over the level cap | ||
#define B_LEVEL_CAP_EXP_UP FALSE // If set to true, mons under level cap will receive more experience | ||
|
||
#if B_EXP_CAP_TYPE != EXP_CAP_NONE && B_EXP_CAP_TYPE != EXP_CAP_HARD && B_EXP_CAP_TYPE != EXP_CAP_SOFT | ||
#error "Invalid choice for B_EXP_CAP_TYPE, must be of [EXP_CAP_NONE, EXP_CAP_HARD, EXP_CAP_SOFT]" | ||
#endif | ||
|
||
#if B_EXP_CAP_TYPE == EXP_CAP_HARD || B_EXP_CAP_TYPE == EXP_CAP_SOFT | ||
#if B_LEVEL_CAP_TYPE != LEVEL_CAP_FLAG_LIST && B_LEVEL_CAP_TYPE != LEVEL_CAP_VARIABLE | ||
#error "Invalid choice for B_LEVEL_CAP_TYPE, must be of [LEVEL_CAP_FLAG_LIST, LEVEL_CAP_VARIABLE]" | ||
#endif | ||
#if B_LEVEL_CAP_TYPE == LEVEL_CAP_VARIABLE && B_LEVEL_CAP_VARIABLE == 0 | ||
#error "B_LEVEL_CAP_TYPE set to LEVEL_CAP_VARIABLE, but no variable chosen for B_LEVEL_CAP_VARIABLE, set B_LEVEL_CAP_VARIABLE to a valid event variable" | ||
#endif | ||
#endif | ||
|
||
u32 GetCurrentLevelCap(void); | ||
u32 GetSoftLevelCapExpValue(u32 level, u32 expValue); | ||
|
||
#endif /* GUARD_LEVEL_CAP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "global.h" | ||
#include "battle.h" | ||
#include "event_data.h" | ||
#include "level_caps.h" | ||
#include "pokemon.h" | ||
|
||
|
||
u32 GetCurrentLevelCap(void) | ||
{ | ||
static const u32 sLevelCapFlagMap[][2] = | ||
{ | ||
{FLAG_BADGE01_GET, 15}, | ||
{FLAG_BADGE02_GET, 19}, | ||
{FLAG_BADGE03_GET, 24}, | ||
{FLAG_BADGE04_GET, 29}, | ||
{FLAG_BADGE05_GET, 31}, | ||
{FLAG_BADGE06_GET, 33}, | ||
{FLAG_BADGE07_GET, 42}, | ||
{FLAG_BADGE08_GET, 46}, | ||
{FLAG_IS_CHAMPION, 58}, | ||
}; | ||
|
||
u32 i; | ||
|
||
if (B_LEVEL_CAP_TYPE == LEVEL_CAP_FLAG_LIST) | ||
{ | ||
for (i = 0; i < ARRAY_COUNT(sLevelCapFlagMap); i++) | ||
{ | ||
if (!FlagGet(sLevelCapFlagMap[i][0])) | ||
return sLevelCapFlagMap[i][1]; | ||
} | ||
} | ||
else if (B_LEVEL_CAP_TYPE == LEVEL_CAP_VARIABLE) | ||
{ | ||
return VarGet(B_LEVEL_CAP_VARIABLE); | ||
} | ||
|
||
return MAX_LEVEL; | ||
} | ||
|
||
u32 GetSoftLevelCapExpValue(u32 level, u32 expValue) | ||
{ | ||
static const u32 sExpScalingDown[5] = { 4, 8, 16, 32, 64 }; | ||
static const u32 sExpScalingUp[5] = { 16, 8, 4, 2, 1 }; | ||
|
||
u32 levelDifference; | ||
u32 currentLevelCap = GetCurrentLevelCap(); | ||
|
||
if (B_EXP_CAP_TYPE == EXP_CAP_NONE) | ||
return expValue; | ||
|
||
if (B_LEVEL_CAP_EXP_UP && level < currentLevelCap) | ||
{ | ||
levelDifference = currentLevelCap - level; | ||
if (levelDifference > ARRAY_COUNT(sExpScalingDown)) | ||
return expValue + (expValue / sExpScalingUp[ARRAY_COUNT(sExpScalingDown) - 1]); | ||
else | ||
return expValue + (expValue / sExpScalingUp[levelDifference]); | ||
} | ||
else if (B_EXP_CAP_TYPE == EXP_CAP_SOFT && level >= currentLevelCap) | ||
{ | ||
levelDifference = level - currentLevelCap; | ||
if (levelDifference > ARRAY_COUNT(sExpScalingDown)) | ||
return expValue / sExpScalingDown[ARRAY_COUNT(sExpScalingDown) - 1]; | ||
else | ||
return expValue / sExpScalingDown[levelDifference]; | ||
} | ||
else | ||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters