;================================================================================
; kim Kaphwan, parte 5: Agarres, y "Esos detalles"
;================================================================================
;Agarre 1: Frankensteiner
[Statedef 800]
type = S
movetype = A
physics = S
anim = 800
poweradd = 50
velset = 0
ctrl = 0

[State 200, 2]
type = HitDef
trigger1 = AnimElem = 1
attr = S, NT
damage = 0
animtype = hard
hitflag = M, miss
sparkno = -1
guardflag = P
pausetime = 0,0
p1stateno = 810
p2stateno = 815

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

[Statedef 810]
type = S
physics = S
anim = 810
poweradd = 0
velset = 0
ctrl = 0
sprpriority = 2

[State 810, target]
type = targetbind
trigger1 = animelem = 1
pos = 50,0

[State 3005, width]
type = width
trigger1 = time = 0
edge = 50,50

[State 810, snd]
type = playsnd
trigger1 = animelem = 2
value = 8,0

[State 1100, 1]
type = Explod
trigger1 = AnimElem = 2
anim = 7013
ID = 800
postype = p1
pos = 45,-75
bindtime = 1
sprpriority = 2
ownpal = 1

[State 810, state]
type = changestate
trigger1 = animtime = 0
value = 811
ctrl = 1

[Statedef 811]
type = S
physics = S
anim = 811
poweradd = 0
velset = 0
ctrl = 0
sprpriority = 2

[State 811, bind]
type = Screenbound
trigger1 = 1
value = 0

[State 811, bind]
type = BindToTarget
trigger1 = 1
pos = 50,0,Head

[State 3005, width]
type = width
trigger1 = time = 0
edge = 50,50

[State 810, state]
type = changestate
trigger1 = animtime = 0
value = 812

[Statedef 812]
type = S
physics = S
anim = 812
poweradd = 0
velset = 0
ctrl = 0
sprpriority = 2

[State 810, snd]
type = playsnd
trigger1 = animelem = 4
value = 7,2

[State 1100, 1]
type = Explod
trigger1 = AnimElem = 4
anim = 7017
postype = p2
removetime = -2
pos = 0,0
postype = p2
bindtime = 1
sprpriority = -1
ownpal = 1

[State 810, snd]
type = playsnd
trigger1 = animelem = 3
value = 800,0

[State 811, bind]
type = Posset
trigger1 = time = 0
y = 0

[State 810, target]
type = targetbind
trigger1 = animelem = 3
pos = 50,-69

[State 810, target]
type = targetbind
trigger1 = animelem = 1
pos = 40,0

[State 810, target]
type = targetbind
trigger1 = animelem = 4
pos = 41,-7

[State 3005, width]
type = width
trigger1 = time = 0
edge = 50,50

[State 810, state]
type = changestate
trigger1 = animtime = 0
value = 0
ctrl = 1

[Statedef 815]
type = A
movetype = H
physics = N
poweradd = 0
velset = 0
ctrl = 0
facep2 = 1
sprpriority = 1

[State 815, anim]
type = changeanim2
trigger1 = time = 0
value = 815

[State 1515, life]
type = lifeadd
trigger1 = animtime = 0
value = -100

[State 855, 39]
type = ChangeState
trigger1 = AnimTime = 0
value = 816

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

[State 865, 2]
type = VelSet
trigger1 = time < 2
x = -5
y = -5

[State 865, 2]
type = VelAdd
trigger1 = 1
y = .58

[State 865, 3]
type = ChangeAnim2
trigger1 = Time = 0
value = 816

[State 865, 5]
type = SelfState
trigger1 = Pos Y >= 0
trigger1 = Vel Y > 0
value = 5100

;agarre 2: Cannon Ball
[Statedef 801]
type = S
movetype = A
physics = S
anim = 800
poweradd = 50
velset = 0
ctrl = 0

[State 200, 2]
type = HitDef
trigger1 = AnimElem = 1
attr = S, NT
damage = 0
animtype = hard
hitflag = M, miss
guardflag = P
sparkno = -1
sparkxy = -20,-60
pausetime = 0,0
p1stateno = 830
p2stateno = 835

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

[Statedef 830]
type = S
physics = S
anim = 830
poweradd = 0
velset = 0
ctrl = 0
sprpriority = 1

[State 3005, width]
type = width
trigger1 = time = 0
edge = 50

[State 811, bind]
type = BindToTarget
trigger1 = animelem = 5
pos = 0,-10,Mid

[State 811, bind]
type = Posadd
trigger1 = animelem = 6
trigger2 = animelem = 7
trigger3 = animelem = 8
x = 20

[State 811, bind]
type = Velset
trigger1 = animelem = 9, >= 0
x = 5

[State 811, bind]
type = Velset
trigger1 = animelem = 9, >= 0
trigger1 = animelem = 9, < 2
y = -2

[State 811, bind]
type = Veladd
trigger1 = animelem = 9, >= 2
y = .5

[State 810, snd]
type = playsnd
trigger1 = animelem = 8
value = 800,0

[State 810, snd]
type = playsnd
trigger1 = animelem = 8
value = 5,4

[State 1100, 1]
type = Explod
trigger1 = AnimElem = 8
anim = 7002
ID = 800
postype = p1
pos = -78,-27
bindtime = 1
sprpriority = 3
ownpal = 1

[State 810, state]
type = changestate
trigger1 = vel Y > 0 && pos Y >= 0
value = 52

[Statedef 835]
type = A
movetype = H
physics = N
poweradd = 0
velset = 0
ctrl = 0
facep2 = 1
sprpriority = 2

[State 815, anim]
type = changeanim2
trigger1 = time = 0
value = 835

[State 1515, life]
type = lifeadd
trigger1 = animtime = 0
value = -100

[State 855, 39]
type = ChangeState
trigger1 = AnimTime = 0
value = 836

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

[State 865, 2]
type = VelSet
trigger1 = time < 2
x = 4
y = -7

[State 865, 2]
type = VelAdd
trigger1 = 1
y = .58

[State 815, anim]
type = changeanim
trigger1 = time = 0
value = 5030

[State 815, anim]
type = changeanim
trigger1 = time = 5
value = 5050

[State 865, 5]
type = SelfState
trigger1 = Pos Y >= 0
trigger1 = Vel Y > 0
value = 5100

;Extra Mode: Zelgadis
[Statedef 310]
type = S
movetype = I
physics = S
anim = 310
velset = 0
ctrl = 0

[State 301, snd]
type = PlaySnd
trigger1 = AnimTime = 0
value = S191,3
channel = 3

[State 350, snd]
type = PlaySnd
trigger1 = AnimTime = 0
value = S20,3
Loop=1
channel = 2

[State 730, 1]
type = ChangeState
trigger1 = AnimTime = 0
value = 311

; Power up
[Statedef 311]
type = S
movetype = I
physics = S
anim = 311

[State 705, 2]
type = Explod
triggerall = numexplod(911) = 0
trigger1 = Time = 0
anim = 7020
ID = 311
sprpriority = 3
postype = p1
pos = 0,0
bindtime = -1
removeongethit = 1
removetime = -1

[State 735, 1]
type = ChangeState
trigger1 = command != "hold_b"
trigger1 = command != "hold_x"
value = 312

[State 735, 2]
type = PowerAdd
trigger1 = Time = [0,9]
value = 9

[State 735, 2]
type = ChangeState
trigger1 = Power >= 3000
value = 313

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

; Power up (end)
[Statedef 312]
type = S
movetype = I
physics = S
anim = 312

[State 301, snd]
type = StopSnd
trigger1 = Time = 0
channel = 3

[State 301, snd]
type = StopSnd
trigger1 = Time = 0
channel = 2

[State 1100, 1]
type = RemoveExplod
trigger1 = AnimElem = 1
ID = 311

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

; Power up (maxed out)
[Statedef 313]
type = S
movetype = I
physics = S
anim = 312

[State 1100, 1]
type = RemoveExplod
trigger1 = AnimElem = 1
ID = 311

[State 313, Explod]
type = Explod
trigger1 = time = 0
anim = 790
pos = 0,0
postype = p1
facing = 1
vfacing = 1
bindtime = 1
removetime = -2
scale = 1,1
sprpriority = 7

[State 301, snd]
type = PlaySnd
trigger1 = AnimElem = 1
value = 7,7

[State 1100, 1]
type = RemoveExplod
trigger1 = AnimElem = 1
ID = 310

[State 1000, EnvShake]
type = EnvShake
trigger1 = AnimElem = 1
time = 15
freq = 90
ampl = -4
phase = 90

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

;------------------------------------------------------------------------------------
;====================================================================================
;------------------------------------------------------------------------------------
[Statedef 6010]
type = S
physics = S
poweradd = 0
sprpriority = -1
velset = 0,0
ctrl = 0
facep2 = 1

[State 6010, anim]
type = Changeanim2
trigger1 = time = 0
value = 6010

[State 6010, air]
type = Changestate
trigger1 = pos Y != 0
value = 5000

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

; HIT_LIEDEAD
[Statedef 5150]
type    = L
movetype= H
physics = N
sprpriority = -3

[State 5150, 1]
type = ChangeAnim
triggerall = 1
trigger1 = Prevstateno = 6010
value = 6011

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

[State 5150, 3] ;Hit up type anim
type = ChangeAnim
triggerall = var(22) = 0
triggerall = Prevstateno != 6010
trigger1 = Time = 0
trigger1 = (anim = [5111,5119]) || (anim = [5171,5179])
trigger1 = SelfAnimExist(5140 + (anim % 10))
value = 5140 + (anim % 10)

[State 5150, 4] ;Match over anim
type = ChangeAnim
triggerall = var(22) = 0
triggerall = Prevstateno != 6010
persistent = 0
;trigger1 = Time = 0
trigger1 = MatchOver = 1
trigger1 = Anim = [5140,5149]
trigger1 = SelfAnimExist(anim+10)
value = anim+10

[State 5150, 5] ;Switch to 5110 if liedead anim does not exist
type = ChangeAnim
triggerall = var(22) = 0
triggerall = Prevstateno != 6010
trigger1 = Time = 0
trigger1 = Anim != [5140,5159]
trigger1 = Anim != [5110,5119]
value = 5110

[State 5150, 1] ;Normal anim
type = ChangeAnim
triggerall = var(22) != 0
triggerall = Prevstateno != 6010
triggerall = Time = 0
triggerall = SelfAnimExist(15140)
trigger1 = (anim != [15111,15119]) && (anim != [15171,15179])
trigger2 = !SelfAnimExist(15140 + (anim % 10))
value = 15140

[State 5150, 3] ;Hit up type anim
type = ChangeAnim
triggerall = var(22) != 0
triggerall = Prevstateno != 6010
trigger1 = Time = 0
trigger1 = (anim = [15111,15119]) || (anim = [15171,15179])
trigger1 = SelfAnimExist(15140 + (anim % 10))
value = 15140 + (anim % 10)

[State 5150, 4] ;Match over anim
type = ChangeAnim
triggerall = var(22) != 0
triggerall = Prevstateno != 6010
persistent = 0
;trigger1 = Time = 0
trigger1 = MatchOver = 1
trigger1 = Anim = [15140,15149]
trigger1 = SelfAnimExist(anim+10)
value = anim+10

[State 5150, 5] ;Switch to 5110 if liedead anim does not exist
type = ChangeAnim
triggerall = var(22) != 0
triggerall = Prevstateno != 6010
trigger1 = Time = 0
trigger1 = Anim != [15140,15159]
trigger1 = Anim != [15110,15119]
value = 15110

[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

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

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

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

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

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

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

; HIT_FALLRECOVER (on the ground)
[Statedef 5201]
type    = S
movetype= H
physics = S
anim = 5200
velset = 0,0

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

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

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

[State 360, push]
type = PlayerPush
trigger1 = 1
value = 0

[State 705, 1]
type = velset
trigger1 = Time = [1,16]
x = -4

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

[State 705, 1]
type = SelfState
trigger1 = Animtime = 0
value = 0
ctrl = 1

;---------- JUMP FORWARD (for AI)
; Jump Start
[Statedef 39]
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 = Time = 0
var(5) = 0

[State 40, 3]
type = VarSet
trigger1 = command = "longjump"
trigger2 = prevstateno = 101 && command = "holdfwd"
var(5) = 1

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

[State 40, 6]
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, 10]
type = ChangeState
trigger1 = AnimTime = 0
value = 50
ctrl = 1

;------------------- LONG JUMP (for AI)
; Jump Start
[Statedef 38]
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 = Time = 0
var(5) = 0

[State 40, 3]
type = VarSet
trigger1 = time = 0
var(5) = 1

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

[State 40, 6]
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, 10]
type = ChangeState
trigger1 = AnimTime = 0
value = 50
ctrl = 1



;------------------------------ RANDOM ANTI AIR ATTACK (FOR AI)
[Statedef 4000]
type = S

[State 3000, choose]
type = VarRandom
trigger1 = time = 0
v = 8
range = 0,5

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [0,1]
trigger1 = Var(59) = 0
value = 1000

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [0,1]
trigger1 = Var(59) = 1
value = 1020

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [2,3]
value = 1100

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [4,5]
value = 1205


;------------------------------ RANDOM CLOSE ATTACK (FOR AI)
[Statedef 4001]
type = S

[State 3000, choose]
type = VarRandom
trigger1 = time = 0
v = 8
range = 0,16

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [0,1]
value = 205

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [2,3]
value = 215

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [4,6]
value = 225

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [7,9]
value = 235

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [10,11]
value = 400

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [12,14]
value = 410

[State 180, 2]
type = ChangeState
trigger1 = Time = 0
trigger1 = Var(8) = [15,16]
value = 420