diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-03 13:33:13 +0200 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-03 13:33:13 +0200 |
commit | 907e281de6953a0d8ed59681306472939532c54f (patch) | |
tree | 5a5bfe94fbb965c32e87810daded0ed245623365 /src | |
parent | 50530b46669b3b18358097391fa9afee27e5f57e (diff) |
decompile label more of item.s
Diffstat (limited to 'src')
-rw-r--r-- | src/item.c | 192 |
1 files changed, 172 insertions, 20 deletions
diff --git a/src/item.c b/src/item.c index c68922c0e..4ad70e11f 100644 --- a/src/item.c +++ b/src/item.c @@ -1,7 +1,19 @@ #include "global.h" #include "item.h" +#include "string_util.h" +#include "text.h" +#include "event_data.h" extern void ApplyNewEncyprtionKeyToHword(u16* hword, u32 newKey); +extern bool8 InBattlePyramid(void); + +extern const u8 gOtherText_PokeBalls[]; +extern const u8 gOtherText_Berries[]; +extern const u8 gOtherText_Berry[]; +extern const u8 gUnknown_085897E4[][28]; // not sure what this one is + +bool8 CheckPyramidBagHasItem(u16 itemId, u16 count); +bool8 CheckPyramidBagHasSpace(u16 itemId, u16 count); enum { @@ -12,14 +24,6 @@ enum KEYITEMS_POCKET }; -struct BagItem -{ - struct ItemSlot (*items)[]; - u8 maxPerPocket; -}; - -extern struct BagItem gBagItems[]; - u16 GetBagItemQuantity(u16* quantity) { return gSaveBlock2Ptr->encryptionKey ^ *quantity; @@ -45,8 +49,8 @@ void ApplyNewEncyprtionKeyToBagItems(u32 newKey) u32 pocket, item; for (pocket = 0; pocket < 5; pocket++) { - for (item = 0; item < gBagItems[pocket].maxPerPocket; item++) - ApplyNewEncyprtionKeyToHword(&((*gBagItems[pocket].items)[item].quantity), newKey); + for (item = 0; item < gBagPockets[pocket].capacity; item++) + ApplyNewEncyprtionKeyToHword(&(gBagPockets[pocket].itemSlots[item].quantity), newKey); } } @@ -59,18 +63,166 @@ void ApplyNewEncyprtionKeyToBagItems_(u32 newKey) // really GF? void SetBagItemsPointers(void) { - gBagItems[ITEMS_POCKET].items = &gSaveBlock1Ptr->bagPocket_Items; - gBagItems[ITEMS_POCKET].maxPerPocket = 30; + gBagPockets[ITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Items; + gBagPockets[ITEMS_POCKET].capacity = 30; - gBagItems[KEYITEMS_POCKET].items = &gSaveBlock1Ptr->bagPocket_KeyItems; - gBagItems[KEYITEMS_POCKET].maxPerPocket = 30; + gBagPockets[KEYITEMS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_KeyItems; + gBagPockets[KEYITEMS_POCKET].capacity = 30; - gBagItems[BALLS_POCKET].items = &gSaveBlock1Ptr->bagPocket_PokeBalls; - gBagItems[BALLS_POCKET].maxPerPocket = 16; + gBagPockets[BALLS_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_PokeBalls; + gBagPockets[BALLS_POCKET].capacity = 16; + + gBagPockets[TMHM_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_TMHM; + gBagPockets[TMHM_POCKET].capacity = 64; + + gBagPockets[BERRIES_POCKET].itemSlots = gSaveBlock1Ptr->bagPocket_Berries; + gBagPockets[BERRIES_POCKET].capacity = 46; +} + +void CopyItemName(u16 itemId, u8 *string) +{ + StringCopy(string, ItemId_GetItem(itemId)->name); +} - gBagItems[TMHM_POCKET].items = &gSaveBlock1Ptr->bagPocket_TMHM; - gBagItems[TMHM_POCKET].maxPerPocket = 64; +void CopyItemNameHandlePlural(u16 itemId, u8 *string, u32 quantity) +{ + if (itemId == 4) + { + if (quantity < 2) + StringCopy(string, ItemId_GetItem(4)->name); + else + StringCopy(string, gOtherText_PokeBalls); + } + else + { + if (itemId >= 0x85 && itemId <= 0xAF) + GetBerryCountString(string, gUnknown_085897E4[itemId], quantity); + else + StringCopy(string, ItemId_GetItem(itemId)->name); + } +} - gBagItems[BERRIES_POCKET].items = &gSaveBlock1Ptr->bagPocket_Berries; - gBagItems[BERRIES_POCKET].maxPerPocket = 46; +void GetBerryCountString(u8* dst, const u8* berryName, u32 quantity) +{ + const u8* berryString; + u8* txtPtr; + + if (quantity < 2) + berryString = gOtherText_Berry; + else + berryString = gOtherText_Berries; + txtPtr = StringCopy(dst, berryName); + *txtPtr = CHAR_SPACE; + StringCopy(txtPtr + 1, berryString); } + +bool8 IsBagPocketNonEmpty(u8 pocket) +{ + u8 i; + + for (i = 0; i < gBagPockets[pocket - 1].capacity; i++) + { + if (gBagPockets[pocket - 1].itemSlots[i].itemId != 0) + return TRUE; + } + return FALSE; +} + +bool8 CheckBagHasItem(u16 itemId, u16 count) +{ + u8 i; + u8 pocket; + + if (ItemId_GetPocket(itemId) == 0) + return FALSE; + if (InBattlePyramid() || FlagGet(0x4004) == TRUE) + return CheckPyramidBagHasItem(itemId, count); + pocket = ItemId_GetPocket(itemId) - 1; + //Check for item slots that contain the item + for (i = 0; i < gBagPockets[pocket].capacity; i++) + { + if (gBagPockets[pocket].itemSlots[i].itemId == itemId) + { + u16 quantity; + //Does this item slot contain enough of the item? + quantity = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); + if (quantity >= count) + return TRUE; + count -= quantity; + //Does this item slot and all previous slots contain enough of the item? + if (count == 0) + return TRUE; + } + } + return FALSE; +} + +bool8 HasAtLeastOneBerry(void) +{ + u16 i; + for (i = 0x85; i < 0xB3; i++) + { + if (CheckBagHasItem(i, 1) == TRUE) + { + gScriptResult = 1; + return TRUE; + } + } + gScriptResult = 0; + return FALSE; +} + +/* Refuses to match. +bool8 CheckBagHasSpace(u16 itemId, u16 count) +{ + u8 i; + u8 pocket; + u16 slotCapacity; + u16 quantity; + + if (ItemId_GetPocket(itemId) == 0) + return FALSE; + if (InBattlePyramid() || FlagGet(0x4004) == TRUE) + return CheckPyramidBagHasSpace(itemId, count); + pocket = ItemId_GetPocket(itemId) - 1; + if (pocket != BERRIES_POCKET) + slotCapacity = 99; + else + slotCapacity = 999; + + //Check space in any existing item slots that already contain this item + for (i = 0; i < gBagPockets[pocket].capacity; i++) + { + if (gBagPockets[pocket].itemSlots[i].itemId == itemId) + { + quantity = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); + if (quantity + count <= slotCapacity) + return TRUE; + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + return FALSE; + count -= slotCapacity - quantity; + if (count == 0) + return TRUE; + } + } + + //Check space in empty item slots + if (count > 0) + { + for (i = 0; i < gBagPockets[pocket].capacity; i++) + { + if (gBagPockets[pocket].itemSlots[i].itemId == 0) + { + if (count <= slotCapacity) + return TRUE; + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + return FALSE; + count -= slotCapacity; + } + } + if (count > 0) + return FALSE; //No more item slots. The bag is full + } + + return TRUE; +}*/ |