summaryrefslogtreecommitdiff
path: root/engine/overworld/pokemart.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/overworld/pokemart.asm')
-rwxr-xr-xengine/overworld/pokemart.asm144
1 files changed, 81 insertions, 63 deletions
diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm
index 8325b93f..ae96c4a9 100755
--- a/engine/overworld/pokemart.asm
+++ b/engine/overworld/pokemart.asm
@@ -1,30 +1,34 @@
DisplayPokemartDialogue_: ; 6c20 (1:6c20)
ld a,[wListScrollOffset]
- ld [wd07e],a
- call UpdateSprites ; move sprites
+ ld [wSavedListScrollOffset],a
+ call UpdateSprites
xor a
- ld [wcf0a],a ; flag that is set if something is sold or bought
+ ld [wBoughtOrSoldItemInMart],a
.loop
xor a
ld [wListScrollOffset],a
ld [wCurrentMenuItem],a
ld [wPlayerMonNumber],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld a,BUY_SELL_QUIT_MENU
ld [wTextBoxID],a
- call DisplayTextBoxID ; do buy/sell/quit menu
- ld hl,wd128 ; pointer to this pokemart's inventory
+ call DisplayTextBoxID
+
+; This code is useless. It copies the address of the pokemart's inventory to hl,
+; but the address is never used.
+ ld hl,wItemListPointer
ld a,[hli]
ld l,[hl]
- ld h,a ; hl = address of inventory
- ld a,[wd12e]
- cp a,$02
+ ld h,a
+
+ ld a,[wMenuExitMethod]
+ cp a,CANCELLED_MENU
jp z,.done
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wChosenMenuItem]
and a ; buying?
jp z,.buyMenu
dec a ; selling?
@@ -32,11 +36,14 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
dec a ; quitting?
jp z,.done
.sellMenu
+
+; the same variables are set again below, so this code has no effect
xor a
- ld [wcf93],a
- ld a,$02
- ld [wd11b],a
- callab Func_39bd5
+ ld [wPrintItemPrices],a
+ ld a,INIT_BAG_ITEM_LIST
+ ld [wInitListType],a
+ callab InitList
+
ld a,[wNumBagItems]
and a
jp z,.bagEmpty
@@ -50,19 +57,19 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call DisplayTextBoxID ; draw money text box
ld hl,wNumBagItems
ld a,l
- ld [wList],a
+ ld [wListPointer],a
ld a,h
- ld [wList + 1],a
+ ld [wListPointer + 1],a
xor a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld [wCurrentMenuItem],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
call DisplayListMenuID
jp c,.returnToMainPokemartMenu ; if the player closed the menu
.confirmItemSale ; if the player is trying to sell a specific item
- call IsKeyItem ; check if item is unsellable
- ld a,[wd124]
+ call IsKeyItem
+ ld a,[wIsKeyItem]
and a
jr nz,.unsellableItem
ld a,[wcf91]
@@ -70,30 +77,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
jr c,.unsellableItem
ld a,PRICEDITEMLISTMENU
ld [wListMenuID],a
- ld [$ff8e],a ; halve prices when selling
+ ld [hHalveItemPrices],a ; halve prices when selling
call DisplayChooseQuantityMenu
inc a
jr z,.sellMenuLoop ; if the player closed the choose quantity menu with the B button
ld hl,PokemartTellSellPriceText
- ld bc,$0e01
+ lb bc, 14, 1 ; location that PrintText always prints to, this is useless
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 08, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jr z,.sellMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jr z,.sellMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.sellMenuLoop ; if the player chose No
+ jr z,.sellMenuLoop
+
.sellItem
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag1
inc a
- ld [wcf0a],a
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl,wNumBagItems
@@ -106,39 +117,42 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
.bagEmpty
ld hl,PokemartItemBagEmptyText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
jp .returnToMainPokemartMenu
.buyMenu
- ld a,$01
- ld [wcf93],a
- ld a,$03
- ld [wd11b],a
- callab Func_39bd5
+
+; the same variables are set again below, so this code has no effect
+ ld a,1
+ ld [wPrintItemPrices],a
+ ld a,INIT_OTHER_ITEM_LIST
+ ld [wInitListType],a
+ callab InitList
+
ld hl,PokemartBuyingGreetingText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
.buyMenuLoop
- call LoadScreenTilesFromBuffer1 ; restore saved screen
+ call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
- ld hl,wStringBuffer2 + 11
+ call DisplayTextBoxID
+ ld hl,wItemList
ld a,l
- ld [wList],a
+ ld [wListPointer],a
ld a,h
- ld [wList + 1],a
+ ld [wListPointer + 1],a
xor a
ld [wCurrentMenuItem],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID],a
call DisplayListMenuID
jr c,.returnToMainPokemartMenu ; if the player closed the menu
- ld a,$63
- ld [wcf97],a
+ ld a,99
+ ld [wMaxItemQuantity],a
xor a
- ld [$ff8e],a
+ ld [hHalveItemPrices],a ; don't halve item prices when buying
call DisplayChooseQuantityMenu
inc a
jr z,.buyMenuLoop ; if the player closed the choose quantity menu with the B button
@@ -148,17 +162,21 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call CopyStringToCF4B ; copy name to wcf4b
ld hl,PokemartTellBuyPriceText
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jp z,.buyMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jp z,.buyMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.buyMenuLoop ; if the player chose No
+ jr z,.buyMenuLoop
+
.buyItem
call .isThereEnoughMoney
jr c,.notEnoughMoney
@@ -166,13 +184,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call AddItemToInventory
jr nc,.bagFull
call SubtractAmountPaidFromMoney
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag2
- ld a,$01
- ld [wcf0a],a
+ ld a,1
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag2
- ld a,(SFX_02_5a - SFX_Headers_02) / 3
+ ld a,SFX_PURCHASE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld hl,PokemartBoughtItemText
@@ -182,13 +200,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld hl,PokemartAnythingElseText
call PrintText
jp .loop
.isThereEnoughMoney
ld de,wPlayerMoney
- ld hl,$ff9f ; item price
+ ld hl,hMoney
ld c,3 ; length of money in bytes
jp StringCmp
.notEnoughMoney
@@ -202,10 +220,10 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
.done
ld hl,PokemartThankYouText
call PrintText
- ld a,$01
+ ld a,1
ld [wUpdateSpritesEnabled],a
- call UpdateSprites ; move sprites
- ld a,[wd07e]
+ call UpdateSprites
+ ld a,[wSavedListScrollOffset]
ld [wListScrollOffset],a
ret