; Common state file for M.U.G.E.N beta 2002.04.14
;
; System variables usage
; ----------------------
; Var name    Type   Purpose
; --------    ----   -------
; sysvar(0)   Temp   Set by state 5081 (HITL_SLIDE) to 1 to prevent
;                    showing ground hit frame in state 5110 (HIT_LIEDOWN).
;                    Used by guarding states.
; sysvar(1)   Temp   Used by state 40 (Jump Start) amd 45 (Air Jump Start)
;                    to keep track of which way to jump.
;                    Used by state 5100 and 5110 to remember downward
;                    velocity of player just before hitting the ground.
;                    Used in state 5080 for storing the anim # to display.

; The following states have special handling within MUGEN, and should be
; overridden with caution:
; Jump Start (40): airjumping bookkeeping at time = 0
; All guard states (120-155): guard handling throughout state
; Hit_trip, shaking (5070): defence increases at time = 0
; Hit_bounce (5100): defence increases at time = 0, player becomes
;                    invincible if within 10 ticks of getting up
; Hit_liedown (5110): player changes to get-up state (5120) when ready
; Hit_getup (5120): player's defence is restored to normal at time = 0
; Hitfall_recover (5200): player's defence is restored at time = 0
; Hitfall_airrecover (5210): player's defence is restored at time = 0

;---------------------------------------------------------------------------
; Stand
[Statedef 0]
type = S
physics = S
sprpriority = 0

[state 0]
type = changestate
trigger1 = ishelper(7000)
value = 7000
ignorehitpause = 1
[state 0]
type = changestate
trigger1 = ishelper(20000)
value = 20000
ignorehitpause = 1

[state 0]
type = destroyself
trigger1 = ishelper
ignorehitpause = 1

[state 0]
type = selfstate
trigger1 = name != "Rumi Nanase"
value = 0

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

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

[State 0, 1]
type = ChangeAnim
triggerall = var(30) = 0
trigger1 = Anim = 1
value = 0
elem = animelemno(0)

[State 0, 1]
type = ChangeAnim
triggerall = var(30) = 1
trigger1 = Anim = 0
value = 1
elem = animelemno(0)

[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

;---------------------------------------------------------------------------
; Stand to Crouch
[Statedef 10]
type    = C
physics = N

[state 10]
type = changestate
trigger1 = time = 1
trigger1 = prevstateno = 101
value = 101
ignorehitpause = 1

[state 10]
type = changeanim
trigger1 = anim != 10 + 3*var(30)
trigger1 = prevstateno != 101
value = 10 + 3*var(30)

[state 10]
type = statetypeset
trigger1 = prevstateno != 101
statetype = C
physics = C

[State 10, 1]
type = VelMul
trigger1 = Time = 0
trigger1 = prevstateno != 101
x = .75

[State 10, 2]
type = ChangeState
trigger1 = AnimTime = 0
value = 11

;---------------------------------------------------------------------------
; Crouching
[Statedef 11]
type    = C
physics = C
anim = 11 + 3*var(30)
sprpriority = 0

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

;---------------------------------------------------------------------------
; Crouch to Stand
[Statedef 12]
type    = S
physics = S
anim = 12 + 3*var(30)

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

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

[state 20,0]
type = changestate
trigger1 = var(59) > 0
trigger1 = time = 0
value = 0
ctrl = 1
ignorehitpause = 1

[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, 3]
type = ChangeAnim
triggerall = var(30) != 1
triggerall = vel x > 0
trigger1 = Anim != 20 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 20

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

[State 20, 3]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x > 0
trigger1 = Anim != 22 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 22

[State 20, 4]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x < 0
trigger1 = Anim != 23 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 23
;---------------------------------------------------------------------------
; Jump Start
[Statedef 40]
type    = S
physics = S
anim = 39 + var(1)
ctrl = 0
sprpriority = 1

[state 20,0]
type = changestate
trigger1 = var(59) > 0
trigger1 = time = 0
value = 0
ctrl = 1
ignorehitpause = 1

[state 40,0]
type = statetypeset
trigger1 = time >= 2
statetype = A

[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, 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,101] ;RUN_FWD
trigger1 = sysvar(1) = 0
x = 1.5

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

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

;---------------------------------------------------------------------------
; AirJump Start
[Statedef 45]
type    = A
physics = N
ctrl = 0
velset = 0,0

[state 45]
type = assertspecial
trigger1 = 1
flag = noautoturn

[State 45, 1]
type = ChangeAnim
trigger1 = 1
value = 41 + var(30)

[state 45]
type = varset
trigger1 = time = 0
var(1) = 1
ignorehitpause = 1

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

[State 45, 4]
type = VarSet
trigger1 = command = "holdfwd"
sysvar(1) = 1

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

[State 45, 6]
type = VelSet
trigger1 = Time = 2
x = ifelse(sysvar(1)=0, const(velocity.airjump.neu.x), ifelse(sysvar(1)=1, const(velocity.airjump.fwd.x), const(velocity.airjump.back.x)))
y = const(velocity.airjump.y)

[State 45, 7]
type = ChangeState
trigger1 = Time = 2
value = 50
ctrl = 1

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

[state 45]
type = assertspecial
trigger1 = 1
flag = noautoturn

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

[State 50, 2]
type = ChangeAnim
trigger1 = Time = 0
value = 41 + var(30)

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

;---------------------------------------------------------------------------
; Jump Down (empty state for compatibility)
[Statedef 51]
type    = A
physics = A

[State 51, 1]
type = Null
trigger1 = 1

;---------------------------------------------------------------------------
; Jump Land
[Statedef 52]
type    = S
physics = S
ctrl = 0
anim = 47 + var(30)

[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, 4]
type = ChangeState
trigger1 = AnimTime = 0
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; RUN_FWD
[Statedef 100]
type    = S
physics = S
anim = 100+var(30)
sprpriority = 1
ctrl = 0

[state 100,0]
type = veladd
trigger1 = vel x < const(velocity.run.fwd.x)
x = 1.5

[State 100, 1]
type = VelSet
trigger1 = vel x >= const(velocity.run.fwd.x)
x = const(velocity.run.fwd.x)

[State 100]
type = AfterImage
trigger1 = time = 0
time = 999
TimeGap  = 1
FrameGap = 3
Trans = Add1
length = 12
PalBright   =   0,  0,  0
PalContrast = 128,128,128
PalAdd      =   0,  0,  0
PalMul      =  1,1,1

[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 = !var(59)
trigger1 = time >= 15
trigger1 = command != "holdfwd"
trigger2 = time >= 50
value = 101

[State 100, 4]
type = ChangeState
triggerall = var(59)
triggerall = time >= 15
triggerall = var(30)
trigger1 = time >= 50
trigger2 = numtarget(1400)
trigger3 = p2bodydist x <= 5
trigger4 = inguarddist
trigger5 = p2statetype != A && p2movetype != H
trigger5 = p2bodydist x <= 30
trigger5 = random <= 200
value = 101


[State 100, 4]
type = ChangeState
triggerall = var(59)
triggerall = time >= 15
triggerall = !var(30)
trigger1 = time >= 50
trigger2 = inguarddist
trigger3 = p2bodydist x <= 5
value = 101
;---------------------------------------------------------------------------
; RUN_FWD
[Statedef 101]
type    = S
physics = N
sprpriority = 1
ctrl = 0

[state 101]
type = ctrlset
trigger1 = time = 1
value = 1

[state 101]
type = changeanim
trigger1 = anim != 102 + var(30)
value = 102 + var(30)
ignorehitpause = 1

[state 102]
type = velset
trigger1 = vel x > 0
x = 0.97*vel x

[State 102, 1]
type = VelSet
trigger1 = vel x <= 1.2
x = 0

[State 102] ;Prevent run from canceling into walk
type = AssertSpecial
trigger1 = 1
flag = NoWalk
flag2 = nostandguard
flag3 = nocrouchguard

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

[State 100, 4]
type = ChangeState
trigger1 = animtime = 0
value = 0
ctrl = 1
;---------------------------------------------------------------------------
; RUN_BACK
[Statedef 105]
type    = A
physics = A
ctrl = 0
anim = 105 + var(30)
sprpriority = 1

[State 105]
type = AfterImage
trigger1 = time = 0
time = 999
TimeGap  = 1
FrameGap = 3
Trans = Add1
length = 12
PalBright   =   0,  0,  0
PalContrast = 128,128,128
PalAdd      =   0,  0,  0
PalMul      =  1,1,1

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

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

;---------------------------------------------------------------------------
; RUN_BACK2 (land)
[Statedef 106]
type    = S
physics = S
ctrl = 0
anim = 47 + var(30)


[State 107]
type = VelSet
trigger1 = Time = 0
x = 0

[State 107]
type = VelSet
trigger1 = Time = 0
y = 0

[State 107]
type = PosSet
trigger1 = Time = 0
y = 0

[State 107]
type = AfterImageTime
trigger1 = Time = 0
time = 0

[State 107]
type = PlaySnd
trigger1 = Time = 0
value = 47,0

[State 106, 3]
type = MakeDust
trigger1 = Time = 1
pos = -5,-2
spacing = 1

[State 107]
type = ChangeState
trigger1 = Animtime = 0
value = 0
ctrl = 1


;---------------------------------------------------------------------------
;空中前ダッシュ
[Statedef 110]
type    = A
movetype = I
physics = N
Velset = 0,0
ctrl = 0
anim = 110 + 2*var(30)

[state 110]
type = turn
trigger1 = time = 0
trigger1 = p2dist x < 0
trigger1 = prevstateno = 115

[state 110]
type = changestate
trigger1 = time = 0
trigger1 = p2dist x < 0
trigger1 = prevstateno != 115
value = 115

[state 110]
type = varset
trigger1 = time = 0
fvar(4) = 0.10
ignorehitpause = 1
persistent = 0

[State 110]
type = AfterImage
trigger1 = time = 0
time = 999
TimeGap  = 1
FrameGap = 3
Trans = Add1
length = 12
PalBright   =   0,  0,  0
PalContrast = 128,128,128
PalAdd      =   0,  0,  0
PalMul      =  1,1,1

[State 110]
type = velset
trigger1 = Time = 0
x = 4.3

[State 110]
type = varset
trigger1 = Time = 0
v = 10
value = 1

[State 110]
type = PlaySnd
trigger1 = Time%8=0
value = 200,0

[State 110]
type = ChangeState
triggerall = !var(59)
trigger1 = command != "holdfwd"
trigger1 = Time = 14
trigger2 = command != "holdfwd"
trigger2 = time >= 14
value = 111
ctrl = 1

[State 110]
type = ChangeState
triggerall = !var(59)
trigger1 = command = "holdfwd"
trigger1 = time = 40
value = 111
ctrl = 1

;--------
;for AI
[State 110];竹刀
type = ChangeState
triggerall = var(59)
triggerall = var(30) = 1 
triggerall = time >= 15
trigger1 = numtarget(1204)
trigger1 = p2bodydist x <= 30
trigger1 = fvar(34) > 90
trigger2 = numtarget(1204)
trigger2 = fvar(34) <= 130
trigger3 = numtarget(720)
trigger3 = fvar(34) <= 150
trigger3 = var(56) <= 19 || enemynear(var(31)),pos y+19*fvar(11)+0.5*361*fvar(38)>-5 - 5*var(42)||var(1)&&fvar(1) >0.95 &&p2bodydist y + 19*fvar(11) + 0.5*361*(fvar(38)-fvar(39))=[30,45]
trigger4 = numtarget(700)||numtarget(710)
trigger4 = var(56) <= 9 ||  p2bodydist y + 8*fvar(11) + 0.5*64*(fvar(38) - fvar(39)) > 35 || enemynear(var(31)),pos y + 8*fvar(11) +32*fvar(38)>=0
trigger5 = p2movetype != H || p2stateno = [120,155]
trigger5 = inguarddist || p2bodydist x < 60
value = 111
ctrl = 1

[State 110];素手
type = ChangeState
triggerall = var(59)
triggerall = var(30) = 0 
triggerall = time >= 15
trigger1 = numtarget(210)
trigger1 = fvar(1) >= 0.40
trigger2 = fvar(1) <= 0.60 || p2statetype = L || p2movetype != H
trigger2 = numhelper(1250)
trigger2 = abs(helper(1250),pos x - pos x) < 90
trigger2 = !var(43)
trigger3 = p2movetype!= H
trigger3 = inguarddist || p2bodydist x <= 45
value = 111
ctrl = 1

[State 110]
type = ChangeState
triggerall = var(59)
trigger1 = time >= 40
value = 111
ctrl = 1

;空中前ダッシュ後
[Statedef 111]
type    = A
movetype= I
physics = A
ctrl = 1
anim = 44 + var(30)

[state 111];軸が入れ替わってたら振り向く。
type = turn
trigger1 = time = 0
trigger1 = p2dist x<0

[State 111]
type = AfterImageTime
trigger1 = Time = 0
time = 0

[State 111]
type = null;Velset
trigger1 = time = 0
x = 4.7

[State 111];変更。
type = Veladd
trigger1 = time = 0
x = -0.5

[State 111]
type = PosSet
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
y = 0

[State 111]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 0
ctrl = 1

;---------------------------------------------------------------------------
;空中バックダッシュ
[Statedef 115]
type    = A
movetype = I
physics = N
Velset = 0,0
ctrl = 0
anim = 115 + 2*var(30)

[state 110]
type = turn
trigger1 = time = 0
trigger1 = p2dist x < 0
trigger1 = prevstateno = 110

[state 110]
type = changestate
trigger1 = time = 0
trigger1 = p2dist x < 0
trigger1 = prevstateno != 110
value = 110

[state 110]
type = varset
trigger1 = time = 0
fvar(4) = 0.10
ignorehitpause = 1
persistent = 0

[State 115]
type = AfterImage
trigger1 = time = 0
time = 999
TimeGap  = 1
FrameGap = 3
Trans = Add1
length = 12
PalBright   =   0,  0,  0
PalContrast = 128,128,128
PalAdd      =   0,  0,  0
PalMul      =  1,1,1

[State 115]
type = velset
trigger1 = Time = 0
x = -4; - 1.7*(palno = 7)

[State 115]
type = varset
trigger1 = Time = 0
v = 10
value = 1

[State 110]
type = PlaySnd
trigger1 = Time%12=0
value = 200,0

[State 115]
type = ChangeState
triggerall = !var(59)
trigger1 = command != "holdback"
trigger1 = Time = 15
trigger2 = command != "holdback"
trigger2 = time >= 15
value = 116

[State 115]
type = ChangeState
triggerall = var(59) = 0
trigger1 = command = "holdback"
trigger1 = time = 40
value = 116
ctrl = 1

[State 115]
type = ChangeState
value = 116
triggerall = var(59)
triggerall = time >= 15
triggerall = !var(30)
trigger1 = time >= 40
trigger2 = fvar(1) <= 0.60 || p2statetype = L || p2movetype != H
trigger2 = numhelper(1250)
trigger2 = abs(helper(1250),pos x - pos x) < 90

[State 115]
type = ChangeState
value = 116
triggerall = var(59)
triggerall = time >= 15
triggerall = var(30)
trigger1 = time >= 40
trigger2 = backedgebodydist < 30
trigger3 = p2bodydist x >= 120
trigger4 = inguarddist

;空中バックダッシュ後
[Statedef 116]
type    = A
movetype= I
physics = A
ctrl = 1
anim = 44 + var(30)

[State 116]
type = AfterImageTime
trigger1 = Time = 0
time = 0

[State 116]
type = Velset
trigger1 = time = 0
x = -3.5

[State 116]
type = PosSet
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
y = 0

[State 116]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; GUARD (start)
[Statedef 120]
type = U    ;Leave state type unchanged
physics = U ;Leave physics unchanged

[state 120,0-1]
type = varset
trigger1 = time = 0
var(13) = 0
ignorehitpause = 1
persistent = 0

[state 120,0-2]
type = varset
trigger1 = time = 0
trigger1 = prevstateno = [160,162]
var(13) = 1
ignorehitpause = 1
persistent = 0

[State 120, 1]
type = ChangeAnim
trigger1 = prevstateno != [160,162]
trigger1 = statetype != S
trigger1 = anim = 21+2*var(30) || time = 0
value = 120 + (statetype = C) + (statetype = A)*2 + 3*var(30)

[State 120, 1]
type = turn
trigger1 = prevstateno != [160,162]
trigger1 = statetype = S
trigger1 = p2dist x < 0

[State 120, 1]
type = ChangeAnim
trigger1 = prevstateno != [160,162]
trigger1 = statetype = S
trigger1 = anim != 21+2*var(30)
value = 21+2*var(30)

[State 20, 2]
type = VelSet
trigger1 = anim = 21+2*var(30)
x = const(velocity.walk.back.x)

[State 20, 2]
type = VelSet
trigger1 = anim != 21+2*var(30)
trigger1 = statetype != A
x = 0

[State 120, 2]
type = StateTypeSet
trigger1 = Time = 0 && statetype = S
physics = S

[State 120, 3]
type = StateTypeSet
trigger1 = Time = 0 && statetype = C
physics = C

[State 120, 4]
type = StateTypeSet
trigger1 = Time = 0 && statetype = A
physics = A


[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14 || enemynear(var(31)),statetype = C
trigger2 = p2stateno = var(53)
statetype = C
physics = C

[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype = S
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(11) != [3,8]
trigger2 = helper(40002),var(11) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%10 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%10)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) - var(45)%6
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = (helper(40002),var(10) = [6,8]) && helper(40002),var(13) != [6,8]
trigger2 = helper(40002),var(11) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%7 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%7)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 120, 5]
type = ChangeState
trigger1 = prevstateno != [160,162]
trigger1 = anim != 21+2*var(30)
trigger1 = AnimTime = 0
value = 130 + (statetype = C) + (statetype = A)*2

[State 120, Stop Guarding]
type = ChangeState
triggerall = prevstateno != [160,162]
triggerall = anim != 21+2*var(30)
trigger1 = command != "holdback"
trigger1 = var(59)<=0
trigger2 = !inguarddist
value = 140

[State 120, Stop Guarding]
type = ChangeState
triggerall = prevstateno != [160,162]
triggerall = anim = 21+2*var(30)
triggerall = var(59) = 0
trigger1 = command != "holdback"
trigger2 = !inguarddist
value = 0
ctrl = 1

[State 120, Stop Guarding]
type = ChangeState
triggerall = prevstateno != [160,162]
triggerall = anim = 21+2*var(30)
triggerall = var(59)
triggerall = !inguarddist
trigger1 = numhelper(40001) && numhelper(40002)
trigger1 =helper(40001),iNguarddist=0&&helper(40002),inguarddist=0
trigger1 = helper(40002),var(0) = 0
trigger1 = random <= 100
trigger2 = var(47)
trigger2 = p2dist x < 0
trigger2 = random <= 500
value = 22
ctrl = 1
;---------------------------------------------------------------------------
;リコイル後硬直
[state 120]
type = Nothitby
trigger1 = prevstateno = [160,162]
value = ,AT

[state 120]
type = changestate
triggerall = prevstateno = [160,162]
trigger1 = time >= 20 + 2*((statetype = A) + (statetype = C))
value = 130 + (statetype = C) + (statetype = A)*2
ctrl = 1
;---------------------------------------------------------------------------
; STAND GUARD (guarding)
[Statedef 130]
type    = S
physics = S

[State 130, 1]
type = ChangeAnim
trigger1 = Anim != 130 + 3*var(30)
value = 130 + 3*var(30)

[State 130, Hi to Lo]
type = ChangeState
triggerall=var(59)<=0
trigger1 = command = "holddown"
value = 131

[State -1, Hi to Lo for AI]
type = ChangeState
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
triggerall = time > 0
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
value = 131

[State -1, Hi to Lo for AI];AI用ステート
type = changestate
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(11) != [3,8]
trigger2 = helper(40002),var(11) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%7 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%7)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
value = 131

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 130, Stop Guarding]
type = ChangeState
trigger1 = !var(59)
trigger1 = command != "holdback"
trigger2 = !inguarddist
value = 140

;---------------------------------------------------------------------------
; CROUCH GUARD (guarding)
[Statedef 131]
type    = C
physics = C

[State 131, 1]
type = ChangeAnim
trigger1 = Anim != 131 + 3*var(30)
value = 131 + 3*var(30)

[State 131, Lo to Hi]
type = ChangeState
triggerall=var(59)<=0
trigger1 = command != "holddown"
value = 130

[State -1, Lo to Hi for AI]
type = ChangeState
value = 130
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
triggerall = time > 0
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2

[State -1, Lo to Hi for AI];AI用ステート
type = changestate
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = (helper(40002),var(10) = [6,8])&& helper(40002),var(13) != [6,8]
trigger1 = prevstateno != 130 || time > 0
trigger2 = helper(40002),var(11) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%7 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%7)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
value = 130

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 131, Stop Guarding]
type = ChangeState
trigger1 = !var(59)
trigger1 = command != "holdback"
trigger2 = !inguarddist
value = 140

;---------------------------------------------------------------------------
; AIR GUARD (guarding)
[Statedef 132]
type    = A
physics = N

[State 132, 1]
type = ChangeAnim
trigger1 = Anim != 132 + 3*var(30)
value = 132 + 3*var(30)

[State 132, 2]
type = VelAdd
trigger1 = 1
y = Const(movement.yaccel)

[State 132, 3]
type = VarSet
trigger1 = 1
sysvar(0) = (pos y >= 0) && (vel y > 0)

[State 132, 4]
type = VelSet
trigger1 = sysvar(0)
y = 0

[State 132, 5]
type = PosSet
trigger1 = sysvar(0)
y = 0

[State 132, 6]
type = ChangeState
trigger1 = sysvar(0)
trigger1 = command = "holdback"
trigger1 = inguarddist
value = 130

[State 132, 7]
type = ChangeState
trigger1 = sysvar(0)
value = 52

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 132, Stop Guarding]
type = ChangeState
trigger1 = !var(59)
trigger1 = command != "holdback"
trigger2 = !inguarddist
value = 140

;---------------------------------------------------------------------------
; GUARD (end)
[Statedef 140]
type = U    ;Leave state type unchanged
physics = U ;Leave physics unchanged
ctrl = 1

[State 140, 1]
type = ChangeAnim
trigger1 = Time = 0
value = 140 + (statetype = C) + (statetype = A)*2 + 3*var(30)

[State 140, 2]
type = StateTypeSet
trigger1 = Time = 0 && statetype = S
physics = S

[State 140, 3]
type = StateTypeSet
trigger1 = Time = 0 && statetype = C
physics = C

[State 140, 4]
type = StateTypeSet
trigger1 = Time = 0 && statetype = A
physics = A

[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
statetype = C
physics = C


[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(12) != [3,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) + 5 - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C

[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = helper(40002),var(10) = [6,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) +5 - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

;[State 140, 5] ;Implemented within engine
;type = ChangeState
;trigger1 = AnimTime = 0
;value = (statetype = C)*11 + (statetype = A)*51

;---------------------------------------------------------------------------
; SGUARDHIT (shaking)
[Statedef 150]
type    = S
movetype= H
physics = N
velset = 0,0

[state 150,0]
type = nothitby
trigger1 = !hitover
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 150, 1]
type = ChangeAnim
trigger1 = 1
value = 150 + 3*var(30)

[State 150, 2]
type = ChangeState
trigger1 = HitShakeOver
value = 151 + 2*(command = "holddown")*(var(59)=0) + 2*(var(59) !=0)*(p2statetype != A)

[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
statetype = C
physics = C


[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(12) != [3,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) + 5 - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C

[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = helper(40002),var(10) = [6,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) +5 - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 150, 3]
type = ForceFeedback
trigger1 = time = 0
waveform = square
time = 3

;---------------------------------------------------------------------------
; SGUARDHIT2 (knocked back)
[Statedef 151]
type    = S
movetype= H
physics = S
anim = 150 + 3*var(30)

[state 150,0]
type = nothitby
trigger1 = !HitOver
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 151, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1

[State 151, 2]
type = VelSet
trigger1 = Time = GetHitVar(slidetime)
trigger2 = HitOver
x = 0

[State 151, 3]
type = CtrlSet
trigger1 = Time = GetHitVar(ctrltime)
value = 1

[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(12) != [3,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) + 5 - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C


[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = helper(40002),var(10) = [6,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) +5 - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 151, 4]
type = ChangeState
trigger1 = HitOver
value = 130
ctrl = 1

;---------------------------------------------------------------------------
; CGUARDHIT (shaking)
[Statedef 152]
type    = C
movetype= H
physics = N
velset = 0,0

[state 150,0]
type = nothitby
trigger1 = !HitOver
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 152, 1]
type = ChangeAnim
trigger1 = 1
value = 151 + 3*var(30)

[State 152, 3]
type = ChangeState
trigger1 = HitShakeOver
value = 151 + 2*(command = "holddown")*(var(59)=0) + 2*(var(59)!=0)

[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(12) != [3,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) + 5 - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C

[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = helper(40002),var(10) = [6,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) +5 - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[State 152, 4]
type = ForceFeedback
trigger1 = time = 0
waveform = square
time = 4

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

;---------------------------------------------------------------------------
; CGUARDHIT2 (knocked back)
[Statedef 153]
type    = C
movetype= H
physics = C
anim = 151 + 3*var(30)

[state 150,0]
type = nothitby
trigger1 = !HitOver
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 153, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1

[State 153, 2]
type = VelSet
trigger1 = Time = GetHitVar(slidetime)
trigger2 = HitOver
x = 0

[State 153, 3]
type = CtrlSet
trigger1 = Time = GetHitVar(ctrltime)
value = 1

[State 120, Hi to Lo]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = S && command = "holddown"
statetype = C
physics = C

[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = var(59)>=4 || enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(54)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype != A
trigger1 = enemynear(var(31)),movetype = A
trigger1 = enemynear(var(31)),time < 14
trigger2 = p2stateno = var(53)
statetype = C
physics = C


[State -1, Hi to Lo for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(54)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) != [11,20]
trigger1 = helper(40002),var(12) != [3,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time <= ifelse(ceil(60*fvar(31)) + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(53)
trigger3 = enemynear,time >= 60*fvar(31) + 5 - var(45)%10
trigger4 = p2statetype = C || p2statetype = L || p2statetype =S && enemynear,time <= 14
trigger4 = var(45) <= 10
statetype = C
physics = C

[State 120, Lo to Hi]
type = StateTypeSet
triggerall=var(59)<=0
trigger1 = statetype = C && command != "holddown"
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall=var(59)>=1
triggerall=statetype!=A
triggerall= var(59)>=4|| enemynear(var(31)),statetype != A && random <= 250*var(59) || random <= 64*var(59)**3
triggerall = p2stateno != var(53)
triggerall = !var(47)
trigger1 = enemynear(var(31)),statetype = A
trigger2 = enemynear(var(31)),statetype != A
trigger2 = enemynear(var(31)),time >= 14 
trigger3 = p2stateno = var(54)
trigger3 = var(59) >= 4 || random <= 20*var(59)**2
statetype = S
physics = S

[State -1, Lo to Hi for AI];AI用ステート
type = StateTypeSet
triggerall = var(59)>=1
triggerall = statetype!=A
triggerall = p2stateno != var(53)
triggerall = var(47)
triggerall = numhelper(40002)
triggerall = var(45) > 10
trigger1 = helper(40002),var(10) = [6,8]
trigger2 = helper(40002),var(12) = [3,5]
trigger2 = enemynear,time > ifelse(ceil(60*fvar(31))  + var(45)%11 < 16 ,16 ,ceil(60*fvar(31)) + var(45)%11)
trigger3 = p2stateno = var(54)
trigger3 = enemynear,time >= 60*fvar(31) +5 - var(45)%10
trigger4 = p2statetype = A || p2statetype = S && enemynear,time > 14
trigger4 = var(45) = [11,20]
statetype = S
physics = S

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 153, 4]
type = ChangeState
trigger1 = HitOver
value = 131
ctrl = 1

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

[state 150,0]
type = nothitby
trigger1 = !HitOver
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 154, 1]
type = ChangeAnim
trigger1 = 1
value = 152 + 3*var(30)

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 154, 2]
type = ChangeState
trigger1 = HitShakeOver
value = 155 ;AGUARDHIT2

[State 154, 3]
type = ForceFeedback
trigger1 = time = 0
waveform = square
time = 4

;---------------------------------------------------------------------------
; AGUARDHIT2 (knocked away)
[Statedef 155]
type    = A
movetype= H
physics = N
anim = 152 + 3*var(30)

[state 150,0]
type = nothitby
trigger1 = !HitOver
trigger2 = !HitShakeOver
value = ,NT,ST,HT
time = 7

[State 155, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1
y = 1

[State 155, 2]
type = VelAdd
trigger1 = 1
y = Const(movement.yaccel)

[State 155, 3]
type = CtrlSet
trigger1 = Time = GetHitVar(ctrltime)
value = 1

[State 155, 4]
type = VarSet
trigger1 = 1
sysvar(0) = (pos y >= 0) && (vel y > 0)

[State 155, 5]
type = VelSet
trigger1 = sysvar(0)
y = 0

[State 155, 6]
type = PosSet
trigger1 = sysvar(0)
y = 0

[state -3]
type = varset
trigger1 = time = 0
trigger2 = statetype = A
var(55)=0

[state -3]
type = varset
trigger1 = var(59)>0
var(55) = (statetype = S) + 2*(statetype = C)

[State 155, 6]
type = ChangeState
trigger1 = sysvar(0)
trigger1 = command = "holdback" || var(59)
trigger1 = inguarddist
value = 130

[State 155, 7]
type = ChangeState
trigger1 = sysvar(0)
value = 52

;---------------------------------------------------------------------------
; LOSE (Time over)
[Statedef 170]
type = S
ctrl = 0
anim = 170
velset = 0,0

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

;---------------------------------------------------------------------------
; DRAWGAME (Time over)
[Statedef 175]
type = S
ctrl = 0
velset = 0,0

[State 175, 1] ; If no anim, use go to lose state.
type = ChangeState
trigger1 = Time = 0
trigger1 = !SelfAnimExist(175)
value = 170

[State 175, 2]
type = ChangeAnim
trigger1 = Time = 0
value = 175

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




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

[state 5000,0]
type = changestate
trigger1 = var(20)
trigger1 = life > 0
trigger1 = alive
trigger1 = time = 0
trigger1 = prevstateno != [5000,5900]
value = 6000
ignorehitpause = 1

[state 5000,0.5]
type = velset
trigger1 = time = 0
x= 0
y= 0
ignorehitpause = 1

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

[State 5000, 2] ;Anim for HIT_BACK
type = ChangeAnim
trigger1 = Time = 0
trigger1 = GetHitVar(animtype) = [3,5]
value = 5030 + 10000*var(30)

[State 5000, 3] ;Anim for HIT_UP/HIT_DIAGUP (only if it exists)
type = ChangeAnim
trigger1 = Time = 0
trigger1 = (GetHitVar(animtype) = [4,5]) && (SelfAnimExist(5047  + 10000*var(30) + GetHitVar(animtype)))
value = 5047 + GetHitVar(animtype)  + 10000*var(30);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 = GetHitVar(yvel) != 0 || GetHitVar(fall)
trigger2 = Pos Y != 0
statetype = a

[State 5000, 6]
type = ChangeState
trigger1 = HitShakeOver
trigger1 = GetHitVar(yvel) = 0 && !GetHitVar(fall)
value = 5001;HITG_SLIDE

[State 5000, 7]
type = ChangeState
trigger1 = HitShakeOver
value = 5030

[State 5000, FFB Light]
type = ForceFeedback
trigger1 = anim = 5000 + 10000*var(30)
trigger2 = anim = 5010 + 10000*var(30)
persistent = 0
time = 6
waveform = square

[State 5000, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5001 + 10000*var(30)
trigger2 = anim = 5011 + 10000*var(30)
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5000, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5012 + 10000*var(30)
trigger2 = anim = 5002 + 10000*var(30)
trigger3 = anim = 5030 + 10000*var(30)
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

;---------------------------------------------------------------------------
; HITG_SLIDE
[Statedef 5001]
type    = S
movetype= H
physics = S

[State 5001, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1

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

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

[State 5001, 4]
type = VelSet
trigger1 = HitOver
x = 0

[State 5001, 5]
type = DefenceMulSet
trigger1 = HitOver
value = 1

[State 5001, 6]
type = ChangeState
trigger1 = HitOver
value = 0
ctrl = 1

;---------------------------------------------------------------------------
; HITC_SHAKE
[Statedef 5010]
type    = C
movetype= H
physics = N

[state 5000,0]
type = changestate
trigger1 = var(20)
trigger1 = life > 0
trigger1 = alive
trigger1 = time = 0
trigger1 = prevstateno != [5000,5900]
value = 6000
ignorehitpause = 1
[state 5000,0.5]
type = velset
trigger1 = time = 0
x= 0
y= 0
ignorehitpause = 1


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

[State 5010, 2] ;Anim for HIT_BACK
type = ChangeAnim
trigger1 = Time = 0
trigger1 = GetHitVar(animtype) = [3,5]
value = 5030 + 10000*var(30)

[State 5010, 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) + 10000*var(30)))
value = 5047 + GetHitVar(animtype) + 10000*var(30) ;5051 - 4 + type

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

[State 5010, 5] ;State type gets set to aerial if getting hit up
type = StateTypeSet
triggerall = Time = 0
trigger1 = GetHitVar(yvel) != 0 || GetHitVar(fall)
trigger2 = Pos Y != 0
statetype = a

[State 5010, 6]
type = ChangeState
trigger1 = HitShakeOver
trigger1 = GetHitVar(yvel) = 0 && !GetHitVar(fall)
value = 5011 ;HITC_SLIDE

[State 5010, 7]
type = ChangeState
trigger1 = HitShakeOver
value = 5030

[State 5010, FFB Light]
type = ForceFeedback
trigger1 = anim = 5020 + 10000*var(30)
persistent = 0
time = 6
waveform = square

[State 5010, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5021 + 10000*var(30)
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5010, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5022 + 10000*var(30)
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

;---------------------------------------------------------------------------
; HITC_SLIDE
[Statedef 5011]
type    = C
movetype= H
physics = C

[State 5011, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1

[State 5011, 2]
type = ChangeAnim
trigger1 = AnimTime = 0
value = 5025 + GetHitVar(animtype) + 10000*var(30)

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

[State 5011, 4]
type = VelSet
trigger1 = HitOver
x = 0

[State 5011, 5]
type = DefenceMulSet
trigger1 = HitOver
value = 1

[State 5011, 6]
type = ChangeState
trigger1 = HitOver
value = 11
ctrl = 1


;---------------------------------------------------------------------------
; HITA_SHAKE
[Statedef 5020]
type    = A
movetype= H
physics = N

[state 5000,0]
type = changestate
trigger1 = var(20)
trigger1 = life > 0
trigger1 = alive
trigger1 = time = 0
trigger1 = prevstateno != [5000,5900]
value = 6000
ignorehitpause = 1

[state 5000,0.5]
type = velset
trigger1 = time = 0
x= 0
y= 0
ignorehitpause = 1

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

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

[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) + 10000*var(30)))
value = 5047 + GetHitVar(animtype) + 10000*var(30) ;5051 - 4 + type

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

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

[State 5020, FFB Light]
type = ForceFeedback
trigger1 = anim = 5000 + 10000*var(30)
trigger2 = anim = 5010 + 10000*var(30)
persistent = 0
time = 6
waveform = square

[State 5020, FFB Medium]
type = ForceFeedback
trigger1 = anim = 5001 + 10000*var(30)
trigger2 = anim = 5011 + 10000*var(30)
persistent = 0
time = 8
waveform = sinesquare
ampl = 110,-1,-.3

[State 5020, FFB Hard]
type = ForceFeedback
trigger1 = anim = 5012 + 10000*var(30)
trigger2 = anim = 5002 + 10000*var(30)
trigger3 = anim = 5030 + 10000*var(30)
trigger4 = anim  - 10000*var(30)= [5051,5059]
persistent = 0
time = 15
waveform = sinesquare
ampl = 140

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

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

[State 5030, 2]
type = HitVelSet
trigger1 = Time = 0
x = 1
y = 1

[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+ 10000*var(30))
trigger1 = Anim - 10000*var(30)!= [5051,5059] ;Not if in hit up anim
trigger1 = Anim - 10000*var(30)!= 5090 ;Not if hit off ground anim
value = 5035 + 10000*var(30)

[State 5035, 2]
type = VelAdd
trigger1 = 1
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  + 10000*var(30);.
value = 5040

[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 + 10000*var(30) ;.
value = 5050

;---------------------------------------------------------------------------
; 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 + 10000*var(30)
trigger2 = Time = 0
trigger2 = Anim != 5035 + 10000*var(30)
value = 5040 + 10000*var(30)

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

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

[State 5040, 5]
type = VelAdd
trigger1 = 1
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+ 10000*var(30)
trigger2 = Time = 0     ;If no transition anim
trigger2 = Anim != 5035+ 10000*var(30)
trigger2 = (Anim - 10000*var(30) != [5051, 5059]) && (Anim - 10000*var(30) != [5061, 5069])
trigger2 = Anim != 5090+ 10000*var(30) ;Not if hit off ground anim
value = 5050 + 10000*var(30)

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

[State 5050, 3] ;Gravity
type = VelAdd
trigger1 = 1
y = GetHitVar(yaccel)

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

[State 5050, 5]; Recover in mid air
type = ChangeState
triggerall = Vel Y > -1
triggerall = alive
triggerall = CanRecover
triggerall = !var(59)
trigger1 = Command = "recovery"
value = 5210 ;HITFALL_AIRRECOVER

[State 5050, 6]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= ifelse((anim - 10000*var(30) = [5051,5059]) || (anim - 10000*var(30) = [5061,5069]), 0, 25)
value = 5100 ;HIT_BOUNCE

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

[state 5000,0]
type = changestate
trigger1 = var(20)
trigger1 = life > 0
trigger1 = alive
trigger1 = time = 0
trigger1 = prevstateno != [5000,5900]
value = 6000
ignorehitpause = 1

[state 5000,0.5]
type = velset
trigger1 = time = 0
x= 0
y= 0
ignorehitpause = 1

[State 5070, 1]
type = ChangeAnim 
trigger1 = 1
value = 5070 + 10000*var(30)

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

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

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

[State 5071, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1
y = 1

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

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

;---------------------------------------------------------------------------
; HITL_SHAKE
[Statedef 5080]
type    = L
movetype= H
physics = N
velset = 0,0

[State 5080, 1] ;Set default anim
type = VarSet
trigger1 = time = 0
sysvar(2) = ifelse (GetHitVar(yvel) = 0, 5080+ 10000*var(30), 5090+ 10000*var(30))

[State 5080, 2]
type = VarAdd
trigger1 = time = 0
trigger1 = (anim  - 10000*var(30)= [5081,5089]) || (anim - 10000*var(30) = [5111,5119])
trigger1 = SelfAnimExist(sysvar(2) + (anim % 10))
sysvar(2) = anim % 10

[State 5080, 3] ;If 5090 doesn't exist, default to 5030
type = VarSet
trigger1 = time = 0
trigger1 = sysvar(2) = 5090 + 10000*var(30)
trigger1 = !SelfAnimExist(5090 + 10000*var(30))
sysvar(2) = 5030 + 10000*var(30)

[State 5080, 3] ;Freeze
type = ChangeAnim
trigger1 = 1
value = sysvar(2)

[State 5080, 4]
type = ChangeState
trigger1 = HitShakeOver
trigger1 = GetHitVar(yvel) = 0
value = 5081 ;HITL_SLIDE

[State 5080, 5]
type = ChangeState
trigger1 = HitShakeOver
trigger1 = GetHitVar(yvel) != 0
value = 5030 ;HITA_UP

;---------------------------------------------------------------------------
; HITL_SLIDE
[Statedef 5081]
type    = L
movetype= H
physics = C

[State 5081, 1]
type = HitVelSet
trigger1 = Time = 0
x = 1

[State 5081, 2]
type = VelSet
trigger1 = HitOver
x = 0

[State 5081, 3] ;Don't show hit ground frame
type = VarSet
trigger1 = Time = 0
sysvar(0) = 1

[State 5081, 4]
type = ChangeState
trigger1 = HitOver
value = 5110 ;HIT_LIEDOWN

;---------------------------------------------------------------------------
; 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  - 10000*var(30)!= [5051,5059]) && (anim  - 10000*var(30)!= [5061,5069])
trigger2 = !SelfAnimExist(5100 + 10000*var(30) + (anim % 10))
value = 5100 + 10000*var(30)

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

[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]
type = PlaySnd
trigger1 = Time = 0
trigger1 = !SysVar(0)
value = S5100,0

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

[State 5100]
type = Explod
trigger1 = Time = 1
anim = 7004
id = 7004
postype = p1
pos = 0, 0
bindtime = 1
ownpal = 1
sprpriority = -1
under = sysvar(1) <= 10
supermove = 1
ignorehitpause = 1
pausemovetime = 20
supermovetime = 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_BOUNCE (bounce into air)
[Statedef 5101]
type    = L
movetype= H
physics = N

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

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

[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
[Statedef 5110]
type    = L
movetype= H
physics = N

[State 5110, Envshake]
type = envshake
Trigger1 = time = 0
time = 10
ampl = -3
freq = 110

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

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

[State 5110, 3] ;Hit ground anim (for hit up)
type = ChangeAnim
triggerall = time = 0
triggerall = anim  - 10000*var(30)!= [5110,5119] ;Not already changed anim
trigger1 = anim  - 10000*var(30)= [5161,5169]
trigger1 = SelfAnimExist(5170 + (anim % 10)+ 10000*var(30))
value = 5170  + 10000*var(30) + (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, 8]
type = VelSet
trigger1 = Time = 0
y = 0

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

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

[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  - 10000*var(30)= [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

;---------------------------------------------------------------------------
; HIT_GETUP
[Statedef 5120]
type    = L
movetype= I
physics = N

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

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

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

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

[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 = 6

[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
[Statedef 5150]
type    = L
movetype= H
physics = N
sprpriority = -3

[State 5150, 1] ;Normal anim
type = ChangeAnim
triggerall = Time = 0
triggerall = SelfAnimExist(5140 + 10000*var(30))
trigger1 = (anim  - 10000*var(30)!= [5111,5119]) && (anim - 10000*var(30) != [5171,5179])
trigger2 = !SelfAnimExist(5140 + (anim % 10) + 10000*var(30))
value = 5140 + 10000*var(30)

[State 5150, 3] ;Hit up type anim
type = ChangeAnim
trigger1 = Time = 0
trigger1 = (anim  - 10000*var(30)= [5111,5119]) || (anim  - 10000*var(30)= [5171,5179])
trigger1 = SelfAnimExist(5140 + (anim % 10) + 10000*var(30))
value = 5140 + (anim % 10) + 10000*var(30)

[State 5150, 4] ;Match over anim
type = ChangeAnim
persistent = 0
;trigger1 = Time = 0
trigger1 = MatchOver = 1
trigger1 = Anim  - 10000*var(30) = [5140,5149]
trigger1 = SelfAnimExist(anim+10)
value = anim+10

[State 5150, 5] ;Switch to 5110 if liedead anim does not exist
type = ChangeAnim
trigger1 = Time = 0
trigger1 = Anim  - 10000*var(30)!= [5140,5159]
trigger1 = Anim  - 10000*var(30)!= [5110,5119]
value = 5110 + 10000*var(30)

[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_FALLRECOVER (still falling)
[Statedef 5200]
type    = A
movetype= H
physics = N

[State 5200, 1] ;Change anim if done with transition
type = ChangeAnim
trigger1 = Anim = 5035 + 10000*var(30)
trigger1 = AnimTime = 0
value = 5050 + 10000*var(30)

[State 5200, 2]
type = VelAdd
trigger1 = 1
y = GetHitVar(yaccel)

[State 5200, 3]
type = SelfState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 10
value = 5201

;---------------------------------------------------------------------------
; HIT_FALLRECOVER (on the ground)
[Statedef 5201]
type    = A
movetype= H
physics = A
anim = 5200 + 10000*var(30)

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

[State 5201, 2]
type = VelSet
trigger1 = Time = 0
x = -.15
y = -3.5

[State 5201, 3]
type = PosSet
trigger1 = Time = 0
y = 0

[State 5201]
type = Explod
trigger1 = time = 1
anim = 7018
scale = 1,1
postype = p1
pos = 0,0
sprpriority = 4
supermove = 0
ownpal = 1

[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 ;256,256,256

[State 5201, 6]
type = GameMakeAnim
trigger1 = Time = 1
value = 60
pos = 0, 0
under = 1

;---------------------------------------------------------------------------
; HIT_AIRFALLRECOVER
[Statedef 5210]
type    = A
movetype= I
physics = N
anim = 5210 + 10000*var(30)
ctrl = 0

[State 5210, 1] ;Blink white
type = PalFX
trigger1 = Time = 0
time = 3
add = 128,128,128 ;256,256,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 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 = Command = "holdup"
y = -2

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

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

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

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

[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

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

[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, 1] ;Clear all int variables
type = VarRangeSet
trigger1 = roundsexisted = 0
value = 0

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

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






;_______________________________________________________________________________

;Common For AI

;21 walk fwd
;22 walk back
;41 Jump fwd
;42 Jump neu
;43 Jump back
;46 Air Jump fwd
;47 Air Jump neu
;48 Air Jump back
;_______________________________________________________________________________

; Walk Fwd
[Statedef 21]
type    = S
physics = S
sprpriority = 0

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

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

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

[State 20, 3]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x > 0
trigger1 = Anim != 22 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 22

[State 20, 4]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x < 0
trigger1 = Anim != 23 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 23

[state 20,5]
type = changestate
triggerall = var(30)
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = inguarddist && !var(25)
trigger4 = p2bodydist x = [56,65]
trigger4 = p2movetype != H
trigger4 = random <= 120
trigger5 = p2bodydist x <= 55
trigger5 = p2movetype != H && (p2statetype = L && var(47)) = 0
value = 0
ctrl = 1


[state 20,5]
type = changestate
triggerall = !var(30)
triggerall = enemynear,stateno != 5656
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = inguarddist && !var(25)
value = 0
ctrl = 1


[state 20,5]
type = changestate
triggerall = !var(30)
triggerall = enemynear,stateno = 5656
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = p2bodydist x + var(48)*facing*enemynear,facing*enemynear,vel x <= 3 + 20*(fvar(1) <= 0.8)
value = 0
ctrl = 1
;---------------------------------------------------------------------------
; Walk Back
[Statedef 22]
type    = S
physics = S
sprpriority = 0

[State 20, 2]
type = VelSet
trigger1 = 1
x = const(velocity.walk.back.x)

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

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

[State 20, 3]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x > 0
trigger1 = Anim != 22 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 22

[State 20, 4]
type = ChangeAnim
triggerall = var(30) = 1
triggerall = vel x < 0
trigger1 = Anim != 23 && Anim != 5
trigger2 = Anim = 5 && AnimTime = 0
value = 23

[state 20,5]
type = changestate
triggerall = var(30)
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = random <= 45
trigger4 = inguarddist && !var(25)
value = 0 + 120*inguarddist
ctrl = 1

[state 20,5]
type = changestate
triggerall = !var(30)
triggerall = enemynear,stateno != 5656
triggerall = numhelper(1250)
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = inguarddist && !var(25)
trigger4 = random <= 45
trigger4 = enemynear(var(31)),statetype != L || abs(helper(1250),pos x - pos x) > 160
value = 0
ctrl = 1

[state 20,5]
type = changestate
triggerall = !var(30)
triggerall = enemynear,stateno = 5656
trigger1 = roundstate != 2
trigger2 = p2dist x < 0
trigger3 = p2bodydist x + var(48)*facing*enemynear,facing*enemynear,vel x > 3 + 20*(fvar(1)<=0.80)
value = 0
ctrl = 1
;---------------------------------------------------------------------------
; Jump Start Fwd
[Statedef 41]
type    = S
physics = S
anim = 39 + var(1)
ctrl = 0
sprpriority = 1

[state 40,0]
type = statetypeset
trigger1 = time >= 2
statetype = A

[State 40, 4]
type = VelSet
trigger1 = AnimTime = 0
x = const(velocity.jump.fwd.x)
y = const(velocity.jump.y)

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

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

;---------------------------------------------------------------------------
; Jump Start Neu
[Statedef 42]
type    = S
physics = S
anim = 39 + var(1)
ctrl = 0
sprpriority = 1

[state 40,0]
type = statetypeset
trigger1 = time >= 2
statetype = A

[State 40, 4]
type = VelSet
trigger1 = AnimTime = 0
x = const(velocity.jump.neu.x)
y = const(velocity.jump.y)

[State 40, 5]
type = VelSet
trigger1 = AnimTime = 0
trigger1 = prevstateno = [100,101]
x = 1.5

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

;---------------------------------------------------------------------------
; Jump Start Back
[Statedef 43]
type    = S
physics = S
anim = 39 + var(1)
ctrl = 0
sprpriority = 1

[state 40,0]
type = statetypeset
trigger1 = time >= 2
statetype = A

[State 40, 4]
type = VelSet
trigger1 = AnimTime = 0
x = const(velocity.jump.back.x)
y = const(velocity.jump.y)

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

;---------------------------------------------------------------------------
; AirJump Start Fwd
[Statedef 46]
type    = A
physics = N
ctrl = 0
velset = 0,0

[state 45]
type = assertspecial
trigger1 = 1
flag = noautoturn

[State 45, 1]
type = ChangeAnim
trigger1 = SelfAnimExist(44)
value = 44

[State 45, 2]
type = ChangeAnim
trigger1 = !SelfAnimExist(44)
value = 41

[state 45]
type = varset
trigger1 = time = 0
var(1) = 1
ignorehitpause = 1

[State 45, 6]
type = VelSet
trigger1 = Time = 2
x = const(velocity.airjump.fwd.x)
y = const(velocity.airjump.y)

[State 45, 7]
type = ChangeState
trigger1 = Time = 2
value = 50
ctrl = 1

;---------------------------------------------------------------------------
; AirJump Start Neu
[Statedef 47]
type    = A
physics = N
ctrl = 0
velset = 0,0

[state 45]
type = assertspecial
trigger1 = 1
flag = noautoturn

[State 45, 1]
type = ChangeAnim
trigger1 = SelfAnimExist(44)
value = 44

[State 45, 2]
type = ChangeAnim
trigger1 = !SelfAnimExist(44)
value = 41

[state 45]
type = varset
trigger1 = time = 0
var(1) = 1
ignorehitpause = 1

[State 45, 6]
type = VelSet
trigger1 = Time = 2
x = const(velocity.airjump.neu.x)
y = const(velocity.airjump.y)

[State 45, 7]
type = ChangeState
trigger1 = Time = 2
value = 50
ctrl = 1

;---------------------------------------------------------------------------
; AirJump Start Back
[Statedef 48]
type    = A
physics = N
ctrl = 0
velset = 0,0

[state 45]
type = assertspecial
trigger1 = 1
flag = noautoturn

[State 45, 1]
type = ChangeAnim
trigger1 = SelfAnimExist(44)
value = 44

[State 45, 2]
type = ChangeAnim
trigger1 = !SelfAnimExist(44)
value = 41

[state 45]
type = varset
trigger1 = time = 0
var(1) = 1
ignorehitpause = 1

[State 45, 6]
type = VelSet
trigger1 = Time = 2
x = const(velocity.airjump.back.x)
y = const(velocity.airjump.y)

[State 45, 7]
type = ChangeState
trigger1 = Time = 2
value = 50
ctrl = 1