forked from y-salnikov/ironseed_fpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils2.pas
1807 lines (1753 loc) · 43.3 KB
/
utils2.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 utils2;
(********************************************************************
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/>.
********************************************************************)
{*********************************************
Overlayable Utilites for IronSeed
Copyright:
1994 Channel 7, Destiny: Virtual
2013 y-salnikov
2020 Matija Nalis <[email protected]>
**********************************************}
{$I-}
{$O+}
interface
procedure adjustplanets(t: integer);
procedure adjustsystem;
procedure redoscreen(x,y,z: integer);
procedure createplanet(xc,yc: integer);
procedure readyplanet;
procedure createstar(c,xc,yc: integer);
procedure readystar;
procedure removedata;
procedure dothatartifactthing(n: integer);
procedure reloadbackground;
procedure makeastoroidfield;
procedure makecloud;
procedure drawastoroid;
procedure getname(n: integer);
procedure addgunnode;
procedure addstuff(n, limit: integer);
procedure getstuffamounts(
const state : Integer;
var ele : array{[0..16]} of integer;
var mat : array{[0..20]} of Integer;
var cmp : array{[0..22]} of Integer);
function getplanetorbit(planet : Integer): Integer;
function getplanetbyorbit(sys, orbit : Integer): Integer;
procedure planettravel(sys, index : Integer);
procedure gotoorbit(sys, n : Integer);
function GetTechnologyLevel(plan : Integer) : Integer;
implementation
uses utils_, data, journey, gmouse, usecode, display, saveload, comm, utils, weird;
type
scandatatype= array[0..11] of byte;
scantype= array[0..16] of scandatatype;
var
a,b,j,i,index: integer;
function GetTechnologyLevel(plan : Integer) : Integer;
var
i,techlvl : integer;
begin
if tempplan^[plan].orbit=0 then
begin
GetTechnologyLevel:=0;
exit;
end;
techlvl:=-2;
case tempplan^[plan].system of
93,138,78,191,171,221:
begin
GetTechnologyLevel:=6*256;
exit;
end;
45: if chevent(27) then
begin
GetTechnologyLevel:=0;
exit;
end
else
begin
GetTechnologyLevel:=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; { case }
GetTechnologyLevel := techlvl;
end;
procedure reloadbackground;
var temp: pscreentype;
begin
new(temp);
backgrx:=random(320);
backgry:=random(200);
loadscreen(loc_data()+'main',temp);
loadscreen(loc_data()+'cloud',backgr);
for j:=0 to 319 do
begin
x:=j+backgrx;
if x>319 then x:=x-320;
for i:=0 to 199 do
begin
y:=i+backgry;
if y>199 then y:=y-200;
if temp^[i,j]=255 then screen[i,j]:=backgr^[y,x];
end;
end;
dispose(temp);
end;
function getsubamount(item : Integer; ele : array{[0..16]} of Integer; mat : array{[0..20]} of Integer) : Integer;
var
i, j, n : Integer;
tt : Integer;
begin
getsubamount := 0;
for i := 1 to maxcargo do
begin
if cargo[i].index = item then
begin
tt := 99;
for j := 1 to 3 do
begin
n := prtcargo[i, j];
case n of
ID_FIRST_ELEMENT..ID_LAST_ELEMENT: begin
n := ele[(n - ID_FIRST_ELEMENT) div 10];
end;
ID_UNKNOWN_MATERIAL..4999: begin
n := mat[n - ID_UNKNOWN_MATERIAL];
end;
ID_UNKNOWN_COMPONENT..3999: begin
n := getsubamount(n, ele, mat);
end;
end; { case }
if n < tt then tt := n;
end;
getsubamount := tt;
exit;
end;
end;
end; { getsubamounts }
procedure getstuffamounts(
const state : Integer;
var ele : array{[0..16]} of integer;
var mat : array{[0..20]} of Integer;
var cmp : array{[0..22]} of Integer);
var
scanfile : file of scantype;
temp : ^scantype;
i, j, k, n : Integer;
tly, tt, cub : Integer;
begin
{load scan data}
new(temp);
assign(scanfile,loc_data()+'scan.dta');
reset(scanfile);
if ioresult<>0 then errorhandler('scan.dta',1);
read(scanfile,temp^);
if ioresult<>0 then errorhandler('scan.dta',5);
close(scanfile);
{copy element amounts}
for i:=0 to 16 do
ele[i] := temp^[i,state];
dispose(temp);
{compute material amounts}
for i:=1 to 19 do
begin
mat[i] := 0;
n := i + ID_UNKNOWN_MATERIAL;
for j:=1 to maxcargo do
if cargo[j].index = n then
begin
tt := 99;
tly := 0;
cub := 1;
for k := 1 to 3 do
begin
n := ele[(prtcargo[j,k] - ID_FIRST_ELEMENT) div 10];
inc(tly, n);
if n < tt then
tt := n;
cub := cub * n;
end;
if tt > 0 then
mat[i] := tly
else
mat[i] := 0;
break;
end;
end;
mat[0] := 0;
mat[20] := 0;
{compute component counts}
for i := 1 to 20 do
cmp[i] := getsubamount(i + ID_UNKNOWN_COMPONENT, ele, mat);
cmp[0] := 0;
cmp[21] := 0;
cmp[22] := 0;
end; { getamounts }
procedure addstuff(n, limit: integer);
var
ele : array[0..16] of integer;
mat : array[0..20] of Integer;
cmp : array[0..22] of Integer;
i, j, r : Integer;
lim : Integer;
total : Integer;
{s : string[10];}
begin
if (tempplan^[n].bots and 7) = 0 then
exit;
ele[0]:=0; mat[0]:=0; cmp[0]:=0; // to turn off warnings, variables are actually correctly initialized by function below
getstuffamounts(tempplan^[n].state, ele, mat, cmp);
total := 0;
lim := limit;
{for i := 0 to 16 do
begin
str(ele[i], s);
printxy(0, i * 6, s);
end;
for i := 0 to 20 do
begin
str(mat[i], s);
printxy(16, i * 6, s);
end;
for i := 0 to 20 do
begin
str(cmp[i], s);
printxy(32, i * 6, s);
end;}
case (tempplan^[n].bots and 7) of
1 : begin {elements}
for i := 0 to 16 do
inc(total, ele[i]);
for i := 1 to 7 do
begin
if tempplan^[n].cache[i] = 0 then
begin
r := random(total);
j := 0;
while (j < 16) and (r >= ele[j]) do
begin
dec(r, ele[j]);
inc(j);
end;
tempplan^[n].cache[i] := ID_FIRST_ELEMENT + j * 10;
dec(lim);
if lim <= 0 then
break;
end;
end;
end;
2, 5 : begin {materials}
for i := 0 to 20 do
begin
mat[i] := mat[i] * 2;
inc(total, mat[i]);
end;
inc(mat[0]); {unknown material}
inc(mat[20]); {worthless junk}
inc(total, 2);
for i := 1 to 7 do
begin
if (tempplan^[n].cache[i] = 0) or ((tempplan^[n].cache[i] = ID_WORTHLESS_JUNK) and (random(2) = 0)) then
begin
r := random(total);
j := 0;
while (j < 20) and (r >= mat[j]) do
begin
dec(r, mat[j]);
inc(j);
end;
tempplan^[n].cache[i] := ID_UNKNOWN_MATERIAL + j;
dec(lim);
if lim <= 0 then
break;
end;
end;
end;
3..4 : begin {components}
for i := 0 to 22 do
begin
cmp[i] := cmp[i] * 2;
inc(total, cmp[i]);
end;
inc(cmp[0]); {unknown component}
inc(cmp[22]); {worthless junk}
inc(total, 2);
for i := 1 to 7 do
begin
if (tempplan^[n].cache[i] = 0) or ((tempplan^[n].cache[i] = ID_WORTHLESS_JUNK) and (random(2) = 0)) then
begin
r := random(total);
j := 0;
while (j < 22) and (r >= cmp[j]) do
begin
dec(r, cmp[j]);
inc(j);
end;
if j = 22 then
tempplan^[n].cache[i] := ID_WORTHLESS_JUNK
else
tempplan^[n].cache[i] := ID_UNKNOWN_COMPONENT + j;
dec(lim);
if lim <= 0 then
break;
end;
end;
end;
end; { case }
end;
(*var scanfile : file of scantype;
temp : ^scantype;
a,total,b,c,t,tt,tly,cnt : integer;
tempcreate : ^creationtype;
creafile : file of creationtype;
amounts : array[0..20] of Integer;
lim : Integer;
{s : string[10];}
begin
new(temp);
assign(scanfile,loc_data()+'scan.dta');
reset(scanfile);
if ioresult<>0 then errorhandler('scan.dta',1);
read(scanfile,temp^);
if ioresult<>0 then errorhandler('scan.dta',5);
close(scanfile);
lim := limit;
if (tempplan^[n].bots and 7)=1 then
begin
total:=0;
for a:=0 to 16 do inc(total,temp^[a,tempplan^[n].state]);
for c:=1 to 7 do
if tempplan^[n].cache[c]=0 then
begin
b:=random(total);
a:=0;
repeat
dec(b,temp^[a,tempplan^[n].state]);
inc(a);
until (b<0) or (a=17);
a:=(a-1)*10+ID_FIRST_ELEMENT;
tempplan^[n].cache[c]:=a;
dec(lim);
if lim <= 0 then break;
end;
end
else if (tempplan^[n].bots and 7)=2 then
begin
new(tempcreate);
assign(creafile,loc_data()+'creation.dta');
reset(creafile);
if ioresult<>0 then errorhandler('creation.dta',1);
total:=0;
for j:=0 to 20 do
amounts[j] := 0;
for j:=1 to totalcreation do
begin
read(creafile,tempcreate^);
if ioresult<>0 then errorhandler('creation.dta',5);
if(tempcreate^.index >= ID_UNKNOWN_MATERIAL) and (tempcreate^.index <= ID_WORTHLESS_JUNK) then
begin
tt:=99;
tly:=0;
for i:=1 to 3 do
if (tempcreate^.parts[i]>=ID_FIRST_ELEMENT) then
begin
cnt := temp^[(tempcreate^.parts[i]-ID_FIRST_ELEMENT) div 10,tempplan^[n].state];
if tt > cnt then tt := cnt;
inc(tly, cnt);
end;
if tt = 99 then
tt := 0;
if tt > 0 then
begin
inc(total, tly + tly);
amounts[tempcreate^.index - ID_UNKNOWN_MATERIAL] := tly + tly;
end else
amounts[tempcreate^.index - ID_UNKNOWN_MATERIAL] := 0;
{str(tempcreate^.index, s);
printxy(0,(tempcreate^.index - ID_UNKNOWN_MATERIAL) * 6, s);
str(tt, s);
printxy(40,(tempcreate^.index - ID_UNKNOWN_MATERIAL) * 6, s);
str(tly, s);
printxy(60,(tempcreate^.index - ID_UNKNOWN_MATERIAL) * 6, s);}
end;
end;
{give a chance for unkowns and worthless junk}
inc(amounts[0]);
inc(amounts[20]);
inc(total, 2);
if total > 0 then
for c:=1 to 7 do
if (tempplan^[n].cache[c]=0) or (tempplan^[n].cache[c]=ID_WORTHLESS_JUNK) then
begin
t := random(total);
for j := 0 to 20 do
begin
if t < amounts[j] then
begin
tempplan^[n].cache[c] := j + ID_UNKNOWN_MATERIAL;
break;
end;
dec(t, amounts[j]);
end;
dec(lim);
if lim <= 0 then break;
end;
close(creafile);
dispose(tempcreate);
end;
dispose(temp);
end;*)
procedure adjustplanets(t: integer);
var j,olds: integer;
begin
randomize;
for j:=1 to 1000 do
begin
if tempplan^[j].bots >0 then
begin
{clear depletion stat}
tempplan^[j].bots := tempplan^[j].bots and 7;
if tempplan^[j].bots>0 then
addstuff(j, 7);
end;
with tempplan^[j] do
begin
age:=age+t;
olds:=state;
case state of
0:case mode of
1,2:if age>=1000000000 then
begin
age:=0;
inc(mode);
end;
3: if age>=500000000 then
begin
age:=0;
mode:=1;
state:=1;
end;
end;
1:case mode of
1: if age>=500000000 then
begin
age:=0;
mode:=2;
end;
2: if age>=400000000 then
begin
age:=0;
mode:=3;
end;
3: if age>=300000000 then
begin
age:=0;
mode:=1;
state:=2;
end;
end;
2:case mode of
1: if age>=200000000 then
begin
age:=0;
mode:=2;
end;
2: if age>=150000000 then
begin
age:=0;
mode:=3;
end;
3: begin
if age>=150000000 then
begin
age:=0;
mode:=1;
state:=3;
end;
if random(40)=0 then
begin
age:=0;
state:=5;
mode:=2;
end;
end;
end;
3:case mode of
1: begin
if age>=15000000 then
begin
age:=0;
mode:=2;
end;
if random(40)=0 then
begin
age:=0;
state:=5;
mode:=2;
end;
end;
2: if age>=10000 then
begin
age:=0;
mode:=3;
end;
3: if age>=8000 then
begin
age:=0;
mode:=1;
state:=4;
end;
end;
4:case mode of
1: if age>=4000 then
begin
age:=0;
mode:=2;
end;
2: begin
if age>=2000 then
begin
age:=0;
mode:=3;
end;
if random(40)=0 then
begin
if random(2)=0 then mode:=1
else mode:=2;
state:=6;
age:=0;
end;
end;
3: begin
if age>=4000 then
begin
age:=0;
mode:=1;
state:=5;
end;
if random(40)=0 then
begin
if random(2)=0 then mode:=1
else mode:=2;
state:=6;
age:=0;
end;
end;
end;
5:case mode of
1: if age>=3000 then
begin
age:=0;
mode:=2;
end;
2: begin
if age>=8000 then
begin
age:=0;
mode:=3;
end;
if random(40)=0 then
begin
age:=0;
state:=2;
mode:=3;
end;
end;
3:;
end;
6:if (mode=1) and (age>=100000) then
begin
age:=0;
mode:=2;
end;
end;
if (olds<>state) then
begin
fillchar(cache,sizeof(cache),0);
bots:=0;
notes:=0;
end;
end;
end;
end;
procedure getname(n: integer);
type nametype= string[12];
var str1: nametype;
f: file of nametype;
begin
assign(f,loc_data()+'sysname.dta');
reset(f);
if ioresult<>0 then errorhandler('data/sysname.txt',1);
seek(f,n-1);
if ioresult<>0 then errorhandler('data/sysname.txt',6);
read(f,str1);
if ioresult<>0 then errorhandler('data/sysname.txt',6);
systems[n].name:=str1;
close(f);
end;
procedure adjustsystem;
begin
if systems[tempplan^[curplan].system].visits=0 then
getname(tempplan^[curplan].system);
inc(systems[tempplan^[curplan].system].visits);
systems[tempplan^[curplan].system].datey:=ship.stardate[3];
systems[tempplan^[curplan].system].datem:=ship.stardate[1];
if systems[tempplan^[curplan].system].visits<255 then inc(tempplan^[j].visits);
tempplan^[j].datey:=ship.stardate[3];
tempplan^[j].datem:=ship.stardate[1];
end;
procedure redoscreen(x,y,z: integer);
var dist: real;
index,time: integer;
str1: string[4];
begin
dist:=sqr((x-ship.posx)/10);
dist:=dist + sqr((y-ship.posy)/10);
dist:=dist + sqr((z-ship.posz)/10);
dist:=sqrt(dist);
if (random(85)+15)<ship.damages[DMG_ENGINES] then
begin
tcolor:=94;
println;
print('NAVIGATION: Ship off course!');
ship.posx:=x-3+random(7);
ship.posy:=y-3+random(7);
ship.posz:=z-3+random(7);
end
else
begin
ship.posx:=x;
ship.posy:=y;
ship.posz:=z;
end;
targetready:=false;
ship.battery:=32000;
checkstats;
showplanet:=false;
for j:=1 to nearbymax do nearby[j].index:=0;
i:=0;
for j:=1 to 250 do
begin
x:=systems[j].x-ship.posx;
y:=systems[j].y-ship.posy;
z:=systems[j].z-ship.posz;
if (abs(x)<400) and (abs(y)<400)
and (abs(z)<400) then
begin
inc(i);
if i>nearbymax then errorhandler('NEARBY STRUCTURE OVERFLOW #1.',6);
nearby[i].index:=j;
nearby[i].x:=x/10;
nearby[i].y:=y/10;
nearby[i].z:=z/10;
systems[j].notes:=systems[j].notes or 1;
end;
end;
move(nearby,nearbybackup,sizeof(nearbyarraytype));
mousehide;
compressfile(loc_tmp()+'current',@screen);
scr_fillchar(screen,sizeof(screen),0);
tcolor:=47;
bkcolor:=0;
time:=round(dist*2)+1;
printxy(42,187,'Acceleration to near light speed...');
mouseshow;
for j:=0 to round(dist*2) do
begin
addlotstime(false, false, random(4000)+4000);
dec(time);
str(time,str1);
if length(str1)<4 then for i:=length(str1)+1 to 4 do str1[i]:=#20;
str1[0]:=#4;
bkcolor:=0;
printxy(222,187,str1);
end;
bkcolor:=3;
tcolor:=31;
{fading;}
fadestopmod(-FADEFULL_STEP, FADEFULL_DELAY);
mousehide;
loadscreen(loc_tmp()+'current',@screen);
showtime;
index:=0;
for j:=1 to nearbymax do
if (systems[nearby[j].index].x=ship.posx) and
(systems[nearby[j].index].y=ship.posy) and
(systems[nearby[j].index].z=ship.posz) then
begin
index:=j;
j:=nearbymax;
end;
if index<>0 then
begin
ship.stardate[3]:=ship.stardate[3]+round(dist);
j:=findfirstplanet(nearby[index].index);
ship.orbiting:=0;
curplan:=j;
showtime;
adjustsystem;
adjustplanets(round(dist));
readystar;
end
else
begin
curplan:=0;
ship.orbiting:=0;
reloadbackground;
fadein;
end;
mouseshow;
if ship.options[OPT_AUTOSAVE]=1 then savegamedata(0,31);
target:=0;
for j:=1 to random(4)+1 do
begin
i:=random(7)+1;
if ship.damages[i]<90 then inc(ship.damages[i]);
end;
if index<>0 then
begin
for j:=0 to maxeventsystems do
if eventsystems[j]=nearby[index].index then event(eventstorun[j]);
end;
end;
{Creates a planet by having a 'cursor' randomly wander over the planet in single pixel steps raise the terrain below it.}
procedure createplanet(xc,yc: integer);
var x1,y1 : integer;
a : longint;
str1 : string[3];
tl, i : Integer;
begin
i:=0;
x1:=xc;
y1:=yc;
randseed:=tempplan^[curplan].seed;
for a:=1 to 75000 do
begin
inc(i);
x1:=x1-1+random(3);
y1:=y1-1+random(3);
if x1>240 then x1:=1 else if x1<1 then x1:=240;
if y1>120 then y1:=1 else if y1<1 then y1:=120;
if landform^[x1,y1]<240 then landform^[x1,y1]:=landform^[x1,y1]+7;
if i=1125 then
begin
inc(index);
str((200-index):3,str1);
printxy(90,170,str1);
i:=0;
end;
end;
tl := GetTechnologyLevel(curplan);
if tl > 0 then
begin
tl := hi(tl) * 10 + lo(tl);
tl := tl * tl div 10;
for a:=1 to tl do
begin
{for i := 1 to 5 do}
x1 := random(240);
y1 := random(120);
if landform^[x1,y1] > water then
begin
landform^[x1,y1] := 255;
{inc(x1);
if x1 > 240 then x1 := 1;
landform^[x1,y1] := 255;}
end;
end;
end;
end;
procedure makeswirl(x, y, sz : Integer);
var
c : byte;
begin
if y <= 60 then
case sz of
2 : begin
c := landform^[x,y-1];
landform^[x,y-1] := landform^[x+1,y] - random(3);
landform^[x+1,y] := c - random(3);
end;
3 : begin
c := landform^[x,y-1];
landform^[x,y-1] := landform^[x+2,y] - random(3);
landform^[x+2,y] := c - random(3);
c := landform^[x+1,y-1];
landform^[x+1,y-1] := landform^[x+1,y] - random(3);
landform^[x+1,y] := c - random(3);
end;
4 : begin
c := landform^[x,y-1];
landform^[x,y-1] := landform^[x+3,y] - random(3);
landform^[x+3,y] := c - random(3);
c := landform^[x+1,y-1];
landform^[x+1,y-1] := landform^[x+2,y] - random(3);
landform^[x+2,y] := c - random(3);
c := landform^[x+2,y-2];
landform^[x+2,y-2] := landform^[x+1,y+1] - random(3);
landform^[x+1,y+1] := c - random(3);
c := landform^[x+1,y-2];
landform^[x+1,y-2] := landform^[x+2,y+1] - random(3);
landform^[x+2,y+1] := c - random(3);
end;
end { case }
else
case sz of
2 : begin
c := landform^[x+1,y-1];
landform^[x+1,y-1] := landform^[x,y] - random(3);
landform^[x,y] := c - random(3);
end;
3 : begin
c := landform^[x,y];
landform^[x,y] := landform^[x+2,y-1] - random(3);
landform^[x+2,y-1] := c - random(3);
c := landform^[x+1,y-1];
landform^[x+1,y-1] := landform^[x+1,y] - random(3);
landform^[x+1,y] := c - random(3);
end;
4 : begin
c := landform^[x,y];
landform^[x,y] := landform^[x+3,y-1] - random(3);
landform^[x+3,y-1] := c - random(3);
c := landform^[x+1,y];
landform^[x+1,y] := landform^[x+2,y-1] - random(3);
landform^[x+2,y-1] := c - random(3);
c := landform^[x+2,y-2];
landform^[x+2,y-2] := landform^[x+1,y+1] - random(3);
landform^[x+1,y+1] := c - random(3);
c := landform^[x+1,y-2];
landform^[x+1,y-2] := landform^[x+2,y+1] - random(3);
landform^[x+2,y+1] := c - random(3);
end;
end; { case }
end;
procedure creategasplanet;
var x1,y1 : integer;
a,b,c : integer;
c1, c2, c3 : Integer;
sz,sz2,sz21 : Integer;
sz22 : Integer;
cnt,d,d2 : Integer;
x, y : Integer;
xx : Integer;
begin
randseed:=tempplan^[curplan].seed;
{decide on colours}
if random(2) > 0 then
begin
c1 := 32;
c2 := 48;
c3 := 64;
end else begin
c1 := 112;
c2 := 128;
c3 := 96;
end;
{create bands}
b := 0;
a := 1;
for y1 := 60 downto 1 do
begin
dec(a);
if a = 0 then
begin
a := (60 - abs(y1 - 60)) div 10;
a := a + 6 + random(a + 5);
if (a < y1) and ((a + 5) > y1) then
a := y1 shr 1;
b := (b + random(2) + 1) mod 3;
case b of
0 : c := c1 + 8 + random(5);
1 : c := c2 + 8 + random(5);
2 : c := c3 + 8 + random(5);
end; { case }
end;
for x1 := 1 to 240 do
begin
landform^[x1, y1] := c + random(2);
landform^[x1, 121 - y1] := c + random(2);
end;
end;
{border turbulence}
for y1 := 3 to 119 do
if (landform^[1, y1] and $f0) <> (landform^[1, y1 - 1] and $f0) then
begin
x1 := 1;
while x1 <= 240 do
begin
b := random(4) + 1;
if b + x1 > 241 then
b := 241 - x1;
makeswirl(x1, y1, b);
inc(x1, b);
end;
inc(y1,2);
end;
{Spots}
cnt := 6 + random(5);
for i := 1 to cnt do
begin
case random(3) of
0 : c := c1 + 2 + random(4);
1 : c := c2 + 2 + random(4);
2 : c := c3 + 2 + random(4);
end; { case }
if i = 1 then
sz := 15 + random(5)
else
sz := 2 + random(6);
sz2 := sz * sz;
sz21 := (sz - 1) * (sz - 1);
sz22 := (sz - 2) * (sz - 2);
x := random(240);
y := random(110 - sz - sz) + 5 + sz;
for x1 := -sz to sz do
begin
xx := x1 + x;
if xx < 1 then inc(xx, 240) else if xx > 240 then dec(xx, 240);
d := round(sqrt(sz2 - x1 * x1));
for y1 := -d to d do
begin
d2 := (x1 * x1) + (y1 * y1);
if d2 > (sz21) then
inc(landform^[xx,y1+y], 1 + random(2))
else if d2 > (sz22) then
landform^[xx,y1+y] := c - 1 - random(2)
else
landform^[xx,y1+y] := c + random(2);
end;
end
end;
randomize;
{ a:=1;
c:=112;
randseed:=tempplan^[curplan].seed;
for j:=1 to 240 do
for i:=1 to 120 do
begin