-
Notifications
You must be signed in to change notification settings - Fork 0
/
grower.lua
1206 lines (867 loc) · 24.6 KB
/
grower.lua
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
----------------------------------------------------------------
-- SEED MANAGEMENT / GROWING
----------------------------------------------------------------
--
-- Oblige Level Maker (C) 2006-2008 Andrew Apted
--
-- This program 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 2
-- of the License, or (at your option) any later version.
--
-- This program 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.
--
----------------------------------------------------------------
--[[ *** CLASS INFORMATION ***
class SEED
{
sx, sy, sz : location in seed map
zone : ZONE, never nil!
room : ROOM
borders : table(DIR -> BORDER) -- DIR can be (2 4 6 8)
target_w, target_h : map size we want to be (bigger is OK)
x1, y1, z1, x2, y2, z2 : map coordinates for 3D bbox
-- grow phase only:
grow, shrink : map size to grow/shrink along current axis
}
class BORDER
{
kind : "solid" | "view" | "walk"
other : SEED -- seed we are connected to, or nil
rlink : RLINK
}
--------------------------------------------------------------]]
require 'defs'
require 'util'
SEED_SIZE = 256
function Seed_init(W, H, D, zone)
assert(zone)
SEED_W = W
SEED_H = H
SEED_D = D
SEEDS = array_2D(W, H)
for x = 1,W do for y = 1,H do
SEEDS[x][y] = {}
for z = 1,D do
SEEDS[x][y][z] = { sx=x, sy=y, sz=z, zone=zone }
end
end end -- x,y
end
function Seed_close()
SEEDS = nil
SEED_W = nil
SEED_H = nil
SEED_D = nil
end
function Seed_valid(x, y, z)
return (x >= 1 and x <= SEED_W) and
(y >= 1 and y <= SEED_H) and
(z >= 1 and z <= SEED_D)
end
function Seed_get_safe(x, y, z)
return Seed_valid(x, y, z) and SEEDS[x][y][z]
end
function Seed_is_free(x, y, z, zone)
assert(Seed_valid(x, y, z))
return not SEEDS[x][y][z].room
end
function Seed_valid_and_free(x, y, z)
if not Seed_valid(x, y, z) then
return false
end
if SEEDS[x][y][z].room then
return false
end
return true
end
function Seed_block_valid_and_free(x1,y1,z1, x2,y2,z2)
assert(x1 <= x2 and y1 <= y2 and z1 <= z2)
if not Seed_valid(x1, y1, z1) then return false end
if not Seed_valid(x2, y2, z2) then return false end
for x = x1,x2 do for y = y1,y2 do for z = z1,z2 do
local S = SEEDS[x][y][z]
if S.room then
return false
end
end end end -- x, y, z
return true
end
function Seed_dump_rooms()
gui.printf("Seed room map:\n")
local ROOM_IDX = 0
local HALL_IDX = 0
local ROOMS = "BFGHIDKLPTQJY"
local HALLS = "acmunorvsewxz"
local function seed_to_char(S)
if not S or not S.zone then return "!" end
if not S.room then
if S.zone.zone_kind == "walk" then return "/" end
if S.zone.zone_kind == "view" then return "%" end
if S.zone.parent then return "#" end
return "."
end
if not S.room.dump_char then
if S.room.kind == "hall" then
S.room.dump_char = string.sub(HALLS, 1+HALL_IDX, 1+HALL_IDX)
HALL_IDX = (HALL_IDX + 1) % string.len(HALLS)
else
S.room.dump_char = string.sub(ROOMS, 1+ROOM_IDX, 1+ROOM_IDX)
ROOM_IDX = (ROOM_IDX + 1) % string.len(ROOMS)
end
end
return S.room.dump_char
end
for y = SEED_H,1,-1 do
for x = 1,SEED_W do
gui.printf("%s", seed_to_char(SEEDS[x][y][1]))
end
gui.printf("\n")
end
gui.printf("\n")
end
function Seed_dump_fabs()
local function char_for_seed(S)
if not S or not S.kind then return "." end
if S.kind == "ground" then return "2" end
if S.kind == "valley" then return "1" end
if S.kind == "hill" then return "3" end
if S.kind == "indoor" then return "#" end
if S.kind == "hall" then return "+" end
if S.kind == "liquid" then return "~" end
return "?"
end
gui.printf("Room Fabs:\n")
for y = SEED_H,1,-1 do
for x = 1,SEED_W do
gui.printf("%s", char_for_seed(SEEDS[x][y][1].room))
end
gui.printf("\n")
end
gui.printf("\n")
end
--[[
require 'gd'
RENDER_NUM = 1
function debug_render()
local im = gd.createTrueColor(500, 300);
local black = im:colorAllocate(0, 0, 0);
local gray = im:colorAllocate(127, 127, 127);
local white = im:colorAllocate(255, 255, 255);
local red = im:colorAllocate(200, 0, 0);
local blue = im:colorAllocate(0, 0, 200);
local purple = im:colorAllocate(200, 0, 200);
local yellow = im:colorAllocate(200, 200, 0);
local green = im:colorAllocate(0, 200, 0);
im:filledRectangle(0, 0, 500, 300, black);
local function draw_seed(x, y, S)
local x1 = (S.x1 + 16) * 6
local y1 = (S.y1 + 16) * 6
local x2 = (S.x2 + 16) * 6 + 5
local y2 = (S.y2 + 16) * 6 + 5
y1,y2 = 300-y2, 300-y1
local aa = (S.x2 - S.x1 + 1) - S.min_W
local bb = (S.y2 - S.y1 + 1) - S.min_H
im:filledRectangle(x1,y1,x2,y2,
sel(aa < 0 or bb < 0, blue,
sel(aa > 4 or bb > 4, red,
sel(aa > 2 or bb > 2, yellow, green))))
-- sel(S.room.mass > 3, yellow,
-- sel(S.room.mass < 1, blue, red)))
for side=2,8,2 do
local dx,dy = dir_to_delta(side)
local N = get_seed_safe(x+dx,y-dy)
local ax,ay, bx,by = side_coords(side, x1,y1, x2,y2)
if (N and N.room == S.room) then
im:filledRectangle(ax,ay, bx,by, black)
else
im:filledRectangle(ax,ay, bx,by, white)
end
end
end
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
draw_seed(x, y, S)
end
end end
im:png(string.format("pics/%04d.png", RENDER_NUM))
print("WROTE PIC", RENDER_NUM)
print()
RENDER_NUM = RENDER_NUM + 1
im = nil ; collectgarbage("collect");
end
--]]
function Seed_grow()
-- FIXME: ULTRA BASIC VERSION OF SEED_GROW
for x = 1,SEED_W do for y = 1,SEED_H do for z = 1,SEED_D do
local S = SEEDS[x][y][z]
S.x1 = x * SEED_SIZE
S.y1 = y * SEED_SIZE
S.x2 = (x+1) * SEED_SIZE
S.y2 = (y+1) * SEED_SIZE
end end end --- x, y, z
return
end
function TODO_REAL_Seed_grow()
-- TODO: 2. implement symmetry preservation
local DIR
local CHANGED
local function get_width(S)
return S.x2 - S.x1 + 1
end
local function get_height(S)
return S.y2 - S.y1 + 1
end
local function same_room(S1, S2)
return S1.room == S2.room
end
local function seed_new_pos(S)
local x1,y1 = S.x1, S.y1
local x2,y2 = S.x2, S.y2
if S.grow then
if DIR==2 then y1 = y1-1
elseif DIR==8 then y2 = y2+1
elseif DIR==4 then x1 = x1-1
elseif DIR==6 then x2 = x2+1
end
end
if S.shrink then
if DIR==2 then y2 = y2-1
elseif DIR==8 then y1 = y1+1
elseif DIR==4 then x2 = x2-1
elseif DIR==6 then x1 = x1+1
end
end
return x1,y1, x2,y2
end
local function mark_grow(S)
if S.grow then return end
S.grow = true
CHANGED = true
end
local function mark_move(S)
if S.grow and S.shrink then return end
S.grow = true
S.shrink = true
CHANGED = true
end
local function mark_shrink(S)
if S.shrink then return end
S.shrink = true
CHANGED = true
-- once a seed reaches its minimum size, never make it smaller.
-- (It turns out that this check is very important).
if DIR==4 or DIR==6 then
if get_width(S) <= S.min_W then S.grow = true end
else
if get_height(S) <= S.min_H then S.grow = true end
end
end
local function check_for_overlap(S)
local x1,y1, x2,y2 = S.x1, S.y1, S.x2, S.y2
-- coordinates for just the "new growth"
if DIR == 6 then x2 = x2 + 1 ; x1 = x2
elseif DIR == 4 then x1 = x1 - 1 ; x2 = x1
elseif DIR == 8 then y2 = y2 + 1 ; y1 = y2
elseif DIR == 2 then y1 = y1 - 1 ; y2 = y1
end
-- FIXME: optimise, but how??
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local F = SEEDS[x][y]
if F and F ~= S then
if boxes_overlap(x1,y1, x2,y2, F.x1,F.y1, F.x2,F.y2) then
mark_shrink(F)
end
end
end end
end
local function link_cur_length(S, N)
if DIR==4 or DIR==6 then
return math.min(S.x2,N.x2) - math.max(S.x1,N.x1) + 1
else
return math.min(S.x2,N.x2) - math.max(S.x1,N.x1) + 1
end
end
local function link_new_length(S, N)
local sx1,sy1, sx2,sy2 = seed_new_pos(S)
local nx1,ny1, nx2,ny2 = seed_new_pos(N)
local low, high
if DIR==4 or DIR==6 then
return math.min(sx2,nx2) - math.max(sx1,nx1)
else
return math.min(sx2,nx2) - math.max(sx1,nx1)
end
end
local function check_side_link(S, N, L)
-- keep rooms in lock-step
if same_room(S, N) then
if S.grow ~= N.grow then
mark_grow(sel(S.grow, N, S))
end
if S.shrink ~= N.shrink then
mark_shrink(sel(S.shrink, N, S))
end
return
end
-- actually linked?
if not L then return end
--!!! -- both are stationary : nothing to do
--!!! if not (S.grow or N.grow or S.shrink or N.shrink) then return end
-- both are moving : nothing to do
if S.grow and N.grow and S.shrink and N.shrink then return end
-- for "low" and "high" WHERE values, we simply ensure that
-- the corresponding side is lock-stepped.
if (L.where == "low" and (DIR==6 or DIR==8)) or
(L.where == "high" and (DIR==4 or DIR==2))
then
if S.shrink ~= N.shrink then
mark_shrink(sel(S.shrink, N, S))
end
return
end
if (L.where == "high" and (DIR==6 or DIR==8)) or
(L.where == "low" and (DIR==4 or DIR==2))
then
if S.grow ~= N.grow then
mark_grow(sel(S.grow, N, S))
end
return
end
if L.where == "middle" then
if S.shrink and S.grow then mark_move(N) ; return end
if N.shrink and N.grow then mark_move(S) ; return end
-- both are growing : not much we can do
if S.grow and N.grow then return end
-- Put the non-growing one into S.
-- If neither are growing, then use the lightest one
if S.grow or (not N.grow and S.room.mass < N.room.mass) then S,N = N,S end
local s_add = sel(S.shrink or S.grow, 1, 0)
local n_add = sel(N.shrink or N.grow, 1, 0)
local diff
if DIR==4 or DIR==6 then
diff = (N.x1 + N.x2 + n_add) - (S.x1 + S.x2 + s_add)
else
diff = (N.y1 + N.y2 + n_add) - (S.y1 + S.y2 + s_add)
end
if DIR==4 or DIR==2 then diff = -diff end
if diff >= 2 then
mark_grow(S)
end
return
end
error("Link contains bad WHERE mode.")
--[[
---> "lazy" mode : only grow when necessary
-- neither seeds are shrinking : nothing to do
if not S.shrink and not N.shrink then return end
-- both are growing : not much we can do
if S.grow and N.grow then return end
local long = link_new_length(S, N)
if long < L.long then
-- Put the non-growing one into S.
-- If neither are growing, then use the lightest one
if S.grow or (not N.grow and S.room.mass < N.room.mass) then S,N = N,S end
mark_grow(S)
end
--]]
end
local function check_back_link(S, B, L)
-- actually linked?
if not L and not same_room(S, B) then return end
if S.shrink then mark_grow(B) end
-- the "B.grow" case already handled (in check_for_overlap)
end
local function maintain_links()
local dx,dy = dir_to_delta(DIR)
local side = sel(DIR==4 or DIR==6, 8, 6)
local sdx, sdy = dir_to_delta(side)
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
-- forwards
if S.grow then
check_for_overlap(S)
end
-- sideways
local N = get_seed_safe(x+sdx, y+sdy)
if N then
local L = S.link[side]
check_side_link(S, N, L)
end
-- backwards
local B = get_seed_safe(x-dx, y-dy)
if B then
check_back_link(S, B, S.link[10-DIR])
end
end
end end
end
local function maintain_symmetry()
--!!! FIXME maintain_symmetry
-- FIXME: support "symmetric" links (L.twin ??)
end
local function do_grow(S)
if DIR==2 then S.y1 = S.y1-1
elseif DIR==8 then S.y2 = S.y2+1
elseif DIR==4 then S.x1 = S.x1-1
elseif DIR==6 then S.x2 = S.x2+1
end
S.grow = nil
end
local function do_shrink(S)
if DIR==2 then S.y2 = S.y2-1
elseif DIR==8 then S.y1 = S.y1+1
elseif DIR==4 then S.x2 = S.x2-1
elseif DIR==6 then S.x1 = S.x1+1
end
S.shrink = nil
end
local GROW_CHANCE = { 25, 37, 50, 75, 99 }
local SHRINK_CHANCE = { 5, 10, 15, 25, 50 }
local function select_growers()
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
local w = get_width(S)
local h = get_height(S)
local diff = S.min_W - w
local other = S.min_H - h
if (DIR==2 or DIR==8) then diff,other = other,diff end
if sel(DIR==4 or DIR==6, S.min_W, S.min_H) < 3 then
mark_grow(S)
elseif diff > 0 and rand_odds(GROW_CHANCE[math.min(diff,5)]) then
mark_grow(S)
elseif diff < 0 and rand_odds(SHRINK_CHANCE[math.min(-diff,5)]) then
mark_shrink(S)
end
---# if force then
---# mark_grow(S)
---# elseif diff > 0 then
---# local chance = 33
---# if diff >= 2 then chance = 66 end
---# if diff >= 4 then chance = 99 end
---#
---# if true then --!!! rand_odds(chance) then
---# mark_grow(S)
---# end
---# end
end
end end
end
local function perform_pass(cur_dir)
DIR = cur_dir
--print("perform_pass: DIR=", DIR)
select_growers()
repeat
CHANGED = false
maintain_links()
maintain_symmetry()
until not CHANGED
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S and S.grow then do_grow(S) end
if S and S.shrink then do_shrink(S) end
end end
end
local function initialise_seeds()
-- initialize all seeds, aligned to a 3x3 grid
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
S.sx, S.sy = x, y
S.x1, S.y1 = x*3+0, y*3+0
S.x2, S.y2 = x*3+2, y*3+2
--- S.grow = { [2]=0, [4]=0, [6]=0, [8]=0 }
--- S.shrink = { [2]=0, [4]=0, [6]=0, [8]=0 }
end
end end
end
local function is_finished()
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
if get_width (S) < S.min_W then return false end
if get_height(S) < S.min_H then return false end
end
end end
return true
end
local function adjust_coordinates()
-- make sure seeds have valid block ranges
-- (in particular: negative coords are not allowed).
local min_x = 999
local min_y = 999
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
S.w = get_width(S)
S.h = get_height(S)
min_x = math.min(min_x, S.x1)
min_y = math.min(min_y, S.y1)
-- sanity checking
assert(S.w >= S.min_W)
assert(S.h >= S.min_H)
local N = SEEDS[x+1] and SEEDS[x+1][y]
--!!! if N then assert(S.x2 < N.x1) end
N = SEEDS[x][y+1]
--!!! if N then assert(S.y2 < N.y1) end
end
end end
min_x = min_x-1
min_y = min_y-1
for x = 1,SEEDS.w do for y = 1,SEEDS.h do
local S = SEEDS[x][y]
if S then
S.x1 = S.x1 - min_x
S.y1 = S.y1 - min_y
S.x2 = S.x2 - min_x
S.y2 = S.y2 - min_y
end
end end
end
----===| grow_seeds |===----
initialise_seeds()
-- perform growth passes until every seed is full-sized
local SIDES = { 2,4,6,8 }
repeat
--debug_render()
rand_shuffle(SIDES)
for zzz,side in ipairs(SIDES) do
perform_pass(side)
end
until is_finished()
--debug_render()
adjust_coordinates();
end -- grow_seeds
function test_grow_all()
print("test_grow_all...")
SEEDS = array_2D(16,12)
local function add_room(room, sx, sy, sw, sh)
sw = sw or 1
sh = sh or 1
for x = sx,sx+sw-1,1 do
for y = sy,sy+sh-1,1 do
assert(not SEEDS[x][y])
SEEDS[x][y] = { sx=x, sy=y, room=room,
min_W=room.size, min_H=room.size,
link={}
}
end
end
end
local function add_link(sx, sy, ex, ey, long, where)
long = long or 3
where = where or "lax"
local dir = delta_to_dir(ex-sx, ey-sy)
assert(dir==2 or dir==4 or dir==6 or dir==8)
local S = SEEDS[sx][sy] ; assert(S)
local N = SEEDS[ex][ey] ; assert(N)
local L = { where=where, long=long }
S.link[dir] = L
N.link[10-dir] = L
L.seeds = { S, N }
end
-- rooms
local r1 = { mass=6.5, size=4 }
local r2 = { mass=4.3, size=9 }
local r3 = { mass=2.8, size=11 }
local r4 = { mass=1.3, size=6 }
local r5 = { mass=1.3, size=10 }
local r6 = { mass=1.2, size=8 }
local r7 = { mass=1.9, size=6 }
local r8 = { mass=1.5, size=9 }
add_room(r1, 4,3, 2,3)
add_room(r2, 1,3, 2,2)
add_room(r3, 3,4)
add_room(r4, 1,5)
add_room(r5, 2,2)
add_room(r6, 5,1)
add_room(r7, 6,1)
add_room(r8, 7,6)
-- halls
local h1 = { mass=0.5, size=3, max=4 }
local h1x = { mass=0.1, size=3 }
local h2 = { mass=0.5, size=3, max=4 }
local h2x = { mass=0.1, size=3 }
local h3 = { mass=0.5, size=3 }
local h4 = { mass=0.5, size=5 }
local h5 = { mass=0.5, size=3 }
local h6 = { mass=0.5, size=3 }
add_room(h1, 3,5, 1,2)
add_room(h1x, 4,6)
add_room(h2, 3,2, 1,2)
add_room(h2x, 4,2)
add_room(h3, 1,2)
add_room(h4, 2,1, 3,1)
add_room(h5, 6,5, 1,2)
add_room(h6, 6,2, 1,2)
-- linkage
add_link(3,4, 4,4, 5, "middle")
add_link(4,5, 4,6, nil, "high")
add_link(4,3, 4,2, nil, "high")
add_link(5,5, 6,5, 2)
add_link(5,3, 6,3, 2)
add_link(1,4, 1,5)
add_link(1,3, 1,2)
add_link(2,4, 3,4)
add_link(2,2, 2,3, 6)
add_link(3,6, 4,6, nil, "high")
add_link(3,2, 4,2, nil, "low")
add_link(3,4, 3,5, nil, "middle")
add_link(3,4, 3,3, nil, "middle")
add_link(2,2, 1,2)
add_link(2,2, 2,1)
add_link(5,1, 4,1, nil)
add_link(5,1, 6,1)
add_link(6,1, 6,2)
add_link(7,6, 6,6)
grow_seeds()
end
------------------------------------------------------------------------
MIN_Z = -2048
MAX_Z = 2048
PAD = 0
function get_seed_wall(S, side)
if side == 4 then
return
{
{ x = S.x1-PAD, y = S.y1-PAD },
{ x = S.x1-PAD, y = S.y2+PAD },
{ x = S.x1+16, y = S.y2+PAD },
{ x = S.x1+16, y = S.y1-PAD },
}
end
if side == 6 then
return
{
{ x = S.x2+PAD, y = S.y2+PAD },
{ x = S.x2+PAD, y = S.y1-PAD },
{ x = S.x2-16, y = S.y1-PAD },
{ x = S.x2-16, y = S.y2+PAD },
}
end
if side == 2 then
return
{
{ x = S.x2+PAD, y = S.y1 },
{ x = S.x1-PAD, y = S.y1 },
{ x = S.x1-PAD, y = S.y1+16 },
{ x = S.x2+PAD, y = S.y1+16 },
}
end
if side == 8 then
return
{
{ x = S.x1-PAD, y = S.y2+PAD },
{ x = S.x2+PAD, y = S.y2+PAD },
{ x = S.x2+PAD, y = S.y2-16 },
{ x = S.x1-PAD, y = S.y2-16 },
}
end
error("BAD SIDE for get_seed_wall: " .. tostring(side))
end
function render_seed(S)
if S.kind == "solid" then return end
local tex = "rock1_2" -- "STARTAN3"
if S.z1 > 100 then tex = "tech01_1" end
if S.z1 > 200 then tex = "ground1_1" end
-- floor
if S.kind == "walkway" then
gui.add_brush(
{
t_face = { texture=tex },
b_face = { texture=tex },
w_face = { texture=tex },
},
{
{ x = S.x1, y = S.y1 },
{ x = S.x1, y = S.y2 },
{ x = S.x2, y = S.y2 },
{ x = S.x2, y = S.y1 },
},
S.z1-PAD, S.z1+16)
end
-- ceiling
if not S.link[9] or
(S.link[9].src == S and S.link[9].dest.kind == "solid") or
(S.link[9].dest == S and S.link[9].src.kind == "solid")
then
gui.add_brush(
{
t_face = { texture=tex },
b_face = { texture=tex },
w_face = { texture=tex },
},
{
{ x = S.x1, y = S.y1 },
{ x = S.x1, y = S.y2 },
{ x = S.x2, y = S.y2 },
{ x = S.x2, y = S.y1 },
},
S.z2-16, S.z2+PAD)
end
-- walls
for side = 2,8,2 do
local L = S.link[side]
local other
if L then other = assert(sel(S == L.src, L.dest, L.src)) end
if not L or other.kind == "solid" then