;==========================================
; CNS File for Freeza Z2 by Balthazar, Cybaster, Websta, KoopaKoot, JMorphman and XGargoyle
; Override files : jump, dash, etc.
;==========================================


;===========================================================================
; STANCE (tail motion sound)
;===========================================================================

[Statedef 0]
type = S
physics = S
sprpriority = 0

[State 0, 1]
type = ChangeAnim
trigger1 = Anim != 0 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0 ;Turn anim over
value = 0

[State 100, tail pounce]
type = null;playsnd
triggerall = anim = 0
triggerall = random<25
trigger1 = animelemtime(13)=0
trigger2 = animelemtime(25)=0
value = 1,0
persistent = 1

[State 0, 2]
type = VelSet
trigger1 = Time = 0
y = 0

[State 0, 3] ;Stop moving if low velocity or 4 ticks pass
type = VelSet
trigger1 = abs(vel x) < 2
trigger2 = Time = 4
x = 0

[State 0, 4] ;Are you dead?
type = ChangeState
trigger1 = !alive
value = 5050

;===========================================================================
; CROUCHING (tail pounce)
;===========================================================================

[Statedef 11]
type    = C
physics = C
anim = 11
sprpriority = 0

[State 100, tail pounce]
type = null;playsnd
triggerall = random<100
triggerall = anim = 11
trigger1 = animelemtime(8)=0
value = 9,1

[State 11, 1] ;Change from turning animation
type = ChangeAnim
trigger1 = Anim = 6 && AnimTime = 0
value = 11

;===========================================================================
;JUMP START OVERRIDE
;===========================================================================

[Statedef 40]
type    = S
physics = S
anim = 40
ctrl = 0
sprpriority = 1
facep2 = 1

[State 100, jump SND]
type = playsnd
trigger1 = !time
value = 40,1

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

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

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

[State 40, 3]
type = VarSet
trigger1 = Time = 0
sysvar(1) = IfElse(random<333,-1,IfElse(random%2=0,0,1))

[State 40, 4]
type = VelSet
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

;===========================================================================
;JUMP UP OVERRIDE (taking into account super jump commands)
;===========================================================================

; Jump Up
[Statedef 50]
type    = A
physics = A

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

[State 50, 1];from normal jump
type = VarSet
trigger1 = Time = 0
var(4) = 0
[State 50, 1];from normal jump
type = VarSet
trigger1 = Time = 0 && prevstateno=40
var(4) = 1

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

[state veladd]
type = veladd
trigger1 = prevstateno = 10230
Y = -0.15

[state veladd]
type = veladd
triggerall = prevstateno = [10231,10233]
trigger1 = time > 8 && vel X< 4
trigger1 = random<25 ;command = "holdfwd" && command != "holdback"
x = 0.25

[state veladd]
type = veladd
triggerall = prevstateno = [10231,10233]
trigger1 = time > 15 && vel X> -4
trigger1 = random<25 ;command != "holdfwd" && command = "holdback"
x = -0.1

[State 50, 3]
type = ChangeAnim
triggerall = (prevstateno != [10231,10233]) && (anim != 44) && (anim != 42) && (anim != 45)
trigger1 = Vel y > -2
trigger1 = SelfAnimExist(anim + 3)
persistent = 0
value = Anim + 3

[State 50, 3]
type = ChangeAnim
triggerall = (prevstateno != [10231,10233]) && (anim = 42)
trigger1 = Vel y > -2
trigger1 = SelfAnimExist(anim + 3)
persistent = 0
value = 45
elem = ifelse(var(4)=1,1,5)

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

;===========================================================================
; WALK - Sounds added
;===========================================================================

[Statedef 20]
type    = S
physics = S
sprpriority = 0

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

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

[State 20, 2]
type = VelSet
trigger1 = time=0 ;command = "holdback"
x = IfElse(random%2=0,const(velocity.walk.back.x),const(velocity.walk.fwd.x))

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

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

[State 100, steps]
type = playsnd
trigger1 = animelemtime(5)=1 && anim=20 && time>3
value = 40,0
volume = -200
[State 100, steps]
type = playsnd
trigger1 = animelemtime(10)=0 && anim=20
value = 40,0
volume = -200

[State 100, steps]
type = playsnd
trigger1 = animelemtime(3)=1 && anim=21 && time>3
value = 40,0
volume = -200
[State 100, steps]
type = playsnd
trigger1 = animelemtime(7)=0 && anim=21
value = 40,0
volume = -200

;===========================================================================
; RUN
;===========================================================================

[Statedef 100]
type    = S
physics = S
anim = 100
sprpriority = 1
ctrl = 0

; DASH COLLISION ACTIVATION
[State -2, Dash Coll]
type = Changestate
triggerall = enemy,stateno=100 || enemy,stateno=950
triggerall = p2bodydist X = [-30,30]
trigger1 = enemy,selfanimexist(128950)
trigger2 = enemy,name = "awoken Ichigo"
trigger3 = enemy,name = "Anderson" && enemy,authorname="DopeFiend"
trigger4 = enemy,name = "Yellow Suika"
trigger5 = enemy,name = "Combo Stickman"
value = 950

[State 8000, flash]
type = PalFX
trigger1 = prevstateno= 1300
trigger2 = prevstateno= 1301
time = 0

[state 1215, Smoke FX]
type = explod
trigger1 = !time
anim = 1206+(var(2)=0)
id = 1206
pos = -10,0
postype = P1
sprpriority = 3
ownpal = 1
removetime = -2
persistent = 0
ignorehitpause = 1
scale = .8,.8

[State 100, steps]
type = playsnd
trigger1 = animelem=2
value = 40,0  ;0,50

[State 100, steps]
type = playsnd
trigger1 = animelem=5
value = 40,0  ;0,51

[State 100, jump]
type = ChangeState
trigger1 = random<25
value=40

[State 100, 1]
type = VelSet
trigger1 = time > 2
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
triggerall = time > 7
trigger1 = p2bodydist x<=90
value = 101


;RUN STOP
[Statedef 101]
type    = S
physics = S
anim = 101
sprpriority = 1
ctrl = 0

[State 100, snd]
type = playsnd
trigger1 = time=0
value = 5,8
persistent = 0

[State 100, 4]
type = ChangeState
trigger1 = random<25
value = 40

[State 101, 1]
type = AssertSpecial
trigger1 = 1
flag = NoWalk

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

[State 100, 1]
type = VelMul
trigger1 = 1
x = .9

[State 100, 1]
type = VelSet
trigger1 = animtime = 0
x = 0

[State 100, 4]
type = ChangeState
trigger1 = animtime = 0
value = 0
ctrl = 1

;===========================================================================
; TELEPORT FORWARD (Sadism Mode only)
;===========================================================================

[Statedef 102]
type    = S
physics = S
anim = 102
sprpriority = 1
ctrl = 0

[State 8000, flash]
type = PalFX
trigger1 = prevstateno= 1300
trigger2 = prevstateno= 1301
time = 0

[State 100, teleport sound]
type = playsnd
trigger1 = animelemtime(2) = 0
trigger2 = animelemtime(3) = 0
value = 2302,0

[State 3000, nhb]
type = nothitby
trigger1 = animelemtime(2) >= 0
time = 1
value = SCA

[State 105, 1]
type = PosAdd
trigger1 = animelem = 3
x = 100

[State 100, 4]
type = null ;ChangeState
trigger1 = random<25
value = 40

[State 3050, Push]
type = playerpush
trigger1 = animelemtime(3) >= 0
value = 0
ignorehitpause = 1

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

[State 100, 4]
type = ChangeState
trigger1 = animtime = 0
value = 103

;----------------------
; TELEPORT STOP
[Statedef 103]
type    = S
physics = S
anim = 103
sprpriority = 1
ctrl = 0
facep2 = 1

[State 100, 4]
type = ChangeState
trigger1 = random<25
value = 40

[State 101, 1]
type = AssertSpecial
trigger1 = 1
flag = NoWalk

[State 100, 4]
type = ChangeState
trigger1 = animtime = 0
value = 0
ctrl = 1

;===========================================================================
;DASH BACK
;===========================================================================

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

[State 100, jump SND]
type = playsnd
trigger1 = !time
value = 40,1

[State 3000, nhb]
type = nothitby
trigger1 = animelemtime(6)<0
time = 1
value = SCA

[State 8000, flash]
type = PalFX
trigger1 = prevstateno= 1300
trigger2 = prevstateno= 1301
time = 0

[State 105, 1]
type = VelSet
trigger1 = Time = 0
x = const(velocity.run.back.x)
y = 1.2*const(velocity.run.back.y)

[State 105, 2]
type = AssertSpecial
trigger1 = Time >= 2
flag = noairguard

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

;-----------------------------------------------------------------------
; DASH BACK (land)

[Statedef 106]
type    = S
physics = S
ctrl = 0
anim = 47

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

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

[State 106, 4]
type = ChangeState
trigger1 = Time = 7
value = 0
ctrl = 1

;===========================================================================
; TELEPORT BACKWARD (Sadism Mode only)
;===========================================================================

[Statedef 107]
type    = S
physics = S
anim = 102
sprpriority = 1
ctrl = 0

[State 100, teleport sound]
type = playsnd
trigger1 = animelemtime(2) = 0
trigger2 = animelemtime(3) = 0
value = 2302,0

[State 3000, nhb]
type = nothitby
trigger1 = animelemtime(2) >= 0
time = 1
value = SCA

[State 105, 1]
type = PosAdd
trigger1 = animelem = 3
x = -80

[State 100, 4]
type = null ;ChangeState
trigger1 = random<25
value = 40

[State 3050, Push]
type = playerpush
trigger1 = animelemtime(3) >= 0
value = 0
ignorehitpause = 1

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

[State 100, 4]
type = ChangeState
trigger1 = animtime = 0
value = 103


;===========================================================================
;JUMP LAND NO FRICTION
;===========================================================================
[Statedef 52]
type    = S
physics = S
ctrl = 0
anim = 47
velset = 0,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
triggerall = prevstateno != 19302
trigger1 = Time = 1
value = 1

[State 52, 5]
type = turn
trigger1 = time = 1 && P2Dist x < 0
trigger1 = random<25

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




;===========================================================================
; HITA_SHAKE - Changing anim
;===========================================================================
; HITA_SHAKE
[Statedef 5020]
type    = A
movetype= H
physics = N
velset = 0,0

[State 5020, 1] ;Anim for HIT_LIGHT to HIT_HARD
type = ChangeAnim
trigger1 = Time = 0
trigger1 = GetHitVar(animtype) != [3,5]
value = 5010 + GetHitVar(animtype)

[State 5020, 2] ;Anim for HIT_BACK
type = ChangeAnim
trigger1 = Time = 0
trigger1 = GetHitVar(animtype) = [3,5]
value = 5030

[State 5020, 3] ;Anim for HIT_UP/HIT_DIAGUP (only if it exists)
type = ChangeAnim
trigger1 = Time = 0
trigger1 = (GetHitVar(animtype) = [4,5]) && (SelfAnimExist(5047 + GetHitVar(animtype)))
value = 5047 + GetHitVar(animtype)

[State 5020, 4] ;Freeze anim
type = ChangeAnim
trigger1 = Time > 0
value = anim

[State 5020, 5]
type = ChangeState
trigger1 = HitShakeOver
value = 5030

;===========================================================================
; HIT_FALLRECOVER (still falling) Giving posadd
;===========================================================================
; HIT_FALLRECOVER (on the ground)
[Statedef 5201]
type    = A
movetype= H
physics = N
anim = 105 ;5200
velset = 0,0

[State 5201, 1] ;Turn if not facing opponent
type = Turn
trigger1 = Time = 0
trigger1 = p2dist X < -5

[State 5201, 3]
type = VelSet
trigger1 = Time = 0
x = 0

[State 5201, 3]
type = PosSet
trigger1 = Time = 0
trigger2 = Pos Y > -5
y = 0

[State 5201, 4]
type = NotHitBy
trigger1 = 1
value = SCA
time = 1

[State 5201, 5] ;Blink white
type = PalFX
trigger1 = Time = 0
time = 3
add = 128,128,128

[State 105, 1]
type = VelSet
trigger1 = !time
x = 0.8*const(velocity.run.back.x)
y = 1.2*const(velocity.run.back.y)

[State 5201, 2]
type = Statetypeset
trigger1 = !time
physics = A

;===========================================================================
; HIT_BOUNCE (hit ground) - redirect
;===========================================================================
[Statedef 5100]
type    = L
movetype= H
physics = N
 
[State 5100]
type = ChangeState
trigger1 = !Time
value = 5102

;===========================================================================
; HIT_BOUNCE (hit ground) - changing falling sound
;===========================================================================
[Statedef 5102]
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, 4] ;Hit ground anim (for flip knockout)
type = Varset
trigger1 = !time
var(47)=0
[State 5100, 4] ;Hit ground anim (for flip knockout)
type = Varset
triggerall = prevstateno = 1264 && selfanimexist(5937)
trigger1 = time = 0
var(47)=1

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

[State 5100, 10]
type = PlaySnd
trigger1 = Time = 1
value = 15000,1

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

[State 5100, 12]
type = ChangeState
triggerall = var(47)=1
trigger1 = AnimElem = 2
value = 5101

[State 5100, 12]
type = ChangeState
triggerall = var(47)=0
trigger1 = AnimTime = 0
value = 5101


;===========================================================================
; HIT_BOUNCE (bounce into air) - Modified for Flip Knockout
;===========================================================================

[Statedef 5101]
type    = L
movetype= H
physics = N

[State 5101, 1] ;Coming hit ground anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim != [5101,5109]
trigger2 = !SelfAnimExist(5160 + (anim % 10))
value = 5160

[State 5101, 2] ;Coming hit ground anim (for hit up)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim = [5101,5109]
trigger1 = SelfAnimExist(5160 + (anim % 10))
value = 5160 + (anim % 10)

[State 5100, 4] ;Hit ground anim (for flip knockout)
type = ChangeAnim
triggerall = var(47)=1 && selfanimexist(5937)
trigger1 = time = 0
value = 5937
elem = 3
[State 5100, 4] ;Hit ground anim (for flip knockout)
type = VelSet
triggerall = var(47)=1 && selfanimexist(5937)
trigger1 = time = 0
X = -2

[State 5101, 3]
type = HitFallVel
trigger1 = Time = 0

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

[State 5101, 5] ;Acceleration
type = VelAdd
trigger1 = 1
y = .4

[State 5101, 6] ;Hit ground
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 12
type = ChangeState
value = 5110

;===========================================================================
; HIT_LIEDOWN - redirect
;===========================================================================
[Statedef 5110]
type    = L
movetype= H
physics = N
 
[State 0, ChangeState]
type = ChangeState
trigger1 = !Time
value = 5111

;===========================================================================
; HIT_LIEDOWN - changing falling sound
;===========================================================================
[Statedef 5111]
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 5100, 4] ;Hit ground anim (for flip knockout)
type = ChangeAnim
triggerall = var(47)=1
trigger1 = time = 0
value = 5100
[State 5100, 4] ;Varset (for flip knockout)
type = Varset
triggerall = var(47)=1
trigger1 = time = 0
var(47)=0

[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 = 15000,0

[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

[State 0, ChangeState]
type = ChangeState
trigger1 = Time >=Const(data.liedown.time)
value =5120

;===========================================================================
; HIT_GETUP - moving forward during getup
;===========================================================================
[Statedef 5120]
type    = L
movetype= I
physics = N

[State 5120, 1a] ;Get up anim (normal)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim != [5111,5119]
trigger2 = !SelfAnimExist(5120 + (anim % 10))
value = 5120

[State 5120, 1b] ;Get up anim (for hit up/diag-up)
type = ChangeAnim
triggerall = time = 0
trigger1 = anim = [5111,5119]
trigger1 = SelfAnimExist(5120 + (anim % 10))
value = 5120 + (anim % 10)

[State 5120, 2]
type = VelSet
trigger1 = Time = 0
x = 0

[State 5120, 3]
type = NotHitBy
trigger1 = 1
value = SCA
time = 1

[State 230, woosh sound]
type = PlaySnd
trigger1 = !time
value = 40,1  ;0, 3

[State 5120, 4]
type = HitFallSet
trigger1 = AnimTime = 0
value = 1

[State 5120, 5] ;Can't be thrown right after getting up
type = NotHitBy
trigger1 = AnimTime = 0
value = , NT,ST,HT
time = 12

[State 5120, 6] ;Can't be hit right after getting up (short time)
type = NotHitBy
trigger1 = AnimTime = 0
value2 = SCA
time = 3

[State 5120, 7]
type = ChangeState
trigger1 = AnimTime = 0
value = 0
ctrl = 1

;===========================================================================
; HIT_LIEDEAD - changing anim when cheap ko
;===========================================================================
[Statedef 5150]
type    = L
movetype= H
physics = N
sprpriority = -3

[State 5150, normal]
type = ChangeAnim
trigger1 = Time = 0
value = 5150

[State 5150, cheap ko]
type = ChangeAnim
trigger1 = Time = 0 && prevstateno=5950
value = 5950
elem = 7

[State 5150, 6] ;Friction
type = VelMul
trigger1 = 1
x = 0.85

[State 5150, 7] ;Friction
type = VelSet
trigger1 = Vel x < .05
persistent = 0
x = 0

[State 5150, 8]
type = NotHitBy
trigger1 = 1
value = SCA
time = 1

;===========================================================================
; HIT_AIRFALLRECOVER - adding sound and changing colour
;===========================================================================

[Statedef 5210]
type    = A
movetype= I
physics = N
anim = 5210
ctrl = 0

[State 0, VarSet]
type = VarSet
trigger1 = !time
var(53) = random%4
ignorehitpause = 1
;persistent =


[State 0, ]
type = Helper
trigger1 = time = 0
helpertype = normal
name = "recoverpulser"
ID = 52100
stateno = 52100
ownpal = 1
supermovetime = 99999
pausemovetime = 99999

[State 5210, 1] ;Blink white
type = PalFX
trigger1 = Time = 0
time = 3
add = 50,50,256

[State 5210, 1]
type = PosFreeze
trigger1 = Time = 0
value = 4

[State 5210, 2] ;Turn if not facing opponent
type = Turn
trigger1 = Time = 0
trigger1 = p2dist X < -20

[State 2302, Twist SFX]
type = playsnd
trigger1 = !time
value = 5052,0
volume = -100

[State 5210, 1] 
type = VelMul
trigger1 = Time = 4
x = .8
y = .8

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
y = -4.5

[State 5210, 1] 
type = VelMul
trigger1 = Time = 4
trigger1 = Vel Y > 0
y = .5

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
trigger1 = Vel Y > -3
y = -2

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
trigger1 = Vel Y > -2
y = -1

[State 5210, 2] ;Go up
type = VelAdd
trigger1 = Time = 4
trigger1 = var(53)=0 ;Command = "holdup"
y = -2

[State 5210, 2] ;Go down
type = VelAdd
trigger1 = Time = 4
trigger1 = var(53)=1 ;Command = "holddown"
y = 1.5

[State 5210, 2] ;Go fwd
type = VelMul
trigger1 = Time = 4
trigger1 = var(53)=2 ;Command = "holdfwd"
x = 1

[State 5210, 2] ;Go back
type = VelAdd
trigger1 = Time = 4
trigger1 = var(53)=3 ;Command = "holdback"
x = -1

[State 0, VarSet]
type = VarSet
trigger1 = time=5
var(53)=0
ignorehitpause = 1
;persistent =


[State 5210, 3]
type = NotHitBy
trigger1 = Time = 0
value = SCA
time = 20

[State 5210, 4]
type = CtrlSet
trigger1 = Time = 20
value = 1

[State 5210, 5]
type = VelAdd;Gravity
trigger1 = Time >= 4
y = .35

[State 5210, 5] ;Land on ground
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 52 ;JUMP_LAND
ctrl = 1

;===========================================================================
; HIT_FALLRECOVER - adding sound and changing colour
;===========================================================================
;still falling

[Statedef 5200]
type    = A
movetype= H
physics = N

[State 5200, 1] ;Change anim if done with transition
type = ChangeAnim
trigger1 = Anim = 5035
trigger1 = AnimTime = 0
value = 5050

[State 5200, 2]
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5200, 3]
type = SelfState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= Const(movement.air.gethit.groundrecover.groundlevel)
value = 5201




;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; FIX VELADD BUG AS EXPLAINED BY VANS :
; http://www.vans.trinitymugen.net/home/mugenbug.html
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; HITA_UP (initial going up)
[Statedef 5030]
type    = A
movetype= H
physics = N
ctrl = 0

[State 5030, 1]
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5030, 2]
type = VelSet
trigger1 = !Time
x = GetHitVar(xvel) * facing
y = gethitvar(yvel)

[State 5030, 3]
type = ChangeState
triggerall = !HitFall
trigger1 = HitOver
trigger2 = Vel Y > 0    ;Hit ground
trigger2 = Pos Y >= 10  ;.
value = 5040 ;HITA_RECOV

[State 5030, 4]
type = ChangeState
triggerall = HitFall
trigger1 = HitOver
trigger2 = Vel Y > 0    ;Hit ground
trigger2 = Pos Y >= 10  ;.
value = 5050 ;HITA_FALL

[State 5030, 5]
type = ChangeState
trigger1 = AnimTime = 0
value = 5035 ;HITA_UP (transition)

;---------------------------------------------------------------------------
; HITA_UP_T (transition)
[Statedef 5035]
type    = A
movetype= H
physics = N

[State 5035, 1]
type = ChangeAnim
trigger1 = Time = 0
trigger1 = SelfAnimExist(5035)
trigger1 = Anim != [5051,5059] ;Not if in hit up anim
trigger1 = Anim != 5090 ;Not if hit off ground anim
value = 5035

[State 5035, 2]
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5035, 3]
type = ChangeState
triggerall = !HitFall
trigger1 = HitOver  ;Hit is over
trigger2 = AnimTime = 0 ;Animation over
trigger3 = Vel Y > 0    ;Hit ground
trigger3 = Pos Y >= 10  ;.
trigger4 = Time = 0     ;No transition anim
trigger4 = Anim != 5035 ;.
value = 5040 ;HITA_RECOV

[State 5035, 4]
type = ChangeState
triggerall = HitFall
trigger1 = HitOver  ;Hit is over
trigger2 = AnimTime = 0 ;Anim is over
trigger3 = Vel Y > 0    ;Hit ground
trigger3 = Pos Y >= 10  ;.
trigger4 = Time = 0     ;No transition anim
trigger4 = Anim != 5035 ;.
value = 5050 ;HITA_FALL

;---------------------------------------------------------------------------
; HITA_RECOV (recovering in air, not falling)
[Statedef 5040]
type    = A
movetype= H
physics = N

[State 5040, 1]
type = ChangeState
trigger1 = !Alive
value = 5050

[State 5040, 2]
type = ChangeAnim
trigger1 = AnimTime = 0
trigger1 = Anim != 5040
trigger2 = Time = 0
trigger2 = Anim != 5035
value = 5040

[State 5040, 3]
type = CtrlSet
trigger1 = HitOver
value = 1

[State 5040, 4]
type = StateTypeSet
trigger1 = HitOver
movetype = I

[State 5040, 5]
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5040, 6]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 52 ;JUMPLAND

;---------------------------------------------------------------------------
; HITA_FALL (knocked up, falling)
[Statedef 5050]
type    = A
movetype= H
physics = N

[State 5050, 1] ;Change anim when done with transition
type = ChangeAnim
trigger1 = AnimTime = 0
trigger1 = Anim = 5035
trigger2 = Time = 0     ;If no transition anim
trigger2 = Anim != 5035
trigger2 = (Anim != [5051, 5059]) && (Anim != [5061, 5069])
trigger2 = Anim != 5090 ;Not if hit off ground anim
value = 5050

[State 5050, 2] ;Coming down anim
type = ChangeAnim
trigger1 = anim = [5050,5059]
trigger1 = Vel Y >= ifelse(anim = 5050, 1, -2)
trigger1 = SelfAnimExist(anim+10)
value = anim+10
persistent = 0

[State 5050, 3] ;Gravity
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5050, 4] ;Recover near ground
type = ChangeState
triggerall = Vel Y > 0
triggerall = Pos Y >= Const(movement.air.gethit.groundrecover.ground.threshold)
triggerall = alive
triggerall = CanRecover
trigger1 = Command = "recovery"
value = 5200 ;HITFALL_RECOVER
 
[State 5050, 5]; Recover in mid air
type = ChangeState
triggerall = Vel Y > Const(movement.air.gethit.airrecover.threshold)
triggerall = alive
triggerall = CanRecover
trigger1 = Command = "recovery"
value = 5210 ;HITFALL_AIRRECOVER
 
[State 5050, 6]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= ifelse((anim = [5051,5059]) || (anim = [5061,5069]), 0, Const(movement.air.gethit.groundlevel))
value = 5100 ;Downed get-hit (hit ground from fall)

;---------------------------------------------------------------------------
; HIT_TRIP (shaking)
[Statedef 5070]
type    = A
movetype= H
physics = N
velset = 0,0

[State 5070, 1]
type = ChangeAnim 
trigger1 = 1
value = 5070

[State 5070, 2]
type = ChangeState
trigger1 = HitShakeOver
value = 5071

;---------------------------------------------------------------------------
; HIT_TRIP2 (fall through air)
[Statedef 5071]
type    = A
movetype= H
physics = N

[State 5071, 1]
type = VelSet
trigger1 = !Time
x = GetHitVar(xvel) * facing
y = gethitvar(yvel)

[State 5071, 2] ;Acceleration
type = VelAdd
trigger1 = time > 0 ;Vans Fix !!!
y = GetHitVar(yaccel)

[State 5071, 3] ;Hit ground
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 15
type = ChangeState
value = 5110

;-------------------------------------------------------------------------------
;GUARD
[Statedef 120]
type=U
physics=U
anim=120+(statetype=C)+(statetype=A)*2

[State 120]
Type=CtrlSet
Trigger1= 1 ;AILevel>0
value=0

[State 120, Type]
type=statetypeset
trigger1= !time && statetype=S
physics=S
[State 120, Type]
type=statetypeset
trigger1= !time && statetype=C
physics=C
[State 120, Type]
type=statetypeset
trigger1= !time && statetype=A
physics=A
[State 120, Vel]
type=velset
trigger1= !time && statetype!=A
x=0
y=0
[State 120, High to Low]
type=statetypeset
triggerall = statetype!=A
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 120, Low to High]
type=statetypeset
triggerall = statetype!=A
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S
[State 120, AI fix]
type=ctrlset
trigger1= numenemy
value= (enemynear,time>=120 || time>=180)
[State 120, End]
type=changestate
trigger1= !animtime
value=130+(statetype=C)+(statetype=A)*2
[State 120, Stop]
type=changestate
trigger1= !inguarddist
trigger2=  numenemy
trigger2= enemynear,hitdefattr=SCA,AT
value=140


;-------------------------------------------------------------------------------
;STAND GUARD (guarding)
[Statedef 130]
type=S
physics=S
[State 120]
Type=CtrlSet
Trigger1= 1 ;AILevel>0
value=0
[State 130, Anim]
type=changeanim
trigger1= anim!=130
value=130
[State 130, AI fix]
type=ctrlset
trigger1= numenemy
value= (enemynear,time>=120 || time>=180)
[State 130, High to Low]
type=changestate
trigger1= random<250
trigger1= (enemynear,movetype=A) && (enemynear,statetype=C)
value=131
[State 130, Stop Guarding]
type=changestate
trigger1= !inguarddist
trigger2= numenemy
trigger2= enemynear,hitdefattr=SCA,AT
value=140


;-------------------------------------------------------------------------------
;CROUCH GUARD (guarding)
[Statedef 131]
type=C
physics=C
[State 120]
Type=CtrlSet
Trigger1= 1 ;AILevel>0
value=0
[State 131, Anim]
type=changeanim
trigger1= anim!=131
value=131
[State 131, Low to High]
type=changestate
trigger1=  random<125
trigger1 = numenemy
trigger1= (enemynear,movetype=A) && (enemynear,statetype!=C)
value=130
[State 131, AI fix]
type=ctrlset
trigger1= numenemy
value= (enemynear,time>=120 || time>=180)
[State 131, Stop Guarding]
type=changestate
trigger1= !inguarddist
trigger2= numenemy
trigger2= enemynear,hitdefattr=SCA,AT
value=140

;-------------------------------------------------------------------------------
;AIR GUARD (guarding)
[Statedef 132]
type=A
physics=N
[State 120]
Type=CtrlSet
Trigger1= 1 ;AILevel>0
value=0
[State 132, Anim]
type=changeanim
trigger1= anim!=132
value=132
[State 132, Grav]
type=veladd
trigger1= 1
y=const(movement.yaccel)
[State 132, Var]
type=varset
trigger1= 1
sysvar(0)=(pos y>=0 && vel y>0)
[State 132, Vel]
type=velset
trigger1= sysvar(0)
y=0
[State 132, Pos]
type=posset
trigger1= sysvar(0)
y=0
[State 132, AI fix]
type=ctrlset
trigger1= numenemy
value= (enemynear,time>=120 || time>=180)
[State 132, End]
type=changestate
trigger1= sysvar(0) && inguarddist
value=130
[State 132, End]
type=changestate
trigger1= sysvar(0)
value=52
[State 132, stop guarding]
type=changestate
trigger1= !inguarddist
trigger2= numenemy
trigger2= enemynear,hitdefattr=SCA,AT
value=140

;-------------------------------------------------------------------------------
;GUARD (end)
[Statedef 140]
type=U
physics=U
ctrl=1
[State 140, Anim]
type=changeanim
trigger1= !time
value=140+(statetype=C)+(statetype=A)*2
[State 140, Type]
type=statetypeset
trigger1= !time && statetype=S
physics=S
[State 140, Type]
type=statetypeset
trigger1= !time && statetype=C
physics=C
[State 140, Type]
type=statetypeset
trigger1= !time && statetype=A
physics=A
[State 140, High to Low]
type=statetypeset
trigger1= random<250
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 140, Low to High]
type=statetypeset
trigger1= random<125
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S
[State 140, End]
type=changestate
trigger1= !animtime
value=(statetype=C)*11+(statetype=A)*51

;-------------------------------------------------------------------------------
;SGUARDHIT (shaking)
[Statedef 150]
type=S
movetype=H
physics=N
velset=0,0
[State 150, Anim]
type=changeanim
trigger1= 1
value=150
[State 150, End]
type=changestate
trigger1= hitshakeover
value=151+2*((enemynear,movetype=A) && (enemynear,statetype=C))
[State 150, High to Low]
type=statetypeset
trigger1= random<250
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 150, Low to High]
type=statetypeset
trigger1= random<125
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S

;-------------------------------------------------------------------------------
;SGUARDHIT2 (knocked back)
[Statedef 151]
type=S
movetype=H
physics=S
anim=150
[State 151, Vel]
type=hitvelset
trigger1= !time
x=1
[State 151, Vel]
type=velset
trigger1= time=gethitvar(slidetime)
trigger2= hitover
x=0
[State 151, Ctrl]
type=ctrlset
trigger1= time=gethitvar(ctrltime)
value=1
[State 151, High to Low]
type=statetypeset
trigger1= random<250
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 151, Low to High]
type=statetypeset
trigger1= random<125
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S
[State 151, End]
type=changestate
trigger1= hitover
value=130
ctrl=1

;-------------------------------------------------------------------------------
;CGUARDHIT (shaking)
[Statedef 152]
type=C
movetype=H
physics=N
velset=0,0
[State 152, Anim]
type=changeanim
trigger1= 1
value=151
[State 152, End]
type=changestate
trigger1= hitshakeover
value=151+2*((enemynear,movetype=A) && (enemynear,statetype=C))
[State 152, High to Low]
type=statetypeset
trigger1= random<250
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 152, Low to High]
type=statetypeset
trigger1= random<125
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S

;-------------------------------------------------------------------------------
;CGUARDHIT2 (knocked back)
[Statedef 153]
type=C
movetype=H
physics=C
anim=151
[State 153, Vel]
type=hitvelset
trigger1= !time
x=1
[State 153, Vel]
type=velset
trigger1= time=gethitvar(slidetime)
trigger2= hitover
x=0
[State 153, Ctrl]
type=ctrlset
trigger1= time=gethitvar(ctrltime)
value=1
[State 153, High to Low]
type=statetypeset
trigger1= random<250
trigger1= statetype=S && (enemynear,movetype=A) && (enemynear,statetype=C)
statetype=C
physics=C
[State 153, Low to High]
type=statetypeset
trigger1= random<125
trigger1= statetype=C && (enemynear,movetype=A) && (enemynear,statetype!=C)
statetype=S
physics=S
[State 153, End]
type=changestate
trigger1= hitover
value=131
ctrl=1

;-------------------------------------------------------------------------------
;AGUARDHIT (shaking)
[Statedef 154]
type=A
movetype=H
physics=N
velset=0,0
[State 154, Anim]
type=changeanim
trigger1= 1
value=152
[State 154, End]
type=changestate
trigger1= hitshakeover
value=155

;-------------------------------------------------------------------------------
;AGUARDHIT2
[Statedef 155]
type=A
movetype=H
physics=N
anim=152
[State 155, Vel]
type=hitvelset
trigger1= !time
x=1
y=1
[State 155, Vel]
type=veladd
trigger1= 1
y=const(movement.yaccel)
[State 155, Ctrl]
type=ctrlset
trigger1= time=gethitvar(ctrltime)
value=1
[State 155, Var]
type=varset
trigger1= 1
sysvar(0)=(pos y>=0 && vel y>0)
[State 155, Vel]
type=velset
trigger1= sysvar(0)
y=0
[State 155, Pos]
type=posset
trigger1= sysvar(0)
y=0
[State 155, End]
type=changestate
trigger1= sysvar(0) && inguarddist
value=130
[State 155, End]
type=changestate
trigger1= sysvar(0)
value=52
