forked from nukebloodaxe/ironseed_fpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cargtool.pas
2123 lines (2050 loc) · 53.2 KB
/
cargtool.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 cargtool;
(********************************************************************
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 <https://www.gnu.org/licenses/>.
********************************************************************)
{*********************************************
Cargo/Creation unit for IronSeed
Copyright:
1994 Channel 7, Destiny: Virtual
2013 y-salnikov
2020 Matija Nalis <[email protected]>
**********************************************}
{$O+}
{$I-}
interface
procedure inventory;
procedure creation;
function StartBuild(background : Boolean; root, item, team : Integer) :Integer;
implementation
uses data, gmouse, utils, weird, saveload, modplay, journey, display, usecode, heapchk, utils_;
{$PACKRECORDS 1}
type
cargobuttontype= array[110..126,92..228] of byte;
iteminfotype=
record
index: integer;
info: array[0..3] of string[28];
end;
{$PACKRECORDS DEFAULT}
var
drawit,qmode,colorcode : boolean;
i,j,a,b,cargoindex,cargomode,viewteam,maxcreation,lastinfo : integer;
teamjob : integer;
cargobuttons : ^cargobuttontype;
filters : array[1..3] of byte;
filters2 : array[1..4] of byte;
createinfo : ^createarray;
iteminfo : ^iteminfotype;
res2cargo : array[1..250] of Integer;
history : array[1..32] of Integer;
historyindex : Integer;
function GetBuildTime(item : Integer):Integer;
var
i : Integer;
begin
for i:= 1 to maxcargo do
if cargo[i].index = item then
begin
{ special artifacts with id>6000 like "Glyptic Scythe" do not have entry creation.dta, so they default to 30000
while their timeleft in go2() is initialized to timeleft:=6000+random(5)*100, which causes progress bar to break.
So initialize to worst case 6500 so we have something more reasonable for progressbar. }
if bldcargo[i]=30000 then bldcargo[i] := 65;
GetBuildTime := bldcargo[i] * 100;
exit;
end;
GetBuildTime := 6500;
end;
function StartBuild(background : Boolean; root, item, team : Integer) :Integer;
var
i, j, k : Integer;
begin
i := 1;
while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);
if i > maxcargo then {doesn't exist!}
begin
StartBuild := -2;
exit;
end;
if prtcargo[i,1] = 0 then {can't be assembled}
begin
StartBuild := 0;
exit;
end;
if (item = ID_THERMOPLAST) and (not chevent(18)) then {thermoplast can only be made after it's discovery}
begin
StartBuild := -3;
exit;
end;
for j := 1 to 6 do {high enough level?}
if lvlcargo[i,j] > ship.crew[j].level then
begin
StartBuild := -1;
exit;
end;
k := 1; {how many of the first part are needed?}
for j := 2 to 3 do
if prtcargo[i,1] = prtcargo[i,j] then
inc(k);
if InCargo(prtcargo[i,1]) < k then {check first part}
begin
if prtcargo[i,1] = item then
StartBuild := 0 {stop infinite recursion}
else
StartBuild := StartBuild(background, root, prtcargo[i,1], team);
exit;
end;
for j := 2 to 3 do
if InCargo(prtcargo[i,j]) < 1 then
begin
if prtcargo[i,j] = item then
StartBuild := 0 {stop infinite recursion}
else
StartBuild := StartBuild(background, root, prtcargo[i,j], team);
exit;
end;
ship.engrteam[team].job := item;
ship.engrteam[team].extra := root;
ship.engrteam[team].jobtype := JOBTYPE_CREATE;
ship.engrteam[team].timeleft := GetBuildTime(item);
for j := 1 to 3 do
RemoveCargo(prtcargo[i,j]);
RebuildCargoReserve;
StartBuild := 1;
for j := 1 to 6 do
addxp(j, lvlcargo[i,j], ord(not background));
teamjob := 0;
end;
function CheckBuildSubStock(item : Integer) :Integer;
var
i, j, k, l : Integer;
begin
i := InCargoIndex(item);
if (i <> 0) and (ship.numcargo[i] - rescargo[i] - res2cargo[i] > 0) then
begin {in stock}
inc(res2cargo[i]);
CheckBuildSubStock := 1;
exit;
end;
i := 1;
while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);
if i > maxcargo then {doesn't exist!}
begin
CheckBuildSubStock := -2;
exit;
end;
for j := 1 to 6 do {high enough level?}
if lvlcargo[i,j] > ship.crew[j].level then
begin
CheckBuildSubStock := -1;
exit;
end;
if prtcargo[i,j] = 0 then
begin
CheckBuildSubStock := 0;
exit;
end;
l := 2;
for j := 1 to 3 do
begin
if prtcargo[i,j] = item then
k := 0 {stop infinite recursion}
else
k := CheckBuildSubStock(prtcargo[i,j]);
case k of
-2 : l := -2;
-1 : if l > -1 then l := -1;
0 : if l > 0 then l := 0;
{1..2: donothing;}
end;
end;
CheckBuildSubStock := l;
end;
function CheckBuildStock(item : Integer):Integer;
var
i, j, k, l : Integer;
begin
for i := 1 to 250 do
res2cargo[i] := 0;
i := 1;
while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);
if i > maxcargo then {doesn't exist!}
begin
CheckBuildStock := -2;
exit;
end;
if prtcargo[i, 1] = 0 then {not a buildable item}
CheckBuildStock := -2;
for j := 1 to 6 do {high enough level?}
if lvlcargo[i,j] > ship.crew[j].level then
begin
CheckBuildStock := -1;
exit;
end;
l := 0;
for j := 1 to 3 do
begin
k := CheckBuildSubStock(prtcargo[i,j]);
case k of
-2 : l := -2;
-1..0: l := l or 0;
1 : l := l or (1 shl (j + j - 2));
2 : l := l or (2 shl (j + j - 2));
{1..2: donothing;}
end;
end;
CheckBuildStock := l;
end;
procedure HistoryClear;
var
i : Integer;
begin
for i := 1 to 32 do
History[i] := 0;
HistoryIndex := 0;
end; { HistoryClear }
procedure HistoryPush(index : Integer);
var
i : Integer;
begin
if HistoryIndex >= 32 then
begin
for i := 1 to 31 do
History[i] := History[i + 1];
History[32] := index;
end else begin
inc(HistoryIndex);
History[HistoryIndex] := index;
end;
end; { HistoryAdd }
function HistoryPop: Integer;
begin
if HistoryIndex <= 0 then
begin
HistoryPop := 0;
exit;
end;
HistoryPop := History[HistoryIndex];
dec(HistoryIndex);
end; { HistoryPop }
procedure opendoors;
begin
if ship.options[OPT_ANIMATION]=0 then
begin
fadestep(1);
for i:=20 to 130 do
scr_fillchar(screen[i,90],144,0);
for i:=110 to 126 do
scrto_move(cargobuttons^[i,92],screen[i,92],34*4);
end
else
for a:=0 to 109 do
begin
fadestep(1);
delay(tslice div 4);
for i:=20 to 130-a do
scrfromto_move(screen[i+1,90],screen[i,90],36*4);
if ((131-a)<127) and ((131-a)>109) then
scrto_move(cargobuttons^[131-a,92],screen[131-a,92],34*4);
end;
plainfadearea(38,78,40,82,-12);
plainfadearea(44,78,46,82,12);
end;
procedure closedoors;
var temp: pscreentype;
begin
if ship.options[OPT_ANIMATION]=0 then exit;
mousehide;
new(temp);
loadscreen(loc_data()+'cargo',temp);
for i:=110 to 126 do
fillchar(temp^[i,94],133,0);
for a:=1 to 110 do
begin
delay(tslice div 4);
for i:=20 to 20+a do
scrto_move(temp^[110-a+i,90],screen[i,90],36*4);
end;
dispose(temp);
mouseshow;
plainfadearea(38,78,40,82,12);
plainfadearea(44,78,46,82,-12);
end;
procedure newcursor(start: integer);
var finished: boolean;
begin
cargoindex:=start;
finished:=false;
if cargoindex=251 then exit;
repeat
inc(cargoindex);
case ship.cargo[cargoindex] of
ID_DIRK..1499: if filters2[1]=1 then finished:=true;
ID_NOSHIELD..1999: if filters2[2]=1 then finished:=true;
ID_NOTHING..3999: if filters2[4]=1 then finished:=true;
ID_UNKNOWN_MATERIAL..ID_LAST_ELEMENT: if filters2[3]=1 then finished:=true;
ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters2[4]=1 then finished:=true;
end;
until (finished) or (cargoindex=251);
end;
procedure revnewcursor(start: integer);
var finished: boolean;
begin
cargoindex:=start;
finished:=false;
if cargoindex<1 then exit;
repeat
dec(cargoindex);
case ship.cargo[cargoindex] of
ID_DIRK..1499: if filters2[1]=1 then finished:=true else dec(cargoindex);
ID_NOSHIELD..1999: if filters2[2]=1 then finished:=true else dec(cargoindex);
ID_NOTHING..3999,ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters2[4]=1 then finished:=true else dec(cargoindex);
ID_UNKNOWN_MATERIAL..ID_LAST_ELEMENT: if filters2[3]=1 then finished:=true else dec(cargoindex);
end;
until (finished) or (cargoindex<1);
end;
procedure drawfilters;
var a,b: integer;
begin
for a:=1 to 2 do
for b:=0 to 1 do
for i:=72+a*5 to 74+a*5 do
for j:=269+b*9 to 276+b*9 do
screen[i,j]:=48+filters2[a+b*2]*8;
end;
procedure readydata;
begin
mousehide;
{compressfile(loc_tmp()+'current',@screen);}
quicksavescreen(loc_tmp()+'current',@screen, true);
{fading;}
fadefull(-FADEFULL_STEP, FADEFULL_DELAY);
playmod(true,loc_sound()+'CARGO.MOD');
loadscreen(loc_data()+'cargo',@screen);
new(cargobuttons);
for i:=110 to 126 do
begin
scrfrom_move(screen[i,92],cargobuttons^[i,92],34*4);
scr_fillchar(screen[i,94],133,0);
end;
plainfadearea(38,78,40,82,12);
drawfilters;
fadein;
opendoors;
dispose(cargobuttons);
mouseshow;
done:=false;
newcursor(0);
cargomode:=0;
lightindex:=232;
bkcolor:=0;
oldt1:=t1;
end;
procedure checklist(down: boolean);
var str1: string[3];
var str2: string[3];
begin
if (x<1) or (x>250) then exit;
str(rescargo[x]:3,str2);
case ship.cargo[x] of
0: ;
ID_DIRK..1499: if filters2[1]=1 then
begin
if down then dec(y) else inc(y);
str(ship.numcargo[x]:3,str1);
j:=1;
while cargo[j].index<>ship.cargo[x] do inc(j);
printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);
end;
ID_NOSHIELD..1999: if filters2[2]=1 then
begin
if down then dec(y) else inc(y);
str(ship.numcargo[x]:3,str1);
j:=1;
while cargo[j].index<>ship.cargo[x] do inc(j);
printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);
end;
ID_NOTHING..3999: if filters2[4]=1 then
begin
if down then dec(y) else inc(y);
str(ship.numcargo[x]:3,str1);
j:=1;
while cargo[j].index<>ship.cargo[x] do inc(j);
printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);
end;
ID_UNKNOWN_MATERIAL..ID_LAST_ELEMENT: if filters2[3]=1 then
begin
if down then dec(y) else inc(y);
str(ship.numcargo[x]:3,str1);
j:=1;
while cargo[j].index<>ship.cargo[x] do inc(j);
printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);
end;
ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters2[4]=1 then
begin
if down then dec(y) else inc(y);
getartifactname(ship.cargo[x]);
str(ship.numcargo[x]:3,str1);
printxy(96-10,16+y*6,str1+' '+cargo[maxcargo].name);
end;
end;
end;
procedure displaylist;
begin
if ship.cargo[cargoindex]=0 then
begin
newcursor(cargoindex);
if cargoindex=251 then revnewcursor(cargoindex);
end;
tcolor:=28;
bkcolor:=0;
x:=cargoindex-1;
mousehide;
y:=7;
repeat
checklist(true);
dec(x);
until (y=1) or (x<1);
if y>1 then
for i:=23 to 16+y*6 do
scr_fillchar(screen[i,92],133,0);
bkcolor:=6;
x:=cargoindex;
y:=6;
repeat
checklist(false);
bkcolor:=0;
inc(x);
until (y=14) or (x>251);
if y<14 then
for i:=23+y*6 to 106 do
scr_fillchar(screen[i,92],133,0);
mouseshow;
end;
procedure displayinfo;
var s: string[9];
draw: boolean;
begin
if ship.cargo[cargoindex]=0 then
begin
newcursor(cargoindex);
if cargoindex=251 then newcursor(0);
end;
if cargoindex=0 then exit;
x:=cargoindex;
tcolor:=28;
bkcolor:=6;
y:=0;
mousehide;
repeat
while (x<251) and (ship.cargo[x]=0) do inc(x);
draw:=false;
case ship.cargo[x] of
ID_DIRK..1499: if filters2[1]=1 then draw:=true;
ID_NOSHIELD..1999: if filters2[2]=1 then draw:=true;
ID_NOTHING..3999,ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters2[4]=1 then draw:=true;
ID_UNKNOWN_MATERIAL..ID_LAST_ELEMENT: if filters2[3]=1 then draw:=true;
end;
if (x<251) and (draw) then
begin
if ship.cargo[x]>ID_ARTIFACT_OFFSET then
begin
j:=maxcargo;
getartifactname(ship.cargo[x]);
end
else
begin
j:=1;
while ship.cargo[x]<>cargo[j].index do inc(j);
end;
inc(y);
printxy(92,2+y*20,cargo[j].name);
if y>0 then bkcolor:=0;
case ship.cargo[x] of
ID_DIRK..1499: s:='Weapon ';
ID_NOSHIELD..1999: s:='Shield ';
ID_NOTHING..2999: s:='Device ';
ID_UNKNOWN_COMPONENT..3999: s:='Component';
ID_UNKNOWN_MATERIAL..ID_LAST_ELEMENT: s:='Material ';
ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: s:='Artifact ';
else s:=' ';
end;
printxy(100,8+y*20,'Type: '+s);
x1:=cargo[j].size/10;
str(x1:7:1,s);
printxy(100,14+y*20,'Size:'+s);
str(ship.numcargo[x]:3,s);
printxy(175,14+y*20,'Num:'+s);
end;
inc(x);
until (y=4) or (x>250);
if y<4 then
for i:=22+y*20 to 106 do
scr_fillchar(screen[i,92],133,0);
mouseshow;
end;
function request(s: string; alt,text: integer): integer;
type
scrtype=array[40..140,74..245] of byte;
var
cursor,lastx,lasty,result: integer;
tempscr: ^scrtype;
done: boolean;
procedure undocursor2;
begin
case cursor of
0: exit;
1: plainfadearea(78,78,128,92,-3);
2: plainfadearea(135,78,185,92,-3);
3: plainfadearea(192,78,242,92,-3);
end;
end;
procedure drawcursor2;
begin
case cursor of
0: exit;
1: plainfadearea(78,78,128,92,3);
2: plainfadearea(135,78,185,92,3);
3: plainfadearea(192,78,242,92,3);
end;
end;
procedure processkey2;
var ans: char;
begin
undocursor2;
ans:=readkey_utf8;
case upcase(ans) of
#0:begin
ans:=readkey;
case ans of
#75,#77:if cursor=1 then cursor:=2 else cursor:=1;
end;
end;
#13:if cursor<>0 then done:=true;
#27: begin
cursor:=4;
done:=true;
end;
'A': begin
cursor:=1;
done:=true;
end;
'H': begin
cursor:=2;
done:=true;
end;
'O','1': begin
cursor:=3;
done:=true;
end;
#10: printbigbox(GetHeapStats1,GetHeapStats2);
end;
drawcursor2;
lastx:=mouse.x;
lasty:=mouse.y;
end;
procedure findmouse2;
var button: boolean;
newcursor: integer;
begin
if mouse.getstatus then button:=true else button:=false;
if (not button) and (mouse.x=lastx) or (mouse.y=lasty) then exit;
case mouse.y of
78..92: case mouse.x of
78..128: newcursor:=1;
135..185: newcursor:=2;
192..242: newcursor:=3;
else newcursor:=0;
end;
else newcursor:=0;
end;
if newcursor<>cursor then
begin
undocursor2;
cursor:=newcursor;
drawcursor2;
end;
if (cursor<>0) and (button) then done:=true;
end;
function mainloop2: integer;
begin
done:=false;
lastx:=0;
lasty:=0;
cursor:=0;
mouseshow;
repeat
findmouse2;
if fastkeypressed then processkey2;
until done;
mainloop2:=cursor;
end;
begin
new(tempscr);
mousehide;
tcolor:=text;
for i:=60 to 102 do
scrfrom_move(screen[i,74],tempscr^[i,74],43*4);
tcolor:=text-5;
bkcolor:=35+alt;
button(75,60,245,102,alt);
button(78,78,128,92,2+alt);
button(135,78,185,92,2+alt);
button(192,78,242,92,2+alt);
printxy(156-round(length(s)*2.5),65,s);
bkcolor:=37+alt;
printxy(92,82,'All');
printxy(146,82,'Half');
printxy(206,82,'One');
result:=mainloop2;
mousehide;
for i:=60 to 102 do
scrto_move(tempscr^[i,74],screen[i,74],43*4);
dispose(tempscr);
request:=result;
bkcolor:=3;
mouseshow;
// mouse.x:=0;
// mouse.y:=0;
move_mouse(0,0);
end;
procedure dropit;
var s: string[20];
begin
if (cargoindex=0) or (cargoindex=251) then exit;
if (ship.cargo[cargoindex]=ID_MOBIUS_DEVICE) or (ship.cargo[cargoindex]>=ID_ART_SHUNT_DRIVE) then
begin
a:=ship.options[OPT_MSGS];
ship.options[OPT_MSGS]:=2;
printbigbox('That item is too vital','to jettison!');
ship.options[OPT_MSGS]:=a;
exit;
end;
if rescargo[cargoindex] >= ship.numcargo[cargoindex] then
begin
a:=ship.options[OPT_MSGS];
ship.options[OPT_MSGS]:=2;
printbigbox('Can''t jettison that!','It''s needed for building.');
ship.options[OPT_MSGS]:=a;
exit;
end;
j:=1;
while cargo[j].index<>ship.cargo[cargoindex] do inc(j);
s:=cargo[j].name;
i:=20;
while (cargo[j].name[i]=' ') do dec(i);
s[0]:=chr(i);
j:=request('Jettison '+s+'?',0,31);
case j of
1 : begin
ship.numcargo[cargoindex]:=0;
ship.cargo[cargoindex]:=0;
revnewcursor(cargoindex);
if cargoindex<1 then newcursor(1);
end;
2 : begin
dec(ship.numcargo[cargoindex],ship.numcargo[cargoindex] div 2);
if ship.numcargo[cargoindex]=0 then
begin
ship.cargo[cargoindex]:=0;
revnewcursor(cargoindex);
if cargoindex<1 then newcursor(1);
end;
end;
3 : begin
if ship.numcargo[cargoindex]=1 then
begin
ship.numcargo[cargoindex]:=0;
ship.cargo[cargoindex]:=0;
revnewcursor(cargoindex);
if cargoindex<1 then newcursor(1);
end
else dec(ship.numcargo[cargoindex]);
end;
end;
bkcolor:=0;
end;
procedure findcargcursor;
begin
if cargomode=0 then y:=((mouse.y-22) div 6)-6
else y:=(mouse.y-22) div 20;
if y=0 then exit;
while (y>0) and (cargoindex<251) do
begin
newcursor(cargoindex);
dec(y);
end;
while (y<0) and (cargoindex>0) do
begin
revnewcursor(cargoindex);
inc(y);
end;
if cargoindex>250 then revnewcursor(251);
if cargoindex<=0 then newcursor(0);
end;
procedure findmouse;
begin
if not mouse.getstatus then exit;
case mouse.x of
94..102: case mouse.y of
22..106: findcargcursor;
110..126: done:=true;
end;
104..113: case mouse.y of
22..106: findcargcursor;
110..126: dropit;
end;
115..159: case mouse.y of
22..106: findcargcursor;
110..117: begin
if filters2[1]=0 then filters2[1]:=1 else filters2[1]:=0;
newcursor(0);
drawfilters;
end;
119..126: begin
if filters2[2]=0 then filters2[2]:=1 else filters2[2]:=0;
newcursor(0);
drawfilters;
end;
end;
161..204: case mouse.y of
22..106: findcargcursor;
110..117: begin
if filters2[3]=0 then filters2[3]:=1 else filters2[3]:=0;
newcursor(0);
drawfilters;
end;
119..126: begin
if filters2[4]=0 then filters2[4]:=1 else filters2[4]:=0;
newcursor(0);
drawfilters;
end;
end;
206..215: case mouse.y of
22..106: findcargcursor;
110..126: begin
if cargomode=1 then cargomode:=0 else cargomode:=1;
for i:=22 to 106 do
scr_fillchar(screen[i,90],140,0);
newcursor(0);
end;
end;
217..226: case mouse.y of
22..106: findcargcursor;
110..117: begin
if cargoindex>1 then revnewcursor(cargoindex)
else revnewcursor(251);
if cargoindex=0 then newcursor(0);
end;
119..126: begin
newcursor(cargoindex);
if cargoindex=251 then revnewcursor(251);
end;
end;
236..250: if (mouse.y>71) and (mouse.y<91) and yesnorequest('PRINT CARGO?',0,31) then printcargo;
end;
if cargoindex>250 then
begin
cargoindex:=0;
mousehide;
for i:=22 to 106 do
scr_fillchar(screen[i,90],140,0);
mouseshow;
end;
if cargomode=0 then displaylist else displayinfo;
idletime:=0;
end;
procedure processkey;
var ans: char;
begin
ans:=readkey_utf8;
case upcase(ans) of
#27,'Q': done:=true;
#0: begin
ans:=readkey;
case ans of
#72:begin
if cargoindex>1 then revnewcursor(cargoindex)
else revnewcursor(251);
if cargoindex=0 then newcursor(0);
end;
#80: begin
newcursor(cargoindex);
if cargoindex=251 then revnewcursor(251);
end;
#81: begin
move_mouse(mouse.x,98);
findcargcursor;
end;
#73: begin
move_mouse(mouse.x,22);
findcargcursor;
end;
end;
end;
'1': begin
if filters2[1]=0 then filters2[1]:=1 else filters2[1]:=0;
newcursor(1);
drawfilters;
end;
'2': begin
if filters2[2]=0 then filters2[2]:=1 else filters2[2]:=0;
newcursor(1);
drawfilters;
end;
'3': begin
if filters2[3]=0 then filters2[3]:=1 else filters2[3]:=0;
newcursor(1);
drawfilters;
end;
'4': begin
if filters2[4]=0 then filters2[4]:=1 else filters2[4]:=0;
newcursor(1);
drawfilters;
end;
'D': dropit;
'`': bossmode;
'/','?': begin
if cargomode=1 then cargomode:=0 else cargomode:=1;
for i:=22 to 106 do
scr_fillchar(screen[i,90],140,0);
newcursor(0);
end;
#10: printbigbox(GetHeapStats1,GetHeapStats2);
end;
if cargoindex>250 then
begin
cargoindex:=0;
mousehide;
for i:=22 to 106 do
scr_fillchar(screen[i,90],140,0);
mouseshow;
end;
if cargomode=0 then displaylist else displayinfo;
idletime:=0;
end;
procedure animation;
begin
setrgb256(lightindex,0,0,0);
inc(lightindex);
if lightindex=240 then lightindex:=232;
setrgb256(lightindex,0,0,48);
mousehide;
for i:=77 to 78 do
for j:=240 to 246 do
if random(2)=0 then screen[i,j]:=63 else screen[i,j]:=0;
mouseshow;
end;
procedure mainloop;
begin
repeat
fadestep(FADESTEP_STEP);
findmouse;
if fastkeypressed then processkey;
inc(idletime);
if idletime=maxidle then screensaver;
animation;
if batindex<8 then inc(batindex) else
begin
batindex:=0;
addtime2;
if cargomode=0 then displaylist else displayinfo;
end;
delay(tslice*FADE_TSLICE_MUL_CARGTOOL);
until done;
end;
procedure removedata;
begin
mousehide;
{fading;}
{fadefull(-FADEFULL_STEP, FADEFULL_DELAY);}
fadestopmod(-FADEFULL_STEP, FADEFULL_DELAY);
mouse.setmousecursor(random(3));
{loadscreen(loc_tmp()+'current',@screen);}
quickloadscreen(loc_tmp()+'current',@screen, true);
showresearchlights;
bkcolor:=3;
displaytextbox(false);
textindex:=25;
if (viewmode=11) and (viewlevel=2) then displaybotinfo(6);
{fadein;}
mouseshow;
anychange:=true;
t1:=oldt1;
end;
procedure inventory;
begin
readydata;
displaylist;
mainloop;
closedoors;
{stopmod;}
removedata;
end;
{***************************************************************************}
procedure inccursor;
begin
drawit:=false;
if cargomode=0 then
repeat
inc(cargoindex);
i:=0;
for j:=1 to 6 do if ship.crew[j].level>=createinfo^[cargoindex].levels[j] then inc(i);
case createinfo^[cargoindex].index of
0..2999: if filters[3]=1 then drawit:=true;
ID_UNKNOWN_COMPONENT..3999: if filters[2]=1 then drawit:=true;
ID_UNKNOWN_MATERIAL..4999: if filters[1]=1 then drawit:=true;
end;
until ((i=6) and (drawit)) or (cargoindex>maxcreation)
else
repeat
inc(cargoindex);
while (cargoindex<251) and (ship.numcargo[cargoindex]=0) do inc(cargoindex);
case ship.cargo[cargoindex] of
0..2999,ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters[3]=1 then drawit:=true;
ID_UNKNOWN_COMPONENT..3999: if filters[2]=1 then drawit:=true;
ID_UNKNOWN_MATERIAL..4999: if filters[1]=1 then drawit:=true;
end;
until (drawit) or (cargoindex>250);
if (qmode) and (viewteam>0) then
begin
viewteam:=0;
for i:=77 to 80 do
scr_fillchar(screen[i,222],77,0);
end;
anychange:=true;
end;
procedure deccursor;
begin
drawit:=false;
if cargomode=0 then
repeat
dec(cargoindex);
i:=0;
for j:=1 to 6 do if ship.crew[j].level>=createinfo^[cargoindex].levels[j] then inc(i);
case createinfo^[cargoindex].index of
0..2999: if filters[3]=1 then drawit:=true;
ID_UNKNOWN_COMPONENT..3999: if filters[2]=1 then drawit:=true;
ID_UNKNOWN_MATERIAL..4999: if filters[1]=1 then drawit:=true;
end;
until ((i=6) and (drawit)) or (cargoindex<1)
else
repeat
dec(cargoindex);
while (cargoindex>0) and (ship.numcargo[cargoindex]=0) do dec(cargoindex);
case ship.cargo[cargoindex] of
0..2999,ID_ARTIFACT_OFFSET..ID_LAST_ARTIFACT: if filters[3]=1 then drawit:=true;
ID_UNKNOWN_COMPONENT..3999: if filters[2]=1 then drawit:=true;
ID_UNKNOWN_MATERIAL..4999: if filters[1]=1 then drawit:=true;
end;
until (drawit) or (cargoindex<1);
if (qmode) and (viewteam>0) then
begin
viewteam:=0;
for i:=77 to 80 do
scr_fillchar(screen[i,222],77,0);
end;
anychange:=true;