;--------------------------------------------------------------------------
; Override common states (use same number to override) :
;---------------------------------------------------------------------------


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

[State 20, 1]
type = VelSet
trigger1 = command = "holdfwd" && var(1) != 1
trigger2 = var(2) = 1 && var(1) = 1
x = const(velocity.walk.fwd.x)

[State 20, 2]
type = VelSet
trigger1 = command = "holdback" && var(1) != 1
trigger2 = var(2) = -1 && var(1) = 1
x = const(velocity.walk.back.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


; RBO characters have their own forward running that is a hop
; Override RunForward for HopForward (stolen from Kung Fu Girl and castrated)
;---------------------------------------------------------------------------
; Run Forward
[Statedef 100]
type    = A
movetype = I
physics = A
ctrl = 0
anim = 100

[state 100, yaccel]
type = varset
trigger1 = time = 0
trigger1 = var(3) = 0
fv = 1
value = 0.36

[state 100, 1]
type = velset
trigger1 = time = 0
x = const(velocity.run.fwd.x)
y = const(velocity.run.fwd.y)

[state 100, gravity]
type = veladd
trigger1 = fvar(1) != 0
y = fvar(1) - const(movement.yaccel)
persistent = 1

[State 100, Land]
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 52


;---------------------------------------------------------------------------
;Air dash forward
[statedef 102]
type    = A
movetype = I
physics = A
ctrl = 0
anim = 100
velset = 12.0, 0
poweradd = -40

[State 102, Explod]
type = Explod
trigger1 = time = 0
anim = 10100
pos = 0,0
facing = 1
scale = Const(size.xscale),Const(size.yscale)
removetime = -2
sprpriority = 5
ownpal = 1

[state 102, sound]
type = playsnd
trigger1 = time = 0
value = 100,0

[state 102, gravity]
type = varset
trigger1 = time = 0
var(3) = 1

[state 107, resetgravity]
type = varset
trigger1 = time = 0
fv = 1
value = 0

[state 102, change]
type = changestate
trigger1 = time = 0
value = 100


;---------------------------------------------------------------------------
; Dash Back
[Statedef 105]
type    = A
movetype = I
physics = A
ctrl = 0
anim = 105
sprpriority = 1

[state 100, yaccel]
type = varset
trigger1 = time = 0
trigger1 = var(3) = 0
fv = 1
value = 0.36

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

[state 50, gravity]
type = veladd
trigger1 = fvar(1) != 0
y = fvar(1) - const(movement.yaccel)
persistent = 1

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



;---------------------------------------------------------------------------
; Hop backwards (land)
[Statedef 106]
type    = S
physics = S
ctrl = 0
anim = 47

[state 107, enablegravity]
type = varset
trigger1 = time = 0
var(3) = 0

[state 52, landsound]
type = playsnd
trigger1 = time = 0
value = 52,0

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

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

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

[State 106, 4]
type = VelSet
trigger1 = abs(vel x) < Const(movement.stand.friction.threshold)
x = 0

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



;---------------------------------------------------------------------------
;Airdash backward
[statedef 107]
type    = A
movetype = I
physics = A
ctrl = 0
anim = 105
velset = -12.0, 0
poweradd = -40

[State 107, Explod]
type = Explod
trigger1 = time = 0
anim = 10100
pos = 0,0
facing = -1
scale = Const(size.xscale),Const(size.yscale)
removetime = -2
sprpriority = 5
ownpal = 1

[state 107, disablegravity]
type = varset
trigger1 = time = 0
var(3) = 1

[state 107, sound]
type = playsnd
trigger1 = time = 0
value = 100,0

[state 107, resetgravity]
type = varset
trigger1 = time = 0
fv = 1
value = 0

[state 107, change]
type = changestate
trigger1 = time = 0
value = 105


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

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

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

[State 40, 3]
type = VarSet
trigger1 = command = "holdback" && var(1) != 1
trigger2 = var(2) = -1 && var(1) = 1
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 ;RUN_FWD
trigger1 = sysvar(1) = 1
x = const(velocity.runjump.fwd.x)

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

[State 40, 7]
type = ChangeAnim
trigger1 = command = "holdback" && var(1) != 1
trigger2 = var(2) = 1 && var(1) = 1
value = 48
persistent = 0


;-------------------------
; AirJump Start (Override to add a state to set var(3) to 1
[Statedef 45]
type    = A
physics = N
ctrl = 0
velset = 0,0

[State 45, N_phys]
type = varset
trigger1 = time = 0
fv = 1
value = 0

[State 45, OnlyOneAirJump]
type = ChangeState
trigger1 = var(3)
value = 50
ctrl = 1

[State 45, Explod]
type = Explod
trigger1 = time = 0
anim = 10045
ID = 60
pos = 0,0
postype = p1  ;p2,front,back,left,right
facing = 1
vfacing = 1
bindtime = 1
random = 0,0
removetime = -2
scale = Const(size.xscale),Const(size.yscale)
sprpriority = 0
ownpal = 1

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

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

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

[State 45, 4]
type = VarSet
trigger1 = command = "holdfwd" && var(1) != 1
trigger2 = var(2) = 1 && var(1) = 1
sysvar(1) = 1

[State 45, 5]
type = VarSet
trigger1 = command = "holdback" && var(1) != 1
trigger2 = var(2) = -1 && var(1) = 1
sysvar(1) = -1

[State 45, set_gravity]
type = VarSet
trigger1 = Time = 2
fv = 1
value = 1.2

[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 (Override to add gravity)
[Statedef 50]
type    = A
physics = A

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

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

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

[state 50, gravity]
type = veladd
trigger1 = fvar(1) != 0
y = fvar(1) - const(movement.yaccel)
persistent = 1


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

[State 106, 3]
type = MakeDust
trigger1 = Time = 0
pos = 0, 0
spacing = 1

[state 52, enablegravity]
type = varset
trigger1 = time = 0
var(3) = 0

[state 52, landsound]
type = playsnd
trigger1 = time = 0
value = 52,0

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

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

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

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



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

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

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

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

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

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

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

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

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

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

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

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

[State 5100, 10]
type = PlaySnd
trigger1 = Time = 1
value = 5100, 0;(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


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

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

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

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

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

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

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

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

[State 5110, 6]
type = PlaySnd
trigger1 = Time = 0
trigger1 = !SysVar(0)
value = 5100,0;F7, (sysvar(1) > 5) + (sysvar(1) > 14)

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

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

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

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

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

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

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

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

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




;---------------------------------------------------------
; STANDING Perfect Guard
[statedef 6510]
type    = S
movetype= H
physics = S
velset = 0, 0
ctrl = 0

[state 6510, PowerShieldHitTime]
type = varset
trigger1 = time = 0
var(25) = GetHitVar(hittime) / 2
ignorehitpause = 1

[state 6510, PowerShieldxvel]
type = varset
trigger1 = time = 0
fvar(6) = GetHitVar(xvel) / 4
ignorehitpause = 1

[state 6510, PowerShield]
type = changestate
trigger1 = time = 0
value = 6520
ignorehitpause = 1
;---------------------------------------------------------
; CROUCHING Perfect Guard
[statedef 6512]
type    = C
movetype= H
physics = C
velset = 0, 0
ctrl = 0

[state 6510, PowerShieldHitTime]
type = varset
trigger1 = time = 0
var(25) = GetHitVar(hittime) / 2
ignorehitpause = 1

[state 6510, PowerShieldxvel]
type = varset
trigger1 = time = 0
fvar(6) = GetHitVar(xvel) / 4
ignorehitpause = 1

[state 6510, PowerShield]
type = changestate
trigger1 = time = 0
value = 6522
ignorehitpause = 1
;---------------------------------------------------------
; STANDING perfect Guard STUN
[statedef 6520]
type    = S
movetype= H
physics = S
velset = fvar(6), 0
ctrl = 0

[State 6520, NotHitBy]
type = NotHitBy
trigger1 = 1
value = SCA,NT,ST,HT
time = 1
ignorehitpause = 1

[State 6520, HitOverride]
type = HitOverride
trigger1 = var(24) < 6
attr = SCA,NA,SA,HA,NP,SP,HP
slot = 0
stateno = 6510
time = 1
ignorehitpause = 1

[State 6520, PalFX]
type = PalFX
trigger1 = time = 0
time = 5
sinadd = 255,255,255,10
ignorehitpause = 1

[State 6520, PowerSheildSnd]
type = PlaySnd
trigger1 = time = 0
value = S1,1
ignorehitpause = 1

[State 6520, PowerShieldRegainLife]
type = LifeAdd
trigger1 = time = 0
value = GetHitVar(damage)
ignorehitpause = 1

[state 6520, end]
type = changestate
trigger1 = time > var(25)
value = 0
ctrl = 1
ignorehitpause = 1
;---------------------------------------------------------
; CROUCHING Perfect Guard STUN
[statedef 6522]
type    = C
movetype= H
physics = C
velset = fvar(6), 0
ctrl = 0

[State 6520, NotHitBy]
type = NotHitBy
trigger1 = 1
value = SCA,NT,ST,HT
time = 1
ignorehitpause = 1

[State 6520, HitOverride]
type = HitOverride
trigger1 = var(24) < 6
attr = SCA,NA,SA,HA,NP,SP,HP
slot = 0
stateno = 6510
time = 1
ignorehitpause = 1

[State 6520, PalFX]
type = PalFX
trigger1 = time = 0
time = 5
sinadd = 255,255,255,10
ignorehitpause = 1

[State 6520, PowerSheildSnd]
type = PlaySnd
trigger1 = time = 0
value = S1,1
ignorehitpause = 1

[State 6520, PowerShieldRegainLife]
type = LifeAdd
trigger1 = time = 0
value = GetHitVar(damage)
ignorehitpause = 1

[state 6520, end]
type = changestate
trigger1 = time > var(25)
value = 11
ctrl = 1

