-
Notifications
You must be signed in to change notification settings - Fork 0
/
hub.c
1915 lines (1792 loc) · 35.9 KB
/
hub.c
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
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include <thread.h>
#include <keyboard.h>
#include "dat.h"
#include "fns.h"
extern Channel *csc;
int qtc;
Score scs[] = {
{"id software-'92", 10000, 1},
{"Adrian Carmack", 10000, 1},
{"John Carmack", 10000, 1},
{"Kevin Cloud", 10000, 1},
{"Tom Hall", 10000, 1},
{"John Romero", 10000, 1},
{"Jay Wilbur", 10000, 1},
};
char savs[11][32];
typedef struct Fade Fade;
typedef struct Sp Sp;
typedef struct Seq Seq;
typedef struct Item Item;
typedef struct Menu Menu;
enum{
LMctl,
LMnew,
LMdifc,
LMsnd,
LMin,
LMsav,
LMmsg,
Lload = 0,
Lintro,
Lftitle,
Ltitle,
Lcreds,
Lscore,
Lfpants,
Lpants,
Ldemo,
Lpsych,
Lgame,
Lretry,
Lmsg,
Lcont1,
Lcont2,
Lgcont,
Lfdie,
Ldie,
Ldie2,
Lhigh,
Lcam,
Lspear,
Linter,
Linteri,
Linterm,
Linterw,
Lintere,
Lsinter,
Lsdmend,
Lcolp,
Lcolp2,
Lcolp3,
Lwon,
Lwon2,
Lsdepi,
Lpres,
Lroll1,
Lroll2,
Lroll3,
Lroll4,
Lroll5,
Lroll6,
Lroll7,
Ldecay,
Lctl,
Ltoctl,
Lftoctl,
Lmtoctl,
Lcur,
Lftonew,
Lmtonew,
Lnewgame,
Lnctl,
Ldenied,
Ldifc1,
Ldifc2,
Ldifc3,
Ldifc4,
Ldifc5,
Lfsnd,
Lmsnd,
Lsctl,
Lsndtog,
Lfin,
Lmin,
Lictl,
Lintog,
Lfsens,
Lmsens,
Lsectl,
Lfsav,
Lmsav,
Lsvctl,
Lsvname,
Lwrsav,
Lflod,
Lmlod,
Lldctl,
Lldsav,
Lldsav2,
Lldsav3,
Lldsav4,
Lldsav5,
Lfvw,
Lmvw,
Lvwctl,
Lfmscore,
Lmscore,
Lovrsav,
Lend,
Lcurgame,
Lquit,
Lmexit,
Lexit
};
struct Sp{
int dt;
void (*f)(void);
};
struct Fade{
Col c;
int dt;
};
struct Seq{
void (*init)(void);
Sp *s;
Sp *e;
Seq *q;
Fade *f;
};
static Seq *qsp, *qesc, ql[];
static Sp *qp;
enum{
DMbg,
DMoff,
DMbrd,
DMbrd2,
DMend,
DIreg = 0x17,
DIsee = 0x4a,
DIeps = 0x6b,
DIrhi = 0x13,
DIshi = 0x47,
DIepi = 0xd0,
};
static int mcol[DMend] = {[DMbg] 0x2d, 0};
#define SEL(c) ((c) - 4 + (((c) >> 1 ^ (c)) >> 5 & 1))
#define UNSEL(c) ((c) + 4 - (((c) >> 1 ^ (c)) >> 5 & 1))
struct Item{
char *s;
int c;
Seq *q;
int a;
};
static Item
ictl[] = {
{"New Game", SEL(DIreg), ql+Lftonew},
{"Sound", DIreg, ql+Lfsnd},
{"Control", DIreg, ql+Lfin},
{"Load Game", DIreg, ql+Lflod},
{"Save Game", DIreg, ql+Lfsav},
{"Change View", DIreg, ql+Lfvw},
{"View Scores", DIreg, ql+Lfmscore},
{"Back to Demo", DIreg, ql+Lftitle},
{"Quit", DIreg, ql+Lquit}
},
inew[] = {
{"Episode 1\nEscape from Wolfenstein", SEL(DIreg), ql+Ldifc1},
{nil},
{"Episode 2\nOperation: Eisenfaust", DIreg, ql+Ldifc1},
{nil},
{"Episode 3\nDie, Fuhrer, Die!", DIreg, ql+Ldifc1},
{nil},
{"Episode 4\nA Dark Secret", DIreg, ql+Ldifc1},
{nil},
{"Episode 5\nTrail of the Madman", DIreg, ql+Ldifc1},
{nil},
{"Episode 6\nConfrontation", DIreg, ql+Ldifc1},
{nil}
},
idifc[] = {
{"Can I play, Daddy?", DIreg, ql+Ldifc4},
{"Don't hurt me.", DIreg, ql+Ldifc4},
{"Bring 'em on!", SEL(DIreg), ql+Ldifc4},
{"I am Death incarnate!", DIreg, ql+Ldifc4}
},
isnd[] = {
{"None", SEL(DIreg)},
{"PC Speaker"},
{"AdLib/Sound Blaster", DIreg},
{nil},
{nil},
{"None", DIreg},
{"Disney Sound Source"},
{"Sound Blaster", DIreg},
{nil},
{nil},
{"None", DIreg},
{"AdLib/Sound Blaster", DIreg}
},
iin[] = {
{"Mouse Enabled", SEL(DIreg), ql+Lintog},
{"Autorun Enabled", DIreg, ql+Lintog},
{"Mouse Sensitivity", DIreg, ql+Lfsens}
},
isv[] = {
{"", SEL(DIreg), nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil},
{"", DIreg, nil}
},
imsg[] = {
{nil}
};
struct Menu{
Item *p;
Item *s;
Item *e;
int x;
int y;
int n;
};
static Menu *mp, ml[] = {
[LMctl] {ictl, ictl, ictl+nelem(ictl), 72},
[LMnew] {inew, inew, inew+nelem(inew), 8},
[LMdifc] {idifc+2, idifc, idifc+nelem(idifc), 48},
[LMsnd] {isnd, isnd, isnd+nelem(isnd), 48},
[LMin] {iin, iin, iin+nelem(iin), 24},
[LMsav] {isv, isv, isv+nelem(isv), 80},
[LMmsg] {imsg}
};
static char *ends[] = {
"Dost thou wish to\nleave with such hasty\nabandon?",
"Chickening out...\nalready?",
"Press N for more carnage.\nPress Y to be a weenie.",
"So, you think you can\nquit this easily, huh?",
"Press N to save the world.\nPress Y to abandon it in\nits hour of need.",
"Press N if you are brave.\nPress Y to cower in shame.",
"Heroes, press N.\nWimps, press Y.",
"You are at an intersection.\nA sign says, 'Press Y to quit.'\n>",
"For guns and glory, press N.\nFor work and worry, press Y.",
"Heroes don't quit, but\ngo ahead and press Y\nif you aren't one.",
"Press Y to quit,\nor press N to enjoy\nmore violent diversion.",
"Depressing the Y key means\nyou must return to the\nhumdrum workday world.",
"Hey, quit or play,\nY or N:\nit's your choice.",
"Sure you don't want to\nwaste a few more\nproductive hours?",
"I think you had better\nplay some more. Please\npress N...please?",
"If you are tough, press N.\nIf not, press Y daintily.",
"I'm thinkin' that\nyou might wanna press N\nto play more. You do it.",
"Sure. Fine. Quit.\nSee if we care.\nGet it over with.\nPress Y."
};
static char **quits;
static Fade
fblk = {{0, 0, 0}, 30},
ftra = {{0, 0, 0}, 10},
fctl = {{0xae, 0, 0}, 10},
focl = {{0, 0x44, 0x44}, 300},
ficl = {{0, 0x44, 0x44}, 30},
fecl = {{0, 0x44, 0x44}, 5};
static int irr[4], *irp;
static int iri, iry, irb;
static uchar **demd;
static char *demf;
static void
reset(Seq *p)
{
qp = p->s;
qtc = 0;
if(p == qsp)
return;
toss();
if(qp->f != fadeout)
pal = pals[C0];
qsp = p;
if(p->init != nil)
p->init();
if(p->f != nil)
fadeop(&p->f->c, p->f->dt);
}
static void
pblink(void)
{
if(mp->n ^= 1)
put(mp->x, mp->y, fnt->w['_'], fnt->h, DIreg);
else
txt(mp->x, mp->y, "_", 0);
out();
}
static void
iblink(void)
{
if(mp->n ^= 1)
txt(111 + irb - 1, mp->y + 3, "\x80", DIrhi);
else
put(111 + irb - 1, mp->y + 3, fnt->w[0x80]-1, fnt->h, mcol[DMbg]);
out();
}
static void
blink(void)
{
put(mp->x, mp->y, 24, 16, mcol[DMbg]);
pic(mp->x, mp->y, pict[Pcur1] + mp->n);
mp->n ^= 1;
out();
}
static void
iswp(Item *on, Item *off)
{
on->a = 1;
on->q = nil;
off->a = 0;
off->q = ql+Lsndtog;
}
static void
toggle(void)
{
Item *i;
i = mp->s;
switch(mp - ml){
case LMsnd:
if(mp->p->a)
return;
switch(mp->p - i){
case 0: iswp(i, i+2); stopsfx(); sfxon = 0; break;
case 2: iswp(i+2, i); sfxon = 1; sfx(Sshoot); break;
case 5: iswp(i+5, i+7); pcmon = 0; break;
case 7: iswp(i+7, i+5); pcmon = 1; break;
case 10: iswp(i+10, i+11); stopmus(); muson = 0; sfx(Sshoot); break;
case 11: iswp(i+11, i+10); muson = 1; mus(Mmenu); break;
}
break;
case LMin:
switch(mp->p - i){
tog: mp->p->a ^= 1; break;
case 0: grabon ^= 1; goto tog;
case 1: autorun ^= 1; goto tog;
}
break;
}
}
static void
inctl(void)
{
Item *i, *e;
Menu *m;
m = ml+LMctl;
i = m->s;
i[3].c = DIreg;
i[4].c = mcol[DMoff];
i[6].s = "View Scores";
i[6].q = ql+Lfmscore;
i[6].c = DIreg;
i[7].s = "Back to Demo";
i[7].q = ql+Lftitle;
i[7].c = DIreg;
m->p = m->s;
m->p->c = SEL(DIreg);
if(ver >= SDM)
i[0].q = ql+Ldifc1;
else
for(i=ml[LMnew].s, e=ml[LMnew].e; i<e && i->q!=ql+Ldenied; i++)
i->q = ql+Ldifc1;
}
static void
ingctl(void)
{
Item *i, *e;
i = ml[LMctl].s;
i[4].c = DIreg;
i[6].s = "End Game";
i[6].q = ql+Lend;
i[7].s = "Back to Game";
i[7].q = ql+Lcont1;
i[7].c = DIsee;
if(i[0].q == ql+Ldifc1)
i[0].q = ql+Lcurgame;
else
for(i=ml[LMnew].s, e=ml[LMnew].e; i<e && i->q!=ql+Ldenied; i++)
i->q = ql+Lcurgame;
}
static void
mbox(int x, int y, int dx, int dy)
{
box(x, y, dx, dy, mcol[DMbg], mcol[DMbrd2], mcol[DMoff]);
}
static void
msg(char *s, int o)
{
int x, y, w, h, curw;
char *nl;
fnt = fnts+1;
h = txth(s);
w = txtw(s);
nl = strrchr(s, '\n');
curw = txtw(nl != nil ? nl + 1 : s);
w = w > curw + 10 ? w : curw + 10;
x = Vw / 2 - w / 2;
y = (step == gstep ? Vhud : Vh) / 2 - h / 2;
box(x - 5, y - 5, w + 10, h + 10, DIreg, 0, DIrhi);
txtnl(x, y, s, 0);
if(o)
out();
mp = ml+LMmsg;
mp->n = 0;
mp->x = x + curw;
mp->y = y + h - fnt->h;
}
static void
quit(void)
{
msg(quits[nrand(nelem(ends)/2)], 0);
mp->p->q = ql+Lmexit;
qesc = ql+Lctl;
}
static void
curgame(void)
{
msg("You are currently in\na game. Continuing will\nerase old game. Ok?", 0);
mp->p->q = ql+Ldifc1;
qesc = ver < SDM ? ql+Lftoctl : ql+Lctl;
}
static void
mend2(void)
{
view();
render();
gm.lives = 0;
ql[Ldie].q = ql+Ldie2;
}
static void
mend(void)
{
msg("Are you sure you want\nto end the game you\nare playing? (Y or N):", 0);
mp->p->q = ql+Lfdie;
qesc = ql+Lctl;
}
static void
ovrsav(void)
{
msg("There's already a game\n"
"saved at this position.\n Overwrite?", 0);
mp->p->q = ql+Lsvname;
qesc = ql+Lsvctl;
}
static void
denied(void)
{
msg("Please select \"Read This!\"\nfrom the Options menu to\n"
"find out how to order this\nepisode from Apogee.", 1);
stopsfx();
sfx(Snoway);
}
static void
sdmend(void)
{
sfx(S1up);
msg("This concludes your demo\nof Spear of Destiny! Now,\n"
"go to your local software\nstore and buy it!", 1);
}
static void
setdifc(void)
{
int m, d;
m = ver < SDM ? (ml[LMnew].p - ml[LMnew].s) * 5 : 0;
d = ml[LMdifc].p - ml[LMdifc].s;
ginit(nil, m, d);
ingctl();
palfill(&fctl.c);
}
static void
difc(void)
{
Menu *m;
Item *i, *e;
mclear();
pic(112, 184, pict[Pmouselback]);
if(ver < SDM){
txt(70, 68, "How tough are you?", DIshi);
qesc = ql+Lftonew;
}else{
pic(70, 68, pict[Pdiffc]);
qesc = ql+Lftoctl;
}
mbox(45, 90, 225, 67);
m = ml+LMdifc;
mp = m;
i = m->s;
e = m->e;
do{
txt(74, 100 + 13 * (i - m->s), i->s, i->c);
}while(++i < e);
pic(235, 107, pict[Pbaby] + m->p - m->s);
m->n = 0;
m->y = 98 + 13 * (m->p - m->s);
}
static void
newgame(void)
{
int n;
Item *i, *e;
Menu *m;
mclear();
pic(112, 184, pict[Pmouselback]);
mbox(6, 19, 308, 162);
txtcen(2, "Which episode to play?", DIshi);
for(n=0; n<6; n++)
pic(40, 23 + n * 26, pict[Pep1] + n);
m = ml+LMnew;
mp = m;
i = m->s;
e = m->e;
do{
txtnl(98, 23 + 13 * (i - m->s), i->s, i->c);
i += 2;
}while(i < e);
qesc = ql+Lftoctl;
m->n = 0;
m->y = 21 + 13 * (m->p - m->s);
}
static void
snd(void)
{
Item *i, *e;
Menu *m;
mclear();
pic(112, 184, pict[Pmouselback]);
mbox(40, 17, 250, 45);
mbox(40, 82, 250, 45);
mbox(40, 147, 250, 32);
pic(96, 0, pict[Psfx]);
pic(96, 65, pict[Ppcm]);
pic(96, 130, pict[Pmus]);
m = ml+LMsnd;
mp = m;
i = m->s;
e = m->e;
do{
if(i->s == nil)
continue;
txt(100, 20 + 13 * (i - m->s), i->s, i->c);
pic(72, 22 + 13 * (i - m->s), pict[i->a ? Psel : Punsel]);
}while(++i < e);
qesc = ql+Lftoctl;
m->n = 0;
m->y = 18 + 13 * (m->p - m->s);
}
static void
sens(void)
{
int n;
mclear();
pic(112, 184, pict[Pmouselback]);
mbox(10, 80, 300, 30);
txtcen(82, "Adjust Mouse Sensitivity", DIsee);
txt(14, 95, "Slow", DIreg);
txt(269, 95, "Fast", DIreg);
put(60, 97, 200, 10, DIreg);
outbox(60, 97, 200, 10, 0x0, DIrhi);
n = 60 + 20 * iri;
put(n + 1, 98, 19, 9, DIshi);
outbox(n, 97, 20, 10, 0x0, DIsee);
qesc = ql+Lfin;
}
static void
in(void)
{
Menu *m;
Item *i, *e;
mclear();
stripe(10);
pic(80, 0, pict[Pctl]);
pic(112, 184, pict[Pmouselback]);
mbox(16, 65, 284, 45);
m = ml+LMin;
mp = m;
i = m->s;
e = m->e;
do{
txt(80, 70 + 13 * (i - m->s), i->s, i->c);
if(i < e - 1)
pic(56, 73 + 13 * (i - m->s), pict[i->a ? Psel : Punsel]);
}while(++i < e);
qesc = ql+Lftoctl;
m->n = 0;
m->y = 68 + 13 * (m->p - m->s);
iri = msense;
}
static void
disk(void)
{
int n;
box(96, 80, 130, 42, DIreg, 0, DIrhi);
pic(104, 85, pict[Pread1]);
fnt = fnts+1;
txt(142, 93, qsp == ql+Lwrsav ? "Saving..." : "Loading...", 0);
out();
n = mp->p - mp->s;
if(qsp == ql+Lwrsav){
qsp->q = ql+Lftoctl;
wrsav(n);
}else{
qsp->q = ql+Lldsav2;
ginit(nil, -1, 0);
greset();
ldsav(n);
ingctl();
loaded++;
}
sfx(Sshoot);
}
static void
savtxt(Item *i, char *s)
{
int n;
n = 56 + (i - mp->s) * 13;
put(110, n, 135, fnt->h, mcol[DMbg]);
txt(111, n, s, i->c);
}
static void
savitem(Item *i, int n)
{
outbox(109, 55 + n * 13, 136, 11, i->c, i->c);
if(savs[n][0] != 0){
savtxt(i, savs[n]);
i->q = qsp->q == ql+Lsvctl ? ql+Lovrsav : ql+Lldsav;
}else{
savtxt(i, " - empty -");
i->q = qsp->q == ql+Lsvctl ? ql+Lsvname : nil;
}
}
static void
sav(void)
{
Menu *m;
Item *i, *e;
mclear();
pic(112, 184, pict[Pmouselback]);
mbox(75, 50, 175, 140);
stripe(10);
pic(56, 0, pict[qsp->q == ql+Lldctl ? Pload : Psave]);
m = ml+LMsav;
mp = m;
i = m->s;
e = m->e;
fnt = fnts;
do
savitem(i, i - m->s);
while(++i < e);
qesc = ql+Lftoctl;
m->n = 0;
m->y = 53 + 13 * (m->p - m->s);
}
static void
savname(void)
{
sav();
memcpy(savs[10], savs[mp->p - mp->s], sizeof savs[10]);
savtxt(mp->p, savs[10]);
iri = strlen(savs[10]);
irb = txtw(savs[10]);
mp->n = 0;
}
static void
mvw(void)
{
int dx, dy;
dx = vw.dx;
dy = vw.dy;
vw.dx = iri * 16;
vw.dy = iri * 8;
viewbox();
vw.dx = dx;
vw.dy = dy;
put(0, Vhud, Vw, 40, 0x7f);
txtcen(161, "Use arrows to size", DIrhi);
txtcen(161 + fnt->h, "ENTER to accept", DIrhi);
txtcen(161 + 2 * fnt->h, "ESC to cancel", DIrhi);
qesc = ql+Lftoctl;
}
static void
ctl(void)
{
Menu *m;
Item *i, *e;
mclear();
pic(112, 184, pict[Pmouselback]);
stripe(10);
pic(80, 0, pict[Popt]);
mbox(68, 52, 178, 123);
fnt = fnts+1;
m = ml+LMctl;
mp = m;
i = m->s;
e = m->e;
do
txt(100, 55 + 13 * (i - m->s), i->s, i->c);
while(++i < e);
qesc = ql+Lquit;
m->n = 0;
m->y = 53 + 13 * (m->p - m->s);
if(qsp == ql+Ltoctl)
stopsfx();
mus(Mmenu);
grab(0);
iri = vwsize;
}
static void
cursfx(void)
{
sfx(Sdrawgun2);
}
static void
slcur(int dir)
{
iri += dir;
switch(qsp - ql){
case Lsectl:
if(iri < 0)
iri = 0;
else if(iri > 9)
iri = 9;
break;
case Lvwctl:
if(iri < 4)
iri = 4;
else if(iri > 19)
iri = 19;
break;
}
qsp->init();
out();
}
static void
slider(void)
{
Rune r;
if(nbrecv(csc, &r) <= 0)
return;
switch(r){
case Kleft: case Kdown: slcur(-1); break;
case Kright: case Kup: slcur(1); break;
case Kesc: sfx(Sesc); reset(qesc); break;
case '\n':
case ' ':
switch(qsp - ql){
case Lsectl: msense = iri; break;
case Lvwctl: vwsize = iri; msg("Thinking...", 1); setvw(); break;
}
sfx(Sshoot);
reset(qesc);
break;
}
}
static void
movcur(Item *p, int dir)
{
Item *i;
p->c = UNSEL(p->c);
i = p;
do{
i += dir;
if(i < mp->s)
i = mp->e - 1;
else if(i == mp->e)
i = mp->s;
}while(i->c == mcol[DMoff] || i->c == 0);
i->c = SEL(i->c);
mp->p = i;
mp->n = 0;
if(i != p + dir){
cursfx();
reset(qsp);
if(qsp->init != nil)
qsp->init();
return;
}
put(mp->x, mp->y, 24, 16, mcol[DMbg]);
mp->y += dir * 6;
blink();
sfx(Sdrawgun1);
ql[Lcur].q = qsp;
reset(ql+Lcur);
}
static void
cwalk(void)
{
static char s[UTFmax*2], *sp = s;
Rune r;
Seq *q;
Item *i;
if(nbrecv(csc, &r) <= 0)
return;
i = mp->p;
switch(r){
case Kup: movcur(i, -1); break;
case Kdown: movcur(i, 1); break;
case Kesc: sfx(Sesc); reset(qesc); break;
case '\n':
case ' ':
q = i->q;
if(q == nil)
break;
if(q != ql+Lquit && q != ql+Lftitle)
sfx(Sshoot);
reset(q);
break;
default:
if(ver < SOD)
break;
sp += runetochar(sp, &r);
if(strncmp(s, "id", sp-s) == 0){
if(sp - s == 2){
reset(ql+Lfpants);
sp = s;
}
}else
sp = s;
}
}
static void
prompt(void)
{
int n, m;
char *s;
Rune r;
if(nbrecv(csc, &r) <= 0)
return;
s = savs[10];
n = strlen(s);
switch(r){
redraw:
savtxt(mp->p, savs[10]);
mp->n = 0;
iblink();
qtc = 0;
break;
default:
if(runelen(r) > 1 || !isprint(r))
break;
m = fnt->w[r];
if(txtw(s) + m > 134 || n == sizeof(savs[10]) - 1)
break;
while(n-- > iri)
s[n+1] = s[n];
s[iri++] = r;
irb += m;
goto redraw;
case Kleft:
if(iri == 0)
break;
irb -= fnt->w[s[--iri]];
goto redraw;
case Kright:
if(iri == n)
break;
irb += fnt->w[s[iri++]];
goto redraw;
case Kdel:
case Kbs:
if(iri == 0)
break;
irb -= fnt->w[s[--iri]];
for(m=iri+1; m<=n; m++)
s[m-1] = s[m];
s[m] = 0;
goto redraw;
abort:
case Kesc:
sfx(Sesc);
reset(ql+Lsvctl);
break;
case '\n':
if(n == 0)
goto abort;
strcpy(savs[mp->p - mp->s], savs[10]);
sfx(Sshoot);
reset(ql+Lwrsav);
break;
}
}
static void
ask(void)
{
Rune r;
if(nbrecv(csc, &r) <= 0)
return;
if(r == 'y'){
sfx(Sshoot);
reset(mp->p->q);
}else if(r == 'n' || r == Kesc){
sfx(Sesc);
reset(qesc);
}
}
static void
skip(void)
{
if(nbrecv(csc, nil) > 0)
reset(ql+Ldecay);
}
static void
swait(void)
{
if(lastsfx() >= 0)
qtc = 0;
else
sfxlck = 0;
}
static void
nbwait(void)