; The CMD file for Sonic 2 by supermystery.
;
; Two parts: 1. Command definition and  2. State entry
; (state entry is after the commands def section)
;
; 1. Command definition
; ---------------------

;-| Button Remapping |-----------------------------------------------------
; This section lets you remap the player's buttons (to easily change the
; button configuration). The format is:
;   old_button = new_button
; If new_button is left blank, the button cannot be pressed.
[Remap]
x = x
y = y
z = z
a = a
b = b
c = c
s = s

;-| Default Values |-------------------------------------------------------
[Defaults]
; Default value for the "time" parameter of a Command. Minimum 1.
command.time = 15

; Default value for the "buffer.time" parameter of a Command. Minimum 1,
; maximum 30.
command.buffer.time = 1

;
;-| Single Button |---------------------------------------------------------
[Command]
name = "a"
command = a
time = 1

[Command]
name = "b"
command = b
time = 1

[Command]
name = "c"
command = c
time = 1

[Command]
name = "x"
command = x
time = 1

[Command]
name = "y"
command = y
time = 1

[Command]
name = "z"
command = z
time = 1

[Command]
name = "start"
command = s
time = 1

;-| Hold Dir |--------------------------------------------------------------
[Command]
name = "holdfwd";Required (do not remove)
command = /$F
time = 1

[Command]
name = "holdback";Required (do not remove)
command = /$B
time = 1

[Command]
name = "holdup" ;Required (do not remove)
command = /$U
time = 1

[Command]
name = "holddown";Required (do not remove)
command = /$D
time = 1

;-| Hold Button |----------------------------------------------------------

[Command]
name = "holda"
command = /a
time = 1

[Command]
name = "holdb"
command = /b
time = 1

[Command]
name = "holdc"
command = /c
time = 1

[Command]
name = "holdx"
command = /x
time = 1

[Command]
name = "holdy"
command = /y
time = 1

[Command]
name = "holdz"
command = /z
time = 1

[Command]
name = "holdstart"
command = /s
time = 1

;--- None of your own command definitions should be above this line. ---

;-| CPU |--------------------------------------------------------------


[Command]
name = "a2"
command = a
time = 1

[Command]
name = "b2"
command = b
time = 1

[Command]
name = "c2"
command = c
time = 1

[Command]
name = "x2"
command = x
time = 1

[Command]
name = "y2"
command = y
time = 1

[Command]
name = "z2"
command = z
time = 1

[Command]
name = "start2"
command = s
time = 1

[Command]
name = "holdfwd2"
command = /$F
time = 1

[Command]
name = "holdback2"
command = /$B
time = 1

[Command]
name = "holdup2"
command = /$U
time = 1

[Command]
name = "holddown2"
command = /$D
time = 1

[Command]
name = "holda2"
command = /a
time = 1

[Command]
name = "holdb2"
command = /b
time = 1

[Command]
name = "holdc2"
command = /c
time = 1

[Command]
name = "holdx2"
command = /x
time = 1

[Command]
name = "holdy2"
command = /y
time = 1

[Command]
name = "holdz2"
command = /z
time = 1

[Command]
name = "holdstart2"
command = /s
time = 1

[Command]
name = "recovery2"
command = x+y
time = 1

;- | Moves |-------------------------------------

[Command]
name = "sonica" 
command = /~30a  ;hold a for at least 20 ticks, then release

[Command]
name = "sonicb" 
command = /~30b  ;hold a for at least 20 ticks, then release

[Command]
name = "sonicc" 
command = /~30c  ;hold a for at least 20 ticks, then release

;-| Double Tap |-----------------------------------------------------------
[Command]
name = "FF"     ;Required (do not remove)
command = F, F
time = 10

[Command]
name = "BB"     ;Required (do not remove)
command = B, B
time = 10

;-| 2/3 Button Combination |-----------------------------------------------
[Command]
name = "recovery";Required (do not remove)
command = x+y
time = 1

;-| Dir + Button |---------------------------------------------------------
[Command]
name = "down_a"
command = /$D,a
time = 1

[Command]
name = "down_b"
command = /$D,b
time = 1

;---------------------------------------------------------------------------
; 2. State entry
; --------------
;
[Statedef -1]

;----------------------------------------------------------
;Simulation mode ON/OFF
;-----------------------------------------------------------

[State -1, Simulation mode ON/OFF]
type = VarSet
trigger1 = 1
v = 32
;value = 1 ; Uncomment this if you want simulation mode to be on 
value = 0
ignorehitpause = 1

;----------------------------------------------------------
;End of configuration
;-----------------------------------------------------------





;============================================================

[State -1, AI Helper Check]
type = ChangeState
trigger1 = IsHelper(9741)
value = 9741

[State -1, AI Helper Check 2]
type = ChangeState
trigger1 = IsHelper(9742)
value = 9742

;===========================================================================
[State -1, Hide]
type = AssertSpecial
trigger1 = IsHelper(44304)
flag = invisible
flag2 = NoShadow
IgnoreHitPause = 1

[State -1, Reset]
type = SelfState
trigger1 = IsHelper(44304)
trigger1 = StateNo != [44304,44305]
value = 44304
IgnoreHitPause = 1

[State -1, WideOpen]
type = AssertSpecial
trigger1 = 1
flag = NoStandGuard
flag2 = NoCrouchGuard
flag3 = NoAirGuard
IgnoreHitPause = 1

[State 0, Dont Turn]
type = AssertSpecial
trigger1 = 1
flag = noautoturn
flag1 = NoWalk
IgnoreHitPause = 1

[State -1, GO]
type = DestroySelf
trigger1 = IsHelper
trigger1 = movereversed = 1

[State 44304, HO]
type = HitOverride
trigger1 = ishelper(3000)
trigger1 = prevstateno != 3500
attr = SCA, AA,AP,AT
time = 1
stateno = 3500

;===========================================================================
; And of course, most human-only command-based ChangeStates also belong
; in State -1.  For example, this move would only be performable by a human:
;
;---------------------------------------------------------------------------
;Sonic Spin Attack
[State -1, Sonic Spin Attack]
type = ChangeState
value = 40
triggerall = var(58) != 1
triggerall = command = "a" || command = "b" || command = "c"
triggerall = command != "holddown"
trigger1 = statetype = S || statetype = C
trigger1 = ctrl
trigger2 = stateno = 600 || stateno = 25 || stateno = 621

;---------------------------------------------------------------------------
[State -1, Look Up]
type = ChangeState
value = 196
triggerall = var(58) != 1 && !var(20) && stateno != 196 && stateno != 198 && stateno != 500
triggerall = command = "holdup"
trigger1 = statetype = S || statetype = C
trigger1 = ctrl

;---------------------------------------------------------------------------
;Spin Dash
[State -1, Spin Dash]
type = ChangeState
value = 620
triggerall = var(58) != 1
triggerall = command = "a" || command = "b" || command = "c"
triggerall = command = "holddown"
trigger1 = statetype = S || statetype = C
trigger1 = ctrl


; This is generally the best place to put most of your AI directives.  For
; example, this controller would only be executed when the CPU is in control:

;================================================================================
;AI
;--------------------------------------------------------------------------------

[State -1, Turn]
type = Turn
triggerall = var(58) = 1
Triggerall = P2Dist X < 0
trigger1 = ctrl = 1 && stateno != 196 && stateno != 620
trigger2 = stateno = 600
trigger3 = var(27) = 1 && stateno != 620
trigger4 = var(27) != 1 
trigger4 = stateno = 25
trigger5 = stateno = 25
trigger5 = vel x > -9
Trigger5 = P2Dist X < 0
trigger5 = var(58) = 1

[State -1, Spin Dash]
type = ChangeState
value = 620
triggerall = var(58) = 1 && stateno != 25
triggerall = p2bodydist y = [-10,0]
trigger1 = statetype = S || statetype = C
trigger1 = ctrl
trigger1 = p2bodydist x = [-4,80]
trigger1 = random < 200
trigger1 = moveguarded != 1
trigger1 = var(27) != 1
trigger2 = var(27) != 1
trigger2 = statetype = S || statetype = C
trigger2 = ctrl
trigger2 = p2bodydist x >= 1
trigger2 = random < 200
trigger2 = p2stateno != [130, 153]
trigger2 = moveguarded != 1
trigger3 = statetype = S || statetype = C
trigger3 = ctrl
trigger3 = p2bodydist x = [-4,50]
trigger3 = random < 200
trigger3 = moveguarded != 1
trigger3 = var(27) = 1


[State -1, AI Walk]
type = Changestate
triggerall = var(58) = 1
triggerall = stateno != 25
triggerall = p2bodydist y = [-10,0]
trigger1 = p2movetype != A
trigger1 = statetype = S || statetype = C
trigger1 = ctrl
trigger1 = p2dist x > 0
trigger1 = random <= 700
trigger1 = var(27) != 1
trigger2 = var(27) = 1
trigger2 = statetype = S || statetype = C
trigger2 = ctrl
trigger2 = p2dist x > 0
trigger2 = random <= 300
trigger2 = p2stateno != [130, 153]
trigger2 = moveguarded != 1
value = 25
ctrl = 0

[State -1, 4 AI]
type = ChangeState
triggerall = var(58) = 1
triggerall = stateno = 25
trigger1 = var(27) != 1
trigger1 = p2movetype = A
trigger1 = fvar(15) = 0
trigger2 = var(27) = 1
trigger2 = stateno = 25
trigger2 = p2movetype = H 
trigger2 = fvar(15) = 0
trigger3 = var(27) = 1
trigger3 = stateno = 25
trigger3 = p2movetype = I && random < 100
trigger3 = fvar(15) = 0
trigger4 = p2stateno = [130, 153]
trigger5 = moveguarded = 1
value = 0
ctrl = 1


[State -1, AI Sonic Spin Attack]
type = ChangeState
value = 40
triggerall = var(58) = 1
trigger1 = statetype = S || statetype = C 
trigger1 = ctrl
trigger1 = p2bodydist x = [-4,70]
trigger1 = p2bodydist y = [-70,-4]
trigger1 = var(27) != 1
trigger1 = random <= 500
trigger2 = stateno = 600 || stateno = 621
trigger2 = p2bodydist x = [-1,70]
trigger2 = p2bodydist y = [-70,-4]
trigger3 = var(27) != 1
trigger3 = stateno = 25
trigger3 = random <= 500
trigger3 = p2bodydist x = [-1,70]
trigger3 = p2bodydist y = [-70,-4]
trigger4 = statetype = S || statetype = C 
trigger4 = ctrl
trigger4 = p2bodydist x = [30,70]
trigger4 = p2bodydist y = [-70,-5]
trigger4 = var(27) = 1
trigger4 = random <= 500
trigger5 = var(27) = 1
trigger5 = stateno = 25
trigger5 = random <= 500
trigger5 = p2bodydist x = [-1,70]
trigger5 = p2bodydist y = [-70,-5]
trigger6 = statetype = S || statetype = C 
trigger6 = ctrl || stateno  = 25
trigger6 = p2bodydist x > 50
trigger6 = p2bodydist y = [-10,0]
trigger6 = p2movetype = A

[State -1, AI Breaks 1] ;Change from turning animation
type = ChangeAnim
triggerall = var(58) = 1
triggerall = pos y = 0 ;&& stateno = 20
trigger1 = fvar(15) != 0
Trigger1 = P2Dist X < 0
trigger1 = stateno = 25 && vel x > 4
value = ifelse(var(27) = 1,1190,191)

[State -1, Break Snd 1]
type = PlaySnd
triggerall = var(58) = 1
triggerall = pos y = 0 ;&& stateno = 20
trigger1 = fvar(15) != 0
Trigger1 = P2Dist X < 0
trigger1 = stateno = 25 ;|| stateno = 600
value = 7,4
channel = 1
