diff --git a/data/data_8115F5C_2.s b/data/data_8115F5C_2.s deleted file mode 100644 index e241b75ea..000000000 --- a/data/data_8115F5C_2.s +++ /dev/null @@ -1,59 +0,0 @@ -.section .rodata - - -.align 2,0 - - - -.byte 0x70, 0x6b, 0x73, 0x64, 0x69, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x6b, 0x73, 0x64 -.byte 0x69, 0x72, 0x30, 0x00 - -.global gUnknown_811633C -gUnknown_811633C: @ 811633C -.string "{CENTER_ALIGN}{NAME_0}'s team received\n" -.string "{CENTER_ALIGN}the {MOVE_ITEM_0} cash reward.\0" -.align 2, 0 - -.global gUnknown_811636C -gUnknown_811636C: @ 811636C -.string "{CENTER_ALIGN}The team also received\n" -.string "{CENTER_ALIGN}one {MOVE_ITEM_0}.\0" -.align 2, 0 - -.global gUnknown_8116390 -gUnknown_8116390: @ 8116390 -.string "{CENTER_ALIGN}{NAME_0}'s team received\n" -.string "{CENTER_ALIGN}the reward {MOVE_ITEM_0}.\0" -.align 2, 0 - -.global gUnknown_81163BC -gUnknown_81163BC: @ 81163BC -@ replacing .incbin "baserom.gba", 0x1163BC, 0x28 -.byte 0x37, 0x00, 0x00, 0x00 -.byte 0x42, 0x00, 0x00, 0x00 -.byte 0x3f, 0x00, 0x00, 0x00 -.byte 0x69, 0x00, 0xf4, 0x01 -.byte 0x3a, 0x00, 0x00, 0x00 -.byte 0x3f, 0x00, 0x00, 0x00 -.byte 0x69, 0x00, 0xf4, 0x01 -.byte 0x14, 0x00, 0x00, 0x00 -.byte 0x3f, 0x00, 0x00, 0x00 -.byte 0x69, 0x00, 0x10, 0x27 - -.global gUnknown_81163E4 -gUnknown_81163E4: @ 81163E4 -.string "{COLOR CYAN_G}%d{RESET} %s\0" -.align 2,0 - -.global gUnknown_81163F0 -gUnknown_81163F0: @ 81163F0 -.string "{CENTER_ALIGN}However, {NAME_0}'s team\n" -.string "{CENTER_ALIGN}had too much money already...\0" -.align 2,0 - -.global gUnknown_811642C -gUnknown_811642C: @ 811642C -.string "{CENTER_ALIGN}However, {NAME_0}'s team\n" -.string "{CENTER_ALIGN}had too many items already...\0" -.align 2,0 - diff --git a/include/script_item.h b/include/script_item.h new file mode 100644 index 000000000..c0d5053df --- /dev/null +++ b/include/script_item.h @@ -0,0 +1,12 @@ +#ifndef GUARD_SCRIPT_ITEM_H +#define GUARD_SCRIPT_ITEM_H + +void InitInternalScriptItemsData(void); +void FreeInternalScriptItemsData(void); +void ClearScriptItemScriptVars(void); +s32 HasItemInInventory(u8 item); +s32 CheckScriptItemSpace(s32 tableId); +s32 TryGiveScriptItem(u32 tableId, s32 a1); +u32 ScriptItemTextboxFunc(void); + +#endif // GUARD_SCRIPT_ITEM_H diff --git a/ld_script.ld b/ld_script.ld index 9eb7f0ca3..366847cf5 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -338,6 +338,7 @@ SECTIONS { src/palette_util.o(.text); src/code_809A560.o(.text); src/code_809C5C4.o(.text); + src/script_item.o(.text); src/ground_lives_helper.o(.text); src/code_809D148.o(.text); src/ground_script.o(.text); @@ -720,7 +721,8 @@ SECTIONS { src/code_8099360.o(.rodata); src/palette_util.o(.rodata); src/code_809A560.o(.rodata); - data/data_8115F5C_2.o(.rodata); + src/code_809C5C4.o(.rodata); + src/script_item.o(.rodata); src/ground_lives_helper.o(.rodata); src/code_809D148.o(.rodata); src/ground_script.o(.rodata); diff --git a/src/code_809A560.c b/src/code_809A560.c index 6b2d827c7..56f3eab14 100644 --- a/src/code_809A560.c +++ b/src/code_809A560.c @@ -33,8 +33,9 @@ #include "wigglytuff_shop3.h" #include "wonder_mail.h" #include "naming_screen.h" +#include "script_item.h" -IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = { NULL }; +static IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = { NULL }; extern bool8 sub_802FCF0(void); u8 ScriptPrintText_809B2B8(struct unkStruct_3001B64_unkC *, s32, s32, const char *); @@ -43,6 +44,13 @@ extern void ResetTextbox_809B294(void); extern s32 sub_803B168(void); extern void sub_803B1BC(void); +struct unkStruct_8096AF8 +{ + bool8 unk0; + /* 0x2 */ s16 clientSpecies; + /* 0x4 */ s16 targetSpecies; +}; + u32 xxx_script_textboxes_809A680(u32 param_1, u32 param_2); void sub_809A62C(void); void sub_809A7EC(void); @@ -54,6 +62,109 @@ Pokemon *sub_80A8D54(s16); void sub_80A7DDC(s16 *, s16*); u8 IsStarterMonster(s16); s16 sub_80A8BFC(s32); +void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); +bool8 sub_809B18C(s32 *sp); +extern void sub_8099A34(s32 a0); +extern void sub_8099A48(s32 a0); +extern void GroundScriptLock(s16 index, s32 r1); +extern void GroundScriptLockJumpZero(s16 index); +extern u8 sub_802B2D4(void); +extern void sub_802B3B8(void); +extern u32 sub_802B358(void); +void sub_8096AF8(struct unkStruct_8096AF8 *, u8 slotIndex, u8 dungeon); +u8 sub_802DB28(u8, u8); +void sub_8096BD0(); +void ScenarioCalc(s16 varId, s32 main, s32 sub); +void MakuhitaDojo_Delete(); +u32 HandleMakuhitaDojoState(); +s16 sub_802FED0(); +u8 sub_801FB50(); +void NamingScreen_Free(); +s32 sub_80160D8(); +void ResetTextbox_809B294(); +s32 sub_801A8AC(); +void sub_801A928(); +s32 sub_8016080(); +void CleanConfirmNameMenu(); +u32 CreateConfirmNameMenu(u32 mode, u8 *name); +bool8 DrawCredits(s32 creditsCategoryIndex, s32); +u32 sub_8035574(); +void sub_803565C(); +u8 sub_8094D14(); +void sub_802465C(); +s32 sub_80246F0(); +s32 GetScriptVarValue(u8 *localVarBuf, s32 varId); +bool8 HasEvolutionCompleted(); +void GroundMap_ExecuteEvent(); +void SetScriptVarValue(u8 *localVarBuf, s32 varId, s32 val); +void CleanLuminousCave(); +u8 sub_80023E4(); +u8 CreateFriendListMenu(); +void PlayMenuSoundEffect(); +bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems); +s32 sub_801516C(); +void sub_80151A4(); +s32 sub_8015198(); +u8 sub_80211AC(); +void sub_80213A0(); +u8 sub_802132C(); +u8 MakuhitaDojo_New(); +u8 sub_803B050(); +void sub_803B100(); +u8 sub_801B60C(); +u8 CreateKecleonBros(); +s16 sub_80A2654(s16); +u8 sub_802F73C(); +u8 sub_802F848(); +s32 sub_802F8A0(); +void sub_802F974(); +s16 sub_802F90C(); +s16 sub_80A26B8(); +u8 sub_80302E8(); +s32 sub_80303AC(); +void sub_8030480(); +s16 sub_8030418(); +void PrepareSavePakWrite(); +u8 WriteSavePak(); +void FinishWriteSavePak(); +u8 CreateKangaskhanStorage(); +void sub_8011C28(); +u8 CreateHelperPelipperMenu(); +u8 CreateWigglytuffShop(); +u8 sub_8099328(); +void GetScriptVarScenario(s32 varId,u32 *outMain,u32 *outSub); +u32 sub_802E90C(); +void sub_802E918(); +u32 sub_80282DC(u8 *r0); +void sub_809927C(u8); +void sub_80282FC(void); +extern u8 CreateThankYouMailPelipper(void); +extern u8 sub_802E864(void); +extern u8 sub_802DFB0(void); +extern void CleanThankYouMailPelipper(void); +extern void CleanHelperPelipper(void); +extern void sub_802E06C(void); +extern void sub_802DC00(void); +extern void sub_801B72C(void); +extern u32 ThankYouMailPelipperCallback(void); +extern u32 HelperPelipperCallback(void); +extern u32 sub_802E890(void); +extern u32 sub_802DFD8(void); +extern u32 sub_802DBD4(void); +extern u32 sub_803B120(void); +extern u32 sub_801B6AC(void); +u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2); +bool8 sub_809B648(void); +void sub_809B57C(void); +bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, u8 *a3); +void sub_809C39C(void); +void sub_809C3D8(void); +void sub_809C504(void); +void sub_809C464(void); +void sub_809C478(void); +void sub_809C414(void); +void sub_809C4B0(void); +void sub_809C550(void); struct Unk8116040Struct { @@ -101,7 +212,7 @@ static const MenuItem gUnknown_811610C[] = {NULL, 0}, }; -static const MenuItem gUnknown_811612C[] = +static const MenuItem sEmptyMenuItems[] = { {NULL, 0}, }; @@ -677,107 +788,6 @@ bool8 sub_809AFAC(void) return (gUnknown_3001B64->unk0 == 4); } -struct unkStruct_8096AF8 -{ - bool8 unk0; - /* 0x2 */ s16 clientSpecies; - /* 0x4 */ s16 targetSpecies; -}; - -void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); -bool8 sub_809B18C(s32 *sp); -extern void sub_8099A34(s32 a0); -extern void sub_8099A48(s32 a0); -extern void GroundScriptLock(s16 index, s32 r1); -extern void GroundScriptLockJumpZero(s16 index); -extern u8 sub_802B2D4(void); -extern void sub_802B3B8(void); -extern u32 sub_802B358(void); -void sub_8096AF8(struct unkStruct_8096AF8 *, u8 slotIndex, u8 dungeon); -u8 sub_802DB28(u8, u8); -void sub_8096BD0(); -void ScenarioCalc(s16 varId, s32 main, s32 sub); -void MakuhitaDojo_Delete(); -u32 HandleMakuhitaDojoState(); -s16 sub_802FED0(); -u8 sub_801FB50(); -void NamingScreen_Free(); -s32 sub_80160D8(); -void ResetTextbox_809B294(); -s32 sub_801A8AC(); -void sub_801A928(); -s32 sub_8016080(); -void CleanConfirmNameMenu(); -u32 CreateConfirmNameMenu(u32 mode, u8 *name); -bool8 DrawCredits(s32 creditsCategoryIndex, s32); -u32 sub_8035574(); -void sub_803565C(); -u8 sub_8094D14(); -void sub_802465C(); -s32 sub_80246F0(); -s32 GetScriptVarValue(u8 *localVarBuf, s32 varId); -bool8 HasEvolutionCompleted(); -void GroundMap_ExecuteEvent(); -void SetScriptVarValue(u8 *localVarBuf, s32 varId, s32 val); -void CleanLuminousCave(); -u8 sub_80023E4(); -u8 CreateFriendListMenu(); -void PlayMenuSoundEffect(); -bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems); -s32 sub_801516C(); -void sub_80151A4(); -s32 sub_8015198(); -u8 sub_80211AC(); -void sub_80213A0(); -u8 sub_802132C(); -u8 MakuhitaDojo_New(); -u8 sub_803B050(); -void sub_803B100(); -s32 sub_809CCDC(); -u8 sub_801B60C(); -u8 CreateKecleonBros(); -s16 sub_80A2654(s16); -u8 sub_802F73C(); -u8 sub_802F848(); -s32 sub_802F8A0(); -void sub_802F974(); -s16 sub_802F90C(); -s16 sub_80A26B8(); -u8 sub_80302E8(); -s32 sub_80303AC(); -void sub_8030480(); -s16 sub_8030418(); -void PrepareSavePakWrite(); -u8 WriteSavePak(); -void FinishWriteSavePak(); -u8 CreateKangaskhanStorage(); -void sub_8011C28(); -u8 CreateHelperPelipperMenu(); -u8 CreateWigglytuffShop(); -u8 sub_8099328(); -void GetScriptVarScenario(s32 varId,u32 *outMain,u32 *outSub); -u32 sub_802E90C(); -void sub_802E918(); -u32 sub_80282DC(u8 *r0); -void sub_809927C(u8); -void sub_80282FC(void); -extern u8 CreateThankYouMailPelipper(void); -extern u8 sub_802E864(void); -extern u8 sub_802DFB0(void); -extern void CleanThankYouMailPelipper(void); -extern void CleanHelperPelipper(void); -extern void sub_802E06C(void); -extern void sub_802DC00(void); -extern void sub_801B72C(void); -extern u32 ThankYouMailPelipperCallback(void); -extern u32 HelperPelipperCallback(void); -extern u32 sub_802E890(void); -extern u32 sub_802DFD8(void); -extern u32 sub_802DBD4(void); -extern u32 sub_803B120(void); -extern u32 sub_809CD48(void); -extern u32 sub_801B6AC(void); - void sub_809AFC8(s32 a0_, s32 a1, s32 a2_, const char *text) { s32 a0 = (u8) a0_; @@ -797,19 +807,6 @@ bool8 sub_809AFFC(u8 *a0) return ret; } -u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2); -bool8 sub_809B648(void); -void sub_809B57C(void); -bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, u8 *a3); -void sub_809C39C(void); -void sub_809C3D8(void); -void sub_809C504(void); -void sub_809C464(void); -void sub_809C478(void); -void sub_809C414(void); -void sub_809C4B0(void); -void sub_809C550(void); - void sub_809B028(const MenuItem * menuItems, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text) { s32 a1 = (u8) a1_; @@ -1276,7 +1273,7 @@ static const struct unkStruct_3001B64_unk418 gUnknown_8116308 = .unk0 = 0, .unk4 = NULL, .unk8 = NULL, - .unkC = sub_809CD48, + .unkC = ScriptItemTextboxFunc, }; static const struct unkStruct_3001B64_unk418 gUnknown_8116318 = @@ -1436,7 +1433,7 @@ bool8 sub_809B648(void) ResetTextbox_809B294(); if (gUnknown_3001B64->unk420 == 1) { ResetTextbox_809B294(); - if (!sub_8015080(gUnknown_3001B64->unk42C, gUnknown_811612C)) { + if (!sub_8015080(gUnknown_3001B64->unk42C, sEmptyMenuItems)) { gUnknown_3001B64->unk430 = -1; return 0; } @@ -1833,7 +1830,7 @@ bool8 sub_809B648(void) gUnknown_3001B64->unk430 = -2; return 0; case 0x2b: - gUnknown_3001B64->unk430 = sub_809CCDC(gUnknown_3001B64->unk424,gUnknown_3001B64->unk428); + gUnknown_3001B64->unk430 = TryGiveScriptItem(gUnknown_3001B64->unk424,gUnknown_3001B64->unk428); gUnknown_3001B64->unk418 = &gUnknown_8116308; return 1; case 0x2c: { diff --git a/src/code_809C5C4.c b/src/code_809C5C4.c index 6b07d91ff..3b7034290 100644 --- a/src/code_809C5C4.c +++ b/src/code_809C5C4.c @@ -1,13 +1,10 @@ #include "global.h" -#include "items.h" +#include "globaldata.h" #include "memory.h" #include "game_options.h" #include "event_flag.h" #include "ground_main.h" #include "code_80A26CC.h" -#include "code_800D090.h" -#include "music_util.h" -#include "string_format.h" struct unkStruct_3001B68 { @@ -27,18 +24,9 @@ struct unkStruct_3001B68 u8 unk20; }; -IWRAM_INIT struct unkStruct_3001B68 *gUnknown_3001B68 = {NULL}; - - -struct unkStruct_20399E0 -{ - u32 unk0; - s32 unk4; - u32 unk8; -}; - -EWRAM_DATA struct unkStruct_20399E0 *gUnknown_20399E0 = {0}; +static IWRAM_INIT struct unkStruct_3001B68 *gUnknown_3001B68 = {NULL}; +UNUSED static const u8 sUnused[4] = {0}; void sub_809C63C(); u8 sub_809C740(void); @@ -53,12 +41,6 @@ void nullsub_114(); void nullsub_115(); void nullsub_116(); -extern const char gUnknown_8116390[]; -extern const char gUnknown_811636C[]; -extern const char gUnknown_811633C[]; - -EWRAM_INIT const char *gUnknown_203B4A0[3] = {gUnknown_8116390, gUnknown_811636C, gUnknown_811633C}; - void sub_809C5C4(void) { gUnknown_3001B68 = MemoryAlloc(sizeof(struct unkStruct_3001B68), 6); @@ -396,7 +378,6 @@ void sub_809CA20(void) } } - void nullsub_106(void) {} void nullsub_107(void) {} void nullsub_108(void) {} @@ -408,139 +389,3 @@ void nullsub_113(void) {} void nullsub_114(void) {} void nullsub_115(void) {} void nullsub_116(void) {} - -void sub_809CB50(void) -{ - gUnknown_20399E0 = MemoryAlloc(sizeof(struct unkStruct_20399E0), 6); - gUnknown_20399E0->unk4 = -1; - gUnknown_20399E0->unk8 = 0; -} - -void sub_809CB74(void) -{ - MemoryFree(gUnknown_20399E0); - gUnknown_20399E0 = NULL; -} - - -void sub_809CB8C(void) -{ - ClearScriptVarArray(NULL, STATION_ITEM_TEMP); - ClearScriptVarArray(NULL, DELIVER_ITEM_TEMP); -} - -bool8 HasItemInInventory(u8 item) -{ - if (FindItemInInventory(item) >= 0) - return TRUE; - else - return FALSE; -} - -extern bool8 ScriptPrintText(s32 a0, s32 a1_, const char *text); -extern u8 IsTextboxOpen_809A750(void); - -extern const u8 gUnknown_81163E4[]; - -struct ItemWithQuantity -{ - u8 id; - s16 quantity; -}; - -static bool8 sub_809CBBC(const struct ItemWithQuantity *itemToAdd, const u8 *maxMoneyStr, const u8 *noItemSpaceStr, const u8 *itemGivenStr) -{ - char buffer[80]; - - if (itemToAdd->id == ITEM_POKE) { - int newMoneyAmount; - sprintfStatic(buffer,gUnknown_81163E4,itemToAdd->quantity,gItemParametersData[ITEM_POKE].name); - newMoneyAmount = gTeamInventoryRef->teamMoney + itemToAdd->quantity; - if (newMoneyAmount > MAX_TEAM_MONEY) { - if (maxMoneyStr != 0) { - ScriptPrintText(0, -1, maxMoneyStr); - } - return FALSE; - } - - gTeamInventoryRef->teamMoney = newMoneyAmount; - } - else { - Item item = {0}; - item.quantity = itemToAdd->quantity; - item.id = itemToAdd->id; - - sub_8090E14(buffer,&item,0); - if (GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) { - if (noItemSpaceStr != 0) { - ScriptPrintText(0, -1, noItemSpaceStr); - } - return FALSE; - } - - AddItemIdToInventory(item.id, FALSE); - FillInventoryGaps(); - } - - if (itemGivenStr != 0) { - strcpy(gFormatBuffer_Items[0], buffer); - ScriptPrintText(0, -1, itemGivenStr); - PlaySoundWithVolume(0xcb,0x100); - } - - return TRUE; -} - -extern const struct ItemWithQuantity gUnknown_81163BC[]; - -s32 sub_809CC90(s32 tableId) -{ - const struct ItemWithQuantity *item = &gUnknown_81163BC[tableId]; - if (item->id == ITEM_POKE) { - if (gTeamInventoryRef->teamMoney + item->quantity > MAX_TEAM_MONEY) - return 2; - } - else { - if (GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) - return 2; - } - return 1; -} - -extern const u8 gUnknown_81163F0[]; -extern const u8 gUnknown_811642C[]; - -s32 sub_809CCDC(u32 tableId, s32 a1) -{ - s32 strId; - const struct ItemWithQuantity *item = &gUnknown_81163BC[tableId]; - gUnknown_20399E0->unk4 = -1; - gUnknown_20399E0->unk8 = 0; - - if (a1 > 99) { - strId = 2; - } - else if (a1 > 1) { - strId = 1; - } - else { - strId = 0; - } - - if (sub_809CBBC(item, gUnknown_81163F0, gUnknown_811642C, gUnknown_203B4A0[strId])) { - gUnknown_20399E0->unk4 = tableId; - gUnknown_20399E0->unk8 = a1; - return 1; - } - else { - return 2; - } -} - -s32 sub_809CD48(void) -{ - if (IsTextboxOpen_809A750()) { - return 0; - } - return 3; -} diff --git a/src/code_809D148.c b/src/code_809D148.c index d7f375480..8a9183282 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -93,11 +93,6 @@ void sub_809D148(s32 r0) } -struct Test1 -{ - u64 ukn0; -}; - void sub_809D158(s32 r0, const PixelPos *r1) { gUnknown_20399E8.unk0 = r0; diff --git a/src/debug_field_map.c b/src/debug_field_map.c index 3d0f364bd..ae57c5ec2 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -15,6 +15,7 @@ #include "string_format.h" #include "sprite.h" #include "game_options.h" +#include "ground_lives_helper.h" #include "input.h" #include "structs/str_position.h" @@ -27,7 +28,6 @@ extern void sub_80999E8(s32 a0); extern void nullsub_120(void); extern void sub_80A59DC(void); extern void sub_809D25C(void); -extern s32 DpadToDirection(u16 param_1); extern PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); extern void sub_809D158(s32, PixelPos*); @@ -68,7 +68,6 @@ UNUSED static void DebugMapViewer(void) break; default: continue; - } break; } diff --git a/src/ground_main.c b/src/ground_main.c index b35035c3a..6304c1615 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -19,6 +19,7 @@ #include "text_util.h" #include "ground_map_conversion_table.h" #include "ground_lives_helper.h" +#include "script_item.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -51,7 +52,6 @@ extern void sub_809B638(); extern void nullsub_106(); extern void sub_80A73EC(); -extern void sub_809CB8C(); extern void sub_8098CC8(); extern void ClearAllItems_8091FB4(); extern u8 sub_809C730(); @@ -74,7 +74,6 @@ extern void FreeGroundLives(void); extern void FreeGroundObjects(void); extern void FreeGroundEffects(void); extern void FreeGroundEvents(void); -extern void sub_809CB74(void); extern void sub_809A610(void); extern void sub_809C618(void); extern void sub_80A658C(void); @@ -91,7 +90,6 @@ extern void sub_809D490(void); extern void sub_80A62F0(void); extern void sub_809C5C4(void); extern void sub_809A560(void); -extern void sub_809CB50(void); extern void AllocGroundMapAction(void); extern void AllocGroundEvents(void); extern void AllocGroundLives(void); @@ -200,7 +198,7 @@ u32 xxx_script_related_8098468(s32 param_1) sub_80A62F0(); sub_809C5C4(); sub_809A560(); - sub_809CB50(); + InitInternalScriptItemsData(); AllocGroundMapAction(); nullsub_117(); AllocGroundEvents(); @@ -393,7 +391,7 @@ u32 xxx_script_related_8098468(s32 param_1) FreeGroundObjects(); FreeGroundEffects(); FreeGroundEvents(); - sub_809CB74(); + FreeInternalScriptItemsData(); sub_809A610(); sub_809C618(); sub_80A658C(); @@ -508,7 +506,7 @@ void sub_8098C58(void) s32 temp, temp2; ClearScriptVarArray(NULL, GROUND_LOCAL); ClearScriptVarArray(NULL, EVENT_LOCAL); - sub_809CB8C(); + ClearScriptItemScriptVars(); sub_8001D88(); if (GetScriptVarValue(NULL, FLAG_KIND_CHANGE_REQUEST) != 0) { diff --git a/src/ground_script.c b/src/ground_script.c index 8cc0945d8..1c810971d 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -44,6 +44,7 @@ #include "palette_util.h" #include "pokemon_3.h" #include "memory.h" +#include "script_item.h" #include "ground_lives_helper.h" #include "friend_area_dialogue.h" #include "structs/str_dungeon_setup.h" @@ -97,8 +98,6 @@ u32 sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char * bool8 sub_809B1C0(s32, s32, char[12]); void sub_809B1D4(u8, s32, s32, const char*); void sub_809C770(s16, s16); -s32 HasItemInInventory(u8); -u32 sub_809CC90(); void sub_809D0BC(void); void sub_809D124(s32, s32, s32); void sub_809D158(s32, PixelPos*); @@ -2885,7 +2884,7 @@ s32 ExecuteScriptCommand(Action *action) break; } case 0xcb: { - val = sub_809CC90(curCmd.argShort); + val = CheckScriptItemSpace(curCmd.argShort); break; } default: { diff --git a/src/script_item.c b/src/script_item.c new file mode 100644 index 000000000..8db7a8480 --- /dev/null +++ b/src/script_item.c @@ -0,0 +1,176 @@ +#include "global.h" +#include "globaldata.h" +#include "script_item.h" +#include "items.h" +#include "event_flag.h" +#include "music_util.h" +#include "memory.h" +#include "string_format.h" +#include "code_800D090.h" + +extern bool8 ScriptPrintText(s32 a0, s32 a1_, const char *text); +extern u8 IsTextboxOpen_809A750(void); + +// These are only written to. +struct ScriptItemsData +{ + u32 unk0; // Unused + s32 tableId; + u32 unk8; +}; + +EWRAM_DATA static struct ScriptItemsData *sScriptItemsData = {NULL}; + +enum { + RECEIVED_STR_ONE_REWARD, + RECEIVED_STR_ALSO_ITEM, + RECEIVED_STR_CASH, +}; + +// Should be just const instead of ewram init, since the pointers aren't modified. +EWRAM_INIT static const char *sItemReceivedStrings[3] = { + [RECEIVED_STR_ONE_REWARD] = _("{CENTER_ALIGN}{NAME_0}'s team received\n{CENTER_ALIGN}the reward {MOVE_ITEM_0}."), + [RECEIVED_STR_ALSO_ITEM] = _("{CENTER_ALIGN}The team also received\n{CENTER_ALIGN}one {MOVE_ITEM_0}."), + [RECEIVED_STR_CASH] = _("{CENTER_ALIGN}{NAME_0}'s team received\n{CENTER_ALIGN}the {MOVE_ITEM_0} cash reward."), +}; + +void InitInternalScriptItemsData(void) +{ + sScriptItemsData = MemoryAlloc(sizeof(struct ScriptItemsData), 6); + sScriptItemsData->tableId = -1; + sScriptItemsData->unk8 = 0; +} + +void FreeInternalScriptItemsData(void) +{ + FREE_AND_SET_NULL(sScriptItemsData); +} + +void ClearScriptItemScriptVars(void) +{ + ClearScriptVarArray(NULL, STATION_ITEM_TEMP); + ClearScriptVarArray(NULL, DELIVER_ITEM_TEMP); +} + +s32 HasItemInInventory(u8 item) +{ + if (FindItemInInventory(item) >= 0) + return TRUE; + else + return FALSE; +} + +struct ItemWithQuantity +{ + u8 id; + s16 quantity; +}; + +static const struct ItemWithQuantity sScriptItemsTable[] = { + {ITEM_ORAN_BERRY, 0}, + {ITEM_PECHA_BERRY, 0}, + {ITEM_RAWST_BERRY, 0}, + {ITEM_POKE, 500}, + {ITEM_REVIVER_SEED, 0}, + {ITEM_RAWST_BERRY, 0}, + {ITEM_POKE, 500}, + {ITEM_PECHA_SCARF, 0}, + {ITEM_RAWST_BERRY, 0}, + {ITEM_POKE, 10000}, +}; + +static bool8 TryAddItemWithText(const struct ItemWithQuantity *itemToAdd, const u8 *maxMoneyStr, const u8 *noItemSpaceStr, const u8 *itemGivenStr) +{ + char buffer[80]; + + if (itemToAdd->id == ITEM_POKE) { + int newMoneyAmount; + sprintfStatic(buffer,_("{COLOR CYAN_G}%d{RESET} %s"),itemToAdd->quantity,gItemParametersData[ITEM_POKE].name); + newMoneyAmount = gTeamInventoryRef->teamMoney + itemToAdd->quantity; + if (newMoneyAmount > MAX_TEAM_MONEY) { + if (maxMoneyStr != NULL) { + ScriptPrintText(0, -1, maxMoneyStr); + } + return FALSE; + } + + gTeamInventoryRef->teamMoney = newMoneyAmount; + } + else { + Item item = {0}; + item.quantity = itemToAdd->quantity; + item.id = itemToAdd->id; + + sub_8090E14(buffer,&item,0); + if (GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) { + if (noItemSpaceStr != NULL) { + ScriptPrintText(0, -1, noItemSpaceStr); + } + return FALSE; + } + + AddItemIdToInventory(item.id, FALSE); + FillInventoryGaps(); + } + + if (itemGivenStr != NULL) { + strcpy(gFormatBuffer_Items[0], buffer); + ScriptPrintText(0, -1, itemGivenStr); + PlaySoundWithVolume(0xcb,0x100); + } + + return TRUE; +} + +s32 CheckScriptItemSpace(s32 tableId) +{ + const struct ItemWithQuantity *item = &sScriptItemsTable[tableId]; + if (item->id == ITEM_POKE) { + if (gTeamInventoryRef->teamMoney + item->quantity > MAX_TEAM_MONEY) + return 2; + } + else { + if (GetNumberOfFilledInventorySlots() >= INVENTORY_SIZE) + return 2; + } + return 1; +} + +s32 TryGiveScriptItem(u32 tableId, s32 a1) +{ + s32 strId; + const struct ItemWithQuantity *item = &sScriptItemsTable[tableId]; + sScriptItemsData->tableId = -1; + sScriptItemsData->unk8 = 0; + + if (a1 > 99) { + strId = RECEIVED_STR_CASH; + } + else if (a1 > 1) { + strId = RECEIVED_STR_ALSO_ITEM; + } + else { + strId = RECEIVED_STR_ONE_REWARD; + } + + if (TryAddItemWithText(item, + _("{CENTER_ALIGN}However, {NAME_0}'s team\n{CENTER_ALIGN}had too much money already..."), + _("{CENTER_ALIGN}However, {NAME_0}'s team\n{CENTER_ALIGN}had too many items already..."), + sItemReceivedStrings[strId])) + { + sScriptItemsData->tableId = tableId; + sScriptItemsData->unk8 = a1; + return 1; + } + else { + return 2; + } +} + +u32 ScriptItemTextboxFunc(void) +{ + if (IsTextboxOpen_809A750()) { + return 0; + } + return 3; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index ba9a6aa68..8cc8e5b60 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -82,6 +82,7 @@ .include "src/palette_util.o" .include "src/code_809A560.o" .include "src/code_809C5C4.o" + .include "src/script_item.o" .space 4 .include "src/code_809D148.o" .include "src/ground_script.o" diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index acad92a01..a0077e7bb 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -137,7 +137,7 @@ .include "src/code_8097670.o" .include "src/exclusive_pokemon.o" .include "src/ground_main.o" -.include "src/code_809C5C4.o" +.include "src/script_item.o" .include "src/ground_script.o" .include "src/ground_sprite.o" .include "src/ground_link.o"