; NAME: Give Everyone Coins except the Current Player (Airsola™)
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Number|coinamount

;====================================================================
; IMPORTANT: This code is specifically designed to give every player
;            a fixed amount of coins except for the player who lands
;            or passes through the space.
;====================================================================

ADDIU SP SP -40
SW RA 36(SP)
SW S0 32(SP)



;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(Message)
ADDIU A1 A1 lo(Message) ; This loads "Message" 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
;MESSAGE DISPLAY END-------------------------------------------------

;GIVE COINS START----------------------------------------------------
LI S0 0x0 ; Begin with Player 1

START:
JAL GetCurrentPlayerIndex ; Current Player Index at V0
NOP

LI T0 0x4 ; If all Players have been given coins, stop
BEQ S0 T0 wait
NOP

BEQ V0 S0 nextplayer ; If the current player is S0, skip them
NOP

MOVE A0 S0 ; A0 = S0
ADDIU A1 R0 coinamount
JAL AdjustPlayerCoinsGradual ; Changes player's coin amount
NOP

nextplayer:
ADDIU S0 S0 1 ; Add 1 to S0 to check next player
J START
NOP
;GIVE COINS END------------------------------------------------------

;WAIT START----------------------------------------------------------
wait:
ADDIU A0 R0 30 ; Amount of frames the game waits for coin handouts
JAL SleepProcess
NOP
;WAIT END------------------------------------------------------------



LW S0 32(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
Message:
.ascii "Everyone else got some"
.byte 0x06 ; Blue font
.ascii " coins"
.byte 0x08 ; White Font
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause (THIS ALWAYS GOES AT THE END)

; 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