From 6f59dcb6552744a42df566c32317c264ea47811a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 11 Mar 2025 10:54:57 +0100 Subject: [PATCH 1/8] sub_80460F8 --- asm/code_8045A00.s | 512 --------------------------------------------- src/code_8045A00.c | 312 +++++++++++++++++++++------ 2 files changed, 252 insertions(+), 572 deletions(-) diff --git a/asm/code_8045A00.s b/asm/code_8045A00.s index 6adcff979..4ab77f462 100644 --- a/asm/code_8045A00.s +++ b/asm/code_8045A00.s @@ -5,518 +5,6 @@ .text - thumb_func_start sub_8045DB4 -sub_8045DB4: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xB8 - mov r10, r0 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0xA8] - bl GetLeader - adds r7, r0, 0 - ldr r0, [r7, 0x70] - str r0, [sp, 0xAC] - mov r1, r10 - movs r2, 0 - ldrsh r0, [r1, r2] - movs r3, 0x2 - ldrsh r1, [r1, r3] - bl GetTile - ldr r4, [r0, 0x14] - cmp r4, 0 - bne _08045DE8 - b _080460E0 -_08045DE8: - adds r0, r4, 0 - bl GetEntityType - cmp r0, 0x3 - beq _08045DF4 - b _080460E0 -_08045DF4: - adds r0, r4, 0 - bl GetItemData - adds r5, r0, 0 - ldr r0, [sp, 0xAC] - adds r0, 0x48 - ldrb r0, [r0] - cmp r0, 0 - bne _08045E08 - b _0804602E -_08045E08: - adds r0, r7, 0 - movs r1, 0x1 - bl ShouldMonsterRunAwayAndShowEffect - lsls r0, 24 - cmp r0, 0 - beq _08045E40 - ldr r0, [sp, 0xA8] - cmp r0, 0 - bne _08045E1E - b _080460E0 -_08045E1E: - ldr r0, _08045E34 - adds r1, r5, 0 - bl sub_8045BF8 - ldr r0, _08045E38 - adds r1, r7, 0 - movs r2, 0 - bl SubstitutePlaceholderStringTags - ldr r0, _08045E3C - b _08046048 - .align 2, 0 -_08045E34: .4byte gFormatBuffer_Items -_08045E38: .4byte gFormatBuffer_Monsters -_08045E3C: .4byte gMonTerrifiedCouldntPickUpItem -_08045E40: - ldrb r0, [r5, 0x2] - bl GetItemCategory - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x6 - bne _08045E7C - movs r0, 0xA6 - lsls r0, 1 - bl PlaySoundEffect - adds r0, r5, 0 - bl GetMoneyValue - bl AddToTeamMoney - ldr r0, _08045E74 - adds r1, r5, 0 - bl sub_8045BF8 - mov r0, r10 - movs r1, 0x1 - bl sub_80461C8 - ldr r0, _08045E78 - b _08045FD0 - .align 2, 0 -_08045E74: .4byte gFormatBuffer_Items -_08045E78: .4byte gPickedUpItem -_08045E7C: - ldr r0, _08045EA8 - ldr r0, [r0] - ldr r1, _08045EAC - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0 - beq _08045EB4 - movs r4, 0 - ldr r0, _08045EB0 - mov r2, sp - ldr r0, [r0] - add r1, sp, 0x54 -_08045E94: - stm r1!, {r0} - stm r2!, {r4} - adds r0, 0x4 - adds r4, 0x1 - cmp r4, 0x13 - ble _08045E94 - movs r2, 0x14 - mov r8, r2 - b _08045EC4 - .align 2, 0 -_08045EA8: .4byte gDungeon -_08045EAC: .4byte 0x0000065b -_08045EB0: .4byte gTeamInventoryRef -_08045EB4: - ldr r0, [sp, 0xAC] - adds r0, 0x60 - str r0, [sp, 0x54] - movs r0, 0x1 - negs r0, r0 - str r0, [sp] - movs r3, 0x1 - mov r8, r3 -_08045EC4: - ldrb r0, [r5, 0x2] - add r6, sp, 0xB0 - strb r0, [r6] - cmp r0, 0x8 - bls _08045ED0 - b _08046000 -_08045ED0: - ldrb r1, [r5] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _08045EDC - b _08046000 -_08045EDC: - movs r1, 0x1 - negs r1, r1 - mov r12, r1 - mov r2, r12 - str r2, [sp, 0xB4] - movs r4, 0 - cmp r4, r8 - bge _08045F2C - ldr r3, _08045FDC - mov r9, r3 - add r3, sp, 0x54 -_08045EF2: - ldr r2, [r3] - ldrb r1, [r2] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08045F24 - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _08045F24 - ldr r1, [r5] - mov r6, r9 - ands r1, r6 - ldr r0, [r2] - ands r0, r6 - cmp r1, r0 - bne _08045F24 - ldrb r0, [r2, 0x1] - cmp r0, 0x63 - beq _08045F24 - ldr r1, [sp, 0xB4] - cmp r1, r0 - bge _08045F24 - str r0, [sp, 0xB4] - mov r12, r4 -_08045F24: - adds r3, 0x4 - adds r4, 0x1 - cmp r4, r8 - blt _08045EF2 -_08045F2C: - movs r0, 0x1 - negs r0, r0 - cmp r12, r0 - bne _08045F80 - mov r2, r12 - str r2, [sp, 0xB4] - movs r4, 0 - cmp r4, r8 - bge _08045F78 - add r3, sp, 0xB0 - ldrb r3, [r3] - mov r9, r3 - add r3, sp, 0x54 -_08045F46: - ldr r2, [r3] - ldrb r1, [r2] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08045F70 - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _08045F70 - ldrb r6, [r2, 0x2] - cmp r9, r6 - bne _08045F70 - ldrb r0, [r2, 0x1] - cmp r0, 0x63 - beq _08045F70 - ldr r1, [sp, 0xB4] - cmp r1, r0 - bge _08045F70 - str r0, [sp, 0xB4] - mov r12, r4 -_08045F70: - adds r3, 0x4 - adds r4, 0x1 - cmp r4, r8 - blt _08045F46 -_08045F78: - movs r0, 0x1 - negs r0, r0 - cmp r12, r0 - beq _08046000 -_08045F80: - add r0, sp, 0x54 - mov r2, r12 - lsls r4, r2, 2 - adds r3, r0, r4 - ldr r2, [r3] - ldrb r1, [r2, 0x1] - ldrb r0, [r5, 0x1] - adds r1, r0 - cmp r1, 0x62 - ble _08045F96 - movs r1, 0x63 -_08045F96: - strb r1, [r2, 0x1] - ldrb r1, [r5] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08045FAC - ldr r0, [r3] - ldrb r1, [r0] - movs r2, 0x8 - orrs r1, r2 - strb r1, [r0] -_08045FAC: - ldr r0, _08045FE0 - adds r1, r5, 0 - bl sub_8045BF8 - mov r0, r10 - movs r1, 0x1 - bl sub_80461C8 - movs r0, 0xA5 - lsls r0, 1 - bl PlaySoundEffect - mov r3, sp - adds r0, r3, r4 - ldr r0, [r0] - cmp r0, 0 - bge _08045FE8 - ldr r0, _08045FE4 -_08045FD0: - ldr r1, [r0] - adds r0, r7, 0 - bl LogMessageByIdWithPopupCheckUser - b _08045FF2 - .align 2, 0 -_08045FDC: .4byte 0x00ff0008 -_08045FE0: .4byte gFormatBuffer_Items -_08045FE4: .4byte gPickedUpItem2 -_08045FE8: - ldr r0, _08045FFC - ldr r1, [r0] - adds r0, r7, 0 - bl LogMessageByIdWithPopupCheckUser -_08045FF2: - ldrb r0, [r5, 0x2] - bl TryDisplayItemPickupTutorialMessage - b _080460E0 - .align 2, 0 -_08045FFC: .4byte gPickedUpItemToolbox -_08046000: - movs r4, 0 - cmp r4, r8 - bge _0804602A - ldr r0, [sp, 0x54] - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0804602A - movs r3, 0x1 - add r2, sp, 0x54 -_08046016: - adds r2, 0x4 - adds r4, 0x1 - cmp r4, r8 - bge _0804602A - ldr r0, [r2] - ldrb r1, [r0] - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - bne _08046016 -_0804602A: - cmp r4, r8 - bne _08046060 -_0804602E: - ldr r6, [sp, 0xA8] - cmp r6, 0 - beq _080460E0 - ldr r0, _08046054 - adds r1, r5, 0 - bl sub_8045BF8 - ldr r0, _08046058 - adds r1, r7, 0 - movs r2, 0 - bl SubstitutePlaceholderStringTags - ldr r0, _0804605C -_08046048: - ldr r1, [r0] - adds r0, r7, 0 - bl LogMessageByIdWithPopupCheckUser - b _080460E0 - .align 2, 0 -_08046054: .4byte gFormatBuffer_Items -_08046058: .4byte gFormatBuffer_Monsters -_0804605C: .4byte gMonSteppedOnItem -_08046060: - movs r0, 0xA5 - lsls r0, 1 - bl PlaySoundEffect - lsls r0, r4, 2 - add r0, sp - ldr r0, [r0] - cmp r0, 0 - bge _08046094 - ldr r0, [r5] - ldr r1, [sp, 0xAC] - str r0, [r1, 0x60] - ldr r0, _0804608C - adds r1, r5, 0 - bl sub_8045BF8 - mov r0, r10 - movs r1, 0x1 - bl sub_80461C8 - ldr r0, _08046090 - b _080460AC - .align 2, 0 -_0804608C: .4byte gFormatBuffer_Items -_08046090: .4byte gPickedUpItem2 -_08046094: - adds r0, r5, 0 - bl AddItemToInventory - lsls r0, 24 - cmp r0, 0 - beq _080460C0 - ldr r0, _080460B8 - adds r1, r7, 0 - movs r2, 0 - bl SubstitutePlaceholderStringTags - ldr r0, _080460BC -_080460AC: - ldr r1, [r0] - adds r0, r7, 0 - bl LogMessageByIdWithPopupCheckUser - b _080460DA - .align 2, 0 -_080460B8: .4byte gFormatBuffer_Monsters -_080460BC: .4byte gMonCouldntPickUpItem -_080460C0: - ldr r0, _080460F0 - adds r1, r5, 0 - bl sub_8045BF8 - mov r0, r10 - movs r1, 0x1 - bl sub_80461C8 - ldr r0, _080460F4 - ldr r1, [r0] - adds r0, r7, 0 - bl LogMessageByIdWithPopupCheckUser -_080460DA: - ldrb r0, [r5, 0x2] - bl TryDisplayItemPickupTutorialMessage -_080460E0: - add sp, 0xB8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080460F0: .4byte gFormatBuffer_Items -_080460F4: .4byte gPickedUpItemToolbox - thumb_func_end sub_8045DB4 - - thumb_func_start sub_80460F8 -sub_80460F8: - push {r4-r7,lr} - adds r5, r0, 0 - adds r6, r1, 0 - lsls r2, 24 - lsrs r7, r2, 24 - bl sub_8045708 - adds r4, r0, 0 - cmp r4, 0 - bne _08046110 - movs r0, 0 - b _080461B6 -_08046110: - ldr r1, [r4, 0x70] - ldr r0, [r6] - str r0, [r1] - ldr r2, [r4, 0x70] - ldrb r1, [r2] - movs r0, 0xEF - ands r0, r1 - strb r0, [r2] - adds r1, r4, 0 - adds r1, 0x20 - movs r0, 0x1 - strb r0, [r1] - movs r1, 0 - ldrsh r0, [r5, r1] - movs r2, 0x2 - ldrsh r1, [r5, r2] - bl GetTileMut - str r4, [r0, 0x14] - ldrh r1, [r0] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _08046186 - ldrb r0, [r6, 0x2] - bl CanSellItem - lsls r0, 24 - cmp r0, 0 - beq _08046186 - ldrb r1, [r6] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _08046170 - cmp r7, 0 - beq _08046186 - adds r0, r6, 0 - bl GetStackBuyPrice - ldr r1, _08046168 - ldr r2, [r1] - ldr r1, _0804616C - b _0804617E - .align 2, 0 -_08046168: .4byte gDungeon -_0804616C: .4byte 0x0000068c -_08046170: - adds r0, r6, 0 - bl GetStackSellPrice - ldr r1, _080461BC - ldr r2, [r1] - movs r1, 0xD2 - lsls r1, 3 -_0804617E: - adds r2, r1 - ldr r1, [r2] - adds r1, r0 - str r1, [r2] -_08046186: - movs r6, 0 - movs r4, 0 -_0804618A: - ldr r5, _080461BC - ldr r0, [r5] - lsls r1, r4, 2 - ldr r2, _080461C0 - adds r0, r2 - adds r0, r1 - ldr r0, [r0] - bl EntityIsValid - lsls r0, 24 - adds r1, r4, 0x1 - cmp r0, 0 - beq _080461A6 - adds r6, r1, 0 -_080461A6: - adds r4, r1, 0 - cmp r4, 0x3F - ble _0804618A - ldr r0, [r5] - ldr r1, _080461C4 - adds r0, r1 - strh r6, [r0] - movs r0, 0x1 -_080461B6: - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_080461BC: .4byte gDungeon -_080461C0: .4byte 0x0001361c -_080461C4: .4byte 0x00003904 - thumb_func_end sub_80460F8 thumb_func_start sub_80461C8 sub_80461C8: diff --git a/src/code_8045A00.c b/src/code_8045A00.c index adeaed8d2..f14880c6f 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -5,20 +5,33 @@ #include "dungeon_map_access.h" #include "dungeon_random.h" #include "dungeon_util.h" +#include "dungeon_leader.h" +#include "dungeon_message.h" +#include "dungeon_music.h" +#include "dungeon_ai_targeting.h" +#include "string_format.h" #include "items.h" #include "status_checks_1.h" #include "structs/map.h" #include "structs/str_dungeon.h" #include "trap.h" +#include "code_80450F8.h" extern u8 *gUnknown_80FE6F4[]; +extern u8 *gPickedUpItemToolbox[]; +extern u8 *gMonTerrifiedCouldntPickUpItem[]; +extern u8 *gPickedUpItem2[]; +extern u8 *gMonCouldntPickUpItem[]; +extern u8 *gPickedUpItem[]; +extern u8 *gMonSteppedOnItem[]; extern struct unkStruct_8090F58 gUnknown_80F699C; extern struct unkStruct_8090F58 gUnknown_80F69A8; extern struct unkStruct_8090F58 gUnknown_80F6990; +extern bool8 sub_80461C8(DungeonPos *, u32); void sub_8045BF8(u8 *, Item *); extern u32 sub_803D73C(u32); -void sub_80460F8(DungeonPos *, Item *, u32); +bool8 sub_80460F8(DungeonPos *, Item *, bool8); void sub_8045ACC(void) { @@ -126,65 +139,244 @@ void sub_8045C28(Item *item, u8 itemID, u32 param_3) void sub_8045CB0(void) { - bool8 shopFlag; - u8 itemID; - u32 x; - int y; - int yCounter; - const Tile *tile; - u32 uVar5; - int xCounter; - Item item; - DungeonPos pos; - u32 flag; + u8 itemID; + s32 yCounter, xCounter; + const Tile *tile; + u32 uVar5; + Item item; + u32 flag; + s32 x = DungeonRandInt(DUNGEON_MAX_SIZE_X); + s32 y = DungeonRandInt(DUNGEON_MAX_SIZE_Y); - x = DungeonRandInt(DUNGEON_MAX_SIZE_X); - y = DungeonRandInt(DUNGEON_MAX_SIZE_Y); - gDungeon->numItems = 0; - for(yCounter = 0; yCounter < DUNGEON_MAX_SIZE_Y; yCounter++) - { - y++; - if (y == DUNGEON_MAX_SIZE_Y) { - y = 0; + gDungeon->numItems = 0; + for (yCounter = 0; yCounter < DUNGEON_MAX_SIZE_Y; yCounter++) { + y++; + if (y == DUNGEON_MAX_SIZE_Y) { + y = 0; + } + + for (xCounter = 0; xCounter < DUNGEON_MAX_SIZE_X; xCounter++) { + x++; + flag = ITEM_FLAG_IN_SHOP; + if (x == DUNGEON_MAX_SIZE_X) { + x = 0; + } + tile = GetTile(x,y); + + if (!(tile->terrainType & TERRAIN_TYPE_STAIRS) && (tile->spawnOrVisibilityFlags & 2)) { + DungeonPos pos; + bool8 shopFlag = FALSE; + pos.x = x; + pos.y = y; + + if (tile->terrainType & TERRAIN_TYPE_SHOP) { + shopFlag = TRUE; + uVar5 = 1; + } + else + { + if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { + uVar5 = 3; + } + else { + uVar5 = (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) ? 2 : 0; + } + } + itemID = sub_803D73C(uVar5); + if (!CanSellItem(itemID)) { + shopFlag = 0; + } + sub_8045C28(&item,itemID,0); + if (shopFlag) { + item.flags |= flag; + } + sub_80460F8(&pos,&item,TRUE); + } + } } - - for(xCounter = 0; xCounter < DUNGEON_MAX_SIZE_X; xCounter++) - { - x++; - flag = ITEM_FLAG_IN_SHOP; - if (x == DUNGEON_MAX_SIZE_X) { - x = 0; - } - tile = GetTile(x,y); - - if (((tile->terrainType & TERRAIN_TYPE_STAIRS) == 0) && ((tile->spawnOrVisibilityFlags & 2) != 0)) { - shopFlag = FALSE; - pos.x = x; - pos.y = y; - - if (tile->terrainType & TERRAIN_TYPE_SHOP) { - shopFlag = TRUE; - uVar5 = 1; - } - else - { - if ((tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY)) == 0) { - uVar5 = 3; - } - else { - uVar5 = -(tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) >> 0x1f & 2; - } - } - itemID = sub_803D73C(uVar5); - if (!CanSellItem(itemID)) { - shopFlag = 0; - } - sub_8045C28(&item,itemID,0); - if (shopFlag) { - item.flags |= flag; - } - sub_80460F8(&pos,&item,1); - } - } - } +} + +void sub_8045DB4(struct DungeonPos *pos, bool8 printMsg) +{ + Item *tileItem; + int inventoryIds[INVENTORY_SIZE + 1]; + Item *inventoryItems[INVENTORY_SIZE + 1]; + Entity *leader = GetLeader(); + EntityInfo *leaderInfo = GetEntInfo(leader); + const Tile *tile = GetTile(pos->x,pos->y); + Entity *tileObject = tile->object; + if (tileObject == NULL) { + return; + } + if (GetEntityType(tileObject) != ENTITY_ITEM) { + return; + } + tileItem = GetItemData(tileObject); + if (leaderInfo->action.actionParameters[0].actionUseIndex == 0) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); + } + else if (ShouldMonsterRunAwayAndShowEffect(leader,1)) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonTerrifiedCouldntPickUpItem); + } + else if (GetItemCategory(tileItem->id) == CATEGORY_POKE) { + PlaySoundEffect(0x14c); + AddToTeamMoney(GetMoneyValue(tileItem)); + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem); + TryDisplayItemPickupTutorialMessage(tileItem->id); + } + else { + s32 i, maxItems; + if (gDungeon->unk644.unk17 != 0) { + for (i = 0; i < INVENTORY_SIZE; i++) { + inventoryItems[i] = &gTeamInventoryRef->teamItems[i]; + inventoryIds[i] = i; + } + maxItems = INVENTORY_SIZE; + } + else { + inventoryItems[0] = &leaderInfo->heldItem; + inventoryIds[0] = -1; + maxItems = 1; + } + + if (tileItem->id <= ITEM_GEO_PEBBLE && !(tileItem->flags & ITEM_FLAG_IN_SHOP)) { + s32 index = -1; + s32 numberItems = -1; + s32 i; + + for (i = 0; i < maxItems; i++) { + if (ItemExists(inventoryItems[i]) + && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) + && (tileItem->id == inventoryItems[i]->id) + && (tileItem->flags & ITEM_FLAG_STICKY) == (inventoryItems[i]->flags & ITEM_FLAG_STICKY) + && inventoryItems[i]->quantity != 99 + && numberItems < inventoryItems[i]->quantity) + { + numberItems = inventoryItems[i]->quantity; + index = i; + } + } + + if (index == -1) { + s32 i; + + numberItems = -1; + for (i = 0; i < maxItems; i++) { + if (ItemExists(inventoryItems[i]) + && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) + && tileItem->id == inventoryItems[i]->id + && inventoryItems[i]->quantity != 99 + && numberItems < inventoryItems[i]->quantity) + { + numberItems = inventoryItems[i]->quantity; + index = i; + } + } + } + + if (index != -1) { + struct Item *addedItem = inventoryItems[index]; + s32 newQuantity = addedItem->quantity + tileItem->quantity; + + if (newQuantity >= 99) { + newQuantity = 99; + } + addedItem->quantity = newQuantity; + + if (tileItem->flags & ITEM_FLAG_STICKY) { + inventoryItems[index]->flags |= ITEM_FLAG_STICKY; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + PlaySoundEffect(0x14a); + if (inventoryIds[index] < 0) { + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); + } + else { + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); + } + TryDisplayItemPickupTutorialMessage(tileItem->id); + return; + } + } + + for (i = 0; i < maxItems; i++) { + if (!ItemExists(inventoryItems[i])) + break; + } + + if (i == maxItems) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); + } + else { + PlaySoundEffect(0x14a); + if (inventoryIds[i] < 0) { + leaderInfo->heldItem = *tileItem; + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); + } + else if (AddItemToInventory(tileItem) != 0) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonCouldntPickUpItem); + } + else { + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); + } + TryDisplayItemPickupTutorialMessage(tileItem->id); + } + } +} + +bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) +{ + s32 i, count; + Tile *tile; + Entity *entity = sub_8045708(pos); + + if (entity == NULL) + return FALSE; + *entity->axObj.info.item = *item; + entity->axObj.info.item->flags &= ~(ITEM_FLAG_SET); + entity->isVisible = TRUE; + tile = GetTileMut(pos->x, pos->y); + tile->object = entity; + if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { + if (item->flags & ITEM_FLAG_IN_SHOP) { + if (a2) { + gDungeon->unk644.unk48 += GetStackBuyPrice(item); + } + } + else { + gDungeon->unk644.unk4C += GetStackSellPrice(item); + } + } + + count = 0; + for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { + if (EntityIsValid(gDungeon->items[i])) { + count = i + 1; + } + } + gDungeon->numItems = count; + return TRUE; } From 5003db440bbba66a9820ec41123c9e832c2629ea Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 11 Mar 2025 12:12:42 +0100 Subject: [PATCH 2/8] sub_80462AC --- asm/code_8045A00.s | 374 --------------------------------------------- include/items.h | 3 +- src/code_8045A00.c | 107 ++++++++++++- src/items.c | 2 +- 4 files changed, 109 insertions(+), 377 deletions(-) diff --git a/asm/code_8045A00.s b/asm/code_8045A00.s index 4ab77f462..79b0398d7 100644 --- a/asm/code_8045A00.s +++ b/asm/code_8045A00.s @@ -6,380 +6,6 @@ .text - thumb_func_start sub_80461C8 -sub_80461C8: - push {r4-r7,lr} - adds r2, r0, 0 - lsls r1, 24 - lsrs r7, r1, 24 - movs r1, 0 - ldrsh r0, [r2, r1] - movs r3, 0x2 - ldrsh r1, [r2, r3] - bl GetTileMut - adds r6, r0, 0 - ldr r5, [r6, 0x14] - cmp r5, 0 - beq _080461EE - adds r0, r5, 0 - bl GetEntityType - cmp r0, 0x3 - beq _080461F2 -_080461EE: - movs r0, 0 - b _08046284 -_080461F2: - adds r0, r5, 0 - bl GetItemData - adds r4, r0, 0 - ldrh r1, [r6] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _0804624E - ldrb r0, [r4, 0x2] - bl CanSellItem - lsls r0, 24 - cmp r0, 0 - beq _0804624E - ldrb r1, [r4] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _08046238 - cmp r7, 0 - beq _0804624E - adds r0, r4, 0 - bl GetStackBuyPrice - ldr r1, _08046230 - ldr r2, [r1] - ldr r1, _08046234 - adds r2, r1 - b _08046248 - .align 2, 0 -_08046230: .4byte gDungeon -_08046234: .4byte 0x0000068c -_08046238: - adds r0, r4, 0 - bl GetStackSellPrice - ldr r1, _0804628C - ldr r2, [r1] - movs r3, 0xD2 - lsls r3, 3 - adds r2, r3 -_08046248: - ldr r1, [r2] - subs r1, r0 - str r1, [r2] -_0804624E: - movs r0, 0 - str r0, [r6, 0x14] - str r0, [r5] - movs r6, 0 - movs r4, 0 -_08046258: - ldr r5, _0804628C - ldr r0, [r5] - lsls r1, r4, 2 - ldr r2, _08046290 - adds r0, r2 - adds r0, r1 - ldr r0, [r0] - bl EntityIsValid - lsls r0, 24 - adds r1, r4, 0x1 - cmp r0, 0 - beq _08046274 - adds r6, r1, 0 -_08046274: - adds r4, r1, 0 - cmp r4, 0x3F - ble _08046258 - ldr r0, [r5] - ldr r3, _08046294 - adds r0, r3 - strh r6, [r0] - movs r0, 0x1 -_08046284: - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0804628C: .4byte gDungeon -_08046290: .4byte 0x0001361c -_08046294: .4byte 0x00003904 - thumb_func_end sub_80461C8 - - thumb_func_start sub_8046298 -sub_8046298: - ldrb r0, [r0, 0x2] - ldr r1, _080462A8 - ldr r1, [r1] - lsls r0, 5 - adds r0, r1 - ldrb r0, [r0, 0xD] - bx lr - .align 2, 0 -_080462A8: .4byte gItemParametersData - thumb_func_end sub_8046298 - - thumb_func_start sub_80462AC -sub_80462AC: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r4, r0, 0 - ldr r0, [sp, 0x28] - lsls r1, 24 - lsrs r1, 24 - mov r10, r1 - lsls r2, 24 - lsrs r5, r2, 24 - lsls r3, 24 - lsrs r3, 24 - mov r9, r3 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r0, 0 - str r0, [sp, 0x4] - adds r0, r4, 0 - bl EntityIsValid - lsls r0, 24 - cmp r0, 0 - bne _080462E4 - b _08046498 -_080462E4: - cmp r5, 0 - beq _08046316 - movs r1, 0x4 - ldrsh r0, [r4, r1] - movs r2, 0x6 - ldrsh r1, [r4, r2] - bl GetTile - ldrh r0, [r0] - movs r1, 0x3 - ands r1, r0 - cmp r1, 0 - bne _08046300 - b _08046498 -_08046300: - cmp r1, 0x2 - bne _08046308 - movs r3, 0x1 - str r3, [sp, 0x4] -_08046308: - adds r0, r4, 0 - bl sub_8045888 - lsls r0, 24 - cmp r0, 0 - bne _08046316 - b _08046498 -_08046316: - ldr r1, [r4, 0xC] - cmp r1, 0 - bge _0804631E - adds r1, 0xFF -_0804631E: - asrs r1, 8 - ldr r0, _080463A4 - ldr r2, [r0] - ldr r5, _080463A8 - adds r0, r2, r5 - movs r3, 0 - ldrsh r0, [r0, r3] - subs r6, r1, r0 - ldr r3, [r4, 0x10] - ldr r0, [r4, 0x1C] - subs r1, r3, r0 - cmp r1, 0 - bge _0804633A - adds r1, 0xFF -_0804633A: - asrs r1, 8 - ldr r5, _080463AC - adds r0, r2, r5 - movs r5, 0 - ldrsh r2, [r0, r5] - subs r1, r2 - mov r8, r1 - adds r0, r3, 0 - cmp r0, 0 - bge _08046350 - adds r0, 0xFF -_08046350: - asrs r0, 8 - subs r0, r2 - adds r7, r0, 0 - adds r7, 0x8 - lsrs r0, r7, 31 - adds r0, r7, r0 - asrs r7, r0, 1 - movs r0, 0x20 - negs r0, r0 - cmp r6, r0 - bge _08046368 - b _08046498 -_08046368: - cmp r8, r0 - bge _0804636E - b _08046498 -_0804636E: - movs r0, 0x88 - lsls r0, 1 - cmp r6, r0 - ble _08046378 - b _08046498 -_08046378: - mov r0, r8 - cmp r0, 0xC0 - ble _08046380 - b _08046498 -_08046380: - ldr r5, _080463B0 - ldrh r1, [r5, 0x2] - ldr r0, _080463B4 - ands r0, r1 - strh r0, [r5, 0x2] - mov r1, r10 - cmp r1, 0 - beq _080463BC - movs r2, 0x17 - mov r10, r2 - movs r2, 0xA0 - lsls r2, 8 - ldrh r1, [r5, 0x4] - ldr r0, _080463B8 - ands r0, r1 - orrs r0, r2 - strh r0, [r5, 0x4] - b _08046408 - .align 2, 0 -_080463A4: .4byte gDungeon -_080463A8: .4byte 0x000181f0 -_080463AC: .4byte 0x000181f2 -_080463B0: .4byte gUnknown_202EDC0 -_080463B4: .4byte 0x0000c1ff -_080463B8: .4byte 0x00000fff -_080463BC: - ldr r0, [r4, 0x70] - bl sub_8046298 - mov r10, r0 - mov r3, r9 - cmp r3, 0xFF - beq _080463EE - cmp r0, 0 - bne _080463EE - ldr r0, _08046478 - add r0, r9 - ldrb r0, [r0] - mov r10, r0 - ldr r0, _0804647C - add r0, r9 - ldrb r1, [r0] - lsls r1, 3 - movs r0, 0x1F - ands r1, r0 - lsls r1, 9 - ldrh r2, [r5, 0x2] - ldr r0, _08046480 - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x2] -_080463EE: - ldr r0, [r4, 0x70] - ldrb r0, [r0, 0x2] - bl GetItemPalette - movs r1, 0xF - ands r0, r1 - lsls r0, 12 - ldr r3, _08046484 - ldrh r2, [r3, 0x4] - ldr r1, _08046488 - ands r1, r2 - orrs r1, r0 - strh r1, [r3, 0x4] -_08046408: - ldr r1, _08046488 - mov r5, r8 - ands r1, r5 - lsls r1, 4 - ldr r4, _08046484 - ldrh r2, [r4, 0x6] - movs r0, 0xF - ands r0, r2 - orrs r0, r1 - strh r0, [r4, 0x6] - ldr r0, _0804648C - ands r6, r0 - ldrh r1, [r4, 0x2] - movs r0, 0xFE - lsls r0, 8 - ands r0, r1 - orrs r0, r6 - strh r0, [r4, 0x2] - ldr r0, [sp, 0x4] - lsls r3, r0, 10 - ldrh r2, [r4] - ldr r1, _08046490 - adds r0, r1, 0 - ands r0, r2 - orrs r0, r3 - strh r0, [r4] - movs r2, 0xC0 - lsls r2, 4 - ldrh r0, [r4, 0x4] - ands r1, r0 - orrs r1, r2 - mov r2, r10 - lsls r0, r2, 2 - movs r3, 0xD0 - lsls r3, 1 - adds r0, r3 - ldr r2, _08046494 - ands r0, r2 - movs r2, 0xFC - lsls r2, 8 - ands r1, r2 - orrs r1, r0 - strh r1, [r4, 0x4] - ldr r5, [sp] - cmp r5, 0 - bne _08046466 - movs r7, 0x1 -_08046466: - adds r0, r4, 0 - adds r1, r7, 0 - movs r2, 0 - movs r3, 0 - bl AddSprite - movs r0, 0x1 - b _0804649A - .align 2, 0 -_08046478: .4byte gUnknown_203B420 -_0804647C: .4byte gUnknown_203B428 -_08046480: .4byte 0x0000c1ff -_08046484: .4byte gUnknown_202EDC0 -_08046488: .4byte 0x00000fff -_0804648C: .4byte 0x000001ff -_08046490: .4byte 0x0000f3ff -_08046494: .4byte 0x000003ff -_08046498: - movs r0, 0 -_0804649A: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80462AC - thumb_func_start sub_80464AC sub_80464AC: push {r4,lr} diff --git a/include/items.h b/include/items.h index 1dd09dd99..933aa5920 100644 --- a/include/items.h +++ b/include/items.h @@ -6,6 +6,7 @@ #include "structs/str_pokemon.h" #include "structs/subStruct_203B240.h" +extern ItemDataEntry *gItemParametersData; extern TeamInventory *gTeamInventoryRef; void LoadItemParameters(void); @@ -25,7 +26,7 @@ s32 GetStackSellPrice(Item *param_1); s32 GetItemBuyPrice(u8 id); s32 GetItemSellPrice(u8 id); s32 GetItemOrder(u8 id); -u8 GetItemPalette(u8 id); +s32 GetItemPalette(u8 id); u32 GetItemActionType(u8 id); u32 GetSpawnAmountRange(u8 id, u32 r1); u8 *GetItemDescription(u8 id); diff --git a/src/code_8045A00.c b/src/code_8045A00.c index f14880c6f..aa3be02d8 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -28,7 +28,7 @@ extern struct unkStruct_8090F58 gUnknown_80F699C; extern struct unkStruct_8090F58 gUnknown_80F69A8; extern struct unkStruct_8090F58 gUnknown_80F6990; -extern bool8 sub_80461C8(DungeonPos *, u32); +bool8 sub_80461C8(DungeonPos *, bool8); void sub_8045BF8(u8 *, Item *); extern u32 sub_803D73C(u32); bool8 sub_80460F8(DungeonPos *, Item *, bool8); @@ -380,3 +380,108 @@ bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) gDungeon->numItems = count; return TRUE; } + +bool8 sub_80461C8(DungeonPos *pos, bool8 a2) +{ + s32 i, count; + Item *item; + Tile *tile = GetTileMut(pos->x, pos->y); + Entity *tileObject = tile->object; + if (tileObject == NULL || GetEntityType(tileObject) != ENTITY_ITEM) + return FALSE; + + item = GetItemData(tileObject); + if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { + if (item->flags & ITEM_FLAG_IN_SHOP) { + if (a2) { + gDungeon->unk644.unk48 -= GetStackBuyPrice(item); + } + } + else { + gDungeon->unk644.unk4C -= GetStackSellPrice(item); + } + } + + tile->object = NULL; + tileObject->type = ENTITY_NOTHING; + + count = 0; + for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { + if (EntityIsValid(gDungeon->items[i])) { + count = i + 1; + } + } + gDungeon->numItems = count; + return TRUE; +} + +s32 sub_8046298(Item *item) +{ + return gItemParametersData[item->id].icon; +} + +extern bool8 sub_8045888(Entity *); + +extern SpriteOAM gUnknown_202EDC0; +extern u8 gUnknown_203B420[]; +extern u8 gUnknown_203B428[]; + +bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) +{ + s32 x, y, y2; + s32 objMode = 0; + + if (!EntityIsValid(entity)) + return FALSE; + + if (a2) { + s32 terrainType = GetTerrainType(GetTile(entity->pos.x, entity->pos.y)); + + if (terrainType == TERRAIN_TYPE_WALL) + return FALSE; + if (terrainType == TERRAIN_TYPE_SECONDARY) { + objMode = 1; + } + + if (!sub_8045888(entity)) + return FALSE; + } + + x = (entity->pixelPos.x / 256) - gDungeon->unk181e8.cameraPixelPos.x; + y = ((entity->pixelPos.y - entity->unk1C.raw) / 256) - gDungeon->unk181e8.cameraPixelPos.y; + y2 = ((entity->pixelPos.y / 256) - gDungeon->unk181e8.cameraPixelPos.y) + 8; + y2 /= 2; + + if (x >= -32 && y >= -32 && x <= 272 && y <= 192) { + s32 tileNum; + + SpriteSetMatrixNum(&gUnknown_202EDC0, 0); + if (a1) { + tileNum = 0x17; + SpriteSetPalNum(&gUnknown_202EDC0, 10); + } + else { + tileNum = sub_8046298(entity->axObj.info.item); + if (a3 != 0xFF && tileNum == 0) { + tileNum = gUnknown_203B420[a3]; + SpriteSetMatrixNum(&gUnknown_202EDC0, gUnknown_203B428[a3] * 8); + } + SpriteSetPalNum(&gUnknown_202EDC0, GetItemPalette(entity->axObj.info.item->id)); + } + + SpriteSetY(&gUnknown_202EDC0, y); + SpriteSetX(&gUnknown_202EDC0, x); + SpriteSetObjMode(&gUnknown_202EDC0, objMode); + SpriteSetPriority(&gUnknown_202EDC0, 3); + SpriteSetTileNum(&gUnknown_202EDC0, 0x1A0 + tileNum * 4); + if (!a4) { + y2 = 1; + } + AddSprite(&gUnknown_202EDC0, y2, NULL, NULL); + return TRUE; + } + + return FALSE; +} + +// diff --git a/src/items.c b/src/items.c index fa898c3b8..69349b080 100644 --- a/src/items.c +++ b/src/items.c @@ -265,7 +265,7 @@ s32 GetItemOrder(u8 id) return gItemParametersData[id].order; } -u8 GetItemPalette(u8 id) +s32 GetItemPalette(u8 id) { return gItemParametersData[id].palette; } From 5b29b421263193a7757fbb00e533099304820e37 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 11 Mar 2025 15:00:49 +0100 Subject: [PATCH 3/8] sub_804652C --- asm/code_8045A00.s | 323 -------------------------------- include/structs/map.h | 2 +- include/structs/str_item_text.h | 13 ++ src/code_8044CC8.c | 13 +- src/code_8045A00.c | 121 ++++++++++++ src/dungeon_action.c | 10 +- 6 files changed, 139 insertions(+), 343 deletions(-) create mode 100644 include/structs/str_item_text.h diff --git a/asm/code_8045A00.s b/asm/code_8045A00.s index 79b0398d7..a64771021 100644 --- a/asm/code_8045A00.s +++ b/asm/code_8045A00.s @@ -6,329 +6,6 @@ .text - thumb_func_start sub_80464AC -sub_80464AC: - push {r4,lr} - ldr r4, _080464C4 - ldrb r0, [r0, 0x2] - bl GetItemActionType - lsls r0, 3 - adds r0, r4 - ldr r0, [r0] - pop {r4} - pop {r1} - bx r1 - .align 2, 0 -_080464C4: .4byte gActions - thumb_func_end sub_80464AC - - thumb_func_start sub_80464C8 -sub_80464C8: - push {r4-r6,lr} - sub sp, 0x78 - adds r6, r0, 0 - adds r3, r1, 0 - adds r5, r2, 0 - movs r0, 0x3 - str r0, [sp, 0x4] - add r0, sp, 0x28 - movs r4, 0 - strb r4, [r0] - add r1, sp, 0x24 - movs r0, 0x1 - strb r0, [r1] - mov r0, sp - adds r0, 0x26 - strb r4, [r0] - str r5, [sp, 0x74] - ldr r0, [r3] - str r0, [sp, 0x8] - movs r1, 0 - ldrsh r0, [r3, r1] - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 3 - adds r1, 0x4 - lsls r1, 8 - movs r2, 0x2 - ldrsh r0, [r3, r2] - lsls r2, r0, 1 - adds r2, r0 - lsls r2, 3 - adds r2, 0x4 - lsls r2, 8 - add r0, sp, 0x4 - bl SetEntityPixelPos - add r0, sp, 0x4 - strh r4, [r0, 0x26] - str r4, [sp] - adds r0, r6, 0 - add r1, sp, 0x4 - adds r2, r5, 0 - movs r3, 0x1 - bl sub_804652C - add sp, 0x78 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80464C8 - - thumb_func_start sub_804652C -sub_804652C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - mov r10, r0 - adds r5, r1, 0 - mov r9, r2 - lsls r3, 24 - lsrs r6, r3, 24 - movs r1, 0x4 - ldrsh r0, [r5, r1] - movs r2, 0x6 - ldrsh r1, [r5, r2] - bl GetTile - adds r4, r0, 0 - ldr r0, [r4, 0x14] - movs r3, 0 - str r3, [sp, 0xC] - cmp r0, 0 - beq _0804658C - bl GetEntityType - cmp r0, 0x2 - bne _0804658C - adds r4, r5, 0x4 - adds r0, r5, 0 - adds r1, r4, 0 - bl sub_8046734 - adds r0, r4, 0 - movs r1, 0x1 - bl sub_807FE44 - ldr r0, _080465A4 - ldr r1, [r0] - mov r0, r10 - bl LogMessageByIdWithPopupCheckUser - mov r0, r9 - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0804658C - b _0804671E -_0804658C: - ldrh r1, [r5, 0x6] - lsls r1, 16 - ldrh r0, [r5, 0x4] - orrs r0, r1 - str r0, [sp] - mov r8, r0 - movs r7, 0x1 - cmp r6, 0 - beq _08046632 - movs r7, 0 - b _08046632 - .align 2, 0 -_080465A4: .4byte gUnknown_80FED30 -_080465A8: - lsls r3, r7, 2 - adds r3, r0 - ldrh r0, [r3] - ldrh r1, [r5, 0x4] - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 - ldr r1, _08046628 - ldr r2, [sp] - ands r2, r1 - orrs r2, r0 - str r2, [sp] - ldrh r0, [r3, 0x2] - ldrh r3, [r5, 0x6] - adds r0, r3 - lsls r0, 16 - ldr r1, _0804662C - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - movs r2, 0 - ldrsh r0, [r0, r2] - asrs r1, 16 - bl GetTile - adds r4, r0, 0 - ldrh r1, [r4] - movs r6, 0x3 - adds r0, r6, 0 - ands r0, r1 - cmp r0, 0 - beq _08046630 - movs r0, 0x80 - lsls r0, 2 - ands r0, r1 - cmp r0, 0 - bne _08046630 - ldr r0, [r4, 0x14] - cmp r0, 0 - bne _08046630 - adds r0, r5, 0 - mov r1, sp - bl sub_8046734 - ldr r3, [sp] - mov r8, r3 - ldrh r1, [r4] - adds r0, r6, 0 - ands r0, r1 - cmp r0, 0x3 - beq _08046620 - mov r0, sp - mov r1, r9 - movs r2, 0x1 - bl sub_80460F8 - lsls r0, 24 - cmp r0, 0 - beq _08046644 -_08046620: - movs r0, 0x1 - str r0, [sp, 0xC] - b _08046644 - .align 2, 0 -_08046628: .4byte 0xffff0000 -_0804662C: .4byte 0x0000ffff -_08046630: - adds r7, 0x1 -_08046632: - ldr r0, _08046688 - lsls r1, r7, 2 - adds r1, r0 - movs r2, 0 - ldrsh r1, [r1, r2] - cmp r1, 0x63 - bne _080465A8 - movs r3, 0 - str r3, [sp, 0xC] -_08046644: - ldr r0, _0804668C - mov r1, r9 - bl sub_8045BF8 - ldr r0, [sp, 0xC] - cmp r0, 0 - beq _080466C8 - mov r0, sp - movs r1, 0 - ldrsh r0, [r0, r1] - mov r4, sp - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl ShowDungeonMapAtPos - mov r0, sp - movs r3, 0 - ldrsh r0, [r0, r3] - movs r2, 0x2 - ldrsh r1, [r4, r2] - bl GetTile - ldrh r0, [r0] - movs r1, 0x3 - ands r1, r0 - adds r0, r1, 0 - cmp r1, 0x1 - beq _0804669A - cmp r1, 0x1 - bgt _08046690 - cmp r1, 0 - beq _080466AC - b _0804671E - .align 2, 0 -_08046688: .4byte gUnknown_80F4468 -_0804668C: .4byte gFormatBuffer_Items -_08046690: - cmp r0, 0x2 - beq _080466A4 - cmp r0, 0x3 - beq _080466B4 - b _0804671E -_0804669A: - ldr r0, _080466A0 - b _080466B6 - .align 2, 0 -_080466A0: .4byte gItemFellOnGround -_080466A4: - ldr r0, _080466A8 - b _080466B6 - .align 2, 0 -_080466A8: .4byte gItemFellInWater -_080466AC: - ldr r0, _080466B0 - b _080466B6 - .align 2, 0 -_080466B0: .4byte gItemBuried -_080466B4: - ldr r0, _080466C4 -_080466B6: - ldr r2, [r0] - mov r0, r10 - mov r1, sp - bl TryDisplayDungeonLoggableMessage5 - b _0804671E - .align 2, 0 -_080466C4: .4byte gItemFellOutOfSight -_080466C8: - mov r3, r8 - lsls r1, r3, 16 - asrs r1, 16 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 11 - movs r1, 0xC0 - lsls r1, 4 - adds r0, r1 - str r0, [sp, 0x4] - asrs r1, r3, 16 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 11 - movs r2, 0xC0 - lsls r2, 4 - adds r0, r2 - add r2, sp, 0x4 - str r0, [r2, 0x4] - ldr r3, [sp, 0x30] - cmp r3, 0 - beq _0804670C - movs r1, 0 - ldrsh r0, [r3, r1] - lsls r0, 8 - ldr r1, [sp, 0x4] - adds r0, r1 - str r0, [sp, 0x4] - movs r1, 0x2 - ldrsh r0, [r3, r1] - lsls r0, 8 - ldr r1, [r2, 0x4] - adds r0, r1 - str r0, [r2, 0x4] -_0804670C: - adds r0, r2, 0 - bl sub_804219C - ldr r0, _08046730 - ldr r2, [r0] - mov r0, r10 - mov r1, sp - bl TryDisplayDungeonLoggableMessage5 -_0804671E: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08046730: .4byte gItemLost - thumb_func_end sub_804652C thumb_func_start sub_8046734 sub_8046734: diff --git a/include/structs/map.h b/include/structs/map.h index b57cb5428..60d83959d 100644 --- a/include/structs/map.h +++ b/include/structs/map.h @@ -113,7 +113,7 @@ static inline void SetTerrainWall(Tile *tile) SetTerrainType(tile, TERRAIN_TYPE_WALL); } -static inline u32 GetTerrainType(const Tile *tile) +static inline s32 GetTerrainType(const Tile *tile) { return tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); } diff --git a/include/structs/str_item_text.h b/include/structs/str_item_text.h new file mode 100644 index 000000000..b1be57cad --- /dev/null +++ b/include/structs/str_item_text.h @@ -0,0 +1,13 @@ +#ifndef GUARD_STR_ITEM_TEXT_H +#define GUARD_STR_ITEM_TEXT_H + +// size: 0x8 +typedef struct ItemText +{ + const u8 *desc; + const u8 *useText; +} ItemText; + +extern const ItemText gActions[]; + +#endif diff --git a/src/code_8044CC8.c b/src/code_8044CC8.c index ee4717edc..e83a382d3 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -5,13 +5,7 @@ #include "dungeon_generation.h" #include "code_8044CC8.h" #include "items.h" - -// size: 0x8 -typedef struct ItemText -{ - u8 *desc; - u8 *useText; -} ItemText; +#include "structs/str_item_text.h" // size: 0x8 typedef struct unkStr_80F7C54 @@ -20,13 +14,10 @@ typedef struct unkStr_80F7C54 u8 *text; } unkStr_80F7C54; - - EWRAM_DATA unkStruct_202EE44 gDungeonSubMenu[10] = {0}; extern s32 gDungeonSubMenuItemsCount; -extern const ItemText gActions[]; extern u16 gUnknown_80F6964[NUM_ITEM_CATEGORIES]; extern u8 gUnknown_80F697C[]; extern u8 *gUnknown_80F7C50[10]; @@ -160,7 +151,7 @@ void sub_8044E24(Entity *entity,int index,u32 unused) } // Similar to sub_8044BA8 -u8 *GetDungeonSubMenuItemString(s32 param_1) +const u8 *GetDungeonSubMenuItemString(s32 param_1) { u16 actionId = gDungeonSubMenu[param_1].actionId; diff --git a/src/code_8045A00.c b/src/code_8045A00.c index aa3be02d8..c84ea6c05 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -8,6 +8,7 @@ #include "dungeon_leader.h" #include "dungeon_message.h" #include "dungeon_music.h" +#include "dungeon_map.h" #include "dungeon_ai_targeting.h" #include "string_format.h" #include "items.h" @@ -16,6 +17,7 @@ #include "structs/str_dungeon.h" #include "trap.h" #include "code_80450F8.h" +#include "structs/str_item_text.h" extern u8 *gUnknown_80FE6F4[]; extern u8 *gPickedUpItemToolbox[]; @@ -96,6 +98,8 @@ void SubstitutePlaceholderStringTags(u8 *buffer, Entity *entity, u32 param_3) } } +// FILE SPLIT HERE + void sub_8045BF8(u8 *buffer, Item *item) { sub_8090E14(buffer, item, &gUnknown_80F699C); @@ -484,4 +488,121 @@ bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) return FALSE; } +const u8 *sub_80464AC(Item *item) +{ + return gActions[GetItemActionType(item->id)].desc; +} + +void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos); + +void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item) +{ + s32 x, y; + Entity itemEntity; + + itemEntity.type = ENTITY_ITEM; + itemEntity.unk24 = 0; + itemEntity.isVisible = TRUE; + itemEntity.unk22 = 0; + itemEntity.axObj.info.item = item; + itemEntity.pos = *pos; + + x = ((pos->x * 24) + 4) << 8; + y = ((pos->y * 24) + 4) << 8; + SetEntityPixelPos(&itemEntity, x, y); + itemEntity.spawnGenID = 0; + sub_804652C(entity, &itemEntity, item, TRUE, NULL); +} + +void sub_8046734(Entity *entity, DungeonPos *pos); + +extern void sub_804219C(PixelPos *pos); + +extern const u8 *const gUnknown_80FED30; +extern const DungeonPos gUnknown_80F4468[]; +extern const u8 *const gItemFellOnGround; +extern const u8 *const gItemLost; +extern const u8 *const gItemFellOutOfSight; +extern const u8 *const gItemFellInWater; +extern const u8 *const gItemBuried; + +void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos) +{ + DungeonPos localPos; + DungeonPos localPos2; + s32 i; + const Tile *tile = GetTile(entity2->pos.x, entity2->pos.y); + Entity *tileObject = tile->object; + bool8 var_24 = FALSE; + + if (tileObject != NULL && GetEntityType(tileObject) == ENTITY_TRAP) { + sub_8046734(entity2, &entity2->pos); + sub_807FE44(&entity2->pos, 1); + LogMessageByIdWithPopupCheckUser(entity1, gUnknown_80FED30); + if (!ItemExists(item)) + return; + } + + localPos.x = entity2->pos.x; + localPos.y = entity2->pos.y; + localPos2 = localPos; + if (a3) { + i = 0; + } + else { + i = 1; + } + + while (1) { + if (gUnknown_80F4468[i].x == 99) { + var_24 = FALSE; + break; + } + localPos.x = entity2->pos.x + gUnknown_80F4468[i].x; + localPos.y = entity2->pos.y + gUnknown_80F4468[i].y; + tile = GetTile(localPos.x, localPos.y); + if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { + sub_8046734(entity2, &localPos); + localPos2 = localPos; + if (GetTerrainType(tile) == (TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL) || (sub_80460F8(&localPos, item, TRUE))) { + var_24 = TRUE; + } + break; + } + i++; + } + + sub_8045BF8(gFormatBuffer_Items[0], item); + if (var_24) { + ShowDungeonMapAtPos(localPos.x, localPos.y); + switch (GetTerrainType(GetTile(localPos.x, localPos.y))) { + case TERRAIN_TYPE_NORMAL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOnGround); + break; + case TERRAIN_TYPE_SECONDARY: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellInWater); + break; + case TERRAIN_TYPE_WALL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemBuried); + break; + case TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOutOfSight); + break; + } + } + else { + PixelPos pixelPos; + + pixelPos.x = X_POS_TO_PIXELPOS(localPos2.x); + pixelPos.y = X_POS_TO_PIXELPOS(localPos2.y); // Intentional or a typo(X vs Y)? + if (pos != NULL) { + pixelPos.x += pos->x << 8; + pixelPos.y += pos->y << 8; + } + + sub_804219C(&pixelPos); + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemLost); + } +} + // diff --git a/src/dungeon_action.c b/src/dungeon_action.c index 54655c2fa..cabeda82d 100644 --- a/src/dungeon_action.c +++ b/src/dungeon_action.c @@ -13,19 +13,13 @@ #include "dungeon_pokemon_attributes.h" #include "pokemon.h" #include "items.h" +#include "structs/str_item_text.h" extern u8 *gUnknown_80F91EC[]; extern u8 *gUnknown_80F7C50[]; extern u8 gUnknown_80F697C[]; extern s16 gSpeedTurns[2][0x19]; -typedef struct ItemText -{ - u8 *desc; - u8 *useText; -} ItemText; -extern const ItemText gActions[]; - extern void sub_8071B48(void); extern void sub_8043ED0(u32); extern u8 GetFloorType(void); @@ -195,7 +189,7 @@ bool8 sub_8044B84(void) } } -u8 *sub_8044BA8(u16 actionId, u8 id) +const u8 *sub_8044BA8(u16 actionId, u8 id) { if (actionId == ACTION_STAIRS && GetFloorType() == FLOOR_TYPE_RESCUE) { return *gUnknown_80F91EC; From d01fcb4b9c4b4dfc0def71aa5ecb468ba45ab210 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Mar 2025 09:49:31 +0100 Subject: [PATCH 4/8] code_8045A00 decompiled --- asm/code_8045A00.s | 705 -------------------------------------------- ld_script.txt | 1 - src/code_8045A00.c | 172 +++++++++++ src/dungeon_items.c | 8 +- 4 files changed, 174 insertions(+), 712 deletions(-) delete mode 100644 asm/code_8045A00.s diff --git a/asm/code_8045A00.s b/asm/code_8045A00.s deleted file mode 100644 index a64771021..000000000 --- a/asm/code_8045A00.s +++ /dev/null @@ -1,705 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - - - thumb_func_start sub_8046734 -sub_8046734: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - mov r8, r0 - ldr r0, _08046858 - ldr r0, [r0] - ldr r2, _0804685C - adds r0, r2 - ldrb r0, [r0] - str r0, [sp, 0xC] - movs r0, 0 - ldrsh r2, [r1, r0] - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 3 - adds r0, 0x4 - lsls r4, r0, 8 - movs r2, 0x2 - ldrsh r1, [r1, r2] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, 0x4 - lsls r5, r0, 8 - mov r1, r8 - ldr r0, [r1, 0xC] - subs r0, r4 - cmp r0, 0 - bge _08046776 - negs r0, r0 -_08046776: - mov r2, r8 - ldr r2, [r2, 0x10] - mov r9, r2 - cmp r0, 0xB - bgt _0804678C - subs r0, r2, r5 - cmp r0, 0 - bge _08046788 - negs r0, r0 -_08046788: - cmp r0, 0xB - ble _08046822 -_0804678C: - movs r0, 0 - mov r10, r0 - movs r1, 0 - str r1, [sp, 0x10] - mov r2, r8 - ldr r0, [r2, 0xC] - str r0, [sp, 0x4] - mov r1, r9 - str r1, [sp, 0x8] - subs r0, r4, r0 - movs r1, 0x18 - bl __divsi3 - adds r6, r0, 0 - mov r2, r9 - subs r0, r5, r2 - movs r1, 0x18 - bl __divsi3 - adds r7, r0, 0 - movs r0, 0 - mov r9, r0 - mov r1, sp - adds r1, 0x4 - str r1, [sp, 0x14] -_080467BE: - ldr r0, [sp, 0x4] - adds r0, r6 - str r0, [sp, 0x4] - ldr r2, [sp, 0x14] - ldr r0, [r2, 0x4] - adds r0, r7 - str r0, [r2, 0x4] - ldr r0, [sp, 0x10] - bl sin_4096 - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - mov r0, r8 - str r1, [r0, 0x1C] - add r1, sp, 0x4 - bl sub_804535C - mov r1, r10 - lsls r3, r1, 24 - lsrs r3, 24 - movs r0, 0 - str r0, [sp] - mov r0, r8 - ldr r1, [sp, 0xC] - movs r2, 0 - bl sub_80462AC - movs r0, 0x13 - bl DungeonRunFrameActions - ldr r2, [sp, 0x10] - adds r2, 0x55 - str r2, [sp, 0x10] - movs r0, 0x3 - mov r1, r9 - ands r0, r1 - cmp r0, 0 - bne _08046810 - movs r2, 0x1 - add r10, r2 -_08046810: - movs r0, 0x7 - mov r1, r10 - ands r1, r0 - mov r10, r1 - movs r2, 0x1 - add r9, r2 - mov r0, r9 - cmp r0, 0x17 - ble _080467BE -_08046822: - mov r0, r8 - adds r1, r4, 0 - adds r2, r5, 0 - bl SetEntityPixelPos - movs r0, 0 - mov r1, r8 - str r0, [r1, 0x1C] - str r0, [sp] - mov r0, r8 - ldr r1, [sp, 0xC] - movs r2, 0x1 - movs r3, 0xFF - bl sub_80462AC - movs r0, 0x13 - bl DungeonRunFrameActions - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08046858: .4byte gDungeon -_0804685C: .4byte 0x00018210 - thumb_func_end sub_8046734 - - thumb_func_start sub_8046860 -sub_8046860: - push {r4,r5,lr} - sub sp, 0x4 - adds r4, r1, 0 - adds r5, r2, 0 - str r3, [sp] - adds r2, r4, 0 - adds r3, r5, 0 - bl sub_804687C - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8046860 - - thumb_func_start sub_804687C -sub_804687C: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _08046970 - add sp, r4 - ldr r5, _08046974 - add r5, sp - str r0, [r5] - movs r0, 0xA5 - lsls r0, 3 - add r0, sp - str r1, [r0] - mov r8, r2 - ldr r1, _08046978 - add r1, sp - str r3, [r1] - movs r1, 0 - movs r7, 0x1D - ldr r0, _0804697C - add r0, sp -_080468A8: - strb r1, [r0] - subs r0, 0x1 - subs r7, 0x1 - cmp r7, 0 - bge _080468A8 - movs r7, 0 - movs r2, 0xAD - lsls r2, 3 - add r2, sp - ldr r2, [r2] - cmp r7, r2 - blt _080468C2 - b _080469DE -_080468C2: - ldr r3, _08046980 - mov r9, r3 - ldr r5, _08046984 - movs r0, 0 - ldrsh r5, [r5, r0] - ldr r0, _08046988 - add r0, sp - str r5, [r0] -_080468D2: - mov r1, r8 - ldrh r0, [r1] - ldr r1, _0804698C - ands r4, r1 - orrs r4, r0 - mov r2, r8 - ldrh r0, [r2, 0x2] - lsls r0, 16 - mov r3, r9 - ands r4, r3 - orrs r4, r0 - movs r5, 0 - adds r0, r7, 0x1 - mov r10, r0 - ldr r1, _08046984 - ldr r2, _08046988 - add r2, sp - ldr r2, [r2] - cmp r2, 0x63 - beq _080469B0 - ldr r3, _08046990 - add r3, sp - ldr r0, _08046994 - add r0, sp - str r3, [r0] -_08046904: - ldr r0, _08046998 - add r0, sp - adds r6, r0, r5 - ldrb r0, [r6] - cmp r0, 0 - bne _0804699C - lsls r2, r5, 2 - adds r2, r1 - ldrh r0, [r2] - mov r1, r8 - ldrh r1, [r1] - adds r0, r1 - lsls r0, 16 - lsrs r0, 16 - ldr r1, _0804698C - ands r4, r1 - orrs r4, r0 - ldrh r0, [r2, 0x2] - mov r2, r8 - ldrh r2, [r2, 0x2] - adds r0, r2 - lsls r0, 16 - mov r3, r9 - ands r4, r3 - orrs r4, r0 - lsls r0, r4, 16 - asrs r0, 16 - asrs r1, r4, 16 - bl GetTile - adds r2, r0, 0 - ldrh r1, [r2] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - beq _0804699C - movs r3, 0x80 - lsls r3, 2 - adds r0, r3, 0 - ands r0, r1 - cmp r0, 0 - bne _0804699C - ldr r0, [r2, 0x14] - cmp r0, 0 - bne _0804699C - lsls r0, r7, 2 - ldr r5, _08046994 - add r5, sp - ldr r5, [r5] - adds r0, r5, r0 - str r4, [r0] - movs r0, 0x1 - strb r0, [r6] - b _080469CE - .align 2, 0 -_08046970: .4byte 0xfffffab8 -_08046974: .4byte 0x00000524 -_08046978: .4byte 0x0000052c -_0804697C: .4byte 0x00000521 -_08046980: .4byte 0x0000ffff -_08046984: .4byte gUnknown_80F4468 -_08046988: .4byte 0x00000534 -_0804698C: .4byte 0xffff0000 -_08046990: .4byte 0x0000048c -_08046994: .4byte 0x00000544 -_08046998: .4byte 0x00000504 -_0804699C: - adds r5, 0x1 - cmp r5, 0x1D - bgt _080469B0 - lsls r0, r5, 2 - ldr r1, _08046A18 - adds r0, r1 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, 0x63 - bne _08046904 -_080469B0: - movs r3, 0 - cmp r3, 0 - bne _080469CE - ldr r1, _08046A1C - add r1, sp - lsls r0, r7, 2 - adds r1, r0 - ldrh r2, [r1] - mov r0, r9 - orrs r0, r2 - strh r0, [r1] - ldrh r2, [r1, 0x2] - mov r0, r9 - orrs r0, r2 - strh r0, [r1, 0x2] -_080469CE: - mov r7, r10 - movs r5, 0xAD - lsls r5, 3 - add r5, sp - ldr r5, [r5] - cmp r7, r5 - bge _080469DE - b _080468D2 -_080469DE: - movs r1, 0 - mov r9, r1 - movs r7, 0 - movs r0, 0xAD - lsls r0, 3 - add r0, sp - ldr r0, [r0] - cmp r7, r0 - blt _080469F2 - b _08046B0A -_080469F2: - movs r2, 0 - mov r8, r2 -_080469F6: - ldr r0, _08046A1C - add r0, sp - lsls r2, r7, 2 - adds r3, r0, r2 - movs r4, 0 - ldrsh r0, [r3, r4] - cmp r0, 0 - bge _08046A20 - movs r0, 0x74 - muls r0, r7 - add r0, sp - adds r0, 0x4 - mov r5, r8 - str r5, [r0] - movs r0, 0x1 - mov r9, r0 - b _08046AFA - .align 2, 0 -_08046A18: .4byte gUnknown_80F4468 -_08046A1C: .4byte 0x0000048c -_08046A20: - movs r0, 0x74 - adds r6, r7, 0 - muls r6, r0 - mov r4, sp - adds r4, r6 - adds r4, 0x4 - movs r0, 0x3 - str r0, [r4] - adds r0, r4, 0 - adds r0, 0x24 - mov r1, r8 - strb r1, [r0] - adds r1, r4, 0 - adds r1, 0x20 - movs r0, 0x1 - strb r0, [r1] - adds r0, r4, 0 - adds r0, 0x22 - mov r5, r8 - strb r5, [r0] - add r0, sp, 0x74 - adds r0, r6 - ldr r1, _08046B2C - add r1, sp - ldr r1, [r1] - adds r2, r1, r2 - str r2, [r0] - add r0, sp, 0x8 - adds r0, r6 - ldr r1, [r3] - str r1, [r0] - movs r2, 0xA5 - lsls r2, 3 - add r2, sp - ldr r2, [r2] - movs r5, 0 - ldrsh r0, [r2, r5] - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 3 - adds r1, 0x4 - lsls r1, 8 - movs r5, 0x2 - ldrsh r0, [r2, r5] - lsls r2, r0, 1 - adds r2, r0 - lsls r2, 3 - adds r2, 0x4 - lsls r2, 8 - adds r0, r4, 0 - movs r5, 0xA8 - lsls r5, 3 - add r5, sp - str r3, [r5] - bl SetEntityPixelPos - mov r0, r8 - strh r0, [r4, 0x26] - ldr r4, _08046B30 - add r4, sp - lsls r5, r7, 3 - adds r4, r5 - movs r1, 0xA8 - lsls r1, 3 - add r1, sp - ldr r3, [r1] - movs r2, 0 - ldrsh r1, [r3, r2] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, 0x4 - lsls r0, 8 - add r1, sp, 0x10 - adds r1, r6 - ldr r1, [r1] - subs r0, r1 - movs r1, 0x18 - movs r2, 0xA8 - lsls r2, 3 - add r2, sp - str r3, [r2] - bl __divsi3 - str r0, [r4] - movs r4, 0x97 - lsls r4, 3 - add r4, sp - adds r4, r5 - movs r5, 0xA8 - lsls r5, 3 - add r5, sp - ldr r3, [r5] - movs r0, 0x2 - ldrsh r1, [r3, r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, 0x4 - lsls r0, 8 - add r1, sp, 0x14 - adds r1, r6 - ldr r1, [r1] - subs r0, r1 - movs r1, 0x18 - bl __divsi3 - str r0, [r4] - movs r1, 0x1 -_08046AFA: - adds r7, 0x1 - movs r2, 0xAD - lsls r2, 3 - add r2, sp - ldr r2, [r2] - cmp r7, r2 - bge _08046B0A - b _080469F6 -_08046B0A: - cmp r1, 0 - bne _08046B54 - movs r3, 0xAD - lsls r3, 3 - add r3, sp - ldr r3, [r3] - cmp r3, 0x1 - ble _08046B3C - ldr r0, _08046B34 - ldr r1, [r0] - ldr r4, _08046B38 - add r4, sp - ldr r0, [r4] - bl LogMessageByIdWithPopupCheckUser - b _08046C7C - .align 2, 0 -_08046B2C: .4byte 0x0000052c -_08046B30: .4byte 0x000004b4 -_08046B34: .4byte gAllItemsLost -_08046B38: .4byte 0x00000524 -_08046B3C: - ldr r0, _08046B4C - ldr r1, [r0] - ldr r5, _08046B50 - add r5, sp - ldr r0, [r5] - bl LogMessageByIdWithPopupCheckUser - b _08046C7C - .align 2, 0 -_08046B4C: .4byte gItemLost -_08046B50: .4byte 0x00000524 -_08046B54: - mov r0, r9 - cmp r0, 0 - beq _08046B68 - ldr r0, _08046C90 - ldr r1, [r0] - ldr r2, _08046C94 - add r2, sp - ldr r0, [r2] - bl LogMessageByIdWithPopupCheckUser -_08046B68: - movs r3, 0 - mov r9, r3 - ldr r0, _08046C98 - ldr r0, [r0] - ldr r4, _08046C9C - adds r0, r4 - ldrb r0, [r0] - movs r5, 0xA6 - lsls r5, 3 - add r5, sp - str r0, [r5] - mov r10, r3 - movs r6, 0 -_08046B82: - movs r7, 0 - mov r0, r10 - adds r0, 0x55 - movs r1, 0xA7 - lsls r1, 3 - add r1, sp - str r0, [r1] - adds r2, r6, 0x1 - ldr r3, _08046CA0 - add r3, sp - str r2, [r3] - movs r4, 0xAD - lsls r4, 3 - add r4, sp - ldr r4, [r4] - cmp r7, r4 - bge _08046C14 - mov r5, r9 - lsls r5, 24 - mov r8, r5 -_08046BAA: - movs r0, 0x74 - adds r5, r7, 0 - muls r5, r0 - mov r4, sp - adds r4, r5 - adds r4, 0x4 - adds r0, r4, 0 - bl EntityIsValid - lsls r0, 24 - cmp r0, 0 - beq _08046C06 - ldr r0, _08046CA4 - add r0, sp - lsls r2, r7, 3 - adds r0, r2 - ldr r1, [r0] - movs r0, 0x97 - lsls r0, 3 - add r0, sp - adds r0, r2 - ldr r2, [r0] - adds r0, r4, 0 - bl IncreaseEntityPixelPos - mov r0, r10 - bl sin_4096 - add r2, sp, 0x20 - adds r2, r5 - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - str r1, [r2] - movs r0, 0 - str r0, [sp] - adds r0, r4, 0 - movs r2, 0xA6 - lsls r2, 3 - add r2, sp - ldr r1, [r2] - movs r2, 0x1 - mov r4, r8 - lsrs r3, r4, 24 - bl sub_80462AC -_08046C06: - adds r7, 0x1 - movs r5, 0xAD - lsls r5, 3 - add r5, sp - ldr r5, [r5] - cmp r7, r5 - blt _08046BAA -_08046C14: - movs r0, 0x13 - bl DungeonRunFrameActions - movs r0, 0xA7 - lsls r0, 3 - add r0, sp - ldr r0, [r0] - mov r10, r0 - movs r0, 0x3 - ands r0, r6 - cmp r0, 0 - bne _08046C30 - movs r1, 0x1 - add r9, r1 -_08046C30: - movs r0, 0x7 - mov r2, r9 - ands r2, r0 - mov r9, r2 - ldr r3, _08046CA0 - add r3, sp - ldr r6, [r3] - cmp r6, 0x17 - ble _08046B82 - movs r4, 0xAD - lsls r4, 3 - add r4, sp - ldr r4, [r4] - cmp r4, 0 - ble _08046C7C - ldr r0, _08046CA8 - add r0, sp - ldr r5, [r0] - ldr r4, _08046CAC - add r4, sp - movs r1, 0xAD - lsls r1, 3 - add r1, sp - ldr r7, [r1] -_08046C60: - movs r2, 0 - ldrsh r0, [r4, r2] - cmp r0, 0 - blt _08046C72 - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0x1 - bl sub_80460F8 -_08046C72: - adds r5, 0x4 - adds r4, 0x4 - subs r7, 0x1 - cmp r7, 0 - bne _08046C60 -_08046C7C: - movs r3, 0xA9 - lsls r3, 3 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08046C90: .4byte gSeveralItemsLost -_08046C94: .4byte 0x00000524 -_08046C98: .4byte gDungeon -_08046C9C: .4byte 0x00018210 -_08046CA0: .4byte 0x0000053c -_08046CA4: .4byte 0x000004b4 -_08046CA8: .4byte 0x0000052c -_08046CAC: .4byte 0x0000048c - thumb_func_end sub_804687C - - .align 2, 0 diff --git a/ld_script.txt b/ld_script.txt index 2ae9cabea..e1d58f851 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -210,7 +210,6 @@ SECTIONS { src/code_80450F8.o(.text); src/dungeon_visibility.o(.text); src/code_8045A00.o(.text); - asm/code_8045A00.o(.text); src/dungeon_items.o(.text); asm/code_8046CE4.o(.text); src/code_8048480.o(.text); diff --git a/src/code_8045A00.c b/src/code_8045A00.c index c84ea6c05..497396ad6 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -16,7 +16,9 @@ #include "structs/map.h" #include "structs/str_dungeon.h" #include "trap.h" +#include "math.h" #include "code_80450F8.h" +#include "dungeon_util.h" #include "structs/str_item_text.h" extern u8 *gUnknown_80FE6F4[]; @@ -605,4 +607,174 @@ void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, Dungeon } } +extern void DungeonRunFrameActions(u32); + +void sub_8046734(Entity *entity, DungeonPos *pos) +{ + PixelPos posPixel; + PixelPos calcPixelPos; + bool8 hallucinating = gDungeon->unk181e8.hallucinating; + + posPixel.x = ((pos->x * 24) + 4) << 8; + posPixel.y = ((pos->y * 24) + 4) << 8; + if (abs(entity->pixelPos.x - posPixel.x) > 11 || abs(entity->pixelPos.y - posPixel.y) > 11) { + s32 i; + PixelPos add; + s32 unk = 0; // Direction? + s32 sinVal = 0; + + calcPixelPos.x = entity->pixelPos.x; + calcPixelPos.y = entity->pixelPos.y; + + add.x = (posPixel.x - calcPixelPos.x) / 24; + add.y = (posPixel.y - calcPixelPos.y) / 24; + for (i = 0; i < 24; i++) { + calcPixelPos.x += add.x; + calcPixelPos.y += add.y; + entity->unk1C.raw = sin_4096(sinVal) * 12; + sub_804535C(entity, &calcPixelPos); + sub_80462AC(entity, hallucinating, 0, unk, 0); + DungeonRunFrameActions(0x13); + sinVal += 85; + if ((i & 3) == 0) { + unk++; + } + unk &= 7; + } + } + + SetEntityPixelPos(entity, posPixel.x, posPixel.y); + entity->unk1C.raw = 0; + sub_80462AC(entity, hallucinating, 1, 0xFF, 0); + DungeonRunFrameActions(0x13); +} + +extern void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 a4); + +void sub_8046860(Entity *entity, DungeonPos *pos, Item *item, s32 a4) +{ + sub_804687C(entity, pos, pos, item, a4); +} + +extern const u8 *gSeveralItemsLost; +extern const u8 *gItemLost; +extern const u8 *gAllItemsLost; + +void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 count) +{ + Entity itemEntities[10]; + DungeonPos targetTilePos[10]; + PixelPos itemVelocity[10]; + u8 targetTileUsed[30]; + s32 sinVal; + s32 i; + bool8 r1, r9; + + for (i = 0; i < 30; i++) { + targetTileUsed[i] = 0; + } + + for (i = 0; i < count; i++) { + s32 j; + bool8 foundTile = FALSE; + DungeonPos pos; + + pos.x = pos2->x; + pos.y = pos2->y; + + for (j = 0; j < 30; j++) { + if (gUnknown_80F4468[j].x == 99) + break; + if (!targetTileUsed[j]) { + const Tile *tile; + + pos.x = pos2->x + gUnknown_80F4468[j].x; + pos.y = pos2->y + gUnknown_80F4468[j].y; + + tile = GetTile(pos.x, pos.y); + if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { + targetTilePos[i] = pos; + targetTileUsed[j] = TRUE; + foundTile = TRUE; + break; + } + } + } + + if (!foundTile) { + targetTilePos[i].x = -1; + targetTilePos[i].y = -1; + } + } + + r1 = FALSE; + r9 = FALSE; + for (i = 0; i < count; i++) { + if (targetTilePos[i].x < 0) { + itemEntities[i].type = ENTITY_NOTHING; + r9 = TRUE; + } + else { + s32 x, y; + + itemEntities[i].type = ENTITY_ITEM; + itemEntities[i].unk24 = 0; + itemEntities[i].isVisible = TRUE; + itemEntities[i].unk22 = 0; + itemEntities[i].axObj.info.item = &item[i]; + itemEntities[i].pos = targetTilePos[i]; + x = ((pos1->x * 24) + 4) << 8; + y = ((pos1->y * 24) + 4) << 8; + SetEntityPixelPos(&itemEntities[i], x, y); + itemEntities[i].spawnGenID = 0; + itemVelocity[i].x = ((((targetTilePos[i].x * 24) + 4) << 8) - (itemEntities[i].pixelPos.x)) / 24; + itemVelocity[i].y = ((((targetTilePos[i].y * 24) + 4) << 8) - (itemEntities[i].pixelPos.y)) / 24; + r1 = TRUE; + } + } + + if (!r1) { + if (count > 1) { + LogMessageByIdWithPopupCheckUser(entity, gAllItemsLost); + } + else { + LogMessageByIdWithPopupCheckUser(entity, gItemLost); + } + } + else { + s32 counter; + s32 dirMaybe; + bool8 hallucinating; + + if (r9) { + LogMessageByIdWithPopupCheckUser(entity, gSeveralItemsLost); + } + + dirMaybe = 0; + hallucinating = gDungeon->unk181e8.hallucinating; + sinVal = 0; + for (counter = 0; counter < 24; counter++) { + for (i = 0; i < count; i++) { + if (EntityIsValid(&itemEntities[i])) { + IncreaseEntityPixelPos(&itemEntities[i], itemVelocity[i].x, itemVelocity[i].y); + itemEntities[i].unk1C.raw = sin_4096(sinVal) * 12; + sub_80462AC(&itemEntities[i], hallucinating, 1, dirMaybe, 0); + } + } + DungeonRunFrameActions(0x13); + sinVal += 85; + if ((counter & 3) == 0) { + dirMaybe++; + } + dirMaybe &= 7; + } + + for (i = 0; i < count; i++) { + if (targetTilePos[i].x >= 0) { + sub_80460F8(&targetTilePos[i], &item[i], TRUE); + } + } + } +} + // diff --git a/src/dungeon_items.c b/src/dungeon_items.c index 1d894a191..d9bcbddf8 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -292,15 +292,11 @@ void sub_8047104(void) if(item->id == ITEM_POKE) { AddToTeamMoney(GetMoneyValue(item)); - item->id = 0; - item->quantity = 0; - item->flags = 0; + ZeroOutItem(item); } if(item->flags & ITEM_FLAG_IN_SHOP) { - item->id = 0; - item->quantity = 0; - item->flags = 0; + ZeroOutItem(item); } } } From d2db84ae73b08531e5fa6901a5d1977687364ffc Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Mar 2025 10:27:27 +0100 Subject: [PATCH 5/8] move to dungeon_items.c --- src/code_8045A00.c | 690 +---------------------------- src/dungeon_items.c | 1031 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 848 insertions(+), 873 deletions(-) diff --git a/src/code_8045A00.c b/src/code_8045A00.c index 497396ad6..cc9756af5 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -21,21 +21,9 @@ #include "dungeon_util.h" #include "structs/str_item_text.h" -extern u8 *gUnknown_80FE6F4[]; -extern u8 *gPickedUpItemToolbox[]; -extern u8 *gMonTerrifiedCouldntPickUpItem[]; -extern u8 *gPickedUpItem2[]; -extern u8 *gMonCouldntPickUpItem[]; -extern u8 *gPickedUpItem[]; -extern u8 *gMonSteppedOnItem[]; -extern struct unkStruct_8090F58 gUnknown_80F699C; -extern struct unkStruct_8090F58 gUnknown_80F69A8; -extern struct unkStruct_8090F58 gUnknown_80F6990; - -bool8 sub_80461C8(DungeonPos *, bool8); void sub_8045BF8(u8 *, Item *); -extern u32 sub_803D73C(u32); -bool8 sub_80460F8(DungeonPos *, Item *, bool8); + +extern u8 *gUnknown_80FE6F4[]; void sub_8045ACC(void) { @@ -102,679 +90,5 @@ void SubstitutePlaceholderStringTags(u8 *buffer, Entity *entity, u32 param_3) // FILE SPLIT HERE -void sub_8045BF8(u8 *buffer, Item *item) -{ - sub_8090E14(buffer, item, &gUnknown_80F699C); -} - -void sub_8045C08(u8 *buffer, Item *item) -{ - sub_8090E14(buffer, item, &gUnknown_80F69A8); -} - -void sub_8045C18(u8 *buffer, Item *item) -{ - sub_8090E14(buffer, item, &gUnknown_80F6990); -} - -void sub_8045C28(Item *item, u8 itemID, u32 param_3) -{ - bool8 stickyFlag; - - xxx_init_itemslot_8090A8C(item,itemID,0); - stickyFlag = FALSE; - if (IsNotSpecialItem(itemID)) { - if (param_3 == 0) { - if (DungeonRandInt(100) < gDungeon->unk1C574.unkA) - stickyFlag = TRUE; - else - stickyFlag = FALSE; - } - else if (param_3 == 1) { - stickyFlag = TRUE; - } - } - if (stickyFlag) { - item->flags |= ITEM_FLAG_STICKY; - } - - if (GetItemCategory(itemID) == CATEGORY_POKE) { - sub_8046CE4(item, gDungeon->unk1C574.unk17 * 40); - } -} - -void sub_8045CB0(void) -{ - u8 itemID; - s32 yCounter, xCounter; - const Tile *tile; - u32 uVar5; - Item item; - u32 flag; - s32 x = DungeonRandInt(DUNGEON_MAX_SIZE_X); - s32 y = DungeonRandInt(DUNGEON_MAX_SIZE_Y); - - gDungeon->numItems = 0; - for (yCounter = 0; yCounter < DUNGEON_MAX_SIZE_Y; yCounter++) { - y++; - if (y == DUNGEON_MAX_SIZE_Y) { - y = 0; - } - - for (xCounter = 0; xCounter < DUNGEON_MAX_SIZE_X; xCounter++) { - x++; - flag = ITEM_FLAG_IN_SHOP; - if (x == DUNGEON_MAX_SIZE_X) { - x = 0; - } - tile = GetTile(x,y); - - if (!(tile->terrainType & TERRAIN_TYPE_STAIRS) && (tile->spawnOrVisibilityFlags & 2)) { - DungeonPos pos; - bool8 shopFlag = FALSE; - pos.x = x; - pos.y = y; - - if (tile->terrainType & TERRAIN_TYPE_SHOP) { - shopFlag = TRUE; - uVar5 = 1; - } - else - { - if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { - uVar5 = 3; - } - else { - uVar5 = (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) ? 2 : 0; - } - } - itemID = sub_803D73C(uVar5); - if (!CanSellItem(itemID)) { - shopFlag = 0; - } - sub_8045C28(&item,itemID,0); - if (shopFlag) { - item.flags |= flag; - } - sub_80460F8(&pos,&item,TRUE); - } - } - } -} - -void sub_8045DB4(struct DungeonPos *pos, bool8 printMsg) -{ - Item *tileItem; - int inventoryIds[INVENTORY_SIZE + 1]; - Item *inventoryItems[INVENTORY_SIZE + 1]; - Entity *leader = GetLeader(); - EntityInfo *leaderInfo = GetEntInfo(leader); - const Tile *tile = GetTile(pos->x,pos->y); - Entity *tileObject = tile->object; - if (tileObject == NULL) { - return; - } - if (GetEntityType(tileObject) != ENTITY_ITEM) { - return; - } - tileItem = GetItemData(tileObject); - if (leaderInfo->action.actionParameters[0].actionUseIndex == 0) { - if (!printMsg) { - return; - } - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); - LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); - } - else if (ShouldMonsterRunAwayAndShowEffect(leader,1)) { - if (!printMsg) { - return; - } - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); - LogMessageByIdWithPopupCheckUser(leader,*gMonTerrifiedCouldntPickUpItem); - } - else if (GetItemCategory(tileItem->id) == CATEGORY_POKE) { - PlaySoundEffect(0x14c); - AddToTeamMoney(GetMoneyValue(tileItem)); - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); - LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem); - TryDisplayItemPickupTutorialMessage(tileItem->id); - } - else { - s32 i, maxItems; - if (gDungeon->unk644.unk17 != 0) { - for (i = 0; i < INVENTORY_SIZE; i++) { - inventoryItems[i] = &gTeamInventoryRef->teamItems[i]; - inventoryIds[i] = i; - } - maxItems = INVENTORY_SIZE; - } - else { - inventoryItems[0] = &leaderInfo->heldItem; - inventoryIds[0] = -1; - maxItems = 1; - } - - if (tileItem->id <= ITEM_GEO_PEBBLE && !(tileItem->flags & ITEM_FLAG_IN_SHOP)) { - s32 index = -1; - s32 numberItems = -1; - s32 i; - - for (i = 0; i < maxItems; i++) { - if (ItemExists(inventoryItems[i]) - && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) - && (tileItem->id == inventoryItems[i]->id) - && (tileItem->flags & ITEM_FLAG_STICKY) == (inventoryItems[i]->flags & ITEM_FLAG_STICKY) - && inventoryItems[i]->quantity != 99 - && numberItems < inventoryItems[i]->quantity) - { - numberItems = inventoryItems[i]->quantity; - index = i; - } - } - - if (index == -1) { - s32 i; - - numberItems = -1; - for (i = 0; i < maxItems; i++) { - if (ItemExists(inventoryItems[i]) - && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) - && tileItem->id == inventoryItems[i]->id - && inventoryItems[i]->quantity != 99 - && numberItems < inventoryItems[i]->quantity) - { - numberItems = inventoryItems[i]->quantity; - index = i; - } - } - } - - if (index != -1) { - struct Item *addedItem = inventoryItems[index]; - s32 newQuantity = addedItem->quantity + tileItem->quantity; - - if (newQuantity >= 99) { - newQuantity = 99; - } - addedItem->quantity = newQuantity; - - if (tileItem->flags & ITEM_FLAG_STICKY) { - inventoryItems[index]->flags |= ITEM_FLAG_STICKY; - } - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); - PlaySoundEffect(0x14a); - if (inventoryIds[index] < 0) { - LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); - } - else { - LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); - } - TryDisplayItemPickupTutorialMessage(tileItem->id); - return; - } - } - - for (i = 0; i < maxItems; i++) { - if (!ItemExists(inventoryItems[i])) - break; - } - - if (i == maxItems) { - if (!printMsg) { - return; - } - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); - LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); - } - else { - PlaySoundEffect(0x14a); - if (inventoryIds[i] < 0) { - leaderInfo->heldItem = *tileItem; - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); - LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); - } - else if (AddItemToInventory(tileItem) != 0) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); - LogMessageByIdWithPopupCheckUser(leader,*gMonCouldntPickUpItem); - } - else { - sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); - LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); - } - TryDisplayItemPickupTutorialMessage(tileItem->id); - } - } -} - -bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) -{ - s32 i, count; - Tile *tile; - Entity *entity = sub_8045708(pos); - - if (entity == NULL) - return FALSE; - *entity->axObj.info.item = *item; - entity->axObj.info.item->flags &= ~(ITEM_FLAG_SET); - entity->isVisible = TRUE; - tile = GetTileMut(pos->x, pos->y); - tile->object = entity; - if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { - if (item->flags & ITEM_FLAG_IN_SHOP) { - if (a2) { - gDungeon->unk644.unk48 += GetStackBuyPrice(item); - } - } - else { - gDungeon->unk644.unk4C += GetStackSellPrice(item); - } - } - - count = 0; - for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { - if (EntityIsValid(gDungeon->items[i])) { - count = i + 1; - } - } - gDungeon->numItems = count; - return TRUE; -} - -bool8 sub_80461C8(DungeonPos *pos, bool8 a2) -{ - s32 i, count; - Item *item; - Tile *tile = GetTileMut(pos->x, pos->y); - Entity *tileObject = tile->object; - if (tileObject == NULL || GetEntityType(tileObject) != ENTITY_ITEM) - return FALSE; - - item = GetItemData(tileObject); - if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { - if (item->flags & ITEM_FLAG_IN_SHOP) { - if (a2) { - gDungeon->unk644.unk48 -= GetStackBuyPrice(item); - } - } - else { - gDungeon->unk644.unk4C -= GetStackSellPrice(item); - } - } - - tile->object = NULL; - tileObject->type = ENTITY_NOTHING; - - count = 0; - for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { - if (EntityIsValid(gDungeon->items[i])) { - count = i + 1; - } - } - gDungeon->numItems = count; - return TRUE; -} - -s32 sub_8046298(Item *item) -{ - return gItemParametersData[item->id].icon; -} - -extern bool8 sub_8045888(Entity *); - -extern SpriteOAM gUnknown_202EDC0; -extern u8 gUnknown_203B420[]; -extern u8 gUnknown_203B428[]; - -bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) -{ - s32 x, y, y2; - s32 objMode = 0; - - if (!EntityIsValid(entity)) - return FALSE; - - if (a2) { - s32 terrainType = GetTerrainType(GetTile(entity->pos.x, entity->pos.y)); - - if (terrainType == TERRAIN_TYPE_WALL) - return FALSE; - if (terrainType == TERRAIN_TYPE_SECONDARY) { - objMode = 1; - } - - if (!sub_8045888(entity)) - return FALSE; - } - - x = (entity->pixelPos.x / 256) - gDungeon->unk181e8.cameraPixelPos.x; - y = ((entity->pixelPos.y - entity->unk1C.raw) / 256) - gDungeon->unk181e8.cameraPixelPos.y; - y2 = ((entity->pixelPos.y / 256) - gDungeon->unk181e8.cameraPixelPos.y) + 8; - y2 /= 2; - - if (x >= -32 && y >= -32 && x <= 272 && y <= 192) { - s32 tileNum; - - SpriteSetMatrixNum(&gUnknown_202EDC0, 0); - if (a1) { - tileNum = 0x17; - SpriteSetPalNum(&gUnknown_202EDC0, 10); - } - else { - tileNum = sub_8046298(entity->axObj.info.item); - if (a3 != 0xFF && tileNum == 0) { - tileNum = gUnknown_203B420[a3]; - SpriteSetMatrixNum(&gUnknown_202EDC0, gUnknown_203B428[a3] * 8); - } - SpriteSetPalNum(&gUnknown_202EDC0, GetItemPalette(entity->axObj.info.item->id)); - } - - SpriteSetY(&gUnknown_202EDC0, y); - SpriteSetX(&gUnknown_202EDC0, x); - SpriteSetObjMode(&gUnknown_202EDC0, objMode); - SpriteSetPriority(&gUnknown_202EDC0, 3); - SpriteSetTileNum(&gUnknown_202EDC0, 0x1A0 + tileNum * 4); - if (!a4) { - y2 = 1; - } - AddSprite(&gUnknown_202EDC0, y2, NULL, NULL); - return TRUE; - } - - return FALSE; -} - -const u8 *sub_80464AC(Item *item) -{ - return gActions[GetItemActionType(item->id)].desc; -} - -void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos); - -void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item) -{ - s32 x, y; - Entity itemEntity; - - itemEntity.type = ENTITY_ITEM; - itemEntity.unk24 = 0; - itemEntity.isVisible = TRUE; - itemEntity.unk22 = 0; - itemEntity.axObj.info.item = item; - itemEntity.pos = *pos; - - x = ((pos->x * 24) + 4) << 8; - y = ((pos->y * 24) + 4) << 8; - SetEntityPixelPos(&itemEntity, x, y); - itemEntity.spawnGenID = 0; - sub_804652C(entity, &itemEntity, item, TRUE, NULL); -} - -void sub_8046734(Entity *entity, DungeonPos *pos); - -extern void sub_804219C(PixelPos *pos); - -extern const u8 *const gUnknown_80FED30; -extern const DungeonPos gUnknown_80F4468[]; -extern const u8 *const gItemFellOnGround; -extern const u8 *const gItemLost; -extern const u8 *const gItemFellOutOfSight; -extern const u8 *const gItemFellInWater; -extern const u8 *const gItemBuried; - -void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos) -{ - DungeonPos localPos; - DungeonPos localPos2; - s32 i; - const Tile *tile = GetTile(entity2->pos.x, entity2->pos.y); - Entity *tileObject = tile->object; - bool8 var_24 = FALSE; - - if (tileObject != NULL && GetEntityType(tileObject) == ENTITY_TRAP) { - sub_8046734(entity2, &entity2->pos); - sub_807FE44(&entity2->pos, 1); - LogMessageByIdWithPopupCheckUser(entity1, gUnknown_80FED30); - if (!ItemExists(item)) - return; - } - - localPos.x = entity2->pos.x; - localPos.y = entity2->pos.y; - localPos2 = localPos; - if (a3) { - i = 0; - } - else { - i = 1; - } - - while (1) { - if (gUnknown_80F4468[i].x == 99) { - var_24 = FALSE; - break; - } - localPos.x = entity2->pos.x + gUnknown_80F4468[i].x; - localPos.y = entity2->pos.y + gUnknown_80F4468[i].y; - tile = GetTile(localPos.x, localPos.y); - if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { - sub_8046734(entity2, &localPos); - localPos2 = localPos; - if (GetTerrainType(tile) == (TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL) || (sub_80460F8(&localPos, item, TRUE))) { - var_24 = TRUE; - } - break; - } - i++; - } - - sub_8045BF8(gFormatBuffer_Items[0], item); - if (var_24) { - ShowDungeonMapAtPos(localPos.x, localPos.y); - switch (GetTerrainType(GetTile(localPos.x, localPos.y))) { - case TERRAIN_TYPE_NORMAL: - TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOnGround); - break; - case TERRAIN_TYPE_SECONDARY: - TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellInWater); - break; - case TERRAIN_TYPE_WALL: - TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemBuried); - break; - case TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL: - TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOutOfSight); - break; - } - } - else { - PixelPos pixelPos; - - pixelPos.x = X_POS_TO_PIXELPOS(localPos2.x); - pixelPos.y = X_POS_TO_PIXELPOS(localPos2.y); // Intentional or a typo(X vs Y)? - if (pos != NULL) { - pixelPos.x += pos->x << 8; - pixelPos.y += pos->y << 8; - } - - sub_804219C(&pixelPos); - TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemLost); - } -} - -extern void DungeonRunFrameActions(u32); - -void sub_8046734(Entity *entity, DungeonPos *pos) -{ - PixelPos posPixel; - PixelPos calcPixelPos; - bool8 hallucinating = gDungeon->unk181e8.hallucinating; - - posPixel.x = ((pos->x * 24) + 4) << 8; - posPixel.y = ((pos->y * 24) + 4) << 8; - if (abs(entity->pixelPos.x - posPixel.x) > 11 || abs(entity->pixelPos.y - posPixel.y) > 11) { - s32 i; - PixelPos add; - s32 unk = 0; // Direction? - s32 sinVal = 0; - - calcPixelPos.x = entity->pixelPos.x; - calcPixelPos.y = entity->pixelPos.y; - - add.x = (posPixel.x - calcPixelPos.x) / 24; - add.y = (posPixel.y - calcPixelPos.y) / 24; - for (i = 0; i < 24; i++) { - calcPixelPos.x += add.x; - calcPixelPos.y += add.y; - entity->unk1C.raw = sin_4096(sinVal) * 12; - sub_804535C(entity, &calcPixelPos); - sub_80462AC(entity, hallucinating, 0, unk, 0); - DungeonRunFrameActions(0x13); - sinVal += 85; - if ((i & 3) == 0) { - unk++; - } - unk &= 7; - } - } - - SetEntityPixelPos(entity, posPixel.x, posPixel.y); - entity->unk1C.raw = 0; - sub_80462AC(entity, hallucinating, 1, 0xFF, 0); - DungeonRunFrameActions(0x13); -} - -extern void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 a4); - -void sub_8046860(Entity *entity, DungeonPos *pos, Item *item, s32 a4) -{ - sub_804687C(entity, pos, pos, item, a4); -} - -extern const u8 *gSeveralItemsLost; -extern const u8 *gItemLost; -extern const u8 *gAllItemsLost; - -void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 count) -{ - Entity itemEntities[10]; - DungeonPos targetTilePos[10]; - PixelPos itemVelocity[10]; - u8 targetTileUsed[30]; - s32 sinVal; - s32 i; - bool8 r1, r9; - - for (i = 0; i < 30; i++) { - targetTileUsed[i] = 0; - } - - for (i = 0; i < count; i++) { - s32 j; - bool8 foundTile = FALSE; - DungeonPos pos; - - pos.x = pos2->x; - pos.y = pos2->y; - - for (j = 0; j < 30; j++) { - if (gUnknown_80F4468[j].x == 99) - break; - if (!targetTileUsed[j]) { - const Tile *tile; - - pos.x = pos2->x + gUnknown_80F4468[j].x; - pos.y = pos2->y + gUnknown_80F4468[j].y; - - tile = GetTile(pos.x, pos.y); - if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { - targetTilePos[i] = pos; - targetTileUsed[j] = TRUE; - foundTile = TRUE; - break; - } - } - } - - if (!foundTile) { - targetTilePos[i].x = -1; - targetTilePos[i].y = -1; - } - } - - r1 = FALSE; - r9 = FALSE; - for (i = 0; i < count; i++) { - if (targetTilePos[i].x < 0) { - itemEntities[i].type = ENTITY_NOTHING; - r9 = TRUE; - } - else { - s32 x, y; - - itemEntities[i].type = ENTITY_ITEM; - itemEntities[i].unk24 = 0; - itemEntities[i].isVisible = TRUE; - itemEntities[i].unk22 = 0; - itemEntities[i].axObj.info.item = &item[i]; - itemEntities[i].pos = targetTilePos[i]; - x = ((pos1->x * 24) + 4) << 8; - y = ((pos1->y * 24) + 4) << 8; - SetEntityPixelPos(&itemEntities[i], x, y); - itemEntities[i].spawnGenID = 0; - itemVelocity[i].x = ((((targetTilePos[i].x * 24) + 4) << 8) - (itemEntities[i].pixelPos.x)) / 24; - itemVelocity[i].y = ((((targetTilePos[i].y * 24) + 4) << 8) - (itemEntities[i].pixelPos.y)) / 24; - r1 = TRUE; - } - } - - if (!r1) { - if (count > 1) { - LogMessageByIdWithPopupCheckUser(entity, gAllItemsLost); - } - else { - LogMessageByIdWithPopupCheckUser(entity, gItemLost); - } - } - else { - s32 counter; - s32 dirMaybe; - bool8 hallucinating; - - if (r9) { - LogMessageByIdWithPopupCheckUser(entity, gSeveralItemsLost); - } - - dirMaybe = 0; - hallucinating = gDungeon->unk181e8.hallucinating; - sinVal = 0; - for (counter = 0; counter < 24; counter++) { - for (i = 0; i < count; i++) { - if (EntityIsValid(&itemEntities[i])) { - IncreaseEntityPixelPos(&itemEntities[i], itemVelocity[i].x, itemVelocity[i].y); - itemEntities[i].unk1C.raw = sin_4096(sinVal) * 12; - sub_80462AC(&itemEntities[i], hallucinating, 1, dirMaybe, 0); - } - } - DungeonRunFrameActions(0x13); - sinVal += 85; - if ((counter & 3) == 0) { - dirMaybe++; - } - dirMaybe &= 7; - } - - for (i = 0; i < count; i++) { - if (targetTilePos[i].x >= 0) { - sub_80460F8(&targetTilePos[i], &item[i], TRUE); - } - } - } -} // diff --git a/src/dungeon_items.c b/src/dungeon_items.c index d9bcbddf8..19df08df7 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -1,6 +1,5 @@ #include "global.h" #include "dungeon_items.h" - #include "code_803E668.h" #include "code_8041AD0.h" #include "code_8045A00.h" @@ -12,6 +11,20 @@ #include "dungeon_util.h" #include "pokemon.h" #include "structs/str_dungeon.h" +#include "constants/item.h" +#include "dungeon_map_access.h" +#include "dungeon_message.h" +#include "dungeon_music.h" +#include "dungeon_map.h" +#include "dungeon_ai_targeting.h" +#include "string_format.h" +#include "items.h" +#include "status_checks_1.h" +#include "structs/map.h" +#include "trap.h" +#include "math.h" +#include "code_80450F8.h" +#include "structs/str_item_text.h" extern s32 gUnknown_810A3F0[]; extern u8 *gUnknown_80FA408[]; @@ -19,30 +32,706 @@ extern u8 *gUnknown_810531C[]; extern u8 *gUnknown_8105360[]; extern u8 *gUnknown_81053A8[]; extern u8 *gUnknown_8105434[]; +extern u8 *gPickedUpItemToolbox[]; +extern u8 *gMonTerrifiedCouldntPickUpItem[]; +extern u8 *gPickedUpItem2[]; +extern u8 *gMonCouldntPickUpItem[]; +extern u8 *gPickedUpItem[]; +extern u8 *gMonSteppedOnItem[]; +extern struct unkStruct_8090F58 gUnknown_80F699C; +extern struct unkStruct_8090F58 gUnknown_80F69A8; +extern struct unkStruct_8090F58 gUnknown_80F6990; +extern const u8 *const gUnknown_80FED30; +extern const DungeonPos gUnknown_80F4468[]; +extern const u8 *const gItemFellOnGround; +extern const u8 *const gItemLost; +extern const u8 *const gItemFellOutOfSight; +extern const u8 *const gItemFellInWater; +extern const u8 *const gItemBuried; +extern const u8 *gSeveralItemsLost; +extern const u8 *gItemLost; +extern const u8 *gAllItemsLost; extern void sub_80416E0(PixelPos *r0, u32, bool8); extern void sub_80855E4(void *); extern void PlaySoundEffect(u32); extern void sub_804178C(u32); -extern void ShowWholeRevealedDungeonMap(void); +extern void sub_804219C(PixelPos *pos); +extern void DungeonRunFrameActions(u32); +extern bool8 sub_8045888(Entity *); static void MusicBoxCreation(void); static u8 sub_8046D70(void); +extern SpriteOAM gUnknown_202EDC0; +extern u8 gUnknown_203B420[]; +extern u8 gUnknown_203B428[]; + +void sub_8046734(Entity *entity, DungeonPos *pos); +void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 a4); +void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos); +bool8 sub_80461C8(DungeonPos *, bool8); +extern u32 sub_803D73C(u32); +bool8 sub_80460F8(DungeonPos *, Item *, bool8); + +void sub_8045BF8(u8 *buffer, Item *item) +{ + sub_8090E14(buffer, item, &gUnknown_80F699C); +} + +void sub_8045C08(u8 *buffer, Item *item) +{ + sub_8090E14(buffer, item, &gUnknown_80F69A8); +} + +void sub_8045C18(u8 *buffer, Item *item) +{ + sub_8090E14(buffer, item, &gUnknown_80F6990); +} + +void sub_8045C28(Item *item, u8 itemID, u32 param_3) +{ + bool8 stickyFlag; + + xxx_init_itemslot_8090A8C(item,itemID,0); + stickyFlag = FALSE; + if (IsNotSpecialItem(itemID)) { + if (param_3 == 0) { + if (DungeonRandInt(100) < gDungeon->unk1C574.unkA) + stickyFlag = TRUE; + else + stickyFlag = FALSE; + } + else if (param_3 == 1) { + stickyFlag = TRUE; + } + } + if (stickyFlag) { + item->flags |= ITEM_FLAG_STICKY; + } + + if (GetItemCategory(itemID) == CATEGORY_POKE) { + sub_8046CE4(item, gDungeon->unk1C574.unk17 * 40); + } +} + +void sub_8045CB0(void) +{ + u8 itemID; + s32 yCounter, xCounter; + const Tile *tile; + u32 uVar5; + Item item; + u32 flag; + s32 x = DungeonRandInt(DUNGEON_MAX_SIZE_X); + s32 y = DungeonRandInt(DUNGEON_MAX_SIZE_Y); + + gDungeon->numItems = 0; + for (yCounter = 0; yCounter < DUNGEON_MAX_SIZE_Y; yCounter++) { + y++; + if (y == DUNGEON_MAX_SIZE_Y) { + y = 0; + } + + for (xCounter = 0; xCounter < DUNGEON_MAX_SIZE_X; xCounter++) { + x++; + flag = ITEM_FLAG_IN_SHOP; + if (x == DUNGEON_MAX_SIZE_X) { + x = 0; + } + tile = GetTile(x,y); + + if (!(tile->terrainType & TERRAIN_TYPE_STAIRS) && (tile->spawnOrVisibilityFlags & 2)) { + DungeonPos pos; + bool8 shopFlag = FALSE; + pos.x = x; + pos.y = y; + + if (tile->terrainType & TERRAIN_TYPE_SHOP) { + shopFlag = TRUE; + uVar5 = 1; + } + else + { + if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { + uVar5 = 3; + } + else { + uVar5 = (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) ? 2 : 0; + } + } + itemID = sub_803D73C(uVar5); + if (!CanSellItem(itemID)) { + shopFlag = 0; + } + sub_8045C28(&item,itemID,0); + if (shopFlag) { + item.flags |= flag; + } + sub_80460F8(&pos,&item,TRUE); + } + } + } +} + +void sub_8045DB4(struct DungeonPos *pos, bool8 printMsg) +{ + Item *tileItem; + int inventoryIds[INVENTORY_SIZE + 1]; + Item *inventoryItems[INVENTORY_SIZE + 1]; + Entity *leader = GetLeader(); + EntityInfo *leaderInfo = GetEntInfo(leader); + const Tile *tile = GetTile(pos->x,pos->y); + Entity *tileObject = tile->object; + if (tileObject == NULL) { + return; + } + if (GetEntityType(tileObject) != ENTITY_ITEM) { + return; + } + tileItem = GetItemData(tileObject); + if (leaderInfo->action.actionParameters[0].actionUseIndex == 0) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); + } + else if (ShouldMonsterRunAwayAndShowEffect(leader,1)) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonTerrifiedCouldntPickUpItem); + } + else if (GetItemCategory(tileItem->id) == CATEGORY_POKE) { + PlaySoundEffect(0x14c); + AddToTeamMoney(GetMoneyValue(tileItem)); + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem); + TryDisplayItemPickupTutorialMessage(tileItem->id); + } + else { + s32 i, maxItems; + if (gDungeon->unk644.unk17 != 0) { + for (i = 0; i < INVENTORY_SIZE; i++) { + inventoryItems[i] = &gTeamInventoryRef->teamItems[i]; + inventoryIds[i] = i; + } + maxItems = INVENTORY_SIZE; + } + else { + inventoryItems[0] = &leaderInfo->heldItem; + inventoryIds[0] = -1; + maxItems = 1; + } + + if (tileItem->id <= ITEM_GEO_PEBBLE && !(tileItem->flags & ITEM_FLAG_IN_SHOP)) { + s32 index = -1; + s32 numberItems = -1; + s32 i; + + for (i = 0; i < maxItems; i++) { + if (ItemExists(inventoryItems[i]) + && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) + && (tileItem->id == inventoryItems[i]->id) + && (tileItem->flags & ITEM_FLAG_STICKY) == (inventoryItems[i]->flags & ITEM_FLAG_STICKY) + && inventoryItems[i]->quantity != 99 + && numberItems < inventoryItems[i]->quantity) + { + numberItems = inventoryItems[i]->quantity; + index = i; + } + } + + if (index == -1) { + s32 i; + + numberItems = -1; + for (i = 0; i < maxItems; i++) { + if (ItemExists(inventoryItems[i]) + && !(inventoryItems[i]->flags & ITEM_FLAG_IN_SHOP) + && tileItem->id == inventoryItems[i]->id + && inventoryItems[i]->quantity != 99 + && numberItems < inventoryItems[i]->quantity) + { + numberItems = inventoryItems[i]->quantity; + index = i; + } + } + } + + if (index != -1) { + struct Item *addedItem = inventoryItems[index]; + s32 newQuantity = addedItem->quantity + tileItem->quantity; + + if (newQuantity >= 99) { + newQuantity = 99; + } + addedItem->quantity = newQuantity; + + if (tileItem->flags & ITEM_FLAG_STICKY) { + inventoryItems[index]->flags |= ITEM_FLAG_STICKY; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + PlaySoundEffect(0x14a); + if (inventoryIds[index] < 0) { + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); + } + else { + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); + } + TryDisplayItemPickupTutorialMessage(tileItem->id); + return; + } + } + + for (i = 0; i < maxItems; i++) { + if (!ItemExists(inventoryItems[i])) + break; + } + + if (i == maxItems) { + if (!printMsg) { + return; + } + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonSteppedOnItem); + } + else { + PlaySoundEffect(0x14a); + if (inventoryIds[i] < 0) { + leaderInfo->heldItem = *tileItem; + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); + } + else if (AddItemToInventory(tileItem) != 0) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + LogMessageByIdWithPopupCheckUser(leader,*gMonCouldntPickUpItem); + } + else { + sub_8045BF8(gFormatBuffer_Items[0],tileItem); + sub_80461C8(pos,1); + LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); + } + TryDisplayItemPickupTutorialMessage(tileItem->id); + } + } +} + +bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) +{ + s32 i, count; + Tile *tile; + Entity *entity = sub_8045708(pos); + + if (entity == NULL) + return FALSE; + *entity->axObj.info.item = *item; + entity->axObj.info.item->flags &= ~(ITEM_FLAG_SET); + entity->isVisible = TRUE; + tile = GetTileMut(pos->x, pos->y); + tile->object = entity; + if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { + if (item->flags & ITEM_FLAG_IN_SHOP) { + if (a2) { + gDungeon->unk644.unk48 += GetStackBuyPrice(item); + } + } + else { + gDungeon->unk644.unk4C += GetStackSellPrice(item); + } + } + + count = 0; + for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { + if (EntityIsValid(gDungeon->items[i])) { + count = i + 1; + } + } + gDungeon->numItems = count; + return TRUE; +} + +bool8 sub_80461C8(DungeonPos *pos, bool8 a2) +{ + s32 i, count; + Item *item; + Tile *tile = GetTileMut(pos->x, pos->y); + Entity *tileObject = tile->object; + if (tileObject == NULL || GetEntityType(tileObject) != ENTITY_ITEM) + return FALSE; + + item = GetItemData(tileObject); + if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { + if (item->flags & ITEM_FLAG_IN_SHOP) { + if (a2) { + gDungeon->unk644.unk48 -= GetStackBuyPrice(item); + } + } + else { + gDungeon->unk644.unk4C -= GetStackSellPrice(item); + } + } + + tile->object = NULL; + tileObject->type = ENTITY_NOTHING; + + count = 0; + for (i = 0; i < DUNGEON_MAX_ITEMS; i++) { + if (EntityIsValid(gDungeon->items[i])) { + count = i + 1; + } + } + gDungeon->numItems = count; + return TRUE; +} + +s32 sub_8046298(Item *item) +{ + return gItemParametersData[item->id].icon; +} + +bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) +{ + s32 x, y, y2; + s32 objMode = 0; + + if (!EntityIsValid(entity)) + return FALSE; + + if (a2) { + s32 terrainType = GetTerrainType(GetTile(entity->pos.x, entity->pos.y)); + + if (terrainType == TERRAIN_TYPE_WALL) + return FALSE; + if (terrainType == TERRAIN_TYPE_SECONDARY) { + objMode = 1; + } + + if (!sub_8045888(entity)) + return FALSE; + } + + x = (entity->pixelPos.x / 256) - gDungeon->unk181e8.cameraPixelPos.x; + y = ((entity->pixelPos.y - entity->unk1C.raw) / 256) - gDungeon->unk181e8.cameraPixelPos.y; + y2 = ((entity->pixelPos.y / 256) - gDungeon->unk181e8.cameraPixelPos.y) + 8; + y2 /= 2; + + if (x >= -32 && y >= -32 && x <= 272 && y <= 192) { + s32 tileNum; + + SpriteSetMatrixNum(&gUnknown_202EDC0, 0); + if (a1) { + tileNum = 0x17; + SpriteSetPalNum(&gUnknown_202EDC0, 10); + } + else { + tileNum = sub_8046298(entity->axObj.info.item); + if (a3 != 0xFF && tileNum == 0) { + tileNum = gUnknown_203B420[a3]; + SpriteSetMatrixNum(&gUnknown_202EDC0, gUnknown_203B428[a3] * 8); + } + SpriteSetPalNum(&gUnknown_202EDC0, GetItemPalette(entity->axObj.info.item->id)); + } + + SpriteSetY(&gUnknown_202EDC0, y); + SpriteSetX(&gUnknown_202EDC0, x); + SpriteSetObjMode(&gUnknown_202EDC0, objMode); + SpriteSetPriority(&gUnknown_202EDC0, 3); + SpriteSetTileNum(&gUnknown_202EDC0, 0x1A0 + tileNum * 4); + if (!a4) { + y2 = 1; + } + AddSprite(&gUnknown_202EDC0, y2, NULL, NULL); + return TRUE; + } + + return FALSE; +} + +const u8 *sub_80464AC(Item *item) +{ + return gActions[GetItemActionType(item->id)].desc; +} + +void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item) +{ + + s32 x, y; + Entity itemEntity; + + itemEntity.type = ENTITY_ITEM; + itemEntity.unk24 = 0; + itemEntity.isVisible = TRUE; + itemEntity.unk22 = 0; + itemEntity.axObj.info.item = item; + itemEntity.pos = *pos; + + x = ((pos->x * 24) + 4) << 8; + y = ((pos->y * 24) + 4) << 8; + SetEntityPixelPos(&itemEntity, x, y); + itemEntity.spawnGenID = 0; + sub_804652C(entity, &itemEntity, item, TRUE, NULL); +} + +void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos) +{ + DungeonPos localPos; + DungeonPos localPos2; + s32 i; + const Tile *tile = GetTile(entity2->pos.x, entity2->pos.y); + Entity *tileObject = tile->object; + bool8 var_24 = FALSE; + + if (tileObject != NULL && GetEntityType(tileObject) == ENTITY_TRAP) { + sub_8046734(entity2, &entity2->pos); + sub_807FE44(&entity2->pos, 1); + LogMessageByIdWithPopupCheckUser(entity1, gUnknown_80FED30); + if (!ItemExists(item)) + return; + } + + localPos.x = entity2->pos.x; + localPos.y = entity2->pos.y; + localPos2 = localPos; + if (a3) { + i = 0; + } + else { + i = 1; + } + + while (1) { + if (gUnknown_80F4468[i].x == 99) { + var_24 = FALSE; + break; + } + localPos.x = entity2->pos.x + gUnknown_80F4468[i].x; + localPos.y = entity2->pos.y + gUnknown_80F4468[i].y; + tile = GetTile(localPos.x, localPos.y); + if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { + sub_8046734(entity2, &localPos); + localPos2 = localPos; + if (GetTerrainType(tile) == (TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL) || (sub_80460F8(&localPos, item, TRUE))) { + var_24 = TRUE; + } + break; + } + i++; + } + + sub_8045BF8(gFormatBuffer_Items[0], item); + if (var_24) { + ShowDungeonMapAtPos(localPos.x, localPos.y); + switch (GetTerrainType(GetTile(localPos.x, localPos.y))) { + case TERRAIN_TYPE_NORMAL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOnGround); + break; + case TERRAIN_TYPE_SECONDARY: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellInWater); + break; + case TERRAIN_TYPE_WALL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemBuried); + break; + case TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL: + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemFellOutOfSight); + break; + } + } + else { + PixelPos pixelPos; + + pixelPos.x = X_POS_TO_PIXELPOS(localPos2.x); + pixelPos.y = X_POS_TO_PIXELPOS(localPos2.y); // Intentional or a typo(X vs Y)? + if (pos != NULL) { + pixelPos.x += pos->x << 8; + pixelPos.y += pos->y << 8; + } + + sub_804219C(&pixelPos); + TryDisplayDungeonLoggableMessage5(entity1, &localPos, gItemLost); + } +} + +void sub_8046734(Entity *entity, DungeonPos *pos) +{ + PixelPos posPixel; + PixelPos calcPixelPos; + bool8 hallucinating = gDungeon->unk181e8.hallucinating; + + posPixel.x = ((pos->x * 24) + 4) << 8; + posPixel.y = ((pos->y * 24) + 4) << 8; + if (abs(entity->pixelPos.x - posPixel.x) > 11 || abs(entity->pixelPos.y - posPixel.y) > 11) { + s32 i; + PixelPos add; + s32 unk = 0; // Direction? + s32 sinVal = 0; + + calcPixelPos.x = entity->pixelPos.x; + calcPixelPos.y = entity->pixelPos.y; + + add.x = (posPixel.x - calcPixelPos.x) / 24; + add.y = (posPixel.y - calcPixelPos.y) / 24; + for (i = 0; i < 24; i++) { + calcPixelPos.x += add.x; + calcPixelPos.y += add.y; + entity->unk1C.raw = sin_4096(sinVal) * 12; + sub_804535C(entity, &calcPixelPos); + sub_80462AC(entity, hallucinating, 0, unk, 0); + DungeonRunFrameActions(0x13); + sinVal += 85; + if ((i & 3) == 0) { + unk++; + } + unk &= 7; + } + } + + SetEntityPixelPos(entity, posPixel.x, posPixel.y); + entity->unk1C.raw = 0; + sub_80462AC(entity, hallucinating, 1, 0xFF, 0); + DungeonRunFrameActions(0x13); +} + +void sub_8046860(Entity *entity, DungeonPos *pos, Item *item, s32 a4) +{ + sub_804687C(entity, pos, pos, item, a4); +} + +void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 count) +{ + Entity itemEntities[10]; + DungeonPos targetTilePos[10]; + PixelPos itemVelocity[10]; + u8 targetTileUsed[30]; + s32 sinVal; + s32 i; + bool8 r1, r9; + + for (i = 0; i < 30; i++) { + targetTileUsed[i] = 0; + } + + for (i = 0; i < count; i++) { + s32 j; + bool8 foundTile = FALSE; + DungeonPos pos; + + pos.x = pos2->x; + pos.y = pos2->y; + + for (j = 0; j < 30; j++) { + if (gUnknown_80F4468[j].x == 99) + break; + if (!targetTileUsed[j]) { + const Tile *tile; + + pos.x = pos2->x + gUnknown_80F4468[j].x; + pos.y = pos2->y + gUnknown_80F4468[j].y; + + tile = GetTile(pos.x, pos.y); + if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { + targetTilePos[i] = pos; + targetTileUsed[j] = TRUE; + foundTile = TRUE; + break; + } + } + } + + if (!foundTile) { + targetTilePos[i].x = -1; + targetTilePos[i].y = -1; + } + } + + r1 = FALSE; + r9 = FALSE; + for (i = 0; i < count; i++) { + if (targetTilePos[i].x < 0) { + itemEntities[i].type = ENTITY_NOTHING; + r9 = TRUE; + } + else { + s32 x, y; + + itemEntities[i].type = ENTITY_ITEM; + itemEntities[i].unk24 = 0; + itemEntities[i].isVisible = TRUE; + itemEntities[i].unk22 = 0; + itemEntities[i].axObj.info.item = &item[i]; + itemEntities[i].pos = targetTilePos[i]; + x = ((pos1->x * 24) + 4) << 8; + y = ((pos1->y * 24) + 4) << 8; + SetEntityPixelPos(&itemEntities[i], x, y); + itemEntities[i].spawnGenID = 0; + itemVelocity[i].x = ((((targetTilePos[i].x * 24) + 4) << 8) - (itemEntities[i].pixelPos.x)) / 24; + itemVelocity[i].y = ((((targetTilePos[i].y * 24) + 4) << 8) - (itemEntities[i].pixelPos.y)) / 24; + r1 = TRUE; + } + } + + if (!r1) { + if (count > 1) { + LogMessageByIdWithPopupCheckUser(entity, gAllItemsLost); + } + else { + LogMessageByIdWithPopupCheckUser(entity, gItemLost); + } + } + else { + s32 counter; + s32 dirMaybe; + bool8 hallucinating; + + if (r9) { + LogMessageByIdWithPopupCheckUser(entity, gSeveralItemsLost); + } + + dirMaybe = 0; + hallucinating = gDungeon->unk181e8.hallucinating; + sinVal = 0; + for (counter = 0; counter < 24; counter++) { + for (i = 0; i < count; i++) { + if (EntityIsValid(&itemEntities[i])) { + IncreaseEntityPixelPos(&itemEntities[i], itemVelocity[i].x, itemVelocity[i].y); + itemEntities[i].unk1C.raw = sin_4096(sinVal) * 12; + sub_80462AC(&itemEntities[i], hallucinating, 1, dirMaybe, 0); + } + } + DungeonRunFrameActions(0x13); + sinVal += 85; + if ((counter & 3) == 0) { + dirMaybe++; + } + dirMaybe &= 7; + } + + for (i = 0; i < count; i++) { + if (targetTilePos[i].x >= 0) { + sub_80460F8(&targetTilePos[i], &item[i], TRUE); + } + } + } +} + bool8 HasHeldItem(Entity *pokemon, u8 id) { - // Weird assignment to fix a regswap. - EntityInfo *pokemonInfo = pokemonInfo = GetEntInfo(pokemon); - if (!(pokemonInfo->heldItem.flags & ITEM_FLAG_EXISTS)) - { + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (!ItemExists(&pokemonInfo->heldItem)) { return FALSE; } - if (pokemonInfo->heldItem.flags & ITEM_FLAG_STICKY) - { + if (pokemonInfo->heldItem.flags & ITEM_FLAG_STICKY) { return FALSE; } - if (pokemonInfo->heldItem.id != id) - { + if (pokemonInfo->heldItem.id != id) { return FALSE; } return TRUE; @@ -50,40 +739,38 @@ bool8 HasHeldItem(Entity *pokemon, u8 id) void sub_8046CE4(Item *item,s32 param_2) { - s32 iVar1; - s32 iVar2; + s32 i; + s32 rand = DungeonRandInt(100); - iVar1 = DungeonRandInt(100); - for(iVar2 = 0; iVar2 < 200; iVar2++) - { - if (gUnknown_810A3F0[iVar1] <= param_2) { - item->quantity = iVar1; - return; + for (i = 0; i < 200; i++) { + if (gUnknown_810A3F0[rand] <= param_2) { + item->quantity = rand; + return; + } + rand /= 2; } - iVar1 = iVar1 / 2; - } - item->quantity = 1; + item->quantity = 1; } void sub_8046D20(void) { - u8 cVar1; + u8 cVar1; - cVar1 = gDungeon->unk8; - gDungeon->unk8 = sub_8046D70(); - if (((gDungeon->unk8 == 1) && (cVar1 == 0)) && - (DisplayDungeonYesNoMessage(0, *gUnknown_80FA408, 1) == 1)) { - gDungeon->unk4 = 1; - gDungeon->unk11 = 2; - } - else { - MusicBoxCreation(); - } + cVar1 = gDungeon->unk8; + gDungeon->unk8 = sub_8046D70(); + if (((gDungeon->unk8 == 1) && (cVar1 == 0)) && + (DisplayDungeonYesNoMessage(0, *gUnknown_80FA408, 1) == 1)) { + gDungeon->unk4 = 1; + gDungeon->unk11 = 2; + } + else { + MusicBoxCreation(); + } } u8 sub_8046D70(void) { - if(gDungeon->unk644.unk46) + if (gDungeon->unk644.unk46) return 0; else return 0; @@ -91,166 +778,146 @@ u8 sub_8046D70(void) void MusicBoxCreation(void) { - bool8 musicBoxOnce; - bool8 createMusicBox; - Item *pbVar3; // r2 - s32 iVar4; - Entity *entity; + bool8 musicBoxOnce; + bool8 createMusicBox; + s32 i; + s32 indexes[3]; - s32 indexes[3]; + createMusicBox = FALSE; + do { + musicBoxOnce = FALSE; + indexes[0] = -1; + indexes[1] = -1; + indexes[2] = -1; - createMusicBox = FALSE; - do { - musicBoxOnce = FALSE; - indexes[0] = -1; - indexes[1] = -1; - indexes[2] = -1; + for (i = 0; i < INVENTORY_SIZE; i++) { + Item *item = &gTeamInventoryRef->teamItems[i]; + if (ItemExists(item)) { + if (item->id == ITEM_ROCK_PART) { + indexes[0] = i; + } + if (item->id == ITEM_ICE_PART) { + indexes[1] = i; + } + if (item->id == ITEM_STEEL_PART) { + indexes[2] = i; + } + } + } - for(iVar4 = 0, pbVar3 = &gTeamInventoryRef->teamItems[iVar4]; iVar4 < 20; pbVar3++, iVar4++) - { - if (pbVar3->flags & ITEM_FLAG_EXISTS) { - if (pbVar3->id == ITEM_ROCK_PART) { - indexes[0] = iVar4; + if ((indexes[0] >= 0) && (indexes[1] >= 0) && (indexes[2] >= 0)) { + + musicBoxOnce = TRUE; + createMusicBox = TRUE; + + // clear out each of the parts + ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[0]]); + ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[1]]); + ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[2]]); + + // init the music box + xxx_init_itemslot_8090A8C(&gTeamInventoryRef->teamItems[indexes[0]], ITEM_MUSIC_BOX, 0); } - if (pbVar3->id == ITEM_ICE_PART) { - indexes[1] = iVar4; - } - if (pbVar3->id == ITEM_STEEL_PART) { - indexes[2] = iVar4; - } - } + } while (musicBoxOnce); + + FillInventoryGaps(); + + if (createMusicBox) { + Entity *leader = GetLeader(); + sub_80855E4(sub_80861A8); + gDungeon->unk1356C = 1; + DisplayDungeonMessage(0,*gUnknown_810531C,1); + sub_803E708(0x3c,0x41); + DisplayDungeonMessage(0,*gUnknown_8105360,1); + sub_80869E4(leader,4,10,0); + sub_80416E0(&leader->pixelPos,0x10c,FALSE); + sub_80421C0(leader,0xd7); + sub_803E708(0x3c,0x41); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],leader,0); + DisplayDungeonMessage(0,*gUnknown_81053A8,1); + sub_803E708(10,0x41); + PlaySoundEffect(0xd4); + DisplayDungeonMessage(0,*gUnknown_8105434,1); + sub_803E708(10,0x41); + sub_804178C(1); + gDungeon->unk1356C = 0; + ShowWholeRevealedDungeonMap(); } - - if ((indexes[0] >= 0) && (indexes[1] >= 0) && (indexes[2] >= 0)) { - - musicBoxOnce = TRUE; - createMusicBox = TRUE; - - // clear out each of the parts - ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[0]]); - ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[1]]); - ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[2]]); - - // init the music box - xxx_init_itemslot_8090A8C(&gTeamInventoryRef->teamItems[indexes[0]], ITEM_MUSIC_BOX, 0); - } - } while (musicBoxOnce); - - FillInventoryGaps(); - - if (createMusicBox) { - entity = GetLeader(); - sub_80855E4(sub_80861A8); - gDungeon->unk1356C = 1; - DisplayDungeonMessage(0,*gUnknown_810531C,1); - sub_803E708(0x3c,0x41); - DisplayDungeonMessage(0,*gUnknown_8105360,1); - sub_80869E4(entity,4,10,0); - sub_80416E0(&entity->pixelPos,0x10c,FALSE); - sub_80421C0(entity,0xd7); - sub_803E708(0x3c,0x41); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],entity,0); - DisplayDungeonMessage(0,*gUnknown_81053A8,1); - sub_803E708(10,0x41); - PlaySoundEffect(0xd4); - DisplayDungeonMessage(0,*gUnknown_8105434,1); - sub_803E708(10,0x41); - sub_804178C(1); - gDungeon->unk1356C = 0; - ShowWholeRevealedDungeonMap(); - } } bool8 sub_8046F00(Item *item) { - bool8 canLearnMove; - bool8 cannotMove; - u16 moveID; - Entity *entity; - s32 index; + s32 i; - if (GetItemCategory(item->id) == CATEGORY_TMS_HMS) { - moveID = GetItemMoveID(item->id); - if (!IsHMItem(item->id)) { - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if (EntityIsValid(entity)) { - canLearnMove = CanMonLearnMove(moveID, GetEntInfo(entity)->id); - cannotMove = CheckVariousStatuses2(entity, FALSE); - if (cannotMove) { - canLearnMove = FALSE; - } - if (canLearnMove) return TRUE; + if (GetItemCategory(item->id) == CATEGORY_TMS_HMS) { + u16 moveID = GetItemMoveID(item->id); + if (!IsHMItem(item->id)) { + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + Entity *entity = gDungeon->teamPokemon[i]; + if (EntityIsValid(entity)) { + bool8 canLearnMove = CanMonLearnMove(moveID, GetEntInfo(entity)->id); + bool8 cannotMove = CheckVariousStatuses2(entity, FALSE); + if (cannotMove) { + canLearnMove = FALSE; + } + if (canLearnMove) + return TRUE; + } + } } - } + return FALSE; } - return FALSE; - } - else + return TRUE; } void sub_8046F84(s32 itemFlag) { - Item *item; - Entity *entity; - EntityInfo *entityInfo; - s32 index; + s32 i; - for(index = 0; index < INVENTORY_SIZE; index++) - { - item = &gTeamInventoryRef->teamItems[index]; - if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) { - item->id = 0; - item->quantity = 0; - item->flags = 0; + for (i = 0; i < INVENTORY_SIZE; i++) { + Item *item = &gTeamInventoryRef->teamItems[i]; + if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) { + ZeroOutItem(item); + } } - } - FillInventoryGaps(); + FillInventoryGaps(); - for(index = 0; index < 4; index++) - { - entity = gDungeon->teamPokemon[index]; - if (EntityIsValid(entity)) { - entityInfo = GetEntInfo(entity); - item = &entityInfo->heldItem; - if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) { - item->id = 0; - item->quantity = 0; - item->flags = 0; - } + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + Entity *entity = gDungeon->teamPokemon[i]; + if (EntityIsValid(entity)) { + EntityInfo *entityInfo = GetEntInfo(entity); + Item *item = &entityInfo->heldItem; + if ((item->flags & ITEM_FLAG_EXISTS) && (item->flags & itemFlag)) { + ZeroOutItem(item); + } + } } - } } void sub_804700C(void) { - Item *item; - Entity *entity; - EntityInfo *entityInfo; - s32 index; + s32 i; - for(index = 0; index < INVENTORY_SIZE; index++) - { - item = &gTeamInventoryRef->teamItems[index]; - if ((item->flags & ITEM_FLAG_EXISTS)) { - xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); + for (i = 0; i < INVENTORY_SIZE; i++) + { + Item *item = &gTeamInventoryRef->teamItems[i]; + if ((item->flags & ITEM_FLAG_EXISTS)) { + xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); + } } - } - FillInventoryGaps(); + FillInventoryGaps(); - for(index = 0; index < MAX_TEAM_MEMBERS; index++) - { - entity = gDungeon->teamPokemon[index]; - if (EntityIsValid(entity)) { - entityInfo = GetEntInfo(entity); - item = &entityInfo->heldItem; - if ((item->flags & ITEM_FLAG_EXISTS)) { - xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); - } + for (i = 0; i < MAX_TEAM_MEMBERS; i++) { + Entity *entity = gDungeon->teamPokemon[i]; + if (EntityIsValid(entity)) { + EntityInfo *entityInfo = GetEntInfo(entity); + Item *item = &entityInfo->heldItem; + if ((item->flags & ITEM_FLAG_EXISTS)) { + xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); + } + } } - } } bool8 sub_8047084(s32 itemFlag) @@ -281,35 +948,29 @@ bool8 sub_8047084(s32 itemFlag) void sub_8047104(void) { - Item *item; - s32 index; + s32 i; - for(index = 0; index < INVENTORY_SIZE; index++) - { - item = &gTeamInventoryRef->teamItems[index]; - if (item->flags & ITEM_FLAG_EXISTS) - { - if(item->id == ITEM_POKE) - { - AddToTeamMoney(GetMoneyValue(item)); - ZeroOutItem(item); - } - if(item->flags & ITEM_FLAG_IN_SHOP) - { - ZeroOutItem(item); + for (i = 0; i < INVENTORY_SIZE; i++) { + Item *item = &gTeamInventoryRef->teamItems[i]; + if (item->flags & ITEM_FLAG_EXISTS) { + if (item->id == ITEM_POKE) { + AddToTeamMoney(GetMoneyValue(item)); + ZeroOutItem(item); + } + if (item->flags & ITEM_FLAG_IN_SHOP) { + ZeroOutItem(item); + } } } - } - FillInventoryGaps(); + FillInventoryGaps(); } void sub_8047158(void) { - s32 index; + s32 i; - index = 0; - for(index = 0; index < INVENTORY_SIZE; index++) { - Item *item = &gTeamInventoryRef->teamItems[index]; + for (i = 0; i < INVENTORY_SIZE; i++) { + Item *item = &gTeamInventoryRef->teamItems[i]; if (ItemExists(item) && item->flags & ITEM_FLAG_UNPAID) { item->flags &= ~(ITEM_FLAG_UNPAID); } From a2ed8bef070a2dd9ba8af944c509644924fe6cd2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Mar 2025 12:36:15 +0100 Subject: [PATCH 6/8] item related documentation --- include/code_801B3C0.h | 4 +- include/constants/dungeon_action.h | 4 ++ include/dungeon_items.h | 26 +++++++++- include/dungeon_menu_items.h | 2 +- include/items.h | 2 +- include/structs/str_dungeon.h | 20 +++++--- src/code_801B3C0.c | 4 +- src/code_801B60C.c | 4 +- src/code_80227B8.c | 4 +- src/code_803D110.c | 16 +++---- src/code_803E724.c | 2 +- src/code_8042B34.c | 23 ++++----- src/code_8045A00.c | 11 +---- src/code_8066D04.c | 6 +-- src/code_8069E0C.c | 6 +-- src/code_806CD90.c | 3 +- src/code_8073CF0.c | 3 +- src/debug_menu2.c | 6 +-- src/dungeon_cutscenes.c | 19 ++++---- src/dungeon_generation.c | 6 +-- src/dungeon_items.c | 76 +++++++++++++++--------------- src/dungeon_main.c | 76 +++++++++++++++--------------- src/dungeon_menu_items.c | 41 ++++++++-------- src/dungeon_menu_team.c | 7 +-- src/friend_area_action_menu.c | 4 +- src/friend_list_menu.c | 4 +- src/friend_rescue.c | 8 ++-- src/items.c | 51 ++++++++++---------- src/kangaskhan_storage1.c | 10 ++-- src/kangaskhan_storage2.c | 12 ++--- src/kecleon_bros1.c | 10 ++-- src/luminous_cave.c | 6 +-- src/move_actions.c | 4 +- src/party_list_menu.c | 4 +- src/status_actions.c | 9 ++-- src/thank_you_wonder_mail.c | 8 ++-- src/trade_items_menu.c | 6 +-- src/trap.c | 5 +- src/weather.c | 2 +- src/wonder_mail_main_menu.c | 2 +- 40 files changed, 258 insertions(+), 258 deletions(-) diff --git a/include/code_801B3C0.h b/include/code_801B3C0.h index 76ad0b429..aff5cacfc 100644 --- a/include/code_801B3C0.h +++ b/include/code_801B3C0.h @@ -21,8 +21,8 @@ typedef struct unkStruct_203B230 MenuInputStructSub unk88; } unkStruct_203B230; -bool8 sub_801B3C0(Item *item); +bool8 InitItemDescriptionWindow(Item *item); u32 sub_801B410(void); -void sub_801B450(void); +void FreeItemDescriptionWindow(void); #endif // GUARD_CODE_801B3C0_H diff --git a/include/constants/dungeon_action.h b/include/constants/dungeon_action.h index d01f17a83..fcc22457f 100644 --- a/include/constants/dungeon_action.h +++ b/include/constants/dungeon_action.h @@ -16,6 +16,7 @@ enum DungeonAction ACTION_THROW_ITEM_PLAYER = 0xB, ACTION_SHOW_INFO = 0xC, ACTION_EAT_BERRY_SEED_DRINK = 0xD, + ACTION_UNK10 = 0x10, ACTION_USE_TM = 0x12, ACTION_TALK_FIELD = 0x13, // Talking to another Pokémon by facing them and interacting. ACTION_USE_MOVE_PLAYER = 0x14, @@ -43,12 +44,15 @@ enum DungeonAction ACTION_USE_ORB = 0x31, ACTION_REGULAR_ATTACK = 0x32, ACTION_UNSET_MOVE = 0x33, + ACTION_UNK35 = 0x35, ACTION_GIVE_ITEM = 0x36, ACTION_TAKE_ITEM = 0x37, ACTION_USE_ITEM = 0x38, ACTION_SECOND_THOUGHTS = 0x39, // Happens with invalid actions, like attempting to eat a non-consumable item. + ACTION_UNK3A = 0x3A, ACTION_SET_ITEM = 0x3C, ACTION_UNSET_ITEM = 0x3D, + ACTION_UNK3E = 0x3E, ACTION_PICK_UP_AI = 0x3F, ACTION_THROW_ARC_PLAYER = 0x41, // Throwing Gravelerocks and Geo Pebbles. NUM_DUNGEON_ACTIONS diff --git a/include/dungeon_items.h b/include/dungeon_items.h index 288a1147b..f1bafd243 100644 --- a/include/dungeon_items.h +++ b/include/dungeon_items.h @@ -2,9 +2,33 @@ #define GUARD_DUNGEON_ITEMS_H #include "structs/dungeon_entity.h" +#include "structs/str_position.h" +#include "structs/str_items.h" +void sub_8045BF8(u8 *buffer, Item *item); +void sub_8045C08(u8 *buffer, Item *item); +void sub_8045C18(u8 *buffer, Item *item); +#define FORCE_STICKY_RANDOM 0 +#define FORCE_STICKY_ALWAYS 1 +#define FORCE_STICKY_NEVER 2 +void CreateItemWithStickyChance(Item *item, u8 itemID, u32 forceSticky); +void CreateFloorItems(void); +void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg); +bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2); +bool8 sub_80461C8(DungeonPos *pos, bool8 a2); +bool8 sub_80462AC(Entity * entity, u8 hallucinating, u8 a2, u8 a3, u8 a4); +const u8 *sub_80464AC(Item *item); +void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item); +void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos); +void sub_8046860(Entity *entity, DungeonPos *pos, Item *item, s32 a4); +void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 count); bool8 HasHeldItem(Entity *pokemon, u8 id); -void sub_8046CE4(Item *item, s32 param_2); void sub_8046D20(void); +bool8 sub_8046F00(Item *item); +void ClearAllItemsWithFlag(s32 itemFlag); +void AllItemsToPlainSeed(void); +bool8 PlayerHasItemWithFlag(s32 itemFlag); +void CleanUpInventoryItems(void); +void ClearUnpaidFlagFromAllItems(void); #endif diff --git a/include/dungeon_menu_items.h b/include/dungeon_menu_items.h index ee8424def..f5dbe9975 100644 --- a/include/dungeon_menu_items.h +++ b/include/dungeon_menu_items.h @@ -6,6 +6,6 @@ bool8 sub_805FD3C(struct UnkMenuBitsStruct *a0); bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1); -void sub_8060D24(UNUSED ActionContainer *a0); +void DungeonShowItemDescription(UNUSED ActionContainer *a0); #endif diff --git a/include/items.h b/include/items.h index 933aa5920..67c11f8c2 100644 --- a/include/items.h +++ b/include/items.h @@ -14,7 +14,7 @@ TeamInventory *GetMoneyItemsInfo(void); void InitializeMoneyItems(void); s32 GetNumberOfFilledInventorySlots(void); bool8 IsThrowableItem(u8 id); -void xxx_init_itemslot_8090A8C(Item *param_1,u8 id,u8 param_3); +void ItemIdToSlot(Item *param_1,u8 id,u8 param_3); void xxx_init_helditem_8090B08(BulkItem *param_1,u8 id); void HeldItemToSlot(Item *param_1, BulkItem *param_2); void SlotToHeldItem(BulkItem *held, Item *slot); diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 845800a51..fe016e4ca 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -127,7 +127,7 @@ typedef struct FloorProperties u8 kecleonShopChance; // Percentage chance 0-100% u8 monsterHouseChance; // Percentage chance 0-100% u8 mazeRoomChance; // Percentage chance 0-100% - u8 unkA; + u8 itemStickyChance; // Percentage chance 0-100% bool8 allowDeadEnds; u8 secondaryStructuresBudget; // Maximum number of secondary structures that can be generated u8 roomFlags; // See ROOM_FLAG_ @@ -146,11 +146,19 @@ typedef struct FloorProperties u8 unk1A; } FloorProperties; -typedef struct UnkDungeonGlobal_unk1C590 +enum { + ITEM_SPAWN_NORMAL, + ITEM_SPAWN_IN_SHOP, + ITEM_SPAWN_IN_MONSTER_HOUSE, + ITEM_SPAWN_WALL, // ? + ITEM_SPAWN_TYPES_COUNT +}; + +typedef struct ItemSpawns { s16 categoryValues[NUM_ITEM_CATEGORIES]; s16 itemValues[NUMBER_OF_ITEM_IDS]; -} UnkDungeonGlobal_unk1C590; +} ItemSpawns; typedef struct UnkDungeonGlobal_unk1CD98 { @@ -252,7 +260,7 @@ typedef struct unkDungeon644 /* 0x14 */ bool8 canRecruit; /* 0x15 */ u8 unk15; /* 0x16 */ u8 unk16; - /* 0x17 */ u8 unk17; + /* 0x17 */ bool8 hasInventory; /* 0x18 */ u8 unk18; /* 0x19 */ u8 unk19; /* 0x1A */ u8 fill1A[2]; @@ -480,8 +488,8 @@ typedef struct Dungeon /* 0x1BDD4 */ struct UnkStructDungeon1BDD4 unk1BDD4; /* 0x1BE14 */ struct MessageLogString messageLogStrings[MESSAGE_LOG_STRINGS_COUNT]; /* 0x1C570 */ DungeonLocation unk1C570; - /* 0x1C574 */ FloorProperties unk1C574; - /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4]; + /* 0x1C574 */ FloorProperties floorProperties; + /* 0x1C590 */ ItemSpawns itemSpawns[ITEM_SPAWN_TYPES_COUNT]; u16 unk1CD70[20]; UnkDungeonGlobal_unk1CD98 unk1CD98[32]; UnkDungeonGlobal_unk1CE98_sub unk1CE98; // TODO: not sure how large this is diff --git a/src/code_801B3C0.c b/src/code_801B3C0.c index 1ea71f135..e803f8184 100644 --- a/src/code_801B3C0.c +++ b/src/code_801B3C0.c @@ -19,7 +19,7 @@ static void sub_801B480(void); static void sub_801B51C(void); static void sub_801B590(void); -bool8 sub_801B3C0(Item *item) +bool8 InitItemDescriptionWindow(Item *item) { ResetSprites(TRUE); sUnknown_203B230 = MemoryAlloc(sizeof(unkStruct_203B230),8); @@ -52,7 +52,7 @@ u32 sub_801B410(void) return 0; } -void sub_801B450(void) +void FreeItemDescriptionWindow(void) { if (sUnknown_203B230 != NULL) { MemoryFree(sUnknown_203B230); diff --git a/src/code_801B60C.c b/src/code_801B60C.c index f44ba2fa0..ae88c5fd0 100644 --- a/src/code_801B60C.c +++ b/src/code_801B60C.c @@ -244,7 +244,7 @@ store: sub_8012D60(&sUnknown_203B234->unk28, sUnknown_203B234->unkCC, 0, 0, sUnknown_203B234->menuAction, 2); break; case 11: - sub_801B3C0(&sUnknown_203B234->unk20); + InitItemDescriptionWindow(&sUnknown_203B234->unk20); break; case 12: sub_801A9E0(); @@ -470,7 +470,7 @@ static void sub_801BEAC(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); sub_801B748(9); case 0: case 1: diff --git a/src/code_80227B8.c b/src/code_80227B8.c index 3bd8dd8f0..6f584aeb3 100644 --- a/src/code_80227B8.c +++ b/src/code_80227B8.c @@ -159,7 +159,7 @@ static void sub_8022A10(void) sub_8012D60(&sUnknown_203B294->unkA4, sUnknown_80DC584, 0, 0, 3, 1); break; case 4: - sub_801B3C0(&sUnknown_203B294->item); + InitItemDescriptionWindow(&sUnknown_203B294->item); break; case 5: CreateDialogueBoxAndPortrait(sDoesNotAppearHungry, 0, 0, 0x301); @@ -446,7 +446,7 @@ static void sub_80230E8(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); sub_8022924(1); case 1: case 0: diff --git a/src/code_803D110.c b/src/code_803D110.c index 95e2d54d0..762afb0d9 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -93,7 +93,7 @@ void sub_803D4D0(void) gDungeon->unk1CEC8 = GetDungeonFloorCount(gDungeon->unk644.dungeonLocation.id); gDungeon->unk14 = sub_80902C8(gDungeon->unk644.dungeonLocation.id); - gDungeon->unk1C574 = ((struct UnkDataFileStruct *)(file->data))->unk4[strPtr->unk0]; + gDungeon->floorProperties = ((struct UnkDataFileStruct *)(file->data))->unk4[strPtr->unk0]; for (i = 0; i < 20; i++) { gDungeon->unk1CD70[i] = ((struct UnkDataFileStruct *)(file->data))->unk10[strPtr->unk4][i]; @@ -127,12 +127,12 @@ void sub_803D4D0(void) arrId = 0; for (j = 0; j < NUM_ITEM_CATEGORIES; j++) { - gDungeon->unk1C590[i].categoryValues[arrId] = spArray[arrId]; + gDungeon->itemSpawns[i].categoryValues[arrId] = spArray[arrId]; arrId++; } for (j = 0; j < NUMBER_OF_ITEM_IDS; j++) { - gDungeon->unk1C590[i].itemValues[j] = spArray[arrId]; + gDungeon->itemSpawns[i].itemValues[j] = spArray[arrId]; arrId++; } } @@ -152,28 +152,28 @@ u8 sub_803D6FC(void) return 16; } -u8 sub_803D73C(s32 a0) +u8 GetRandomFloorItem(s32 spawnType) { s32 i; s32 rand = DungeonRandInt(10000); u8 category = NUM_ITEM_CATEGORIES; for (i = 0; i < NUM_ITEM_CATEGORIES; i++) { - if (gDungeon->unk1C590[a0].categoryValues[i] != 0 && gDungeon->unk1C590[a0].categoryValues[i] >= rand) { + if (gDungeon->itemSpawns[spawnType].categoryValues[i] != 0 && gDungeon->itemSpawns[spawnType].categoryValues[i] >= rand) { category = i; break; } } if (category == NUM_ITEM_CATEGORIES) - return 105; + return ITEM_POKE; rand = DungeonRandInt(10000); for (i = 0; i < NUMBER_OF_ITEM_IDS; i++) { - if (gDungeon->unk1C590[a0].itemValues[i] != 0 && GetItemCategory(i) == category && gDungeon->unk1C590[a0].itemValues[i] >= rand) { + if (gDungeon->itemSpawns[spawnType].itemValues[i] != 0 && GetItemCategory(i) == category && gDungeon->itemSpawns[spawnType].itemValues[i] >= rand) { return i; } } - return 105; + return ITEM_POKE; } s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) diff --git a/src/code_803E724.c b/src/code_803E724.c index 8807f6e81..64a70a270 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -694,7 +694,7 @@ void sub_803F27C(bool8 a0) gUnknown_202EDFC = 0xFFFF; if (!a0) { - strPtr->visibilityRange = gDungeon->unk1C574.unk16 & 3; + strPtr->visibilityRange = gDungeon->floorProperties.unk16 & 3; if (strPtr->visibilityRange == 0) { strPtr->unk1820C = 1; } diff --git a/src/code_8042B34.c b/src/code_8042B34.c index f72c581b4..b946e8a4b 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -41,6 +41,7 @@ #include "dungeon_serializer.h" #include "dungeon_config.h" #include "dungeon_map.h" +#include "dungeon_items.h" extern void sub_800EE5C(s32); extern void sub_800EF64(void); @@ -263,10 +264,8 @@ extern void sub_803E250(void); extern void sub_803E830(void); extern void sub_803E214(void); extern void nullsub_56(void); -extern void sub_8047104(void); extern void sub_8068F28(void); extern void sub_806C1D8(void); -extern void sub_804700C(void); extern void IncrementThievingSuccesses(void); extern void sub_803E13C(void); extern void sub_80841EC(void); @@ -313,7 +312,6 @@ extern void sub_806B168(void); extern void sub_806B6C4(void); extern void sub_806A338(void); extern void sub_8051E3C(void); -extern void sub_8045CB0(void); extern void sub_807FA18(void); extern void sub_806A974(void); extern void sub_806CF60(void); @@ -327,7 +325,6 @@ extern void sub_803EAF0(u32, u32); extern void sub_806A914(bool8 a0, bool8 a1, bool8 showRunAwayEffect); extern void sub_803F4A0(Entity *a0); extern void sub_8083AB0(s16 param_0, Entity * target, Entity * entity); -extern void sub_8046F84(s32 itemFlag); extern bool8 sub_8083C50(void); extern void sub_8068FE0(Entity *, u32, Entity *r2); extern void ResetMonEntityData(EntityInfo *, u32); @@ -405,7 +402,7 @@ void RunDungeon(UnkStruct_RunDungeon *r8) gDungeon->unk644.unk16 = r8->unkC; gDungeon->unk644.canRecruit = r8->unkA; gDungeon->unk644.unk15 = r8->unkB; - gDungeon->unk644.unk17 = r8->unkD; + gDungeon->unk644.hasInventory = r8->unkD; gDungeon->unk644.unk19 = r8->unkE; StopDungeonBGM(); sub_803D4AC(); @@ -562,9 +559,9 @@ void RunDungeon(UnkStruct_RunDungeon *r8) gDungeon->unk644.unk40 = 99; gDungeon->unk644.unk42 = 99; gDungeon->weather.weather = 0; - gDungeon->tileset = gDungeon->unk1C574.unk2; - gDungeon->unk3A10 = gDungeon->unk1C574.unk3; - gDungeon->fixedRoomNumber = gDungeon->unk1C574.unk12; + gDungeon->tileset = gDungeon->floorProperties.unk2; + gDungeon->unk3A10 = gDungeon->floorProperties.unk3; + gDungeon->fixedRoomNumber = gDungeon->floorProperties.unk12; sub_807E5E4(0); sub_80842F0(); } @@ -618,7 +615,7 @@ void RunDungeon(UnkStruct_RunDungeon *r8) gDungeon->unk17B40 = 0; if (!r6) { sub_807FA18(); - sub_8045CB0(); + CreateFloorItems(); gDungeon->unk644.unk50 = gDungeon->unk644.unk48; gDungeon->unk644.unk4C = 0; sub_8051E3C(); @@ -793,13 +790,13 @@ void RunDungeon(UnkStruct_RunDungeon *r8) SaveDungeonState(gSerializedData_203B41C, 0x4800); } else { - sub_8046F84(ITEM_FLAG_IN_SHOP); + ClearAllItemsWithFlag(ITEM_FLAG_IN_SHOP); } sub_806C1D8(); if (gDungeon->unk644.unk10 == 1) { if (gDungeon->unk644.unk2A != 0) { - sub_804700C(); + AllItemsToPlainSeed(); } check = TRUE; } @@ -915,7 +912,7 @@ void RunDungeon(UnkStruct_RunDungeon *r8) nullsub_56(); CloseDungeonMapFile(); if (r8->unk7C == 1 || r8->unk7C == 4 || r8->unk7C == 2) { - sub_8047104(); + CleanUpInventoryItems(); } if (r8->unk7C == 1 || r8->unk7C == -2 || r8->unk7C == 4 || r8->unk7C == -1 || r8->unk7C == 2) { if (r8->unk7C == 1 || r8->unk7C == 4 || r8->unk7C == 2) { @@ -1023,7 +1020,7 @@ void sub_8043D60(void) } } - sub_8046F84(ITEM_FLAG_IN_SHOP); + ClearAllItemsWithFlag(ITEM_FLAG_IN_SHOP); } bool8 sub_8043ED0(bool8 a0) diff --git a/src/code_8045A00.c b/src/code_8045A00.c index cc9756af5..a4ffb2d67 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -12,14 +12,10 @@ #include "dungeon_ai_targeting.h" #include "string_format.h" #include "items.h" +#include "trap.h" #include "status_checks_1.h" #include "structs/map.h" #include "structs/str_dungeon.h" -#include "trap.h" -#include "math.h" -#include "code_80450F8.h" -#include "dungeon_util.h" -#include "structs/str_item_text.h" void sub_8045BF8(u8 *, Item *); @@ -87,8 +83,3 @@ void SubstitutePlaceholderStringTags(u8 *buffer, Entity *entity, u32 param_3) break; } } - -// FILE SPLIT HERE - - -// diff --git a/src/code_8066D04.c b/src/code_8066D04.c index 3b60aa4e2..083ff0bea 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -92,19 +92,15 @@ extern Item *sub_8044D90(Entity *, s32, u32); void sub_8045BF8(u8 *, Item *); u8 sub_8048D50(); void SetActionUnusableInDungeonSubMenu(u16 param_1); -u8 * sub_80464AC(); void AddActionToDungeonSubMenu(u16 param_1, u8 param_2); void sub_8044DF0(); void sub_8042208(Entity *pokemon, u8 r1); void sub_803E708(); void sub_80479B8(); -u8 sub_80460F8(DungeonPos *, Item *, u32); extern void sub_807AB38(Entity *, u32); extern Entity * sub_8044DA4(Entity *param_1,int param_2); extern void sub_806A6E8(Entity *); extern void sub_8044DF0(Entity *, u32, u32); -extern void sub_8045DB4(DungeonPos *, u32); -extern bool8 sub_80461C8(DungeonPos *, u32); extern bool32 sub_8055A00(Entity *attacker, s32 firstMoveId, s32 var_34, s32 itemId, s32 arg_0); extern bool8 sub_8044B28(void); Entity *sub_806773C(Entity *entity); @@ -119,7 +115,7 @@ extern Entity * sub_80696A8(Entity *target); void HandlePickUpPlayerAction(Entity *entity) { GetEntInfo(entity)->action.actionParameters[0].actionUseIndex = 1; - sub_8045DB4(&entity->pos,0); + PickUpItemFromPos(&entity->pos,0); } void HandleSetItemAction(Entity *param_1, bool8 param_2) diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index d24ddd72a..adf13948b 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -66,7 +66,7 @@ extern DungeonPos gUnknown_202EE0C; extern void sub_803F4A0(Entity *a0); extern bool8 sub_80860A8(u8 id); extern u8 gUnknown_202F32C; -extern u8 sub_803D73C(s32 a0); +extern u8 GetRandomFloorItem(s32 a0); extern void DeletePokemonDungeonSprite(s32 id); extern void sub_80429E8(Entity *r0); extern s32 sub_803DA20(s32 param_1); @@ -1407,9 +1407,9 @@ bool8 sub_806B8CC(s16 _species, s32 x, s32 y, PokemonStruct2 *monPtr, Entity **a && (entityInfo->abilities[0] == ABILITY_PICKUP || entityInfo->abilities[1] == ABILITY_PICKUP) && !ItemExists(&entityInfo->heldItem)) { - u32 pickUpItem = sub_803D73C(0); + u32 pickUpItem = GetRandomFloorItem(0); if (pickUpItem != ITEM_POKE) { - xxx_init_itemslot_8090A8C(&entityInfo->heldItem, pickUpItem, 0); + ItemIdToSlot(&entityInfo->heldItem, pickUpItem, 0); entityInfo->unkF3 = TRUE; } } diff --git a/src/code_806CD90.c b/src/code_806CD90.c index 0810e0ac0..34f4bc571 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -282,7 +282,6 @@ extern void sub_806A390(Entity *r0); extern void sub_806F63C(Entity *r0); extern void sub_8078084(Entity * pokemon); extern void sub_800DBBC(void); -extern void sub_8045C28(Item *Item, u8 itemID, u32 param_3); extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern bool8 DoEnemiesEvolveWhenKOed(u8 dungeon); extern bool8 sub_806FA5C(Entity *, Entity *, struct unkStruct_8069D4C *); @@ -869,7 +868,7 @@ static bool8 HandleDealingDamageInternal(Entity *attacker, Entity *target, struc if (reviverSeed != NULL) { sub_8042148(target); - sub_8045C28(reviverSeed, ITEM_PLAIN_SEED, 2); + CreateItemWithStickyChance(reviverSeed, ITEM_PLAIN_SEED, FORCE_STICKY_NEVER); target->unk22 = 0; targetData->HP = targetData->maxHPStat; targetData->unk158 = 0; diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index fa2eb2d7d..d2e6eb8a3 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -42,7 +42,6 @@ extern void sub_8067110(Entity *); extern void sub_80671A0(Entity *); extern void sub_8073D14(Entity *); extern void sub_8045BF8(u8 *, Item *); -extern bool8 sub_80461C8(DungeonPos *, u32); extern void sub_805229C(void); extern void sub_807E8F0(Entity *); extern void sub_80444F4(Entity *pokemon); @@ -156,7 +155,7 @@ void sub_8073D14(Entity *entity) Item *carriedItems[INVENTORY_SIZE + 1]; // plus held s32 newQuantity; - if (gDungeon->unk644.unk17 && !_entityInfo->isNotTeamMember) { + if (gDungeon->unk644.hasInventory && !_entityInfo->isNotTeamMember) { for (i = 0; i < INVENTORY_SIZE; i++) { carriedItems[i] = &gTeamInventoryRef->teamItems[i]; inventoryIds[i] = i; diff --git a/src/debug_menu2.c b/src/debug_menu2.c index af32641b8..3a2fe7eff 100644 --- a/src/debug_menu2.c +++ b/src/debug_menu2.c @@ -128,8 +128,8 @@ static void sub_803A5A0(void) sub_803A690(); break; case 4: - xxx_init_itemslot_8090A8C(&item, sUnknown_203B3F0->id, 0); - sub_801B3C0(&item); + ItemIdToSlot(&item, sUnknown_203B3F0->id, 0); + InitItemDescriptionWindow(&item); break; case 5: break; @@ -239,7 +239,7 @@ static void sub_803A86C(void) break; case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); sub_803A504(1); break; } diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index 6b41e2580..6eba3934a 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -388,10 +388,7 @@ extern u32 sub_8085EC8(u32, u32, u32, DungeonPos *, u32); extern void sub_807EAA0(u32, u32); extern void sub_8072008(Entity *, Entity *, s16, u32, u32); extern void sub_8085374(void); -extern void sub_8045C28(Item *, u8 , u8 *); -extern void sub_8046860(Entity *, DungeonPos *, Item *, u32); -extern u32 sub_803D73C(u32); -extern void sub_80460F8(DungeonPos *, Item *, u8); +extern u32 GetRandomFloorItem(u32); extern u8 sub_8044B28(void); extern bool8 sub_8085B80(struct_8085B80 *); @@ -3548,7 +3545,7 @@ void sub_808AE54(u8 param_1,u8 param_2,DungeonPos *param_3) if (!sub_8098100(0x22) && (param_2 == 0x2E) && (param_1 == 0x17)) { sub_808B1CC(ITEM_NOTHING); if (!sub_8098100(0x1d)) { - xxx_init_itemslot_8090A8C(&item,ITEM_ROCK_PART,0); + ItemIdToSlot(&item,ITEM_ROCK_PART,0); sub_80464C8(GetLeader(),param_3,&item); DungeonStartNewBGM(MUS_IN_THE_DEPTHS_OF_THE_PIT); // Something fell from Regirock's body @@ -3571,7 +3568,7 @@ void sub_808AEC8(u8 param_1,u8 param_2,DungeonPos *param_3) if (!sub_8098100(0x22) && (param_2 == 0x2F) && (param_1 == 0x18)) { sub_808B1CC(ITEM_NOTHING); if (!sub_8098100(0x1d)) { - xxx_init_itemslot_8090A8C(&item,ITEM_ICE_PART,0); + ItemIdToSlot(&item,ITEM_ICE_PART,0); sub_80464C8(GetLeader(),param_3,&item); DungeonStartNewBGM(MUS_IN_THE_DEPTHS_OF_THE_PIT); // Something fell from Regice's body @@ -3593,7 +3590,7 @@ void sub_808AF3C(u8 param_1,u8 param_2,DungeonPos *param_3) if (!sub_8098100(0x22) && (param_2 == 0x30) && (param_1 == 0x19)) { sub_808B1CC(ITEM_NOTHING); if (!sub_8098100(0x1d)) { - xxx_init_itemslot_8090A8C(&item,ITEM_STEEL_PART,0); + ItemIdToSlot(&item,ITEM_STEEL_PART,0); sub_80464C8(GetLeader(),param_3, &item); DungeonStartNewBGM(MUS_IN_THE_DEPTHS_OF_THE_PIT); // Something fell from Registeel's body @@ -3716,7 +3713,7 @@ void sub_808B1CC(u8 itemID) tile->terrainType = tile->terrainType | TERRAIN_TYPE_STAIRS; if (((itemID != ITEM_NOTHING) && (sub_80860A8(itemID) == 0)) && (sub_80860A8(ITEM_MUSIC_BOX) == 0)) { - xxx_init_itemslot_8090A8C(&item,itemID,0); + ItemIdToSlot(&item,itemID,0); pos.y--; sub_80460F8(&pos,&item,1); } @@ -3925,7 +3922,7 @@ void JirachiWish(void) { for(index = 0; index < 9; index++) { - sub_8045C28(&moneyItems[index], ITEM_POKE, 0); + CreateItemWithStickyChance(&moneyItems[index], ITEM_POKE, 0); } pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); pos.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1); @@ -3950,7 +3947,7 @@ void JirachiWish(void) { for(index = 0; index < 9; index++) { - sub_8045C28(&items[index], sub_803D73C(0),0); + CreateItemWithStickyChance(&items[index], GetRandomFloorItem(0),0); } pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); pos.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1); @@ -4006,7 +4003,7 @@ void JirachiWish(void) for(index = 0; index < 4; index++) { - sub_8045C28(&strengthItems[index],gUnknown_81074FC[DungeonRandInt(8)],0); + CreateItemWithStickyChance(&strengthItems[index],gUnknown_81074FC[DungeonRandInt(8)],0); } pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1); diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index bddd4608d..02d76ddcb 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -171,7 +171,7 @@ void GenerateFloor(void) s32 x, y; s32 spawnAttempts; bool8 secondaryGen = FALSE; - FloorProperties *floorProps = &gDungeon->unk1C574; + FloorProperties *floorProps = &gDungeon->floorProperties; gDungeon->unk13568 = OpenFileAndGetFileDataPtr(gUnknown_80F6DCC, &gDungeonFileArchive); sHasKecleonShop = FALSE; @@ -6094,10 +6094,10 @@ static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) DungeonPos pos = {x, y}; if (sub_805210C(itemId)) { - xxx_init_itemslot_8090A8C(&item, ITEM_LINK_CABLE, 0); + ItemIdToSlot(&item, ITEM_LINK_CABLE, 0); } else { - xxx_init_itemslot_8090A8C(&item, itemId, 0); + ItemIdToSlot(&item, itemId, 0); } item.flags |= itemFlags; diff --git a/src/dungeon_items.c b/src/dungeon_items.c index 19df08df7..e7892e579 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -59,6 +59,7 @@ extern void sub_804178C(u32); extern void sub_804219C(PixelPos *pos); extern void DungeonRunFrameActions(u32); extern bool8 sub_8045888(Entity *); +extern u32 GetRandomFloorItem(u32); static void MusicBoxCreation(void); static u8 sub_8046D70(void); @@ -67,12 +68,8 @@ extern SpriteOAM gUnknown_202EDC0; extern u8 gUnknown_203B420[]; extern u8 gUnknown_203B428[]; -void sub_8046734(Entity *entity, DungeonPos *pos); -void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, s32 a4); -void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, DungeonPos *pos); -bool8 sub_80461C8(DungeonPos *, bool8); -extern u32 sub_803D73C(u32); -bool8 sub_80460F8(DungeonPos *, Item *, bool8); +static void sub_8046734(Entity *entity, DungeonPos *pos); +static void sub_8046CE4(Item *item,s32 param_2); void sub_8045BF8(u8 *buffer, Item *item) { @@ -89,38 +86,39 @@ void sub_8045C18(u8 *buffer, Item *item) sub_8090E14(buffer, item, &gUnknown_80F6990); } -void sub_8045C28(Item *item, u8 itemID, u32 param_3) +void CreateItemWithStickyChance(Item *item, u8 itemID, u32 forceSticky) { bool8 stickyFlag; - xxx_init_itemslot_8090A8C(item,itemID,0); + ItemIdToSlot(item, itemID, FALSE); stickyFlag = FALSE; if (IsNotSpecialItem(itemID)) { - if (param_3 == 0) { - if (DungeonRandInt(100) < gDungeon->unk1C574.unkA) + if (forceSticky == FORCE_STICKY_RANDOM) { + if (DungeonRandInt(100) < gDungeon->floorProperties.itemStickyChance) stickyFlag = TRUE; else stickyFlag = FALSE; } - else if (param_3 == 1) { + else if (forceSticky == FORCE_STICKY_ALWAYS) { stickyFlag = TRUE; } } + if (stickyFlag) { item->flags |= ITEM_FLAG_STICKY; } if (GetItemCategory(itemID) == CATEGORY_POKE) { - sub_8046CE4(item, gDungeon->unk1C574.unk17 * 40); + sub_8046CE4(item, gDungeon->floorProperties.unk17 * 40); } } -void sub_8045CB0(void) +void CreateFloorItems(void) { u8 itemID; s32 yCounter, xCounter; const Tile *tile; - u32 uVar5; + s32 spawnType; Item item; u32 flag; s32 x = DungeonRandInt(DUNGEON_MAX_SIZE_X); @@ -141,7 +139,7 @@ void sub_8045CB0(void) } tile = GetTile(x,y); - if (!(tile->terrainType & TERRAIN_TYPE_STAIRS) && (tile->spawnOrVisibilityFlags & 2)) { + if (!(tile->terrainType & TERRAIN_TYPE_STAIRS) && (tile->spawnOrVisibilityFlags & SPAWN_FLAG_ITEM)) { DungeonPos pos; bool8 shopFlag = FALSE; pos.x = x; @@ -149,22 +147,22 @@ void sub_8045CB0(void) if (tile->terrainType & TERRAIN_TYPE_SHOP) { shopFlag = TRUE; - uVar5 = 1; + spawnType = ITEM_SPAWN_IN_SHOP; } else { if (GetTerrainType(tile) == TERRAIN_TYPE_WALL) { - uVar5 = 3; + spawnType = ITEM_SPAWN_WALL; } else { - uVar5 = (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) ? 2 : 0; + spawnType = (tile->terrainType & TERRAIN_TYPE_IN_MONSTER_HOUSE) ? ITEM_SPAWN_IN_MONSTER_HOUSE : ITEM_SPAWN_NORMAL; } } - itemID = sub_803D73C(uVar5); + itemID = GetRandomFloorItem(spawnType); if (!CanSellItem(itemID)) { - shopFlag = 0; + shopFlag = FALSE; } - sub_8045C28(&item,itemID,0); + CreateItemWithStickyChance(&item,itemID,FORCE_STICKY_RANDOM); if (shopFlag) { item.flags |= flag; } @@ -174,7 +172,7 @@ void sub_8045CB0(void) } } -void sub_8045DB4(struct DungeonPos *pos, bool8 printMsg) +void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) { Item *tileItem; int inventoryIds[INVENTORY_SIZE + 1]; @@ -216,7 +214,7 @@ void sub_8045DB4(struct DungeonPos *pos, bool8 printMsg) } else { s32 i, maxItems; - if (gDungeon->unk644.unk17 != 0) { + if (gDungeon->unk644.hasInventory) { for (i = 0; i < INVENTORY_SIZE; i++) { inventoryItems[i] = &gTeamInventoryRef->teamItems[i]; inventoryIds[i] = i; @@ -393,12 +391,12 @@ bool8 sub_80461C8(DungeonPos *pos, bool8 a2) return TRUE; } -s32 sub_8046298(Item *item) +static s32 GetItemIconId(Item *item) { return gItemParametersData[item->id].icon; } -bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) +bool8 sub_80462AC(Entity * entity, u8 hallucinating, u8 a2, u8 a3, u8 a4) { s32 x, y, y2; s32 objMode = 0; @@ -428,12 +426,12 @@ bool8 sub_80462AC(Entity * entity, u8 a1, u8 a2, u8 a3, u8 a4) s32 tileNum; SpriteSetMatrixNum(&gUnknown_202EDC0, 0); - if (a1) { + if (hallucinating) { tileNum = 0x17; SpriteSetPalNum(&gUnknown_202EDC0, 10); } else { - tileNum = sub_8046298(entity->axObj.info.item); + tileNum = GetItemIconId(entity->axObj.info.item); if (a3 != 0xFF && tileNum == 0) { tileNum = gUnknown_203B420[a3]; SpriteSetMatrixNum(&gUnknown_202EDC0, gUnknown_203B428[a3] * 8); @@ -560,7 +558,7 @@ void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, Dungeon } } -void sub_8046734(Entity *entity, DungeonPos *pos) +static void sub_8046734(Entity *entity, DungeonPos *pos) { PixelPos posPixel; PixelPos calcPixelPos; @@ -737,7 +735,7 @@ bool8 HasHeldItem(Entity *pokemon, u8 id) return TRUE; } -void sub_8046CE4(Item *item,s32 param_2) +static void sub_8046CE4(Item *item,s32 param_2) { s32 i; s32 rand = DungeonRandInt(100); @@ -768,7 +766,7 @@ void sub_8046D20(void) } } -u8 sub_8046D70(void) +static u8 sub_8046D70(void) { if (gDungeon->unk644.unk46) return 0; @@ -776,7 +774,7 @@ u8 sub_8046D70(void) return 0; } -void MusicBoxCreation(void) +static void MusicBoxCreation(void) { bool8 musicBoxOnce; bool8 createMusicBox; @@ -816,7 +814,7 @@ void MusicBoxCreation(void) ZeroOutItem(&gTeamInventoryRef->teamItems[indexes[2]]); // init the music box - xxx_init_itemslot_8090A8C(&gTeamInventoryRef->teamItems[indexes[0]], ITEM_MUSIC_BOX, 0); + ItemIdToSlot(&gTeamInventoryRef->teamItems[indexes[0]], ITEM_MUSIC_BOX, 0); } } while (musicBoxOnce); @@ -871,7 +869,7 @@ bool8 sub_8046F00(Item *item) return TRUE; } -void sub_8046F84(s32 itemFlag) +void ClearAllItemsWithFlag(s32 itemFlag) { s32 i; @@ -895,7 +893,7 @@ void sub_8046F84(s32 itemFlag) } } -void sub_804700C(void) +void AllItemsToPlainSeed(void) { s32 i; @@ -903,7 +901,7 @@ void sub_804700C(void) { Item *item = &gTeamInventoryRef->teamItems[i]; if ((item->flags & ITEM_FLAG_EXISTS)) { - xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); + ItemIdToSlot(item, ITEM_PLAIN_SEED, FALSE); } } FillInventoryGaps(); @@ -914,13 +912,13 @@ void sub_804700C(void) EntityInfo *entityInfo = GetEntInfo(entity); Item *item = &entityInfo->heldItem; if ((item->flags & ITEM_FLAG_EXISTS)) { - xxx_init_itemslot_8090A8C(item, ITEM_PLAIN_SEED, 0); + ItemIdToSlot(item, ITEM_PLAIN_SEED, FALSE); } } } } -bool8 sub_8047084(s32 itemFlag) +bool8 PlayerHasItemWithFlag(s32 itemFlag) { s32 i; @@ -946,7 +944,7 @@ bool8 sub_8047084(s32 itemFlag) return FALSE; } -void sub_8047104(void) +void CleanUpInventoryItems(void) { s32 i; @@ -965,7 +963,7 @@ void sub_8047104(void) FillInventoryGaps(); } -void sub_8047158(void) +void ClearUnpaidFlagFromAllItems(void) { s32 i; diff --git a/src/dungeon_main.c b/src/dungeon_main.c index 10afb73a9..0bfc8ab63 100644 --- a/src/dungeon_main.c +++ b/src/dungeon_main.c @@ -68,16 +68,14 @@ extern void PlayDungeonStartButtonSE(void); extern void PlayDungeonCancelSE(void); extern void PlayDungeonConfirmationSE(void); extern void sub_806A6E8(Entity *); -extern bool8 sub_8047084(s32 itemFlag); extern void HandleTrap(Entity *pokemon, DungeonPos *pos, int param_3, char param_4); -extern void sub_8045DB4(DungeonPos *, u32); bool8 sub_807EF48(void); void sub_806A2BC(Entity *a0, u8 a1); bool8 sub_80701A4(Entity *a0); void sub_803E708(s32 a0, s32 a1); void sub_8075680(u32); void sub_8094C88(void); -void sub_8047158(void); +void ClearUnpaidFlagFromAllItems(void); void sub_806A914(u8 a0, u8 a1, u8 a2); void SetLeaderActionToNothing(u8 a0); u16 GetLeaderActionId(void); @@ -584,7 +582,7 @@ void DungeonHandlePlayerInput(void) } else { DungeonRunFrameActions(0xF); - sub_8047158(); + ClearUnpaidFlagFromAllItems(); ShowMainMenu((r6.a0_16 == 0), r6.a0_24); ResetRepeatTimers(); ResetUnusedInputStruct(); @@ -1047,7 +1045,7 @@ void sub_805EE30(void) case ENTITY_ITEM: { Item *item = GetItemData(tileObject); if (!(item->flags & ITEM_FLAG_IN_SHOP)) { - sub_8045DB4(&leader->pos, 1); + PickUpItemFromPos(&leader->pos, 1); } else { gDungeon->unk5C0 = 4; @@ -1111,7 +1109,7 @@ void sub_805F02C(void) if (r8->isTeamLeader) { DisplayDungeonLoggableMessageTrue(r7, gUnknown_80F9BD8); } - else if (sub_8047084(ITEM_FLAG_IN_SHOP) || sub_807EF48()) { + else if (PlayerHasItemWithFlag(ITEM_FLAG_IN_SHOP) || sub_807EF48()) { DisplayDungeonLoggableMessageTrue(r7, gUnknown_80F9C08); } else if (gDungeon->unk644.unk2A) { @@ -1204,7 +1202,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) while (1) { if (r10 < 0) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); gTeamMenuChosenId = -1; PrintOnMainMenu(printAll); sub_806A2BC(GetLeader(), 0); @@ -1242,7 +1240,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) if (chosenOption == MAIN_MENU_ITEMS) { u16 action; - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); var_34.a0_8 = 0; var_34.a0_16 = 1; var_34.a0_24 = 0; @@ -1251,75 +1249,75 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) r10 = -1; } if (sub_805FD3C(&var_34) && ShowDungeonItemsMenu(GetLeader(), &var_34)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } action = GetLeaderActionId(); - if (action == 12) { + if (action == ACTION_SHOW_INFO) { sub_8044D90(GetLeader(), 0, 12)->flags |= ITEM_FLAG_UNPAID; - sub_8060D24(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); + DungeonShowItemDescription(GetLeaderActionContainer()); + SetLeaderActionToNothing(TRUE); } - else if (action == 53) { + else if (action == ACTION_UNK35) { item = sub_8044D90(GetLeader(), 0, 13); if (!sub_8048A68(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } - else if (action == 16) { + else if (action == ACTION_UNK10) { item = sub_8044D90(GetLeader(), 0, 14); if (!sub_8048950(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } - else if (action == 44) { + else if (action == ACTION_USE_LINK_BOX) { item = sub_8044D90(GetLeader(), 0, 15); if (!sub_8048B9C(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } - else if (action == 60) { + else if (action == ACTION_SET_ITEM) { HandleSetItemAction(GetLeader(), TRUE); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); sub_803E708(0x50, 0x4D); sub_8052210(0); break; } - else if (action == 61) { + else if (action == ACTION_UNSET_ITEM) { HandleUnsetItemAction(GetLeader(), TRUE); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); sub_803E708(0x50, 0x4D); sub_8052210(0); break; } - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } else if (chosenOption == MAIN_MENU_TEAM) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); if (ShowDungeonTeamMenu(GetLeader())) { r10 = -1; } if (GetLeaderActionId() == ACTION_CHECK_SUMMARY) { ShowDungeonSummaryOrIQMenu(GetLeaderActionContainer(), FALSE); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } else if (GetLeaderActionId() == ACTION_TALK_MENU) { sub_806752C(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } else if (GetLeaderActionId() == 0x34) { sub_8067768(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } else if (GetLeaderActionId() == ACTION_CHANGE_TACTICS) { ShowDungeonTacticsMenu(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } else if (GetLeaderActionId() == ACTION_VIEW_IQ) { ShowDungeonSummaryOrIQMenu(GetLeaderActionContainer(), TRUE); - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } else if (GetLeaderActionId() == ACTION_CHECK_MOVES) { s32 i, count; @@ -1349,7 +1347,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) Entity *currEntity; currMonId = 0; - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); for (i = 0; i < MAX_TEAM_MEMBERS; i++) { Entity *teamMon = gDungeon->teamPokemon[i]; if (EntityIsValid(teamMon)) { @@ -1452,7 +1450,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) if (GetEntityType(tileObject) == ENTITY_ITEM) { u16 action; - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); var_30.a0_8 = 0; var_30.a0_16 = 1; var_30.a0_24 = 1; @@ -1462,45 +1460,45 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) ASM_MATCH_TRICK(leader); } if (sub_805FD3C(&var_30) && ShowDungeonItemsMenu(GetLeader(), &var_30)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } action = GetLeaderActionId(); if (action == 0xC) { sub_8044D90(GetLeader(), 0, 0x10)->flags |= ITEM_FLAG_UNPAID; - sub_8060D24(GetLeaderActionContainer()); - SetLeaderActionToNothing(1); + DungeonShowItemDescription(GetLeaderActionContainer()); + SetLeaderActionToNothing(TRUE); } else if (action == 0x35) { item = sub_8044D90(GetLeader(), 0, 0x11); if (!sub_8048A68(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } else if (action == 0x10) { item = sub_8044D90(GetLeader(), 0, 0x12); if (!sub_8048950(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } else if (action == 0x2C) { item = sub_8044D90(GetLeader(), 0, 0x13); if (!sub_8048B9C(GetLeader(), item)) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); } } if (GetLeaderActionId() != 0) break; } else if (GetEntityType(tileObject) == ENTITY_TRAP) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); ShowDungeonTileMenu(GetLeader()); if (GetLeaderActionId() != 0) break; } } else if (tile->terrainType & TERRAIN_TYPE_STAIRS) { - SetLeaderActionToNothing(1); + SetLeaderActionToNothing(TRUE); ShowDungeonStairsMenu(GetLeader()); if (GetLeaderActionId() != 0) break; diff --git a/src/dungeon_menu_items.c b/src/dungeon_menu_items.c index e38732557..b5a3242eb 100644 --- a/src/dungeon_menu_items.c +++ b/src/dungeon_menu_items.c @@ -36,7 +36,6 @@ extern void PlayDungeonConfirmationSE(void); extern void sub_806A2BC(Entity *a0, u8 a1); extern void SetLeaderActionToNothing(u8 a0); extern void sub_803E708(s32 a0, s32 a1); -extern void sub_8047158(void); extern Item *sub_8044D90(Entity *, s32, u32); extern bool8 sub_8070F14(Entity * pokemon, s32 direction); bool8 sub_805EC2C(Entity *a0, s32 x, s32 y); @@ -235,7 +234,7 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) s16 arr[10]; PlaySoundEffect(0x132); - sub_8047158(); + ClearUnpaidFlagFromAllItems(); ConvertMoneyItemToMoney(); sUnknown_202F240 = 0; r3 = sub_8060D64(arr, var_30, var_34, var_28, a0); @@ -611,10 +610,10 @@ static void sub_8060900(Entity *a0) gDungeonSubMenuItemsCount = 0; if (sUnknownActionUnk4.actionUseIndex < 144) { if (sUnknownActionUnk4.actionUseIndex == 128) { - AddActionToDungeonSubMenu(9, item->id); + AddActionToDungeonSubMenu(ACTION_PICK_UP_PLAYER, item->id); if (GetItemCategory(item->id) != CATEGORY_POKE) { bool32 r2 = 0; - if (gDungeon->unk644.unk17 != 0) { + if (gDungeon->unk644.hasInventory) { if (gTeamInventoryRef->teamItems[INVENTORY_SIZE - 1].flags & ITEM_FLAG_EXISTS) { r2 = TRUE; } @@ -628,7 +627,7 @@ static void sub_8060900(Entity *a0) } } } - if (sUnknownActionUnk4.actionUseIndex == 128 && gDungeon->unk644.unk17 != 0) { + if (sUnknownActionUnk4.actionUseIndex == 128 && gDungeon->unk644.hasInventory) { AddActionToDungeonSubMenu(10, item->id); } val_sub8044DC8 = sub_8044DC8(item); @@ -648,10 +647,10 @@ static void sub_8060900(Entity *a0) s32 i; if (ItemSet(item)) { - AddActionToDungeonSubMenu(0x3D, item->id); + AddActionToDungeonSubMenu(ACTION_UNSET_ITEM, item->id); } else { - AddActionToDungeonSubMenu(0x3C, item->id); + AddActionToDungeonSubMenu(ACTION_SET_ITEM, item->id); } for (i = 0; i < INVENTORY_SIZE; i++) { @@ -659,8 +658,8 @@ static void sub_8060900(Entity *a0) && ItemSet(&gTeamInventoryRef->teamItems[i]) && ItemSticky(&gTeamInventoryRef->teamItems[i])) { - SetActionUnusableInDungeonSubMenu(0x3C); - SetActionUnusableInDungeonSubMenu(0x3D); + SetActionUnusableInDungeonSubMenu(ACTION_SET_ITEM); + SetActionUnusableInDungeonSubMenu(ACTION_UNSET_ITEM); break; } } @@ -688,7 +687,7 @@ static void sub_8060900(Entity *a0) } } } - else if (gDungeon->unk644.unk17) { + else if (gDungeon->unk644.hasInventory) { if (gTeamInventoryRef->teamItems[INVENTORY_SIZE - 1].flags & ITEM_FLAG_EXISTS) { AddActionToDungeonSubMenu(0x3E, item->id); } @@ -705,10 +704,10 @@ static void sub_8060900(Entity *a0) if (sUnknownActionUnk4.actionUseIndex <= 20) { Entity *tileEntity = GetTile(a0->pos.x, a0->pos.y)->object; if (tileEntity == NULL) { - AddActionToDungeonSubMenu(8, item->id); + AddActionToDungeonSubMenu(ACTION_PLACE_ITEM, item->id); } else if (GetEntityType(tileEntity) == ENTITY_ITEM) { - AddActionToDungeonSubMenu(0x3A, item->id); + AddActionToDungeonSubMenu(ACTION_UNK3A, item->id); } } @@ -749,17 +748,17 @@ static void sub_8060900(Entity *a0) if (GetItemCategory(item->id) == CATEGORY_TMS_HMS) r5 = TRUE; if (GetItemCategory(item->id) == CATEGORY_ORBS) r5 = TRUE; - if (gDungeon->unk644.unk17) { + if (gDungeon->unk644.hasInventory) { if (r4) { - AddActionToDungeonSubMenu(0x3E, item->id); + AddActionToDungeonSubMenu(ACTION_UNK3E, item->id); } else { - AddActionToDungeonSubMenu(0x37, item->id); + AddActionToDungeonSubMenu(ACTION_TAKE_ITEM, item->id); } if (r6) { - SetActionUnusableInDungeonSubMenu(0x37); - SetActionUnusableInDungeonSubMenu(0x3E); + SetActionUnusableInDungeonSubMenu(ACTION_TAKE_ITEM); + SetActionUnusableInDungeonSubMenu(ACTION_UNK3E); } } @@ -797,17 +796,17 @@ static void ChosenSubMenuToAction(ActionContainer *a0) a0->actionParameters[1].itemPos.y = 0; } -void sub_8060D24(UNUSED ActionContainer *a0) +void DungeonShowItemDescription(UNUSED ActionContainer *a0) { Item *item = sub_8044D90(GetLeader(), 0, 0xB); DungeonShowWindows(NULL, 0); - sub_801B3C0(item); + InitItemDescriptionWindow(item); do { DungeonRunFrameActions(0x16); } while (sub_801B410() == 0); - sub_801B450(); + FreeItemDescriptionWindow(); sub_803EAF0(0, NULL); } @@ -816,7 +815,7 @@ static s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4) s32 i; s32 count = 0; - if (gDungeon->unk644.unk17 && !a1) { + if (gDungeon->unk644.hasInventory && !a1) { if (gTeamInventoryRef->teamItems[0].flags & ITEM_FLAG_EXISTS) { a0[count++] = 0; } diff --git a/src/dungeon_menu_team.c b/src/dungeon_menu_team.c index 451b71063..f6ff6d6e5 100644 --- a/src/dungeon_menu_team.c +++ b/src/dungeon_menu_team.c @@ -55,9 +55,7 @@ extern void PlayDungeonCancelSE(void); extern void PlayDungeonConfirmationSE(void); extern void PlayDungeonCursorSE(u8 param_1); extern void sub_806A6E8(Entity *); -extern bool8 sub_8047084(s32 itemFlag); extern void HandleTrap(Entity *pokemon, DungeonPos *pos, int param_3, char param_4); -extern void sub_8045DB4(DungeonPos *, u32); bool8 sub_807EF48(void); void sub_806A2BC(Entity *a0, u8 a1); bool8 sub_805E874(void); @@ -70,7 +68,6 @@ void ShowDungeonOthersMenu(void); void sub_8075680(u32); void sub_8094C88(void); void sub_8040A84(void); -void sub_8047158(void); void sub_806A914(u8 a0, u8 a1, u8 a2); void SetLeaderActionToNothing(u8 a0); u16 GetLeaderActionId(void); @@ -86,7 +83,7 @@ bool8 sub_805EF60(Entity *a0, EntityInfo *a1); bool8 sub_8070F80(Entity * pokemon, s32 direction); void PrintOnMainMenu(bool8 printAll); bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1); -void sub_8060D24(UNUSED ActionContainer *a0); +void DungeonShowItemDescription(UNUSED ActionContainer *a0); bool8 ShowDungeonTeamMenu(Entity *a0); void ActionShowMoveInfo(ActionContainer *a0); void ActionToggleMoveUsableForAi(ActionContainer *a0); @@ -201,7 +198,7 @@ bool8 ShowDungeonTeamMenu(Entity *a0) } } - if (!gDungeon->unk644.unk17) { + if (!gDungeon->unk644.hasInventory) { windows.id[0].type = WINDOW_TYPE_NORMAL; windows.id[0].pos.y++; } diff --git a/src/friend_area_action_menu.c b/src/friend_area_action_menu.c index 9220cc7a8..6d5ff8b7a 100644 --- a/src/friend_area_action_menu.c +++ b/src/friend_area_action_menu.c @@ -202,7 +202,7 @@ void sub_8027274(void) break; case 0xd: HeldItemToSlot(&slot, &sUnknown_203B2BC->itemToGive); - sub_801B3C0(&slot); + InitItemDescriptionWindow(&slot); break; case 0xe: unk_CopyMoves4To8(sUnknown_203B2BC->moves,sUnknown_203B2BC->pokeStruct->moves); @@ -625,7 +625,7 @@ void sub_8027C84() { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); SetFriendAreaActionMenuState(0xB); case 0: case 1: diff --git a/src/friend_list_menu.c b/src/friend_list_menu.c index 6797e99ff..aad9ac460 100644 --- a/src/friend_list_menu.c +++ b/src/friend_list_menu.c @@ -219,7 +219,7 @@ void sub_8025518(void) break; case FRIEND_LIST_MENU_STATE_INFO: HeldItemToSlot(&item, &gUnknown_203B2B4->item1); - sub_801B3C0(&item); + InitItemDescriptionWindow(&item); break; case FRIEND_LIST_MENU_STATE_ITEM_GIVEN: gUnknown_203B2B4->fallbackState = 2; @@ -560,7 +560,7 @@ void sub_8025D90(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); SetFriendListMenuState(0xC); case 0: case 1: diff --git a/src/friend_rescue.c b/src/friend_rescue.c index 0f02fb76a..75426d02e 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -693,7 +693,7 @@ void CleanFriendRescueMenu(void) sub_802F2C0(); sub_8030DE4(); sub_802453C(); - sub_801B450(); + FreeItemDescriptionWindow(); } } @@ -2470,7 +2470,7 @@ void sub_8034B88(void) RestoreUnkTextStruct_8006518(&gUnknown_203B33C->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&gUnknown_203B33C->item); + InitItemDescriptionWindow(&gUnknown_203B33C->item); SetFriendRescueMenuState(0x61); break; } @@ -2482,7 +2482,7 @@ void sub_8034C38(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); ResetUnusedInputStruct(); ShowWindows(&gUnknown_203B33C->unk3BC, TRUE, TRUE); sub_801CB5C(TRUE); @@ -2519,7 +2519,7 @@ void sub_8034C98(void) RestoreUnkTextStruct_8006518(&gUnknown_203B33C->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&gUnknown_203B33C->item); + InitItemDescriptionWindow(&gUnknown_203B33C->item); SetFriendRescueMenuState(0x61); break; case 5: diff --git a/src/items.c b/src/items.c index 69349b080..4f6ed3ce2 100644 --- a/src/items.c +++ b/src/items.c @@ -98,33 +98,32 @@ bool8 IsThrowableItem(u8 id) return TRUE; } -void xxx_init_itemslot_8090A8C(Item *slot, u8 id, u8 param_3) +void ItemIdToSlot(Item *slot, u8 id, u8 makeSticky) { - u32 uVar3; - u32 uVar4; + if (id != ITEM_NOTHING) { + slot->flags = ITEM_FLAG_EXISTS; + slot->id = id; + if (IsThrowableItem(id)) { + s32 min = GetSpawnAmountRange(id, MIN_SPAWN_AMOUNT); + s32 max = GetSpawnAmountRange(id, MAX_SPAWN_AMOUNT); + slot->quantity = RandRange(min, max); + } + else if (GetItemCategory(id) == CATEGORY_POKE) { + slot->quantity = 1; + } + else { + slot->quantity = 0; + } - if (id != ITEM_NOTHING) { - slot->flags = ITEM_FLAG_EXISTS; - slot->id = id; - if (IsThrowableItem(id)) { - uVar3 = GetSpawnAmountRange(id, MIN_SPAWN_AMOUNT); - uVar4 = GetSpawnAmountRange(id, MAX_SPAWN_AMOUNT); - slot->quantity = RandRange(uVar3, uVar4); + if (makeSticky) { + slot->flags |= ITEM_FLAG_STICKY; + } } - else if (GetItemCategory(id) == CATEGORY_POKE) - slot->quantity = 1; - else + else { + slot->flags = 0; + slot->id = ITEM_NOTHING; slot->quantity = 0; - - if (param_3 != 0) - slot->flags |= ITEM_FLAG_STICKY; - - } - else { - slot->flags = 0; - slot->id = ITEM_NOTHING; - slot->quantity = 0; - } + } } void xxx_init_helditem_8090B08(BulkItem *held, u8 id) @@ -299,7 +298,7 @@ void BufferItemName(u8* dest, u8 id, struct unkStruct_8090F58* a2) Item unkItem; strncpy(acStack104, gItemParametersData[id].name, 80); - xxx_init_itemslot_8090A8C(&unkItem, id, 0); + ItemIdToSlot(&unkItem, id, 0); unkItem.quantity = 1; sub_8090F58(dest, acStack104, &unkItem, a2); } @@ -548,7 +547,7 @@ void ClearItemSlotAt(u32 index) bool8 sub_809124C(u8 id, u8 param_3) { Item temp; - xxx_init_itemslot_8090A8C(&temp, id, param_3); + ItemIdToSlot(&temp, id, param_3); return AddItemToInventory(&temp); } @@ -1201,7 +1200,7 @@ u8 sub_8091E94(s32 a0, s32 a1, s32 a2) { s32 id, i, arrId; u8 foundCategory, ret; - struct UnkDungeonGlobal_unk1C590 data; + struct ItemSpawns data; s16 rawArray[NUM_ITEM_CATEGORIES + NUMBER_OF_ITEM_IDS]; const u16 *ptr = gUnknown_8108E58[a0 - 1]; diff --git a/src/kangaskhan_storage1.c b/src/kangaskhan_storage1.c index a5b6cfa36..76b2e6515 100644 --- a/src/kangaskhan_storage1.c +++ b/src/kangaskhan_storage1.c @@ -323,7 +323,7 @@ static void sub_8016FF8(void) break; case 16: case 26: - sub_801B3C0(&gKangaskhanStorageWork->storedItem); + InitItemDescriptionWindow(&gKangaskhanStorageWork->storedItem); break; case 27: sub_80177F8(); @@ -669,14 +669,14 @@ static void sub_8017B88(void) UpdateKangaskhanStorageState(28); else { gKangaskhanStorageWork->id = sub_801CB24(); - xxx_init_itemslot_8090A8C(&gKangaskhanStorageWork->storedItem, gKangaskhanStorageWork->id, 0); + ItemIdToSlot(&gKangaskhanStorageWork->storedItem, gKangaskhanStorageWork->id, 0); gKangaskhanStorageWork->storedItem.quantity = 1; UpdateKangaskhanStorageState(25); } break; case 4: gKangaskhanStorageWork->id = sub_801CB24(); - xxx_init_itemslot_8090A8C(&gKangaskhanStorageWork->storedItem, gKangaskhanStorageWork->id, 0); + ItemIdToSlot(&gKangaskhanStorageWork->storedItem, gKangaskhanStorageWork->id, 0); gKangaskhanStorageWork->storedItem.quantity = 1; UpdateKangaskhanStorageState(26); break; @@ -785,7 +785,7 @@ static void sub_8017DC0(void) break; case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateKangaskhanStorageState(14); break; } @@ -800,7 +800,7 @@ static void sub_8017DDC(void) break; case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateKangaskhanStorageState(23); break; } diff --git a/src/kangaskhan_storage2.c b/src/kangaskhan_storage2.c index 031183c8d..ca026110f 100644 --- a/src/kangaskhan_storage2.c +++ b/src/kangaskhan_storage2.c @@ -168,7 +168,7 @@ static void sub_8018100(void) sub_8012D60(&sUnknown_203B20C->unk70, sUnknown_203B20C->unk20, 0, sUnknown_203B20C->unk60, sUnknown_203B20C->menuAction2, 2); break; case 7: - sub_801B3C0(&sUnknown_203B20C->item); + InitItemDescriptionWindow(&sUnknown_203B20C->item); break; case 10: sub_801C8C4(1, 3, 0, 10); @@ -202,7 +202,7 @@ static void sub_8018100(void) sub_8012D60(&sUnknown_203B20C->unk70, sUnknown_203B20C->unk20, 0, sUnknown_203B20C->unk60, sUnknown_203B20C->menuAction3, 2); break; case 14: - sub_801B3C0(&sUnknown_203B20C->item); + InitItemDescriptionWindow(&sUnknown_203B20C->item); break; case KANGASKHAN_STORAGE_2_INIT: default: @@ -447,14 +447,14 @@ static void sub_80186F8(void) } else { sUnknown_203B20C->id = sub_801CB24(); - xxx_init_itemslot_8090A8C(&sUnknown_203B20C->item, sUnknown_203B20C->id, 0); + ItemIdToSlot(&sUnknown_203B20C->item, sUnknown_203B20C->id, 0); sUnknown_203B20C->item.quantity = 1; UpdateKangaskhanStorage2State(13); } break; case 4: sUnknown_203B20C->id = sub_801CB24(); - xxx_init_itemslot_8090A8C(&sUnknown_203B20C->item, sUnknown_203B20C->id, 0); + ItemIdToSlot(&sUnknown_203B20C->item, sUnknown_203B20C->id, 0); sUnknown_203B20C->item.quantity = 1; UpdateKangaskhanStorage2State(14); break; @@ -606,7 +606,7 @@ static void sub_8018AC8(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateKangaskhanStorage2State(5); break; case 0: @@ -621,7 +621,7 @@ static void sub_8018AE4(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateKangaskhanStorage2State(11); break; case 0: diff --git a/src/kecleon_bros1.c b/src/kecleon_bros1.c index bc56a7c83..2d6f440f6 100644 --- a/src/kecleon_bros1.c +++ b/src/kecleon_bros1.c @@ -394,7 +394,7 @@ static void UpdateKecleonStoreDialogue(void) break; case KECLEON_STORE_BUY_ITEM_INFO: case KECLEON_STORE_SELL_ITEM_INFO: - sub_801B3C0(&sKecleonBrosWork1->soldItem); + InitItemDescriptionWindow(&sKecleonBrosWork1->soldItem); break; case KECLEON_STORE_SELL_ITEM_RECEIPT: if (GetNumberOfFilledInventorySlots() == 0 || gTeamInventoryRef->teamMoney >= MAX_TEAM_MONEY) { @@ -699,7 +699,7 @@ static void sub_80199CC(void) item = GetKecleonWareItem(sKecleonBrosWork1->wareShopItemIndex); } - xxx_init_itemslot_8090A8C(&sKecleonBrosWork1->soldItem, item->id, 0); + ItemIdToSlot(&sKecleonBrosWork1->soldItem, item->id, 0); sKecleonBrosWork1->soldItem.quantity = item->quantity; sKecleonBrosWork1->itemSellPrice = GetStackBuyPrice(&sKecleonBrosWork1->soldItem); SetKecleonBrosState(20); @@ -714,7 +714,7 @@ static void sub_80199CC(void) item = GetKecleonWareItem(sKecleonBrosWork1->wareShopItemIndex); } - xxx_init_itemslot_8090A8C(&sKecleonBrosWork1->soldItem, item->id, 0); + ItemIdToSlot(&sKecleonBrosWork1->soldItem, item->id, 0); sKecleonBrosWork1->soldItem.quantity = item->quantity; sKecleonBrosWork1->itemSellPrice = GetStackBuyPrice(&sKecleonBrosWork1->soldItem); SetKecleonBrosState(KECLEON_STORE_BUY_ITEM_INFO); @@ -831,7 +831,7 @@ static void sub_8019D30(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); SetKecleonBrosState(19); break; case 0: @@ -845,7 +845,7 @@ static void sub_8019D4C(void) switch (sub_801B410()) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); SetKecleonBrosState(27); break; case 0: diff --git a/src/luminous_cave.c b/src/luminous_cave.c index 3f381d91e..ba628e768 100644 --- a/src/luminous_cave.c +++ b/src/luminous_cave.c @@ -268,7 +268,7 @@ static void UpdateLuminousCaveDialogue(void) break; case 9: case 14: - sub_801B3C0(&sLuminousCaveWork->chosenItem); + InitItemDescriptionWindow(&sLuminousCaveWork->chosenItem); break; case LUMINOUS_CAVE_LACK_WHAT_NEEDED: sLuminousCaveWork->fallbackState = LUMINOUS_CAVE_GIVE_ITEM_1; @@ -671,7 +671,7 @@ static void sub_80251CC(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateLuminousCaveState(0x7); break; case 0: @@ -686,7 +686,7 @@ static void sub_80251E8(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); UpdateLuminousCaveState(0xC); break; case 0: diff --git a/src/move_actions.c b/src/move_actions.c index 1a797a308..1047ef507 100644 --- a/src/move_actions.c +++ b/src/move_actions.c @@ -116,9 +116,7 @@ void sub_8075900(Entity *pokemon, u8 r1); extern u8 sub_8044B28(void); extern void sub_807EC28(bool8); extern void sub_806F370(Entity *r0, Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); -extern void sub_804652C(Entity *, Entity *, Item *, u32, DungeonPos *); extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); -extern void sub_8045C28(Item *, u8 , u8); static void sub_805A7D4(Entity *, Entity *, Item *, DungeonPos *); extern void MudWaterSportEffect(u32); extern void CalcDamage(Entity *, Entity *, u8, u32, u32, s32 *, u32, u16, u32); @@ -2391,7 +2389,7 @@ bool8 PayDayMoveAction(Entity *pokemon, Entity *target, Move *move, u32 param_4) if (!EntityIsValid(target)) { pos.x = 0; pos.y = 0; - sub_8045C28(&item,ITEM_POKE,2); + CreateItemWithStickyChance(&item,ITEM_POKE,2); sub_805A7D4(pokemon,target,&item,&pos); } } diff --git a/src/party_list_menu.c b/src/party_list_menu.c index d8a525d4d..9b85d90d2 100644 --- a/src/party_list_menu.c +++ b/src/party_list_menu.c @@ -229,7 +229,7 @@ void HandlePartyListMenuCallback(void) break; case 0x15: HeldItemToSlot(&item,&sUnknown_203B2B8->item1); - sub_801B3C0(&item); + InitItemDescriptionWindow(&item); break; case PARTY_LIST_STATE_MOVES: unk_CopyMoves4To8(sUnknown_203B2B8->moves,sUnknown_203B2B8->pokeStruct->moves); @@ -699,7 +699,7 @@ void sub_8026CF0(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); SetPartyListMenuState(PARTY_LIST_STATE_GIVE_ITEM_1); break; case 0: diff --git a/src/status_actions.c b/src/status_actions.c index de33f439a..1f714d7de 100644 --- a/src/status_actions.c +++ b/src/status_actions.c @@ -36,8 +36,7 @@ extern void sub_807F43C(Entity *, Entity *); extern void HandleOneRoomOrb(Entity *, Entity *); -extern u32 sub_803D73C(u32); -extern void sub_8045C28(Item *, u8 , u8); +extern u32 GetRandomFloorItem(u32); extern void sub_80464C8(Entity *, DungeonPos *, Item *); extern void sub_8068FE0(Entity *, u32, Entity *r2); extern void sub_806F370(Entity *r0, Entity *r1, u32, u32, u8 *, u8, s32, u32, u32, u32); @@ -524,13 +523,13 @@ bool8 RecycleMoveAction(Entity * pokemon, Entity * target, Move *move, s32 param { Item *item = &gTeamInventoryRef->teamItems[i]; if (item->id == ITEM_TM_USED_TM) { - xxx_init_itemslot_8090A8C(item, item->quantity + 0x7d,0); + ItemIdToSlot(item, item->quantity + 0x7d,0); isTMRecycled = TRUE; } } } if (ItemExists(&entityInfo->heldItem) && (entityInfo->heldItem.id == ITEM_TM_USED_TM)) { - xxx_init_itemslot_8090A8C(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0); + ItemIdToSlot(&entityInfo->heldItem,entityInfo->heldItem.quantity + 0x7D,0); isTMRecycled = TRUE; } } @@ -1133,7 +1132,7 @@ bool8 ItemizeOrbAction(Entity *pokemon, Entity *target, Move *move, s32 param_4) else { target->isVisible = FALSE; - sub_8045C28(&stack, sub_803D73C(0), 0); + CreateItemWithStickyChance(&stack, GetRandomFloorItem(0), 0); sub_80464C8(pokemon, &posStruct, &stack); sub_8068FE0(target, 0x218, pokemon); return TRUE; diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index a3daad4eb..5455bd5b6 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -411,7 +411,7 @@ void CleanThankYouMailPelipper(void) MemoryFree(sUnknown_203B2C4); sUnknown_203B2C4 = NULL; sub_8030DE4(); - sub_801B450(); + FreeItemDescriptionWindow(); sub_803084C(); sub_801CBB8(); sub_80155F0(); @@ -663,7 +663,7 @@ void sub_802A28C(void) RestoreUnkTextStruct_8006518(&sUnknown_203B2C4->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&sUnknown_203B2C4->unk41C); + InitItemDescriptionWindow(&sUnknown_203B2C4->unk41C); SetThankYouMailMenuState(SHOW_ITEM_TO_SEND_INFO); break; } @@ -675,7 +675,7 @@ void sub_802A33C(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); ResetUnusedInputStruct(); ShowWindows(&sUnknown_203B2C4->unk3BC, TRUE, TRUE); sub_801CB5C(TRUE); @@ -714,7 +714,7 @@ void sub_802A39C(void) RestoreUnkTextStruct_8006518(&sUnknown_203B2C4->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&sUnknown_203B2C4->unk41C); + InitItemDescriptionWindow(&sUnknown_203B2C4->unk41C); SetThankYouMailMenuState(SHOW_ITEM_TO_SEND_INFO); break; case CANCEL_ACTION: diff --git a/src/trade_items_menu.c b/src/trade_items_menu.c index 47d528bbc..fc9804dd8 100644 --- a/src/trade_items_menu.c +++ b/src/trade_items_menu.c @@ -179,7 +179,7 @@ void sub_80365AC(void) RestoreUnkTextStruct_8006518(&sTradeItemsMenu->unk1E4); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&sTradeItemsMenu->itemToSend); + InitItemDescriptionWindow(&sTradeItemsMenu->itemToSend); SetTradeItemMenu(TRADE_ITEMS_ITEM_INFO); break; } @@ -203,7 +203,7 @@ void sub_8036674(void) RestoreUnkTextStruct_8006518(&sTradeItemsMenu->unk1E4); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_801B3C0(&sTradeItemsMenu->itemToSend); + InitItemDescriptionWindow(&sTradeItemsMenu->itemToSend); SetTradeItemMenu(TRADE_ITEMS_ITEM_INFO); break; case 7: @@ -222,7 +222,7 @@ void sub_8036728(void) { case 2: case 3: - sub_801B450(); + FreeItemDescriptionWindow(); ResetUnusedInputStruct(); ShowWindows(&sTradeItemsMenu->unk1E4, TRUE, TRUE); sub_801CB5C(TRUE); diff --git a/src/trap.c b/src/trap.c index 036f18b2a..35624f6ad 100644 --- a/src/trap.c +++ b/src/trap.c @@ -57,16 +57,13 @@ extern u32 gUnknown_8106A4C; extern u32 gUnknown_8106A50; void sub_806A9B4(Entity *, u32); -void sub_80461C8(DungeonPos *, u32); void ShowDungeonMapAtPos(s32, s32); s16 sub_803D970(u32); bool8 sub_806AA0C(s32, s32); void sub_80421EC(DungeonPos *, u32); -extern void sub_804687C(Entity *, DungeonPos *, DungeonPos *, Item *, u32); bool8 sub_8045888(Entity *); u8 GetFloorType(void); void sub_8068FE0(Entity *, u32, Entity *); -void sub_8045C28(Item *, u8 , u8); void sub_8045BF8(u8 *, Item *); void DealDamageToEntity(Entity *,s16,u32,u32); void sub_806F480(Entity *, u32); @@ -503,7 +500,7 @@ void HandleGrimyTrap(Entity *pokemon, Entity *target) if (((GetItemCategory(itemStack[index]->id) == CATEGORY_FOOD_GUMMIES) && (itemStack[index]->id != ITEM_GRIMY_FOOD)) && (DungeonRandInt(100) < gGrimyTrapActivateChance)) { badFoodCount++; - sub_8045C28(itemStack[index], ITEM_GRIMY_FOOD, 2); + CreateItemWithStickyChance(itemStack[index], ITEM_GRIMY_FOOD, 2); } } if (badFoodCount == 1) { diff --git a/src/weather.c b/src/weather.c index 1a5976f7f..80069ab39 100644 --- a/src/weather.c +++ b/src/weather.c @@ -24,7 +24,7 @@ u8 GetApparentWeather(Entity *pokemon) void sub_807E5AC(void) { u8 weather; - weather = gDungeon->unk1C574.unk4; + weather = gDungeon->floorProperties.unk4; if(weather == WEATHER_COUNT) weather = DungeonRandInt(WEATHER_COUNT); sub_807E5E4(weather); diff --git a/src/wonder_mail_main_menu.c b/src/wonder_mail_main_menu.c index 5cec3e8e2..bbfd2148e 100644 --- a/src/wonder_mail_main_menu.c +++ b/src/wonder_mail_main_menu.c @@ -168,7 +168,7 @@ void CleanWonderMailMenu(void) MemoryFree(gUnknown_203B3E8); gUnknown_203B3E8 = NULL; sub_8030DE4(); // Frees 203B324 - sub_801B450(); // Frees 203B230 + FreeItemDescriptionWindow(); // Frees 203B230 sub_803084C(); // Frees 203B320 sub_801CBB8(); // Frees 203B244 sub_80155F0(); // Frees 203B1FC From 838d076a153df324fb121730c21e8cef7dc10e56 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Mar 2025 14:22:55 +0100 Subject: [PATCH 7/8] dungeon items done --- data/data_80F59C8.s | 230 +---------------------------- data/data_80F59C8_5.s | 211 ++++++++++++++++++++++++++ include/constants/dungeon_action.h | 2 + include/dungeon_items.h | 4 +- ld_script.txt | 2 + src/code_8042B34.c | 2 - src/code_8044CC8.c | 12 +- src/code_8066D04.c | 16 +- src/code_8073CF0.c | 8 +- src/code_807CD9C.c | 10 +- src/code_807E5AC.c | 8 +- src/dungeon_cutscenes.c | 2 +- src/dungeon_generation.c | 4 +- src/dungeon_items.c | 74 +++++----- src/dungeon_main.c | 26 ++-- src/dungeon_menu_items.c | 116 +++++++-------- src/dungeon_serializer.c | 4 +- src/trap.c | 2 +- sym_ewram_init.txt | 1 + 19 files changed, 365 insertions(+), 369 deletions(-) create mode 100644 data/data_80F59C8_5.s diff --git a/data/data_80F59C8.s b/data/data_80F59C8.s index 40e27742d..e9c5a95e5 100644 --- a/data/data_80F59C8.s +++ b/data/data_80F59C8.s @@ -1,236 +1,16 @@ #include "constants/status.h" .section .rodata -#.incbin "baserom.gba", 0xF59C4, 0x4 -.string "pksdir0\0" -.string "pksdir0\0" - -.global gUnknown_80F6624 -gUnknown_80F6624: @ 80F6624 -@ replacing .incbin "baserom.gba", 0xF6624, 0x78 -.byte 0x78, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x79, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 -.byte 0x7b, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 -.byte 0x7d, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0xb9, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xba, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 -.byte 0xbb, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 - -.global gStatusSpriteMasks_SleepClassStatus -gStatusSpriteMasks_SleepClassStatus: @ 80F669C -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_SLEEP @ STATUS_SLEEP -.4byte STATUS_SPRITE_SLEEPLESS @ STATUS_SLEEPLESS -.4byte STATUS_SPRITE_SLEEP @ STATUS_NIGHTMARE -.4byte 0 @ STATUS_YAWNING -.4byte STATUS_SPRITE_SLEEP @ STATUS_NAPPING - -.global gStatusSpriteMasks_BurnClassStatus -gStatusSpriteMasks_BurnClassStatus: @ 80F66B4 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_BURNED @ STATUS_BURN -.4byte STATUS_SPRITE_POISONED @ STATUS_POISONED -.4byte STATUS_SPRITE_BADLY_POISONED @ STATUS_BADLY_POISONED -.4byte 0 @ STATUS_PARALYSIS - -.global gStatusSpriteMasks_FrozenClassStatus -gStatusSpriteMasks_FrozenClassStatus: @ 80F66C8 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_FROZEN @ STATUS_FROZEN -.4byte 0 @ STATUS_SHADOW_HOLD -.4byte 0 @ STATUS_WRAP -.4byte 0 @ STATUS_WRAPPED -.4byte 0 @ STATUS_INGRAIN -.4byte 0 @ STATUS_PETRIFIED -.4byte 0 @ STATUS_CONSTRICTION - -.global gStatusSpriteMasks_CringeClassStatus -gStatusSpriteMasks_CringeClassStatus: @ 80F66E8 -.4byte 0 @ STATUS_NONE -.4byte 0 @ STATUS_CRINGE -.4byte STATUS_SPRITE_CONFUSED @ STATUS_CONFUSED -.4byte 0 @ STATUS_PAUSED -.4byte STATUS_SPRITE_COWERING @ STATUS_COWERING -.4byte STATUS_SPRITE_TAUNTED @ STATUS_TAUNTED -.4byte STATUS_SPRITE_ENCORE @ STATUS_ENCORE -.4byte 0 @ STATUS_INFATUATED - -.global gStatusSpriteMasks_BideClassStatus -gStatusSpriteMasks_BideClassStatus: @ 80F6708 -.4byte 0 @ STATUS_NONE -.4byte 0 @ STATUS_BIDE -.4byte 0 @ STATUS_SOLARBEAM -.4byte 0 @ STATUS_SKY_ATTACK -.4byte 0 @ STATUS_RAZOR_WIND -.4byte 0 @ STATUS_FOCUS_PUNCH -.4byte 0 @ STATUS_SKULL_BASH -.4byte 0 @ STATUS_FLYING -.4byte 0 @ STATUS_BOUNCING -.4byte 0 @ STATUS_DIVING -.4byte 0 @ STATUS_DIGGING -.4byte 0 @ STATUS_CHARGING -.4byte 0 @ STATUS_ENRAGED - -.global gStatusSpriteMasks_ReflectClassStatus -gStatusSpriteMasks_ReflectClassStatus: @ 80F673C -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_REFLECT -.4byte STATUS_SPRITE_SHIELD_RED @ STATUS_SAFEGUARD -.4byte STATUS_SPRITE_SHIELD_YELLOW @ STATUS_LIGHT_SCREEN -.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_COUNTER -.4byte STATUS_SPRITE_SHIELD_YELLOW @ STATUS_MAGIC_COAT -.4byte 0 @ STATUS_WISH -.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_PROTECT -.4byte STATUS_SPRITE_SHIELD_RED @ STATUS_MIRROR_COAT -.4byte STATUS_SPRITE_ENDURE @ STATUS_ENDURING -.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_MINI_COUNTER -.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_MIRROR_MOVE -.4byte 0 @ STATUS_CONVERSION2 -.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_VITAL_THROW -.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_MIST - -.global gStatusSpriteMasks_CurseClassStatus -gStatusSpriteMasks_CurseClassStatus: @ 80F6778 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_CURSED @ STATUS_CURSED -.4byte 0 @ STATUS_DECOY -.4byte STATUS_SPRITE_SNATCH @ STATUS_SNATCH - -.global gStatusSpriteMasks_LeechSeedClassStatus -gStatusSpriteMasks_LeechSeedClassStatus: @ 80F6788 -.4byte 0 @ STATUS_NONE -.4byte 0 @ STATUS_LEECH_SEED -.4byte 0 @ STATUS_DESTINY_BOND - -.global gStatusSpriteMasks_SureShotClassStatus -gStatusSpriteMasks_SureShotClassStatus: @ 80F6794 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_SURE_SHOT @ STATUS_SURE_SHOT -.4byte STATUS_SPRITE_WHIFFER @ STATUS_WHIFFER -.4byte STATUS_SPRITE_SET_DAMAGE @ STATUS_SET_DAMAGE -.4byte STATUS_SPRITE_FOCUS_ENERGY @ STATUS_FOCUS_ENERGY - -.global gStatusSpriteMasks_LongTossClassStatus -gStatusSpriteMasks_LongTossClassStatus: @ 80F67A8 -.4byte 0 @ STATUS_NONE -.4byte 0 @ STATUS_LONG_TOSS -.4byte 0 @ STATUS_PIERCE - -.global gStatusSpriteMasks_InvisibleClassStatus -gStatusSpriteMasks_InvisibleClassStatus: @ 80F67B4 -.4byte 0 @ STATUS_NONE -.4byte 0 @ STATUS_INVISIBLE -.4byte 0 @ STATUS_TRANSFORMED -.4byte 0 @ STATUS_MOBILE - -.global gStatusSpriteMasks_BlinkerClassStatus -gStatusSpriteMasks_BlinkerClassStatus: @ 80F67C4 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_BLINKER @ STATUS_BLINKER -.4byte STATUS_SPRITE_CROSS_EYED @ STATUS_CROSS_EYED -.4byte STATUS_SPRITE_EYEDROPS @ STATUS_EYEDROPS - -.global gStatusSpriteMasks_MuzzledStatus -gStatusSpriteMasks_MuzzledStatus: @ 80F67D4 -.4byte 0 @ STATUS_NONE -.4byte STATUS_SPRITE_MUZZLED @ STATUS_MUZZLED - -.global gUnknown_80F67DC -gUnknown_80F67DC: @ 80F67DC -@ u16[4]. They are sound effect IDs -.byte 0xD8, 0x00, 0xD9, 0x00 -.byte 0xD9, 0x00, 0x73, 0x01 - -.global gUnknown_80F67E4 -gUnknown_80F67E4: @ 80F67E4 -@ u16[4]. They are sound effect IDs -.byte 0xDA, 0x00, 0xDB, 0x00 -.byte 0xDB, 0x00, 0x74, 0x01 - -.global gUnknown_80F67EC -gUnknown_80F67EC: @ 80F67EC -@ s32[8] -.byte 0xff, 0xff, 0xff, 0xff, 0x4b, 0x01, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff -.byte 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x00, 0x00, 0x00 - -.global gUnknown_80F680C -gUnknown_80F680C: @ 80F680C -@ u32[8] -.byte 0xff, 0xff, 0xff, 0xff, 0x4b, 0x01, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff -.byte 0xb8, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x00, 0x00, 0x00 - -.global gUnknown_80F682C -gUnknown_80F682C: @ 80F682C -@ u16[8] -.byte 0xe5, 0x03, 0xe5, 0x03, 0xe5, 0x03, 0xa9, 0x01, 0xe5, 0x03, 0xe5, 0x03, 0xaa, 0x01, 0xe5, 0x03 - -.global gUnknown_80F683C -gUnknown_80F683C: @ 80F683C -@ replacing .incbin "baserom.gba", 0xF683C, 0x14 -.byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00 - -.global gUnknown_80F6850 -gUnknown_80F6850: @ 80F6850 -@ replacing .incbin "baserom.gba", 0xF6850, 0x10 -.byte 0x9e, 0x01, 0xa1, 0x01, 0xa2, 0x01, 0xa3, 0x01 -.byte 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 - -.global gSpeedTurns -gSpeedTurns: @ 80F6860 -@ replacing .incbin "baserom.gba", 0xF6860, 0x104 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x00 -.byte 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00 -.byte 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x14, 0x00 -.byte 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x17, 0x00, 0x18, 0x00, 0x00, 0x00 -.byte 0x19, 0x00, 0x1a, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x1d, 0x00, 0x1e, 0x00, 0x00, 0x00 -.byte 0x1f, 0x00, 0x20, 0x00, 0x21, 0x00, 0x00, 0x00, 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x00, 0x00 -.byte 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x29, 0x00, 0x2a, 0x00, 0x2b, 0x00 -.byte 0x2c, 0x00, 0x2d, 0x00, 0x2e, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00 -.byte 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x3a, 0x00, 0x3b, 0x00 -.byte 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00 - -.global gUnknown_80F6964 -gUnknown_80F6964: @ 80F6964 -@ replacing .incbin "baserom.gba", 0xF6964, 0x18 -.byte 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x00 -.byte 0x12, 0x00, 0x31, 0x00, 0x2c, 0x00, 0x12, 0x00 - -.global gUnknown_80F697C -gUnknown_80F697C: @ 80F697C -.byte 0x58, 0x00, 0x00, 0x00 +.align 2,0 +.string "pksdir0" +.align 2,0 .string "pksdir0" .align 2,0 .string "pksdir0" .align 2,0 +.string "pksdir0" -.global gUnknown_80F6990 -gUnknown_80F6990: @ 80F6990 -.byte 0x01, 0x00, 0x00, 0x00 -.byte 0x01, 0x00, 0x00, 0x00 -.byte 0x01, 0x00, 0x00, 0x00 - -.global gUnknown_80F699C -gUnknown_80F699C: @ 80F699C -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x01, 0x00, 0x00, 0x00 - -.global gUnknown_80F69A8 -gUnknown_80F69A8: @ 80F69A8 -@ replacing .incbin "baserom.gba", 0xF69A8, 0x2C -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00, 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 - +.align 2,0 .global gOtherOobTile gOtherOobTile: @ 80F69D4 @ replacing .incbin "baserom.gba", 0xF69D4, 0x18 diff --git a/data/data_80F59C8_5.s b/data/data_80F59C8_5.s new file mode 100644 index 000000000..e0600f28f --- /dev/null +++ b/data/data_80F59C8_5.s @@ -0,0 +1,211 @@ +#include "constants/status.h" +.section .rodata +#.incbin "baserom.gba", 0xF59C4, 0x4 + +.string "pksdir0\0" +.string "pksdir0\0" + +.global gUnknown_80F6624 +gUnknown_80F6624: @ 80F6624 +@ replacing .incbin "baserom.gba", 0xF6624, 0x78 +.byte 0x78, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x79, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 +.byte 0x7b, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7c, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 +.byte 0x7d, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +.byte 0xb9, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xba, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 +.byte 0xbb, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 + +.global gStatusSpriteMasks_SleepClassStatus +gStatusSpriteMasks_SleepClassStatus: @ 80F669C +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_SLEEP @ STATUS_SLEEP +.4byte STATUS_SPRITE_SLEEPLESS @ STATUS_SLEEPLESS +.4byte STATUS_SPRITE_SLEEP @ STATUS_NIGHTMARE +.4byte 0 @ STATUS_YAWNING +.4byte STATUS_SPRITE_SLEEP @ STATUS_NAPPING + +.global gStatusSpriteMasks_BurnClassStatus +gStatusSpriteMasks_BurnClassStatus: @ 80F66B4 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_BURNED @ STATUS_BURN +.4byte STATUS_SPRITE_POISONED @ STATUS_POISONED +.4byte STATUS_SPRITE_BADLY_POISONED @ STATUS_BADLY_POISONED +.4byte 0 @ STATUS_PARALYSIS + +.global gStatusSpriteMasks_FrozenClassStatus +gStatusSpriteMasks_FrozenClassStatus: @ 80F66C8 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_FROZEN @ STATUS_FROZEN +.4byte 0 @ STATUS_SHADOW_HOLD +.4byte 0 @ STATUS_WRAP +.4byte 0 @ STATUS_WRAPPED +.4byte 0 @ STATUS_INGRAIN +.4byte 0 @ STATUS_PETRIFIED +.4byte 0 @ STATUS_CONSTRICTION + +.global gStatusSpriteMasks_CringeClassStatus +gStatusSpriteMasks_CringeClassStatus: @ 80F66E8 +.4byte 0 @ STATUS_NONE +.4byte 0 @ STATUS_CRINGE +.4byte STATUS_SPRITE_CONFUSED @ STATUS_CONFUSED +.4byte 0 @ STATUS_PAUSED +.4byte STATUS_SPRITE_COWERING @ STATUS_COWERING +.4byte STATUS_SPRITE_TAUNTED @ STATUS_TAUNTED +.4byte STATUS_SPRITE_ENCORE @ STATUS_ENCORE +.4byte 0 @ STATUS_INFATUATED + +.global gStatusSpriteMasks_BideClassStatus +gStatusSpriteMasks_BideClassStatus: @ 80F6708 +.4byte 0 @ STATUS_NONE +.4byte 0 @ STATUS_BIDE +.4byte 0 @ STATUS_SOLARBEAM +.4byte 0 @ STATUS_SKY_ATTACK +.4byte 0 @ STATUS_RAZOR_WIND +.4byte 0 @ STATUS_FOCUS_PUNCH +.4byte 0 @ STATUS_SKULL_BASH +.4byte 0 @ STATUS_FLYING +.4byte 0 @ STATUS_BOUNCING +.4byte 0 @ STATUS_DIVING +.4byte 0 @ STATUS_DIGGING +.4byte 0 @ STATUS_CHARGING +.4byte 0 @ STATUS_ENRAGED + +.global gStatusSpriteMasks_ReflectClassStatus +gStatusSpriteMasks_ReflectClassStatus: @ 80F673C +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_REFLECT +.4byte STATUS_SPRITE_SHIELD_RED @ STATUS_SAFEGUARD +.4byte STATUS_SPRITE_SHIELD_YELLOW @ STATUS_LIGHT_SCREEN +.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_COUNTER +.4byte STATUS_SPRITE_SHIELD_YELLOW @ STATUS_MAGIC_COAT +.4byte 0 @ STATUS_WISH +.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_PROTECT +.4byte STATUS_SPRITE_SHIELD_RED @ STATUS_MIRROR_COAT +.4byte STATUS_SPRITE_ENDURE @ STATUS_ENDURING +.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_MINI_COUNTER +.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_MIRROR_MOVE +.4byte 0 @ STATUS_CONVERSION2 +.4byte STATUS_SPRITE_SHIELD_GREEN @ STATUS_VITAL_THROW +.4byte STATUS_SPRITE_SHIELD_BLUE @ STATUS_MIST + +.global gStatusSpriteMasks_CurseClassStatus +gStatusSpriteMasks_CurseClassStatus: @ 80F6778 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_CURSED @ STATUS_CURSED +.4byte 0 @ STATUS_DECOY +.4byte STATUS_SPRITE_SNATCH @ STATUS_SNATCH + +.global gStatusSpriteMasks_LeechSeedClassStatus +gStatusSpriteMasks_LeechSeedClassStatus: @ 80F6788 +.4byte 0 @ STATUS_NONE +.4byte 0 @ STATUS_LEECH_SEED +.4byte 0 @ STATUS_DESTINY_BOND + +.global gStatusSpriteMasks_SureShotClassStatus +gStatusSpriteMasks_SureShotClassStatus: @ 80F6794 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_SURE_SHOT @ STATUS_SURE_SHOT +.4byte STATUS_SPRITE_WHIFFER @ STATUS_WHIFFER +.4byte STATUS_SPRITE_SET_DAMAGE @ STATUS_SET_DAMAGE +.4byte STATUS_SPRITE_FOCUS_ENERGY @ STATUS_FOCUS_ENERGY + +.global gStatusSpriteMasks_LongTossClassStatus +gStatusSpriteMasks_LongTossClassStatus: @ 80F67A8 +.4byte 0 @ STATUS_NONE +.4byte 0 @ STATUS_LONG_TOSS +.4byte 0 @ STATUS_PIERCE + +.global gStatusSpriteMasks_InvisibleClassStatus +gStatusSpriteMasks_InvisibleClassStatus: @ 80F67B4 +.4byte 0 @ STATUS_NONE +.4byte 0 @ STATUS_INVISIBLE +.4byte 0 @ STATUS_TRANSFORMED +.4byte 0 @ STATUS_MOBILE + +.global gStatusSpriteMasks_BlinkerClassStatus +gStatusSpriteMasks_BlinkerClassStatus: @ 80F67C4 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_BLINKER @ STATUS_BLINKER +.4byte STATUS_SPRITE_CROSS_EYED @ STATUS_CROSS_EYED +.4byte STATUS_SPRITE_EYEDROPS @ STATUS_EYEDROPS + +.global gStatusSpriteMasks_MuzzledStatus +gStatusSpriteMasks_MuzzledStatus: @ 80F67D4 +.4byte 0 @ STATUS_NONE +.4byte STATUS_SPRITE_MUZZLED @ STATUS_MUZZLED + +.global gUnknown_80F67DC +gUnknown_80F67DC: @ 80F67DC +@ u16[4]. They are sound effect IDs +.byte 0xD8, 0x00, 0xD9, 0x00 +.byte 0xD9, 0x00, 0x73, 0x01 + +.global gUnknown_80F67E4 +gUnknown_80F67E4: @ 80F67E4 +@ u16[4]. They are sound effect IDs +.byte 0xDA, 0x00, 0xDB, 0x00 +.byte 0xDB, 0x00, 0x74, 0x01 + +.global gUnknown_80F67EC +gUnknown_80F67EC: @ 80F67EC +@ s32[8] +.byte 0xff, 0xff, 0xff, 0xff, 0x4b, 0x01, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff +.byte 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x00, 0x00, 0x00 + +.global gUnknown_80F680C +gUnknown_80F680C: @ 80F680C +@ u32[8] +.byte 0xff, 0xff, 0xff, 0xff, 0x4b, 0x01, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff +.byte 0xb8, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x00, 0x00, 0x00 + +.global gUnknown_80F682C +gUnknown_80F682C: @ 80F682C +@ u16[8] +.byte 0xe5, 0x03, 0xe5, 0x03, 0xe5, 0x03, 0xa9, 0x01, 0xe5, 0x03, 0xe5, 0x03, 0xaa, 0x01, 0xe5, 0x03 + +.global gUnknown_80F683C +gUnknown_80F683C: @ 80F683C +@ replacing .incbin "baserom.gba", 0xF683C, 0x14 +.byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 +.byte 0x69, 0x72, 0x30, 0x00 + +.global gUnknown_80F6850 +gUnknown_80F6850: @ 80F6850 +@ replacing .incbin "baserom.gba", 0xF6850, 0x10 +.byte 0x9e, 0x01, 0xa1, 0x01, 0xa2, 0x01, 0xa3, 0x01 +.byte 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00 + +.global gSpeedTurns +gSpeedTurns: @ 80F6860 +@ replacing .incbin "baserom.gba", 0xF6860, 0x104 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00 +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +.byte 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +.byte 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +.byte 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x00 +.byte 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00 +.byte 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x14, 0x00 +.byte 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x17, 0x00, 0x18, 0x00, 0x00, 0x00 +.byte 0x19, 0x00, 0x1a, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x1d, 0x00, 0x1e, 0x00, 0x00, 0x00 +.byte 0x1f, 0x00, 0x20, 0x00, 0x21, 0x00, 0x00, 0x00, 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x00, 0x00 +.byte 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x29, 0x00, 0x2a, 0x00, 0x2b, 0x00 +.byte 0x2c, 0x00, 0x2d, 0x00, 0x2e, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00 +.byte 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x3a, 0x00, 0x3b, 0x00 +.byte 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 +.byte 0x69, 0x72, 0x30, 0x00 + +.global gUnknown_80F6964 +gUnknown_80F6964: @ 80F6964 +@ replacing .incbin "baserom.gba", 0xF6964, 0x18 +.byte 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x12, 0x00 +.byte 0x12, 0x00, 0x31, 0x00, 0x2c, 0x00, 0x12, 0x00 + +.global gUnknown_80F697C +gUnknown_80F697C: @ 80F697C +.byte 0x58, 0x00, 0x00, 0x00 +.string "pksdir0" +.align 2,0 diff --git a/include/constants/dungeon_action.h b/include/constants/dungeon_action.h index fcc22457f..edd1d28b1 100644 --- a/include/constants/dungeon_action.h +++ b/include/constants/dungeon_action.h @@ -13,6 +13,7 @@ enum DungeonAction ACTION_PLACE_ITEM = 0x8, // Some actions are different between the leader and AI-controlled Pokémon. ACTION_PICK_UP_PLAYER = 0x9, // Picking up an item underfoot. + ACTION_UNKA = 0xA, ACTION_THROW_ITEM_PLAYER = 0xB, ACTION_SHOW_INFO = 0xC, ACTION_EAT_BERRY_SEED_DRINK = 0xD, @@ -44,6 +45,7 @@ enum DungeonAction ACTION_USE_ORB = 0x31, ACTION_REGULAR_ATTACK = 0x32, ACTION_UNSET_MOVE = 0x33, + ACTION_UNK34 = 0x34, ACTION_UNK35 = 0x35, ACTION_GIVE_ITEM = 0x36, ACTION_TAKE_ITEM = 0x37, diff --git a/include/dungeon_items.h b/include/dungeon_items.h index f1bafd243..0322425d5 100644 --- a/include/dungeon_items.h +++ b/include/dungeon_items.h @@ -14,8 +14,8 @@ void sub_8045C18(u8 *buffer, Item *item); void CreateItemWithStickyChance(Item *item, u8 itemID, u32 forceSticky); void CreateFloorItems(void); void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg); -bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2); -bool8 sub_80461C8(DungeonPos *pos, bool8 a2); +bool8 AddItemToDungeonAt(DungeonPos *pos, Item *item, bool8 a2); +bool8 RemoveItemFromDungeonAt(DungeonPos *pos, bool8 a2); bool8 sub_80462AC(Entity * entity, u8 hallucinating, u8 a2, u8 a3, u8 a4); const u8 *sub_80464AC(Item *item); void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item); diff --git a/ld_script.txt b/ld_script.txt index e1d58f851..71c5e973e 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -543,6 +543,8 @@ SECTIONS { data/data_80F59C8_0.o(.rodata); src/dungeon_map.o(.rodata); src/code_8040094_1.o(.rodata); + data/data_80F59C8_5.o(.rodata); + src/dungeon_items.o(.rodata); data/data_80F59C8.o(.rodata); src/dungeon_message.o(.rodata); src/dungeon_move.o(.rodata); diff --git a/src/code_8042B34.c b/src/code_8042B34.c index b946e8a4b..4fcad96d3 100644 --- a/src/code_8042B34.c +++ b/src/code_8042B34.c @@ -61,8 +61,6 @@ EWRAM_INIT DungeonPos gPlayerDotMapPosition = {100, 100}; static EWRAM_INIT struct UnkStruct_203B414 *sUnknown_203B414 = NULL; EWRAM_INIT Dungeon *gDungeon = NULL; EWRAM_INIT u8 *gSerializedData_203B41C = NULL; -EWRAM_INIT u8 gUnknown_203B420[8] = {0x15, 0x00, 0x16, 0x00, 0x15, 0x00, 0x16, 0x00}; // Could be a different file? -EWRAM_INIT u8 gUnknown_203B428[8] = {0x02, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02}; // Could be a different file? struct UnkStruct_80F6624 { diff --git a/src/code_8044CC8.c b/src/code_8044CC8.c index e83a382d3..27e8a4746 100644 --- a/src/code_8044CC8.c +++ b/src/code_8044CC8.c @@ -25,8 +25,8 @@ extern const unkStr_80F7C54 gUnknown_80F7C54[65]; extern u8 *gUnknown_80F91EC[]; extern bool8 sub_8045888(Entity *); extern u8 GetFloorType(void); -void sub_80460F8(DungeonPos *, Item *, u32); -bool8 sub_80461C8(DungeonPos *, u32); +void AddItemToDungeonAt(DungeonPos *, Item *, u32); +bool8 RemoveItemFromDungeonAt(DungeonPos *, u32); Item * sub_8044CC8(Entity *param_1, ActionParameter *param_2, UNUSED s32 a3) { @@ -74,7 +74,7 @@ bool8 sub_8044D40(ActionContainer *param_1,s32 index) if (puVar1->actionUseIndex != 0x80) { return FALSE; } - sub_80461C8(&puVar1->itemPos,1); + RemoveItemFromDungeonAt(&puVar1->itemPos,1); } return TRUE; } @@ -109,7 +109,7 @@ void sub_8044DF0(Entity *entity, s32 index, u32 unused) info = GetEntInfo(entity); item = sub_8044D90(entity,index,unused); if ((info->action).actionParameters[0].actionUseIndex == 0x80) { - sub_80461C8(&(info->action).actionParameters[0].itemPos,1); + RemoveItemFromDungeonAt(&(info->action).actionParameters[0].itemPos,1); } else { item->id = ITEM_NOTHING; @@ -134,10 +134,10 @@ void sub_8044E24(Entity *entity,int index,u32 unused) if (info->action.actionParameters[index].actionUseIndex == 0x80) { item = *itemPtr; pos = &info->action.actionParameters[index].itemPos; - sub_80461C8(pos,1); + RemoveItemFromDungeonAt(pos,1); item.quantity = itemPtr->id - 125; item.id = ITEM_TM_USED_TM; - sub_80460F8(pos,&item,1); + AddItemToDungeonAt(pos,&item,1); } else { itemPtr->quantity = itemPtr->id - 125; diff --git a/src/code_8066D04.c b/src/code_8066D04.c index 083ff0bea..178a3ce73 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -224,7 +224,7 @@ void HandleGiveItemAction(Entity *param_1) item2.flags &= ~(ITEM_FLAG_SET); sub_8044DF0(param_1,0,100); if (bVar3) { - sub_80460F8(¶m_1->pos,&item1,1); + AddItemToDungeonAt(¶m_1->pos,&item1,1); } else { AddItemToInventory(&item1); @@ -382,7 +382,7 @@ void HandlePlaceItemAction(Entity *entity) else { item->flags &= ~(ITEM_FLAG_SET); sub_8045BF8(gFormatBuffer_Items[0],item); - if (sub_80460F8(&entity->pos,item,1) == 0) { + if (AddItemToDungeonAt(&entity->pos,item,1) == 0) { LogMessageByIdWithPopupCheckUser(entity,*gUnknown_80F8E04); } else { @@ -428,9 +428,9 @@ void sub_8066E14(Entity *entity) newItems[0].flags &= ~(ITEM_FLAG_SET); newItems[1].flags &= ~(ITEM_FLAG_SET); - sub_80461C8(&info->action.actionParameters[0].itemPos,1); + RemoveItemFromDungeonAt(&info->action.actionParameters[0].itemPos,1); ZeroOutItem(item[1]); - if (!sub_80460F8(&info->action.actionParameters[0].itemPos,&newItems[1],1)) { + if (!AddItemToDungeonAt(&info->action.actionParameters[0].itemPos,&newItems[1],1)) { LogMessageByIdWithPopupCheckUser(entity,*gNothingCanBePutDownHere); } else { @@ -480,9 +480,9 @@ void sub_8066FA4(Entity *entity) newItems[0].flags &= ~(ITEM_FLAG_SET); newItems[1].flags &= ~(ITEM_FLAG_SET); - sub_80461C8(&entity->pos,1); + RemoveItemFromDungeonAt(&entity->pos,1); ZeroOutItem(item[0]); - if (!sub_80460F8(&entity->pos, &newItems[0],1)) { + if (!AddItemToDungeonAt(&entity->pos, &newItems[0],1)) { LogMessageByIdWithPopupCheckUser(entity,*gNothingCanBePutDownHere); } else { @@ -560,7 +560,7 @@ void sub_80671A0(Entity *entity) if (info->action.actionParameters[0].actionUseIndex == 0x80) { item = NULL; - sub_80461C8(&info->action.actionParameters[0].itemPos, 1); + RemoveItemFromDungeonAt(&info->action.actionParameters[0].itemPos, 1); } r7 = TRUE; @@ -577,7 +577,7 @@ void sub_80671A0(Entity *entity) else { if (info->action.actionParameters[0].actionUseIndex == 0x80) { newItem.quantity--; - sub_80460F8(&info->action.actionParameters[0].itemPos, &newItem, 1); + AddItemToDungeonAt(&info->action.actionParameters[0].itemPos, &newItem, 1); } else { item->quantity--; diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index d2e6eb8a3..1c06e33c5 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -146,7 +146,7 @@ void sub_8073D14(Entity *entity) } AddToTeamMoney(GetMoneyValue(groundItem)); sub_8045BF8(gFormatBuffer_Items[0], groundItem); - sub_80461C8(&entity->pos, 1); + RemoveItemFromDungeonAt(&entity->pos, 1); DisplayDungeonLoggableMessageTrue(entity, gMonPickedUpItem); } else { @@ -208,7 +208,7 @@ void sub_8073D14(Entity *entity) carriedItems[newInventoryId]->flags |= ITEM_FLAG_STICKY; sub_8045BF8(gFormatBuffer_Items[0], groundItem); - sub_80461C8(&entity->pos, 1); + RemoveItemFromDungeonAt(&entity->pos, 1); PlaySoundEffect(0x14A); if (inventoryIds[newInventoryId] <= -1) DisplayDungeonLoggableMessageTrue(entity, gMonPickedUpItem2); @@ -239,7 +239,7 @@ void sub_8073D14(Entity *entity) if (inventoryIds[i] <= -1) { _entityInfo->heldItem = *groundItem; sub_8045BF8(gFormatBuffer_Items[0], groundItem); - sub_80461C8(&entity->pos, 1); + RemoveItemFromDungeonAt(&entity->pos, 1); DisplayDungeonLoggableMessageTrue(entity, gMonPickedUpItem2); } else if (AddItemToInventory(groundItem)) { @@ -248,7 +248,7 @@ void sub_8073D14(Entity *entity) } else { sub_8045BF8(gFormatBuffer_Items[0], groundItem); - sub_80461C8(&entity->pos, 1); + RemoveItemFromDungeonAt(&entity->pos, 1); DisplayDungeonLoggableMessageTrue(entity, gMonPickedUpItemToolbox); } } diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index ccad2b1b2..8ff8df2f6 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -53,7 +53,7 @@ extern struct DungeonPos *gUnknown_8107178[3]; extern void sub_807E1A0(Entity *pokemon,Entity *target,u8 moveType,s32 param_4,s32 param_5); // TODO: param_4 should be s16 extern void sub_804216C(Entity *pokemon, Entity *target, u32 r2); -extern void sub_80461C8(DungeonPos *, u32); +extern void RemoveItemFromDungeonAt(DungeonPos *, u32); extern void sub_804218C(Entity *pokemon, Entity *target); EWRAM_INIT u32 gUnknown_203B444[3] = {0x28, 0x28, 0x50}; @@ -74,7 +74,7 @@ void sub_807BB78(Entity *pokemon); extern void sub_803F580(u32); bool8 sub_808384C(DungeonPos *, DungeonPos *); u8 sub_8083660(DungeonPos *); -void sub_80460F8(DungeonPos *, Item *, u32); +void AddItemToDungeonAt(DungeonPos *, Item *, u32); void sub_80462AC(Entity * ,u32, u32, u8, u32); extern void ShowDungeonMapAtPos(s32, s32); @@ -502,7 +502,7 @@ void HandleTrawlOrbAction(Entity *user, Entity *target) for (i = 0; i < itemsCount; i++) { if (EntityIsValid(&itemEntities[i])) { - sub_80461C8(&itemEntities[i].pos, 1); + RemoveItemFromDungeonAt(&itemEntities[i].pos, 1); ShowDungeonMapAtPos(itemEntities[i].pos.x, itemEntities[i].pos.y); itemVelocity[i].x = (((targetTilePos[i].x * 24 + 4) * 256) - itemEntities[i].pixelPos.x) / 60; itemVelocity[i].y = (((targetTilePos[i].y * 24 + 4) * 256) - itemEntities[i].pixelPos.y) / 60; @@ -533,7 +533,7 @@ void HandleTrawlOrbAction(Entity *user, Entity *target) for (i = 0; i < itemsCount; i++) { if (targetTilePos[i].x >= 0) { - sub_80460F8(&targetTilePos[i], GetItemData(&itemEntities[i]), 1); + AddItemToDungeonAt(&targetTilePos[i], GetItemData(&itemEntities[i]), 1); ShowDungeonMapAtPos(targetTilePos[i].x, targetTilePos[i].y); hasTrawled = TRUE; } @@ -834,7 +834,7 @@ void HandleExplosion(Entity *pokemon,Entity *target,DungeonPos *param_3,s32 para } entity2 = tile->object; if (((entity2 != NULL) && (entity2 != target)) && (GetEntityType(entity2) == ENTITY_ITEM)) { - sub_80461C8(&pos, 0); + RemoveItemFromDungeonAt(&pos, 0); } entity2 = tile->monster; if (((entity2 != NULL) && (entity2 != target)) && (GetEntityType(entity2) == ENTITY_MONSTER)) { diff --git a/src/code_807E5AC.c b/src/code_807E5AC.c index 467fecef3..df43219a5 100644 --- a/src/code_807E5AC.c +++ b/src/code_807E5AC.c @@ -38,7 +38,7 @@ extern u8 gUnknown_203B40D; extern OpenedFile *gUnknown_202ECA0; extern void sub_804178C(u32); -extern bool8 sub_80461C8(DungeonPos *, u32); +extern bool8 RemoveItemFromDungeonAt(DungeonPos *, u32); extern void sub_80429D8(Entity *r0); extern s32 GetMonsterApparentID(Entity *pokemon, s32 id); extern void sub_803E874(bool8 r10, s32 r9); @@ -46,7 +46,7 @@ extern void GetWeatherName(u8 *dst, u8 weatherId); extern s32 CalculateStatusTurns(Entity *target, const s16 *turnRange, bool8 factorCurerSkills); extern void sub_80838EC(u8 *a); extern bool8 sub_8044B28(void); -extern void sub_80460F8(DungeonPos *, Item *, u32); +extern void AddItemToDungeonAt(DungeonPos *, Item *, u32); void sub_807E7FC(bool8 arg0); void sub_807EFFC(bool8 arg0); @@ -498,11 +498,11 @@ void sub_807EFFC(bool8 arg0) Item *itemPtr = GetItemData(tile->object); if (!ItemInShop(itemPtr)) { Item item = *itemPtr; - sub_80461C8(&pos, 1); + RemoveItemFromDungeonAt(&pos, 1); if (CanSellItem(item.id)) { item.flags |= ITEM_FLAG_IN_SHOP; } - sub_80460F8(&pos, &item, 1); + AddItemToDungeonAt(&pos, &item, 1); } } } diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index 6eba3934a..e7d67616a 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -3715,7 +3715,7 @@ void sub_808B1CC(u8 itemID) (sub_80860A8(ITEM_MUSIC_BOX) == 0)) { ItemIdToSlot(&item,itemID,0); pos.y--; - sub_80460F8(&pos,&item,1); + AddItemToDungeonAt(&pos,&item,1); } sub_8049ED4(); ShowWholeRevealedDungeonMap(); diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 02d76ddcb..a1559dbf1 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -21,7 +21,7 @@ extern const u8 gUnknown_80F6DCC[]; extern struct FileArchive gDungeonFileArchive; -extern void sub_80460F8(DungeonPos *, Item *, u32); +extern void AddItemToDungeonAt(DungeonPos *, Item *, u32); extern s32 sub_803DA20(s16 species); extern void sub_8049840(void); extern void sub_80429FC(DungeonPos *r0); @@ -6105,7 +6105,7 @@ static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) item.quantity = quantity; } - sub_80460F8(&pos, &item, 1); + AddItemToDungeonAt(&pos, &item, 1); } // s16 species memes strike again. Will the fix ever be discovered? diff --git a/src/dungeon_items.c b/src/dungeon_items.c index e7892e579..0ccc45613 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "dungeon_items.h" #include "code_803E668.h" #include "code_8041AD0.h" @@ -26,21 +27,20 @@ #include "code_80450F8.h" #include "structs/str_item_text.h" -extern s32 gUnknown_810A3F0[]; -extern u8 *gUnknown_80FA408[]; -extern u8 *gUnknown_810531C[]; -extern u8 *gUnknown_8105360[]; -extern u8 *gUnknown_81053A8[]; -extern u8 *gUnknown_8105434[]; -extern u8 *gPickedUpItemToolbox[]; -extern u8 *gMonTerrifiedCouldntPickUpItem[]; -extern u8 *gPickedUpItem2[]; -extern u8 *gMonCouldntPickUpItem[]; -extern u8 *gPickedUpItem[]; -extern u8 *gMonSteppedOnItem[]; -extern struct unkStruct_8090F58 gUnknown_80F699C; -extern struct unkStruct_8090F58 gUnknown_80F69A8; -extern struct unkStruct_8090F58 gUnknown_80F6990; +extern SpriteOAM gUnknown_202EDC0; + +extern const s32 gUnknown_810A3F0[]; +extern const u8 *gUnknown_80FA408[]; +extern const u8 *gUnknown_810531C[]; +extern const u8 *gUnknown_8105360[]; +extern const u8 *gUnknown_81053A8[]; +extern const u8 *gUnknown_8105434[]; +extern const u8 *gPickedUpItemToolbox[]; +extern const u8 *gMonTerrifiedCouldntPickUpItem[]; +extern const u8 *gPickedUpItem2[]; +extern const u8 *gMonCouldntPickUpItem[]; +extern const u8 *gPickedUpItem[]; +extern const u8 *gMonSteppedOnItem[]; extern const u8 *const gUnknown_80FED30; extern const DungeonPos gUnknown_80F4468[]; extern const u8 *const gItemFellOnGround; @@ -64,13 +64,16 @@ extern u32 GetRandomFloorItem(u32); static void MusicBoxCreation(void); static u8 sub_8046D70(void); -extern SpriteOAM gUnknown_202EDC0; -extern u8 gUnknown_203B420[]; -extern u8 gUnknown_203B428[]; +static EWRAM_INIT u8 sUnkItemTileNums[8] = {0x15, 0x00, 0x16, 0x00, 0x15, 0x00, 0x16, 0x00}; +static EWRAM_INIT u8 sUnkItemMatrixNums[8] = {0x02, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02}; static void sub_8046734(Entity *entity, DungeonPos *pos); static void sub_8046CE4(Item *item,s32 param_2); +static const struct unkStruct_8090F58 gUnknown_80F6990 = {1, 1, 0, 0, 1}; +static const struct unkStruct_8090F58 gUnknown_80F699C = {0, 0, 0, 0, 1}; +static const struct unkStruct_8090F58 gUnknown_80F69A8 = {0, 0, 0, 0, 0}; + void sub_8045BF8(u8 *buffer, Item *item) { sub_8090E14(buffer, item, &gUnknown_80F699C); @@ -166,7 +169,7 @@ void CreateFloorItems(void) if (shopFlag) { item.flags |= flag; } - sub_80460F8(&pos,&item,TRUE); + AddItemToDungeonAt(&pos,&item,TRUE); } } } @@ -208,7 +211,7 @@ void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) PlaySoundEffect(0x14c); AddToTeamMoney(GetMoneyValue(tileItem)); sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); + RemoveItemFromDungeonAt(pos,TRUE); LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem); TryDisplayItemPickupTutorialMessage(tileItem->id); } @@ -275,7 +278,7 @@ void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) inventoryItems[index]->flags |= ITEM_FLAG_STICKY; } sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); + RemoveItemFromDungeonAt(pos,TRUE); PlaySoundEffect(0x14a); if (inventoryIds[index] < 0) { LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); @@ -306,7 +309,7 @@ void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) if (inventoryIds[i] < 0) { leaderInfo->heldItem = *tileItem; sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); + RemoveItemFromDungeonAt(pos,TRUE); LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItem2); } else if (AddItemToInventory(tileItem) != 0) { @@ -315,7 +318,7 @@ void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) } else { sub_8045BF8(gFormatBuffer_Items[0],tileItem); - sub_80461C8(pos,1); + RemoveItemFromDungeonAt(pos,TRUE); LogMessageByIdWithPopupCheckUser(leader,*gPickedUpItemToolbox); } TryDisplayItemPickupTutorialMessage(tileItem->id); @@ -323,19 +326,19 @@ void PickUpItemFromPos(struct DungeonPos *pos, bool8 printMsg) } } -bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) +bool8 AddItemToDungeonAt(DungeonPos *pos, Item *item, bool8 a2) { s32 i, count; Tile *tile; - Entity *entity = sub_8045708(pos); + Entity *itemEntity = sub_8045708(pos); - if (entity == NULL) + if (itemEntity == NULL) return FALSE; - *entity->axObj.info.item = *item; - entity->axObj.info.item->flags &= ~(ITEM_FLAG_SET); - entity->isVisible = TRUE; + *itemEntity->axObj.info.item = *item; + itemEntity->axObj.info.item->flags &= ~(ITEM_FLAG_SET); + itemEntity->isVisible = TRUE; tile = GetTileMut(pos->x, pos->y); - tile->object = entity; + tile->object = itemEntity; if ((tile->terrainType & TERRAIN_TYPE_SHOP) && CanSellItem(item->id)) { if (item->flags & ITEM_FLAG_IN_SHOP) { if (a2) { @@ -357,7 +360,7 @@ bool8 sub_80460F8(DungeonPos *pos, Item *item, bool8 a2) return TRUE; } -bool8 sub_80461C8(DungeonPos *pos, bool8 a2) +bool8 RemoveItemFromDungeonAt(DungeonPos *pos, bool8 a2) { s32 i, count; Item *item; @@ -433,8 +436,8 @@ bool8 sub_80462AC(Entity * entity, u8 hallucinating, u8 a2, u8 a3, u8 a4) else { tileNum = GetItemIconId(entity->axObj.info.item); if (a3 != 0xFF && tileNum == 0) { - tileNum = gUnknown_203B420[a3]; - SpriteSetMatrixNum(&gUnknown_202EDC0, gUnknown_203B428[a3] * 8); + tileNum = sUnkItemTileNums[a3]; + SpriteSetMatrixNum(&gUnknown_202EDC0, sUnkItemMatrixNums[a3] * 8); } SpriteSetPalNum(&gUnknown_202EDC0, GetItemPalette(entity->axObj.info.item->id)); } @@ -461,7 +464,6 @@ const u8 *sub_80464AC(Item *item) void sub_80464C8(Entity *entity, DungeonPos *pos, Item *item) { - s32 x, y; Entity itemEntity; @@ -517,7 +519,7 @@ void sub_804652C(Entity *entity1, Entity *entity2, Item *item, bool8 a3, Dungeon if (GetTerrainType(tile) != TERRAIN_TYPE_WALL && !(tile->terrainType & TERRAIN_TYPE_STAIRS) && tile->object == NULL) { sub_8046734(entity2, &localPos); localPos2 = localPos; - if (GetTerrainType(tile) == (TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL) || (sub_80460F8(&localPos, item, TRUE))) { + if (GetTerrainType(tile) == (TERRAIN_TYPE_SECONDARY | TERRAIN_TYPE_NORMAL) || (AddItemToDungeonAt(&localPos, item, TRUE))) { var_24 = TRUE; } break; @@ -714,7 +716,7 @@ void sub_804687C(Entity *entity, DungeonPos *pos1, DungeonPos *pos2, Item *item, for (i = 0; i < count; i++) { if (targetTilePos[i].x >= 0) { - sub_80460F8(&targetTilePos[i], &item[i], TRUE); + AddItemToDungeonAt(&targetTilePos[i], &item[i], TRUE); } } } diff --git a/src/dungeon_main.c b/src/dungeon_main.c index 0bfc8ab63..804f6c260 100644 --- a/src/dungeon_main.c +++ b/src/dungeon_main.c @@ -184,7 +184,7 @@ void DungeonHandlePlayerInput(void) ShowDungeonStairsMenu(GetLeader()); ResetRepeatTimers(); ResetUnusedInputStruct(); - if (GetLeaderActionId() != 0) { + if (GetLeaderActionId() != ACTION_NOTHING) { return; } } @@ -1307,7 +1307,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) sub_806752C(GetLeaderActionContainer()); SetLeaderActionToNothing(TRUE); } - else if (GetLeaderActionId() == 0x34) { + else if (GetLeaderActionId() == ACTION_UNK34) { sub_8067768(GetLeaderActionContainer()); SetLeaderActionToNothing(TRUE); } @@ -1329,7 +1329,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) if (EntityIsValid(teamMon)) { if (i == GetLeaderActionContainer()->actionParameters[0].actionUseIndex) { gTeamMenuChosenId = count; - if (GetLeaderActionId() != 0) { + if (GetLeaderActionId() != ACTION_NOTHING) { sub_806A2BC(teamMon, 0); } break; @@ -1339,7 +1339,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) } } - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } else if (chosenOption == MAIN_MENU_MOVES) { @@ -1439,7 +1439,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) } sub_806A2BC(GetLeader(), 0); ChangeDungeonCameraPos(&GetLeader()->pos, 0, 1, 1); - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } else if (chosenOption == MAIN_MENU_GROUND) { @@ -1464,43 +1464,43 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) } action = GetLeaderActionId(); - if (action == 0xC) { + if (action == ACTION_SHOW_INFO) { sub_8044D90(GetLeader(), 0, 0x10)->flags |= ITEM_FLAG_UNPAID; DungeonShowItemDescription(GetLeaderActionContainer()); SetLeaderActionToNothing(TRUE); } - else if (action == 0x35) { + else if (action == ACTION_UNK35) { item = sub_8044D90(GetLeader(), 0, 0x11); if (!sub_8048A68(GetLeader(), item)) { SetLeaderActionToNothing(TRUE); } } - else if (action == 0x10) { + else if (action == ACTION_UNK10) { item = sub_8044D90(GetLeader(), 0, 0x12); if (!sub_8048950(GetLeader(), item)) { SetLeaderActionToNothing(TRUE); } } - else if (action == 0x2C) { + else if (action == ACTION_USE_LINK_BOX) { item = sub_8044D90(GetLeader(), 0, 0x13); if (!sub_8048B9C(GetLeader(), item)) { SetLeaderActionToNothing(TRUE); } } - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } else if (GetEntityType(tileObject) == ENTITY_TRAP) { SetLeaderActionToNothing(TRUE); ShowDungeonTileMenu(GetLeader()); - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } } else if (tile->terrainType & TERRAIN_TYPE_STAIRS) { SetLeaderActionToNothing(TRUE); ShowDungeonStairsMenu(GetLeader()); - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; } else { @@ -1514,7 +1514,7 @@ static void ShowMainMenu(bool8 fromBPress, bool8 a1) ShowDungeonOthersMenu(); if (gDungeon->unk4) break; - if (GetLeaderActionId() != 0) + if (GetLeaderActionId() != ACTION_NOTHING) break; r10 = -1; } diff --git a/src/dungeon_menu_items.c b/src/dungeon_menu_items.c index b5a3242eb..848c3cec6 100644 --- a/src/dungeon_menu_items.c +++ b/src/dungeon_menu_items.c @@ -82,7 +82,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 a2, bool8 a3, Wind static s32 sub_8060800(WindowHeader *a0, s32 a1); static bool8 sub_8060860(s32 a0); static void sub_8060890(DungeonPos *a0); -static void sub_8060900(Entity *a0); +static void SetSubMenuActions(Entity *a0); static void ChosenSubMenuToAction(ActionContainer *a0); static s32 sub_8060D64(s16 *a0, bool8 a1, bool8 a2, bool8 a3, Entity *a4); @@ -110,7 +110,7 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) { s32 i, i_r6; s32 r8; - s32 r9 = 0; + s32 inputAction = 0; u8 var_34 = 1; u8 var_30 = 0; @@ -161,7 +161,7 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) s32 id; Entity *r4; - r9 = 0; + inputAction = 0; for (i = 0; i < INVENTORY_SIZE; i++) { Item *item = &gTeamInventoryRef->teamItems[i]; if (item->flags & ITEM_FLAG_EXISTS && item->flags & ITEM_FLAG_UNPAID) { @@ -261,46 +261,46 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) if ((gRealInputs.pressed & A_BUTTON) || gDungeonMenu.unk28.a_button) { PlayDungeonConfirmationSE(); sub_8060890(&a0->pos); - r9 = 1; + inputAction = 1; break; } if (gRealInputs.pressed & START_BUTTON) { PlayDungeonStartButtonSE(); sub_8060890(&a0->pos); - r9 = 3; + inputAction = 3; break; } if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { PlayDungeonCancelSE(); - r9 = 2; + inputAction = 2; break; } } else { sub_8060890(&a0->pos); - r9 = 1; + inputAction = 1; break; } } AddMenuCursorSprite(&gDungeonMenu); DungeonRunFrameActions(0x14); if (sUnknown_202F248[gDungeonMenu.unk1E] <= 1 && !(gTeamInventoryRef->teamItems[0].flags & ITEM_FLAG_EXISTS)) { - r9 = 2; + inputAction = 2; } - if (r9 == 2) { + if (inputAction == 2) { sub_803EAF0(0, NULL); - r9 = 1; + inputAction = 1; break; } - else if (r9 == 0) { + else if (inputAction == 0) { continue; } - else if (r9 == 3) { + else if (inputAction == 3) { SetMonsterActionFields(&a0Info->action, 0xC); a0Info->action.actionParameters[0] = sUnknownActionUnk4; sub_803EAF0(0, NULL); - r9 = 0; + inputAction = 0; break; } else { @@ -308,11 +308,11 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) if (var_2C != 0) { a0Info->action.actionParameters[1] = sUnknownActionUnk4; sub_803EAF0(0, NULL); - r9 = 0; + inputAction = 0; break; } - sub_8060900(a0); + SetSubMenuActions(a0); sub_8060800(&header, gDungeonMenu.unk1E); CreateDungeonMenuSubWindow(&windows.id[0], 0x16); while (1) { @@ -330,27 +330,27 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) if (CanSubMenuItemBeChosen(gDungeonMenu.menuIndex)) { PlayDungeonConfirmationSE(); ChosenSubMenuToAction(&a0Info->action); - r9 = 0; + inputAction = 0; break; } PlayDungeonCancelSE(); } if ((gRealInputs.pressed & B_BUTTON) || gDungeonMenu.unk28.b_button) { PlayDungeonCancelSE(); - r9 = 1; + inputAction = 1; break; } } AddMenuCursorSprite(&gDungeonMenu); DungeonRunFrameActions(0x14); gDungeon->unk181e8.unk18212 = 0; - if (r9 != 1 || var_30 != 0) { - if (a0Info->action.action == 0x37 || a0Info->action.action == 0x38 || a0Info->action.action == 0x3E) { + if (inputAction != 1 || var_30 != 0) { + if (a0Info->action.action == ACTION_TAKE_ITEM || a0Info->action.action == ACTION_USE_ITEM || a0Info->action.action == ACTION_UNK3E) { // Hm... int newAction = sUnknownActionUnk4.actionUseIndex - 0x90; a0Info->action.actionParameters[0].actionUseIndex = newAction; sub_803EAF0(0, 0); - r9 = 0; + inputAction = 0; break; } else if (a0Info->action.action == ACTION_GIVE_ITEM) { @@ -358,7 +358,7 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) if (ShowDungeonToWhichMonMenu(&teamId, WHICH_MENU_ITEMS) != NULL) { a0Info->action.actionParameters[1].actionUseIndex = teamId; sub_803EAF0(0, 0); - r9 = 0; + inputAction = 0; break; } sub_803EAF0(0, NULL); @@ -366,7 +366,7 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) } else { sub_803EAF0(0, 0); - r9 = 0; + inputAction = 0; break; } } @@ -377,12 +377,12 @@ bool8 ShowDungeonItemsMenu(Entity * a0, struct UnkMenuBitsStruct *a1) sub_803E708(2, 0x61); sub_804AA60(); sub_803E708(2, 0x61); - return r9; + return inputAction; } static const struct unkStruct_8090F58 gUnknown_8106B60 = {1, 1, 0, 80, 1}; -static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, bool8 a3, WindowTemplates *windows, WindowHeader *a5) +static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, bool8 a3, WindowTemplates *windows, WindowHeader *header) { s32 i, x, y; s32 r10; @@ -400,7 +400,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, b EntityInfo *a1Info; a1Info = GetEntInfo(a1); - r10 = sub_8060800(a5, a0); + r10 = sub_8060800(header, a0); gDungeonMenu.menuIndex = sUnknown_202F240; gDungeonMenu.unk1A = 0; gDungeonMenu.unk1E = a0; @@ -415,7 +415,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, b case 1: windows->id[0].unk10 = 0x10; windows->id[0].height = 0x10; - a5->width = 0xC; + header->width = 0xC; gDungeonMenu.firstEntryY = 0x10; gDungeonMenu.unk1C = 0xA; gDungeon->unk181e8.unk18212 = 1; @@ -423,7 +423,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, b case 2: windows->id[0].unk10 = 4; windows->id[0].height = 4; - a5->width = 6; + header->width = 6; gDungeonMenu.firstEntryY = 0x12; gDungeonMenu.unk1C = 1; break; @@ -431,7 +431,7 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, b default: windows->id[0].unk10 = 4; windows->id[0].height = 4; - a5->width = 0xC; + header->width = 0xC; gDungeonMenu.firstEntryY = 0x12; gDungeonMenu.unk1C = 1; break; @@ -540,9 +540,9 @@ static void PrintOnDungeonItemsMenu(s32 a0, Entity *a1, bool8 showWhichWindow, b } } -static s32 sub_8060800(WindowHeader *a0, s32 a1) +static s32 sub_8060800(WindowHeader *header, s32 a1) { - s32 i, r1, r2, r3; + s32 i, r1, count, currId; r1 = 0; for (i = 0; i < sUnknown_202F258; i++) { @@ -552,19 +552,19 @@ static s32 sub_8060800(WindowHeader *a0, s32 a1) } if (sUnknown_202F248[a1] <= 1) { - r3 = a1; - r2 = r1; + currId = a1; + count = r1; r1 = 0; } else { - r3 = a1 - r1; - r2 = sUnknown_202F258 - r1; + currId = a1 - r1; + count = sUnknown_202F258 - r1; } - if (a0 != NULL) { - a0->count = r2; - a0->currId = r3; - a0->f3 = 0; + if (header != NULL) { + header->count = count; + header->currId = currId; + header->f3 = 0; } return r1; @@ -601,7 +601,7 @@ static void sub_8060890(DungeonPos *a0) sUnknownActionUnk4.itemPos.y = a0->y; } -static void sub_8060900(Entity *a0) +static void SetSubMenuActions(Entity *a0) { u16 val_sub8044DC8; Item *item = sub_8044CC8(a0, &sUnknownActionUnk4, 0xA); @@ -612,23 +612,23 @@ static void sub_8060900(Entity *a0) if (sUnknownActionUnk4.actionUseIndex == 128) { AddActionToDungeonSubMenu(ACTION_PICK_UP_PLAYER, item->id); if (GetItemCategory(item->id) != CATEGORY_POKE) { - bool32 r2 = 0; + bool32 noSpace = FALSE; if (gDungeon->unk644.hasInventory) { if (gTeamInventoryRef->teamItems[INVENTORY_SIZE - 1].flags & ITEM_FLAG_EXISTS) { - r2 = TRUE; + noSpace = TRUE; } } else if (a0Info->heldItem.flags & ITEM_FLAG_EXISTS) { - r2 = TRUE; + noSpace = TRUE; } - if (r2) { - SetActionUnusableInDungeonSubMenu(9); + if (noSpace) { + SetActionUnusableInDungeonSubMenu(ACTION_PICK_UP_PLAYER); } } } if (sUnknownActionUnk4.actionUseIndex == 128 && gDungeon->unk644.hasInventory) { - AddActionToDungeonSubMenu(10, item->id); + AddActionToDungeonSubMenu(ACTION_UNKA, item->id); } val_sub8044DC8 = sub_8044DC8(item); if (val_sub8044DC8 != 0) { @@ -670,7 +670,7 @@ static void sub_8060900(Entity *a0) s32 i; bool32 r8 = FALSE; - AddActionToDungeonSubMenu(0x36, item->id); + AddActionToDungeonSubMenu(ACTION_GIVE_ITEM, item->id); for (i = 0; i < MAX_TEAM_MEMBERS; i++) { Entity *teamMon = gDungeon->teamPokemon[i]; if (EntityIsValid(teamMon)) { @@ -683,21 +683,21 @@ static void sub_8060900(Entity *a0) } } if (!r8) { - SetActionUnusableInDungeonSubMenu(0x36); + SetActionUnusableInDungeonSubMenu(ACTION_GIVE_ITEM); } } } else if (gDungeon->unk644.hasInventory) { if (gTeamInventoryRef->teamItems[INVENTORY_SIZE - 1].flags & ITEM_FLAG_EXISTS) { - AddActionToDungeonSubMenu(0x3E, item->id); + AddActionToDungeonSubMenu(ACTION_UNK3E, item->id); } else { - AddActionToDungeonSubMenu(0x37, item->id); + AddActionToDungeonSubMenu(ACTION_TAKE_ITEM, item->id); } if (CheckVariousConditions(a0)) { - SetActionUnusableInDungeonSubMenu(0x37); - SetActionUnusableInDungeonSubMenu(0x3E); + SetActionUnusableInDungeonSubMenu(ACTION_TAKE_ITEM); + SetActionUnusableInDungeonSubMenu(ACTION_UNK3E); } } @@ -712,19 +712,19 @@ static void sub_8060900(Entity *a0) } if (GetItemCategory(item->id) == CATEGORY_THROWN_LINE) { - AddActionToDungeonSubMenu(0x27, item->id); + AddActionToDungeonSubMenu(ACTION_THROW_STRAIGHT_PLAYER, item->id); } else if (GetItemCategory(item->id) == CATEGORY_THROWN_ARC) { - AddActionToDungeonSubMenu(0x41, item->id); + AddActionToDungeonSubMenu(ACTION_THROW_ARC_PLAYER, item->id); } else { - AddActionToDungeonSubMenu(0xB, item->id); + AddActionToDungeonSubMenu(ACTION_THROW_ITEM_PLAYER, item->id); } if (!MonsterCanThrowItems(a0Info)) { - SetActionUnusableInDungeonSubMenu(0x27); - SetActionUnusableInDungeonSubMenu(0x41); - SetActionUnusableInDungeonSubMenu(0xB); + SetActionUnusableInDungeonSubMenu(ACTION_THROW_STRAIGHT_PLAYER); + SetActionUnusableInDungeonSubMenu(ACTION_THROW_ARC_PLAYER); + SetActionUnusableInDungeonSubMenu(ACTION_THROW_ITEM_PLAYER); } } else { @@ -783,7 +783,7 @@ static void sub_8060900(Entity *a0) } } - AddActionToDungeonSubMenu(0xC, item->id); + AddActionToDungeonSubMenu(ACTION_SHOW_INFO, item->id); sub_8045064(); } diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index 6f3530849..01694763f 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -134,7 +134,7 @@ static Entity* sub_80828E0(s16 id, s16 apparentID, s32 index); static Entity* sub_8082A08(s32 id, s32 apparentID, s32 index); // These externs are from other files -extern void sub_80460F8(DungeonPos *, Item *, u32); +extern void AddItemToDungeonAt(DungeonPos *, Item *, u32); void SaveDungeonState(u8 *buffer, u32 bufLen) { @@ -877,7 +877,7 @@ static void ReadDungeonItems(DataSerializer *seri) ReadTilePos(seri, &pos); if (item.flags & ITEM_FLAG_EXISTS) - sub_80460F8(&pos, &item, 0); + AddItemToDungeonAt(&pos, &item, 0); } } diff --git a/src/trap.c b/src/trap.c index 35624f6ad..963be294b 100644 --- a/src/trap.c +++ b/src/trap.c @@ -764,7 +764,7 @@ void HandlePokemonTrap(Entity *param_1,DungeonPos *pos) local_50.unk4 = 0; local_50.unk10 = 0; if (sub_806B7F8(&local_50, TRUE) != 0) { - sub_80461C8(&local_50.pos,0); + RemoveItemFromDungeonAt(&local_50.pos,0); counter++; } } diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index d1d5f2e9a..9fc3a807c 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -110,6 +110,7 @@ .include "src/code_803D0D8.o" .include "src/code_803E46C.o" .include "src/code_8042B34.o" +.include "src/dungeon_items.o" .include "src/dungeon_map_access.o" .include "src/dungeon_message.o" .include "src/dungeon_move.o" From 11707826efd8974e4fc3ed1aedb84bf6d373a4d7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 13 Mar 2025 20:43:40 +0100 Subject: [PATCH 8/8] remove question mark --- include/structs/str_dungeon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index fe016e4ca..fc3c24c5a 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -150,7 +150,7 @@ enum { ITEM_SPAWN_NORMAL, ITEM_SPAWN_IN_SHOP, ITEM_SPAWN_IN_MONSTER_HOUSE, - ITEM_SPAWN_WALL, // ? + ITEM_SPAWN_WALL, ITEM_SPAWN_TYPES_COUNT };