-
Notifications
You must be signed in to change notification settings - Fork 5
/
oop.go
818 lines (779 loc) · 20.7 KB
/
oop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
package main // unit: Oop
// interface uses: GameVars
// implementation uses: Sounds, TxtWind, Game, Elements
func OopError(statId int16, message string) {
stat := &Board.Stats[statId]
DisplayMessage(200, "ERR: "+message)
SoundQueue(5, "P\n")
stat.DataPos = -1
}
func OopReadChar(statId int16, position *int16) {
stat := &Board.Stats[statId]
if *position >= 0 && *position < stat.DataLen {
OopChar = stat.Data[*position]
*position++
} else {
OopChar = '\x00'
}
}
func OopReadWord(statId int16, position *int16) {
OopWord = ""
for {
OopReadChar(statId, position)
if OopChar != ' ' {
break
}
}
OopChar = UpCase(OopChar)
if OopChar < '0' || OopChar > '9' {
for OopChar >= 'A' && OopChar <= 'Z' || OopChar == ':' || OopChar >= '0' && OopChar <= '9' || OopChar == '_' {
OopWord += string([]byte{OopChar})
OopReadChar(statId, position)
OopChar = UpCase(OopChar)
}
}
if *position > 0 {
*position--
}
}
func OopReadValue(statId int16, position *int16) {
var (
s string
code int16
)
s = ""
for {
OopReadChar(statId, position)
if OopChar != ' ' {
break
}
}
OopChar = UpCase(OopChar)
for OopChar >= '0' && OopChar <= '9' {
s += string([]byte{OopChar})
OopReadChar(statId, position)
OopChar = UpCase(OopChar)
}
if *position > 0 {
*position--
}
if Length(s) != 0 {
OopValue = Val(s, &code)
} else {
OopValue = -1
}
}
func OopSkipLine(statId int16, position *int16) {
for {
OopReadChar(statId, position)
if OopChar == '\x00' || OopChar == '\r' {
break
}
}
}
func OopParseDirection(statId int16, position *int16, dx, dy *int16) (OopParseDirection_ bool) {
stat := &Board.Stats[statId]
OopParseDirection_ = true
if OopWord == "N" || OopWord == "NORTH" {
*dx = 0
*dy = -1
} else if OopWord == "S" || OopWord == "SOUTH" {
*dx = 0
*dy = 1
} else if OopWord == "E" || OopWord == "EAST" {
*dx = 1
*dy = 0
} else if OopWord == "W" || OopWord == "WEST" {
*dx = -1
*dy = 0
} else if OopWord == "I" || OopWord == "IDLE" {
*dx = 0
*dy = 0
} else if OopWord == "SEEK" {
CalcDirectionSeek(int16(stat.X), int16(stat.Y), dx, dy)
} else if OopWord == "FLOW" {
*dx = stat.StepX
*dy = stat.StepY
} else if OopWord == "RND" {
CalcDirectionRnd(dx, dy)
} else if OopWord == "RNDNS" {
*dx = 0
*dy = Random(2)*2 - 1
} else if OopWord == "RNDNE" {
*dx = Random(2)
if *dx == 0 {
*dy = -1
} else {
*dy = 0
}
} else if OopWord == "CW" {
OopReadWord(statId, position)
OopParseDirection_ = OopParseDirection(statId, position, dy, dx)
*dx = -*dx
} else if OopWord == "CCW" {
OopReadWord(statId, position)
OopParseDirection_ = OopParseDirection(statId, position, dy, dx)
*dy = -*dy
} else if OopWord == "RNDP" {
OopReadWord(statId, position)
OopParseDirection_ = OopParseDirection(statId, position, dy, dx)
if Random(2) == 0 {
*dx = -*dx
} else {
*dy = -*dy
}
} else if OopWord == "OPP" {
OopReadWord(statId, position)
OopParseDirection_ = OopParseDirection(statId, position, dx, dy)
*dx = -*dx
*dy = -*dy
} else {
*dx = 0
*dy = 0
OopParseDirection_ = false
}
return
}
func OopReadDirection(statId int16, position *int16, dx, dy *int16) {
OopReadWord(statId, position)
if !OopParseDirection(statId, position, dx, dy) {
OopError(statId, "Bad direction")
}
}
func OopFindString(statId int16, s string) (OopFindString int16) {
var pos, wordPos, cmpPos int16
stat := &Board.Stats[statId]
pos = 0
for pos <= stat.DataLen {
wordPos = 1
cmpPos = pos
for {
OopReadChar(statId, &cmpPos)
if UpCase(s[wordPos-1]) != UpCase(OopChar) {
goto NoMatch
}
wordPos++
if wordPos > Length(s) {
break
}
}
OopReadChar(statId, &cmpPos)
OopChar = UpCase(OopChar)
if OopChar >= 'A' && OopChar <= 'Z' || OopChar == '_' {
} else {
OopFindString = pos
return
}
NoMatch:
pos++
}
OopFindString = -1
return
}
func OopIterateStat(statId int16, iStat *int16, lookup string) (OopIterateStat bool) {
var (
pos int16
found bool
)
*iStat++
found = false
if lookup == "ALL" {
if *iStat <= Board.StatCount {
found = true
}
} else if lookup == "OTHERS" {
if *iStat <= Board.StatCount {
if *iStat != statId {
found = true
} else {
*iStat++
found = *iStat <= Board.StatCount
}
}
} else if lookup == "SELF" {
if statId > 0 && *iStat <= statId {
*iStat = statId
found = true
}
} else {
for *iStat <= Board.StatCount && !found {
if Board.Stats[*iStat].Data != "" {
pos = 0
OopReadChar(*iStat, &pos)
if OopChar == '@' {
OopReadWord(*iStat, &pos)
if OopWord == lookup {
found = true
}
}
}
if !found {
*iStat++
}
}
}
OopIterateStat = found
return
}
func OopFindLabel(statId int16, sendLabel string, iStat, iDataPos *int16, labelPrefix string) (OopFindLabel bool) {
var (
targetSplitPos int16
targetLookup string
objectMessage string
foundStat bool
)
foundStat = false
targetSplitPos = Pos(':', sendLabel)
if targetSplitPos <= 0 {
if *iStat < statId {
objectMessage = sendLabel
*iStat = statId
targetSplitPos = 0
foundStat = true
}
} else {
targetLookup = Copy(sendLabel, 1, targetSplitPos-1)
objectMessage = Copy(sendLabel, targetSplitPos+1, Length(sendLabel)-targetSplitPos)
foundStat = OopIterateStat(statId, iStat, targetLookup)
}
FindNextStat:
if foundStat {
if objectMessage == "RESTART" {
*iDataPos = 0
} else {
*iDataPos = OopFindString(*iStat, labelPrefix+objectMessage)
if *iDataPos < 0 && targetSplitPos > 0 {
foundStat = OopIterateStat(statId, iStat, targetLookup)
goto FindNextStat
}
}
foundStat = *iDataPos >= 0
}
OopFindLabel = foundStat
return
}
func WorldGetFlagPosition(name string) (WorldGetFlagPosition int16) {
var i int16
WorldGetFlagPosition = -1
for i = 1; i <= 10; i++ {
if World.Info.Flags[i-1] == name {
WorldGetFlagPosition = i
}
}
return
}
func WorldSetFlag(name string) {
var i int16
if WorldGetFlagPosition(name) < 0 {
i = 1
for i < MAX_FLAG && Length(World.Info.Flags[i-1]) != 0 {
i++
}
World.Info.Flags[i-1] = name
}
}
func WorldClearFlag(name string) {
if WorldGetFlagPosition(name) >= 0 {
World.Info.Flags[WorldGetFlagPosition(name)-1] = ""
}
}
func OopStringToWord(input string) (OopStringToWord string) {
var (
output string
i int16
)
output = ""
for i = 1; i <= Length(input); i++ {
if input[i-1] >= 'A' && input[i-1] <= 'Z' || input[i-1] >= '0' && input[i-1] <= '9' {
output += string([]byte{input[i-1]})
} else if input[i-1] >= 'a' && input[i-1] <= 'z' {
output += Chr(Ord(input[i-1]) - 0x20)
}
}
OopStringToWord = output
return
}
func OopParseTile(statId, position *int16, tile *TTile) (OopParseTile bool) {
var i int16
OopParseTile = false
tile.Color = 0
OopReadWord(*statId, position)
for i = 1; i <= 7; i++ {
if OopWord == OopStringToWord(ColorNames[i-1]) {
tile.Color = byte(i + 0x08)
OopReadWord(*statId, position)
goto ColorFound
}
}
ColorFound:
for i = 0; i <= MAX_ELEMENT; i++ {
if OopWord == OopStringToWord(ElementDefs[i].Name) {
OopParseTile = true
tile.Element = byte(i)
return
}
}
return
}
func GetColorForTileMatch(tile *TTile) (GetColorForTileMatch byte) {
if ElementDefs[tile.Element].Color < COLOR_SPECIAL_MIN {
GetColorForTileMatch = byte(int16(ElementDefs[tile.Element].Color) & 0x07)
} else if ElementDefs[tile.Element].Color == COLOR_WHITE_ON_CHOICE {
GetColorForTileMatch = byte(int16(tile.Color)>>4&0x0F + 8)
} else {
GetColorForTileMatch = byte(int16(tile.Color) & 0x0F)
}
return
}
func FindTileOnBoard(x, y *int16, tile TTile) (FindTileOnBoard bool) {
FindTileOnBoard = false
for true {
*x++
if *x > BOARD_WIDTH {
*x = 1
*y++
if *y > BOARD_HEIGHT {
return
}
}
if Board.Tiles[*x][*y].Element == tile.Element {
if tile.Color == 0 || GetColorForTileMatch(&Board.Tiles[*x][*y]) == tile.Color {
FindTileOnBoard = true
return
}
}
}
return
}
func OopPlaceTile(x, y int16, tile *TTile) {
var color byte
if Board.Tiles[x][y].Element != 4 {
color = tile.Color
if ElementDefs[tile.Element].Color < COLOR_SPECIAL_MIN {
color = ElementDefs[tile.Element].Color
} else {
if color == 0 {
color = Board.Tiles[x][y].Color
}
if color == 0 {
color = 0x0F
}
if ElementDefs[tile.Element].Color == COLOR_WHITE_ON_CHOICE {
color = byte((int16(color)-8)*0x10 + 0x0F)
}
}
if Board.Tiles[x][y].Element == tile.Element {
Board.Tiles[x][y].Color = color
} else {
BoardDamageTile(x, y)
if ElementDefs[tile.Element].Cycle >= 0 {
AddStat(x, y, tile.Element, int16(color), ElementDefs[tile.Element].Cycle, StatTemplateDefault)
} else {
Board.Tiles[x][y].Element = tile.Element
Board.Tiles[x][y].Color = color
}
}
BoardDrawTile(x, y)
}
}
func OopCheckCondition(statId int16, position *int16) (OopCheckCondition_ bool) {
var (
deltaX, deltaY int16
tile TTile
ix, iy int16
)
stat := &Board.Stats[statId]
if OopWord == "NOT" {
OopReadWord(statId, position)
OopCheckCondition_ = !OopCheckCondition(statId, position)
} else if OopWord == "ALLIGNED" {
OopCheckCondition_ = stat.X == Board.Stats[0].X || stat.Y == Board.Stats[0].Y
} else if OopWord == "CONTACT" {
OopCheckCondition_ = Sqr(int16(stat.X)-int16(Board.Stats[0].X))+Sqr(int16(stat.Y)-int16(Board.Stats[0].Y)) == 1
} else if OopWord == "BLOCKED" {
OopReadDirection(statId, position, &deltaX, &deltaY)
OopCheckCondition_ = !ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable
} else if OopWord == "ENERGIZED" {
OopCheckCondition_ = World.Info.EnergizerTicks > 0
} else if OopWord == "ANY" {
if !OopParseTile(&statId, position, &tile) {
OopError(statId, "Bad object kind")
}
ix = 0
iy = 1
OopCheckCondition_ = FindTileOnBoard(&ix, &iy, tile)
} else {
OopCheckCondition_ = WorldGetFlagPosition(OopWord) >= 0
}
return
}
func OopReadLineToEnd(statId int16, position *int16) (OopReadLineToEnd string) {
var s string
s = ""
OopReadChar(statId, position)
for OopChar != '\x00' && OopChar != '\r' {
s += string([]byte{OopChar})
OopReadChar(statId, position)
}
OopReadLineToEnd = s
return
}
func OopSend(statId int16, sendLabel string, ignoreLock bool) (OopSend bool) {
var (
iDataPos, iStat int16
ignoreSelfLock bool
)
if statId < 0 {
statId = -statId
ignoreSelfLock = true
} else {
ignoreSelfLock = false
}
OopSend = false
iStat = 0
for OopFindLabel(statId, sendLabel, &iStat, &iDataPos, "\r:") {
if Board.Stats[iStat].P2 == 0 || ignoreLock || statId == iStat && !ignoreSelfLock {
if iStat == statId {
OopSend = true
}
Board.Stats[iStat].DataPos = iDataPos
}
}
return
}
func OopExecute(statId int16, position *int16, name string) {
var (
textWindow TTextWindowState
textLine string
deltaX, deltaY int16
ix, iy int16
stopRunning bool
replaceStat bool
endOfProgram bool
replaceTile TTile
namePosition int16
lastPosition int16
repeatInsNextTick bool
lineFinished bool
labelDataPos int16
labelStatId int16
counterPtr *int16
counterSubtract bool
bindStatId int16
insCount int16
argTile TTile
argTile2 TTile
)
stat := &Board.Stats[statId]
StartParsing:
TextWindowInitState(&textWindow)
textWindow.Selectable = false
stopRunning = false
repeatInsNextTick = false
replaceStat = false
endOfProgram = false
insCount = 0
for {
ReadInstruction:
lineFinished = true
lastPosition = *position
OopReadChar(statId, position)
for OopChar == ':' {
for {
OopReadChar(statId, position)
if OopChar == '\x00' || OopChar == '\r' {
break
}
}
OopReadChar(statId, position)
}
if OopChar == '\'' {
OopSkipLine(statId, position)
} else if OopChar == '@' {
OopSkipLine(statId, position)
} else if OopChar == '/' || OopChar == '?' {
if OopChar == '/' {
repeatInsNextTick = true
}
OopReadWord(statId, position)
if OopParseDirection(statId, position, &deltaX, &deltaY) {
if deltaX != 0 || deltaY != 0 {
if !ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
ElementPushablePush(int16(stat.X)+deltaX, int16(stat.Y)+deltaY, deltaX, deltaY)
}
if ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
MoveStat(statId, int16(stat.X)+deltaX, int16(stat.Y)+deltaY)
repeatInsNextTick = false
}
} else {
repeatInsNextTick = false
}
OopReadChar(statId, position)
if OopChar != '\r' {
*position--
}
stopRunning = true
} else {
OopError(statId, "Bad direction")
}
} else if OopChar == '#' {
ReadCommand:
OopReadWord(statId, position)
if OopWord == "THEN" {
OopReadWord(statId, position)
}
if Length(OopWord) == 0 {
goto ReadInstruction
}
insCount++
if Length(OopWord) != 0 {
if OopWord == "GO" {
OopReadDirection(statId, position, &deltaX, &deltaY)
if !ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
ElementPushablePush(int16(stat.X)+deltaX, int16(stat.Y)+deltaY, deltaX, deltaY)
}
if ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
MoveStat(statId, int16(stat.X)+deltaX, int16(stat.Y)+deltaY)
} else {
repeatInsNextTick = true
}
stopRunning = true
} else if OopWord == "TRY" {
OopReadDirection(statId, position, &deltaX, &deltaY)
if !ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
ElementPushablePush(int16(stat.X)+deltaX, int16(stat.Y)+deltaY, deltaX, deltaY)
}
if ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
MoveStat(statId, int16(stat.X)+deltaX, int16(stat.Y)+deltaY)
stopRunning = true
} else {
goto ReadCommand
}
} else if OopWord == "WALK" {
OopReadDirection(statId, position, &deltaX, &deltaY)
stat.StepX = deltaX
stat.StepY = deltaY
} else if OopWord == "SET" {
OopReadWord(statId, position)
WorldSetFlag(OopWord)
} else if OopWord == "CLEAR" {
OopReadWord(statId, position)
WorldClearFlag(OopWord)
} else if OopWord == "IF" {
OopReadWord(statId, position)
if OopCheckCondition(statId, position) {
goto ReadCommand
}
} else if OopWord == "SHOOT" {
OopReadDirection(statId, position, &deltaX, &deltaY)
if BoardShoot(E_BULLET, int16(stat.X), int16(stat.Y), deltaX, deltaY, SHOT_SOURCE_ENEMY) {
SoundQueue(2, "0\x01&\x01")
}
stopRunning = true
} else if OopWord == "THROWSTAR" {
OopReadDirection(statId, position, &deltaX, &deltaY)
if BoardShoot(E_STAR, int16(stat.X), int16(stat.Y), deltaX, deltaY, SHOT_SOURCE_ENEMY) {
}
stopRunning = true
} else if OopWord == "GIVE" || OopWord == "TAKE" {
if OopWord == "TAKE" {
counterSubtract = true
} else {
counterSubtract = false
}
OopReadWord(statId, position)
if OopWord == "HEALTH" {
counterPtr = &World.Info.Health
} else if OopWord == "AMMO" {
counterPtr = &World.Info.Ammo
} else if OopWord == "GEMS" {
counterPtr = &World.Info.Gems
} else if OopWord == "TORCHES" {
counterPtr = &World.Info.Torches
} else if OopWord == "SCORE" {
counterPtr = &World.Info.Score
} else if OopWord == "TIME" {
counterPtr = &World.Info.BoardTimeSec
} else {
counterPtr = nil
}
if counterPtr != nil {
OopReadValue(statId, position)
if OopValue > 0 {
if counterSubtract {
OopValue = -OopValue
}
if *counterPtr+OopValue >= 0 {
*counterPtr += OopValue
} else {
goto ReadCommand
}
}
}
GameUpdateSidebar()
} else if OopWord == "END" {
*position = -1
OopChar = '\x00'
} else if OopWord == "ENDGAME" {
World.Info.Health = 0
} else if OopWord == "IDLE" {
stopRunning = true
} else if OopWord == "RESTART" {
*position = 0
lineFinished = false
} else if OopWord == "ZAP" {
OopReadWord(statId, position)
labelStatId = 0
for OopFindLabel(statId, OopWord, &labelStatId, &labelDataPos, "\r:") {
Board.Stats[labelStatId].Data = Replace(Board.Stats[labelStatId].Data, labelDataPos+1, '\'')
}
} else if OopWord == "RESTORE" {
OopReadWord(statId, position)
labelStatId = 0
for OopFindLabel(statId, OopWord, &labelStatId, &labelDataPos, "\r'") {
for {
Board.Stats[labelStatId].Data = Replace(Board.Stats[labelStatId].Data, labelDataPos+1, ':')
labelDataPos = OopFindString(labelStatId, "\r'"+OopWord+"\r")
if labelDataPos <= 0 {
break
}
}
}
} else if OopWord == "LOCK" {
stat.P2 = 1
} else if OopWord == "UNLOCK" {
stat.P2 = 0
} else if OopWord == "SEND" {
OopReadWord(statId, position)
if OopSend(statId, OopWord, false) {
lineFinished = false
}
} else if OopWord == "BECOME" {
if OopParseTile(&statId, position, &argTile) {
replaceStat = true
replaceTile.Element = argTile.Element
replaceTile.Color = argTile.Color
} else {
OopError(statId, "Bad #BECOME")
}
} else if OopWord == "PUT" {
OopReadDirection(statId, position, &deltaX, &deltaY)
if deltaX == 0 && deltaY == 0 {
OopError(statId, "Bad #PUT")
} else if !OopParseTile(&statId, position, &argTile) {
OopError(statId, "Bad #PUT")
} else if int16(stat.X)+deltaX > 0 && int16(stat.X)+deltaX <= BOARD_WIDTH && int16(stat.Y)+deltaY > 0 && int16(stat.Y)+deltaY < BOARD_HEIGHT {
if !ElementDefs[Board.Tiles[int16(stat.X)+deltaX][int16(stat.Y)+deltaY].Element].Walkable {
ElementPushablePush(int16(stat.X)+deltaX, int16(stat.Y)+deltaY, deltaX, deltaY)
}
OopPlaceTile(int16(stat.X)+deltaX, int16(stat.Y)+deltaY, &argTile)
}
} else if OopWord == "CHANGE" {
if !OopParseTile(&statId, position, &argTile) {
OopError(statId, "Bad #CHANGE")
}
if !OopParseTile(&statId, position, &argTile2) {
OopError(statId, "Bad #CHANGE")
}
ix = 0
iy = 1
if argTile2.Color == 0 && ElementDefs[argTile2.Element].Color < COLOR_SPECIAL_MIN {
argTile2.Color = ElementDefs[argTile2.Element].Color
}
for FindTileOnBoard(&ix, &iy, argTile) {
OopPlaceTile(ix, iy, &argTile2)
}
} else if OopWord == "PLAY" {
textLine = SoundParse(OopReadLineToEnd(statId, position))
if Length(textLine) != 0 {
SoundQueue(-1, textLine)
}
lineFinished = false
} else if OopWord == "CYCLE" {
OopReadValue(statId, position)
if OopValue > 0 {
stat.Cycle = OopValue
}
} else if OopWord == "CHAR" {
OopReadValue(statId, position)
if OopValue > 0 && OopValue <= 255 {
stat.P1 = byte(OopValue)
BoardDrawTile(int16(stat.X), int16(stat.Y))
}
} else if OopWord == "DIE" {
replaceStat = true
replaceTile.Element = E_EMPTY
replaceTile.Color = 0x0F
} else if OopWord == "BIND" {
OopReadWord(statId, position)
bindStatId = 0
if OopIterateStat(statId, &bindStatId, OopWord) {
stat.Data = Board.Stats[bindStatId].Data
stat.DataLen = Board.Stats[bindStatId].DataLen
*position = 0
}
} else {
textLine = OopWord
if OopSend(statId, OopWord, false) {
lineFinished = false
} else {
if Pos(':', textLine) <= 0 {
OopError(statId, "Bad command "+textLine)
}
}
}
}
if lineFinished {
OopSkipLine(statId, position)
}
} else if OopChar == '\r' {
if textWindow.LineCount > 0 {
TextWindowAppend(&textWindow, "")
}
} else if OopChar == '\x00' {
endOfProgram = true
} else {
textLine = string([]byte{OopChar})
textLine += OopReadLineToEnd(statId, position)
TextWindowAppend(&textWindow, textLine)
}
if endOfProgram || stopRunning || repeatInsNextTick || replaceStat || insCount > 32 {
break
}
}
if repeatInsNextTick {
*position = lastPosition
}
if OopChar == '\x00' {
*position = -1
}
if textWindow.LineCount > 1 {
namePosition = 0
OopReadChar(statId, &namePosition)
if OopChar == '@' {
name = OopReadLineToEnd(statId, &namePosition)
}
if Length(name) == 0 {
name = "Interaction"
}
textWindow.Title = name
TextWindowDrawOpen(&textWindow)
TextWindowSelect(&textWindow, true, false)
TextWindowDrawClose(&textWindow)
TextWindowFree(&textWindow)
if Length(textWindow.Hyperlink) != 0 {
if OopSend(statId, textWindow.Hyperlink, false) {
goto StartParsing
}
}
} else if textWindow.LineCount == 1 {
DisplayMessage(200, textWindow.Lines[0])
TextWindowFree(&textWindow)
}
if replaceStat {
ix = int16(stat.X)
iy = int16(stat.Y)
DamageStat(statId)
OopPlaceTile(ix, iy, &replaceTile)
}
}