forked from y-salnikov/ironseed_fpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
comm.pas
1919 lines (1854 loc) · 47.8 KB
/
comm.pas
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
unit comm;
(********************************************************************
This file is part of Ironseed.
Ironseed is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ironseed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ironseed. If not, see <http://www.gnu.org/licenses/>.
********************************************************************)
{*********************************************
Communication unit for IronSeed
Copyright:
1994 Channel 7, Destiny: Virtual
2013 y-salnikov
2020 Matija Nalis <[email protected]>
**********************************************}
{$O+}
{$I-}
interface
uses data, utils_;
procedure conversewithcrew;
procedure continuecontact(hail: boolean);
procedure getspecial(n,contactindex: integer);
procedure addtofile;
procedure createwandering(order: integer);
procedure getinfo;
procedure checkwandering;
procedure animatealien;
procedure gettechlevel(plan: integer);
function calc_anger (anger, congeniality: integer): integer;
implementation
uses gmouse, utils, utils2, weird, modplay, comm2, journey, saveload, heapchk;
const
numback= 19;
type
eventtype=
record
want,give: integer;
msg: string[255];
end;
eventarray= array[0..9] of eventtype;
var
i,j,techlvl,eattype,contactindex,cursorx,indexa,indexb,indexc,oldcontactindex: integer;
brighter,infomode,shipflag,eventflag: boolean;
str1, str2: ^string;
question: string[20];
c: ^conversearray;
r: ^responsearray;
tmpm: ^mouseicontype;
aliens: pscreentype;
p: ^paltype;
procedure createwandering(order: integer);
var x,y: integer; { order = 0 > attack }
begin { = 1 > retreat }
with ship.wandering do { = 2 > nothing }
begin
orders:=order;
x:=hi(alien.techmin);
y:=lo(alien.techmin);
techlevel:=alien.techmin;
i:=5+random(4);
repeat
inc(y);
if y>9 then
begin
inc(x);
y:=0;
if x>6 then
begin
x:=6;
y:=0;
end;
end;
dec(i);
until (i=0) or (techlevel=alien.techmax);
techlevel:=x*256+y;
congeniality:=abs(alien.congeniality+random(11)-5);
anger:=abs(alien.anger+random(11)-5);
alienid:=alien.id;
case orders of
WNDORDER_ATTACK: begin
relx:=3000+random(10000);
if random(2)=1 then relx:=-relx;
rely:=3000+random(10000);
if random(2)=1 then rely:=-rely;
relz:=3000+random(10000);
if random(2)=1 then relz:=-relz;
end;
WNDORDER_RETREAT: begin
relx:=5000+random(12000);
if random(2)=1 then relx:=-relx;
rely:=5000+random(12000);
if random(2)=1 then rely:=-rely;
relz:=5000+random(12000);
if random(2)=1 then relz:=-relz;
end;
WNDORDER_NONE: begin
relx:=3000+random(2000);
if random(2)=1 then relx:=-relx;
rely:=3000+random(2000);
if random(2)=1 then rely:=-rely;
relz:=3000+random(2000);
if random(2)=1 then relz:=-relz;
end;
end;
end;
end;
procedure checkwandering;
var confile: file of alientype;
begin
if ship.wandering.alienid<16000 then exit;
assign(confile,loc_tmp()+'contacts.dta');
reset(confile);
if ioresult<>0 then errorhandler('contacts.dta',1);
repeat
read(confile,alien);
until (alien.id=curplan) or (ioresult<>0);
close(confile);
if (alien.id=curplan) and (alien.anger>0) and (alien.congeniality/alien.anger<0.7) then createwandering(WNDORDER_ATTACK);
end;
procedure gettechlevel(plan: integer);
var i: integer;
begin
if tempplan^[plan].orbit=0 then
begin
techlvl:=0;
exit;
end;
techlvl:=-2;
case tempplan^[plan].system of
93,138,78,191,171,221:
begin
techlvl:=6*256;
exit;
end;
45: if chevent(27) then
begin
techlvl:=0;
exit;
end
else
begin
techlvl:=6*256;
exit;
end;
end;
case tempplan^[plan].state of
2: case tempplan^[plan].mode of
2: techlvl:=-1;
3: techlvl:=tempplan^[plan].age div 15000000;
end;
3: begin
techlvl:=(tempplan^[plan].mode-1)*256;
case tempplan^[plan].mode of
1: techlvl:=techlvl+(tempplan^[plan].age div 1500000);
2: techlvl:=techlvl+(tempplan^[plan].age div 1000);
3: techlvl:=techlvl+(tempplan^[plan].age div 800);
end;
end;
4: begin
techlvl:=(tempplan^[plan].mode+2)*256;
case tempplan^[plan].mode of
1: techlvl:=techlvl+(tempplan^[plan].age div 400);
2: techlvl:=techlvl+(tempplan^[plan].age div 200);
end;
end;
5: case tempplan^[plan].mode of
1: begin
i:=tempplan^[plan].age div 100000000;
if i>9 then i:=9;
techlvl:=techlvl+i;
end;
2: techlvl:=-1;
end;
6: if tempplan^[curplan].mode=2 then techlvl:=6*256; {void dwellers}
end;
i:=random(9); { junk first random number }
eattype:=random(3);
randomize;
end;
procedure getname(n: integer);
type nametype= string[15];
var str1: nametype;
f: file of nametype;
begin
n:=n-tempplan^[n].system;
assign(f,loc_data()+'planname.txt');
reset(f);
if ioresult<>0 then errorhandler('data/planname.txt',1);
seek(f,n);
if ioresult<>0 then errorhandler('data/planname.txt',6);
read(f,str1);
if ioresult<>0 then errorhandler('data/planname.txt',6);
alien.name:=str1;
close(f);
end;
procedure addtofile;
var confile: file of alientype;
err,already: boolean;
temp: alientype;
index: integer;
begin
assign(confile,loc_tmp()+'contacts.dta');
reset(confile);
if ioresult<>0 then errorhandler('contacts.dta (adding new alien)',1);
err:=false;
already:=false;
index:=-1;
repeat
inc(index);
read(confile,temp);
if ioresult<>0 then err:=true;
if temp.id=alien.id then already:=true;
until (err) or (already);
if err then { add to end }
begin
seek(confile,index);
if ioresult<>0 then errorhandler(loc_tmp()+'contacts.dta (appending alien)',5);
write(confile,alien);
if ioresult<>0 then errorhandler(loc_tmp()+'contacts.dta (appending alien)',5);
end;
close(confile);
end;
{ fills alien structure with gamedata from file for alien "n" (unless n=13), and sets index to "contactindex" }
procedure getspecial(n,contactindex: integer);
var f: file of alientype;
begin
if n=13 then
begin
alien.id:=contactindex;
exit;
end;
assign(f,loc_data()+'contact0.dta');
reset(f);
if ioresult<>0 then errorhandler('data/contact0.dta',1);
seek(f,n-1);
if ioresult<>0 then errorhandler('data/contact0.dta',5);
read(f,alien);
if ioresult<>0 then errorhandler('data/contact0.dta',5);
alien.id:=contactindex;
close(f);
end;
procedure setalienstructure(starting: integer);
begin
case tempplan^[contactindex].system of
93: getspecial(1,contactindex);
138: getspecial(2,contactindex);
45: if not chevent(27) then getspecial(4,contactindex);
221: getspecial(5,contactindex);
78: getspecial(6,contactindex);
171: getspecial(8,contactindex);
191: getspecial(9,contactindex);
else
if (tempplan^[contactindex].mode=2) and (tempplan^[contactindex].state=6)
then getspecial(11,contactindex)
else
begin
case hi(techlvl) of
3: x:=1;
4: x:=2;
5: x:=3;
else x:=0;
end;
alien.conindex:=30+x;
getname(contactindex);
x:=hi(techlvl);
y:=lo(techlvl);
with alien do
begin
y:=y-5;
if y<0 then
begin
dec(x);
y:=10+y;
end;
if x<0 then
begin
x:=0;
y:=0;
end;
techmin:=x*256+y;
y:=lo(techlvl);
y:=y+5;
if y>9 then
begin
inc(x);
y:=y-10;
end;
if x>5 then
begin
x:=5;
y:=0;
end;
techmax:=x*256+y;
id:=contactindex;
victory:=random(40);
war:=false;
case starting of
1: begin
if random(3)=0 then war:=true;
congeniality:=15;
anger:=30;
createwandering(WNDORDER_ATTACK);
end;
2: begin
congeniality:=20;
anger:=10;
end;
3: begin
congeniality:=40;
anger:=0;
end;
4: begin
congeniality:=20;
anger:=15;
end;
5: begin
congeniality:=5;
anger:=0;
createwandering(WNDORDER_RETREAT);
end;
end;
end;
end;
end;
addtofile;
end;
procedure clearconvflags;
var
i : Integer;
begin
for i := 500 to 599 do
clearevent(i);
end; { clearconvflags }
procedure contactsequence(plan,com: integer);
var contactmade: integer;
begin
mousehide;
if plan=0 then techlvl:=alien.techmax
else if (plan>-1) and (plan<1000) then gettechlevel(plan)
else if plan>1000 then techlvl:=1280
else techlvl:=0;
if techlvl<1 then
begin
printxy(12,135,'Unintelligible Cypher');
printxy(12,145,'Contact Failure');
mouseshow;
exit;
end;
contactmade:=0;
if (hi(techlvl)<4) then
case eattype of
0: contactmade:=1;
1: case com of
0: contactmade:=5;
1: contactmade:=3;
2: contactmade:=2;
end;
2: contactmade:=random(5);
end
else
case eattype of
0: case com of
0: if random(2)=0 then contactmade:=1 else contactmade:=3;
1: contactmade:=2+random(2);
2: contactmade:=2;
end;
1: case com of
0: contactmade:=4;
1: contactmade:=2+random(2);
2: contactmade:=2;
end;
2: contactmade:=random(5);
end;
if (contactmade>0) and (contactindex=-1) then
begin
contactindex:=plan;
tempplan^[contactindex].notes:=tempplan^[contactindex].notes or 2;
setalienstructure(contactmade);
end;
printxy(12,135,'Cypher Acknowledged');
printxy(12,145,'Awaiting Response');
if contactmade>0 then printxy(12,155,'Contact Established')
else contactindex:=-1;
mouseshow;
end;
{***************************************************************************}
procedure loadconversation;
var fc: file of converseindex;
fr: file of responsetype;
str1: string[4];
begin
fillchar(r^,sizeof(responsearray),0);
fillchar(c^,sizeof(conversearray),0);
str((contactindex+1):4,str1);
if contactindex<1000 then str1[1]:='0';
if contactindex<100 then str1[2]:='0';
if contactindex<10 then str1[3]:='0';
assign(fc,loc_data()+'conv'+str1+'.ind');
reset(fc);
if ioresult<>0 then errorhandler('data/conv'+str1+'.ind',1);
i:=0;
repeat
inc(i);
read(fc,c^[i]);
until ioresult<>0;
close(fc);
assign(fr,loc_data()+'conv'+str1+'.dta');
reset(fr);
if ioresult<>0 then errorhandler('data/conv'+str1+'.dta',1);
i:=0;
repeat
inc(i);
read(fr,r^[i]);
until ioresult<>0;
close(fr);
end;
procedure showportrait(n: integer);
var s: string[2];
portrait: ^portraittype;
begin
new(portrait);
str(n:2,s);
if n<10 then s[1]:='0';
loadscreen(loc_data()+'image'+s,portrait);
for i:=0 to 34 do
begin
scrto_move(portrait^[i*2],screen[i*2+41,126],70);
delay(tslice div 5);
end;
for i:=0 to 34 do
begin
scrto_move(portrait^[i*2+1],screen[i*2+42,126],70);
delay(tslice div 5);
end;
dispose(portrait);
end;
procedure drawcursor;
begin
for i:=(contactindex mod 3)*30+37 to (contactindex mod 3)*30+42 do
for j:=(contactindex div 3)*138+89 to (contactindex div 3)*138+93 do
if screen[i,j] div 16=3 then screen[i,j]:=screen[i,j]+32;
showportrait(ship.crew[contactindex+1].index);
end;
procedure erasecursor;
begin
for i:=(contactindex mod 3)*30+37 to (contactindex mod 3)*30+42 do
for j:=(contactindex div 3)*138+89 to (contactindex div 3)*138+93 do
if screen[i,j] div 16=5 then screen[i,j]:=screen[i,j]-32;
end;
procedure displaycrewnames;
var a,b: integer;
begin
t1:=22/36;
for a:=0 to 5 do
begin
if (ship.crew[a+1].index=18) or (ship.crew[a+1].index=25) or (ship.crew[a+1].index=26)
then i:=6 else i:=1;
b:=1;
repeat
printxy((a div 3)*230+12+b*5,(a mod 3)*30+37,ship.crew[a+1].name[i]);
inc(i);
inc(b);
until ship.crew[a+1].name[i]=' ';
j:=round((0.40*ship.crew[a+1].men+0.60*ship.crew[a+1].emo-0.20*ship.crew[a+1].phy)*0.36);
if j>36 then j:=36
else if j<1 then j:=0;
for b:=0 to j do
begin
screen[(a mod 3)*30+48,(a div 3)*258+b+13]:=round(t1*b)+73;
screen[(a mod 3)*30+49,(a div 3)*258+b+13]:=round(t1*b)+73;
end;
if j<34 then
for b:=j+1 to 36 do
begin
screen[(a mod 3)*30+48,(a div 3)*258+b+13]:=0;
screen[(a mod 3)*30+49,(a div 3)*258+b+13]:=0;
end;
end;
end;
procedure checkstring(p,q,s: integer); forward;
procedure command2(n: integer);
begin
mousehide;
for i:=135 to 189 do
scr_fillchar(screen[i,15],278,0);
printxy(12,182,'Subject:');
if contactindex>-1 then erasecursor;
contactindex:=n;
drawcursor;
showportrait(ship.crew[contactindex+1].index);
mouseshow;
loadconversation;
question:='HI';
{checkstring(95,176,170);}
checkstring(95,42,170);
end;
procedure findmouse2;
begin
if not mouse.getstatus then exit;
case mouse.y of
30..50: case mouse.x of
9..85: if contactindex<>0 then command2(0);
235..311: if contactindex<>3 then command2(3);
end;
60..80: case mouse.x of
9..85: if contactindex<>1 then command2(1);
235..311: if contactindex<>4 then command2(4);
end;
90..110: case mouse.x of
9..85: if contactindex<>2 then command2(2);
235..311: if contactindex<>5 then command2(5);
end;
154..170: if mouse.x>309 then done:=true;
end;
idletime:=0;
end;
procedure printxy2(x1,y1,m,n,o: integer; s: string);
var letter,j2,a,x,y,t : integer;
label skipit;
begin
t:=tcolor;
brighter:=false;
j2:=0;
x1:=x1+4;
for j:=1 to length(s) do
begin
if s[j]=#200 then
begin
if brighter then brighter:=false else brighter:=true;
goto skipit;
end;
letter:=ord(s[j]);
if brighter then
tcolor := n
else
{if (brighter) then
case ship.options[OPT_DIFFICULTY] of
0: tcolor:=m;
1: tcolor:=n;
2: tcolor:=o;
end
else} tcolor:=o;
bkcolor:=m;
inc(j2);
y:=y1;
for i:=0 to 5 do
begin
inc(y);
x:=x1;
for a:=7 downto 4 do
begin
inc(x);
if font[ship.options[OPT_FONT],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,1);
x:=x1;
inc(y);
inc(i);
for a:=3 downto 0 do
begin
inc(x);
if font[ship.options[OPT_FONT],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,2);
end;
for i:=1 to 6 do screen[y1+i,x1+5]:=bkcolor;
delay(tslice div 3);
bkcolor:=0;
if brighter then
tcolor := n
else
{ if (brighter) then
case ship.options[OPT_DIFFICULTY] of
0: tcolor:=m;
1: tcolor:=n;
2: tcolor:=o;
end
else} tcolor:=o;
y:=y1;
for i:=0 to 5 do
begin
x:=x1;
inc(y);
for a:=7 downto 4 do
begin
inc(x);
if font[ship.options[OPT_FONT],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,1);
inc(i);
inc(y);
x:=x1;
for a:=3 downto 0 do
begin
inc(x);
if font[ship.options[OPT_FONT],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor
else if bkcolor<255 then screen[y,x]:=bkcolor;
end;
dec(tcolor,2);
end;
for i:=1 to 6 do screen[y1+i,x1+5]:=bkcolor;
x1:=x1+5;
skipit:
end;
tcolor:=t;
end;
function parsestatement(y,n,p,q,s: integer): integer;
var done: boolean;
a,b,c,i2,letter: integer;
begin
str1^:=r^[n].response;
i:=1;
j:=1;
{copy response string, inserting crew names if needed}
repeat
if str1^[i]=#201 then
begin
inc(i);
a:=ord(str1^[i])+35-48;
b:=20;
while ship.crew[a].name[b]=' ' do dec(b);
for c:=1 to b do
begin
letter:=ord(ship.crew[a].name[c]);
case chr(letter) of
' ' ..'"': letter:=letter-31;
''''..'?': letter:=letter-35;
'A' ..'Z': letter:=letter-36;
'a' ..'z': letter:=letter-40;
else letter:=1;
end;
str2^[j]:=chr(letter);
inc(j);
end;
dec(j);
end
else str2^[j]:=str1^[i];
inc(j);
inc(i);
until i>ord(str1^[0]);
str2^[0]:=chr(j-1);
done:=false;
repeat
str1^:=str2^;
i:=56;
if ord(str1^[0])>56 then
begin
while str1^[i]<>#1 do dec(i);
str2^:=copy(str1^,i+1,ord(str1^[0])-i);
str1^[0]:=chr(i-1);
end else done:=true;
printxy2(12,135+y*6,p,q,s,str1^);
inc(y);
if y=8 then
begin
for j:=184 to 188 do
scr_fillchar(screen[j,15],288,0);
tcolor:=47;
printxy(146,191,'MORE');
i2:=47;
mouseshow;
repeat
fadestep(FADESTEP_STEP);
tcolor:=i2;
printxy(146,191,'MORE');
dec(i2);
if i2=41 then i2:=47;
animatealien;
delay(tslice*FADE_TSLICE_MUL_COMM);
until (fastkeypressed) or (mouse.getstatus);
while fastkeypressed do readkey;
mousehide;
for j:=141 to 188 do
scr_fillchar(screen[j,15],288,0);
printxy(146,191,' ');
tcolor:=s;
y:=1;
end;
until done;
parsestatement:=y;
end;
{ 2000x events set while conversing with some race, in Data_Generators/makedata/*con*.txt }
procedure run20000event(n: integer);
begin
case n of
20000: begin {good bye}
for i:=182 to 188 do
scr_fillchar(screen[i,12],200,0);
contactindex:=-1;
end;
20001: begin {trade}
if alien.war then
begin
for i:=141 to 181 do
scr_fillchar(screen[i,12],288,0);
printxy(12,141,'WE ARE AT WAR!');
end
else trade;
end;
20002: begin {attack!}
for i:=182 to 188 do
scr_fillchar(screen[i,12],200,0);
contactindex:=-1;
createwandering(WNDORDER_ATTACK);
ship.wandering.relx:=500+random(100);
ship.wandering.rely:=500+random(100);
ship.wandering.relz:=500+random(100);
end;
20003: begin {increase anger by 1} // FIXME: not used in *con*.txt ?
if alien.anger<100 then inc(alien.anger);
if infomode then
begin
getinfo;
getinfo;
end;
end;
20004: begin {increase anger by 5} // FIXME: not used in *con*.txt ?
inc(alien.anger,5);
if alien.anger>100 then alien.anger:=100;
begin
getinfo;
getinfo;
end;
end;
20005: begin {increase congeniality by 1} // FIXME: not used in *con*.txt ?
if alien.congeniality<100 then inc(alien.congeniality);
if infomode then
begin
getinfo;
getinfo;
end;
end;
20006: begin {increase congeniality by 5} // FIXME: not used in *con*.txt ?
inc(alien.congeniality,5);
if alien.congeniality>100 then alien.congeniality:=100;
begin
getinfo;
getinfo;
end;
end;
end;
end;
function run21000event(n, p,q,s: integer) : Boolean;
var result : boolean;
begin
run21000event := false;
assert ((p <> -1) and (q <> - 1)); { just to get rid of warning, really not used }
case n of
21001 : begin {Phaedor Moch: Coolant + Radioactive}
if (incargo(ID_COOLANTS) >= 1) and (incargo(ID_RADIOACTIVES) >= 1) then
begin
bkcolor := 0;
tcolor := s;
printxy(12,135+(1)*6,'Give the Phaedor Moch a radioactive and a coolant?');
mouseshow;
result := yesnorequest('Give supplies?',0,31);
mousehide;
if result then
begin
removecargo(ID_COOLANTS);
removecargo(ID_RADIOACTIVES);
addcargo(ID_ART_GLYPTIC_SCYTHE, true);
run21000event := true;
addpending(1101, 0);
event(500);
end else begin
printxy(12,135+(2)*6,'No.');
end;
end else begin
bkcolor := 0;
tcolor := s;
printxy(12,135+(1)*6,'(Eng: We have no radioactives and coolants to spare.)');
end;
end;
21002 : begin {Aard: Stratamount}
if (incargo(ID_STRATAMOUNT) >= 1) then
begin
printxy(12,135+(1)*6,'Give the Aard a stratamount?');
mouseshow;
result := yesnorequest('Give supplies?',0,31);
mousehide;
if result then
begin
removecargo(ID_STRATAMOUNT);
addcargo(ID_BALLISTA, true);
run21000event := true;
addpending(1102, 0);
event(500);
end else begin
printxy(12,135+(2)*6,'No.');
end;
end else begin
bkcolor := 0;
tcolor := s;
printxy(12,135+(1)*6,'(Eng: We have no stratamounts to spare.)');
end;
end;
end;
end;
procedure checkstring(p,q,s: integer);
var index,index2,i,i2: integer;
begin
mousehide;
for i:=135 to 181 do
scr_fillchar(screen[i,15],288,0);
for i:=182 to 187 do
scr_fillchar(screen[i,61],100,0);
tcolor:=s;
printxy(12,135,question);
i:=20;
while question[i]=' ' do dec(i);
if i=0 then
begin
mouseshow;
exit;
end;
question[0]:=chr(i);
for j:=1 to i do
case question[j] of
' ' ..'"': question[j]:=chr(ord(question[j])-31);
''''..'?': question[j]:=chr(ord(question[j])-35);
'A' ..'Z': question[j]:=chr(ord(question[j])-36);
'a' ..'z': question[j]:=chr(ord(question[j])-40);
'%' : question[j]:=#55;
else question[j]:=#1;
end;
index:=0;
{i:=1;}
repeat
inc(index);
j:=pos(#1+question+#1,c^[index].keyword);
{if j > 0 then
begin
str(index,str1^);
str(ord(chevent(c^[index].event)),str2^);
str1^ := str1^ + ',' + str2^;
str(c^[index].event,str2^);
printxy(1, i * 6, str1^ + ',' + str2^ + ' ');
inc(i);
printxy(1, i * 6, ' ');
end;}
if (c^[index].event <> -1) and not chevent(c^[index].event) then
j := 0;
until (j>0) or (c^[index].rcode=0);
fillchar(question,21,ord(' '));
question[0]:=#20;
cursorx:=1;
if j=0 then
begin
mouseshow;
exit;
end;
i:=1;
while (r^[i].index<>c^[index].index) and (i<=maxconverse) do inc(i);
if i>maxconverse then
begin
str(c^[index].index,str1^);
errorhandler('index:'+str1^+' keyword:'+question+' not found.',6);
end;
if (c^[index].runevent<21000) or run21000event(c^[index].runevent,p,q,s) then
begin
case c^[index].rcode of
1 : parsestatement(1,i,p,q,s);
2 : begin
j:=1;
while r^[i+j].index=c^[index].index do inc(j);
parsestatement(1,i+random(j),p,q,s);
end;
3 : begin
index2:=i;
i2:=1;
repeat
i2:=parsestatement(i2,index2,p,q,s);
inc(index2);
until r^[i].index<>r^[index2].index;
printxy(12,182,'Subject:');
end;
end; { case }
end;
if (c^[index].runevent>19999) and (c^[index].runevent<21000) then
run20000event(c^[index].runevent);
mouseshow;
end;
procedure processkey2;
var ans: char;
old: integer;
begin
// writeln('comm.pas:917 processkey2');
// p^:=0;
ans:=upcase(readkey_utf8);
// ans:=readkey;
// writeln('key= ',ord(ans));
tcolor:=31;
case ans of
'A'..'Z',' ','0'..'9','''','-': if contactindex>-1 then
begin
if cursorx<20 then
begin
for j:=20 downto cursorx do question[j]:=question[j-1];
question[cursorx]:=ans;
inc(cursorx);
end else question[cursorx]:=ans;
mousehide;
printxy(57,182,question);
mouseshow;
end;
#8: if contactindex>-1 then
begin
if cursorx>1 then dec(cursorx);
for j:=cursorx to 19 do question[j]:=question[j+1];
question[20]:=' ';
mousehide;
printxy(57,182,question);
mouseshow;
end;
#0: if contactindex>-1 then
begin
ans:=readkey;
case ans of
#77: if cursorx<20 then inc(cursorx);
#75: if cursorx>1 then dec(cursorx);
#83: begin
for j:=cursorx to 19 do question[j]:=question[j+1];
mousehide;
printxy(57,182,question);
mouseshow;
end;
#59: command2(0);
#60: command2(1);
#61: command2(2);
#62: command2(3);
#63: command2(4);
#64: command2(5);
end;
end
else
begin
ans:=readkey;
if (ans>#58) and (ans<#65) then command2(ord(ans)-59);
end;
#13: if contactindex>-1 then
begin
old:=contactindex;
{checkstring(95,176,170);}
checkstring(95,42,170);
if contactindex=-1 then
begin
i:=old;
old:=contactindex;
contactindex:=i;
erasecursor;
contactindex:=old;
end;
end;