mirror of
https://github.com/pret/pokefirered.git
synced 2024-11-26 23:00:28 +00:00
Add hidden item constant usage
This commit is contained in:
parent
46a38eb3f4
commit
4bf48cf211
@ -3,14 +3,6 @@
|
||||
|
||||
#include "global.h"
|
||||
|
||||
enum HiddenItemAttr
|
||||
{
|
||||
HIDDEN_ITEM_ID = 0,
|
||||
HIDDEN_ITEM_FLAG,
|
||||
HIDDEN_ITEM_QUANTITY,
|
||||
HIDDEN_ITEM_UNDERFOOT
|
||||
};
|
||||
|
||||
u8 GetLeadMonIndex(void);
|
||||
s32 CountDigits(s32 number);
|
||||
void TV_PrintIntToStringVar(u8 varidx, s32 number);
|
||||
|
@ -50,6 +50,31 @@ enum
|
||||
TILE_TERRAIN_WATERFALL,
|
||||
};
|
||||
|
||||
// Identifiers for the hidden item data stored in BgEvent's u32 hiddenItem
|
||||
enum
|
||||
{
|
||||
HIDDEN_ITEM_ITEM,
|
||||
HIDDEN_ITEM_FLAG,
|
||||
HIDDEN_ITEM_QUANTITY,
|
||||
HIDDEN_ITEM_UNDERFOOT
|
||||
};
|
||||
|
||||
// Masks/shifts to read the data above from the u32 hiddenItem, calculated from size.
|
||||
#define HIDDEN_ITEM_ITEM_BITS 16
|
||||
#define HIDDEN_ITEM_FLAG_BITS 8
|
||||
#define HIDDEN_ITEM_QUANTITY_BITS 7
|
||||
#define HIDDEN_ITEM_UNDERFOOT_BITS 1
|
||||
|
||||
#define HIDDEN_ITEM_ITEM_SHIFT 0
|
||||
#define HIDDEN_ITEM_FLAG_SHIFT (HIDDEN_ITEM_ITEM_SHIFT + HIDDEN_ITEM_ITEM_BITS)
|
||||
#define HIDDEN_ITEM_QUANTITY_SHIFT (HIDDEN_ITEM_FLAG_SHIFT + HIDDEN_ITEM_FLAG_BITS)
|
||||
#define HIDDEN_ITEM_UNDERFOOT_SHIFT (HIDDEN_ITEM_QUANTITY_SHIFT + HIDDEN_ITEM_QUANTITY_BITS)
|
||||
|
||||
#define GET_HIDDEN_ITEM_ITEM(raw) (((raw) >> HIDDEN_ITEM_ITEM_SHIFT) & ((1 << HIDDEN_ITEM_ITEM_BITS) - 1))
|
||||
#define GET_HIDDEN_ITEM_FLAG(raw) (((raw) >> HIDDEN_ITEM_FLAG_SHIFT) & ((1 << HIDDEN_ITEM_FLAG_BITS) - 1))
|
||||
#define GET_HIDDEN_ITEM_QUANTITY(raw) (((raw) >> HIDDEN_ITEM_QUANTITY_SHIFT) & ((1 << HIDDEN_ITEM_QUANTITY_BITS) - 1))
|
||||
#define GET_HIDDEN_ITEM_UNDERFOOT(raw)(((raw) >> HIDDEN_ITEM_UNDERFOOT_SHIFT) & ((1 << HIDDEN_ITEM_UNDERFOOT_BITS) - 1))
|
||||
|
||||
typedef void (*TilesetCB)(void);
|
||||
|
||||
struct Tileset
|
||||
@ -133,13 +158,7 @@ struct BgEvent
|
||||
u8 kind; // The "kind" field determines how to access bgUnion union below.
|
||||
union {
|
||||
u8 *script;
|
||||
struct {
|
||||
u32 itemId:16;
|
||||
u32 hiddenItemId:8; // flag offset to determine flag lookup
|
||||
u32 quantity:7;
|
||||
u32 isUnderfoot:1;
|
||||
} hiddenItemStr;
|
||||
u32 hiddenItem;
|
||||
u32 hiddenItem; // Contains all the hidden item data. See GET_HIDDEN_ITEM_* defines further up
|
||||
} bgUnion;
|
||||
};
|
||||
|
||||
|
@ -495,11 +495,11 @@ static const u8 *GetInteractedBackgroundEventScript(struct MapPosition *position
|
||||
case 5:
|
||||
case 6:
|
||||
case BG_EVENT_HIDDEN_ITEM:
|
||||
if (GetHiddenItemAttr((u32)bgEvent->bgUnion.script, HIDDEN_ITEM_UNDERFOOT) == TRUE)
|
||||
if (GetHiddenItemAttr(bgEvent->bgUnion.hiddenItem, HIDDEN_ITEM_UNDERFOOT) == TRUE)
|
||||
return NULL;
|
||||
gSpecialVar_0x8005 = GetHiddenItemAttr((u32)bgEvent->bgUnion.script, HIDDEN_ITEM_ID);
|
||||
gSpecialVar_0x8004 = GetHiddenItemAttr((u32)bgEvent->bgUnion.script, HIDDEN_ITEM_FLAG);
|
||||
gSpecialVar_0x8006 = GetHiddenItemAttr((u32)bgEvent->bgUnion.script, HIDDEN_ITEM_QUANTITY);
|
||||
gSpecialVar_0x8005 = GetHiddenItemAttr(bgEvent->bgUnion.hiddenItem, HIDDEN_ITEM_ITEM);
|
||||
gSpecialVar_0x8004 = GetHiddenItemAttr(bgEvent->bgUnion.hiddenItem, HIDDEN_ITEM_FLAG);
|
||||
gSpecialVar_0x8006 = GetHiddenItemAttr(bgEvent->bgUnion.hiddenItem, HIDDEN_ITEM_QUANTITY);
|
||||
if (FlagGet(gSpecialVar_0x8004) == TRUE)
|
||||
return NULL;
|
||||
gSpecialVar_Facing = direction;
|
||||
|
@ -1750,15 +1750,15 @@ u16 StickerManGetBragFlags(void)
|
||||
|
||||
u16 GetHiddenItemAttr(u32 hiddenItem, u8 attr)
|
||||
{
|
||||
if (attr == 0)
|
||||
return hiddenItem & 0xFFFF;
|
||||
else if (attr == 1)
|
||||
return ((hiddenItem >> 16) & 0xFF) + 1000;
|
||||
else if (attr == 2)
|
||||
return (hiddenItem >> 24) & 0x7F;
|
||||
else if (attr == 3)
|
||||
return (hiddenItem >> 31) & 0x01;
|
||||
else
|
||||
if (attr == HIDDEN_ITEM_ITEM)
|
||||
return GET_HIDDEN_ITEM_ITEM(hiddenItem);
|
||||
else if (attr == HIDDEN_ITEM_FLAG)
|
||||
return GET_HIDDEN_ITEM_FLAG(hiddenItem) + FLAG_HIDDEN_ITEMS_START;
|
||||
else if (attr == HIDDEN_ITEM_QUANTITY)
|
||||
return GET_HIDDEN_ITEM_QUANTITY(hiddenItem);
|
||||
else if (attr == HIDDEN_ITEM_UNDERFOOT)
|
||||
return GET_HIDDEN_ITEM_UNDERFOOT(hiddenItem);
|
||||
else // Invalid
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -242,8 +242,8 @@ static void SetUnderfootHiddenItem(u8 taskId, u32 hiddenItem)
|
||||
{
|
||||
s16 *data = gTasks[taskId].data;
|
||||
gSpecialVar_0x8004 = GetHiddenItemAttr(hiddenItem, HIDDEN_ITEM_FLAG);
|
||||
gSpecialVar_0x8005 = GetHiddenItemAttr(hiddenItem, HIDDEN_ITEM_ID);
|
||||
gSpecialVar_0x8006 = 1;
|
||||
gSpecialVar_0x8005 = GetHiddenItemAttr(hiddenItem, HIDDEN_ITEM_ITEM);
|
||||
gSpecialVar_0x8006 = 1; // Quantity. The 'HIDDEN_ITEM_QUANTITY' data is ignored for underfoot items
|
||||
TV_PrintIntToStringVar(0, gSpecialVar_0x8005);
|
||||
tHiddenItemFound = TRUE;
|
||||
tItemX = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user