From 4a102dca8e764bb28569356e6539c40988d61498 Mon Sep 17 00:00:00 2001 From: psf <77138753+pkmnsnfrn@users.noreply.github.com> Date: Thu, 4 Apr 2024 01:08:34 -0400 Subject: [PATCH] Add explanation of STATIC_ASSERTS in pokemon.c (#4294) --- src/pokemon.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pokemon.c b/src/pokemon.c index 4f21b3ea14..5f2dfb3019 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -743,6 +743,20 @@ static const u32 sCompressedStatuses[] = // - The maximum PP. // - The maximum HP. // - The maximum form countdown. + +// The following STATIC_ASSERT will prevent developers from compiling the game if the value of the constant on the left does not fit within the number of bits defined in PokemonSubstruct0 (currently located in include/pokemon.h). + +// To successfully compile, developers will need to do one of the following: +// 1) Decrease the size of the constant. +// 2) Increase the number of bits both on the struct AND in the corresponding assert. This will likely break user's saves unless there is free space after the member that is being adjsted. +// 3) Repurpose unused IDs. + +// EXAMPLES +// If a developer has added enough new items so that ITEMS_COUNT now equals 1200, they could... +// 1) remove new items until ITEMS_COUNT is 1023, the max value that will fit in 10 bits. +// 2) change heldItem:10 to heldItem:11 AND change the below assert for ITEMS_COUNT to check for (1 << 11). +// 3) repurpose IDs from other items that aren't being used, like ITEM_GOLD_TEETH or ITEM_SS_TICKET until ITEMS_COUNT equals 1023, the max value that will fit in 10 bits. + STATIC_ASSERT(NUM_SPECIES < (1 << 11), PokemonSubstruct0_species_TooSmall); STATIC_ASSERT(NUMBER_OF_MON_TYPES + 1 <= (1 << 5), PokemonSubstruct0_teraType_TooSmall); STATIC_ASSERT(ITEMS_COUNT < (1 << 10), PokemonSubstruct0_heldItem_TooSmall);