; NAME: Prediction of Jeanie
; GAMES: MP3_USA
; EXECUTION: Direct
; PARAM: Space|SpaceDirection

ADDIU SP SP -80
SW RA 76(SP)
SW S1 72(SP) ;holds plant number
SW S2 68(SP) ;used to store various values
SW S3 64(SP) ;holds the RAM address 1 of CW
SW S4 60(SP) ;used for warp & curse values
SW S5 56(SP) ;holds the value of the RAM address 1 of CW
SW S6 52(SP) ;used for the Nipper event
SW S0 48(SP) ;used to store various values

;===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 Sparkles Sound
LI A0 0x11B

JAL SleepProcess ; Sleeps for 40 frames
ADDIU A0 R0 40

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0x3C ; Character image (Jeanie)
LUI A1 hi(Prediction_Start)
ADDIU A1 A1 lo(Prediction_Start)

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

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

JAL PlaySound ; Play Magic Power Sound
LI A0 0x11A

JAL SleepProcess ; Sleeps for 20 frames
ADDIU A0 R0 20
;FIRST WINDOW END===========================================

;SELECTION OF WINDOW===========================================
JAL GetRandomByte ; Random Int at V0
NOP

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

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

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

J LeadingTest
NOP
;END SELECTION OF WINDOW=======================================

;REST OF THE WINDOW===================================================
RestWindow:
SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0x3C ; Character image (Jeanie)
LI A2 0
JAL ShowMessage
LI A3 0

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

JAL SleepProcess ; Sleeps for 15 frames
ADDIU A0 R0 15

J exit
NOP
;REST OF THE WINDOW END===============================================

;CHECKS FOR BONUS STARS===========================================
;HAPPENING STAR
HappeningTest:
JAL GetCurrentPlayerHappeningStarCount
LI S2 0x2;
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 NormalWindow 
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 NormalWindow
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 NormalWindow
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 NormalWindow
NOP

J HappeningWindow
NOP
;COIN STAR
CoinTest:
JAL GetCurrentPlayerCoinStarCount
LUI S2 hi(bank_coin_total)
ADDIU S2 S2 lo(bank_coin_total) ; Loading coins in bank in S2
LHU S2 0(S2)
ADDU S1 S2 V0 ; Add S2 to the value

LUI S2 hi(p1_coin_star)
ADDIU S2 S2 lo(p1_coin_star) ; Loading P1 $STAR
LHU S2 0(S2)

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

LUI S2 hi(p2_coin_star)
ADDIU S2 S2 lo(p2_coin_star) ; Loading P2 $STAR
LHU S2 0(S2)

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

LUI S2 hi(p3_coin_star)
ADDIU S2 S2 lo(p3_coin_star) ; Loading P3 $STAR
LHU S2 0(S2)

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

LUI S2 hi(p4_coin_star)
ADDIU S2 S2 lo(p4_coin_star) ; Loading P4 $STAR
LHU S2 0(S2)

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

J CoinWindow
NOP
;GAME STAR
GameTest:
JAL GetCurrentPlayerMiniGameStarCount
LUI S2 hi(current_turn)
ADDIU S2 S2 lo(current_turn) ; Loading current turn number in S2
LBU S2 0(S2)
ADDU S1 S2 V0 ; Add S2 to the value

LUI S2 hi(p1_minigame_star)
ADDIU S2 S2 lo(p1_minigame_star) ; Loading P1 GSTAR
LHU S2 0(S2)

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

LUI S2 hi(p2_minigame_star)
ADDIU S2 S2 lo(p2_minigame_star) ; Loading P2 GSTAR
LHU S2 0(S2)

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

LUI S2 hi(p3_minigame_star)
ADDIU S2 S2 lo(p3_minigame_star) ; Loading P3 GSTAR
LHU S2 0(S2)

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

LUI S2 hi(p4_minigame_star)
ADDIU S2 S2 lo(p4_minigame_star) ; Loading P4 GSTAR
LHU S2 0(S2)

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

J GameWindow
NOP
;LEADER TEST
LeadingTest:
JAL GetCurrentPlayerStarCount
NOP
MOVE S2 V0 ; S2 = V0
JAL GetFirstPlaceStarCount
NOP
BEQ S2 V0 LeadingRandom ;Does current player have the same number of stars as first place?
NOP
J NormalWindow
NOP
;LEADER RANDOM
LeadingRandom:
JAL GetRandomByte ; Random Int at V0
NOP

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

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

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

J NormalWindow
NOP
;CHECKS FOR BONUS STARS END=======================================

;ALL THE WINDOWS===============================================
HappeningWindow:
LUI A1 hi(Prediction_Happening)
ADDIU A1 A1 lo(Prediction_Happening)
;Implement text of the window
J RestWindow
NOP
GameWindow:
LUI A1 hi(Prediction_Minigame)
ADDIU A1 A1 lo(Prediction_Minigame)
;Implement text of the window
J RestWindow
NOP
CoinWindow:
LUI A1 hi(Prediction_Coin)
ADDIU A1 A1 lo(Prediction_Coin)
;Implement text of the window
J RestWindow
NOP
NormalWindow:
LUI A1 hi(Prediction_Nothing)
ADDIU A1 A1 lo(Prediction_Nothing)
;Implement text of the window
J RestWindow
NOP
;ALL THE WINDOWS END===========================================
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 S3 64(SP)
LW S4 60(SP)
LW S5 56(SP)
LW S6 52(SP)
LW S0 48(SP)
JR RA
ADDIU SP SP 80

.align 16
Prediction_Start:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "FUNGUS"
.byte 0x3D ; - (minus)
.ascii "POCUS"
.byte 0xC2 ; Exclamation Mark (!)
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "My crystal ball is telling me"
.byte 0x85,0x85,0x85 ; Period (...)
.byte 0xFF,0 ; FF=Pause

.align 16
Prediction_Happening:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x05 ; Green Font
.ascii "That YOU have the Happening Star"
.byte 0x85 ; Period (.)
.byte 0x08 ; White Font
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Hmph"
.byte 0x82 ; Comma (,)
.ascii " no skill"
.byte 0x82 ; Comma (,)
.ascii " all luck"
.byte 0x85,0x85,0x85 ; Period (...)
.byte 0xFF,0 ; FF=Pause

.align 16
Prediction_Minigame:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x06 ; Blue font
.ascii "That YOU have the MiniGame Star"
.byte 0x85 ; Period (.)
.byte 0x08 ; White Font
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Just let them win one minigame"
.byte 0x82 ; Comma (,)
.ascii " geez"
.byte 0x85,0x85,0x85 ; Period (...)
.byte 0xFF,0 ; FF=Pause

.align 16
Prediction_Coin:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x07 ; Yellow Font
.ascii "That YOU have the Coin Star"
.byte 0x85 ; Period (.)
.byte 0x08 ; White Font
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Hey"
.byte 0xC2 ; Exclamation Mark (!)
.ascii " Stop hoarding coins already"
.byte 0x85,0x85,0x85 ; Period (...)
.byte 0xFF,0 ; FF=Pause

.align 16
Prediction_Nothing:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x04 ; Purple Font
.ascii "That YOU have NO Bonus Stars"
.byte 0x85,0x85,0x85 ; Period (...)
.byte 0x0A ; Newline
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.byte 0x08 ; White Font
.ascii "Do you think that"
.byte 0x5C ; Apostrophe (')
.ascii "s how you"
.byte 0x5C ; Apostrophe (')
.ascii "re going to win"
.byte 0xC3 ; Question Mark (?)
.byte 0xFF,0 ; FF=Pause

.align 16
GetCurrentPlayerCharacterString:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct ; get player struct at V0
LI A0, -1
LBU T2 0x3(V0) ; load character value into T2 from offset of player struct
LI T0 0x1c00 ; add the needed value
ADDU V0 T2 T0 ; send it to V0
LW RA 36(SP)
JR RA
ADDIU SP SP 40

.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
GetCurrentPlayerCoinStarCount:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct
LI A0, -1
LHU V0, 0x002A (v0) ;load current player coin star count to V0
LW RA 36(SP)
JR RA
ADDIU SP SP 40

.align 16
GetCurrentPlayerMiniGameStarCount:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct
LI A0, -1
LHU V0, 0x0028 (v0) ;load current player minigame 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
GetCurrentPlayerCoinCount:
ADDIU SP SP -40
SW RA 36(SP)
JAL GetPlayerStruct
LI A0, -1
LHU V0, 0x0006 (v0) ;load current player coin 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