;---------------------------------------------------------------------------
; HITG_SHAKE
[Statedef 15000]
type    = S
movetype= H
physics = N
velset = 0,0
ctrl = 0

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

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

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

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

[State 5000, 5] ;State type gets set to aerial if getting hit up
type = StateTypeSet
trigger1 = Time = 0
trigger1 = helper(2000),GetHitVar(yvel) != 0 && helper(2000),GetHitVar(fall)
trigger2 = Pos Y != 0
type = a

[State 5000, 6]
type = ChangeState
trigger1 = alive = 1
trigger1 = helper(2000),HitShakeOver
trigger1 = helper(2000),GetHitVar(yvel) = 0
value = 15001 ;HITG_SLIDE

[State 5000, 7]
type = ChangeState
trigger1 = helper(2000),HitShakeOver
value = ifelse(alive = 0,5030,15030)

[State 5000, FFB Light]
type = ForceFeedback
trigger1 = anim = 5000
trigger2 = anim = 5010
persistent = 0
time = 6
waveform = square

[State 5000, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5001
trigger2 = anim = 5011
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5000, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5012
trigger2 = anim = 5002
trigger3 = anim = 5030
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

[State 5000, 11]
type = Lifeadd
trigger1 = time = 0
trigger1 = prevstateno != [5000,5099]
value = -(helper(2000),GetHitVar(damage))

;---------------------------------------------------------------------------
; HITG_SLIDE
[Statedef 15001]
type    = S
movetype= H
physics = S
ctrl = 0

[State 5001, 1]
type = VelSet
trigger1 = Time = 0
x = Helper(2000),GetHitVar(xvel)*ifelse(facing = -1,-1,1)

[State 5001, 2]
type = ChangeAnim
trigger1 = AnimTime = 0
value = 5005 + helper(2000),GetHitVar(animtype) + (helper(2000),GetHitVar(groundtype)=2)*10

[State 5001, 3] ;Stop sliding back
type = VelMul
trigger1 = Time >= helper(2000),GetHitVar(slidetime)
x = .6

[State 5001, 4]
type = VelSet
trigger1 = helper(2000),HitOver
x = 0

[State 5001, 5]
type = DefenceMulSet
trigger1 = helper(2000),HitOver
value = 1

[State 5001, 6]
type = ChangeState
trigger1 = helper(2000),HitOver
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; HITC_SHAKE
[Statedef 15010]
type    = C
movetype= H
physics = N
velset = 0,0
ctrl = 0

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

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

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

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

[State 5010, 5]
type = ChangeState
trigger1 = alive = 1
trigger1 = helper(2000),HitShakeOver
trigger1 = helper(2000),GetHitVar(yvel) = 0
value = 15011 ;HITC_SLIDE

[State 5010, 6]
type = ChangeState
trigger1 = helper(2000),HitShakeOver
value = ifelse(alive = 0,5030,15030)

[State 5010, FFB Light]
type = ForceFeedback
trigger1 = anim = 5020
persistent = 0
time = 6
waveform = square

[State 5010, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5021
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5010, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5022
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

[State 5000, 11]
type = Lifeadd
trigger1 = time = 0
trigger1 = prevstateno != [5000,5099]
value = -(helper(2000),GetHitVar(damage))

;---------------------------------------------------------------------------
; HITC_SLIDE
[Statedef 15011]
type    = C
movetype= H
physics = C
ctrl = 0

[State 5001, 1]
type = VelSet
trigger1 = Time = 0
x = Helper(2000),GetHitVar(xvel)*ifelse(facing = -1,-1,1)

[State 5011, 2]
type = ChangeAnim
trigger1 = AnimTime = 0
value = 5025 + helper(2000),GetHitVar(animtype)

[State 5011, 3] ;Stop sliding back
type = VelMul
trigger1 = Time >= helper(2000),GetHitVar(slidetime)
x = .6

[State 5011, 4]
type = VelSet
trigger1 = helper(2000),HitOver
x = 0

[State 5011, 5]
type = DefenceMulSet
trigger1 = helper(2000),HitOver
value = 1

[State 5011, 6]
type = ChangeState
trigger1 = helper(2000),HitOver
value = 11
ctrl = 1

;---------------------------------------------------------------------------
; HITA_SHAKE
[Statedef 15020]
type    = A
movetype= H
physics = N
velset = 0,0
ctrl = 0

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

[State 5020, 2] ;Anim for HIT_BACK
type = ChangeAnim
trigger1 = Time = 0
trigger1 = helper(2000),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 = (helper(2000),GetHitVar(animtype) = [4,5]) && (SelfAnimExist(5047 + helper(2000),GetHitVar(animtype)))
value = 5047 + helper(2000),GetHitVar(animtype) ;5051 - 4 + type

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

[State 5020, 5]
type = ChangeState
trigger1 = helper(2000),HitShakeOver
value = ifelse(alive = 0,5030,15030)

[State 5020, FFB Light]
type = ForceFeedback
trigger1 = anim = 5000
trigger2 = anim = 5010
persistent = 0
time = 6
waveform = square

[State 5020, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5001
trigger2 = anim = 5011
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5020, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5012
trigger2 = anim = 5002
trigger3 = anim = 5030
trigger4 = anim = [5051,5059]
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

[State 5000, 11]
type = Lifeadd
trigger1 = time = 0
trigger1 = prevstateno != [5000,5099]
value = -(helper(2000),GetHitVar(damage))

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

[State 5030, 1]
type = VelAdd;Gravity
trigger1 = 1
y = helper(2000),GetHitVar(yaccel)

[State 5001, 1]
type = VelSet
trigger1 = Time = 0
x = Helper(2000),GetHitVar(xvel)*ifelse(facing = -1,-1,1)
y = Helper(2000),GetHitVar(yvel)

[State 5030, 3]
type = ChangeState
triggerall = Helper(2000),HitFall = 0
trigger1 = helper(2000),HitOver
trigger2 = Vel Y > 0    ;Hit ground
trigger2 = Pos Y >= 10  ;.
value = 15040 ;HITA_RECOV

[State 5030, 4]
type = ChangeState
triggerall = Helper(2000),HitFall
trigger1 = helper(2000),HitOver
trigger2 = Vel Y > 0    ;Hit ground
trigger2 = Pos Y >= 10  ;.
value = 15050 ;HITA_FALL

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

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

[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 = helper(2000),HitOver
value = 1

[State 5040, 4]
type = StateTypeSet
trigger1 = helper(2000),HitOver
movetype = I

[State 5040, 5]
type = VelAdd
trigger1 = 1
y = helper(2000),GetHitVar(yaccel)

[State 5040, 5] ;Recover near ground
type = ChangeState
triggerall = Vel Y > 0
triggerall = Pos Y >= -20
triggerall = alive
trigger1 = Command = "recovery"
value = 5200 ;HITFALL_RECOVER

[State 5040, 6]; Recover in mid air
type = ChangeState
triggerall = Vel Y > -1
triggerall = alive
trigger1 = Command = "recovery"
value = 5210 ;HITFALL_AIRRECOVER

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

;---------------------------------------------------------------------------
; HITA_FALL (knocked up, falling)
[Statedef 15050]
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 = 1
y = helper(2000),GetHitVar(yaccel)

[State 5050, 4] ;Recover near ground
type = ChangeState
triggerall = Vel Y > 0
triggerall = Pos Y >= -20
triggerall = alive
triggerall = helper(2000),CanRecover
trigger1 = Command = "recovery"
value = 5200 ;HITFALL_RECOVER

[State 5050, 5]; Recover in mid air
type = ChangeState
triggerall = Vel Y > -1
triggerall = alive
triggerall = helper(2000),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, 25)
value = 15100 ;HIT_BOUNCE

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

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

[State 5070, 2]
type = ChangeState
trigger1 = helper(2000),HitShakeOver
value = 15071

[State 5070, 3]
type = ForceFeedback
trigger1 = time = 0
time = 12
waveform = sinesquare
ampl = 140

[State 5000, 11]
type = Lifeadd
trigger1 = time = 0
trigger1 = prevstateno != [5000,5099]
value = -(helper(2000),GetHitVar(damage))

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

[State 5001, 1]
type = VelSet
trigger1 = Time = 0
x = Helper(2000),GetHitVar(xvel)*ifelse(facing = -1,-1,1)
y = Helper(2000),GetHitVar(yvel)

[State 5071, 2] ;Acceleration
type = VelAdd
trigger1 = 1
y = helper(2000),GetHitVar(yaccel)

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

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

[State 5100, 1]
type = VelSet
trigger1 = Time = 0
trigger1 = helper(2000),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
;trigger1 = helper(2000),GetHitVar(fall.yvel) = 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 = helper(2000),GetHitVar(fall.yvel) = 0
value = 5110 ;HIT_LIEDOWN

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

[State 5100, 9]
type = Lifeadd
trigger1 = time = 3
value = -(Helper(2000),GetHitVar(fall.damage))

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

[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
