diff --git a/src/shop.c b/src/shop.c index 26bd964c5..dac43c96d 100755 --- a/src/shop.c +++ b/src/shop.c @@ -40,11 +40,14 @@ #include "constants/songs.h" #include "constants/tv.h" -EWRAM_DATA struct MartInfo gMartInfo = {0}; -EWRAM_DATA struct ShopData *gShopDataPtr = NULL; -EWRAM_DATA struct ListMenuItem *gUnknown_02039F74 = NULL; -EWRAM_DATA u8 (*gUnknown_02039F78)[16] = {0}; -EWRAM_DATA u8 gMartPurchaseHistoryId = 0; +#define TAG_SCROLL_ARROW 2100 +#define TAG_ITEM_ICON_BASE 2110 + +static EWRAM_DATA struct MartInfo sMartInfo = {0}; +static EWRAM_DATA struct ShopData *sShopData = NULL; +static EWRAM_DATA struct ListMenuItem *sListMenuItems = NULL; +static EWRAM_DATA u8 (*sItemNames)[16] = {0}; +static EWRAM_DATA u8 sPurchaseHistoryId = 0; EWRAM_DATA struct ItemSlot gMartPurchaseHistory[3] = {0}; static void Task_ShopMenu(u8 taskId); @@ -276,15 +279,15 @@ static u8 CreateShopMenu(u8 martType) int numMenuItems; ScriptContext2_Enable(); - gMartInfo.martType = martType; + sMartInfo.martType = martType; if (martType == MART_TYPE_NORMAL) { struct WindowTemplate winTemplate; winTemplate = sShopMenuWindowTemplates[0]; winTemplate.width = GetMaxWidthInMenuTable(sShopMenuActions_BuySellQuit, ARRAY_COUNT(sShopMenuActions_BuySellQuit)); - gMartInfo.windowId = AddWindow(&winTemplate); - gMartInfo.menuActions = sShopMenuActions_BuySellQuit; + sMartInfo.windowId = AddWindow(&winTemplate); + sMartInfo.menuActions = sShopMenuActions_BuySellQuit; numMenuItems = ARRAY_COUNT(sShopMenuActions_BuySellQuit); } else @@ -292,35 +295,35 @@ static u8 CreateShopMenu(u8 martType) struct WindowTemplate winTemplate; winTemplate = sShopMenuWindowTemplates[1]; winTemplate.width = GetMaxWidthInMenuTable(sShopMenuActions_BuyQuit, ARRAY_COUNT(sShopMenuActions_BuyQuit)); - gMartInfo.windowId = AddWindow(&winTemplate); - gMartInfo.menuActions = sShopMenuActions_BuyQuit; + sMartInfo.windowId = AddWindow(&winTemplate); + sMartInfo.menuActions = sShopMenuActions_BuyQuit; numMenuItems = ARRAY_COUNT(sShopMenuActions_BuyQuit); } - SetStandardWindowBorderStyle(gMartInfo.windowId, 0); - PrintMenuTable(gMartInfo.windowId, numMenuItems, gMartInfo.menuActions); - InitMenuInUpperLeftCornerPlaySoundWhenAPressed(gMartInfo.windowId, numMenuItems, 0); - PutWindowTilemap(gMartInfo.windowId); - CopyWindowToVram(gMartInfo.windowId, 1); + SetStandardWindowBorderStyle(sMartInfo.windowId, 0); + PrintMenuTable(sMartInfo.windowId, numMenuItems, sMartInfo.menuActions); + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sMartInfo.windowId, numMenuItems, 0); + PutWindowTilemap(sMartInfo.windowId); + CopyWindowToVram(sMartInfo.windowId, 1); return CreateTask(Task_ShopMenu, 8); } static void SetShopMenuCallback(void (* callback)(void)) { - gMartInfo.callback = callback; + sMartInfo.callback = callback; } static void SetShopItemsForSale(const u16 *items) { u16 i = 0; - gMartInfo.itemList = items; - gMartInfo.itemCount = 0; + sMartInfo.itemList = items; + sMartInfo.itemCount = 0; - while (gMartInfo.itemList[i]) + while (sMartInfo.itemList[i]) { - gMartInfo.itemCount++; + sMartInfo.itemCount++; i++; } } @@ -337,7 +340,7 @@ static void Task_ShopMenu(u8 taskId) Task_HandleShopMenuQuit(taskId); break; default: - gMartInfo.menuActions[inputCode].func.void_u8(taskId); + sMartInfo.menuActions[inputCode].func.void_u8(taskId); break; } } @@ -368,14 +371,14 @@ void CB2_ExitSellMenu(void) static void Task_HandleShopMenuQuit(u8 taskId) { - ClearStdWindowAndFrameToTransparent(gMartInfo.windowId, 2); - RemoveWindow(gMartInfo.windowId); + ClearStdWindowAndFrameToTransparent(sMartInfo.windowId, 2); + RemoveWindow(sMartInfo.windowId); SaveRecordedItemPurchasesForTVShow(); ScriptContext2_Disable(); DestroyTask(taskId); - if (gMartInfo.callback) - gMartInfo.callback(); + if (sMartInfo.callback) + sMartInfo.callback(); } static void Task_GoToBuyOrSellMenu(u8 taskId) @@ -398,7 +401,7 @@ static void Task_ReturnToShopMenu(u8 taskId) { if (IsWeatherNotFadingIn() == TRUE) { - if (gMartInfo.martType == MART_TYPE_DECOR2) + if (sMartInfo.martType == MART_TYPE_DECOR2) DisplayItemMessageOnField(taskId, gText_CanIHelpWithAnythingElse, ShowShopMenuAfterExitingBuyOrSellMenu); else DisplayItemMessageOnField(taskId, gText_AnythingElseICanHelp, ShowShopMenuAfterExitingBuyOrSellMenu); @@ -407,7 +410,7 @@ static void Task_ReturnToShopMenu(u8 taskId) static void ShowShopMenuAfterExitingBuyOrSellMenu(u8 taskId) { - CreateShopMenu(gMartInfo.martType); + CreateShopMenu(sMartInfo.martType); DestroyTask(taskId); } @@ -447,10 +450,10 @@ static void CB2_InitBuyMenu(void) ResetSpriteData(); ResetTasks(); ClearScheduledBgCopiesToVram(); - gShopDataPtr = AllocZeroed(sizeof(struct ShopData)); - gShopDataPtr->scrollIndicatorsTaskId = TASK_NONE; - gShopDataPtr->itemSpriteIds[0] = SPRITE_NONE; - gShopDataPtr->itemSpriteIds[1] = SPRITE_NONE; + sShopData = AllocZeroed(sizeof(struct ShopData)); + sShopData->scrollIndicatorsTaskId = TASK_NONE; + sShopData->itemSpriteIds[0] = SPRITE_NONE; + sShopData->itemSpriteIds[1] = SPRITE_NONE; BuyMenuBuildListMenuTemplate(); BuyMenuInitBgs(); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); @@ -480,9 +483,9 @@ static void CB2_InitBuyMenu(void) static void BuyMenuFreeMemory(void) { - Free(gShopDataPtr); - Free(gUnknown_02039F74); - Free(gUnknown_02039F78); + Free(sShopData); + Free(sListMenuItems); + Free(sItemNames); FreeAllWindowBuffers(); } @@ -490,29 +493,29 @@ static void BuyMenuBuildListMenuTemplate(void) { u16 i; - gUnknown_02039F74 = Alloc((gMartInfo.itemCount + 1) * sizeof(*gUnknown_02039F74)); - gUnknown_02039F78 = Alloc((gMartInfo.itemCount + 1) * sizeof(*gUnknown_02039F78)); - for (i = 0; i < gMartInfo.itemCount; i++) - BuyMenuSetListEntry(&gUnknown_02039F74[i], gMartInfo.itemList[i], gUnknown_02039F78[i]); + sListMenuItems = Alloc((sMartInfo.itemCount + 1) * sizeof(*sListMenuItems)); + sItemNames = Alloc((sMartInfo.itemCount + 1) * sizeof(*sItemNames)); + for (i = 0; i < sMartInfo.itemCount; i++) + BuyMenuSetListEntry(&sListMenuItems[i], sMartInfo.itemList[i], sItemNames[i]); - StringCopy(gUnknown_02039F78[i], gText_Cancel2); - gUnknown_02039F74[i].name = gUnknown_02039F78[i]; - gUnknown_02039F74[i].id = -2; + StringCopy(sItemNames[i], gText_Cancel2); + sListMenuItems[i].name = sItemNames[i]; + sListMenuItems[i].id = LIST_CANCEL; gMultiuseListMenuTemplate = sShopBuyMenuListTemplate; - gMultiuseListMenuTemplate.items = gUnknown_02039F74; - gMultiuseListMenuTemplate.totalItems = gMartInfo.itemCount + 1; + gMultiuseListMenuTemplate.items = sListMenuItems; + gMultiuseListMenuTemplate.totalItems = sMartInfo.itemCount + 1; if (gMultiuseListMenuTemplate.totalItems > 8) gMultiuseListMenuTemplate.maxShowed = 8; else gMultiuseListMenuTemplate.maxShowed = gMultiuseListMenuTemplate.totalItems; - gShopDataPtr->itemsShowed = gMultiuseListMenuTemplate.maxShowed; + sShopData->itemsShowed = gMultiuseListMenuTemplate.maxShowed; } static void BuyMenuSetListEntry(struct ListMenuItem *menuItem, u16 item, u8 *name) { - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) CopyItemName(item, name); else StringCopy(name, gDecorations[item].name); @@ -527,16 +530,16 @@ static void BuyMenuPrintItemDescriptionAndShowItemIcon(s32 item, bool8 onInit, s if (onInit != TRUE) PlaySE(SE_SELECT); - if (item != -2) - BuyMenuAddItemIcon(item, gShopDataPtr->iconSlot); + if (item != LIST_CANCEL) + BuyMenuAddItemIcon(item, sShopData->iconSlot); else - BuyMenuAddItemIcon(-1, gShopDataPtr->iconSlot); + BuyMenuAddItemIcon(-1, sShopData->iconSlot); - BuyMenuRemoveItemIcon(item, gShopDataPtr->iconSlot ^ 1); - gShopDataPtr->iconSlot ^= 1; - if (item != -2) + BuyMenuRemoveItemIcon(item, sShopData->iconSlot ^ 1); + sShopData->iconSlot ^= 1; + if (item != LIST_CANCEL) { - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) description = ItemId_GetDescription(item); else description = gDecorations[item].description; @@ -554,9 +557,9 @@ static void BuyMenuPrintPriceInList(u8 windowId, s32 item, u8 y) { u8 x; - if (item != -2) + if (item != LIST_CANCEL) { - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) { ConvertIntToDecimalStringN( gStringVar1, @@ -581,26 +584,26 @@ static void BuyMenuPrintPriceInList(u8 windowId, s32 item, u8 y) static void BuyMenuAddScrollIndicatorArrows(void) { - if (gShopDataPtr->scrollIndicatorsTaskId == TASK_NONE && gMartInfo.itemCount + 1 > 8) + if (sShopData->scrollIndicatorsTaskId == TASK_NONE && sMartInfo.itemCount + 1 > 8) { - gShopDataPtr->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized( + sShopData->scrollIndicatorsTaskId = AddScrollIndicatorArrowPairParameterized( SCROLL_ARROW_UP, - 0xAC, - 0xC, - 0x94, - gMartInfo.itemCount - 7, - 2100, - 2100, - &gShopDataPtr->scrollOffset); + 172, + 12, + 148, + sMartInfo.itemCount - 7, + TAG_SCROLL_ARROW, + TAG_SCROLL_ARROW, + &sShopData->scrollOffset); } } static void BuyMenuRemoveScrollIndicatorArrows(void) { - if (gShopDataPtr->scrollIndicatorsTaskId != TASK_NONE) + if (sShopData->scrollIndicatorsTaskId != TASK_NONE) { - RemoveScrollIndicatorArrowPair(gShopDataPtr->scrollIndicatorsTaskId); - gShopDataPtr->scrollIndicatorsTaskId = TASK_NONE; + RemoveScrollIndicatorArrowPair(sShopData->scrollIndicatorsTaskId); + sShopData->scrollIndicatorsTaskId = TASK_NONE; } } @@ -613,13 +616,13 @@ static void BuyMenuPrintCursor(u8 scrollIndicatorsTaskId, u8 colorSet) static void BuyMenuAddItemIcon(u16 item, u8 iconSlot) { u8 spriteId; - u8 *spriteIdPtr = &gShopDataPtr->itemSpriteIds[iconSlot]; + u8 *spriteIdPtr = &sShopData->itemSpriteIds[iconSlot]; if (*spriteIdPtr != SPRITE_NONE) return; - if (gMartInfo.martType == MART_TYPE_NORMAL || item == 0xFFFF) + if (sMartInfo.martType == MART_TYPE_NORMAL || item == 0xFFFF) { - spriteId = AddItemIconSprite(iconSlot + 2110, iconSlot + 2110, item); + spriteId = AddItemIconSprite(iconSlot + TAG_ITEM_ICON_BASE, iconSlot + TAG_ITEM_ICON_BASE, item); if (spriteId != MAX_SPRITES) { *spriteIdPtr = spriteId; @@ -629,7 +632,7 @@ static void BuyMenuAddItemIcon(u16 item, u8 iconSlot) } else { - spriteId = AddDecorationIconObject(item, 20, 84, 1, iconSlot + 2110, iconSlot + 2110); + spriteId = AddDecorationIconObject(item, 20, 84, 1, iconSlot + TAG_ITEM_ICON_BASE, iconSlot + TAG_ITEM_ICON_BASE); if (spriteId != MAX_SPRITES) *spriteIdPtr = spriteId; } @@ -637,12 +640,12 @@ static void BuyMenuAddItemIcon(u16 item, u8 iconSlot) static void BuyMenuRemoveItemIcon(u16 item, u8 iconSlot) { - u8 *spriteIdPtr = &gShopDataPtr->itemSpriteIds[iconSlot]; + u8 *spriteIdPtr = &sShopData->itemSpriteIds[iconSlot]; if (*spriteIdPtr == SPRITE_NONE) return; - FreeSpriteTilesByTag(iconSlot + 2110); - FreeSpritePaletteByTag(iconSlot + 2110); + FreeSpriteTilesByTag(iconSlot + TAG_ITEM_ICON_BASE); + FreeSpritePaletteByTag(iconSlot + TAG_ITEM_ICON_BASE); DestroySprite(&gSprites[*spriteIdPtr]); *spriteIdPtr = SPRITE_NONE; } @@ -651,9 +654,9 @@ static void BuyMenuInitBgs(void) { ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sShopBuyMenuBgTemplates, ARRAY_COUNT(sShopBuyMenuBgTemplates)); - SetBgTilemapBuffer(1, gShopDataPtr->tilemapBuffers[1]); - SetBgTilemapBuffer(2, gShopDataPtr->tilemapBuffers[3]); - SetBgTilemapBuffer(3, gShopDataPtr->tilemapBuffers[2]); + SetBgTilemapBuffer(1, sShopData->tilemapBuffers[1]); + SetBgTilemapBuffer(2, sShopData->tilemapBuffers[3]); + SetBgTilemapBuffer(3, sShopData->tilemapBuffers[2]); SetGpuReg(REG_OFFSET_BG0HOFS, 0); SetGpuReg(REG_OFFSET_BG0VOFS, 0); SetGpuReg(REG_OFFSET_BG1HOFS, 0); @@ -673,7 +676,7 @@ static void BuyMenuInitBgs(void) static void BuyMenuDecompressBgGraphics(void) { DecompressAndCopyTileDataToVram(1, gBuyMenuFrame_Gfx, 0x3A0, 0x3E3, 0); - LZDecompressWram(gBuyMenuFrame_Tilemap, gShopDataPtr->tilemapBuffers[0]); + LZDecompressWram(gBuyMenuFrame_Tilemap, sShopData->tilemapBuffers[0]); LoadCompressedPalette(gMenuMoneyPal, 0xC0, 0x20); } @@ -763,16 +766,16 @@ static void BuyMenuDrawMapMetatile(s16 x, s16 y, const u16 *src, u8 metatileLaye switch (metatileLayerType) { case 0: - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src); - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[1], offset1, offset2, src + 4); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[3], offset1, offset2, src); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[1], offset1, offset2, src + 4); break; case 1: - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src); - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src + 4); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[2], offset1, offset2, src); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[3], offset1, offset2, src + 4); break; case 2: - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src); - BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[1], offset1, offset2, src + 4); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[2], offset1, offset2, src); + BuyMenuDrawMapMetatileLayer(sShopData->tilemapBuffers[1], offset1, offset2, src + 4); break; } } @@ -796,7 +799,7 @@ static void BuyMenuCollectObjectEventData(void) GetXYCoordsOneStepInFrontOfPlayer(&facingX, &facingY); for (y = 0; y < OBJECT_EVENTS_COUNT; y++) - gShopDataPtr->viewportObjects[y][OBJ_EVENT_ID] = OBJECT_EVENTS_COUNT; + sShopData->viewportObjects[y][OBJ_EVENT_ID] = OBJECT_EVENTS_COUNT; for (y = 0; y < 5; y++) { for (x = 0; x < 7; x++) @@ -805,25 +808,25 @@ static void BuyMenuCollectObjectEventData(void) if (objEventId != OBJECT_EVENTS_COUNT) { - gShopDataPtr->viewportObjects[r8][OBJ_EVENT_ID] = objEventId; - gShopDataPtr->viewportObjects[r8][X_COORD] = x; - gShopDataPtr->viewportObjects[r8][Y_COORD] = y; - gShopDataPtr->viewportObjects[r8][LAYER_TYPE] = MapGridGetMetatileLayerTypeAt(facingX - 4 + x, facingY - 2 + y); + sShopData->viewportObjects[r8][OBJ_EVENT_ID] = objEventId; + sShopData->viewportObjects[r8][X_COORD] = x; + sShopData->viewportObjects[r8][Y_COORD] = y; + sShopData->viewportObjects[r8][LAYER_TYPE] = MapGridGetMetatileLayerTypeAt(facingX - 4 + x, facingY - 2 + y); switch (gObjectEvents[objEventId].facingDirection) { case DIR_SOUTH: - gShopDataPtr->viewportObjects[r8][ANIM_NUM] = 0; + sShopData->viewportObjects[r8][ANIM_NUM] = 0; break; case DIR_NORTH: - gShopDataPtr->viewportObjects[r8][ANIM_NUM] = 1; + sShopData->viewportObjects[r8][ANIM_NUM] = 1; break; case DIR_WEST: - gShopDataPtr->viewportObjects[r8][ANIM_NUM] = 2; + sShopData->viewportObjects[r8][ANIM_NUM] = 2; break; case DIR_EAST: default: - gShopDataPtr->viewportObjects[r8][ANIM_NUM] = 3; + sShopData->viewportObjects[r8][ANIM_NUM] = 3; break; } r8++; @@ -840,25 +843,25 @@ static void BuyMenuDrawObjectEvents(void) for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { - if (gShopDataPtr->viewportObjects[i][OBJ_EVENT_ID] == OBJECT_EVENTS_COUNT) + if (sShopData->viewportObjects[i][OBJ_EVENT_ID] == OBJECT_EVENTS_COUNT) continue; - graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[gShopDataPtr->viewportObjects[i][OBJ_EVENT_ID]].graphicsId); + graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[sShopData->viewportObjects[i][OBJ_EVENT_ID]].graphicsId); spriteId = AddPseudoObjectEvent( - gObjectEvents[gShopDataPtr->viewportObjects[i][OBJ_EVENT_ID]].graphicsId, + gObjectEvents[sShopData->viewportObjects[i][OBJ_EVENT_ID]].graphicsId, SpriteCallbackDummy, - (u16)gShopDataPtr->viewportObjects[i][X_COORD] * 16 + 8, - (u16)gShopDataPtr->viewportObjects[i][Y_COORD] * 16 + 48 - graphicsInfo->height / 2, + (u16)sShopData->viewportObjects[i][X_COORD] * 16 + 8, + (u16)sShopData->viewportObjects[i][Y_COORD] * 16 + 48 - graphicsInfo->height / 2, 2); - if (BuyMenuCheckIfObjectEventOverlapsMenuBg(gShopDataPtr->viewportObjects[i]) == TRUE) + if (BuyMenuCheckIfObjectEventOverlapsMenuBg(sShopData->viewportObjects[i]) == TRUE) { gSprites[spriteId].subspriteTableNum = 4; gSprites[spriteId].subspriteMode = SUBSPRITES_ON; } - StartSpriteAnim(&gSprites[spriteId], gShopDataPtr->viewportObjects[i][ANIM_NUM]); + StartSpriteAnim(&gSprites[spriteId], sShopData->viewportObjects[i][ANIM_NUM]); } } @@ -877,8 +880,8 @@ static bool8 BuyMenuCheckIfObjectEventOverlapsMenuBg(s16 *object) static void BuyMenuCopyMenuBgToBg1TilemapBuffer(void) { s16 i; - u16 *dest = gShopDataPtr->tilemapBuffers[1]; - const u16 *src = gShopDataPtr->tilemapBuffers[0]; + u16 *dest = sShopData->tilemapBuffers[1]; + const u16 *src = sShopData->tilemapBuffers[0]; for (i = 0; i < 1024; i++) { @@ -891,7 +894,7 @@ static void BuyMenuCopyMenuBgToBg1TilemapBuffer(void) static bool8 BuyMenuCheckForOverlapWithMenuBg(int x, int y) { - const u16 *metatile = gShopDataPtr->tilemapBuffers[0]; + const u16 *metatile = sShopData->tilemapBuffers[0]; int offset1 = x * 2; int offset2 = y * 64; @@ -913,7 +916,7 @@ static void Task_BuyMenu(u8 taskId) if (!gPaletteFade.active) { s32 itemId = ListMenu_ProcessInput(tListTaskId); - ListMenuGetScrollAndRow(tListTaskId, &gShopDataPtr->scrollOffset, &gShopDataPtr->selectedRow); + ListMenuGetScrollAndRow(tListTaskId, &sShopData->scrollOffset, &sShopData->selectedRow); switch (itemId) { @@ -930,22 +933,22 @@ static void Task_BuyMenu(u8 taskId) BuyMenuRemoveScrollIndicatorArrows(); BuyMenuPrintCursor(tListTaskId, 2); - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) { - gShopDataPtr->totalCost = (ItemId_GetPrice(itemId) >> GetPriceReduction(POKENEWS_SLATEPORT)); + sShopData->totalCost = (ItemId_GetPrice(itemId) >> GetPriceReduction(POKENEWS_SLATEPORT)); } else { - gShopDataPtr->totalCost = gDecorations[itemId].price; + sShopData->totalCost = gDecorations[itemId].price; } - if (!IsEnoughMoney(&gSaveBlock1Ptr->money, gShopDataPtr->totalCost)) + if (!IsEnoughMoney(&gSaveBlock1Ptr->money, sShopData->totalCost)) { BuyMenuDisplayMessage(taskId, gText_YouDontHaveMoney, BuyMenuReturnToItemList); } else { - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) { CopyItemName(itemId, gStringVar1); if (ItemId_GetPocket(itemId) == POCKET_TM_HM) @@ -961,9 +964,9 @@ static void Task_BuyMenu(u8 taskId) else { StringCopy(gStringVar1, gDecorations[itemId].name); - ConvertIntToDecimalStringN(gStringVar2, gShopDataPtr->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); + ConvertIntToDecimalStringN(gStringVar2, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); - if (gMartInfo.martType == MART_TYPE_DECOR) + if (sMartInfo.martType == MART_TYPE_DECOR) StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2); else // MART_TYPE_DECOR2 StringExpandPlaceholders(gStringVar4, gText_YouWantedVar1ThatllBeVar2); @@ -992,15 +995,15 @@ static void Task_BuyHowManyDialogueInit(u8 taskId) BuyMenuPrintItemQuantityAndPrice(taskId); ScheduleBgCopyTilemapToVram(0); - maxQuantity = GetMoney(&gSaveBlock1Ptr->money) / gShopDataPtr->totalCost; + maxQuantity = GetMoney(&gSaveBlock1Ptr->money) / sShopData->totalCost; if (maxQuantity > MAX_BAG_ITEM_CAPACITY) { - gShopDataPtr->maxQuantity = MAX_BAG_ITEM_CAPACITY; + sShopData->maxQuantity = MAX_BAG_ITEM_CAPACITY; } else { - gShopDataPtr->maxQuantity = maxQuantity; + sShopData->maxQuantity = maxQuantity; } gTasks[taskId].func = Task_BuyHowManyDialogueHandleInput; @@ -1010,9 +1013,9 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) { s16 *data = gTasks[taskId].data; - if (AdjustQuantityAccordingToDPadInput(&tItemCount, gShopDataPtr->maxQuantity) == TRUE) + if (AdjustQuantityAccordingToDPadInput(&tItemCount, sShopData->maxQuantity) == TRUE) { - gShopDataPtr->totalCost = (ItemId_GetPrice(tItemId) >> GetPriceReduction(POKENEWS_SLATEPORT)) * tItemCount; + sShopData->totalCost = (ItemId_GetPrice(tItemId) >> GetPriceReduction(POKENEWS_SLATEPORT)) * tItemCount; BuyMenuPrintItemQuantityAndPrice(taskId); } else @@ -1027,7 +1030,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) PutWindowTilemap(1); CopyItemName(tItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, BAG_ITEM_CAPACITY_DIGITS); - ConvertIntToDecimalStringN(gStringVar3, gShopDataPtr->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); + ConvertIntToDecimalStringN(gStringVar3, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); BuyMenuDisplayMessage(taskId, gText_Var1AndYouWantedVar2, BuyMenuConfirmPurchase); } else if (JOY_NEW(B_BUTTON)) @@ -1053,7 +1056,7 @@ static void BuyMenuTryMakePurchase(u8 taskId) PutWindowTilemap(1); - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) { if (AddBagItem(tItemId, tItemCount) == TRUE) { @@ -1069,7 +1072,7 @@ static void BuyMenuTryMakePurchase(u8 taskId) { if (DecorationAdd(tItemId)) { - if (gMartInfo.martType == MART_TYPE_DECOR) + if (sMartInfo.martType == MART_TYPE_DECOR) BuyMenuDisplayMessage(taskId, gText_ThankYouIllSendItHome, BuyMenuSubtractMoney); else // MART_TYPE_DECOR2 BuyMenuDisplayMessage(taskId, gText_ThanksIllSendItHome, BuyMenuSubtractMoney); @@ -1084,11 +1087,11 @@ static void BuyMenuTryMakePurchase(u8 taskId) static void BuyMenuSubtractMoney(u8 taskId) { IncrementGameStat(GAME_STAT_SHOPPED); - RemoveMoney(&gSaveBlock1Ptr->money, gShopDataPtr->totalCost); + RemoveMoney(&gSaveBlock1Ptr->money, sShopData->totalCost); PlaySE(SE_SHOP); PrintMoneyAmountInMoneyBox(0, GetMoney(&gSaveBlock1Ptr->money), 0); - if (gMartInfo.martType == MART_TYPE_NORMAL) + if (sMartInfo.martType == MART_TYPE_NORMAL) { gTasks[taskId].func = Task_ReturnToItemListAfterItemPurchase; } @@ -1143,7 +1146,7 @@ static void BuyMenuPrintItemQuantityAndPrice(u8 taskId) s16 *data = gTasks[taskId].data; FillWindowPixelBuffer(4, PIXEL_FILL(1)); - PrintMoneyAmount(4, 38, 1, gShopDataPtr->totalCost, TEXT_SPEED_FF); + PrintMoneyAmount(4, 38, 1, sShopData->totalCost, TEXT_SPEED_FF); ConvertIntToDecimalStringN(gStringVar1, tItemCount, STR_CONV_MODE_LEADING_ZEROS, BAG_ITEM_CAPACITY_DIGITS); StringExpandPlaceholders(gStringVar4, gText_xVar1); BuyMenuPrint(4, gStringVar4, 0, 1, 0, 0); @@ -1169,7 +1172,7 @@ static void Task_ExitBuyMenu(u8 taskId) static void ClearItemPurchases(void) { - gMartPurchaseHistoryId = 0; + sPurchaseHistoryId = 0; memset(gMartPurchaseHistory, 0, sizeof(gMartPurchaseHistory)); } @@ -1179,27 +1182,23 @@ static void RecordItemPurchase(u8 taskId) u16 i; - for (i = 0; i < 3; i++) + for (i = 0; i < ARRAY_COUNT(gMartPurchaseHistory); i++) { if (gMartPurchaseHistory[i].itemId == tItemId && gMartPurchaseHistory[i].quantity != 0) { if (gMartPurchaseHistory[i].quantity + tItemCount > 255) - { gMartPurchaseHistory[i].quantity = 255; - } else - { gMartPurchaseHistory[i].quantity += tItemCount; - } return; } } - if (gMartPurchaseHistoryId < 3) + if (sPurchaseHistoryId < ARRAY_COUNT(gMartPurchaseHistory)) { - gMartPurchaseHistory[gMartPurchaseHistoryId].itemId = tItemId; - gMartPurchaseHistory[gMartPurchaseHistoryId].quantity = tItemCount; - gMartPurchaseHistoryId++; + gMartPurchaseHistory[sPurchaseHistoryId].itemId = tItemId; + gMartPurchaseHistory[sPurchaseHistoryId].quantity = tItemCount; + sPurchaseHistoryId++; } }