diff --git a/asm/goronMerchant.s b/asm/goronMerchant.s deleted file mode 100644 index 6f9d3259..00000000 --- a/asm/goronMerchant.s +++ /dev/null @@ -1,61 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_08069718 -sub_08069718: @ 0x08069718 - push {r4, r5, r6, r7, lr} - adds r4, r0, #0 - adds r7, r1, #0 - bl sub_080696BC - adds r6, r0, #0 - ldr r0, _08069754 @ =gSave - adds r0, #0xc0 - ldrh r0, [r0] - cmp r6, r0 - bgt _08069764 - ldr r5, _08069758 @ =gRoomVars - ldrb r0, [r5, #7] - bl sub_0801E7D0 - cmp r0, #0x62 - bhi _0806975C - rsbs r0, r6, #0 - bl ModRupees - ldrb r1, [r5, #7] - movs r0, #0x5c - movs r2, #0 - bl sub_080A7C18 - movs r0, #0 - strb r0, [r5, #6] - strb r0, [r5, #7] - movs r0, #1 - b _0806976E - .align 2, 0 -_08069754: .4byte gSave -_08069758: .4byte gRoomVars -_0806975C: - ldr r0, _08069760 @ =0x00002C1F - b _08069766 - .align 2, 0 -_08069760: .4byte 0x00002C1F -_08069764: - ldr r0, _0806977C @ =0x00002C1E -_08069766: - adds r1, r4, #0 - bl TextboxNoOverlap - movs r0, #0 -_0806976E: - str r0, [r7, #0x14] - ldr r2, _08069780 @ =gActiveScriptInfo - ldrb r1, [r2, #7] - movs r0, #1 - orrs r0, r1 - strb r0, [r2, #7] - pop {r4, r5, r6, r7, pc} - .align 2, 0 -_0806977C: .4byte 0x00002C1E -_08069780: .4byte gActiveScriptInfo diff --git a/data/const/npc/bladeBrothers.s b/data/const/npc/bladeBrothers.s index eba691a7..a2265099 100644 --- a/data/const/npc/bladeBrothers.s +++ b/data/const/npc/bladeBrothers.s @@ -12,7 +12,7 @@ gUnk_081115C0:: @ 081115C0 gUnk_081115D0:: @ 081115D0 .4byte sub_08068AFC - .4byte FUN_08068b2c + .4byte sub_08068b2c .4byte sub_08068B70 gUnk_081115DC:: @ 081115DC diff --git a/data/const/npc/goronMerchant.s b/data/const/npc/goronMerchant.s deleted file mode 100644 index b2c8b139..00000000 --- a/data/const/npc/goronMerchant.s +++ /dev/null @@ -1,18 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2 - -gUnk_08111B88:: @ 08111B88 - .4byte sub_08069584 - .4byte sub_080695AC - .4byte sub_080695E8 - .4byte sub_0806961C - -gUnk_08111B98:: @ 08111B98 - .4byte sub_0806963C - .4byte sub_08069654 - -gUnk_08111BA0:: @ 08111BA0 - .incbin "baserom.gba", 0x111BA0, 0x000001E diff --git a/data/data_080FC8A4.s b/data/data_080FC8A4.s index 41fbfa1c..4ae5d7cd 100644 --- a/data/data_080FC8A4.s +++ b/data/data_080FC8A4.s @@ -48,7 +48,7 @@ gUnk_080FC9B0:: @ 080FC9B0 .4byte sub_0805141C gUnk_080FC9BC:: @ 080FC9BC - .4byte FUN_080515c8 + .4byte sub_080515c8 .4byte sub_080515D4 .4byte sub_080516E0 diff --git a/data/scripts/script_08010264.inc b/data/scripts/script_08010264.inc index 08c027a3..7e020262 100644 --- a/data/scripts/script_08010264.inc +++ b/data/scripts/script_08010264.inc @@ -487,7 +487,7 @@ script_08010860: _0807EA94 _0807E3E8 JumpIfNot script_080108B2 - Call sub_08069718 + Call GoronMerchant_TryToBuyKinstone JumpIfNot script_080108B2 WaitPlayerAction8 _0807EA94 diff --git a/linker.ld b/linker.ld index 219dc8b3..38ee97c7 100644 --- a/linker.ld +++ b/linker.ld @@ -606,7 +606,6 @@ SECTIONS { src/npc/cow.o(.text); src/npc/goron.o(.text); src/npc/goronMerchant.o(.text); - asm/goronMerchant.o(.text); asm/gorman.o(.text); asm/dog.o(.text); src/npc/syrup.o(.text); @@ -640,7 +639,6 @@ SECTIONS { src/npc/ezloCap.o(.text); src/npc/npc4E.o(.text); src/npc/npc4F.o(.text); - asm/npc4E.o(.text); src/npc/clothesRack.o(.text); asm/clothesRack.o(.text); asm/picolyteBottles.o(.text); @@ -1319,7 +1317,7 @@ SECTIONS { data/animations/npc/cow.o(.rodata); data/const/npc/goron.o(.rodata); data/animations/npc/goron.o(.rodata); - data/const/npc/goronMerchant.o(.rodata); + src/npc/goronMerchant.o(.rodata); data/animations/npc/goronMerchant.o(.rodata); data/const/npc/gorman.o(.rodata); data/animations/npc/gorman.o(.rodata); diff --git a/src/enemy/businessScrub.c b/src/enemy/businessScrub.c index 30f0000e..a6fa26a4 100644 --- a/src/enemy/businessScrub.c +++ b/src/enemy/businessScrub.c @@ -469,7 +469,7 @@ bool32 sub_0802915C(Entity* this) { return TRUE; break; case 0x1c: - if (CheckGlobalFlag(0x5a) == 0) + if (CheckGlobalFlag(AKINDO_BOTTLE_SELL) == 0) return TRUE; break; case 0x5c: @@ -486,7 +486,7 @@ bool32 sub_08029198(const struct SalesOffering* offer) { if ((offer->field_0x0 & 0xfc) != 0xc) { switch (offer->field_0x8) { case 0x1c: - tmp = CheckGlobalFlag(0x5a); + tmp = CheckGlobalFlag(AKINDO_BOTTLE_SELL); break; case 0x9: case 0x44: diff --git a/src/fileScreen.c b/src/fileScreen.c index f048b296..925e1f54 100644 --- a/src/fileScreen.c +++ b/src/fileScreen.c @@ -1009,7 +1009,7 @@ void HandleFileDelete(void) { sub_08050A64(gUnk_02019EE0.unk6); } -void FUN_080515c8(void) { +void sub_080515c8(void) { sub_080A7114(1); } diff --git a/src/game.c b/src/game.c index 2b9e9e32..49fe233f 100644 --- a/src/game.c +++ b/src/game.c @@ -247,7 +247,7 @@ void InitializePlayer(void) { MemClear((void*)pl, 0x88); gRoomControls.cameraTarget = pl; gPlayerState.playerAction = gUnk_080FCAC8[gScreenTransition.field_0xf]; - if (!CheckGlobalFlag(0x14)) { + if (!CheckGlobalFlag(EZERO_1ST)) { gPlayerState.flags.all |= 8; } switch (gScreenTransition.field_0xf) { diff --git a/src/npc/bladeBrothers.c b/src/npc/bladeBrothers.c index 7bb1fdc3..37067485 100644 --- a/src/npc/bladeBrothers.c +++ b/src/npc/bladeBrothers.c @@ -119,7 +119,7 @@ void sub_08068AFC(Entity* this) { sub_0807DD50(this); } -void FUN_08068b2c(Entity* this) { +void sub_08068b2c(Entity* this) { u32 uVar1; if (this->interactType == '\x02') { diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index 5329bd15..06b6e9a2 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -6,13 +6,16 @@ #include "room.h" #include "flags.h" #include "script.h" +#include "save.h" -extern u32 sub_080696BC(Entity*); +extern u32 GoronMerchant_GetSalePrice(Entity*); extern void (*const gUnk_08111B88[])(Entity*); extern void (*const gUnk_08111B98[])(Entity*); -extern u16 gUnk_08111BA0[]; +const u16 GoronMerchant_KinstonePrices[]; + +extern u32 sub_0801E7D0(u32); void GoronMerchant(Entity* this) { if ((this->flags & 2) != 0) { @@ -78,7 +81,7 @@ void sub_08069660(Entity* this) { u32 uVar1; TextboxNoOverlap(0x2c1c, this); - gTextBox.field_0x10 = (u16)sub_080696BC(this); + gTextBox.field_0x10 = (u16)GoronMerchant_GetSalePrice(this); } void sub_08069684(void) { @@ -98,33 +101,86 @@ void sub_080696B0(void) { gRoomVars.itemForSaleIndex = 0; } -u32 sub_080696BC(Entity* this) { - u32 uVar1; +u32 GoronMerchant_GetSalePrice(Entity* this) { + u32 restockCount; u32 temp; - u32 iVar3; - s32 temp2; + u32 kinstoneType; + s32 itemForSale; - temp2 = gRoomVars.field_0x7; - if (temp2 > 0x70) { - iVar3 = 1; + itemForSale = gRoomVars.field_0x7; + if (itemForSale > 0x70) { + kinstoneType = 1; } else { - iVar3 = 0; + kinstoneType = 0; } - if (temp2 > 0x72) { - iVar3 = 2; + if (itemForSale > 0x72) { + kinstoneType = 2; } - temp = CheckGlobalFlag(0x3e); - uVar1 = BOOLCAST(temp); + temp = CheckGlobalFlag(GORON_KAKERA_LV2); + restockCount = BOOLCAST(temp); - if (CheckGlobalFlag(0x3f)) { - uVar1 = 2; + if (CheckGlobalFlag(GORON_KAKERA_LV3)) { + restockCount = 2; } - if (CheckGlobalFlag(0x40)) { - uVar1 = 3; + if (CheckGlobalFlag(GORON_KAKERA_LV4)) { + restockCount = 3; } - if (CheckGlobalFlag(0x41)) { - uVar1 = 4; + if (CheckGlobalFlag(GORON_KAKERA_LV5)) { + restockCount = 4; } - return gUnk_08111BA0[uVar1 * 3 + iVar3]; + return GoronMerchant_KinstonePrices[restockCount * 3 + kinstoneType]; } + +void GoronMerchant_TryToBuyKinstone(Entity* this, ScriptExecutionContext* context) { + s32 salePrice = GoronMerchant_GetSalePrice(this); + if (salePrice <= gSave.stats.rupees) { + if (sub_0801E7D0(gRoomVars.field_0x7) < 99) { + ModRupees(-salePrice); + sub_080A7C18(0x5c, gRoomVars.field_0x7, 0); + gRoomVars.itemForSaleIndex = 0; + gRoomVars.field_0x7 = 0; + context->condition = 1; + } else { + TextboxNoOverlap(0x2c1f, this); + context->condition = 0; + } + } else { + TextboxNoOverlap(0x2c1e, this); + context->condition = 0; + } + gActiveScriptInfo.flags = gActiveScriptInfo.flags | 1; +} + +void (*const gUnk_08111B88[])(Entity*) = { + sub_08069584, + sub_080695AC, + sub_080695E8, + sub_0806961C, +}; +void (*const gUnk_08111B98[])(Entity*) = { + sub_0806963C, + sub_08069654, +}; + +const u16 GoronMerchant_KinstonePrices[] = { + 300, + 200, + 50, + // prices after restock 1 + 300, + 200, + 50, + // prices after restock 2 + 300, + 200, + 50, + // prices after restock 3 + 300, + 200, + 50, + // prices after restock 4 + 300, + 200, + 50, +}; \ No newline at end of file diff --git a/src/npc/librari.c b/src/npc/librari.c index ce6fbefc..992a920c 100644 --- a/src/npc/librari.c +++ b/src/npc/librari.c @@ -43,7 +43,7 @@ void sub_0806B260(Entity* this, ScriptExecutionContext* context) { context->condition = 0; // flippers if (!GetInventoryValue(0x46)) { - if (CheckGlobalFlag(0x29)) { + if (CheckGlobalFlag(MIZUKAKI_START)) { index = 2; context->condition = 1; } else if (!CheckLocalFlag(0x7a)) { diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c index df2d8fe3..79f35176 100644 --- a/src/npc/townMinish.c +++ b/src/npc/townMinish.c @@ -256,7 +256,7 @@ void sub_0806AFE8(Entity* this, ScriptExecutionContext* context) { void sub_0806B004(Entity* this, ScriptExecutionContext* context) { int idx = 0; - if (CheckGlobalFlag(0x29)) { + if (CheckGlobalFlag(MIZUKAKI_START)) { if (CheckLocalFlag(0x73)) { if (GetInventoryValue(0x46) == 0) { idx = 3; @@ -279,7 +279,7 @@ void sub_0806B004(Entity* this, ScriptExecutionContext* context) { void sub_0806B064(Entity* this) { int idx = 0; - if (CheckGlobalFlag(0x29)) { + if (CheckGlobalFlag(MIZUKAKI_START)) { idx = 1; if (CheckLocalFlag(0x73)) { idx = 2; @@ -294,8 +294,8 @@ void sub_0806B098(Entity* this) { if (GetInventoryValue(0x46) == 0) { idx = 1; - if (CheckGlobalFlag(0x29)) { - f = CheckGlobalFlag(0x2a); + if (CheckGlobalFlag(MIZUKAKI_START)) { + f = CheckGlobalFlag(MIZUKAKI_HARIFALL); idx = BOOLCAST(f); } } diff --git a/src/room.c b/src/room.c index 18ca4e10..682a6935 100644 --- a/src/room.c +++ b/src/room.c @@ -1003,13 +1003,13 @@ extern EntityData gUnk_080D9108; extern EntityData gUnk_080D9098; void sub_0804C018(void) { - if (!CheckGlobalFlag(0x20)) { + if (!CheckGlobalFlag(HAKA_KEY_LOST)) { // graveyard key if (GetInventoryValue(0x3c) == 1) { LoadRoomEntityList(&gUnk_080D90C8); LoadRoomEntityList(&gUnk_080D9108); } - } else if (!CheckGlobalFlag(0x21)) + } else if (!CheckGlobalFlag(HAKA_KEY_FOUND)) LoadRoomEntityList(&gUnk_080D9108); if (GetInventoryValue(0x3c) != 2) {