Merge level_caps and ev_caps into one caps file (#5429)

* Merge level_caps and ev_caps into one caps file

* Update caps.h
This commit is contained in:
kittenchilly 2024-09-27 16:40:49 -05:00 committed by GitHub
parent ad0778722b
commit c1dffc694e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 73 additions and 89 deletions

View file

@ -1,5 +1,5 @@
#ifndef GUARD_LEVEL_CAP_H
#define GUARD_LEVEL_CAP_H
#ifndef GUARD_CAPS_H
#define GUARD_CAPS_H
#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]"
@ -14,7 +14,12 @@
#endif
#endif
#if B_EV_CAP_TYPE != EV_CAP_NONE && B_EV_CAP_TYPE != EV_CAP_FLAG_LIST && B_EV_CAP_TYPE != EV_CAP_VARIABLE && B_EV_CAP_TYPE != EV_CAP_NO_GAIN
#error "Invalid choice for B_EV_CAP_TYPE, must be one of [EV_CAP_NONE, EV_CAP_FLAG_LIST, EV_CAP_VARIABLE, EV_CAP_NO_GAIN]"
#endif
u32 GetCurrentLevelCap(void);
u32 GetSoftLevelCapExpValue(u32 level, u32 expValue);
u32 GetCurrentEVCap(void);
#endif /* GUARD_LEVEL_CAP_H */
#endif /* GUARD_CAPS_H */

View file

@ -1,7 +1,7 @@
#ifndef GUARD_CONFIG_LEVEL_CAP_H
#define GUARD_CONFIG_LEVEL_CAP_H
#ifndef GUARD_CONFIG_CAPS_H
#define GUARD_CONFIG_CAPS_H
// Constants
// Level Cap Constants
#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
@ -10,7 +10,7 @@
#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
// Configs
// Level Cap Configs
#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
@ -18,4 +18,16 @@
#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
#endif /* GUARD_CONFIG_LEVEL_CAP_H */
// EV Cap Constants
#define EV_CAP_NONE 0 // Regular behavior, no EV caps are applied
#define EV_CAP_FLAG_LIST 1 // EV cap is chosen according to the first unset flag in `sEVCapFlagMap`
#define EV_CAP_VARIABLE 2 // EV cap is chosen according to the contents of the event variable specified by B_EV_CAP_VARIABLE
#define EV_CAP_NO_GAIN 3 // No EVs can be gained
// EV Cap Configs
#define B_EV_CAP_TYPE EV_CAP_NONE // [EV_CAP_NONE, EV_CAP_FLAG_LIST, EV_CAP_VARIABLE, EV_CAP_NO_GAIN] choose the type of EV cap to apply#define B_EV_CAP_VARIABLE 12 // event variable used to derive EV cap if B_EV_CAP_TYPE is set to EV_CAP_VARIABLE
#define B_EV_CAP_VARIABLE 8 // event variable used to derive EV cap if B_EV_CAP_TYPE is set to EV_CAP_VARIABLE
#define B_EV_ITEMS_CAP FALSE // If set to true, EV-boosting items can't be used to go over the EV cap
#endif /* GUARD_CONFIG_CAPS_H */

View file

@ -1,16 +0,0 @@
#ifndef GUARD_CONFIG_EV_CAP_H
#define GUARD_CONFIG_EV_CAP_H
// Constants for EV Cap Types
#define EV_CAP_NONE 0 // Regular behavior, no EV caps are applied
#define EV_CAP_FLAG_LIST 1 // EV cap is chosen according to the first unset flag in `sEVCapFlagMap`
#define EV_CAP_VARIABLE 2 // EV cap is chosen according to the contents of the event variable specified by B_EV_CAP_VARIABLE
#define EV_CAP_NO_GAIN 3 // No EVs can be gained
// Configs for EV Cap
#define B_EV_CAP_TYPE EV_CAP_NONE // [EV_CAP_NONE, EV_CAP_FLAG_LIST, EV_CAP_VARIABLE, EV_CAP_NO_GAIN] choose the type of EV cap to apply#define B_EV_CAP_VARIABLE 12 // event variable used to derive EV cap if B_EV_CAP_TYPE is set to EV_CAP_VARIABLE
#define B_EV_CAP_VARIABLE 8 // event variable used to derive EV cap if B_EV_CAP_TYPE is set to EV_CAP_VARIABLE
#define B_EV_ITEMS_CAP FALSE // If set to true, EV-boosting items can't be used to go over the EV cap
#endif /*GUARD_CONFIG_EV_CAP_H*/

View file

@ -5,10 +5,9 @@
#include "config/battle.h"
#include "config/debug.h"
#include "config/item.h"
#include "config/level_caps.h"
#include "config/caps.h"
#include "config/pokemon.h"
#include "config/overworld.h"
#include "config/ev_caps.h"
// Invalid Versions show as "----------" in Gen 4 and Gen 5's summary screen.
// In Gens 6 and 7, invalid versions instead show "a distant land" in the summary screen.

View file

@ -1,10 +0,0 @@
#ifndef GUARD_EV_CAP_H
#define GUARD_EV_CAP_H
#if B_EV_CAP_TYPE != EV_CAP_NONE && B_EV_CAP_TYPE != EV_CAP_FLAG_LIST && B_EV_CAP_TYPE != EV_CAP_VARIABLE && B_EV_CAP_TYPE != EV_CAP_NO_GAIN
#error "Invalid choice for B_EV_CAP_TYPE, must be one of [EV_CAP_NONE, EV_CAP_FLAG_LIST, EV_CAP_VARIABLE, EV_CAP_NO_GAIN]"
#endif
u32 GetCurrentEVCap(void);
#endif /* GUARD_EV_CAP_H */

View file

@ -41,7 +41,7 @@
#include "constants/songs.h"
#include "constants/trainers.h"
#include "constants/rgb.h"
#include "level_caps.h"
#include "caps.h"
#include "menu.h"
#include "pokemon_summary_screen.h"
#include "type_icons.h"

View file

@ -33,7 +33,7 @@
#include "constants/rgb.h"
#include "constants/songs.h"
#include "constants/items.h"
#include "level_caps.h"
#include "caps.h"
enum
{ // Corresponds to gHealthboxElementsGfxTable (and the tables after it) in graphics.c

View file

@ -27,7 +27,7 @@
#include "bg.h"
#include "string_util.h"
#include "pokemon_icon.h"
#include "level_caps.h"
#include "caps.h"
#include "m4a.h"
#include "mail.h"
#include "event_data.h"

View file

@ -1,7 +1,7 @@
#include "global.h"
#include "battle.h"
#include "event_data.h"
#include "level_caps.h"
#include "caps.h"
#include "pokemon.h"
@ -81,3 +81,39 @@ u32 GetSoftLevelCapExpValue(u32 level, u32 expValue)
return expValue;
}
}
u32 GetCurrentEVCap(void)
{
static const u16 sEvCapFlagMap[][2] = {
// Define EV caps for each milestone
{FLAG_BADGE01_GET, 30},
{FLAG_BADGE02_GET, 90},
{FLAG_BADGE03_GET, 150},
{FLAG_BADGE04_GET, 210},
{FLAG_BADGE05_GET, 270},
{FLAG_BADGE06_GET, 330},
{FLAG_BADGE07_GET, 390},
{FLAG_BADGE08_GET, 450},
{FLAG_IS_CHAMPION, MAX_TOTAL_EVS},
};
if (B_EV_CAP_TYPE == EV_CAP_FLAG_LIST)
{
for (u32 evCap = 0; evCap < ARRAY_COUNT(sEvCapFlagMap); evCap++)
{
if (!FlagGet(sEvCapFlagMap[evCap][0]))
return sEvCapFlagMap[evCap][1];
}
}
else if (B_EV_CAP_TYPE == EV_CAP_VARIABLE)
{
return VarGet(B_EV_CAP_VARIABLE);
}
else if (B_EV_CAP_TYPE == EV_CAP_NO_GAIN)
{
return 0;
}
return MAX_TOTAL_EVS;
}

View file

@ -3,7 +3,7 @@
#include "battle.h"
#include "daycare.h"
#include "string_util.h"
#include "level_caps.h"
#include "caps.h"
#include "mail.h"
#include "pokemon_storage_system.h"
#include "event_data.h"

View file

@ -1,41 +0,0 @@
#include "global.h"
#include "battle.h"
#include "event_data.h"
#include "ev_caps.h"
#include "pokemon.h"
u32 GetCurrentEVCap(void)
{
static const u16 sEvCapFlagMap[][2] = {
// Define EV caps for each milestone
{FLAG_BADGE01_GET, 30},
{FLAG_BADGE02_GET, 90},
{FLAG_BADGE03_GET, 150},
{FLAG_BADGE04_GET, 210},
{FLAG_BADGE05_GET, 270},
{FLAG_BADGE06_GET, 330},
{FLAG_BADGE07_GET, 390},
{FLAG_BADGE08_GET, 450},
{FLAG_IS_CHAMPION, MAX_TOTAL_EVS},
};
if (B_EV_CAP_TYPE == EV_CAP_FLAG_LIST)
{
for (u32 evCap = 0; evCap < ARRAY_COUNT(sEvCapFlagMap); evCap++)
{
if (!FlagGet(sEvCapFlagMap[evCap][0]))
return sEvCapFlagMap[evCap][1];
}
}
else if (B_EV_CAP_TYPE == EV_CAP_VARIABLE)
{
return VarGet(B_EV_CAP_VARIABLE);
}
else if (B_EV_CAP_TYPE == EV_CAP_NO_GAIN)
{
return 0;
}
return MAX_TOTAL_EVS;
}

View file

@ -32,7 +32,7 @@
#include "item.h"
#include "item_menu.h"
#include "item_use.h"
#include "level_caps.h"
#include "caps.h"
#include "link.h"
#include "link_rfu.h"
#include "mail.h"

View file

@ -19,7 +19,7 @@
#include "field_weather.h"
#include "graphics.h"
#include "item.h"
#include "level_caps.h"
#include "caps.h"
#include "link.h"
#include "main.h"
#include "overworld.h"
@ -60,7 +60,6 @@
#include "constants/union_room.h"
#include "constants/weather.h"
#include "wild_encounter.h"
#include "ev_caps.h"
#define FRIENDSHIP_EVO_THRESHOLD ((P_FRIENDSHIP_EVO_THRESHOLD >= GEN_9) ? 160 : 220)
@ -3879,11 +3878,11 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
// Ensure the increase does not exceed the max EV per stat (252)
evCap = (itemEffect[10] & ITEM10_IS_VITAMIN) ? EV_ITEM_RAISE_LIMIT : MAX_PER_STAT_EVS;
// Check if the per-stat limit is reached
if (dataSigned >= evCap)
return TRUE; // Prevents item use if the per-stat cap is already reached
if (dataSigned + evChange > evCap)
temp2 = evCap - dataSigned;
else
@ -4068,11 +4067,11 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
// Ensure the increase does not exceed the max EV per stat (252)
evCap = (itemEffect[10] & ITEM10_IS_VITAMIN) ? EV_ITEM_RAISE_LIMIT : MAX_PER_STAT_EVS;
// Check if the per-stat limit is reached
if (dataSigned >= evCap)
return TRUE; // Prevents item use if the per-stat cap is already reached
if (dataSigned + evChange > evCap)
temp2 = evCap - dataSigned;
else