forked from y-salnikov/ironseed_fpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
journey.pas
1575 lines (1509 loc) · 43.4 KB
/
journey.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 journey;
(********************************************************************
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/>.
********************************************************************)
{*********************************************
Main Control unit for IronSeed
Copyright:
1994 Channel 7, Destiny: Virtual
2013 y-salnikov
2020 Matija Nalis <[email protected]>
**********************************************}
{$I-}
interface
procedure print(s: string);
procedure println;
procedure showtime;
procedure addtime;
procedure setalertmode(mode: integer; do_shields: boolean);
procedure makesphere;
procedure makegasplanet;
procedure makestar;
procedure shadowprint(s: string);
procedure shadowprintln;
procedure displaytextbox(scrollit: boolean);
procedure mainloop;
implementation
uses utils_, gmouse, usecode, data, saveload, utils, display, combat, utils2, weird, modplay, comm, crewtick, heapchk;
const
asintab :array[0..1024] of byte =
(0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,
2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3, {fudged}
{2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,} {proper}
4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,
5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,
7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,
9,9,9,9,9,10,10,10,10,10,10,10,10,10,11,11,
11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,
14,14,15,15,15,15,15,15,15,15,15,16,16,16,16,16,
16,16,16,17,17,17,17,17,17,17,17,17,18,18,18,18,
18,18,18,18,18,19,19,19,19,19,19,19,19,19,20,20,
20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,
22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,
23,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,
25,25,26,26,26,26,26,26,26,26,26,27,27,27,27,27,
27,27,27,27,28,28,28,28,28,28,28,28,28,29,29,29,
29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,
31,31,31,31,31,31,32,32,32,32,32,32,32,32,32,33,
33,33,33,33,33,33,33,33,34,34,34,34,34,34,34,34,
35,35,35,35,35,35,35,35,35,36,36,36,36,36,36,36,
36,37,37,37,37,37,37,37,37,37,38,38,38,38,38,38,
38,38,39,39,39,39,39,39,39,39,39,40,40,40,40,40,
40,40,40,41,41,41,41,41,41,41,41,42,42,42,42,42,
42,42,42,42,43,43,43,43,43,43,43,43,44,44,44,44,
44,44,44,44,45,45,45,45,45,45,45,45,46,46,46,46,
46,46,46,46,46,47,47,47,47,47,47,47,47,48,48,48,
48,48,48,48,48,49,49,49,49,49,49,49,49,50,50,50,
50,50,50,50,50,51,51,51,51,51,51,51,51,52,52,52,
52,52,52,52,52,53,53,53,53,53,53,53,53,54,54,54,
54,54,54,54,54,55,55,55,55,55,55,55,55,56,56,56,
56,56,56,56,56,57,57,57,57,57,57,57,57,58,58,58,
58,58,58,58,58,59,59,59,59,59,59,59,59,60,60,60,
60,60,60,60,61,61,61,61,61,61,61,61,62,62,62,62,
62,62,62,62,63,63,63,63,63,63,63,64,64,64,64,64,
64,64,64,65,65,65,65,65,65,65,66,66,66,66,66,66,
66,66,67,67,67,67,67,67,67,68,68,68,68,68,68,68,
68,69,69,69,69,69,69,69,70,70,70,70,70,70,70,71,
71,71,71,71,71,71,71,72,72,72,72,72,72,72,73,73,
73,73,73,73,73,74,74,74,74,74,74,74,75,75,75,75,
75,75,75,76,76,76,76,76,76,76,77,77,77,77,77,77,
77,78,78,78,78,78,78,78,79,79,79,79,79,79,79,80,
80,80,80,80,80,80,81,81,81,81,81,81,81,82,82,82,
82,82,82,82,83,83,83,83,83,83,84,84,84,84,84,84,
84,85,85,85,85,85,85,85,86,86,86,86,86,86,87,87,
87,87,87,87,87,88,88,88,88,88,88,89,89,89,89,89,
89,90,90,90,90,90,90,90,91,91,91,91,91,91,92,92,
92,92,92,92,93,93,93,93,93,93,94,94,94,94,94,94,
95,95,95,95,95,95,96,96,96,96,96,96,97,97,97,97,
97,97,98,98,98,98,98,98,99,99,99,99,99,99,100,100,
100,100,100,100,101,101,101,101,101,102,102,102,102,102,102,103,
103,103,103,103,103,104,104,104,104,104,105,105,105,105,105,105,
106,106,106,106,106,107,107,107,107,107,108,108,108,108,108,108,
109,109,109,109,109,110,110,110,110,110,111,111,111,111,111,112,
112,112,112,112,113,113,113,113,113,114,114,114,114,114,115,115,
115,115,115,116,116,116,116,117,117,117,117,117,118,118,118,118,
118,119,119,119,119,120,120,120,120,120,121,121,121,121,122,122,
122,122,123,123,123,123,123,124,124,124,124,125,125,125,125,126,
126,126,126,127,127,127,127,128,128,128,128,129,129,129,129,130,
130,130,131,131,131,131,132,132,132,132,133,133,133,134,134,134,
134,135,135,135,136,136,136,136,137,137,137,138,138,138,139,139,
139,140,140,140,141,141,141,142,142,142,143,143,143,144,144,144,
145,145,146,146,146,147,147,147,148,148,149,149,150,150,150,151,
151,152,152,153,153,154,154,155,155,156,156,157,157,158,158,159,
160,160,161,162,162,163,164,165,166,167,168,169,170,171,173,175,
180);
var
alt, i,j,q,m,index,a,b,j2,ofsx,ofsy,clickcode: integer;
part: real;
part4: real;
s: string[30];
msg,oldcube: integer;
procedure printstring(x1,y1: integer; snum: byte);
var letter,x,y: integer;
color: byte;
begin
color:=tcolor;
s:=textdisplay^[snum];
x1:=x1+4;
for j:=1 to 30 do
begin
tcolor:=colordisplay^[snum,j];
case s[j] of
'a'..'z': letter:=ord(s[j])-40;
'A' ..'Z': letter:=ord(s[j])-36;
' ' ..'"': letter:=ord(s[j])-31;
''''..'?': letter:=ord(s[j])-35;
'%': letter:=55;
else letter:=1;
end;
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 shr 1] and (1 shl a)>0 then screen2^[y,x]:=tcolor
else if bkcolor<255 then screen2^[y,x]:=bkcolor;
end;
inc(y);
x:=x1;
inc(i);
dec(tcolor,2);
for a:=3 downto 0 do
begin
inc(x);
if font[ship.options[OPT_FONT],letter,i shr 1] and (1 shl a)>0 then screen2^[y,x]:=tcolor
else if bkcolor<255 then screen2^[y,x]:=bkcolor;
end;
dec(tcolor,2);
end;
x1:=x1+5;
for i:=1 to 6 do screen2^[i+y1,x1]:=bkcolor;
end;
tcolor:=color;
end;
procedure displaytextbox(scrollit: boolean);
var i2: integer;
begin
if cursorx>1 then
begin
for i2:=textindex to textindex+5 do printstring(9,(i2-textindex)*6+150,i2);
mousehide;
for i:=151 to 186 do scrto_move(screen2^[i,11],screen[i,11],150);
end
else
begin
for i2:=textindex-1 to textindex+5 do
printstring(9,(i2-textindex+1)*6+150,i2);
mousehide;
if scrollit then
for i2:=0 to 6 do
begin
for i:=151 to 186 do scrto_move(screen2^[i+i2,11],screen[i,11],150);
delay(tslice div 3);
end
else
for i:=151 to 186 do scrto_move(screen2^[i,11],screen[i,11],150);
end;
for i:=158 to 182 do
scr_fillchar(screen[i,163],6,2);
for j:=163 to 168 do
screen[157+textindex,j]:=86;
mouseshow;
end;
procedure println;
begin
cursorx:=1;
for j:=0 to 29 do
move(textdisplay^[j+1],textdisplay^[j],30);
fillchar(textdisplay^[30],ord(' '),30);
for j:=0 to 29 do
move(colordisplay^[j+1],colordisplay^[j],30);
fillchar(colordisplay^[30],30,0);
displaytextbox(true);
end;
procedure print(s: string);
var maxsize: byte;
s1: string[30];
s2: string[100];
color: byte;
begin
textindex:=25;
color:=tcolor;
if (length(s)+cursorx)>30 then
begin
maxsize:=31-cursorx;
repeat
dec(maxsize);
until (s[maxsize]=' ') or (s[maxsize]='.') or
(s[maxsize]=',') or (maxsize=0);
if maxsize=0 then begin println; print(s); end
else
begin
s1:=copy(s,1,maxsize);
s2:=copy(s,maxsize+1,length(s));
print(s1);
println;
tcolor:=color;
print(s2);
end;
end
else
begin
for j:=1 to length(s) do
begin
textdisplay^[30,cursorx+j-1]:=s[j];
colordisplay^[30,cursorx+j-1]:=tcolor;
end;
cursorx:=cursorx+length(s);
end;
displaytextbox(true);
end;
procedure shadowprintln;
begin
cursorx:=1;
for j:=0 to 29 do
move(textdisplay^[j+1],textdisplay^[j],30);
fillchar(textdisplay^[30],ord(' '),30);
for j:=0 to 29 do
move(colordisplay^[j+1],colordisplay^[j],30);
fillchar(colordisplay^[30],30,0);
end;
procedure shadowprint(s: string);
var maxsize: byte;
s1,s2: ^string;
color: byte;
begin
new(s1);
new(s2);
textindex:=25;
color:=tcolor;
if (length(s)+cursorx)>30 then
begin
maxsize:=31-cursorx;
repeat
dec(maxsize);
until (s[maxsize]=' ') or (s[maxsize]='.') or
(s[maxsize]=',') or (maxsize=0);
if maxsize=0 then
begin
shadowprintln;
shadowprint(s);
end
else
begin
s1^:=copy(s,1,maxsize);
s2^:=copy(s,maxsize+1,length(s));
shadowprint(s1^);
shadowprintln;
tcolor:=color;
shadowprint(s2^);
end;
end
else
begin
for j:=1 to length(s) do
begin
textdisplay^[30,cursorx+j-1]:=s[j];
colordisplay^[30,cursorx+j-1]:=tcolor;
end;
cursorx:=cursorx+length(s);
end;
dispose(s1);
dispose(s2);
end;
procedure getcube(src,tar: byte);
begin
assert ((src<=9*9) and (tar<=9*9)); // to turn off warnings, we don't really use those variables here
move(cubetar^,cubesrc^,sizeof(cubetype));
for a:=0 to 2 do
for b:=0 to 2 do
for j:=0 to 16 do
for i:=0 to 14 do
cubetar^[b*15+i,a*17+j]:=icons^[tar*9+a*3+b,j,i];
end;
procedure rotatecube2(src,tar: byte; fkey: boolean);
label skip1;
begin {215,145}
getcube(src,tar);
if (ship.options[OPT_ANIMATION]=0) or (fkey) then
begin
mousehide;
for i:=0 to 44 do
scrto_move(cubetar^[i,0],screen[i+145,215],51);
mouseshow;
cube:=tar;
exit;
end;
b:=tslice div 4;
mousehide;
for t:=1 to 21 do
begin
m:=round(10.5624*sin(3*t/20));
q:=round(sin(3*t/40)*51);
part:=51/q;
for j:=0 to q-1 do
begin
index:=round(j*part);
if index<51 then
for i:=145 to 189 do
screen[i,j+215-m]:=cubetar^[i-145,index];
end;
if (51+2*m-q)=0 then goto skip1;
part:=51/(51+2*m-q);
for j:=215-m+q to 266+m do
begin
index:=round((j-215+m-q)*part);
if index<51 then
for i:=145 to 189 do
screen[i,j]:=cubesrc^[i-145,index];
end;
skip1:
for i:=145 to 189 do
begin
for j:=266+m to 278 do screen[i,j]:=back4[j-266,i-145];
for j:=202 to 214-m do screen[i,j]:=back3[j-202,i-145];
end;
mouseshow;
delay(b);
mousehide;
end;
for i:=0 to 44 do
scrto_move(cubetar^[i,0],screen[i+145,215],51);
mouseshow;
cube:=tar;
end;
procedure rotatecube(src,tar: byte; fkey: boolean);
label skip1;
begin {215,145}
if tar+src=5 then
begin
if (tar=2) or (tar=3) then rotatecube2(src,tar-2,fkey)
else if (tar>0) then rotatecube2(src,tar-1,fkey)
else rotatecube2(src,tar+1,fkey);
end;
if random(4)=0 then
begin
rotatecube2(src,tar,fkey);
exit;
end;
getcube(src,tar);
if (ship.options[OPT_ANIMATION]=0) or (fkey) then
begin
mousehide;
for i:=0 to 44 do
scrto_move(cubetar^[i,0],screen[i+145,215],51);
mouseshow;
cube:=tar;
exit;
end;
mousehide;
for i:=133 to 144 do
scrfrom_move(screen[i,215],back1[i-133],13*4);
b:=tslice div 4;
for t:=1 to 20 do
begin
m:=round(10.5624*sin(3*t/20));
q:=round(sin(3*t/40)*45);
part:=45/q;
for j:=0 to q-1 do
begin
index:=round(j*part);
if index<46 then
for i:=215 to 265 do
screen[j+145-m,i]:=cubetar^[index,i-215];
end;
if (45+2*m-q)=0 then goto skip1;
part:=45/(45+2*m-q);
for j:=145-m+q to 188+m do
begin
index:=round((j-145+m-q)*part);
if index<46 then
for i:=215 to 265 do
screen[j,i]:=cubesrc^[index,i-215];
end;
skip1:
for j:=133 to 145-m do
scrto_move(back1[j-133],screen[j,215],13*4);
for j:=190+m to 199 do
scrto_move(back2[j-190],screen[j,215],13*4);
mouseshow;
delay(b);
mousehide;
end;
for i:=0 to 44 do
scrto_move(cubetar^[i],screen[i+145,215],51);
scrto_move(back2,screen[190,215],13*4);
mouseshow;
cube:=tar;
end;
function asin(x : Real) : Real;
begin
asin := ArcTan(x / sqrt(1 - sqr(x)));
end;
function fmod(x, y : Real) : Real;
begin
fmod := x - Int(x / y) * y;
end;
procedure rendersphere(xx, yy, radius : Integer; angle : Real; eclipse: Boolean; ecl : Real);
var
x, y : Integer;
sx, sy : Integer;
ax : Integer;
e1, e2, ed : Integer;
radius2 : Integer;
radius1 : Real;
radiusx : Integer;
c : Integer;
ox : Integer;
begin
e1 := round(ecl) mod 360;
{e2 := fmod(ecl + 210, 360);}
e2 := 240;{fmod(240, 360);}
Radius2 := radius * radius;
ox := round(angle * 240 / 360) mod 240;
for y := -radius to radius do
begin
if ((yy + y) >= 1) and ((yy + y) < 120) then
begin
{ay := round(asin(y / radius) / PI * 180);
sy := 120 * (ay + 90) / 181; }{proper y source value*/}
sy := round(120 * (y + radius) / (Radius * 2 + 1)); {cheating y source, looks better}
radius1 := sqrt(radius2 - y * y);
radiusx := round(radius1 + 1);
for x := -Radiusx to Radiusx do
begin
if (x * x + y * y < Radius2) and ((xx + x) >= 1) and ((xx + x) <= 120) then
begin
{ax := Round(angle + asin(x / Radius1) / PI * 180);
sx := ((120 * (ax + 90) div 181) + 239) mod 240 + 1;}
if x < 0 then
begin
ax := -asintab[round(1024 / Radius1 * -x)];
end else begin
ax := asintab[round(1024 / Radius1 * x)];
end;
sx := (90 + ox + ax div 3) mod 240 + 1;
ax := ax shr 1;
c := colorlookup[landform^[sx, sy]];
if c < 6 then
c := spcindex[c];
if (c > 246) and eclipse then
c := 116
else if eclipse then
begin
ax := (ax + 360 - e1) mod 360;
if (ax > 0) and (ax < e2) then
begin
if(abs(ax - 0) < abs(ax - e2)) then
ed := abs(ax - 0)
else
ed := abs(ax - e2);
if (ed > 60) then
ed := 60;
if c < 32 then
c := c * (80 - ed) div 60
else
c := (c and $f0) or ((c and $0f) * ((60 - ed) div 60));
end;
end;
planet^[yy + y, xx + x] := c;
end;
end;
end;
end;
end;
procedure makegasplanet;
label endcheck;
var
ii : Integer;
begin
for i:=6 to 2*r2+4 do
begin
ii := 119 * (i - 6) div (2 * r2 -2) + 1;
alt:=0;
ofsy:=i+offset;
ofsx:=pm[i]+offset;
part4:=0;
for j:=1 to xw do
begin
part4:=part4+ppart[i];
index:=round(part4);
if index>xw then goto endcheck;
inc(ofsx);
if ecl>170 then
begin
if j=1 then alt:=6
else alt:=(index-ecl+186) div 2;
end
else if ecl<171 then
begin
if index=xw then alt:=6
else alt:=(ecl-index) div 2
end
else alt:=0;
if alt<0 then alt:=0;
if (index+c)>240 then j2:=index+c-240
else j2:=index+c;
if alt>(landform^[j2,ii] mod 16) then planet^[ofsy,ofsx]:=1
else planet^[ofsy,ofsx]:=landform^[j2,ii]-alt;
endcheck:
end;
end;
mousehide;
for i:=1 to 120 do
scrto_move(planet^[i],screen[i+12,28],30*4);
mouseshow;
inc(c);
if c>240 then c:=c-240;
end;
procedure makesphere1;
label endcheck;
var
ii : Integer;
begin
ofsy:=5+offset;
for i:=6 to spherei do
begin
ii := 60 * i div spherei;
inc(ofsy);
ofsx:=pm[i]+offset;
part4:=0;
for j:=1 to xw do
begin
part4:=part4+ppart[i];
index:=round(part4);
if index>xw then goto endcheck;
inc(ofsx);
if ecl>170 then
begin
if j=1 then alt:=10
else alt:=(index-ecl+186) div 2;
end
else if ecl<171 then
begin
if index=xw then alt:=10
else alt:=(ecl-index) div 2;
end
else alt:=0;
if alt<0 then alt:=0;
j2:=index+c;
if j2>240 then j2:=j2-240;
z:=colorlookup[landform^[j2,ii]];
if (z=waterindex) and (alt<6) then planet^[ofsy,ofsx]:=waterindex+6-alt
else if z=waterindex then planet^[ofsy,ofsx]:=waterindex
else if z >= 247 then
planet^[ofsy,ofsx] := 116
else
begin
if z<6 then
begin
if alt>spcindex2[z] then z:=1 else z:=spcindex[z]-alt;
end
else if z<32 then
begin
if z>alt then z:=z-alt else z:=1;
end;
planet^[ofsy,ofsx]:=z;
end;
endcheck:
end;
end;
end;
procedure makesphere2;
label endcheck;
var
ii : Integer;
begin
ofsy:=spherei+offset;
for i:=spherei+1 to maxspherei do
begin
ii := 60 * i div spherei;
inc(ofsy);
ofsx:=pm[i]+offset;
part4:=0;
for j:=1 to xw do
begin
part4:=part4+ppart[i];
index:=round(part4);
if index>xw then goto endcheck;
inc(ofsx);
if ecl>170 then
begin
if j=1 then alt:=10
else alt:=(index-ecl+186) div 2;
end
else if ecl<171 then
begin
if index=xw then alt:=10
else alt:=(ecl-index) div 2
end
else alt:=0;
if alt<0 then alt:=0;
j2:=index+c;
if j2>240 then j2:=j2-240;
z:=colorlookup[landform^[j2,ii]];
if (z=waterindex) and (alt<6) then planet^[ofsy,ofsx]:=waterindex+6-alt
else if z=waterindex then planet^[ofsy,ofsx]:=waterindex
else if z >= 247 then
planet^[ofsy,ofsx] := 116
else
begin
if z<6 then
begin
if alt>spcindex2[z] then z:=1 else z:=spcindex[z]-alt;
end
else if z<32 then
begin
if z>alt then z:=z-alt else z:=1;
end;
planet^[ofsy,ofsx]:=z;
end;
endcheck:
end;
end;
end;
procedure makesphere3;
begin
mousehide;
for i:=1 to 120 do
scrto_move(planet^[i],screen[i+12,28],30*4);
mouseshow;
inc(c);
if c>240 then c:=c-240;
end;
procedure makesphere;
begin
makesphere1;
makesphere2;
{rendersphere(60, 60, spherei, c * 360.0 / 240, true, ecl * 360.0 / 240);}
makesphere3;
end;
procedure makestar;
label endcheck;
begin
for i:=6 to 2*r2+4 do
begin
ofsy:=i+offset;
ofsx:=pm[i]+offset;
part4:=0;
for j:=1 to xw do
begin
part4:=part4+ppart[i];
index:=round(part4);
if index>xw then goto endcheck;
inc(ofsx);
if (index+c)>240 then j2:=index+c-240
else j2:=index+c;
if j=1 then alt:=6
else if index=xw then alt:=6
else alt:=0;
if alt>(landform^[j2,i] mod 16) then planet^[ofsy,ofsx]:=landform^[j2,i] div 16
else planet^[ofsy,ofsx]:=landform^[j2,i]-alt;
end;
endcheck:
end;
mousehide;
for i:=1 to 120 do
scrto_move(planet^[i],screen[i+12,28],30*4);
mouseshow;
inc(c);
if c>240 then c:=c-240;
end;
procedure msg1(m: word);
begin
if msg=100+m then exit;
tcolor:=45;
bkcolor:=0;
mousehide;
printxy(208,128,menunames[m]);
mouseshow;
bkcolor:=3;
msg:=100+m;
end;
procedure msg2;
begin
if cube=msg then exit;
tcolor:=45;
bkcolor:=0;
mousehide;
printxy(208,128,cubefaces[cube]);
mouseshow;
bkcolor:=3;
msg:=cube;
end;
procedure findmouse;
var
y : Integer;
{ s : string[4];}
begin
if not mouse.getstatus then
begin
case mouse.x of
215..231: case mouse.y of
145..159: msg1(cube*9);
160..174: msg1(cube*9+3);
175..189: msg1(cube*9+6);
else if cube<>msg then msg2;
end;
232..248: case mouse.y of
145..159: msg1(cube*9+1);
160..174: msg1(cube*9+4);
175..189: msg1(cube*9+7);
else if cube<>msg then msg2;
end;
249..265: case mouse.y of
145..159: msg1(cube*9+2);
160..174: msg1(cube*9+5);
175..189: msg1(cube*9+8);
else if cube<>msg then msg2;
end;
else if cube<>msg then msg2;
end;
exit;
end;
oldcube:=cube;
case mouse.x of
27..143: if ((viewmode2=1) or (viewmode2=2)) and (mouse.y<124) and (mouse.y>16) then
targetstar(mouse.x,mouse.y);
184..202: case mouse.y of
149..159: if cube<>0 then rotatecube(cube,0,false);
161..171: if cube<>1 then rotatecube(cube,1,false);
173..183: if cube<>2 then rotatecube(cube,2,false);
end;
276..294: case mouse.y of
149..159: if cube<>3 then rotatecube(cube,3,false);
161..171: if cube<>4 then rotatecube(cube,4,false);
173..183: if cube<>5 then rotatecube(cube,5,false);
end;
215..231: case mouse.y of
145..159: processcube(cube*9);
160..174: processcube(cube*9+3);
175..189: processcube(cube*9+6);
end;
232..248: case mouse.y of
145..159: processcube(cube*9+1);
160..174: processcube(cube*9+4);
175..189: processcube(cube*9+7);
end;
249..265: case mouse.y of
145..159: processcube(cube*9+2);
160..174: processcube(cube*9+5);
175..189: processcube(cube*9+8);
end;
161..171: case mouse.y of
148..156: begin
if textindex>1 then dec(textindex);
displaytextbox(false);
end;
158..182: begin
textindex:=mouse.y-157;
displaytextbox(false);
end;
185..192: begin
if textindex<25 then inc(textindex);
displaytextbox(false);
end;
end;
0..8: if mouse.y>182 then
begin
if alert<ALRT_COMBAT then
begin
armweapons;
raiseshields;
end
else
begin
powerdownweapons;
lowershields;
end;
end;
300..313: case mouse.y of
19..38: if viewmode<>1 then
begin
cleanright(true);
readystatus;
if clickcode=3 then
begin
clickcode:=0;
{$IFNDEF DEMO}
easteregg5;
{$ENDIF}
end;
end;
49..58: if viewmode<>1 then
begin
cleanright(true);
readystatus;
if clickcode=2 then clickcode:=3 else clickcode:=0;
end;
69..78: if viewmode<>1 then
begin
cleanright(true);
readystatus;
if clickcode=1 then clickcode:=2 else clickcode:=0;
end;
89..98: if viewmode<>1 then
begin
cleanright(true);
readystatus;
if clickcode=0 then clickcode:=1;
end;
else clickcode:=0;
end;
else clickcode:=0;
end;
if panelon then
begin
if (mouse.y>8) and (mouse.y<24) and (mouse.x>153) and (mouse.x<291)
then command:=(mouse.x-137) div 17
else
case viewmode of
2: if (viewlevel=0) and (mouse.x>165) and (mouse.x<279) and (mouse.y>31) and (mouse.y<116) then
begin
i:=((mouse.y-32) div 7);
j:=1;
repeat
if ship.gunnodes[j]>0 then dec(i);
inc(j);
until (j>10) or (i<1);
if j<11 then viewindex:=j-1;
end;
3: if (viewlevel=0) and (mouse.x>165) and (mouse.x<279) and (mouse.y>37)
and (mouse.y<116) then
begin
if mouse.y<74 then i:=-6+((mouse.y-38) div 6)
else i:=((mouse.y-74) div 6);
if i<0 then
begin
repeat
dec(target);
if nearby[target].index>0 then inc(i);
until (target<1) or (i=0);
if target<1 then
begin
target:=1;
while nearby[target].index=0 do inc(target);
end;
end
else if i>0 then
begin
repeat
inc(target);
if nearby[target].index>0 then dec(i);
until (target>nearbymax) or (i=0);
if target>nearbymax then
begin
target:=nearbymax;
while nearby[target].index=0 do dec(target);
end;
end;
end;
4: if viewlevel=0 then
begin
case mouse.y of
61..68: viewindex:=1;
70..74: if (mouse.x>172) and (mouse.x<274) then
begin
viewindex:=1;
ship.shieldopt[SHLD_LOWERED_WANT]:=mouse.x-173;
end;
79..86: viewindex:=2;
88..92: if (mouse.x>172) and (mouse.x<274) then
begin
viewindex:=2;
ship.shieldopt[SHLD_ALERT_WANT]:=mouse.x-173;
end;
97..104: viewindex:=3;
106..110: if (mouse.x>172) and (mouse.x<274) then
begin
viewindex:=3;
ship.shieldopt[SHLD_COMBAT_WANT]:=mouse.x-173;
end;
end;
end
else if (viewlevel=2) and (viewindex2>0) and (mouse.x>165) and (mouse.x<279) and (mouse.y>37)
and (mouse.y<116) then
begin
if mouse.y<74 then i:=-6+((mouse.y-38) div 6)
else i:=((mouse.y-74) div 6);
if i<0 then
begin
repeat
dec(viewindex2);
if (ship.cargo[viewindex2]>=ID_NOSHIELD) and (ship.cargo[viewindex2]<ID_NOTHING-1) then inc(i);
until (viewindex2<1) or (i=0);
if viewindex2<1 then
begin
viewindex2:=1;
while (ship.cargo[viewindex2]<ID_NOSHIELD) or (ship.cargo[viewindex2]>=ID_NOTHING) do inc(viewindex2);
end;
end
else if i>0 then
begin
repeat
inc(viewindex2);
if (ship.cargo[viewindex2]>=ID_NOSHIELD) and (ship.cargo[viewindex2]<ID_NOTHING-1) then dec(i);
until (viewindex2>250) or (i=0);
if viewindex2>250 then
begin
viewindex2:=250;
while (ship.cargo[viewindex2]<ID_NOSHIELD) or (ship.cargo[viewindex2]>=ID_NOTHING) do dec(viewindex2);
end;
end;
end;
5: if (mouse.x>165) and (mouse.x<279) and (mouse.y>31) then
begin
if viewlevel=1 then
case mouse.y of
36..49: viewindex:=1;
63..76: viewindex:=2;
90..103: viewindex:=3;
end
else if viewlevel=2 then
begin
i:=((mouse.y-46) div 7);
if (ship.engrteam[viewindex].jobtype=JOBTYPE_REPAIR) and (i<9) then
begin
j:=ship.engrteam[viewindex].job;
bkcolor:=5;
printxy(159+6*viewindex,46+j*7,' ');
ship.engrteam[viewindex].job:=i;
with ship.engrteam[viewindex] do
case job of
0: timeleft:=0;
1..7: if ship.damages[job]>0 then timeleft:=ship.damages[job]*70+random(30);
8: if ship.hullintegrity<ship.hullmax then timeleft:=(ship.hullmax-ship.hullintegrity)*30+random(40);
end;
end;
end;
end;
6: if (mouse.x>165) and (mouse.x<279) and (mouse.y>37) and (mouse.y<116) then
viewindex:=(mouse.y-27) div 9;
7: if (viewlevel=0) and (viewindex>0) and (mouse.x>165) and (mouse.x<279) and (mouse.y>37)
and (mouse.y<116) then
begin
if mouse.y<74 then i:=-6+((mouse.y-38) div 6)
else i:=((mouse.y-74) div 6);
if i<0 then
begin
repeat
dec(viewindex);
if systems[viewindex].visits>0 then inc(i);
until (viewindex<1) or (i=0);
if viewindex<1 then