;==============================================================================;
;Command Buffering File for: Ash                                             ;
; Welcome to Tiny Buffering Type X!                                            ;
;==============================================================================;
;Introduction:
;This is a buffering system aimed at recreating the control feel of the NeoGeo
;KOF series of games. 
;
;The helper is capable of providing buffering as well as PERFECT reversed
;commands.
;
;Any and all editions should be done in the BUFFER DEFINITION section.
;
;Unless you plan to modify the whole system, do not touch the numbers in the
;varsets, ever.
;
;Try to keep a list of the variables used as well as the respective commands,
;just to keep some sort of order.
;
;In addition, try to follow this list as much as possible to avoid problems:
;FUNDAMENTAL MOVEMENT        = System variables  (RESERVED.)
;Basic and system commands:  = var(0)  - var(19) (RESERVED.)
;Special move type commands: = var(20) - var(39)
;Super move type commands    = var(40) - var(49)
;MISC. commands              = var(50) - var(59)
;Ultimate Button Check       = fvar(1)
;Scramble mode switch        = fvar(2)

[Statedef 10371]
anim = 1
ctrl = 0

;================================================================================
; ------- Chizuru compatibility --------
;===============================================================================
[State 10371, NO SPECIAL COMMANDS]
type = VarRangeSet
trigger1 = root,numprojid(131035)
value = 0
first = 20
last = 59
;-------------------------------------------------------------------------------

[State 654654, VarSet]
type = VarSet
trigger1 = 1
fvar(2) = root,var(42)
[State 10371, VarSet]
type = VarSet
trigger1 = !root,AILevel
fvar(1)=(command="hold_x")*2+(command="hold_a")*2+(command="hold_y")*2+(command="hold_b")*2+(command="hold_z")*4+(command="hold_c")*4

[State -2, VarSet]
type = VarAdd
trigger1 = root,movehit = 1
fvar(11) = 1

[State -2, VarSet]
type = VarSet
trigger1 = root,movehit = 2
trigger2 = root,hitpausetime = 0
fvar(11) = 0

[State -2, VarSet]
type = VarSet
trigger1 = 1;root,movecontact = 1 && var(2) = 0
fvar(12) = root,movecontact

;Breaker Box
[State -2, VarSet]
type = VarSet
trigger1 = root, HitPauseTime = 0
sysvar(4) = 0
ignorehitpause = 1
[State -2, VarSet]
type = VarSet
trigger1 = (command="hold_x") && (!(sysvar(4)&1))
sysvar(4) = sysvar(4)+1
ignorehitpause = 1
[State -2, VarSet]
type = VarSet
trigger1 = (command="hold_a") && (!(sysvar(4)&2))
sysvar(4) = sysvar(4)+2
ignorehitpause = 1
[State -2, VarSet]
type = VarSet
trigger1 = (command="hold_y") && (!(sysvar(4)&4))
sysvar(4) = sysvar(4)+4
ignorehitpause = 1
[State -2, VarSet]
type = VarSet
trigger1 = (command="hold_b") && (!(sysvar(4)&8))
sysvar(4) = sysvar(4)+8
ignorehitpause = 1


[State 10371, MAX MODE ALL RESET]
type = VarRangeSet
trigger1 = root,stateno = 780
trigger2 = root,stateno = 8103
trigger2 = root,time < 3
value = 0

[State 10371, NO TURN BEHAVIOR.]
type = AssertSpecial
trigger1 = 1
flag = invisible ;Just in case.
ignorehitpause = 1

[State 10371, BindToRoot]
type = BindToRoot
trigger1 = 1
time = 1
pos = 0,0
ignorehitpause = 1

;"Buffering - (head.pos)"

[State 10371, AM I WORKING ?]
type = DisplayToClipboard
trigger1 = 1
text = "CEE = %f down = %d SANS = %d check = %f pls = %f"
params = fvar(26),var(29),var(44),fvar(1), fvar(13)
ignorehitpause = 1

[State 10371, AM I WORKING ?]
type = AppendToClipboard
trigger1 = 1
text = "TAG = %d SVar(0)=%d DIR=%d BREAK=%d"
params = fvar(2), sysvar(0), sysvar(1), var(44)
ignorehitpause = 1

;----------------------------[BUFFER DECREASE]---------------------------------;

;--------------------------------[BUTTONS]-------------------------------------;
;NON-NEGATIVE EDGE:
;var(0)  = LP (A)
;var(1)  = MP (C)
;var(2)  = HP (E)
;var(3)  = LK (B)
;var(4)  = MK (D)
;var(5)  = HK (SHORTCUT)
;var(6)  = Start
;NEGATIVE EDGE:
;var(7)  = LP
;var(8)  = MP
;var(9)  = HP
;var(10) = LK
;var(11) = MK
;var(12) = HK
;var(13) = Start
;DOUBLE BUTTON:
;var(14) = LP+LK (A+B)
;var(15) = LK+MP (B+D)
;var(16) = MP+MK (C+D)
;var(17) = LP+MP (A+C)
;var(18) = LK+MK (B+D)
;var(19) = LP+HK (A+D)


[State 10371, LP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(0)
var(0) = -1

[State 10371, MP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(1)
var(1) = -1

[State 10371, HP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(2)
var(2) = -1

[State 10371, LK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(3)
var(3) = -1

[State 10371, MK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(4)
var(4) = -1

[State 10371, HK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(5)
var(5) = -1

[State 10371, START Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(6)
var(6) = -1

;NEGATIVE EDGE SETS:

[State 10371, NEG LP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(7) && !var(0)
var(7) = -1

[State 10371, NEG MP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(8) && !var(1)
var(8) = -1

[State 10371, NEG HP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(9) && !var(2)
var(9) = -1

[State 10371, NEG LK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(10) && !var(3)
var(10) = -1

[State 10371, NEG MK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(11) && !var(4)
var(11) = -1

[State 10371, NEG HK Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(12) && !var(5)
var(12) = -1

[State 10371, NEG START Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(13) && !var(6)
var(13) = -1

;--------------------------------[COMMANDS]------------------------------------;
;var(20)  = QCB
;var(21)  = QCF
;var(22)  = DP
;var(23)  = RDP
;var(24)  = 'ABCD'
;var(25)  = HCF
;var(26)  = HCB
;var(27)  = 
;var(40)  = 2xQCF
;var(41)  = 2xQCB
;var(42)  = 2xHCB
;var(43)  = 2xHCF
;var(44)  = 
;------------------- SUPERS ---------------------------------------------------;
[State 10371, 40]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(40)
var(40) = -1
[State 10371, 41]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(41)
var(41) = -1
[State 10371, 42]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(42)
var(42) = -1
[State 10371, 43]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(43)
var(43) = -1
;[State 10371, 44]
;type = VarAdd
;triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
;trigger1 = var(44)
;var(44) = -1
[State 10371, 45]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(45)
var(45) = -1
[State 10371, 46]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(46)
var(46) = -1
[State 10371, 47]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(47)
var(47) = -1
[State 10371, 48]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(48)
var(48) = -1
[State 10371, 49]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(49)
var(49) = -1

[State 10371, Sans 2 Dec]
type = VarAdd
trigger1 = (var(44)/2**4)&15
var(44) = -1*2**4
[State 10371, Sans 1 Dec]
type = VarAdd
trigger1 = var(44)&15
var(44) = -1

;------------------- SPECIALS -------------------------------------------------;
[State 10371, QCF Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(20)
var(20) = -1

[State 10371, DP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(21)
var(21) = -1

[State 10371, QCB Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(22)
var(22) = -1

[State 10371, rDP Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0  ;^^ root, HitPausetime = 1
trigger1 = var(23)
var(23) = -1

[State 10371, HCB Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(24)
var(24) = -1

[State 10371, HCB,F Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(25)
var(25) = -1

[State 10371, DU Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(26)
var(26) = -1

[State 10371, HCF Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(27)
var(27) = -1

[State 10371, FBF Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(28)
var(28) = -1

[State 10371, D.Charge Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(29)
var(29) = -1

[State 10371, B.Charge Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(30)
var(30) = -1

;------------------- SUPERS -------------------------------------------------;
[State 10371, Sans 2 Init];Hold C
type = VarSet
trigger1 = sysvar(4) = 6
trigger1 = var(44)&15
var(44) = var(44) | ((15&15)*2**4)
[State 10371, Sans 1 Init];Hold C
type = VarSet
trigger1 = sysvar(4) = 5
trigger1 = ((var(44)/2**4)&15) = 0
var(44) = 15

[State 10371, Sans 2 Init];Hold B
type = VarSet
trigger1 = sysvar(4) = 6
trigger1 = var(45)&15
var(45) = var(45) | ((15&15)*2**4)
[State 10371, Sans 1 Init];Hold B
type = VarSet
trigger1 = sysvar(4) = 3
trigger1 = ((var(45)/2**4)&15) = 0
var(45) = 15

[State 10371, Sans 2 Init];Hold A
type = VarSet
trigger1 = sysvar(4) = 5
trigger1 = var(46)&15
var(46) = var(46) | ((15&15)*2**4)
[State 10371, Sans 1 Init];Hold A
type = VarSet
trigger1 = sysvar(4) = 3
trigger1 = ((var(46)/2**4)&15) = 0
var(46) = 15
;--------------------------[FUNDAMENTAL MOVEMENT]------------------------------;
;------ Running ---------------------------------
[State 10371, Reset]
type = VarSet
trigger1 = !root,AILevel
trigger1 = command != "FF" && command != "BB"
trigger2 = numpartner
trigger2 = root,AILevel && fvar(2)
trigger2 = partner,command != "FF" && partner,command != "BB"
sysvar(0) = 0
[State 10371, FF Init]
type = VarSet
trigger1 = !root,AILevel
trigger1 = p2dist X >= 0 && command = "FF" && command != "holdback"
trigger2 = !root,AILevel
trigger2 = p2dist X < 0 && command = "BB" && command != "holdfwd"
trigger3 = numpartner
trigger3 = root,AILevel && fvar(2)
trigger3 = p2dist X >= 0 && partner,command = "FF" && partner,command != "holdback"
trigger4 = root,AILevel && fvar(2)
trigger4 = p2dist X < 0 && partner,command = "BB" && partner,command != "holdfwd"
sysvar(0) = 1
[State 10371, BB Init]
type = VarSet
trigger1 = !root,AILevel
trigger1 = p2dist X >= 0 && command = "BB" && command != "holdfwd"
trigger2 = !root,AILevel
trigger2 = p2dist X < 0 && command = "FF" && command != "holdback"
trigger3 = numpartner
trigger3 = root,AILevel && fvar(2)
trigger3 = p2dist X >= 0 && partner,command = "BB" && partner,command != "holdfwd"
trigger4 = numpartner
trigger4 = root,AILevel && fvar(2)
trigger4 = p2dist X < 0 && partner,command = "FF" && partner,command != "holdback"
sysvar(0) = -1

;------ Jump buffer ---------------------
[State 10371, DOWN]
type = VarAdd
trigger1 = sysvar(2)
sysvar(2) = -1
[State 10371, DOWN]
type = Varset
trigger1 = !root,AILevel
trigger1 = command = "down2" && !(sysvar(1)&8)
trigger2 = numpartner
trigger2 = root,AILevel && fvar(2)
trigger2 = partner,command = "down2" && !(sysvar(1)&8)
sysvar(2) = 15

;------ Holding a direction ---------------------
;-CODES:
;- 1000 UP    0100 DOWN
;- 0010 RIGHT 0001 LEFT
[State 10371, LEFT]
type = Varset
trigger1 = root, HitPauseTime = 0
sysvar(1) = 0
[State 10371, LEFT]
type = Varset
triggerall = !(sysvar(1)&2)
trigger1 = !root,AILevel
trigger1 = p2dist X >= 0 && command = "holdfwd"
trigger2 = !root,AILevel
trigger2 = p2dist X < 0 && command = "holdback"
trigger3 = numpartner
trigger3 = root,AILevel && fvar(2)
trigger3 = p2dist X >= 0 && partner,command = "holdfwd"
trigger4 = numpartner
trigger4 = root,AILevel && fvar(2)
trigger4 = p2dist X < 0 && partner,command = "holdback"
sysvar(1) = sysvar(1)+2
[State 10371, RIGHT]
type = Varset
triggerall = !(sysvar(1)&4)
trigger1 = !root,AILevel
trigger1 = p2dist X >= 0 && command = "holdback"
trigger2 = !root,AILevel
trigger2 = p2dist X < 0 && command = "holdfwd"
trigger3 = root,AILevel && fvar(2)
trigger3 = p2dist X >= 0 && partner,command = "holdback"
trigger4 = root,AILevel && fvar(2)
trigger4 = p2dist X < 0 && partner,command = "holdfwd"
sysvar(1) = sysvar(1)+4
[State 10371, DOWN]
type = Varset
triggerall = !(sysvar(1)&8)
trigger1 = !root,AILevel
trigger1 = command = "holddown"
trigger2 = numpartner
trigger2 = root,AILevel && fvar(2)
trigger2 = partner,command = "holddown"
sysvar(1) = sysvar(1)+8
[State 10371, UP]
type = Varset
triggerall = !(sysvar(1)&16)
trigger1 = !root,AILevel
trigger1 = command = "holdup"
trigger2 = numpartner
trigger2 = root,AILevel && fvar(2)
trigger2 = partner,command = "holdup"
sysvar(1) = sysvar(1)+16

;--------------------------[BUFFER DEFINITION]---------------------------------;

;----------------------------[CHARGE MOTIONS]----------------------------------;
;In order to properly detect charge motions, the following four-way timers have
;been set.
;These were made with the KOF standard in mind, but other games use the same
;principle. 
;Until a charge-motion fix is provided by Elecbyte, this will have to do.

;[State 10371, D.Charge Abs Init]
;type = VarAdd
;triggerall = fvar(3) > 0 && fvar(3) < 30.0
;trigger1 = command = "holddown"
;fvar(3) = 1.0

;----------------------------[COMMAND BUFFER]----------------------------------;
;This is where ONLY THE NECESSARY commands are buffered. The buffer requires
;both the regular command and its reversed equivalent.
;
;ALL COMMANDS SET HERE MUST ALSO BE PUT IN [Commands] UNDER [Buffer Decrease]
;
;One last thing, just like the CMD file, put the complicated commands on top.
;Command checklist:
;
;var(20)  = QCB
;var(21)  = QCF
;var(22)  = DP
;var(23)  = RDP
;var(24)  = 'ABCD'
;var(25)  = HCF
;var(26)  = HCB
;var(27)  = 
;var(40)  = 2xQCF
;var(41)  = 2xQCB
;var(42)  = 2xHCB
;var(43)  = 2xHCF
;var(44)  = Sans Culottes
;------------------- SUPERS -------------------------------------------------;

;----------------[DOUBLE BUTTON CHECK]----------------
;var(14) = LP+MP (A+B)
;var(15) = LK+MP (B+C)
;var(16) = MP+MK (C+D)
;var(17) = LP+HP (A+C) 
;var(18) = LK+MK (B+D)
;var(19) = LP+MK (A+D)
[State c, CRACK CRACK CRACK THE EGG INTO THE BOWL]
type = null
trigger1 = var(14) := (((var(0) = [1,3]) && (var(3) = [1,3])))
[State c, M.I.X. THE FLOUR INTO THE BOWL]
type = null
trigger1 = var(15) := (((var(1) = [1,3]) && (var(3) = [1,3])))
[State c, BUTTER BUTTER BUTTER JOINS THE BOWL]
type = null
trigger1 = var(16) := (((var(1) = [1,3]) && (var(4) = [1,3])))
[State c, BUTTER BUTTER BUTTER JOINS THE BOWL]
type = null
trigger1 = var(17) := (((var(0) = [1,3]) && (var(1) = [1,3])))
[State c, BUTTER BUTTER BUTTER JOINS THE BOWL]
type = null
trigger1 = var(18) := (((var(3) = [1,3]) && (var(4) = [1,3])))
[State c, BUTTER BUTTER BUTTER JOINS THE BOWL]
type = null
trigger1 = var(19) := (((var(0) = [1,3]) && (var(4) = [1,3])))