Untangled TMs and HMs from item ids (#7173)

This commit is contained in:
Nephrite
2025-07-04 18:07:53 +01:00
committed by GitHub
parent b3f52166df
commit e8abfbce49
21 changed files with 201 additions and 209 deletions

View File

@@ -1027,9 +1027,6 @@
#define MAIL_NONE 0xFF
#define ITEM_TO_MULCH(itemId)(((itemId) - ITEM_GROWTH_MULCH) + 1)
#define NUM_TECHNICAL_MACHINES 100
#define NUM_HIDDEN_MACHINES 8
#define MAX_BAG_ITEM_CAPACITY 999
#define MAX_PC_ITEM_CAPACITY 999
#define MAX_PYRAMID_BAG_ITEM_CAPACITY 99 // Values higher than 255 require free SaveBlock2 space.

View File

@@ -3,8 +3,44 @@
#include "constants/item.h"
#include "constants/items.h"
#include "constants/moves.h"
#include "constants/tms_hms.h"
/* Expands to:
* enum
* {
* ITEM_TM_FOCUS_PUNCH = ITEM_TM01,
* ...
* ITEM_HM_CUT = ITM_HM01,
* ...
* }; */
#define ENUM_TM(n, id) CAT(ITEM_TM_, id) = CAT(ITEM_TM, n),
#define ENUM_HM(n, id) CAT(ITEM_HM_, id) = CAT(ITEM_HM, n),
#define TO_TMHM_NUMS(a, ...) (__VA_ARGS__)
enum TMHMItemId
{
RECURSIVELY(R_ZIP(ENUM_TM, TO_TMHM_NUMS NUMBERS_256, (FOREACH_TM(APPEND_COMMA))))
RECURSIVELY(R_ZIP(ENUM_HM, TO_TMHM_NUMS NUMBERS_256, (FOREACH_HM(APPEND_COMMA))))
};
#undef ENUM_TM
#undef ENUM_HM
#undef TO_TMHM_NUMS
/* Each of these TM_HM enums corresponds an index in the list of TMs + HMs item ids in
* gTMHMItemMoveIds. The index for an item can be retrieved with GetItemTMHMIndex below.
*/
#define UNPACK_TM_HM_ENUM(_tmHm) CAT(ENUM_TM_HM_, _tmHm),
enum TMHMIndex
{
FOREACH_TMHM(UNPACK_TM_HM_ENUM)
NUM_ALL_MACHINES,
NUM_TECHNICAL_MACHINES = (0 FOREACH_TM(PLUS_ONE)),
NUM_HIDDEN_MACHINES = (0 FOREACH_HM(PLUS_ONE)),
};
#undef UNPACK_TM_HM_ENUM
typedef void (*ItemUseFunc)(u8);
struct Item
@@ -20,8 +56,8 @@ struct Item
u8 holdEffectParam;
u8 importance:2;
u8 notConsumed:1;
u8 padding:5;
enum Pocket pocket:8;
enum Pocket pocket:5;
u8 padding;
u8 type;
u8 battleUsage;
u8 flingPower;
@@ -29,14 +65,75 @@ struct Item
const u16 *iconPalette;
};
struct __attribute__((packed, aligned(2))) BagPocket
struct ALIGNED(2) BagPocket
{
struct ItemSlot *itemSlots;
u16 capacity;
};
struct TmHmIndexKey
{
enum TMHMItemId itemId:16;
u16 moveId;
};
extern const struct Item gItemsInfo[];
extern struct BagPocket gBagPockets[];
extern const struct TmHmIndexKey gTMHMItemMoveIds[];
#define UNPACK_ITEM_TO_TM_INDEX(_tm) case CAT(ITEM_TM_, _tm): return CAT(ENUM_TM_HM_, _tm) + 1;
#define UNPACK_ITEM_TO_HM_INDEX(_hm) case CAT(ITEM_HM_, _hm): return CAT(ENUM_TM_HM_, _hm) + 1;
#define UNPACK_ITEM_TO_TM_MOVE_ID(_tm) case CAT(ITEM_TM_, _tm): return CAT(MOVE_, _tm);
#define UNPACK_ITEM_TO_HM_MOVE_ID(_hm) case CAT(ITEM_HM_, _hm): return CAT(MOVE_, _hm);
static inline enum TMHMIndex GetItemTMHMIndex(u16 item)
{
switch (item)
{
/* Expands to:
* case ITEM_TM_FOCUS_PUNCH:
* return 1;
* case ITEM_TM_DRAGON_CLAW:
* return 2;
* etc */
FOREACH_TM(UNPACK_ITEM_TO_TM_INDEX)
FOREACH_HM(UNPACK_ITEM_TO_HM_INDEX)
default:
return 0;
}
}
static inline u16 GetItemTMHMMoveId(u16 item)
{
switch (item)
{
/* Expands to:
* case ITEM_TM_FOCUS_PUNCH:
* return MOVE_FOCUS_PUNCH;
* case ITEM_TM_DRAGON_CLAW:
* return MOVE_DRAGON_CLAW;
* etc */
FOREACH_TM(UNPACK_ITEM_TO_TM_MOVE_ID)
FOREACH_HM(UNPACK_ITEM_TO_HM_MOVE_ID)
default:
return MOVE_NONE;
}
}
#undef UNPACK_ITEM_TO_TM_INDEX
#undef UNPACK_ITEM_TO_HM_INDEX
#undef UNPACK_ITEM_TO_TM_MOVE_ID
#undef UNPACK_ITEM_TO_HM_MOVE_ID
static inline enum TMHMItemId GetTMHMItemId(enum TMHMIndex index)
{
return gTMHMItemMoveIds[index].itemId;
}
static inline u16 GetTMHMMoveId(enum TMHMIndex index)
{
return gTMHMItemMoveIds[index].moveId;
}
u16 GetBagItemId(enum Pocket pocketId, u32 pocketPos);
u16 GetBagItemQuantity(enum Pocket pocketId, u32 pocketPos);
@@ -85,25 +182,4 @@ u32 GetItemStatus1Mask(u16 itemId);
u32 GetItemStatus2Mask(u16 itemId);
u32 GetItemSellPrice(u32 itemId);
/* Expands to:
* enum
* {
* ITEM_TM_FOCUS_PUNCH,
* ...
* ITEM_HM_CUT,
* ...
* }; */
#define ENUM_TM(id) CAT(ITEM_TM_, id),
#define ENUM_HM(id) CAT(ITEM_HM_, id),
enum
{
ENUM_TM_START_ = ITEM_TM01 - 1,
FOREACH_TM(ENUM_TM)
ENUM_HM_START_ = ITEM_HM01 - 1,
FOREACH_HM(ENUM_HM)
};
#undef ENUM_TM
#undef ENUM_HM
#endif // GUARD_ITEM_H

View File

@@ -26,8 +26,9 @@
#define STR(...) STR_(__VA_ARGS__)
#define STR_(...) #__VA_ARGS__
/* You'll never guess what this one does */
/* You'll never guess what these do */
#define APPEND_SEMICOLON(a) a;
#define APPEND_COMMA(a) a,
/* Converts a string to a compound literal, essentially making it a pointer to const u8 */
#define COMPOUND_STRING(str) (const u8[]) _(str)
@@ -98,6 +99,21 @@
#define R_FOR_EACH_WITH_(macro, args, a, ...) INVOKE_WITH(macro, args, a) __VA_OPT__(R_FOR_EACH_WITH_P PARENS (macro, args, __VA_ARGS__))
#define R_FOR_EACH_WITH_P() R_FOR_EACH_WITH_
/* Expands to 'macro(a, b)' for each 'a' in 'as' and 'b' in 'bs'.
* Uses the shorter of 'as' and 'bs'. (Credit to MGriffin) */
#define R_ZIP(macro, as, bs) CAT(R_ZIP_, CAT(R_ZIP_NONEMPTY(as), R_ZIP_NONEMPTY(bs)))(macro, FIRST as, FIRST bs, (EXCEPT_1 as), (EXCEPT_1 bs))
#define R_ZIP_00(macro, a, b, as, bs)
#define R_ZIP_01(macro, a, b, as, bs)
#define R_ZIP_10(macro, a, b, as, bs)
#define R_ZIP_11(macro, a, b, as, bs) macro(a, b) R_ZIP_P PARENS (macro, as, bs)
#define R_ZIP_P() R_ZIP
#define R_ZIP_NONEMPTY(as) R_ZIP_NONEMPTY_ as
#define R_ZIP_NONEMPTY_(...) FIRST(__VA_OPT__(1,) 0)
/* Just a lot of numbers (with leading zeroes - remove with REMOVE_LEADING_ZEROES) */
#define NUMBERS_256 (00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255)
/* Picks the xth VA_ARG if it exists, otherwise returns a default value */
#define DEFAULT(_default, ...) FIRST(__VA_OPT__(__VA_ARGS__, ) _default)
#define DEFAULT_2(_default, ...) DEFAULT(_default __VA_OPT__(, SECOND(__VA_ARGS__)))
@@ -171,4 +187,10 @@ Input must be of the form (upper << lower) where upper can be up to 3, lower up
/* Finds the required digits to display the number (maximum 4) */
#define MAX_DIGITS(_num) 1 + !!(_num / 10) + !!(_num / 100) + !!(_num / 1000)
/* Converts a number with leading zeroes to a normal int (base 10 and up to three digits only!) */
#define REMOVE_LEADING_ZEROES(_num) (((0x##_num / 256) * 100) + ((0x##_num / 16) * 10) + (0x##_num % 16))
/* Useful for counting arguments */
#define PLUS_ONE(...) + 1
#endif

View File

@@ -824,7 +824,8 @@ void CreateTask_PlayMapChosenOrBattleBGM(u16 songId);
const u16 *GetMonFrontSpritePal(struct Pokemon *mon);
const u16 *GetMonSpritePalFromSpeciesAndPersonality(u16 species, bool32 isShiny, u32 personality);
const u16 *GetMonSpritePalFromSpecies(u16 species, bool32 isShiny, bool32 isFemale);
bool8 IsMoveHM(u16 move);
bool32 IsMoveHM(u16 move);
bool32 CannotForgetMove(u16 move);
bool8 IsMonSpriteNotFlipped(u16 species);
s8 GetMonFlavorRelation(struct Pokemon *mon, u8 flavor);
s8 GetFlavorRelationByPersonality(u32 personality, u8 flavor);