; NAME: Give Current Player Specific Item [NoItemIfFull] (Airsola™)
; GAMES: MP3_USA
; EXECUTION: Direct

;====================================================================
; IMPORTANT: This code is specifically designed to give the landing
;            or passing player an item of your choice. If they have
;            no space to carry the item, they will receive nothing.
;===================================================================

ADDIU SP SP -40
SW RA 36(SP)
SW S1 32(SP)
SW S2 28(SP)
SW S0 24(SP)



;FIND CURRENT PLAYER START-------------------------------------------
JAL GetCurrentPlayerIndex ; Current Player Index at V0
NOP

LI S0 0x0 ; Start with Player 1 
LUI S1 hi(p1_item1)
ADDIU S1 S1 lo(p1_item1) ; S1 is the address of Player 1's First Item

START:
BEQ S0 V0 checkslots
NOP

ADDIU S0 S0 1 ; Add 1 to check the next Player
ADDIU S1 S1 0x38 ; This makes it load the next Player's First Item
J START
NOP
;FIND CURRENT PLAYER END---------------------------------------------

;CHECK ITEM SLOTS START----------------------------------------------
checkslots:
ADDIU S0 R0 0xFF ; 0xFF = No Item Value
LBU S2 0(S1) ; S2 is the value of the item in the first slot
BEQ S0 S2 itemmessage ; Go to itemmessage if the first slot is empty
NOP
ADDIU S1 S1 1 ; Add 1 to check Slot #2
LBU S2 0(S1) ; S2 is the value of the item in the second slot
BEQ S0 S2 itemmessage ; Go to itemmessage if the second slot is empty
NOP
ADDIU S1 S1 1 ; Add 1 to check Slot #3
LBU S2 0(S1) ; S2 is the value of the item in the third slot
BEQ S0 S2 itemmessage ; Go to itemmessage if the third slot is empty
NOP
; If the Player has 3 Items, they'll get the "No Item" message
;CHECK ITEM SLOTS END------------------------------------------------

;NO ITEM MESSAGE DISPLAY START---------------------------------------
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
ADDI A0 R0 -1 ; Character image (-1 for none)
; Visit the following link to get the full list of Character Images
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(noitem)
ADDIU A1 A1 lo(noitem) ; This loads "noitem" into the Textbox
LI A2 0x0
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

J exit ; Player got no item, exit
NOP
;NO ITEM MESSAGE DISPLAY END-----------------------------------------

;GOT ITEM MESSAGE DISPLAY START--------------------------------------
itemmessage:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
ADDI A0 R0 -1 ; Character image (-1 for none)
; Visit the following link to get the full list of Character Images
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(gotitem)
ADDIU A1 A1 lo(gotitem) ; This loads "gotitem" into the Textbox
LI A2 0x0
JAL 0x800EC8EC ; ShowMessage
LI A3 0x0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;GOT ITEM MESSAGE DISPLAY END----------------------------------------

;GIVE ITEM START-----------------------------------------------------
LI S0 0x00 ; S0 contains Mushroom Value
SB S0 0(S1) ; Place Mushroom on empty Item slot

; 0x00 = Mushroom
; 0x01 = Skeleton Key
; 0x02 = Poison Mushroom
; 0x03 = Reverse Mushroom
; 0x04 = Cellular Shopper
; 0x05 = Warp Block
; 0x06 = Plunder Chest
; 0x07 = Bowser Phone
; 0x08 = Dueling Glove
; 0x09 = Lucky Lamp
; 0x0A = Golden Mushroom
; 0x0B = Boo Bell
; 0x0C = Boo Repellant
; 0x0D = Bowser Suit
; 0x0E = Magic Lamp
; 0x0F = Koopa Card
; 0x10 = Barter Box
; 0x11 = Lucky Coin
; 0x12 = Wacky Watch
;GIVE ITEM END-------------------------------------------------------

;SOUND START---------------------------------------------------------
LI A0 0x10C ; Turn Start Sound Index
; Use the Audio Player on PP64 to find other sound indexes to use
; Then use the following link to know what Sound Index you need
; https://pastebin.com/H1jxNFqr
JAL PlaySound 
NOP

ADDIU A0 R0 0 ; Number of frames the game waits for sound to finish
JAL SleepProcess 
NOP
;SOUND END-----------------------------------------------------------



exit:
LW S1 32(SP)
LW S2 28(SP)
LW S0 24(SP)
LW RA 36(SP)
JR RA
ADDIU SP SP 40

; .ascii is used to output Text. Anything surrounded by " will be 
; displayed in the message (Special characters are not included).
; For those, you must use .byte and the respective byte value.
; Bytes that change text color will change the color of everything
; that is written after it, until another color is used.

.align 16
gotitem:
.ascii "You got a"
.byte 0x07 ; Yellow Font
.ascii " Mushroom"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
noitem:
.ascii "You have too many"
.byte 0x07 ; Yellow Font
.ascii " items"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

; Here's a list of the most common bytes you'll need
; .byte 0x01 ; Black Font
; .byte 0x03 ; Red Font
; .byte 0x04 ; Purple Font
; .byte 0x05 ; Green Font
; .byte 0x06 ; Blue font
; .byte 0x07 ; Yellow Font
; .byte 0x08 ; White Font
; .byte 0x85 ; Period (.)
; .byte 0xC2 ; Exclamation Mark (!)
; .byte 0xC3 ; Question Mark (?)
; .byte 0x82 ; Comma (,)
; .byte 0x0A ; New Line (Writes Below)
; .byte 0x5C ; Apostrophe (')
; .byte 0x29 ; Coin icon
; .byte 0x3D ; - (minus)
; .byte 0x3E ; x (multiply)
; .byte 0xFF,0 ; FF=Pause

; If your message has an image, use this at the start of each line
; .byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture