From c1dffc694e29e2a104a5b97312b367a8514aa7f8 Mon Sep 17 00:00:00 2001 From: kittenchilly Date: Fri, 27 Sep 2024 16:40:49 -0500 Subject: [PATCH] Merge level_caps and ev_caps into one caps file (#5429) * Merge level_caps and ev_caps into one caps file * Update caps.h --- include/{level_caps.h => caps.h} | 11 +++++-- include/config/{level_caps.h => caps.h} | 22 ++++++++++--- include/config/ev_caps.h | 16 ---------- include/constants/global.h | 3 +- include/ev_caps.h | 10 ------ src/battle_controller_player.c | 2 +- src/battle_interface.c | 2 +- src/battle_script_commands.c | 2 +- src/{level_caps.c => caps.c} | 38 ++++++++++++++++++++++- src/daycare.c | 2 +- src/ev_caps.c | 41 ------------------------- src/party_menu.c | 2 +- src/pokemon.c | 11 +++---- 13 files changed, 73 insertions(+), 89 deletions(-) rename include/{level_caps.h => caps.h} (68%) rename include/config/{level_caps.h => caps.h} (55%) delete mode 100644 include/config/ev_caps.h delete mode 100644 include/ev_caps.h rename src/{level_caps.c => caps.c} (69%) delete mode 100644 src/ev_caps.c diff --git a/include/level_caps.h b/include/caps.h similarity index 68% rename from include/level_caps.h rename to include/caps.h index c455408079..f6dd61b632 100644 --- a/include/level_caps.h +++ b/include/caps.h @@ -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 */ diff --git a/include/config/level_caps.h b/include/config/caps.h similarity index 55% rename from include/config/level_caps.h rename to include/config/caps.h index e8d7b8818e..2debe442cf 100644 --- a/include/config/level_caps.h +++ b/include/config/caps.h @@ -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 */ diff --git a/include/config/ev_caps.h b/include/config/ev_caps.h deleted file mode 100644 index 0513ff086e..0000000000 --- a/include/config/ev_caps.h +++ /dev/null @@ -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*/ diff --git a/include/constants/global.h b/include/constants/global.h index a4623c9d8b..89508e374d 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -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. diff --git a/include/ev_caps.h b/include/ev_caps.h deleted file mode 100644 index 2b2dd0b02b..0000000000 --- a/include/ev_caps.h +++ /dev/null @@ -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 */ diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index afff143266..cc5454ad54 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -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" diff --git a/src/battle_interface.c b/src/battle_interface.c index 4c17322b53..5c514a0d80 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -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 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 283f42a23b..8bbe5ba89f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -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" diff --git a/src/level_caps.c b/src/caps.c similarity index 69% rename from src/level_caps.c rename to src/caps.c index 61b4c8dc8f..9c30e55527 100644 --- a/src/level_caps.c +++ b/src/caps.c @@ -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; +} diff --git a/src/daycare.c b/src/daycare.c index e13f993c3f..7a31f15b27 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -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" diff --git a/src/ev_caps.c b/src/ev_caps.c deleted file mode 100644 index 8eb3531ca4..0000000000 --- a/src/ev_caps.c +++ /dev/null @@ -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; -} diff --git a/src/party_menu.c b/src/party_menu.c index 5def34b3eb..ecee16d0af 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -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" diff --git a/src/pokemon.c b/src/pokemon.c index faa1a65aef..43199c8538 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -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