;==============================================================================;
;Command Buffering File for: SNK GALS FIGHTERS Y                                  ;
;Original system for Capcom VS. SNK: Collision Course                          ;
;KOF buffering system for The King of Fighters: Yillion (working title)        ;
;by Vans                                                                       ;
;==============================================================================;
;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:
;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)
;Development Testing Use     = fvar(0)
;Ultimate Button Check       = fvar(1)
;Charge Motions              = fvar(2) - fvar(5) (RESERVED.)

[Statedef 10371]
anim = 1
ctrl = 0

[State 10371, VarSet]
type = VarSet
trigger1 = 1
fvar(1)=(command="hold_x")*2+(command="hold_a")*2+(command="hold_y")*2+(command="hold_b")*2

[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

;[State -2, DTC]
;type = DisplayToClipboard
;trigger1 = NumHelper(247)
;text = "MoveHit = %d MoveContact = %d"
;params = Var(1), var(2)

[State 10371, MAX MODE ALL RESET]
type = VarRangeSet
trigger1 = root,stateno = 780
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 = Const(size.mid.pos.x),Const(size.mid.pos.y)
ignorehitpause = 1

[State 10371, AM I WORKING ?]
type = DisplayToClipboard
trigger1 = 1
text = "A = %d  DP = %d A = %d D.Charge = %d check = %f"
params = var(0),var(23),var(3),var(29),fvar(3)
ignorehitpause = 1
[State 10371, SGS fact check]
type = AppendToClipboard
trigger1 = 1
text = "SGS = %d SGS1=%d SGS2=%d SGS3=%d SGS4=%d"
params = var(43),var(43)&15,(var(43)/2**4)&15,(var(43)/2**8)&15,(var(43)/2**12)&15
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)

[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

;-----------------------------[CHARGE KILL]------------------------------------;
[State 10371, B.Charge Dec]
type = VarSet
trigger1 = command != "holdback"
fvar(2) = 0
[State 10371, B.Charge Dec]
type = VarSet
trigger1 = command != "holddown"
fvar(3) = 0
[State 10371, B.Charge Dec]
type = VarSet
trigger1 = command != "holdfwd"
fvar(4) = 0
[State 10371, B.Charge Dec]
type = VarSet
trigger1 = command != "holdup"
fvar(5) = 0

;--------------------------------[COMMANDS]------------------------------------;
;var(20)  = QCF
;var(21)  = DP
;var(22)  = QCB
;var(23)  = rDP
;var(24)  = HCF
;var(25)  = HCB,F
;var(26)  = DU
;var(27)  = HCF
;var(29) = D.Charge
;var(40)  = 2xQCF
;var(41)  = 2xQCB
;var(42)  = 2xHCB
;var(43)  = 2xQCB
;var(44)  = TIGER
;var(45)  = FHCF
;var(46)  = QCFHCB
;------------------- SUPERS ---------------------------------------------------;
[State 10371, 2xQCF Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(40)
var(40) = -1

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

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

[State 10371, SGS Timer 4 Dec]
type = VarAdd
trigger1 = (var(43)/2**12)&15
var(43) = -1*2**12
[State 10371, SGS Timer 3 Dec]
type = VarAdd
trigger1 = (var(43)/2**8)&15
var(43) = -1*2**8
[State 10371, SGS Timer 2 Dec]
type = VarAdd
trigger1 = (var(43)/2**4)&15
var(43) = -1*2**4
[State 10371, SGS Timer 1 Dec]
type = VarAdd
trigger1 = var(43)&15
var(43) = -1

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

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

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

[State 10371, "xHCF Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(47)
var(47) = -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, DD Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(30)
var(30) = -1

[State 10371, B.Charge Dec]
type = VarAdd
triggerall = root, HitPauseTime = 0 ;^^ root, HitPausetime = 1
trigger1 = var(31)
var(31) = -1
;--------------------------[BUFFER DEFINITION]---------------------------------;
;----------------------------[BUTTON BUFFER]-----------------------------------;
;Leave the BUTTON BUFFER alone for compatibility.
;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 (RESERVED):
;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)

[State 10371, LP Init]
type = VarSet
trigger1 = command = "x"
var(0) = 3

[State 10371, MP Init]
type = VarSet
trigger1 = command = "y"
var(1) = 3

[State 10371, HP Init]
type = VarSet
trigger1 = command = "z"
var(2) = 3

[State 10371, LK Init]
type = VarSet
trigger1 = command = "a"
var(3) = 3

[State 10371, MK Init]
type = VarSet
trigger1 = command = "b"
var(4) = 3

[State 10371, HK Init]
type = VarSet
trigger1 = command = "c"
var(5) = 3

[State 10371, START Init]
type = VarSet
trigger1 = command = "start"
var(6) = 3

;----------------------------[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, B.Charge Abs Init]
type = VarAdd
triggerall = fvar(2) < 30
trigger1 = command = "holdback"
fvar(2) = 1
[State 10371, D.Charge Abs Init]
type = VarAdd
triggerall = fvar(3) < 30
trigger1 = command = "holddown"
fvar(3) = 1
[State 10371, F.Charge Abs Init]
type = VarAdd
triggerall = fvar(4) < 30
trigger1 = command = "holdfwd"
fvar(4) = 1
[State 10371, U.Charge Abs Init]
type = VarAdd
triggerall = fvar(5) < 30
trigger1 = command = "holdup"
fvar(5) = 1

;----------------------------[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)  = DP
;var(21)  = QCF
;var(22)  = QCB
;var(23)  = rDP
;var(24)  = HCB
;var(25)  = HCB,F
;var(26)  = DU
;var(27)  = HCF
;var(28)  = FBF
;var(29)  = D.Charge
;var(40)  = QCBHCF
;var(41)  = 2xQCF
;var(42)  = 2xHCB
;var(43)  = 2xQCB
;var(44)  = TIGER
;var(45)  = FHCF
;------------------- SUPERS -------------------------------------------------;
[State 10371, HCF Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "2hcf" && command != "holdback"
trigger2 = p2dist X < 0 && command = "2hcb" && command != "holdfwd"
var(47) = 16

[State 10371, QCFHCB Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "qcfhcb" && command != "holdfwd"
;trigger1 = command = "relf"
trigger2 = p2dist X < 0 && command = "qcbhcf" && command != "holdback"
;trigger2 = command = "relb"
var(46) = 17

[State 10371, FHCF Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "fhcf" && command != "holdback"
trigger2 = p2dist X < 0 && command = "bhcb" && command != "holdfwd"
var(45) = 16

[State 10371, TIGER Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "tigerkiller1" && command != "holdback"
trigger2 = p2dist X < 0 && command = "tigerkiller2" && command != "holdfwd"
var(44) = 16

[State 10371, HCB Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "2hcb" && command != "holdfwd"
trigger2 = p2dist X < 0 && command = "2hcf" && command != "holdback"
var(42) = 16

[State 10371, 2QCF]
type = VarSet
trigger1 = p2dist X >= 0 && command = "2qcf" && command != "holdback"
trigger2 = p2dist X < 0 && command = "2qcb" && command != "holdfwd"
var(40) = 17

[State 10371, 2QCB]
type = VarSet
trigger1 = p2dist X >= 0 && command = "2qcb" && command != "holdfwd"
trigger2 = p2dist X < 0 && command = "2qcf" && command != "holdback"
var(41) = 18

[State 10371, HCB Init]
type = VarSet
trigger1 = p2dist X >= 0 && command = "2qcb" && command != "holdfwd"
trigger2 = p2dist X < 0 && command = "2qcf" && command != "holdback"
var(43) = 18

;------------------- SPECIALS -------------------------------------------------;

;----------------[2]----------------
[State p, 1]
type = VarSet
trigger1 = 1
fvar(0)  = ceil(parent, Power)
[State f, BURN COOKIES]
type = VarSet
trigger1 = Var(40) = [1,6]
fvar(22)=ifElse((((Var(1)=[1,2])||(Var(8) =[1,2]))&&FVar(0)  >= 2000)||(((Var(2)=[1,2])||(Var(9)=[1,2]))&&(FVar(0) =[2000,2999])),1,IfElse(((Var(2)=[1,2])||(Var(9)=[1,2]))&&(FVar(0) >=3000),2,0))
[State f, BURN COOKIES]
type = VarSet
trigger1 = Var(40) = [1,6]
fvar(23)=ifElse((((Var(4)=[1,2])||(Var(11) =[1,2]))&&FVar(0)  >= 2000)||(((Var(5)=[1,2])||(Var(12)=[1,2]))&&(FVar(0) =[2000,2999])),1,IfElse(((Var(5)=[1,2])||(Var(12)=[1,2]))&&(FVar(0) >=3000),2,0))
;var(14) = LP+MP
;var(15) = LP+HP
;var(16) = MP+HP
;----------------[DOUBLE BUTTON CHECK]----------------
;[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])))

