; NAME: Free Warp Change
; GAMES: MP3_USA
; EXECUTION: Direct

;====================================================================
; Made by Spongyoshi, feel free to use on your own boards!!
; This event will randomly change the warp connections
; It changes to a random one that isn't the current one
;===================================================================

ADDIU SP SP -80
SW RA 76(SP)
SW S4 72(SP) ;holds the player index the majority of the time
SW S1 68(SP) ;holds the address 1 of Chilly Waters
SW S2 64(SP) ;loads character value
SW S0 60(SP) ;used for various values
SW S5 56(SP) ;holds the value of address 1 of Chilly Waters
SW S3 52(SP) ;used for decision and holding the warp course value

LUI S1 hi(0x800CD096)
ADDIU S1 S1 lo(0x800CD096) ; Loading RAM address 1 of Chilly Waters
LBU S5 0(S1)

JAL PlaySound 
LI A0 0x35B ; Baby Bowser Voice Sound Index

;===Set Player Idle Animation===
LI A0 -1 ; Load Current Player Index
LI A1 -1 ; Set player's idle animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop the animation

;BEGIN MESSAGE========================================================
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0x5 ; Character image (Baby Bowser)
LUI A1 hi(Display_Message)
ADDIU A1 A1 lo(Display_Message)
LI A2 0x0
JAL ShowMessage
LI A3 0x0
JAL CloseMessage
NOP
;END MESSAGE==========================================================

;BEGIN TRANSITION=======================================
ADDIU A0 R0 3 ; Assigns Bowser Code fade-out
JAL InitFadeOut
ADDIU A1 R0 15 ; Assigns 15 frames of fade-out

JAL SleepProcess ; Sleeps for 20 frames
ADDIU A0 R0 20

JAL PlaySound 
LI A0 0x20E ; Thunder Sound Index

JAL SleepProcess ; Sleeps for 40 frames
ADDIU A0 R0 40

ADDIU A0 R0 3 ; Assigns Bowser Code fade-in
JAL InitFadeIn
ADDIU A1 R0 15 ; Assigns 15 frames of fade-in

JAL SleepProcess ; Sleeps for 10 frames
ADDIU A0 R0 10
;END TRANSITION=========================================

;SELECT NEW WARP===================================
JAL GetRandomByte ; Random Int at V0
NOP

SLTI S0 V0 11 ; Is the number less than 11?
NOP
BNE S0 R0 WarpCourse1
NOP

SLTI S0 V0 22 ; Is the number less than 22?
NOP
BNE S0 R0 WarpCourse2
NOP

SLTI S0 V0 33 ; Is the number less than 33?
NOP
BNE S0 R0 WarpCourse3
NOP

SLTI S0 V0 44 ; Is the number less than 44?
NOP
BNE S0 R0 WarpCourse4
NOP

SLTI S0 V0 55 ; Is the number less than 55?
NOP
BNE S0 R0 WarpCourse5
NOP

SLTI S0 V0 66 ; Is the number less than 66?
NOP
BNE S0 R0 WarpCourse6
NOP

SLTI S0 V0 77 ; Is the number less than 77?
NOP
BNE S0 R0 WarpCourse7
NOP

SLTI S0 V0 88 ; Is the number less than 88?
NOP
BNE S0 R0 WarpCourse8
NOP

SLTI S0 V0 99 ; Is the number less than 99?
NOP
BNE S0 R0 WarpCourse9
NOP

SLTI S0 V0 111 ; Is the number less than 111?
NOP
BNE S0 R0 WarpCourse10
NOP

SLTI S0 V0 122 ; Is the number less than 122?
NOP
BNE S0 R0 WarpCourse11
NOP

SLTI S0 V0 133 ; Is the number less than 133?
NOP
BNE S0 R0 WarpCourse12
NOP

SLTI S0 V0 144 ; Is the number less than 144?
NOP
BNE S0 R0 WarpCourse13
NOP

SLTI S0 V0 155 ; Is the number less than 155?
NOP
BNE S0 R0 WarpCourse14
NOP

SLTI S0 V0 166 ; Is the number less than 166?
NOP
BNE S0 R0 WarpCourse15
NOP

SLTI S0 V0 177 ; Is the number less than 177?
NOP
BNE S0 R0 WarpCourse16
NOP

SLTI S0 V0 188 ; Is the number less than 188?
NOP
BNE S0 R0 WarpCourse17
NOP

SLTI S0 V0 199 ; Is the number less than 199?
NOP
BNE S0 R0 WarpCourse18
NOP

SLTI S0 V0 211 ; Is the number less than 211?
NOP
BNE S0 R0 WarpCourse19
NOP

SLTI S0 V0 222 ; Is the number less than 222?
NOP
BNE S0 R0 WarpCourse20
NOP

SLTI S0 V0 233 ; Is the number less than 233?
NOP
BNE S0 R0 WarpCourse21
NOP

SLTI S0 V0 244 ; Is the number less than 244?
NOP
BNE S0 R0 WarpCourse22
NOP

; Else
LI S3 23 ;Give to S3 the Course ID of 23
J WarpTesting
NOP
;END SELECT NEW WARP===================================

;ALL THE WARPS==========================
WarpCourse1:
J WarpTesting
LI S3 1 ;Give to S3 the Course ID of 1

WarpCourse2:
J WarpTesting
LI S3 2 ;Give to S3 the Course ID of 2

WarpCourse3:
J WarpTesting
LI S3 3 ;Give to S3 the Course ID of 3

WarpCourse4:
J WarpTesting
LI S3 4 ;Give to S3 the Course ID of 4

WarpCourse5:
J WarpTesting
LI S3 5 ;Give to S3 the Course ID of 5

WarpCourse6:
J WarpTesting
LI S3 6 ;Give to S3 the Course ID of 6

WarpCourse7:
J WarpTesting
LI S3 7 ;Give to S3 the Course ID of 7

WarpCourse8:
J WarpTesting
LI S3 8 ;Give to S3 the Course ID of 8

WarpCourse9:
J WarpTesting
LI S3 9 ;Give to S3 the Course ID of 9

WarpCourse10:
J WarpTesting
LI S3 10 ;Give to S3 the Course ID of 10

WarpCourse11:
J WarpTesting
LI S3 11 ;Give to S3 the Course ID of 11

WarpCourse12:
J WarpTesting
LI S3 12 ;Give to S3 the Course ID of 12

WarpCourse13:
J WarpTesting
LI S3 13 ;Give to S3 the Course ID of 13

WarpCourse14:
J WarpTesting
LI S3 14 ;Give to S3 the Course ID of 14

WarpCourse15:
J WarpTesting
LI S3 15 ;Give to S3 the Course ID of 15

WarpCourse16:
J WarpTesting
LI S3 16 ;Give to S3 the Course ID of 16

WarpCourse17:
J WarpTesting
LI S3 17 ;Give to S3 the Course ID of 17

WarpCourse18:
J WarpTesting
LI S3 18 ;Give to S3 the Course ID of 18

WarpCourse19:
J WarpTesting
LI S3 19 ;Give to S3 the Course ID of 19

WarpCourse20:
J WarpTesting
LI S3 20 ;Give to S3 the Course ID of 20

WarpCourse21:
J WarpTesting
LI S3 21 ;Give to S3 the Course ID of 21

WarpCourse22:
J WarpTesting
LI S3 22 ;Give to S3 the Course ID of 22

WarpCourse24:
J Accepted
LI S3 24 ;Give to S3 the Course ID of 24
;END ALL THE WARPS==========================

;WARP TEST==============================
WarpTesting:
BEQ S5, S3, WarpCourse24
NOP

J Accepted
NOP
;END WARP TEST==============================

;BEGIN ACCEPTED MESSAGE========================================
Accepted:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0x5 ; Character image (Baby Bowser)
LUI A1 hi(End_Message)
ADDIU A1 A1 lo(End_Message)
LI A2 0x0
JAL ShowMessage
LI A3 0x0
JAL CloseMessage
NOP
;END ACCEPTED MESSAGE==========================================

LW RA 76(SP)
LW S4 72(SP)
LW S1 68(SP)
LW S2 64(SP)
LW S0 60(SP)
LW S5 56(SP)
LW S3 52(SP)
JR RA
ADDIU SP SP 80
 
 percent_d:
.asciiz "%d" ; 0x25640000

coin_string_loc:
.fill 8
 
 D_8011D308:
.word 0x00000000

.align 16
Display_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Bowser told me those Warp Machines"
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture
.ascii "needed fresh new connections"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture
.ascii "No need to thank me"
.byte 0x85 ; Period (.)
.ascii " Wah"
.byte 0x82 ; Comma (,)
.ascii " hah"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
End_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Another job well done"
.byte 0x85 ; Period (.)
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture
.ascii "Bowser will be pleased"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause