• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Go で書き直した Ikemen


Commit MetaInfo

修订版9144d50cc5991de50c5fa680345d5ae5a1a98834 (tree)
时间2016-12-19 00:56:20
作者SUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Log Message

ステートコントローラーのところを書いていく

更改概述

差异

--- a/src/bytecode.go
+++ b/src/bytecode.go
@@ -66,6 +66,7 @@ const (
6666 OC_pop
6767 OC_dup
6868 OC_swap
69+ OC_run
6970 OC_jmp8
7071 OC_jz8
7172 OC_jnz8
@@ -177,7 +178,6 @@ const (
177178 OC_numpartner
178179 OC_ailevel
179180 OC_palno
180- OC_matchover
181181 OC_hitcount
182182 OC_uniqhitcount
183183 OC_hitpausetime
@@ -359,6 +359,7 @@ const (
359359 OC_ex_loseko
360360 OC_ex_losetime
361361 OC_ex_drawgame
362+ OC_ex_matchover
362363 OC_ex_matchno
363364 OC_ex_tickspersecond
364365 )
@@ -626,6 +627,7 @@ func (_ BytecodeExp) blor(v1 *BytecodeValue, v2 BytecodeValue) {
626627 }
627628 func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
628629 sys.bcStack.Clear()
630+ orgc := c
629631 for i := 1; i <= len(be); i++ {
630632 switch be[i-1] {
631633 case OC_jz8, OC_jnz8:
@@ -649,15 +651,13 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
649651 case OC_jmp:
650652 i += int(*(*int32)(unsafe.Pointer(&be[i]))) + 4
651653 case OC_int8:
652- sys.bcStack.Push(BytecodeValue{VT_Int, float64(int8(be[i]))})
654+ sys.bcStack.Push(BytecodeInt(int32(int8(be[i]))))
653655 i++
654656 case OC_int:
655- sys.bcStack.Push(BytecodeValue{VT_Int,
656- float64(*(*int32)(unsafe.Pointer(&be[i])))})
657+ sys.bcStack.Push(BytecodeInt(*(*int32)(unsafe.Pointer(&be[i]))))
657658 i += 4
658659 case OC_float:
659- sys.bcStack.Push(BytecodeValue{VT_Float,
660- float64(*(*float32)(unsafe.Pointer(&be[i])))})
660+ sys.bcStack.Push(BytecodeFloat(*(*float32)(unsafe.Pointer(&be[i]))))
661661 i += 4
662662 case OC_blnot:
663663 be.blnot(sys.bcStack.Top())
@@ -715,17 +715,34 @@ func (be BytecodeExp) run(c *Char, scpn int) BytecodeValue {
715715 case OC_blor:
716716 v2 := sys.bcStack.Pop()
717717 be.blor(sys.bcStack.Top(), v2)
718+ case OC_ifelse:
719+ v3 := sys.bcStack.Pop()
720+ v2 := sys.bcStack.Pop()
721+ if sys.bcStack.Top().ToB() {
722+ *sys.bcStack.Top() = v2
723+ } else {
724+ *sys.bcStack.Top() = v3
725+ }
718726 case OC_pop:
719727 sys.bcStack.Pop()
720728 case OC_dup:
721729 sys.bcStack.Dup()
722730 case OC_swap:
723731 sys.bcStack.Swap()
732+ case OC_run:
733+ l := int(*(*int32)(unsafe.Pointer(&be[i])))
734+ sys.bcStack.Push(be[i+4:i+4+l].run(c, scpn))
735+ i += 4 + l
724736 case OC_time:
725737 sys.bcStack.Push(BytecodeInt(c.time()))
738+ case OC_alive:
739+ sys.bcStack.Push(BytecodeBool(c.alive()))
740+ case OC_random:
741+ sys.bcStack.Push(BytecodeInt(Rand(0, 999)))
726742 default:
727743 unimplemented()
728744 }
745+ c = orgc
729746 }
730747 return sys.bcStack.Pop()
731748 }
@@ -783,7 +800,7 @@ func (scb *StateControllerBase) add(id byte, exp []BytecodeExp) {
783800 }
784801 }
785802 func (scb StateControllerBase) run(c *Char, ps *int32,
786- f func(byte, []BytecodeExp)) bool {
803+ f func(byte, []BytecodeExp) bool) bool {
787804 (*ps)--
788805 if *ps > 0 {
789806 return false
@@ -804,8 +821,8 @@ func (scb StateControllerBase) run(c *Char, ps *int32,
804821 if !exp[0].evalB(c, scb.playerNo) {
805822 return false
806823 }
807- } else {
808- f(id, exp)
824+ } else if !f(id, exp) {
825+ break
809826 }
810827 }
811828 *ps = scb.persistent
@@ -828,7 +845,7 @@ const (
828845 )
829846
830847 func (sc stateDef) Run(c *Char, ps *int32) bool {
831- StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
848+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
832849 switch id {
833850 case stateDef_hitcountpersist:
834851 if !exp[0].evalB(c, sc.playerNo) {
@@ -865,6 +882,7 @@ func (sc stateDef) Run(c *Char, ps *int32) bool {
865882 case stateDef_poweradd:
866883 c.addPower(exp[0].evalI(c, sc.playerNo))
867884 }
885+ return true
868886 })
869887 return false
870888 }
@@ -879,7 +897,7 @@ const (
879897
880898 func (sc hitBy) Run(c *Char, ps *int32) bool {
881899 time := int32(1)
882- StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
900+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
883901 switch id {
884902 case hitBy_time:
885903 time = exp[0].evalI(c, sc.playerNo)
@@ -888,6 +906,7 @@ func (sc hitBy) Run(c *Char, ps *int32) bool {
888906 case hitBy_value2:
889907 unimplemented()
890908 }
909+ return true
891910 })
892911 return false
893912 }
@@ -896,7 +915,7 @@ type notHitBy hitBy
896915
897916 func (sc notHitBy) Run(c *Char, ps *int32) bool {
898917 time := int32(1)
899- StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
918+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
900919 switch id {
901920 case hitBy_time:
902921 time = exp[0].evalI(c, sc.playerNo)
@@ -905,15 +924,273 @@ func (sc notHitBy) Run(c *Char, ps *int32) bool {
905924 case hitBy_value2:
906925 unimplemented()
907926 }
927+ return true
908928 })
909929 return false
910930 }
911931
912932 type assertSpecial StateControllerBase
913933
934+const (
935+ assertSpecial_flag byte = iota
936+ assertSpecial_flag_g
937+)
938+
914939 func (sc assertSpecial) Run(c *Char, ps *int32) bool {
915- StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) {
940+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
941+ switch id {
942+ case assertSpecial_flag:
943+ unimplemented()
944+ case assertSpecial_flag_g:
945+ sys.specialFlag |= GlobalSpecialFlag(exp[0].evalI(c, sc.playerNo))
946+ }
947+ return true
948+ })
949+ return false
950+}
951+
952+type playSnd StateControllerBase
953+
954+const (
955+ playSnd_value = iota
956+ playSnd_channel
957+ playSnd_lowpriority
958+ playSnd_pan
959+ playSnd_abspan
960+ playSnd_volume
961+ playSnd_freqmul
962+ playSnd_loop
963+)
964+
965+func (sc playSnd) Run(c *Char, ps *int32) bool {
966+ f, lw, lp := false, false, false
967+ var g, n, ch, vo int32 = -1, 0, -1, 0
968+ if sys.cgi[sc.playerNo].ver[0] == 1 {
969+ vo = 100
970+ }
971+ var p, fr float32 = 0, 1
972+ x := &c.pos[0]
973+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
974+ switch id {
975+ case playSnd_value:
976+ f = exp[0].evalB(c, sc.playerNo)
977+ g = exp[1].evalI(c, sc.playerNo)
978+ if len(exp) > 2 {
979+ n = exp[2].evalI(c, sc.playerNo)
980+ }
981+ case playSnd_channel:
982+ ch = exp[0].evalI(c, sc.playerNo)
983+ case playSnd_lowpriority:
984+ lw = exp[0].evalB(c, sc.playerNo)
985+ case playSnd_pan:
986+ p = exp[0].evalF(c, sc.playerNo)
987+ case playSnd_abspan:
988+ x = nil
989+ p = exp[0].evalF(c, sc.playerNo)
990+ case playSnd_volume:
991+ vo = exp[0].evalI(c, sc.playerNo)
992+ case playSnd_freqmul:
993+ fr = exp[0].evalF(c, sc.playerNo)
994+ case playSnd_loop:
995+ lp = exp[0].evalB(c, sc.playerNo)
996+ }
997+ return true
998+ })
999+ c.playSound(f, lw, lp, g, n, ch, vo, p, fr, x)
1000+ return false
1001+}
1002+
1003+type changeState StateControllerBase
1004+
1005+const (
1006+ changeState_value byte = iota
1007+ changeState_ctrl
1008+ changeState_anim
1009+)
1010+
1011+func (sc changeState) Run(c *Char, ps *int32) bool {
1012+ var v, a, ctrl int32 = -1, -1, -1
1013+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1014+ switch id {
1015+ case changeState_value:
1016+ v = exp[0].evalI(c, sc.playerNo)
1017+ case changeState_ctrl:
1018+ ctrl = exp[0].evalI(c, sc.playerNo)
1019+ case changeState_anim:
1020+ a = exp[0].evalI(c, sc.playerNo)
1021+ }
1022+ return true
1023+ })
1024+ c.changeState(v, a, ctrl)
1025+ return true
1026+}
1027+
1028+type selfState changeState
1029+
1030+func (sc selfState) Run(c *Char, ps *int32) bool {
1031+ var v, a, ctrl int32 = -1, -1, -1
1032+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1033+ switch id {
1034+ case changeState_value:
1035+ v = exp[0].evalI(c, sc.playerNo)
1036+ case changeState_ctrl:
1037+ ctrl = exp[0].evalI(c, sc.playerNo)
1038+ case changeState_anim:
1039+ a = exp[0].evalI(c, sc.playerNo)
1040+ }
1041+ return true
1042+ })
1043+ c.selfState(v, a, ctrl)
1044+ return true
1045+}
1046+
1047+type tagIn StateControllerBase
1048+
1049+const (
1050+ tagIn_stateno = iota
1051+ tagIn_partnerstateno
1052+)
1053+
1054+func (sc tagIn) Run(c *Char, ps *int32) bool {
1055+ var p *Char
1056+ sn := int32(-1)
1057+ ret := false
1058+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1059+ if p == nil {
1060+ p = c.partner(0)
1061+ if p == nil {
1062+ return false
1063+ }
1064+ }
1065+ switch id {
1066+ case tagIn_stateno:
1067+ sn = exp[0].evalI(c, sc.playerNo)
1068+ case tagIn_partnerstateno:
1069+ if psn := exp[0].evalI(c, sc.playerNo); psn >= 0 {
1070+ if sn >= 0 {
1071+ c.changeState(sn, -1, -1)
1072+ }
1073+ p.standby = false
1074+ p.changeState(psn, -1, -1)
1075+ ret = true
1076+ } else {
1077+ return false
1078+ }
1079+ }
1080+ return true
1081+ })
1082+ return ret
1083+}
1084+
1085+type tagOut StateControllerBase
1086+
1087+const (
1088+ tagOut_ = iota
1089+)
1090+
1091+func (sc tagOut) Run(c *Char, ps *int32) bool {
1092+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1093+ switch id {
1094+ case tagOut_:
1095+ c.standby = true
1096+ }
1097+ return true
1098+ })
1099+ return true
1100+}
1101+
1102+type destroySelf StateControllerBase
1103+
1104+const (
1105+ destroySelf_recursive = iota
1106+ destroySelf_removeexplods
1107+)
1108+
1109+func (sc destroySelf) Run(c *Char, ps *int32) bool {
1110+ rec, rem := false, false
1111+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1112+ switch id {
1113+ case destroySelf_recursive:
1114+ rec = exp[0].evalB(c, sc.playerNo)
1115+ case destroySelf_removeexplods:
1116+ rem = exp[0].evalB(c, sc.playerNo)
1117+ }
1118+ return true
1119+ })
1120+ return c.destroySelf(rec, rem)
1121+}
1122+
1123+type changeAnim StateControllerBase
1124+
1125+const (
1126+ changeAnim_elem byte = iota
1127+ changeAnim_value
1128+)
1129+
1130+func (sc changeAnim) Run(c *Char, ps *int32) bool {
1131+ var elem int32
1132+ setelem := false
1133+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1134+ switch id {
1135+ case changeAnim_elem:
1136+ elem = exp[0].evalI(c, sc.playerNo)
1137+ setelem = true
1138+ case changeAnim_value:
1139+ c.changeAnim(exp[0].evalI(c, sc.playerNo))
1140+ if setelem {
1141+ c.setAnimElem(elem)
1142+ }
1143+ }
1144+ return true
1145+ })
1146+ return false
1147+}
1148+
1149+type changeAnim2 changeAnim
1150+
1151+func (sc changeAnim2) Run(c *Char, ps *int32) bool {
1152+ var elem int32
1153+ setelem := false
1154+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1155+ switch id {
1156+ case changeAnim_elem:
1157+ elem = exp[0].evalI(c, sc.playerNo)
1158+ setelem = true
1159+ case changeAnim_value:
1160+ c.changeAnim2(exp[0].evalI(c, sc.playerNo))
1161+ if setelem {
1162+ c.setAnimElem(elem)
1163+ }
1164+ }
1165+ return true
1166+ })
1167+ return false
1168+}
1169+
1170+type helper StateControllerBase
1171+
1172+const (
1173+ helper_helpertype byte = iota
1174+ helper_name
1175+)
1176+
1177+func (sc helper) Run(c *Char, ps *int32) bool {
1178+ var h *Char
1179+ StateControllerBase(sc).run(c, ps, func(id byte, exp []BytecodeExp) bool {
1180+ if h == nil {
1181+ h = c.newHelper()
1182+ if h == nil {
1183+ return false
1184+ }
1185+ }
1186+ switch id {
1187+ case helper_helpertype:
1188+ h.player = exp[0].evalB(c, sc.playerNo)
1189+ case helper_name:
1190+ h.name = string(*(*[]byte)(unsafe.Pointer(&exp[0])))
1191+ }
9161192 unimplemented()
1193+ return true
9171194 })
9181195 return false
9191196 }
--- a/src/char.go
+++ b/src/char.go
@@ -5,6 +5,36 @@ import (
55 "strings"
66 )
77
8+type CharSpecialFlag uint32
9+
10+const (
11+ CSF_nostandguard CharSpecialFlag = 1 << iota
12+ CSF_nocrouchguard
13+ CSF_noairguard
14+ CSF_noshadow
15+ CSF_invisible
16+ CSF_unguardable
17+ CSF_nojugglecheck
18+ CSF_noautoturn
19+ CSF_nowalk
20+)
21+
22+type GlobalSpecialFlag uint32
23+
24+const (
25+ GSF_intro GlobalSpecialFlag = 1 << iota
26+ GSF_roundnotover
27+ GSF_nomusic
28+ GSF_nobardisplay
29+ GSF_nobg
30+ GSF_nofg
31+ GSF_globalnoshadow
32+ GSF_timerfreeze
33+ GSF_nokosnd
34+ GSF_nokoslow
35+ GSF_noko
36+)
37+
838 type CharData struct {
939 life int32
1040 power int32
@@ -279,6 +309,9 @@ type Char struct {
279309 sprpriority int32
280310 juggle int32
281311 size CharSize
312+ pos [2]float32
313+ vel [2]float32
314+ standby bool
282315 }
283316
284317 func newChar(n, idx int) (c *Char) {
@@ -554,14 +587,20 @@ func (c *Char) setJuggle(juggle int32) {
554587 c.juggle = juggle
555588 }
556589 func (c *Char) setXV(xv float32) {
557- unimplemented()
590+ c.vel[0] = xv
558591 }
559592 func (c *Char) setYV(yv float32) {
560- unimplemented()
593+ c.vel[1] = yv
561594 }
562595 func (c *Char) changeAnim(animNo int32) {
563596 unimplemented()
564597 }
598+func (c *Char) changeAnim2(animNo int32) {
599+ unimplemented()
600+}
601+func (c *Char) setAnimElem(e int32) {
602+ unimplemented()
603+}
565604 func (c *Char) setCtrl(ctrl bool) {
566605 unimplemented()
567606 }
@@ -572,3 +611,47 @@ func (c *Char) time() int32 {
572611 unimplemented()
573612 return 0
574613 }
614+func (c *Char) alive() bool {
615+ unimplemented()
616+ return false
617+}
618+func (c *Char) playSound(f, lw, lp bool, g, n, ch, vo int32,
619+ p, fr float32, x *float32) {
620+ unimplemented()
621+}
622+func (c *Char) changeState(no, anim, ctrl int32) {
623+ unimplemented()
624+}
625+func (c *Char) selfState(no, anim, ctrl int32) {
626+ unimplemented()
627+}
628+func (c *Char) partner(n int32) *Char {
629+ n = Max(0, n)
630+ if int(n) > len(sys.chars)/2-2 {
631+ return nil
632+ }
633+ var p int
634+ if int(n) == c.playerNo>>1 {
635+ p = c.playerNo + 2
636+ } else {
637+ p = c.playerNo&1 + int(n)<<1
638+ if int(n) > c.playerNo>>1 {
639+ p += 2
640+ }
641+ }
642+ if len(sys.chars[p]) > 0 {
643+ return sys.chars[p][0]
644+ }
645+ return nil
646+}
647+func (c *Char) destroySelf(recursive, removeexplods bool) bool {
648+ if c.helperIndex <= 0 {
649+ return false
650+ }
651+ unimplemented()
652+ return true
653+}
654+func (c *Char) newHelper() *Char {
655+ unimplemented()
656+ return nil
657+}
--- a/src/common.go
+++ b/src/common.go
@@ -150,6 +150,9 @@ func Atof(str string) float64 {
150150 return f
151151 }
152152 func readDigit(d string) (int32, bool) {
153+ if len(d) == 0 || (len(d) >= 2 && d[0] == '0') {
154+ return 0, false
155+ }
153156 for _, c := range d {
154157 if c < '0' || c > '9' {
155158 return 0, false
--- a/src/compiler.go
+++ b/src/compiler.go
@@ -310,7 +310,6 @@ func (c *Compiler) kakkotojiru(in *string) error {
310310 if c.token != ")" {
311311 return Error(c.token + "の前に')'がありません")
312312 }
313- c.token = c.tokenizer(in)
314313 return nil
315314 }
316315 func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
@@ -324,9 +323,56 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string) (BytecodeValue,
324323 if !sys.ignoreMostErrors {
325324 defer func() { c.usiroOp = false }()
326325 }
326+ var be1, be2, be3 BytecodeExp
327+ var bv1, bv2, bv3 BytecodeValue
328+ var err error
327329 switch c.token {
328330 case "time":
329331 out.append(OC_time)
332+ case "alive":
333+ out.append(OC_alive)
334+ case "ifelse":
335+ if c.tokenizer(in) != "(" {
336+ return BytecodeSF(), Error(c.token + "の次に'('がありません")
337+ }
338+ c.token = c.tokenizer(in)
339+ if bv1, err = c.expBoolOr(&be1, in); err != nil {
340+ return BytecodeSF(), err
341+ }
342+ if c.token != "," {
343+ return BytecodeSF(), Error("','がありません")
344+ }
345+ c.token = c.tokenizer(in)
346+ if bv2, err = c.expBoolOr(&be2, in); err != nil {
347+ return BytecodeSF(), err
348+ }
349+ if c.token != "," {
350+ return BytecodeSF(), Error("','がありません")
351+ }
352+ c.token = c.tokenizer(in)
353+ if bv3, err = c.expBoolOr(&be3, in); err != nil {
354+ return BytecodeSF(), err
355+ }
356+ if err := c.kakkotojiru(in); err != nil {
357+ return BytecodeSF(), err
358+ }
359+ if bv1.IsSF() || bv2.IsSF() || bv3.IsSF() {
360+ out.append(be1...)
361+ out.appendValue(bv1)
362+ out.append(be2...)
363+ out.appendValue(bv2)
364+ out.append(be3...)
365+ out.appendValue(bv3)
366+ out.append(OC_ifelse)
367+ } else {
368+ if bv1.ToB() {
369+ bv = bv2
370+ } else {
371+ bv = bv3
372+ }
373+ }
374+ case "random":
375+ out.append(OC_random)
330376 default:
331377 println(c.token)
332378 unimplemented()
@@ -409,14 +455,14 @@ func (c *Compiler) expPow(out *BytecodeExp, in *string) (BytecodeValue,
409455 if err != nil {
410456 return BytecodeSF(), err
411457 }
412- if !bv.IsSF() && !bv2.IsSF() {
413- out.pow(&bv, bv2, c.playerNo)
414- } else {
458+ if bv.IsSF() || bv2.IsSF() {
415459 out.appendValue(bv)
416460 out.append(be...)
417461 out.appendValue(bv2)
418462 out.append(OC_pow)
419463 bv = BytecodeSF()
464+ } else {
465+ out.pow(&bv, bv2, c.playerNo)
420466 }
421467 } else {
422468 break
@@ -523,19 +569,20 @@ func (c *Compiler) expRange(out *BytecodeExp, in *string,
523569 if err := c.kakkotojiru(in); err != nil {
524570 return err
525571 }
526- if !bv.IsSF() && !bv2.IsSF() {
572+ c.token = c.tokenizer(in)
573+ if bv.IsSF() || bv2.IsSF() {
574+ out.appendValue(*bv)
575+ out.append(be2...)
576+ out.appendValue(bv2)
577+ out.append(opc)
578+ *bv = BytecodeSF()
579+ } else {
527580 switch opc {
528581 case OC_eq:
529582 out.eq(bv, bv2)
530583 case OC_ne:
531584 out.ne(bv, bv2)
532585 }
533- } else {
534- out.appendValue(*bv)
535- out.append(be2...)
536- out.appendValue(bv2)
537- out.append(opc)
538- *bv = BytecodeSF()
539586 }
540587 return nil
541588 }
@@ -546,23 +593,7 @@ func (c *Compiler) expRange(out *BytecodeExp, in *string,
546593 return Error("]か)がありません")
547594 }
548595 c.token = c.tokenizer(in)
549- if !bv.IsSF() && !bv2.IsSF() && !bv3.IsSF() {
550- tmp := *bv
551- if open == "(" {
552- out.gt(&tmp, bv2)
553- } else {
554- out.ge(&tmp, bv2)
555- }
556- if close == ")" {
557- out.lt(bv, bv3)
558- } else {
559- out.le(bv, bv3)
560- }
561- bv.SetB(tmp.ToB() && bv.ToB())
562- if opc == OC_ne {
563- bv.SetB(!bv.ToB())
564- }
565- } else {
596+ if bv.IsSF() || bv2.IsSF() || bv3.IsSF() {
566597 var op1, op2, op3 OpCode
567598 if opc == OC_ne {
568599 if open == "(" {
@@ -600,6 +631,22 @@ func (c *Compiler) expRange(out *BytecodeExp, in *string,
600631 out.append(op2)
601632 out.append(op3)
602633 *bv = BytecodeSF()
634+ } else {
635+ tmp := *bv
636+ if open == "(" {
637+ out.gt(&tmp, bv2)
638+ } else {
639+ out.ge(&tmp, bv2)
640+ }
641+ if close == ")" {
642+ out.lt(bv, bv3)
643+ } else {
644+ out.le(bv, bv3)
645+ }
646+ bv.SetB(tmp.ToB() && bv.ToB())
647+ if opc == OC_ne {
648+ bv.SetB(!bv.ToB())
649+ }
603650 }
604651 return nil
605652 }
@@ -653,14 +700,14 @@ func (_ *Compiler) expOneOpSub(out *BytecodeExp, in *string, bv *BytecodeValue,
653700 if err != nil {
654701 return err
655702 }
656- if !bv.IsSF() && !bv2.IsSF() {
657- opf(bv, bv2)
658- } else {
703+ if bv.IsSF() || bv2.IsSF() {
659704 out.appendValue(*bv)
660705 out.append(be...)
661706 out.appendValue(bv2)
662707 out.append(opc)
663708 *bv = BytecodeSF()
709+ } else {
710+ opf(bv, bv2)
664711 }
665712 return nil
666713 }
@@ -853,7 +900,7 @@ func (c *Compiler) stateParam(is IniSection, name string,
853900 return nil
854901 }
855902 func (c *Compiler) scAdd(sc *StateControllerBase, id byte,
856- data string, vt ValueType, numArg int) error {
903+ data string, vt ValueType, numArg int, topbe ...BytecodeExp) error {
857904 bes := []BytecodeExp{}
858905 for n := 1; n <= numArg; n++ {
859906 var be BytecodeExp
@@ -871,7 +918,7 @@ func (c *Compiler) scAdd(sc *StateControllerBase, id byte,
871918 break
872919 }
873920 }
874- sc.add(id, bes)
921+ sc.add(id, append(topbe, bes...))
875922 return nil
876923 }
877924 func (c *Compiler) stateDef(is IniSection, sbc *StateBytecode) error {
@@ -1063,6 +1110,287 @@ func (c *Compiler) notHitBy(is IniSection, sbc *StateBytecode,
10631110 func (c *Compiler) assertSpecial(is IniSection, sbc *StateBytecode,
10641111 sc *StateControllerBase) (StateController, error) {
10651112 return assertSpecial(*sc), c.stateSec(is, func() error {
1113+ foo := func(data string) error {
1114+ switch data {
1115+ case "nostandguard":
1116+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_nostandguard)))
1117+ case "nocrouchguard":
1118+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_nocrouchguard)))
1119+ case "noairguard":
1120+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_noairguard)))
1121+ case "noshadow":
1122+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_noshadow)))
1123+ case "invisible":
1124+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_invisible)))
1125+ case "unguardable":
1126+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_unguardable)))
1127+ case "nojugglecheck":
1128+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_nojugglecheck)))
1129+ case "noautoturn":
1130+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_noautoturn)))
1131+ case "nowalk":
1132+ sc.add(assertSpecial_flag, sc.iToExp(int32(CSF_nowalk)))
1133+ case "intro":
1134+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_intro)))
1135+ case "roundnotover":
1136+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_roundnotover)))
1137+ case "nomusic":
1138+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nomusic)))
1139+ case "nobardisplay":
1140+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nobardisplay)))
1141+ case "nobg":
1142+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nobg)))
1143+ case "nofg":
1144+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nofg)))
1145+ case "globalnoshadow":
1146+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_globalnoshadow)))
1147+ case "timerfreeze":
1148+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_timerfreeze)))
1149+ case "nokosnd":
1150+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nokosnd)))
1151+ case "nokoslow":
1152+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_nokoslow)))
1153+ case "noko":
1154+ sc.add(assertSpecial_flag_g, sc.iToExp(int32(GSF_noko)))
1155+ default:
1156+ return Error(data + "が無効な値です")
1157+ }
1158+ return nil
1159+ }
1160+ f := false
1161+ if err := c.stateParam(is, "flag", func(data string) error {
1162+ f = true
1163+ return foo(data)
1164+ }); err != nil {
1165+ return err
1166+ }
1167+ if !f {
1168+ return Error("flagが指定されていません")
1169+ }
1170+ if err := c.stateParam(is, "flag2", func(data string) error {
1171+ return foo(data)
1172+ }); err != nil {
1173+ return err
1174+ }
1175+ if err := c.stateParam(is, "flag3", func(data string) error {
1176+ return foo(data)
1177+ }); err != nil {
1178+ return err
1179+ }
1180+ return nil
1181+ })
1182+}
1183+func (c *Compiler) playSnd(is IniSection, sbc *StateBytecode,
1184+ sc *StateControllerBase) (StateController, error) {
1185+ return playSnd(*sc), c.stateSec(is, func() error {
1186+ f := false
1187+ if err := c.stateParam(is, "value", func(data string) error {
1188+ f = true
1189+ fflg := false
1190+ if len(data) > 0 {
1191+ switch data[0] {
1192+ case 'F', 'f':
1193+ fflg = true
1194+ data = data[1:]
1195+ case 'S', 's':
1196+ data = data[1:]
1197+ }
1198+ }
1199+ return c.scAdd(sc, playSnd_value, data, VT_Int, 2,
1200+ sc.iToExp(Btoi(fflg))...)
1201+ }); err != nil {
1202+ return err
1203+ }
1204+ if !f {
1205+ return Error("valueが指定されていません")
1206+ }
1207+ if err := c.stateParam(is, "channel", func(data string) error {
1208+ return c.scAdd(sc, playSnd_channel, data, VT_Int, 1)
1209+ }); err != nil {
1210+ return err
1211+ }
1212+ if err := c.stateParam(is, "lowpriority", func(data string) error {
1213+ return c.scAdd(sc, playSnd_lowpriority, data, VT_Bool, 1)
1214+ }); err != nil {
1215+ return err
1216+ }
1217+ if err := c.stateParam(is, "pan", func(data string) error {
1218+ return c.scAdd(sc, playSnd_pan, data, VT_Float, 1)
1219+ }); err != nil {
1220+ return err
1221+ }
1222+ if err := c.stateParam(is, "abspan", func(data string) error {
1223+ return c.scAdd(sc, playSnd_abspan, data, VT_Float, 1)
1224+ }); err != nil {
1225+ return err
1226+ }
1227+ var volname string
1228+ if sys.cgi[c.playerNo].ver[0] == 1 {
1229+ volname = "volumescale"
1230+ } else {
1231+ volname = "volume"
1232+ }
1233+ if err := c.stateParam(is, volname, func(data string) error {
1234+ return c.scAdd(sc, playSnd_volume, data, VT_Int, 1)
1235+ }); err != nil {
1236+ return err
1237+ }
1238+ if err := c.stateParam(is, "freqmul", func(data string) error {
1239+ return c.scAdd(sc, playSnd_freqmul, data, VT_Float, 1)
1240+ }); err != nil {
1241+ return err
1242+ }
1243+ if err := c.stateParam(is, "loop", func(data string) error {
1244+ return c.scAdd(sc, playSnd_loop, data, VT_Bool, 1)
1245+ }); err != nil {
1246+ return err
1247+ }
1248+ return nil
1249+ })
1250+}
1251+func (c *Compiler) changeStateSub(is IniSection,
1252+ sc *StateControllerBase) error {
1253+ f := false
1254+ if err := c.stateParam(is, "value", func(data string) error {
1255+ f = true
1256+ return c.scAdd(sc, changeState_value, data, VT_Int, 1)
1257+ }); err != nil {
1258+ return err
1259+ }
1260+ if !f {
1261+ return Error("valueが指定されていません")
1262+ }
1263+ if err := c.stateParam(is, "ctrl", func(data string) error {
1264+ return c.scAdd(sc, changeState_ctrl, data, VT_Int, 1)
1265+ }); err != nil {
1266+ return err
1267+ }
1268+ if err := c.stateParam(is, "anim", func(data string) error {
1269+ return c.scAdd(sc, changeState_anim, data, VT_Int, 1)
1270+ }); err != nil {
1271+ return err
1272+ }
1273+ return nil
1274+}
1275+func (c *Compiler) changeState(is IniSection, sbc *StateBytecode,
1276+ sc *StateControllerBase) (StateController, error) {
1277+ return changeState(*sc), c.stateSec(is, func() error {
1278+ return c.changeStateSub(is, sc)
1279+ })
1280+}
1281+func (c *Compiler) selfState(is IniSection, sbc *StateBytecode,
1282+ sc *StateControllerBase) (StateController, error) {
1283+ return selfState(*sc), c.stateSec(is, func() error {
1284+ return c.changeStateSub(is, sc)
1285+ })
1286+}
1287+func (c *Compiler) tagIn(is IniSection, sbc *StateBytecode,
1288+ sc *StateControllerBase) (StateController, error) {
1289+ return tagIn(*sc), c.stateSec(is, func() error {
1290+ f := false
1291+ if err := c.stateParam(is, "stateno", func(data string) error {
1292+ f = true
1293+ return c.scAdd(sc, tagIn_stateno, data, VT_Int, 1)
1294+ }); err != nil {
1295+ return err
1296+ }
1297+ if !f {
1298+ return Error("statenoが指定されていません")
1299+ }
1300+ f = false
1301+ if err := c.stateParam(is, "partnerstateno", func(data string) error {
1302+ f = true
1303+ return c.scAdd(sc, tagIn_partnerstateno, data, VT_Int, 1)
1304+ }); err != nil {
1305+ return err
1306+ }
1307+ if !f {
1308+ sc.add(tagIn_partnerstateno, sc.iToExp(-1))
1309+ }
1310+ return nil
1311+ })
1312+}
1313+func (c *Compiler) tagOut(is IniSection, sbc *StateBytecode,
1314+ sc *StateControllerBase) (StateController, error) {
1315+ return tagOut(*sc), c.stateSec(is, func() error {
1316+ sc.add(tagOut_, nil)
1317+ return nil
1318+ })
1319+}
1320+func (c *Compiler) destroySelf(is IniSection, sbc *StateBytecode,
1321+ sc *StateControllerBase) (StateController, error) {
1322+ return destroySelf(*sc), c.stateSec(is, func() error {
1323+ if err := c.stateParam(is, "recursive", func(data string) error {
1324+ return c.scAdd(sc, destroySelf_recursive, data, VT_Bool, 1)
1325+ }); err != nil {
1326+ return err
1327+ }
1328+ if err := c.stateParam(is, "removeexplods", func(data string) error {
1329+ return c.scAdd(sc, destroySelf_removeexplods, data, VT_Bool, 1)
1330+ }); err != nil {
1331+ return err
1332+ }
1333+ return nil
1334+ })
1335+}
1336+func (c *Compiler) changeAnimSub(is IniSection,
1337+ sc *StateControllerBase) error {
1338+ if err := c.stateParam(is, "elem", func(data string) error {
1339+ return c.scAdd(sc, changeAnim_elem, data, VT_Int, 1)
1340+ }); err != nil {
1341+ return err
1342+ }
1343+ f := false
1344+ if err := c.stateParam(is, "value", func(data string) error {
1345+ f = true
1346+ return c.scAdd(sc, changeAnim_value, data, VT_Int, 1)
1347+ }); err != nil {
1348+ return err
1349+ }
1350+ if !f {
1351+ return Error("valueが指定されていません")
1352+ }
1353+ return nil
1354+}
1355+func (c *Compiler) changeAnim(is IniSection, sbc *StateBytecode,
1356+ sc *StateControllerBase) (StateController, error) {
1357+ return changeAnim(*sc), c.stateSec(is, func() error {
1358+ return c.changeAnimSub(is, sc)
1359+ })
1360+}
1361+func (c *Compiler) changeAnim2(is IniSection, sbc *StateBytecode,
1362+ sc *StateControllerBase) (StateController, error) {
1363+ return changeAnim2(*sc), c.stateSec(is, func() error {
1364+ return c.changeAnimSub(is, sc)
1365+ })
1366+}
1367+func (c *Compiler) helper(is IniSection, sbc *StateBytecode,
1368+ sc *StateControllerBase) (StateController, error) {
1369+ return helper(*sc), c.stateSec(is, func() error {
1370+ if err := c.stateParam(is, "helpertype", func(data string) error {
1371+ if len(data) == 0 {
1372+ return Error("値が指定されていません")
1373+ }
1374+ switch strings.ToLower(data)[0] {
1375+ case 'n':
1376+ case 'p':
1377+ sc.add(helper_helpertype, sc.iToExp(1))
1378+ default:
1379+ return Error(data + "が無効な値です")
1380+ }
1381+ return nil
1382+ }); err != nil {
1383+ return err
1384+ }
1385+ if err := c.stateParam(is, "name", func(data string) error {
1386+ if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
1387+ return Error("\"で囲まれていません")
1388+ }
1389+ sc.add(helper_name, sc.beToExp(BytecodeExp(data[1:len(data)-1])))
1390+ return nil
1391+ }); err != nil {
1392+ return err
1393+ }
10661394 unimplemented()
10671395 return nil
10681396 })
@@ -1130,6 +1458,24 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
11301458 scf = c.notHitBy
11311459 case "assertspecial":
11321460 scf = c.assertSpecial
1461+ case "playsnd":
1462+ scf = c.playSnd
1463+ case "changestate":
1464+ scf = c.changeState
1465+ case "selfstate":
1466+ scf = c.selfState
1467+ case "tagin":
1468+ scf = c.tagIn
1469+ case "tagout":
1470+ scf = c.tagOut
1471+ case "destroyself":
1472+ scf = c.destroySelf
1473+ case "changeanim":
1474+ scf = c.changeAnim
1475+ case "changeanim2":
1476+ scf = c.changeAnim2
1477+ case "helper":
1478+ scf = c.helper
11331479 default:
11341480 println(data)
11351481 unimplemented()
@@ -1159,7 +1505,7 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
11591505 }
11601506 default:
11611507 tn, ok := readDigit(name[7:])
1162- if !ok || tn <= 0 || tn > 65536 {
1508+ if !ok || tn < 1 || tn > 65536 {
11631509 errmes(Error("トリガー名 (" + name + ") が不正です"))
11641510 }
11651511 if len(trigger) < int(tn) {
@@ -1208,12 +1554,10 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
12081554 }
12091555 var texp BytecodeExp
12101556 for i, e := range triggerall {
1211- if len(e) > 0 {
1212- texp.append(e...)
1213- if i < len(triggerall)-1 {
1214- texp.append(OC_jz8, 0)
1215- texp.append(OC_pop)
1216- }
1557+ texp.append(e...)
1558+ if i < len(triggerall)-1 {
1559+ texp.append(OC_jz8, 0)
1560+ texp.append(OC_pop)
12171561 }
12181562 }
12191563 if allUtikiri {
@@ -1232,18 +1576,16 @@ func (c *Compiler) stateCompile(bc *Bytecode, filename, def string) error {
12321576 oldlen := len(te)
12331577 for j := len(tr) - 1; j >= 0; j-- {
12341578 tmp := tr[j]
1235- if len(tmp) > 0 {
1236- if j < len(tr)-1 {
1237- if len(te) > int(math.MaxUint8-1) {
1238- tmp.appendJmp(OC_jz, int32(len(te)+1))
1239- tmp.append(OC_pop)
1240- } else {
1241- tmp.append(OC_jz8, OpCode(len(te)+1))
1242- tmp.append(OC_pop)
1243- }
1579+ if j < len(tr)-1 {
1580+ if len(te) > int(math.MaxUint8-1) {
1581+ tmp.appendJmp(OC_jz, int32(len(te)+1))
1582+ tmp.append(OC_pop)
1583+ } else {
1584+ tmp.append(OC_jz8, OpCode(len(te)+1))
1585+ tmp.append(OC_pop)
12441586 }
1245- te = append(tmp, te...)
12461587 }
1588+ te = append(tmp, te...)
12471589 }
12481590 if len(te) == oldlen {
12491591 te = nil
--- a/src/system.go
+++ b/src/system.go
@@ -94,6 +94,7 @@ type System struct {
9494 ignoreMostErrors bool
9595 stringPool [MaxSimul * 2]StringPool
9696 bcStack BytecodeStack
97+ specialFlag GlobalSpecialFlag
9798 }
9899
99100 func (s *System) init(w, h int32) *lua.LState {