; NAME: Substract to happening star
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Boolean|DisplayMessage

ADDIU SP SP -80
SW RA 76(SP)
SW S0 72(SP)
SW S1 68(SP)
SW S2 64(SP)

;===============================================================
;Code made by Spongyoshi! Feel free to use for your boards!
;This code takes one from the player's current Happening Spaces count
;If DisplayMessage is True, a message will appear on activation
;Otherwise, the game will do it silently...
;===============================================================

LUI S1 hi(0x800D1134)
ADDIU S1 S1 lo(0x800D1134) ; Loading address of P1's Happening values

JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP

LI A0 0x38
mult V0,A0 ; Multiply it by A0
mflo S0
add S1, S0, S1 ; Add it to P1 address to get the player's address
LBU S2 0(S1)

LI S0 0x01
sub S2, S2, S0 ; Takes 1 from the player Happening Space count
SB S2 0(S1) ; And send it to the address

;===============================================================
; Test: See if the Message is activated
LI S1 DisplayMessage
BNE S1 R0 StartUp ; if yes, show message
NOP
J exit ; If not, exit
NOP
;===============================================================

StartUp:
JAL PlaySound
LI A0 0x143 ;Shinning Star
JAL SleepProcess
ADDIU A0 R0 40 ;Sleep for 40 frames for anticipation

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)
LUI A1 hi(Display_Message)
ADDIU A1 A1 lo(Display_Message)
LI A2 0x0
JAL ShowMessage
LI A3 0x0
JAL CloseMessage
NOP

exit:
LW RA 76(SP)
LW S0 72(SP)
LW S1 68(SP)
SW S2 64(SP)
JR RA
ADDIU SP SP 80

.align 16
Display_Message:
.ascii "Your"
.byte 0x05 ; Green Font
.ascii " Happening Star "
.byte 0x08 ; White Font
.ascii "got lowered by"
.byte 0x03 ; Red Font
.ascii " 1"
.byte 0x08 ; White Font
.byte 0x85 ; Period (.)
.byte 0xFF,0 ; FF=Pause