diff --git a/asm/mauville_old_man.s b/asm/mauville_old_man.s index af4764d76d..924e35b89d 100644 --- a/asm/mauville_old_man.s +++ b/asm/mauville_old_man.s @@ -90,7 +90,7 @@ sub_8120128: @ 8120128 thumb_func_start sub_8120154 sub_8120154: @ 8120154 push {lr} - bl sub_81339F8 + bl TraderSetup pop {r0} bx r0 thumb_func_end sub_8120154 diff --git a/asm/trader.s b/asm/trader.s deleted file mode 100644 index a43f594023..0000000000 --- a/asm/trader.s +++ /dev/null @@ -1,558 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_81339F8 -sub_81339F8: @ 81339F8 - push {r4-r6,lr} - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00002e28 - adds r5, r1, r0 - movs r2, 0 - movs r0, 0x2 - strb r0, [r5] - ldr r0, =0x00002e59 - adds r1, r0 - strb r2, [r1] - movs r4, 0 - ldr r6, =gUnknown_085B09E4 -_08133A12: - movs r0, 0xB - muls r0, r4 - adds r0, 0x5 - adds r0, r5, r0 - lsls r1, r4, 2 - adds r1, r6 - ldr r1, [r1] - bl StringCopy - adds r1, r5, 0x1 - adds r1, r4 - ldr r0, =gUnknown_085B09F4 - adds r0, r4, r0 - ldrb r0, [r0] - strb r0, [r1] - adds r0, r5, 0 - adds r0, 0x32 - adds r0, r4 - movs r1, 0x2 - strb r1, [r0] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x3 - bls _08133A12 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81339F8 - - thumb_func_start sub_8133A60 -sub_8133A60: @ 8133A60 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00002e59 - adds r0, r1 - movs r1, 0 - strb r1, [r0] - bx lr - .pool - thumb_func_end sub_8133A60 - - thumb_func_start sub_8133A78 -sub_8133A78: @ 8133A78 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x14 - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - ldr r0, =gTasks + 0x8 - adds r7, r1, r0 - ldr r0, =gSaveBlock1Ptr - ldr r4, [r0] - ldr r0, =0x00002e28 - adds r0, r4 - mov r9, r0 - ldr r0, =gUnknown_085B09F8 - ldr r1, [r0, 0x4] - ldr r0, [r0] - str r0, [sp, 0xC] - str r1, [sp, 0x10] - ldr r1, =gText_Exit - movs r0, 0x1 - movs r2, 0 - bl GetStringWidth - adds r6, r0, 0 - ldr r1, =gText_FiveMarks - movs r0, 0x1 - movs r2, 0 - bl GetStringWidth - mov r8, r0 - movs r5, 0 - ldr r0, =0x00002e29 - adds r4, r0 -_08133AC2: - mov r0, r9 - adds r0, 0x1 - adds r1, r0, r5 - ldrb r0, [r1] - cmp r0, 0x78 - bls _08133AF0 - mov r0, r8 - b _08133B00 - .pool -_08133AF0: - ldrb r1, [r1] - lsls r1, 5 - ldr r0, =gDecorations + 1 - adds r1, r0 - movs r0, 0x1 - movs r2, 0 - bl GetStringWidth -_08133B00: - cmp r0, r6 - ble _08133B06 - adds r6, r0, 0 -_08133B06: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x3 - bls _08133AC2 - adds r0, r6, 0 - bl convert_pixel_width_to_tile_width - lsls r0, 24 - ldr r2, =0x00ffffff - ldr r1, [sp, 0xC] - ands r1, r2 - orrs r1, r0 - str r1, [sp, 0xC] - add r0, sp, 0xC - bl AddWindow - strh r0, [r7, 0x6] - lsls r0, 24 - lsrs r0, 24 - movs r2, 0x85 - lsls r2, 2 - movs r1, 0 - movs r3, 0xE - bl SetWindowBorderStyle - movs r5, 0 -_08133B3C: - adds r1, r4, r5 - ldrb r0, [r1] - cmp r0, 0x78 - bls _08133B70 - ldrb r0, [r7, 0x6] - lsls r1, r5, 4 - adds r1, 0x1 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp] - movs r1, 0xFF - str r1, [sp, 0x4] - movs r1, 0 - str r1, [sp, 0x8] - movs r1, 0x1 - ldr r2, =gText_FiveMarks - movs r3, 0x8 - bl PrintTextOnWindow - b _08133B94 - .pool -_08133B70: - ldrb r0, [r7, 0x6] - ldrb r2, [r1] - lsls r2, 5 - ldr r1, =gDecorations + 1 - adds r2, r1 - lsls r1, r5, 4 - adds r1, 0x1 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp] - movs r1, 0xFF - str r1, [sp, 0x4] - movs r1, 0 - str r1, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x8 - bl PrintTextOnWindow -_08133B94: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x3 - bls _08133B3C - ldrb r0, [r7, 0x6] - ldr r2, =gText_Exit - lsls r1, r5, 4 - adds r1, 0x1 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp] - movs r1, 0xFF - str r1, [sp, 0x4] - movs r1, 0 - str r1, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x8 - bl PrintTextOnWindow - ldrb r0, [r7, 0x6] - movs r1, 0x5 - movs r2, 0 - bl InitMenuInUpperLeftCornerPlaySoundWhenAPressed - movs r0, 0 - bl schedule_bg_copy_tilemap_to_vram - add sp, 0x14 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133A78 - - thumb_func_start sub_8133BE4 -sub_8133BE4: @ 8133BE4 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r2, r1, 24 - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r4, r0, r1 - cmp r2, 0x78 - bls _08133C14 - ldr r1, =gSpecialVar_0x8004 - ldr r2, =0x0000ffff - adds r0, r2, 0 - strh r0, [r1] - b _08133C18 - .pool -_08133C14: - ldr r0, =gSpecialVar_0x8004 - strh r2, [r0] -_08133C18: - ldrb r0, [r4, 0x6] - movs r1, 0 - bl sub_8198070 - ldrb r0, [r4, 0x6] - bl ClearWindowTilemap - ldrb r0, [r4, 0x6] - bl RemoveWindow - movs r0, 0 - bl schedule_bg_copy_tilemap_to_vram - adds r0, r5, 0 - bl DestroyTask - bl EnableBothScriptContexts - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133BE4 - - thumb_func_start sub_8133C48 -sub_8133C48: @ 8133C48 - push {r4-r7,lr} - lsls r0, 24 - lsrs r7, r0, 24 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00002e28 - adds r6, r0, r1 - bl ProcessMenuInput - lsls r0, 24 - lsrs r4, r0, 24 - asrs r1, r0, 24 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - beq _08133C80 - cmp r1, r0 - bgt _08133C7C - subs r0, 0x1 - cmp r1, r0 - beq _08133CCA - b _08133C90 - .pool -_08133C7C: - cmp r1, 0x4 - bne _08133C90 -_08133C80: - movs r0, 0x5 - bl PlaySE - adds r0, r7, 0 - movs r1, 0 - bl sub_8133BE4 - b _08133CCA -_08133C90: - movs r0, 0x5 - bl PlaySE - ldr r0, =gSpecialVar_0x8005 - lsls r4, 24 - asrs r4, 24 - strh r4, [r0] - ldr r5, =gStringVar1 - movs r0, 0xB - adds r1, r4, 0 - muls r1, r0 - adds r1, 0x5 - adds r1, r6, r1 - adds r0, r5, 0 - bl StringCopy - adds r0, r6, 0 - adds r0, 0x32 - adds r0, r4 - ldrb r1, [r0] - adds r0, r5, 0 - bl ConvertInternationalString - adds r0, r6, 0x1 - adds r0, r4 - ldrb r1, [r0] - adds r0, r7, 0 - bl sub_8133BE4 -_08133CCA: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133C48 - - thumb_func_start sub_8133CD8 -sub_8133CD8: @ 8133CD8 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =gSpecialVar_Result - ldr r2, =0x00002e59 - adds r0, r2 - ldrb r0, [r0] - strh r0, [r1] - bx lr - .pool - thumb_func_end sub_8133CD8 - - thumb_func_start sub_8133CF4 -sub_8133CF4: @ 8133CF4 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gSpecialVar_Result -_08133CFA: - adds r0, r4, 0 - bl CountDecorationCategoryN - lsls r0, 24 - cmp r0, 0 - beq _08133D10 - movs r0, 0 - strh r0, [r5] - b _08133D20 - .pool -_08133D10: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x7 - bls _08133CFA - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] -_08133D20: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133CF4 - - thumb_func_start sub_8133D2C -sub_8133D2C: @ 8133D2C - push {r4-r6,lr} - ldr r6, =gSpecialVar_Result - movs r0, 0 - strh r0, [r6] - ldr r4, =gDecorations - ldr r5, =gSpecialVar_0x8004 - ldrh r0, [r5] - lsls r0, 5 - adds r2, r0, r4 - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - lsls r0, 5 - adds r0, r4 - ldrb r1, [r2, 0x13] - ldrb r0, [r0, 0x13] - cmp r1, r0 - beq _08133D72 - adds r0, r1, 0 - bl GetFirstEmptyDecorSlot - lsls r0, 24 - asrs r0, 24 - movs r1, 0x1 - negs r1, r1 - cmp r0, r1 - bne _08133D72 - ldr r0, =gStringVar2 - ldrh r1, [r5] - lsls r1, 5 - adds r1, r4 - ldrb r1, [r1, 0x13] - bl sub_8127250 - movs r0, 0x1 - strh r0, [r6] -_08133D72: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133D2C - - thumb_func_start sub_8133D8C -sub_8133D8C: @ 8133D8C - push {lr} - ldr r0, =sub_8127208 - movs r1, 0 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133D8C - - thumb_func_start sub_8133DA0 -sub_8133DA0: @ 8133DA0 - push {r4-r6,lr} - lsls r0, 24 - lsrs r6, r0, 24 - bl IsSelectedDecorInThePC - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _08133DFC - ldr r5, =gSpecialVar_0x8006 - ldr r0, =gCurDecorationIndex - ldrb r1, [r0] - ldr r0, =gCurDecorInventoryItems - ldr r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strh r0, [r5] - ldr r0, =gStringVar3 - ldr r1, =gSpecialVar_0x8004 - ldrh r1, [r1] - lsls r1, 5 - ldr r4, =gDecorations + 1 - adds r1, r4 - bl StringCopy - ldr r0, =gStringVar2 - ldrh r1, [r5] - lsls r1, 5 - adds r1, r4 - bl StringCopy - b _08133E04 - .pool -_08133DFC: - ldr r1, =gSpecialVar_0x8006 - ldr r2, =0x0000ffff - adds r0, r2, 0 - strh r0, [r1] -_08133E04: - adds r0, r6, 0 - bl DestroyTask - bl EnableBothScriptContexts - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133DA0 - - thumb_func_start sub_8133E1C -sub_8133E1C: @ 8133E1C - push {lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gSpecialVar_0x8006 - movs r1, 0 - strh r1, [r2] - bl DestroyTask - bl EnableBothScriptContexts - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133E1C - - thumb_func_start sub_8133E38 -sub_8133E38: @ 8133E38 - push {r4-r6,lr} - mov r6, r8 - push {r6} - ldr r0, =gSaveBlock1Ptr - ldr r6, [r0] - ldr r0, =0x00002e28 - adds r5, r6, r0 - ldr r1, =gSpecialVar_0x8006 - mov r8, r1 - ldrb r0, [r1] - bl DecorationRemove - ldr r0, =gSpecialVar_0x8004 - ldrb r0, [r0] - bl DecorationAdd - ldr r4, =gSpecialVar_0x8005 - ldrh r1, [r4] - movs r0, 0xB - muls r0, r1 - adds r0, 0x5 - adds r5, r0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - adds r0, r5, 0 - bl StringCopy - ldr r2, =0x00002e29 - adds r0, r6, r2 - ldrh r1, [r4] - adds r0, r1 - mov r2, r8 - ldrh r1, [r2] - strb r1, [r0] - ldr r1, =0x00002e5a - adds r0, r6, r1 - ldrh r4, [r4] - adds r0, r4 - movs r1, 0x2 - strb r1, [r0] - ldr r2, =0x00002e59 - adds r6, r2 - movs r0, 0x1 - strb r0, [r6] - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133E38 - - thumb_func_start sub_8133EC0 -sub_8133EC0: @ 8133EC0 - push {lr} - ldr r0, =sub_8133C48 - movs r1, 0 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - bl sub_8133A78 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8133EC0 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/scripts/mauville_man.inc b/data/scripts/mauville_man.inc index 2e00ee702d..917e2cf89a 100644 --- a/data/scripts/mauville_man.inc +++ b/data/scripts/mauville_man.inc @@ -157,7 +157,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_28E4D4:: @ 828E4D4 msgbox MauvilleCity_PokemonCenter_1F_Text_28E1B1, 5 compare VAR_RESULT, 0 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E503 - special sub_8133CD8 + special ScrSpecial_GetTraderTradedFlag compare VAR_RESULT, 1 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E50D message MauvilleCity_PokemonCenter_1F_Text_28E23F @@ -176,7 +176,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_28E50D:: @ 828E50D end MauvilleCity_PokemonCenter_1F_EventScript_28E517:: @ 828E517 - special sub_8133EC0 + special ScrSpecial_TraderMenuGetDecoration waitstate compare VAR_0x8004, 0 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E558 @@ -185,7 +185,7 @@ MauvilleCity_PokemonCenter_1F_EventScript_28E517:: @ 828E517 msgbox MauvilleCity_PokemonCenter_1F_Text_28E2A9, 5 compare VAR_RESULT, 0 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E56E - special sub_8133CF4 + special ScrSpecial_DoesPlayerHaveNoDecorations compare VAR_RESULT, 1 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E57A goto MauvilleCity_PokemonCenter_1F_EventScript_28E584 @@ -215,19 +215,19 @@ MauvilleCity_PokemonCenter_1F_EventScript_28E57A:: @ 828E57A MauvilleCity_PokemonCenter_1F_EventScript_28E584:: @ 828E584 msgbox MauvilleCity_PokemonCenter_1F_Text_28E323, 4 - special sub_8133D8C + special ScrSpecial_TraderMenuGiveDecoration waitstate compare VAR_0x8006, 0 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E5D4 compare VAR_0x8006, 65535 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E5DE - special sub_8133D2C + special ScrSpecial_IsDecorationFull compare VAR_RESULT, 1 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E5EC msgbox MauvilleCity_PokemonCenter_1F_Text_28E3C4, 5 compare VAR_RESULT, 0 goto_eq MauvilleCity_PokemonCenter_1F_EventScript_28E584 - special sub_8133E38 + special ScrSpecial_TraderDoDecorationTrade msgbox MauvilleCity_PokemonCenter_1F_Text_28E424, 4 release end diff --git a/data/specials.inc b/data/specials.inc index 2290c9d216..7b79e21d99 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -124,12 +124,12 @@ gSpecials:: @ 81DBA64 def_special sub_81213D8 def_special sub_8121450 def_special sub_8121424 - def_special sub_8133EC0 - def_special sub_8133CD8 - def_special sub_8133CF4 - def_special sub_8133D2C - def_special sub_8133D8C - def_special sub_8133E38 + def_special ScrSpecial_TraderMenuGetDecoration + def_special ScrSpecial_GetTraderTradedFlag + def_special ScrSpecial_DoesPlayerHaveNoDecorations + def_special ScrSpecial_IsDecorationFull + def_special ScrSpecial_TraderMenuGiveDecoration + def_special ScrSpecial_TraderDoDecorationTrade def_special GetSeedotSizeRecordInfo def_special CompareSeedotSize def_special GetLotadSizeRecordInfo diff --git a/data/trader.s b/data/trader.s deleted file mode 100644 index 1fe929ae7a..0000000000 --- a/data/trader.s +++ /dev/null @@ -1,22 +0,0 @@ - - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_085B09E4:: @ 85B09E4 - .4byte gText_Tristan - .4byte gText_Philip - .4byte gText_Dennis - .4byte gText_Roberto - - .align 2 -gUnknown_085B09F4:: @ 85B09F4 - .byte 0x5b, 0x6b, 0x25, 0x15 - - .align 2 -gUnknown_085B09F8:: @ 85B09F8 - .4byte 0x0a010100, 0x00010f0a - - diff --git a/include/constants/decorations.h b/include/constants/decorations.h index 2e35587216..b9f626d244 100644 --- a/include/constants/decorations.h +++ b/include/constants/decorations.h @@ -122,5 +122,6 @@ #define DECOR_REGIROCK_DOLL 118 #define DECOR_REGICE_DOLL 119 #define DECOR_REGISTEEL_DOLL 120 +#define NUM_DECORATIONS DECOR_REGISTEEL_DOLL #endif // GUARD_CONSTANTS_DECORATIONS_H diff --git a/include/decoration.h b/include/decoration.h index a51d9ccce6..76b2f2ec46 100644 --- a/include/decoration.h +++ b/include/decoration.h @@ -70,5 +70,8 @@ void sub_8126968(void); void sub_8126AD8(u8 taskId); void sub_8127D38(u16 mapX, u16 mapY, u16 decor); void sub_8126B2C(u8 taskId); +void sub_8127208(u8 taskId); +void sub_8127250(u8 *dest, u8 decorCat); +bool8 IsSelectedDecorInThePC(void); #endif //GUARD_DECORATION_H diff --git a/include/global.h b/include/global.h index f88203c900..c8c9338ca9 100644 --- a/include/global.h +++ b/include/global.h @@ -452,10 +452,11 @@ struct UnkMauvilleOldManStruct2 struct MauvilleOldManTrader { - u8 unk0; - u8 unk1[4]; - u8 unk5[4][11]; - u8 unk31; + /* 0x2E28 */ u8 id; + /* 0x2E29 */ u8 unk1[4]; + /* 0x2E2D */ u8 unk5[4][11]; + /* 0x2E59 */ bool8 alreadyTraded; + /* 0x2E5A */ u8 language[4]; }; typedef union OldMan diff --git a/include/script_menu.h b/include/script_menu.h index 717eda0418..810e84dcb4 100644 --- a/include/script_menu.h +++ b/include/script_menu.h @@ -9,5 +9,6 @@ bool8 ScriptMenu_YesNo(u8 var1, u8 var2); bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, u8 a4, u8 columnCount); bool8 ScriptMenu_ShowPokemonPic(u16 var1, u8 var2, u8 var3); bool8 (*ScriptMenu_GetPicboxWaitFunc(void))(void); +s32 convert_pixel_width_to_tile_width(s32 pixelWidth); #endif //GUARD_SCRIPT_MENU_H diff --git a/include/strings.h b/include/strings.h index 7c81dbcfba..e635549d54 100644 --- a/include/strings.h +++ b/include/strings.h @@ -429,5 +429,11 @@ extern const u8 gText_TooImportantToToss[]; extern const u8 gText_ConfirmTossItems[]; extern const u8 gText_MoveVar1Where[]; +extern const u8 gText_Tristan[]; +extern const u8 gText_Philip[]; +extern const u8 gText_Dennis[]; +extern const u8 gText_Roberto[]; +extern const u8 gText_FiveMarks[]; + #endif //GUARD_STRINGS_H diff --git a/ld_script.txt b/ld_script.txt index 2832bcada4..bd26f78eb6 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -173,7 +173,7 @@ SECTIONS { asm/slot_machine.o(.text); asm/contest_painting.o(.text); src/battle_ai_script_commands.o(.text); - asm/trader.o(.text); + src/trader.o(.text); src/starter_choose.o(.text); src/wallclock.o(.text); src/rom6.o(.text); @@ -466,7 +466,7 @@ SECTIONS { data/slot_machine.o(.rodata); data/contest_painting.o(.rodata); src/battle_ai_script_commands.o(.rodata); - data/trader.o(.rodata); + src/trader.o(.rodata); data/starter_choose.o(.rodata); src/wallclock.o(.rodata); src/pokeblock.o(.rodata); diff --git a/src/trader.c b/src/trader.c new file mode 100644 index 0000000000..4914f8140e --- /dev/null +++ b/src/trader.c @@ -0,0 +1,209 @@ +#include "global.h" +#include "constants/decorations.h" +#include "constants/mauville_man.h" +#include "decoration.h" +#include "decoration_inventory.h" +#include "event_data.h" +#include "main.h" +#include "menu.h" +#include "menu_helpers.h" +#include "script.h" +#include "constants/songs.h" +#include "sound.h" +#include "string_util.h" +#include "strings.h" +#include "task.h" +#include "script_menu.h" + +static const u8 * const gUnknown_085B09E4[] = +{ + gText_Tristan, + gText_Philip, + gText_Dennis, + gText_Roberto, +}; + +static const u8 gTraderDecorations[] = +{ + DECOR_DUSKULL_DOLL, + DECOR_BALL_CUSHION, + DECOR_TIRE, + DECOR_PRETTY_FLOWERS, +}; + +void TraderSetup(void) +{ + u8 i; + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + + trader->id = MAUVILLE_MAN_TRADER; + trader->alreadyTraded = FALSE; + + for (i = 0; i < 4; i++) + { + StringCopy(trader->unk5[i], gUnknown_085B09E4[i]); + trader->unk1[i] = gTraderDecorations[i]; + trader->language[i] = GAME_LANGUAGE; + } +} + +void sub_8133A60(void) +{ + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + trader->alreadyTraded = FALSE; +} + +void CreateAvailableDecorationsMenu(u8 taskId) +{ + u8 i; + s16 * data = gTasks[taskId].data; + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + struct WindowTemplate windowTemplate = {0, 1, 1, 10, 10, 15, 1}; + s32 windowWidth = GetStringWidth(1, gText_Exit, 0); + s32 fiveMarksWidth = GetStringWidth(1, gText_FiveMarks, 0); + for (i = 0; i < 4; i++) + { + s32 curWidth; + if (trader->unk1[i] > NUM_DECORATIONS) + curWidth = fiveMarksWidth; + else + curWidth = GetStringWidth(1, gDecorations[trader->unk1[i]].name, 0); + if (curWidth > windowWidth) + windowWidth = curWidth; + } + windowTemplate.width = convert_pixel_width_to_tile_width(windowWidth); + data[3] = AddWindow(&windowTemplate); + SetWindowBorderStyle(data[3], FALSE, 0x214, 14); + for (i = 0; i < 4; i++) + { + if (trader->unk1[i] > NUM_DECORATIONS) + PrintTextOnWindow(data[3], 1, gText_FiveMarks, 8, 16 * i + 1, 255, NULL); + else + PrintTextOnWindow(data[3], 1, gDecorations[trader->unk1[i]].name, 8, 16 * i + 1, 255, NULL); + } + PrintTextOnWindow(data[3], 1, gText_Exit, 8, 16 * i + 1, 255, NULL); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[3], 5, 0); + schedule_bg_copy_tilemap_to_vram(0); +} + +void sub_8133BE4(u8 taskId, u8 decorationId) +{ + s16 * data = gTasks[taskId].data; + if (decorationId > NUM_DECORATIONS) + { + gSpecialVar_0x8004 = 0xFFFF; + } + else + { + gSpecialVar_0x8004 = decorationId; + } + + sub_8198070(data[3], FALSE); + ClearWindowTilemap(data[3]); + RemoveWindow(data[3]); + schedule_bg_copy_tilemap_to_vram(0); + DestroyTask(taskId); + EnableBothScriptContexts(); +} + +void Task_HandleGetDecorationMenuInput(u8 taskId) +{ + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + s8 input = ProcessMenuInput(); + + switch (input) + { + case -2: + break; + case -1: + case 4: + PlaySE(SE_SELECT); + sub_8133BE4(taskId, 0); + break; + default: + PlaySE(SE_SELECT); + gSpecialVar_0x8005 = input; + StringCopy(gStringVar1, trader->unk5[input]); + ConvertInternationalString(gStringVar1, trader->language[input]); + sub_8133BE4(taskId, trader->unk1[input]); + break; + } +} + +void ScrSpecial_GetTraderTradedFlag(void) +{ + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + gSpecialVar_Result = trader->alreadyTraded; +} + +void ScrSpecial_DoesPlayerHaveNoDecorations(void) +{ + u8 i; + + for (i = 0; i < 8; i++) + { + if (CountDecorationCategoryN(i)) + { + gSpecialVar_Result = FALSE; + return; + } + } + gSpecialVar_Result = TRUE; +} + +void ScrSpecial_IsDecorationFull(void) +{ + gSpecialVar_Result = FALSE; + if (gDecorations[gSpecialVar_0x8004].category != gDecorations[gSpecialVar_0x8006].category + && GetFirstEmptyDecorSlot(gDecorations[gSpecialVar_0x8004].category) == -1) + { + sub_8127250(gStringVar2, gDecorations[gSpecialVar_0x8004].category); + gSpecialVar_Result = TRUE; + } +} + +void ScrSpecial_TraderMenuGiveDecoration(void) +{ + CreateTask(sub_8127208, 0); +} + +void sub_8133DA0(u8 taskId) +{ + if (IsSelectedDecorInThePC() == TRUE) + { + gSpecialVar_0x8006 = gCurDecorInventoryItems[gCurDecorationIndex]; + StringCopy(gStringVar3, gDecorations[gSpecialVar_0x8004].name); + StringCopy(gStringVar2, gDecorations[gSpecialVar_0x8006].name); + } + else + { + gSpecialVar_0x8006 = 0xFFFF; + } + DestroyTask(taskId); + EnableBothScriptContexts(); +} + +void sub_8133E1C(u8 taskId) +{ + gSpecialVar_0x8006 = 0; + DestroyTask(taskId); + EnableBothScriptContexts(); +} + +void ScrSpecial_TraderDoDecorationTrade(void) +{ + struct MauvilleOldManTrader *trader = &gSaveBlock1Ptr->oldMan.trader; + + DecorationRemove(gSpecialVar_0x8006); + DecorationAdd(gSpecialVar_0x8004); + StringCopy(trader->unk5[gSpecialVar_0x8005], gSaveBlock2Ptr->playerName); + trader->unk1[gSpecialVar_0x8005] = gSpecialVar_0x8006; + trader->language[gSpecialVar_0x8005] = GAME_LANGUAGE; + trader->alreadyTraded = TRUE; +} + +void ScrSpecial_TraderMenuGetDecoration(void) +{ + u8 taskId = CreateTask(Task_HandleGetDecorationMenuInput, 0); + CreateAvailableDecorationsMenu(taskId); +}