-
Notifications
You must be signed in to change notification settings - Fork 2
/
randmaps.pp
1634 lines (1431 loc) · 45.9 KB
/
randmaps.pp
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 RandMaps;
interface
uses crt,RPGDice,TexModel,TexMaps,plotbase,dcitems,critters,GameBook,charts,cwords,dcchars,texutil;
Const
SceneSize = 12;
Type
RoomPtr = ^Room;
Room = Record {This is the description for one room.}
Style: Integer;
X,Y,W,H: Integer; {X,Y,Width,Height}
Floor,Wall: Integer; {What terr type should be used for the floor and the wall.}
Next: RoomPtr;
end;
RStyle = Record {This describes a type of room}
Name: String;
Floor,Wall: Integer;
SP: Byte; {% of halls which should be service tunnels}
WC,WR,HC,HR: Byte; {Constants for determining size.}
end;
Scenery = Array [1..SceneSize,1..SceneSize] of byte;
SceneryPtr = ^Scenery;
Const
EmptyTerrain = 6;
{Direction 1 corresponds to 3 O'Clock; 2 is 6 O'Clock, 3 is 9 O'Clock, and 4 is 12 O'Clock.}
{This ordering should make Right/Left rotations easier.}
AngDir: Array [0..5,1..2] of Integer = (
(0,-1),(1,0),(0,1),(-1,0),(0,-1),(1,0)
);
RNormStyle = 1;
REngineWorks = 2;
NumStyle = 21;
{And now, our interior decoration manual.}
IntDec: Array [1..NumStyle] of RStyle = (
( Name: 'Normal Room';
Floor: 2; Wall: 3; SP: 15;
WC: 5; WR: 20; HC: 5; HR: 12 ),
( Name: 'Engine Works';
Floor: 5; Wall: 6; SP: 100;
WC: 5; WR: 5; HC: 5; HR: 5 ),
( Name: 'Lounge';
Floor: 15; Wall: 3; SP: 20;
WC: 12; WR: 12; HC: 7; HR: 10 ),
( Name: 'Security Center';
Floor: 2; Wall: 3; SP: 0;
WC: 8; WR: 12; HC: 5; HR: 10 ),
( Name: 'Storage Room';
Floor: 5; Wall: 3; SP: 25;
WC: 20; WR: 10; HC: 10; HR: 10 ),
( Name: 'Obstructed room';
Floor: 2; Wall: 3; SP: 45;
WC: 5; WR: 20; HC: 5; HR: 20 ),
( Name: 'Shuttle Bay';
Floor: 2; Wall: 3; SP: 30;
WC: 20; WR: 12; HC: 20; HR: 12 ),
( Name: 'Transitway Left';
Floor: 2; Wall: 3; SP: 5;
WC: 9; WR: 1; HC: 6; HR: 3 ),
( Name: 'Transitway Right';
Floor: 2; Wall: 3; SP: 5;
WC: 9; WR: 1; HC: 6; HR: 3 ),
( Name: 'Residential Block';
Floor: 2; Wall: 3; SP: 10;
WC: 17; WR: 18; HC: 15; HR: 3 ),
( Name: 'Andros Guero Quarters';
Floor: 2; Wall: 3; SP: 10;
WC: 17; WR: 18; HC: 15; HR: 3 ),
( Name: 'Chapel';
Floor: 40; Wall: 3; SP: 2;
WC: 12; WR: 7; HC: 12; HR: 12 ),
( Name: 'Reliquary';
Floor: 2; Wall: 3; SP: 0;
WC: 12; WR: 18; HC: 12; HR: 12 ),
( Name: 'Medical Center';
Floor: 15; Wall: 3; SP: 25;
WC: 16; WR: 16; HC: 8; HR: 5 ),
( Name: 'Gravesite';
Floor: 40; Wall: 3; SP: 3;
WC: 15; WR: 32; HC: 8; HR: 25 ),
( Name: 'Computer Control Center';
Floor: 5; Wall: 6; SP: 100;
WC: 5; WR: 5; HC: 5; HR: 5 ),
( Name: 'Cryogenics Lab';
Floor: 5; Wall: 3; SP: 70;
WC: 12; WR: 8; HC: 15; HR: 20 ),
( Name: 'Transitway Down';
Floor: 2; Wall: 3; SP: 5;
WC: 9; WR: 1; HC: 6; HR: 3 ),
( Name: 'Transitway Up';
Floor: 2; Wall: 3; SP: 5;
WC: 9; WR: 1; HC: 6; HR: 3 ),
( Name: 'Museum';
Floor: 15; Wall: 3; SP: 2;
WC: 21; WR: 5; HC: 19; HR: 3 ),
( Name: 'DesCartes Control Center';
Floor: 5; Wall: 6; SP: 100;
WC: 10; WR: 5; HC: 10; HR: 5 )
);
RocketShip: Scenery = (
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 27,25,25,25,25,24, 0, 0, 0, 0, 0, 0 ),
( 0, 0,20,20,20,20, 8,24,28, 0, 0, 0 ),
( 0,27,26,29,29,26,29,20,25,25,20, 0 ),
( 0,27,20,29,29, 8,29,29,29,21,22,23 ),
( 0,27,26,29,29,26,29,20,25,25,20, 0 ),
( 0, 0,20,20,20,20, 8,24,28, 0, 0, 0 ),
( 27,25,25,25,25,24, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) );
TransitChassis: Scenery = (
( 36,36,36, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 30, 0,31, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
);
Apartment: Scenery = (
( 16,16,16, 8,16,16,16, 0, 0, 0, 0, 0 ),
( 16,15,15,15,15,15,16, 0, 0, 0, 0, 0 ),
( 16,15,15,15,14,15,16, 0, 0, 0, 0, 0 ),
( 16,15,15,14,37,14,16, 0, 0, 0, 0, 0 ),
( 16,15,15,15,14,15,16, 0, 0, 0, 0, 0 ),
( 16,16,16,15,15,15,16, 0, 0, 0, 0, 0 ),
( 16,38, 8,15,15,19,16, 0, 0, 0, 0, 0 ),
( 16,16,16,16,16,16,16, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
);
Capsule: Scenery = (
( 48,49,50, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 47,45,47, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 46,12,46, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
);
Level_Contents: Array [0..Num_Levels] of string = (
'8 9',
' 7 10 14 8 12 9 11 5',
' 4 8 15 9 12 15 16 17',
' 8 9 18',
' 8 5 9',
' 8 9',
' 4 8 4 9',
' 8 9 19',
'12 8 20 10 13 9 12 21'
);
Procedure RectFill(gb: GameBoardPtr; X1,Y1,X2,Y2,terr: integer);
Procedure RoomFill(gb: GameBoardPtr; X1,Y1,X2,Y2,W,F: integer);
Function AddRoom(var LList: RoomPtr): RoomPtr;
Procedure RandomLevel(SC: ScenarioPtr; R: RoomPtr);
Procedure GenerateCurrentLevel( SC: ScenarioPtr );
Procedure GotoLevel( SC: ScenarioPtr; N, Entry_Terrain: Integer );
implementation
Const
ItsAFloor: Boolean = False;
NormHall = 1;
ServTunnel = 2;
HallStyle: Byte = NormHall;
WallStyle: Integer = 3;
StorageRoomItem = 20; {% chance of item in each pile.}
StorageRoomMaxRolls = 3; {Max # of items to be generated per pile.}
StorageRoomRobot = 8; {% chance of a robot, if no item.}
SecurityCellItem = 88; {% chance of a stockpile in a security cell.}
SecurityCellNum = 4; {Max number of items per cell.}
SecurityCellZombie = 35; {% chance of a zombie, if no stockpile.}
CryptItem = 25; {% chance of a stockpile in a crypt tile.}
CryptNum = 3; {Max number of items per cell.}
CryptCritter = 70; {% chance of a zombie, if no stockpile.}
Procedure RectFill(gb: GameBoardPtr; X1,Y1,X2,Y2,terr: integer);
{Fill the given rectangular area with terrain type terr}
var
x,y: Integer;
begin
for x := x1 to x2 do
for y := y1 to y2 do
gb^.map[x,y].terr := terr;
end;
Procedure RoomFill(gb: GameBoardPtr; X1,Y1,X2,Y2,W,F: integer);
{Create a room, with wall type W and floor type F.}
var
x,y: Integer;
begin
for x := x1 to x2 do
for y := y1 to y2 do begin
if (X=X1) or (X=X2) or (Y=Y1) or (Y=Y2) then
gb^.map[x,y].terr := W
else
gb^.map[X,Y].terr := F;
end;
end;
Procedure AddScenery(gb: GameBoardPtr; X0,Y0: Integer; Scene: SceneryPtr; Reveal: Boolean);
{Add the scenery to the map}
var
X,Y: Integer;
begin
for X := 1 to SceneSize do begin
for Y := 1 to SceneSize do begin
if OnTheMap(X+X0-1,Y+Y0-1) then begin
{Apparently, I made a boo-boo when defining things, so now}
{Scenery data is stored with its coordinates as Y,X instead of X,Y.}
if (Scene^[Y,X] <> 0) then begin
gb^.map[X+X0-1,Y+Y0-1].terr := Scene^[Y,X];
if reveal then gb^.map[X+X0-1,Y+Y0-1].visible := true;
end;
end;
end;
end;
end;
Function LastRoom(LList: RoomPtr): RoomPtr;
{Search through the linked list, and return the last element.}
{If LList is empty, return Nil.}
begin
if LList <> Nil then
while LList^.Next <> Nil do
LList := LList^.Next;
LastRoom := LList;
end;
Function AddRoom(var LList: RoomPtr): RoomPtr;
{Add a new element to the end of LList.}
var
it: RoomPtr;
begin
{Allocate memory for our new element.}
New(it);
if it = Nil then exit;
{Initialize values.}
it^.Next := Nil;
it^.Style := 0;
it^.X := -1;
it^.Y := -1;
it^.Floor := 2;
it^.Wall := 3;
{Attach IT to the list.}
if LList = Nil then
LList := it
else
LastRoom(LList)^.Next := it;
{Return a pointer to the new element.}
AddRoom := it;
end;
Procedure DisposeRoomList(var LList: RoomPtr);
{Dispose of the list, freeing all associated system resources.}
var
LTemp: RoomPtr;
begin
while LList <> Nil do begin
LTemp := LList^.Next;
Dispose(LList);
LList := LTemp;
end;
end;
Function NextRoom(RList,R: RoomPtr): RoomPtr;
{Return the address of the next room in the list.}
{If we're already looking at the last room, loop around}
{to the first one again.}
var
it: RoomPtr;
begin
it := R^.Next;
if it = Nil then it := RList;
NextRoom := it;
end;
Procedure InitRoom(R: RoomPtr);
{Given room R, whose Style field has been filled out,}
{set appropriate values for each of the other fields.}
begin
R^.W := IntDec[R^.Style].WC + Random(IntDec[R^.Style].WR);
R^.H := IntDec[R^.Style].HC + Random(IntDec[R^.Style].HR);
R^.Wall := IntDec[R^.Style].Wall;
R^.Floor := IntDec[R^.Style].Floor;
{Special check- make sure that a lounge area will look pretty!}
if (R^.Style = 3) or (R^.Style = 12) then begin
if not Odd(R^.H) then Inc(R^.H);
if not Odd(R^.W) then Inc(R^.W);
end;
end;
Function NewRoom(var RList: RoomPtr): RoomPtr;
{Add a random new room to the list.}
var
R: RoomPtr;
begin
R := AddRoom(RList);
{Decide upon the style of this room. For now,}
{just pick one at random.}
R^.Style := Random(6)+1;
InitRoom(R);
NewRoom := R;
end;
Function AreaClear(GB: GameBoardPtr; X1,Y1,W,H: Integer): Boolean;
{Search the area defined by X,Y,W and H on the game map.}
{Return True if the area consists of blank terrain.}
{Return False if there's anything else there.}
var
it: Boolean;
X,Y,X2,Y2: Integer;
begin
{Initialize variables.}
it := true;
X2 := X1 + W - 1;
Y2 := Y1 + H - 1;
for X := X1 to X2 do begin
for Y := Y1 to Y2 do begin
if gb^.map[X,Y].terr <> EmptyTerrain then it := False;
end;
end;
AreaClear := it;
end;
Function IsASpace(gb: GameBoardPtr; X,Y: Integer): Boolean;
{Check the space indicated. Return True if it is passable}
{terrain, False otherwise.}
var
it: Boolean;
begin
if not OnTheMap( X , Y ) then Exit( TRUE );
if (HallStyle <> ServTunnel) and (gb^.map[X,Y].terr = Crawlspace) then it := false
else if (TerrPass[gb^.map[X,Y].terr] > 0) then it := true
else if (gb^.map[X,Y].terr = ClosedDoor) or (gb^.map[X,Y].terr = ClosedServicePanel) or (gb^.map[X,Y].terr = HiddenServicePanel) then it := true
else it := false;
IsASpace := it;
end;
Function IsAWall(gb: GameBoardPtr; X,Y: Integer): Boolean;
{Check the space indicated. Return True if it is a plain}
{wall, False otherwise.}
var
it: Boolean;
begin
if TerrPass[gb^.map[X,Y].terr] = 0 then it := true
else it := false;
IsAWall := it;
end;
Function PathClear(gb: GameBoardPtr; X,Y,D,L: Integer): Integer;
{Check the path indicated by the details given. In particular,}
{check to see whether or not this path will intersect with}
{a room or corridor in a bad way.}
var
t,r: Integer;
begin
r := 1;
for t := 1 to L do begin
if IsAWall(gb,X,Y) then begin
if IsASpace(gb,X+AngDir[D+1,1],Y+AngDir[D+1,2]) then begin
r := 1;
break;
end;
if IsASpace(gb,X+AngDir[D-1,1],Y+AngDir[D-1,2]) then begin
r := -1;
break;
end;
end;
X := X + AngDir[D,1];
Y := Y + AngDir[D,2];
end;
PathClear := t * r;
end;
Procedure PlotWall(gb: GameBoardPtr; X,Y: Integer);
{Draw a wall in the current wall style. The rule is as}
{follows: If intersecting empty terrain or default wall}
{type, draw the wall as normal. If intersecting a crawlspace}
{then set down a HiddenServicePanel instead of a wall.}
{If intersecting any other kind of space, don't do anything.}
begin
if IsAWall(gb,X,Y) then gb^.map[X,Y].terr := WallStyle
else if gb^.map[X,Y].terr = Crawlspace then gb^.map[X,Y].terr := HiddenServicePanel;
end;
Procedure PlotDoor(gb: GameBoardPtr; X,Y: Integer);
{Plot a door at location X,Y. Select one of the possible}
{door types randomly. It may be open or closed, or even}
{a hidden service panel.}
begin
{There's a very small chance that instead of a regular door,}
{we'll plot a service panel instead.}
if Random(100) = 23 then begin
{Plot service panel.}
if Random(5) = 1 then begin
if Random(3) = 1 then begin
gb^.map[x,y].terr := OpenServicePanel;
end else begin
gb^.map[x,y].terr := ClosedServicePanel;
end;
end else begin
gb^.map[x,y].terr := HiddenServicePanel;
end;
end else begin
{Plot door.}
if Random(3) = 1 then begin
{Open door.}
gb^.map[x,y].terr := OpenDoor;
end else begin
{Closed door.}
gb^.map[x,y].terr := ClosedDoor;
end;
end;
end;
Procedure RenderCorner(gb: GameBoardPtr; X,Y: Integer);
{Render a corner, in the current wall style.}
var
XX,YY: Integer;
begin
if HallStyle = ServTunnel then exit;
{Make sure that our center point is within bounds.}
if X<2 then X := 2
else if X>=XMax then X := XMax - 1;
if Y<2 then Y := 2
else if Y>=YMax then Y := YMax - 1;
{Do the rendering. Just replace all walls in the vicinity}
{with the wall style currently selected.}
for XX := X-1 to X+1 do
for YY := Y-1 to Y+1 do
PlotWall(gb,XX,YY);
end;
Procedure RenderCorridorSection(gb: GameBoardPtr; X,Y,D: Integer);
{Render a single block of corridor.}
begin
{Plot the floor, if appropriate.}
if HallStyle = NormHall then begin
if (TerrPass[gb^.map[X,Y].terr] = 0) or (gb^.map[X,Y].terr = Crawlspace) then begin
{If we have a wall or a crawlspace, draw a corridor through it.}
if ItsAFloor and (Random(2) = 1) then
PlotDoor(gb,X,Y)
else begin
if (TerrPass[gb^.map[X+AngDir[D,1],Y+AngDir[D,2]].terr] > 0) and (Random(2) = 1) then
PlotDoor(gb,X,Y)
else
gb^.map[X,Y].terr := 2;
end;
ItsAFloor := False;
end else if (TerrPass[gb^.map[X,Y].terr] < 0) then begin
ItsAFloor := False;
end else begin
ItsAFloor := True;
end;
end else if HallStyle = ServTunnel then begin
{Here are the rules. If the current square is a}
{standard wall, change it to a HiddenServicePanel.}
{If it's empty terrain, draw a crawlspace.}
if gb^.map[X,Y].terr = EmptyTerrain then begin
gb^.map[X,Y].terr := Crawlspace;
end else if (TerrPass[gb^.map[X,Y].terr] = 0) then begin
gb^.map[X,Y].terr := HiddenServicePanel;
end;
end;
if HallStyle <> ServTunnel then begin
{Service tunnels don't get walls surrounding them.}
PlotWall(gb,X + AngDir[D+1,1],Y + AngDir[D+1,2]);
PlotWall(gb,X + AngDir[D-1,1],Y + AngDir[D-1,2]);
end;
end;
Procedure RenderCorridor(gb: GameBoardPtr; X1,Y1,D,L: Integer);
{Draw a corridor onto the map, starting at X,Y and}
{proceeding L units in direction D.}
var
X,Y,T: Integer;
begin
X := X1;
Y := Y1;
ItsAFloor := False;
for t := 1 to L do begin
RenderCorridorSection(gb,X,Y,D);
X := X + AngDir[D,1];
Y := Y + AngDir[D,2];
end;
{Finish off the corner of the hall.}
RenderCorner(gb,X - AngDir[D,1],Y - AngDir[D,2]);
end;
Procedure RenderWTunnel(gb: GameBoardPtr; X,Y,D: Integer);
{Start rendering a worm tunnel. Yay!}
{This tunnel has no preset length or destination.}
{It keeps going until either it runs out of map or it}
{intersects a room/corridor.}
var
KeepGoing: Boolean;
t: Integer;
{WTunnel Procedures Block}
procedure ChangeDirection;
begin
D := D + Random(2) - Random(2);
if D < 1 then D := 4
else if D > 4 then D := 1;
RenderCorner(gb,X,Y);
end;
begin
KeepGoing := True;
{Because WTunnels will be set up on room walls, initialize}
{this value to True.}
ItsAFloor := True;
{Check- if this is not a good place to start doing a WTunnel,}
{exit without rendering anything.}
if (X = 1) or (X = XMax) or (Y = 1) or (Y = YMax) then begin
KeepGoing := False;
end else if IsASpace(gb,X,y) or IsASpace(gb,X+AngDir[D+1,1],Y+AngDir[D+1,2]) or IsASpace(gb,X+AngDir[D-1,1],Y+AngDir[D-1,2]) then begin
KeepGoing := False;
end;
t := 0;
While KeepGoing do begin
Inc(t);
if IsASpace(gb,X,y) or IsASpace(gb,X+AngDir[D+1,1],Y+AngDir[D+1,2]) or IsASpace(gb,X+AngDir[D-1,1],Y+AngDir[D-1,2]) then begin
KeepGoing := False;
end else if Random(1000) = 0 then begin
KeepGoing := False;
end;
RenderCorridorSection(gb,X,Y,D);
{Maybe change direction now.}
{First, check for the edge of the map.}
if (X+AngDir[D,1]=1) or (X+AngDir[D,1]=XMax) or (Y+AngDir[D,2]=1) or (Y+AngDir[D,2]=YMax) then begin
ChangeDirection;
end else if (Random(33) = 12) and (t > 1) then begin
ChangeDirection;
end;
{Move to the next square.}
X := X + AngDir[D,1];
Y := Y + AngDir[D,2];
{Check for the edge of the map}
if (X = 1) or (X = XMax) or (Y = 1) or (Y = YMax) then begin
KeepGoing := False;
end;
end;
RenderCorner(gb,X,Y);
end;
Procedure AddWTunnels(gb: GameBoardPtr; R: RoomPtr; N: Integer);
{Attempt to add dN wormtunnels to room R.}
var
T,D,X,Y: Integer;
begin
For t := 1 to Dice(N) do begin
{Determine the starting direction of this tunnel.}
{This will decide what wall it's starting in.}
D := Random(4) + 1;
X := R^.X;
Y := R^.Y;
if D = 1 then begin
Y := Y + Random(R^.H - 2) + 1;
X := X + R^.W - 1;
end else if D = 3 then begin
Y := Y + Random(R^.H - 2) + 1;
end else if D = 2 then begin
X := X + Random(R^.W - 2) + 1;
Y := Y + R^.H - 1;
end else begin
X := X + Random(R^.W - 2) + 1;
end;
{Determine the style of the tunnel.}
if (Random(100)+1) <= IntDec[R^.Style].SP then
HallStyle := ServTunnel
else
HallStyle := NormHall;
RenderWTunnel(gb,X,Y,D);
end;
end;
Procedure ConnectRoom(gb: GameBoardPtr; R1,R2: RoomPtr);
{Connect R1 to R2 by means of a hallway.}
var
X1,Y1,X2,Y2: Integer;
T,DH,DV: Integer;
begin
{Before we start on the connection tunnels, let's add some}
{random tunnels to the room.}
AddWTunnels(gb,R1,4);
{Select the origin points of the corridor in both rooms.}
X1 := Random(R1^.W - 2) + R1^.X + 1;
Y1 := Random(R1^.H - 2) + R1^.Y + 1;
X2 := Random(R2^.W - 2) + R2^.X + 1;
Y2 := Random(R2^.H - 2) + R2^.Y + 1;
IF x2>x1 then DH := 1
else DH := 3;
T := 0;
while (Abs(PathClear(gb,X1,Y1,DH,Abs(X2-X1)+1)) <> (Abs(X2-X1)+1)) and (T < 30) do begin
Y1 := Random(R1^.H - 2) + R1^.Y + 1;
Inc(t);
end;
if Y2 > Y1 then DV := 2
else DV := 4;
t := 0;
while (Abs(PathClear(gb,X2,Y1,DV,Abs(Y2-Y1)+1)) <> (Abs(Y2-Y1)+1)) and (T < 30) do begin
X2 := Random(R2^.W - 2) + R2^.X + 1;
Inc(t);
end;
{These halls, which connect the key rooms, are more likely}
{to be service tunnels than they are to be normal hallways.}
if (R1^.Style = REngineWorks) or (R2^.Style = REngineWorks) then
HallStyle := ServTunnel
else if (Random(100)+1) > IntDec[R1^.Style].SP then
HallStyle := NormHall
else
HallStyle := ServTunnel;
{Horizontal Tunnel}
RenderCorridor(gb,X1,Y1,DH,Abs(X2-X1)+1);
{Vertical Tunnel}
RenderCorridor(gb,X2,Y1,DV,Abs(Y2-Y1)+1);
end;
Procedure PlaceItemCache( SC: ScenarioPtr; X , Y: Integer );
{ Place a number of random, highly valuable items in this spot. }
const
{ This array tells what treasure type chart to use. }
TTL: Array [0..9] of byte = (
TType_AllMedicene,TType_AllMedicene,TType_AllAmmo,TType_AllAmmo,TType_AllAmmo,
TType_BasicGuns,TType_BasicWeps,TType_TechnoItems,TType_SpaceGear,TType_StorageRoom
);
var
N,T: Integer;
I: DCItemPtr;
begin
{ Determine how many items to generate. }
N := Random(10) + 1;
{ Place N items. }
for T := 1 to N do begin
I := GenerateItem(SC,TTL[Random(10)]);
PlaceDCItem(SC^.gb,SC^.ig,I,X,Y);
end;
end;
Procedure DetailLounge(SC: ScenarioPtr; R: RoomPtr);
{Add details needed for a lounge area.}
var
NX,NY,T: Integer;
begin
{Determine how many chairs to add, horiz and vert.}
NX := (R^.W - 3) div 2;
NY := (R^.H - 3) div 2;
for t := 1 to NX do begin
SC^.gb^.map[R^.X+t*2,R^.Y+2].terr := chair;
SC^.gb^.map[R^.X+t*2,R^.Y+2*NY].terr := chair;
end;
for t := 1 to NY do begin
SC^.gb^.map[R^.X+2,R^.Y+t*2].terr := chair;
SC^.gb^.map[R^.X+2*NX,R^.Y+t*2].terr := chair;
end;
end;
Procedure DetailSecArea(SC: ScenarioPtr; R: RoomPtr);
{Draw in the details appropriate for the security area.}
const
SecTrap: Array [1..10] of byte = (3,2,2,2,2,2,2,3,3,3);
{*** DetailSecArea Procedures Block ***}
Procedure SecCell(X,Y,D: Integer);
{Draw a 3 x 3 security cell at location X,Y.}
var
N,T: Integer;
I: DCItemPtr;
begin
RoomFill(SC^.gb,X,Y,X+2,Y+2,SecureWall,R^.Floor);
{Add a door... with alarm.}
SC^.gb^.map[X+1+D,Y+1].terr := ClosedDoor;
SC^.gb^.map[X+1+D*2,Y+1].trap := -4;
if (Random(100)+1) <= SecurityCellItem then begin
{Add an item...}
N := Random( SecurityCellNum ) + 1;
for t := 1 to N do begin
I := GenerateItem(SC,TType_SecurityArea);
PlaceDCItem(SC^.gb,SC^.ig,I,X+1,Y+1);
end;
{... then add a trap}
if Random(100) <> 74 then SC^.gb^.map[X+1,Y+1].trap := -SecTrap[Random(10)+1];
end else if (Random(100)+1) <= SecurityCellZombie then begin
AddCritter(SC^.CList,SC^.gb,3,X+1,Y+1);
end else if Random(3) <> 1 then begin
{Just add a trap.}
SC^.gb^.map[X+1,Y+1].trap := -SecTrap[Random(10)+1];
end;
end;
var
t,n,x,y: Integer;
begin
if R^.W >= 11 then begin
{Add two lines of security cells}
for t := 1 to ((R^.H - 4) div 3) do begin
SecCell(R^.X+2,R^.Y-1+t*3,1);
SecCell(R^.X+R^.W-5,R^.Y-1+t*3,-1);
end;
end else if R^.W >= 8 then begin
{Add one line of security cells}
for t := 1 to ((R^.H - 4) div 3) do begin
SecCell(R^.X+2,R^.Y-1+t*3,1);
end;
end;
{Add security robots.}
if Random(2) = 1 then AddCritter(SC^.CList,SC^.gb,5,R^.X+1,R^.Y+1);
if Random(2) = 1 then AddCritter(SC^.CList,SC^.gb,5,R^.X+1,R^.Y+R^.H-2);
if Random(2) = 1 then AddCritter(SC^.CList,SC^.gb,5,R^.X+R^.W-2,R^.Y+1);
if Random(2) = 1 then AddCritter(SC^.CList,SC^.gb,5,R^.X+R^.W-2,R^.Y+R^.H-2);
X := R^.X + ( R^.W div 2 );
Y := R^.Y + ( R^.H div 2 );
if IsASpace( SC^.GB , X , Y ) and ( Random( 10 ) = 1 ) then begin
AddCritter(SC^.CList,SC^.gb,21,X,Y);
end;
{ Add some alarms and/or traps. }
N := Random( 10 );
for t := 1 to N do begin
X := Random( R^.W - 2 ) + R^.X + 1;
Y := Random( R^.H - 2 ) + R^.Y + 1;
if IsASpace( SC^.GB , X , Y ) and ( SC^.GB^.map[X,Y].Trap = 0 ) then begin
if Random( 10 ) = 1 then SC^.GB^.Map[X,Y].trap := -2
else SC^.GB^.Map[X,Y].trap := -4;
end;
end;
end;
Procedure DetailStorage(SC: ScenarioPtr; R: RoomPtr);
{Draw in the details appropriate for the storage room.}
const
Robo: Array [1..10] of integer = (1,1,1,1,5, 1,1,1,1,5);
var
X,Y,N: Integer;
I: DCItemPtr;
begin
{Loop through each avaliable storage pile position. For}
{each one, add a pile of goods, a robot of some type, or}
{nothing at all.}
for X := 1 to ((R^.W-5) div 2) do begin
for Y := 1 to ((R^.H-5) div 2) do begin
if (Random(100)+1) <= StorageRoomItem then begin
{We are going to stick one (or more) items on the floor at this position.}
N := 1;
repeat
Inc(N);
I := GenerateItem(SC,TType_StorageRoom);
PlaceDCItem(SC^.gb,SC^.ig,I,R^.X+(X*2)+1,R^.Y+(Y*2)+1);
until ((Random(100)+1) > StorageRoomItem) or (N >= StorageRoomMaxRolls);
end else if (Random(100)+1) <= StorageRoomRobot then begin
{There's no item here... so, we're gonna add a robot instead.}
AddCritter(SC^.CList,SC^.gb,Robo[Random(10)+1],R^.X+(X*2)+1,R^.Y+(Y*2)+1);
end;
end;
end;
end;
Procedure DetailBigBox(SC: ScenarioPtr; R: RoomPtr);
{Why such a strange name? Because that's all this room}
{is- a regular room with a huge box-shaped obstacle in}
{the middle.}
var
N,T,D,X,Y: Integer;
begin
if Random(3) = 1 then begin
{Hollow box.}
if Random(99) = 23 then
RoomFill(SC^.gb,R^.X+2,R^.Y+2,R^.X+R^.W-3,R^.Y+R^.H-3,SecureWall,4)
else
RoomFill(SC^.gb,R^.X+2,R^.Y+2,R^.X+R^.W-3,R^.Y+R^.H-3,SecureWall,5);
{Add some entry points, maybe.}
N := RollStep(2) - 1;
for t := 1 to N do begin
D := Random(4) + 1;
X := R^.X+2;
Y := R^.Y+2;
if D = 1 then begin
Y := Y + Random(R^.H - 6) + 1;
X := X + R^.W - 5;
end else if D = 3 then begin
Y := Y + Random(R^.H - 6) + 1;
end else if D = 2 then begin
X := X + Random(R^.W - 6) + 1;
Y := Y + R^.H - 5;
end else begin
X := X + Random(R^.W - 6) + 1;
end;
SC^.gb^.map[X,Y].terr := HiddenServicePanel;
end;
end else begin
{Filled box.}
RoomFill(SC^.gb,R^.X+2,R^.Y+2,R^.X+R^.W-3,R^.Y+R^.H-3,SecureWall,R^.Wall);
end;
end;
Procedure DetailShuttleBay(SC: ScenarioPtr; R: RoomPtr);
{Draw the spaceship for the shuttle bay.}
var
T: Integer;
MP: MPUPtr;
I: DCItemPtr;
begin
AddScenery(SC^.gb,R^.X+5,R^.Y+5,@RocketShip,True);
{Add the plot arcs and the triggers for the message to be}
{printed when the PC first exits the spaceship.}
{7,3 7,9 8,3 8,9}
SC^.gb^.map[R^.X+11,R^.Y+ 7].special := 1;
SC^.gb^.map[R^.X+11,R^.Y+13].special := 1;
SC^.gb^.map[R^.X+12,R^.Y+ 7].special := 1;
SC^.gb^.map[R^.X+12,R^.Y+13].special := 1;
for t := R^.X to (R^.X + R^.W - 1) do begin
SC^.gb^.map[T,R^.Y].special := 2;
SC^.gb^.map[T,R^.Y + R^.H - 1].special := 2;
end;
for t := R^.Y to (R^.Y + R^.H - 1) do begin
SC^.gb^.map[R^.X,T].special := 2;
SC^.gb^.map[R^.X + R^.W - 1,T].special := 2;
end;
{ Add the entry messages. }
SetSAtt( SC^.PLLocal , 'MS1 <if= V1 0 V= 1 1 print ExitShipMsg>');
SetSAtt( SC^.PLLocal , 'msgEXITSHIPMSG <You step out into the shuttle bay. There are no maintenance crews, no security teams, to greet your arrival. The only noise is the distant hum of the ventilators.>');
SetSAtt( SC^.PLLocal , 'MS2 <if= V1 1 V= 1 2 print ExitHangarMsg>');
SetSAtt( SC^.PLLocal , 'msgEXITHANGARMSG <The design of this level is characteristic of many old space stations. New modules were simply welded on as needed, resulting in a confusing and unplanned mass of tunnels. Finding your way may be difficult.>');
{ Add the maintenance robot. }
AddCritter(SC^.CList,SC^.gb,1,R^.X+1,R^.Y+1);
{ Add a handymap. }
I := NewDCItem;
I^.IKind := IKIND_Electronics;
I^.ICode := 1;
PlaceDCItem(SC^.gb,SC^.ig,I, R^.X+8 , R^.Y+10);
MP := AddMPU( SC^.Comps , SC^.GB , 1 , R^.X + R^.W - 3 , R^.Y + R^.H - 3 );
MP^.Attr := '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15';
end;
Procedure DetailTransitway(SC: ScenarioPtr; R: RoomPtr; Door: Integer );
{Draw a left-leading transit tube.}
begin
AddScenery(SC^.gb,R^.X+3,R^.Y+2,@TransitChassis,False);
SC^.GB^.Map[ R^.X + 4 , R^.Y + 3 ].terr := Door;
end;
Procedure DetailResidence(SC: ScenarioPtr; R: RoomPtr);
{Draw some living quarters.}
var
N,T: Integer;
begin
{ Do a big internal box. }
RoomFill( SC^.gb , R^.X + 2 , R^.Y + 2 , R^.X + R^.W - 3 , R^.Y + R^.H - 3 , 16 , 6 );
{Figure out how many apartments we have space to add.}
N := (R^.W - 5) div 6;
for t := 0 to ( N-1 ) do begin
AddScenery( SC^.gb , R^.X+2+T*6 , R^.Y+2 , @Apartment , False );
end;
end;
Procedure DetailAGQ(SC: ScenarioPtr; R: RoomPtr);
{Detail Andros Guero's quarters. This is where the PC}
{can find Andros's security pass and also his diary.}
var
N: Integer;
I: DCItemPtr;
begin
{Start by detailing this area as you would any residence.}
DetailResidence(SC,R);
{Next, detail Andros's place. Put blood stains on the floor,}
{and add the needed items.}
N := Random((R^.W - 5) div 6);
{Add the security card.}
I := NewDCItem;
I^.IKind := IKIND_KeyItem;
I^.ICode := 1;
PlaceDCItem(SC^.gb,SC^.ig,I, R^.X+5+N*6 , R^.Y+7);
{Add the diary.}
I := NewDCItem;
I^.IKind := IKIND_Book;
I^.ICode := 1;
PlaceDCItem(SC^.gb,SC^.ig,I, R^.X+5+N*6 , R^.Y+8);
{Add some blood stains.}
SC^.gb^.map[R^.X+5+N*6 , R^.Y+7].terr := 10;
SC^.gb^.map[R^.X+5+N*6 , R^.Y+8].terr := 10;
SC^.gb^.map[R^.X+6+N*6 , R^.Y+7].terr := 10;
SC^.gb^.map[R^.X+4+N*6 , R^.Y+6].terr := 10;
end;
Procedure DetailChapel(SC: ScenarioPtr; R: RoomPtr);
{Draw in the details for the chapel type room.}
var
t,X,CX: Integer;
I: DCItemPtr;
begin
{Determine the midpoint of the chapel.}
CX := R^.X + (( R^.W + 1 ) div 2) - 1;
{Draw the columns and pews.}
for t := 1 to ((R^.H - 3) div 2) do begin
SC^.gb^.map[R^.X+2,R^.Y+t*2].terr := MarbleColumn;
SC^.gb^.map[R^.X+R^.W-3,R^.Y+t*2].terr := MarbleColumn;
if t = 1 then begin
{Do the altar & Holy Water.}
SC^.gb^.map[CX,R^.Y+1+t*2].terr := 39;
I := NewDCItem;
I^.IKind := IKIND_Grenade;
I^.ICode := 8;
I^.charge := 1 + Random(3);
PlaceDCItem(SC^.gb,SC^.ig,I, CX , R^.Y+2+t*2 );