; Common state overrides

;---------------------------------------------------------------------------
; Walk
[Statedef 20]
type    = S
physics = S
sprpriority = 0

[State 20, Stone]
type = VelSet
triggerall = PalNo = 9
trigger1 = command = "holdfwd"
x = .7

[State 20, Stone]
type = VelSet
triggerall = PalNo = 9
trigger1 = command = "holdback"
x = -.7

[State 20, Stone]
type = VelSet
triggerall = PalNo = 12
trigger1 = command = "holdfwd"
x = .7

[State 20, Stone]
type = VelSet
triggerall = PalNo = 12
trigger1 = command = "holdback"
x = -.7

;[State 20, 0]
;type = VelSet
;trigger1 = command = "holdfwd"
;x = const(velocity.walk.fwd.x)

;[State 20, 0]
;type = VelSet
;trigger1 = command = "holdback"
;x = const(velocity.walk.back.x)

[State 20, 1]
type = VelSet
triggerall = PalNo != 9
triggerall = PalNo != 12
trigger1 = command = "holdfwd"
x = const(velocity.walk.fwd.x)

[State 20, 2]
type = VelSet
triggerall = PalNo != 9
triggerall = PalNo != 12
trigger1 = command = "holdback"
x = const(velocity.walk.back.x)

[State 20, 5]
type = ChangeAnim
triggerall = vel x > 0
trigger1 = Anim != 20 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 20

[State 20, 6]
type = ChangeAnim
triggerall = vel x < 0
trigger1 = Anim != 21 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 21

;---------------------------------------------------------------------------
; Jump Start
[Statedef 40]
type    = S
physics = S
anim = 40
ctrl = 0
sprpriority = 1

[State 40, 0]
type = PlaySnd
trigger1 = Time = 1
value = S0, 7

[State 40, 1]
type = VarSet
trigger1 = Time = 0
sysvar(1) = 0

[State 40, 2]
type = VarSet
trigger1 = command = "holdfwd"
sysvar(1) = 1

[State 40, 3]
type = VarSet
trigger1 = command = "holdback"
sysvar(1) = -1

[State 40, Stone]
type = VelSet
triggerall = PalNo = 12
trigger1 = AnimTime = 0
x = ifelse(sysvar(1)=0, const(velocity.jump.neu.x), ifelse(sysvar(1)=1, const(velocity.jump.fwd.x), const(velocity.jump.back.x)))
y = -6

[State 40, Stone]
type = VelSet
triggerall = PalNo = 9
trigger1 = AnimTime = 0
x = ifelse(sysvar(1)=0, const(velocity.jump.neu.x), ifelse(sysvar(1)=1, const(velocity.jump.fwd.x), const(velocity.jump.back.x)))
y = -6

[State 40, 4]
type = VelSet
triggerall = PalNo != 12
triggerall = PalNo != 9
trigger1 = AnimTime = 0
x = ifelse(sysvar(1)=0, const(velocity.jump.neu.x), ifelse(sysvar(1)=1, const(velocity.jump.fwd.x), const(velocity.jump.back.x)))
y = const(velocity.jump.y)

[State 40, 5]
type = VelSet
trigger1 = AnimTime = 0
trigger1 = prevstateno = 100 ;RUN_FWD
trigger1 = sysvar(1) = 1
x = const(velocity.runjump.fwd.x)

[State 40, 6]
type = ChangeState
trigger1 = AnimTime = 0
value = 50
ctrl = 1

;---------------------------------------------------------------------------
;below coding is by Chairman Kaga
; Jump Up - Manual fall and land.
[Statedef 50]
type    = A
physics = N

[state 50, fall my pretty]
type = Gravity
Trigger1 = 1

[State 50, 1]
type = VarSet
trigger1 = Time = 0
sysvar(1) = 0

[State 50, 2]
type = ChangeAnim
trigger1 = Time = 0
value = ifelse((vel x)=0, 41, ifelse((vel x)>0, 42, 43))

[State 50, 3]
type = ChangeAnim
trigger1 = Vel y > -2
trigger1 = SelfAnimExist(anim + 3)
persistent = 0
value = Anim + 3

[State 50, hit da deck]
type = ChangeState
trigger1 = (Pos Y > 0) && (Vel Y > 0)
value = 52

;---------------------------------------------------------------------------
; Jump Land
[Statedef 52]
type    = S
physics = S
ctrl = 0
anim = 47

[State 52, Var]
type = VarSet
trigger1 = Time = 0
var(1) = 0

[State 52, 1]
type = VelSet
trigger1 = Time = 0
y = 0

[State 52, 2]
type = PosSet
trigger1 = Time = 0
y = 0

[State 52, 3]
type = CtrlSet
trigger1 = Time = 3
value = 1

[State 52, Landing]
type = PlaySnd
triggerall = AnimElem = 1
trigger1 = Time = 0
value = S7,0
volume = -160

[State 52, Shaking]
type = EnvShake
triggerall = AnimElem = 1
trigger1 = PalNo = 12
trigger2 = PalNo = 9
time = 20

[State 52, Heavy Landing]
type = PlaySnd
triggerall = AnimElem = 1
trigger1 = PalNo = 12
trigger2 = PalNo = 9
value = S1,9
persistent = 0

[State 52, 4]
type = ChangeState
trigger1 = AnimTime = 0
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; RUN_FWD
[Statedef 100]
type    = S
physics = S
anim = 100
sprpriority = 1

[State 100, Shaking]
type = EnvShake
trigger1 = PalNo = 12
trigger1 = Animelem = 2 
trigger1 = stateno = 100
trigger2 = PalNo = 12
trigger2 = AnimElem = 6
trigger2 = stateno = 100
trigger3 = PalNo = 9
trigger3 = Animelem = 2 
trigger3 = stateno = 100
trigger4 = PalNo = 9
trigger4 = AnimElem = 6
trigger4 = stateno = 100
freq = 30
ampl = -3
time = 20

[State 100, Running]
type = PlaySnd
trigger1 = PalNo = 12
trigger1 = Animelem = 2 
trigger1 = stateno = 100
trigger2 = PalNo = 12
trigger2 = AnimElem = 6
trigger2 = stateno = 100
trigger3 = PalNo = 9
trigger3 = Animelem = 2 
trigger3 = stateno = 100
trigger4 = PalNo = 9
trigger4 = AnimElem = 6
trigger4 = stateno = 100
value = S1,9

[State 100, Stone]
type = VelSet
triggerall = PalNo = 9
trigger1 = 1
x = 4

[State 100, Stone]
type = VelSet
triggerall = PalNo = 12
trigger1 = 1
x = 4

[State 100, 1]
type = VelSet
triggerall = PalNo != 12
triggerall = PalNo != 9
trigger1 = 1
x = const(velocity.run.fwd.x)

[State 100, 2] ;Prevent run from canceling into walk
type = AssertSpecial
trigger1 = 1
flag = NoWalk

[State 100, 3] ;Prevent from turning
type = AssertSpecial
trigger1 = 1
flag = NoAutoTurn

[State 100, 4]
type = ChangeState
trigger1 = command != "holdfwd"
value = 0

;---------------------------------------------------------------------------
; RUN_BACK
[Statedef 105]
type    = A
physics = A
ctrl = 0
anim = 105
sprpriority = 1

[State 105, Stone]
type = VelSet
triggerall = PalNo = 9
trigger1 = Time = 0
x = 4

[State 105, Stone]
type = VelSet
triggerall = PalNo = 12
trigger1 = Time = 0
x = 4

[State 105, 1]
type = VelSet
triggerall = PalNo != 12
triggerall = PalNo != 9
trigger1 = Time = 0
x = const(velocity.run.back.x)
y = const(velocity.run.back.y)

[State 105, 2]
type = CtrlSet
trigger1 = Time = 2
value = 1

[State 105, 3]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 106

;---------------------------------------------------------------------------
; Roll Forwards
[Statedef 110]
type    = S
physics = S
ctrl = 0
anim = 110

[State 110, Facing]
type = Turn
triggerall = P2BodyDist X < 0
trigger1 = AnimElem = 4  

[State 110, 0]
type = PlaySnd
trigger1 = Time = 1
value = S0, 0
volume = 255

[State 110, Stone]
type = VelSet
triggerall = PalNo != 9
trigger1 = AnimTime < -16
x = 5.5
y = 0

[State 110, Stone]
type = VelSet
triggerall = PalNo != 12
trigger1 = AnimTime < -16
x = 5.5
y = 0

[State 110, 1]
type = VelSet
triggerall = PalNo != 12
triggerall = PalNo != 9
trigger1 = AnimTime < -16
x = 7.5
y = 0

[State 110, 2]
type = CtrlSet
trigger1 = AnimTime = 0
value = 1

[State 110, 3]
type = ChangeState
trigger1 = AnimTime = 0
value = 0

[State 110, MakeDust]
type = MakeDust
trigger1 = 1
pos = -3, 0
spacing = 15

[State 110, Shadow]
type = AfterImage
trigger1 = AnimElem = 3
trigger1 = PalNo != 10
trigger1 = PalNo != 11
trigger1 = PalNo != 7
trigger1 = PalNo != 8
time = 10
TimeGap = 2
FrameGap = 1
length = 30
PalBright   = 0,0,0
PalContrast = 0,0,300
Trans = add

;---------------------------------------------------------------------------
; Lose by Time Over
[Statedef 170]
type = S
ctrl = 0
anim = 5300
velset = 0,0

[State 170, 0]
type = PlaySnd
trigger1 = Time = 1
value = S1, 22

[State 170, 0]
type = PlaySnd
trigger1 = Time = 5
value = S1, 1
volume = 255

[State 170, 1]
type = NotHitBy
trigger1 = Time >= 0
value = SCA
time = 1

;---------------------------------------------------------------------------
; Technically not exactly a common state override, but it ought to be.  =P
; Win state decider
[Statedef 180]
type = S

[State 180, 0]
type = Changestate
trigger1 = life >= 999
trigger1 = PalNo = 4
value = 4020

[State 180, Ghost Mario and Luigi]
type = Changestate
trigger1 = life >= 350
trigger1 = PalNo = 11
trigger2 = life >= 350
trigger2 = PalNo = 8
value = 3800

[State 180, 1]
type = VarRandom
trigger1 = Time = 0
trigger1 = PalNo != 10
trigger2 = Time = 0
trigger2 = PalNo != 7
v = 1
range = 0,75

[State 180, Neo]
type = VarRandom
trigger1 = Time = 0
trigger1 = PalNo = 10
trigger2 = Time = 0
trigger2 = PalNo = 7
v = 17
range = 0,75

[State 180, Neo]
type = Changestate
v = 1
trigger1 = Var(17) = [0,24]
trigger1 = PalNo = 10
trigger2 = Var(17) = [0,24]
trigger2 = PalNo = 7
value = 206

[State 180, Neo]
type = Changestate
v = 1
trigger1 = Var(17) = [25,49]
trigger1 = PalNo = 10
trigger2 = Var(17) = [25,49]
trigger2 = PalNo = 7
value = 181

[State 180, Neo]
type = Changestate
v = 1
trigger1 = Var(17) = [50,75]
trigger1 = PalNo = 10
trigger2 = Var(17) = [50,75]
trigger2 = PalNo = 7
value = 183

[State 180, Stone]
type = VarRandom
trigger1 = Time = 0
trigger1 = PalNo = 12
trigger2 = Time = 0
trigger2 = PalNo = 9
v = 18
range = 0,50

[State 180, Stone]
type = Changestate
v = 1
trigger1 = Var(18) = [0,24]
trigger1 = PalNo = 12
trigger2 = Var(18) = [0,24]
trigger2 = PalNo = 9
value = 181

[State 180, Stone]
type = Changestate
v = 1
trigger1 = Var(18) = [25,50]
trigger1 = PalNo = 12
trigger2 = Var(18) = [25,50]
trigger2 = PalNo = 9
value = 183

[State 180, Normal]
type = Changestate
v = 1
trigger1 = Var(1) = [0,24]
value = 181

[State 180, Normal]
type = Changestate
v = 1
trigger1 = Var(1) = [25,49]
trigger1 = PalNo != 10
trigger1 = PalNo != 12
trigger1 = PalNo != 7
trigger1 = PalNo != 9
value = 182

[State 180, Normal]
type = Changestate
v = 1
trigger1 = Var(1) = [50,75]
value = 183

;---------------------------------------------------------------------------
; INTRO
[Statedef 191]
type = S

[State 191, SuperMario Intro]
type = Changestate
v = 1
triggerall = P4Name != "SuperMario"
triggerall = P3Name != "SuperMario"
trigger1 = P2Name = "SuperMario"
;trigger1 = P2BodyDist X <= 120
value = 197

[State 191, Peach Intro]
type = Changestate
v = 1
trigger1 = P2Name = "Peach"
trigger2 = P4Name = "Peach"
value = 194

[State 191, DK Intro]
type = Changestate
v = 1
trigger1 = P2Name = "dk"
trigger2 = P4Name = "dk"
value = 195

[State 191, Special Intro]
type = Changestate
v = 1
trigger1 = P2name = "Dark Chun Li"
trigger2 = P4name = "Dark Chun Li"
trigger3 = P2name = "Psycho Shredder[S]"
trigger4 = P4name = "Psycho Shredder[S]"
trigger5 = P2name = "Broli Remix ver1.2"
trigger6 = P4name = "Broli Remix ver1.2"
trigger7 = P2name = "Dark Chun Li2"
trigger8 = P4name = "Dark Chun Li2"
trigger9 = P2name = "Super Dan"
trigger10 = P4name = "Super Dan"
value = 201

[State 191, Neo Random]
type = VarRandom
trigger1 = Time = 0
v = 17
range = 0, 10

[State 191, Neo Mario Intro]
type = Changestate
v = 1
trigger1 = PalNo = 10
trigger1 = Var(17) <= 5
trigger2 = PalNo = 7
trigger2 = Var(17) <= 5
value = 205

[State 191, Neo Drop Intro]
type = Changestate
v = 1
trigger1 = PalNo = 10
trigger1 = Var(17) >= 6
trigger2 = PalNo = 7
trigger2 = Var(17) >= 6
value = 207

[State 191, Stone Random]
type = VarRandom
trigger1 = Time = 0
v = 18
range = 0, 10

[State 191, Stone Drop Intro]
type = Changestate
v = 1
trigger1 = PalNo = 12
trigger1 = Var(18) <= 5
trigger2 = PalNo = 9
trigger2 = Var(18) <= 5
value = 207

[State 191, Stone Drop Intro]
type = Changestate
v = 1
trigger1 = PalNo = 12
trigger1 = Var(18) >= 6
trigger2 = PalNo = 9
trigger2 = Var(18) >= 6
value = 3700

[State 191, Ghost Random]
type = VarRandom
trigger1 = Time = 0
v = 19
range = 0, 75

[State 191, Soul Intro]
type = Changestate
v = 1
trigger1 = PalNo = 11
trigger1 = Var(19) = [0,25]
trigger2 = PalNo = 8
trigger2 = Var(19) = [0,25]
value = 4010

[State 191, Ghost Pipe Intro]
type = Changestate
v = 1
trigger1 = PalNo = 11
trigger1 = Var(19) = [26,50]
trigger2 = PalNo = 8
trigger2 = Var(19) = [26,50]
value = 192

[State 191, Ghost Grow Intro]
type = Changestate
v = 1
trigger1 = PalNo = 11
trigger1 = Var(19) = [51,75]
trigger2 = PalNo = 8
trigger2 = Var(19) = [51,75]
value = 193

[State 191, 1]
type = VarRandom
trigger1 = Time = 0
v = 1
range = 0, 10

[State 191, 2]
type = Changestate
v = 1
trigger1 = Var(1) <= 5
trigger1 = PalNo != 10
trigger1 = PalNo != 12
trigger1 = PalNo != 7
trigger1 = PalNo != 9
trigger1 = PalNo != 8
trigger1 = PalNo != 11
value = 192

[State 191, 3]
type = Changestate
v = 1
trigger1 = Var(1) >= 6
trigger1 = PalNo != 10
trigger1 = PalNo != 12
trigger1 = PalNo != 7
trigger1 = PalNo != 9
trigger1 = PalNo != 8
trigger1 = PalNo != 11
value = 193

;---------------------------------------------------------------------------
; HIT_BOUNCE (hit ground)
[Statedef 5100]
type    = L
movetype= H
physics = N

[State 5100, 1]
type = VelSet
trigger1 = Time = 0
trigger1 = GetHitVar(fall.yvel) = 0
trigger1 = vel x > 1
x = 1

[State 5100, EnvShake]
type = FallEnvShake
trigger1 = Time = 0

[State 5100, Var] ;Save fall velocity
type = VarSet
trigger1 = Time = 0
sysvar(1) = floor(vel y)

[State 5100, 2] ;Hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = (anim != [5051,5059]) && (anim != [5061,5069])
trigger2 = !SelfAnimExist(5100 + (anim % 10))
value = 5100

[State 5100, 3] ;Hit ground anim (for hit up)
type = ChangeAnim
trigger1 = time = 0
trigger1 = (anim = [5051,5059]) || (anim = [5061,5069])
trigger1 = SelfAnimExist(5100 + (anim % 10))
value = 5100 + (anim % 10)

[State 5100, 4]
type = PosSet
trigger1 = Time = 0
y = 0

[State 5100, 5]
type = VelSet
trigger1 = Time = 0
y = 0

[State 5100, 6] ;Reduce speed
type = VelMul
trigger1 = Time = 0
x = 0.75

[State 5100, 7]
type = ChangeState
trigger1 = Time = 0
trigger1 = GetHitVar(fall.yvel) = 0
value = 5110 ;HIT_LIEDOWN

[State 5100, 8]
type = GameMakeAnim
trigger1 = Time = 1
value = 60 + (sysvar(1) > 5) + (sysvar(1) > 14)
pos = 0, 0
under = sysvar(1) <= 14

[State 5100, 9]
type = HitFallDamage
trigger1 = Time = 3

[State 5100, 10]
type = PlaySnd
trigger1 = Time = 1
;value = F7, (sysvar(1) > 5) + (sysvar(1) > 14)
value = S1, 9

[State 5100, Stone]
type = PlaySnd
triggerall = Time = 0
triggerall = !SysVar(0)
trigger1 = PalNo = 12
trigger2 = PalNo = 9
;value = F7, 0 ;Hit ground
value = S1, 9 

[State 5100, Shaking]
type = EnvShake
triggerall = Time = 0
trigger1 = PalNo = 12
trigger2 = PalNo = 9
freq = 70
ampl = -8
time = 20

[State 5100, 11]
type = PosFreeze
trigger1 = 1

[State 5100, 12]
type = ChangeState
trigger1 = AnimTime = 0
value = 5101

[State 5100, 13]
type = ForceFeedback
trigger1 = Time = 0
waveform = sinesquare
ampl = 128,-3,-.2,.005
time = 20

;---------------------------------------------------------------------------
; HIT_LIEDOWN
[Statedef 5110]
type    = L
movetype= H
physics = N

[State 5110, EnvShake]
type = FallEnvShake
trigger1 = Time = 0

[State 5110, 1] ;For hit up/up-diag type (from state 5081)
type = ChangeAnim
persistent = 0
trigger1 = SelfAnimExist(5110 + (anim % 10))
trigger1 = anim = [5081,5089]
value = 5110 + (anim % 10)

[State 5110, 2] ;Hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
triggerall = anim != [5110,5119] ;Not already changed anim
trigger1 = anim != [5161,5169]
trigger2 = !SelfAnimExist(5170 + (anim % 10))
value = 5170

[State 5110, 3] ;Hit ground anim (for hit up)
type = ChangeAnim
triggerall = time = 0
triggerall = anim != [5110,5119] ;Not already changed anim
trigger1 = anim = [5161,5169]
trigger1 = SelfAnimExist(5170 + (anim % 10))
value = 5170 + (anim % 10)

[State 5110, 4]
type = HitFallDamage
trigger1 = Time = 0

[State 5110, 5]
type = PosSet
trigger1 = Time = 0
y = 0

[State 5110, Var] ;Get fall velocity
type = VarSet
trigger1 = Time = 0
trigger1 = GetHitVar(fall.yvel) != 0
sysvar(1) = floor(vel y)

[State 5110, 6]
type = PlaySnd
trigger1 = Time = 0
trigger1 = !SysVar(0)
value = S1, 9

[State 5110, Stone]
type = PlaySnd
triggerall = Time = 0
triggerall = !SysVar(0)
trigger1 = PalNo = 12
trigger2 = PalNo = 9
;value = F7, 0 ;Hit ground
value = S1, 9

[State 5110, Shaking]
type = EnvShake
triggerall = Time = 0
trigger1 = PalNo = 12
trigger2 = PalNo = 9
freq = 70
ampl = -8
time = 20

[State 5110, 7]
type = GameMakeAnim
trigger1 = Time = 0
trigger1 = !SysVar(0)
value = 60 + (sysvar(1) > 5) + (sysvar(1) > 14)
pos = 0, 0
under = sysvar(1) <= 14

[State 5110, 8]
type = VelSet
trigger1 = Time = 0
y = 0

[State 5110, 9] ;For hit up type
type = ChangeAnim
persistent = 0
triggerall = anim = [5171,5179]
triggerall = SelfAnimExist(5110 + (anim % 10))
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground anim
value = 5110 + (anim % 10)

[State 5110, 10] ;For normal
type = ChangeAnim
persistent = 0
triggerall = Anim != [5111,5119]
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground frame
value = 5110

[State 5110, 11] ;If just died
type = ChangeState
triggerall = !alive
trigger1 = AnimTime = 0
trigger2 = SysVar(0) ;SysVar(0) = 1 avoids hit ground frame
trigger3 = Anim = [5110,5119]
value = 5150

[State 5110, 12]
type = VarSet
trigger1 = SysVar(0)
trigger1 = Time = 0
sysvar(0) = 0

[State 5110, 13] ;Friction
type = VelMul
trigger1 = 1
x = 0.85

[State 5110, 14]
type = ForceFeedback
trigger1 = alive
trigger1 = Time = 0
time = 8
ampl = 240
waveform = sine

[State 5110, 15]
type = ForceFeedback
trigger1 = !alive
trigger1 = Time = 0
ampl = 200, 7, -.467
time = 30
waveform = sine

;---------------------------------------------------------------------------
; Continue?
[Statedef 5500]
type = S
ctrl = 0
anim = 5300
velset = 0,0

[State 5500, Invisible Pal]
type = AssertSpecial
trigger1 = PalNo = 11
trigger2 = PalNo = 8
flag = invisible

[State 5500, Ghost Mario]
type = AfterImage
trigger1 = PalNo = 11 
trigger2 = PalNo = 8
time = 99999
TimeGap  = 1
FrameGap = 1
length = 5
PalContrast = 50,50,50
Trans = add

[State 5500, 1] ;Use continue animation if available
type = ChangeAnim
trigger1 = time = 0
trigger1 = SelfAnimExist(5500)
value = 5500

;---------------------------------------------------------------------------
; Initialize (at the start of the round)
[Statedef 5900]
type = S

[State 5900, Ghost Mario]
type = AfterImage
trigger1 = PalNo = 11 ;&& Var(20) = 1
trigger2 = PalNo = 8 ;&& Var(20) = 1
time = 99999
TimeGap  = 1
FrameGap = 1
length = 5
PalContrast = 50,50,50
Trans = add

[State 5900, 1] ;Clear all int variables
type = VarRangeSet
trigger1 = !RoundsExisted
value = 0

[State 5900, 2] ;Clear all float variables
type = VarRangeSet
trigger1 = !RoundsExisted
fvalue = 0

[State 5900, 3] ;Intro
type = ChangeState
trigger1 = roundno = 1
value = 190
