; NAME: Blowing Angler Fish
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Space|SpaceDirection
; PARAM: Space|Destination1
; PARAM: Space|PreviousSpace1
; PARAM: Space|NextSpace1
; PARAM: Space|Destination2
; PARAM: Space|PreviousSpace2
; PARAM: Space|NextSpace2
; PARAM: Space|Destination3
; PARAM: Space|PreviousSpace3
; PARAM: Space|NextSpace3
; PARAM: Space|Destination4
; PARAM: Space|PreviousSpace4
; PARAM: Space|NextSpace4
; PARAM: Space|Destination5
; PARAM: Space|PreviousSpace5
; PARAM: Space|NextSpace5
; PARAM: Space|Destination6
; PARAM: Space|PreviousSpace6
; PARAM: Space|NextSpace6
; PARAM: Boolean|Rubberbanding
; PARAM: Boolean|EverdriveCompatibility

ADDIU SP SP -80
SW RA 76(SP)
SW S1 72(SP) ;holds rubberbanding variable
SW S2 68(SP) ;used to store various values
SW S4 64(SP) ;used for the warp values
SW S0 60(SP) ;used to store various values

;===============================================================
;Code by Spongyoshi, feel free to use on your own boards!
;Angler Fish will blow you unto one of the 6 spaces at random
;Destination1 to 6 should be one of the possible destinations
;Destination should be the same type as the current space
;PreviousSpace1 to 6 should be the space before said destination
;NextSpace1 to 6 should be the space after said destination
;SpaceDirection should be where the player looks at during the event
;If Rubberbanding is True, Destination 6's likelyhood will be modified
;It will be more likely for frontrunners to land on it
;If Rubberbanding is False, All Destinations get similar odds
;Thanks to Airsola and the Mario Party Legacy Discord for their help!
;===============================================================

;===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

;===Rotate Player Model Towards Space===
LI A0 -1 ; Load Current Player Index
LI A1 10 ; Frames it takes to turn
JAL 0x800ED20C ; RotatePlayerModel function
LI A2 SpaceDirection ; Space Index to face towards

;FIRST WINDOW=====================================================
JAL PlaySound ; Play Weird Voice Sound
LI A0 0x146

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0x39 ; Character image (Angler Fish)
LUI A1 hi(Message_Start)
ADDIU A1 A1 lo(Message_Start)

ADDU A2 R0 R0
JAL 0x800EC8EC ; ShowMessage
ADDU A3 R0 R0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP
;FIRST WINDOW END=====================================================

;CHECK FOR RUBBERBAND=================================================
LI S1 Rubberbanding
BNE S1 R0 FishTest ; if yes, do the checks
NOP ; If not, randomly pick
;CHECK FOR RUBBERBAND END=============================================

;COMPLETLY RANDOM PICK===============================================
FishRandom:
JAL GetRandomByte ; Random Int at V0
NOP

SLTI S0 V0 200 ; Is the number less than 200?
BNE S0 R0 Good_Blow
NOP

J Bad_Blow
NOP
;COMPLETLY RANDOM PICK END===========================================

;CHECKS FOR MISSFIRE1===========================================
FishTest:
JAL SleepProcess ; Sleeps for 5 frames
ADDIU A0 R0 5

JAL GetRandomByte ; Random Int at V0
NOP

SLTI S0 V0 80 ; Is the number less than 80?
BNE S0 R0 LeadingTest
NOP

SLTI S0 V0 160 ; Is the number less than 160?
BNE S0 R0 CoinsTest
NOP

SLTI S0 V0 240 ; Is the number less than 240?
BNE S0 R0 HappeningTest
NOP

J LoserTest
NOP
;CHECKS FOR MISSFIRE1 END=======================================

;CHECKS FOR MISSFIRE2===========================================
;Check if player has same number of stars as first place
LeadingTest:
JAL GetCurrentPlayerStarCount
NOP
MOVE S2 V0 ; S2 = V0
JAL GetFirstPlaceStarCount 
NOP
BEQ S2 V0 Bad_Blow
NOP
J Good_Blow
NOP
;Check if player has 20 coins or more
CoinsTest:
LI A1 20 ; A1 = The ammount of Coins to check for
JAL PlayerHasCoins ; Checks if Player has that ammount of Coins
LI A0 -1 ;current_player_index
BNE V0 R0 Bad_Blow
NOP
J Good_Blow
NOP
;Check if player has happening star
HappeningTest:
JAL GetCurrentPlayerHappeningStarCount
LI S2 0x1;
ADDU S1 S2 V0 ; Add S2 to the value

LUI S2 hi(p1_happening_space_count)
ADDIU S2 S2 lo(p1_happening_space_count) ; Loading P1 ?STAR
LBU S2 0(S2)

SLT S0 S1 S2 ; Is P1 Happening Star higher than current player?
NOP
BNE S0 R0 Good_Blow
NOP

LUI S2 hi(p2_happening_space_count)
ADDIU S2 S2 lo(p2_happening_space_count) ; Loading P2 ?STAR
LBU S2 0(S2)

SLT S0 S1 S2 ; Is P2 Happening Star higher than current player?
NOP
BNE S0 R0 Good_Blow
NOP

LUI S2 hi(p3_happening_space_count)
ADDIU S2 S2 lo(p3_happening_space_count) ; Loading P3 ?STAR
LBU S2 0(S2)

SLT S0 S1 S2 ; Is P3 Happening Star higher than current player?
NOP
BNE S0 R0 Good_Blow
NOP

LUI S2 hi(p4_happening_space_count)
ADDIU S2 S2 lo(p4_happening_space_count) ; Loading P4 ?STAR
LBU S2 0(S2)

SLT S0 S1 S2 ; Is P4 Happening Star higher than current player?
NOP
BNE S0 R0 Good_Blow
NOP

J Bad_Blow
NOP
;Check if Last Place or First Place
LoserTest:
JAL GetCurrentPlayerIndex
NOP
JAL GetPlayerPlacement
MOVE A0 V0
LI S2 0
BEQ V0 S2 Bad_Blow ;Does current player have a rank of 0? (first)
NOP
JAL GetCurrentPlayerIndex
NOP
JAL GetPlayerPlacement
MOVE A0 V0
LI S2 3
BEQ V0 S2 Bad_Blow ;Does current player have a rank of 3? (last)
NOP
J Good_Blow
NOP
;CHECKS FOR MISSFIRE2 END=======================================

;SPACE PICKER---------------------------------------------------------
Good_Blow:
JAL PlaySound ; Play Blowing Away Sound
LI A0 0x190

LI S1 EverdriveCompatibility
BEQ S1 R0 EmulatorSkip ; if no, skip
NOP ; If yes, continue

LI A0 -1 ; Load Current Player Index
LI A1 04 ; Set player's dizzy animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop the animation

;!!!LONG ANIMATION, MIGHT NEED TO OPTIMIZE THIS!!!
JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x41F00000 ;value 30 as float
SW t0, 0x0010 (v0) ;store 30 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42700000 ;value 60 as float
SW t0, 0x0010 (v0) ;store 60 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42B40000 ;value 90 as float
SW t0, 0x0010 (v0) ;store 90 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42F00000 ;value 120 as float
SW t0, 0x0010 (v0) ;store 120 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43160000 ;value 150 as float
SW t0, 0x0010 (v0) ;store 150 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43340000 ;value 180 as float
SW t0, 0x0010 (v0) ;store 180 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43520000 ;value 210 as float
SW t0, 0x0010 (v0) ;store 210 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43700000 ;value 240 as float
SW t0, 0x0010 (v0) ;store 240 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43870000 ;value 270 as float
SW t0, 0x0010 (v0) ;store 270 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43960000 ;value 300 as float
SW t0, 0x0010 (v0) ;store 300 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43AF0000;value 350 as float
SW t0, 0x0010 (v0) ;store 350 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43C80000 ;value 400 as float
SW t0, 0x0010 (v0) ;store 400 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43E10000 ;value 450 as float
SW t0, 0x0010 (v0) ;store 450 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43fA0000 ;value 500 as float
SW t0, 0x0010 (v0) ;store 500 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44098000 ;value 550 as float
SW t0, 0x0010 (v0) ;store 550 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44160000 ;value 600 as float
SW t0, 0x0010 (v0) ;store 600 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44228000 ;value 650 as float
SW t0, 0x0010 (v0) ;store 650 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP
EmulatorSkip:
;Actual Warp Picker
JAL GetRandomByte ; Random Int at V0
NOP

SLTI S0 V0 51 ; Is the number less than 51?
BNE S0 R0 First_Blow
NOP

SLTI S0 V0 102 ; Is the number less than 102?
BNE S0 R0 Second_Blow
NOP

SLTI S0 V0 153 ; Is the number less than 153?
BNE S0 R0 Third_Blow
NOP

SLTI S0 V0 204 ; Is the number less than 204?
BNE S0 R0 Fourth_Blow
NOP

J Fifth_Blow
NOP
;SPACE PICKER END-----------------------------------------------------

;WARP 1 START----------------------------------------------------------
First_Blow:
JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination1_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination1_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace1_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace1_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace1_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace1_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination1_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination1_chain_space_index

J Continue_Warp
NOP
;WARP 1 END------------------------------------------------------------

;WARP 2 START----------------------------------------------------------
Second_Blow:
JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination2_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination2_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace2_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace2_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace2_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace2_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination2_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination2_chain_space_index

J Continue_Warp
NOP
;WARP 2 END------------------------------------------------------------

;WARP 3 START----------------------------------------------------------
Third_Blow:
JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination3_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination3_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace3_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace3_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace3_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace3_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination3_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination3_chain_space_index

J Continue_Warp
NOP
;WARP 3 END------------------------------------------------------------

;WARP 4 START----------------------------------------------------------
Fourth_Blow:
JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination4_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination4_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace4_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace4_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace4_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace4_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination4_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination4_chain_space_index

J Continue_Warp
NOP
;WARP 4 END------------------------------------------------------------

;WARP 5 START----------------------------------------------------------
Fifth_Blow:
JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination5_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination5_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace5_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace5_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace5_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace5_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination5_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination5_chain_space_index

J Continue_Warp
NOP
;WARP 5 END------------------------------------------------------------

;WARP 6 START----------------------------------------------------------
Bad_Blow:
JAL PlaySound ; Play Blowing Away Sound
LI A0 0x190

LI S1 EverdriveCompatibility
BEQ S1 R0 EmulatorSkip2 ; if no, skip
NOP ; If yes, continue

LI A0 -1 ; Load Current Player Index
LI A1 04 ; Set player's dizzy animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop the animation

;!!!LONG ANIMATION, MIGHT NEED TO OPTIMIZE THIS!!!
JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x41F00000 ;value 30 as float
SW t0, 0x0010 (v0) ;store 30 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42700000 ;value 60 as float
SW t0, 0x0010 (v0) ;store 60 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42B40000 ;value 90 as float
SW t0, 0x0010 (v0) ;store 90 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42F00000 ;value 120 as float
SW t0, 0x0010 (v0) ;store 120 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43160000 ;value 150 as float
SW t0, 0x0010 (v0) ;store 150 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43340000 ;value 180 as float
SW t0, 0x0010 (v0) ;store 180 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43520000 ;value 210 as float
SW t0, 0x0010 (v0) ;store 210 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43700000 ;value 240 as float
SW t0, 0x0010 (v0) ;store 240 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43870000 ;value 270 as float
SW t0, 0x0010 (v0) ;store 270 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43960000 ;value 300 as float
SW t0, 0x0010 (v0) ;store 300 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43AF0000;value 350 as float
SW t0, 0x0010 (v0) ;store 350 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43C80000 ;value 400 as float
SW t0, 0x0010 (v0) ;store 400 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43E10000 ;value 450 as float
SW t0, 0x0010 (v0) ;store 450 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43fA0000 ;value 500 as float
SW t0, 0x0010 (v0) ;store 500 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44098000 ;value 550 as float
SW t0, 0x0010 (v0) ;store 550 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44160000 ;value 600 as float
SW t0, 0x0010 (v0) ;store 600 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x44228000 ;value 650 as float
SW t0, 0x0010 (v0) ;store 650 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetCurrentPlayerIndex ; Player Index located at V0
NOP
MOVE S4 V0 ; Copy Current Player's Index to S4
EmulatorSkip2:
MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 Destination6_chain_index ; Assigns Chain Index to A1
JAL SetPlayerOntoChain
LI A2 Destination6_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 PreviousSpace6_chain_index ; Assigns Chain Index to A1
JAL SetPrevChainAndSpace
LI A2 PreviousSpace6_chain_space_index ; Assigns Space Index to A2

MOVE A0 S4 ; Assigns Current Player Index to A0
LI A1 NextSpace6_chain_index ; Assigns Chain Index to A1
JAL SetNextChainAndSpace
LI A2 NextSpace6_chain_space_index ; Assigns Space Index to A2

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S0 V0

LI A0 Destination6_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination6_chain_space_index

J Continue_Warp
NOP
;WARP 6 END------------------------------------------------------------

;FINALISE WARP-------------------------------------------------------
Continue_Warp:
LI S1 EverdriveCompatibility
BNE S1 R0 EverdriveSkip ; if yes, skip
NOP ; If not, keep going

LI A0 4 ; Happening Space Fade-out 
JAL InitFadeOut
LI A1 5 ; Fade Out for 5 Frames

JAL SleepProcess ; Sleeps for 5 frames
ADDIU A0 R0 5

JAL GetPlayerStruct ; Player Struct at V0
LI A0 -1 ; Current Player
MOVE S1 V0

LI A0 Destination6_chain_index
JAL GetAbsSpaceIndexFromChainSpaceIndex ; Gets True Space Index at V0
LI A1 Destination6_chain_space_index

JAL GetSpaceData ; Pointer to Space Data at V0
MOVE A0 V0 ; True Space Index

ADDIU V0 V0 8 ; This gets the X pos of the space
LW V1 0(V0) 
MOVE T0 V1 ; Copy to T0

ADDIU V0 V0 8 ; This gets the Y pos of the space
LW V1 0(V0)
MOVE T1 V1 ; Copy to T1

LI T2 0x41200000 ; Float value for 10?
MTC1 T2 F0 ; Move Float to F1?
MTC1 T1 F1 ; Move Space Y Pos float to F1?
ADD.S F0 F0 F1 ; Add the floats for maximum floatiness
MFC1 T1 F0 ; Move total to T1?

LW V1 0x24(S1) ; Load Offset 24 into V1
ADDIU V1 V1 0xC ; Add 0xC to get current player's X Coords
SW T0 0(V1) 

ADDIU V1 V1 8 ; This should load current player's Y Coords
SW T1 0(V1)

JAL SleepProcess ; Sleeps for 50 frames
ADDIU A0 R0 50

LI A0 -1 ; Load Current Player Index
LI A1 04 ; Set player's dizzy animation
JAL SetBoardPlayerAnimation
LI A2 2 ; Loop the animation

LI A0 4 ; Happening Space Fade-out 
JAL InitFadeIn
LI A1 10 ; Fade Out for 10 Frames

;!!!LONG ANIMATION, MIGHT NEED TO OPTIMIZE THIS!!!
JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43960000 ;value 300 as float
SW t0, 0x0010 (v0) ;store 300 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43870000 ;value 270 as float
SW t0, 0x0010 (v0) ;store 270 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43700000 ;value 240 as float
SW t0, 0x0010 (v0) ;store 240 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43520000 ;value 210 as float
SW t0, 0x0010 (v0) ;store 210 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43340000 ;value 180 as float
SW t0, 0x0010 (v0) ;store 180 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x43160000 ;value 150 as float
SW t0, 0x0010 (v0) ;store 150 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42F00000 ;value 120 as float
SW t0, 0x0010 (v0) ;store 120 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42B40000 ;value 90 as float
SW t0, 0x0010 (v0) ;store 90 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x42700000 ;value 60 as float
SW t0, 0x0010 (v0) ;store 60 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x41f00000 ;value 30 as float
SW t0, 0x0010 (v0) ;store 30 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x00000000 ;value 0 as float
SW t0, 0x0010 (v0) ;store 0 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

LI A0 0x179 ; Land Effect Sound
JAL PlaySound ; Play the Land Effect Sound
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40000000 ;value 2 as float
SW t0, 0x0010 (v0) ;store 2 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40800000 ;value 4 as float
SW t0, 0x0010 (v0) ;store 4 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40A00000 ;value 5 as float
SW t0, 0x0010 (v0) ;store 5 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40800000 ;value 4 as float
SW t0, 0x0010 (v0) ;store 4 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40400000 ;value 3 as float
SW t0, 0x0010 (v0) ;store 3 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x40000000 ;value 2 as float
SW t0, 0x0010 (v0) ;store 2 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP

JAL GetPlayerStruct
LI a0, -1
LW v0, 0x0024 (v0)
LI t0, 0x00000000 ;value 0 as float
SW t0, 0x0010 (v0) ;store 0 to player y pos

JAL SleepVProcess ;Sleep for one frame
NOP
EverdriveSkip:
JAL SleepProcess ; Sleeps for 20 frames
ADDIU A0 R0 20

LUI A1 hi(Message_End)
ADDIU A1 A1 lo(Message_End)

J Window_Exit
NOP
;FINALISE WARP END---------------------------------------------------
Window_Exit:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 -1 ; Character image (-1 for none)

ADDU A2 R0 R0
JAL ShowMessage
ADDU A3 R0 R0

JAL 0x800EC9DC
NOP
JAL 0x800EC6C8
NOP
JAL 0x800EC6EC
NOP

exit:

;===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

LW RA 76(SP)
LW S1 72(SP)
LW S2 68(SP)
LW S4 64(SP)
LW S0 60(SP)
JR RA
ADDIU SP SP 80

.align 16
Message_Start:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x85,0x85,0x85 ; Period (...)
.ascii "Oh"
.byte 0x82 ; Comma (,)
.ascii " pardon me"
.byte 0x82 ; Comma (,)
.ascii " but I think I"
.byte 0x5C ; Apostrophe (')
.ascii "m going"
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "to blow you away"
.byte 0x85 ; Period (.)
.ascii " Hmm"
.byte 0x82 ; Comma (,)
.ascii " now where"
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "should I send you"
.byte 0xC3 ; Question Mark (?)
.ascii " Ha"
.byte 0x3D ; - (minus)
.ascii "ha"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0xFF,0 ; FF=Pause

.align 16
Message_End:
.ascii "You"
.byte 0x5C ; Apostrophe (')
.ascii "ve landed"
.byte 0x05 ; Green Font
.ascii " somewhere else"
.byte 0x08 ; White Font
.byte 0x85 ; Period (.)
.byte 0xFF,0 ; FF=Pause

.align 16
GetCurrentPlayerHappeningStarCount:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct
LI A0, -1
LBU V0, 0x002C (v0) ;load current player happening star count to V0
LW RA 36(SP)
JR RA
ADDIU SP SP 40

.align 16
GetCurrentPlayerStarCount:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct
LI A0, -1
LBU V0, 0x000A (v0) ;load current player star count to V0
LW RA 36(SP)
JR RA
ADDIU SP SP 40

.align 16
GetFirstPlaceStarCount:
ADDIU SP SP -40
SW RA 36(SP)
LI T0 0x0
;Test if player one is in first place
JAL GetPlayerPlacement
LI A0 0x0
BEQ T0 V0 GetPlayerOneStarCount
NOP
;Test if player two is in first place
JAL GetPlayerPlacement
LI A0 0x1
BEQ T0 V0 GetPlayerTwoStarCount
NOP
;Test if player three is in first place
JAL GetPlayerPlacement
LI A0 0x2
BEQ T0 V0 GetPlayerThreeStarCount
NOP
;Test if player four is in first place
JAL GetPlayerPlacement
LI A0 0x3
BEQ T0 V0 GetPlayerFourStarCount
NOP
;Get player one star count into V0
GetPlayerOneStarCount:
LUI V0 hi(p1_stars)
ADDIU V0 V0 lo(p1_stars)
LBU V0 0(V0)
J starcountend
NOP
;Get player two star count into V0
GetPlayerTwoStarCount:
LUI V0 hi(p2_stars)
ADDIU V0 V0 lo(p2_stars)
LBU V0 0(V0)
J starcountend
NOP
;Get player three star count into V0
GetPlayerThreeStarCount:
LUI V0 hi(p3_stars)
ADDIU V0 V0 lo(p3_stars)
LBU V0 0(V0)
J starcountend
NOP
;Get player four star count into V0
GetPlayerFourStarCount:
LUI V0 hi(p4_stars)
ADDIU V0 V0 lo(p4_stars)
LBU V0 0(V0)
starcountend:
LW RA 36(SP)
JR RA
ADDIU SP SP 40