; NAME: Red Space Ruleset
; GAMES: MP3_USA
; EXECUTION: Direct

ADDIU SP SP -80
SW RA 76(SP)
SW S1 72(SP) ;holds addresses
SW S2 68(SP) ;holds test values
SW S0 64(SP) ;holds test values
SW S3 60(SP) ;holds addresses values

;====================================================================
; Made by Spongyoshi, feel free to use for your own boards!!
; Part of the last five turns custom event, put it on every red space
; Will trigger either battle, bowser, game guy, chance time or red
; Thanks to Rain and the Mario Party Legacy Discord as always!!
;===================================================================
;TESTING BEGIN;
LUI S3 hi(0x800CD0A1)
ADDIU S3 S3 lo(0x800CD0A1) ; Loading ram address
LBU S3 0(S3)
LI S2 2
BEQ S3 S2 Start ; If rule 2 is active then begin
NOP
J exit ;else, exit
NOP
;TESTING END;
;SOUNDEFFECT BEGIN;
Start:
JAL PlaySound
LI A0 0x143 ;Shinning Star
JAL SleepProcess
ADDIU A0 R0 60 ;Sleep for 60 frames for anticipation
;SOUNDEFFECT END;
;RANDOM BEGIN;
JAL GetRandomByte ; Random Int at V0
NOP
SLTI S0 V0 64 ; Is the number less than 64?
BNE S0 R0 DetermineIfBowser
NOP
SLTI S0 V0 128 ; Is the number less than 128?
BNE S0 R0 DetermineIfBattle
NOP
SLTI S0 V0 192 ; Is the number less than 192?
BNE S0 R0 DetermineIfGameGuy
NOP
J DetermineIfChanceTime
NOP
;RANDOM END;
;CONDITION BEGIN;
DetermineIfBowser:
JAL GetRandomByte ; Random Int at V0
NOP
SLTI S0 V0 200 ; Is the number less than 200?
BNE S0 R0 BowserTransformation
NOP
J RedSpaceTransformation
NOP
DetermineIfBattle:
JAL GetRandomByte ; Random Int at V0
NOP
SLTI S0 V0 200 ; Is the number less than 200?
BNE S0 R0 BattleTransformation
NOP
J RedSpaceTransformation
NOP
DetermineIfGameGuy:
JAL GetRandomByte ; Random Int at V0
NOP
SLTI S0 V0 200 ; Is the number less than 200?
BNE S0 R0 GameGuyTransformation
NOP
J RedSpaceTransformation
NOP
DetermineIfChanceTime:
JAL GetRandomByte ; Random Int at V0
NOP
SLTI S0 V0 200 ; Is the number less than 200?
BNE S0 R0 ChanceTimeTransformation
NOP
J RedSpaceTransformation
NOP
;CONDITION END;
;SPACE CHANGE BEGIN;
BowserTransformation:
JAL GetCurrentSpaceIndex
NOP
MOVE A0 V0 
JAL SetSpaceType 
LI A1 0x0C
J exit
NOP
BattleTransformation:
JAL GetCurrentSpaceIndex
NOP
MOVE A0 V0 
JAL SetSpaceType 
LI A1 0x09
J exit
NOP
GameGuyTransformation:
JAL GetCurrentSpaceIndex
NOP
MOVE A0 V0 
JAL SetSpaceType 
LI A1 0x0F
J exit
NOP
ChanceTimeTransformation:
JAL GetCurrentSpaceIndex
NOP
MOVE A0 V0 
JAL SetSpaceType 
LI A1 0x05
J exit
NOP
RedSpaceTransformation:
JAL GetCurrentSpaceIndex
NOP
MOVE A0 V0 
JAL SetSpaceType 
LI A1 0x02
;SPACE CHANGE END;
exit:
LW RA 76(SP)
LW S1 72(SP)
LW S2 68(SP)
LW S0 64(SP)
LW S3 60(SP)
JR RA
ADDIU SP SP 80