-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex_dm.lua
3200 lines (2153 loc) · 58.3 KB
/
hex_dm.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
------------------------------------------------------------------------
-- HEXAGONAL DEATH-MATCH / CTF
------------------------------------------------------------------------
--
-- Oblige Level Maker
--
-- Copyright (C) 2013-2014 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 HEXAGON
{
cx, cy -- position in cell map
kind : keyword -- "free", "used"
-- "edge", "solid", "dead"
neighbor[HDIR] : HEXAGON -- neighboring cells
-- will be NIL at edge of map
-- HDIR is 1 .. 6
content : CONTENT -- what to make in middle of cell
border[HDIR] : BORDER -- what to make on edge of cell
corner[HDIR] : BORDER -- these corners are ON THE OUTSIDE
mid_x, mid_y -- coordinate of mid point
vertex[HDIR] : { x=#, y=# } -- leftmost vertex for each edge
wall_vert[HDIR] : { x=#, y=# }
mid_vert[HDIR] : { x=#, y=# }
path[HDIR] : HEXAGON -- forms a cyclical pathway around the map
peer : HEXAGON -- in CTF mode, this is the cell on opposite
-- side of the map
thread : THREAD
is_branch -- true if a thread branched off here
dist[keyword] -- distance to various stuff (e.g. "wall")
}
class THREAD
{
id : number
start : HEXAGON -- starting place (in an existing "used" cell)
pos : HEXAGON -- last cell 'converted' to this thread
dir : HDIR -- current direction
cells : array(HEXAGON) -- all cells in this thread
history : array(HDIR) -- directions to follow from start cell
grow_prob : number
limit : number -- when this reached zero, make a room
}
class ROOM
{
id : number -- normally > 0, negative for a mirrored room
cells : list(HEXAGON)
peer : ROOM -- opposite room when level is mirrored (CTF)
flag_room : boolean
base : keyword -- "red" or "blue" if part of a team's base
-- unset for the neutral zone
kind : keyword -- "building", "cave", "outdoors"
is_outdoor : boolean -- true for outdoor room
wall_mat : string -- texturing for this room
floor_mat : string --
ceil_mat : string --
floor_h : number -- floor height
walk_neighbors : list(ROOM)
}
class BORDER
{
kind : keyword -- "wall", "fence", "step"
wall_mat : string --
floor_mat : string -- texturing info
ceil_mat : string --
floor_h : number -- height for the fence or step
ceil_h : number
}
class CONTENT
{
kind : keyword -- "START", "WEAPON", "ENTITY", etc...
entity : name
team : keyword -- "red" or "blue" (for FLAG and START)
-- not used for DM maps
no_mirror : boolean -- do not mirror this
}
Directions:
_______
/ 5 \
/4 6\
/ \
\ /
\1 3/
\___2___/
----------------------------------------------------------------]]
-- two dimensional grid / map
--
-- rows with an _even_ Y value are offset to the right:
--
-- 1 2 3 4
-- 1 2 3 4
-- 1 2 3 4
-- 1 2 3 4
HEX_CELLS = {}
-- these must be odd (for CTF mode)
HEX_W = 15
HEX_H = 49
HEX_MID_X = 0 -- computed later
HEX_MID_Y = 0 --
HEX_LEFT = { 2, 3, 6, 1, 4, 5 }
HEX_RIGHT = { 4, 1, 2, 5, 6, 3 }
HEX_OPP = { 6, 5, 4, 3, 2, 1 }
HEX_DIRS = { 1, 4, 5, 6, 3, 2 }
HEXAGON_CLASS = {}
function HEXAGON_CLASS.new(cx, cy)
local C =
{
cx = cx
cy = cy
kind = "free"
neighbor = {}
vertex = {}
wall_vert = {}
mid_vert = {}
border = {}
corner = {}
path = {}
dist = {}
random1 = gui.random()
random2 = gui.random()
}
table.set_class(C, HEXAGON_CLASS)
return C
end
function HEXAGON_CLASS.tostr(C)
return string.format("CELL[%d,%d]", C.cx, C.cy)
end
function HEXAGON_CLASS.is_active(C)
if not C.thread then return false end
return not C.thread.dead
end
function HEXAGON_CLASS.free_neighbors(C)
local count = 0
for dir = 1,6 do
local N = C.neighbor[dir]
if N and N.kind == "free" then
count = count + 1
end
end
return count
end
function HEXAGON_CLASS.is_leaf(C)
local count = 0
for dir = 1, 6 do
local N = C.neighbor[dir]
if C.path[dir] then count = count + 1 end
end
if LEVEL.CTF and C.cy == HEX_MID_Y then
return (count == 0)
end
return (count <= 1)
end
function HEXAGON_CLASS.trim(C)
C.kind = "free"
C.content = nil
C.trimmed = true
-- we keep C.thread
-- handle path links
for dir = 1, 6 do
local N = C.path[dir]
if N then
N.path[HEX_OPP[dir]] = nil
end
end
C.path = {}
end
function HEXAGON_CLASS.can_join(C, T)
local hit_dir
for dir = 1, 6 do
local N = C.neighbor[dir]
-- a thread cannot join onto itself
if N.kind == "used" and N.thread != T then
hit_dir = dir
end
end
return hit_dir
end
function HEXAGON_CLASS.used_dist_from_neighbors(C)
local dist
for i = 1, 6 do
local N = C.neighbor[i]
if N and N.dist.used and (N.dist.used < (dist or 999)) then
dist = N.dist.used
end
end
return dist
end
function HEXAGON_CLASS.touches_edge(C)
for dir = 1, 6 do
local N = C.neighbor[dir]
if not N or N.kind == "edge" then
return true
end
end
return false
end
function HEXAGON_CLASS.can_travel_in_dir(C, dir)
local N = C.neighbor[dir]
if not (N and N.room) then return false end
if C.path[dir] then return true end
if N.room != C.room then return false end
return true
end
function HEXAGON_CLASS.near_wall(C)
for dir = 1, 6 do
if not C:can_travel_in_dir(dir) then
return true
end
end
return false
end
function HEXAGON_CLASS.get_brush(C)
local brush = {}
for i = 6, 1, -1 do
local dir = HEX_DIRS[i]
local coord =
{
x = C.vertex[dir].x
y = C.vertex[dir].y
}
table.insert(brush, coord)
end
return brush
end
function HEXAGON_CLASS.get_small_brush(C)
local brush = {}
for i = 6, 1, -1 do
local dir = HEX_DIRS[i]
local coord =
{
x = C.mid_vert[dir].x
y = C.mid_vert[dir].y
}
table.insert(brush, coord)
end
return brush
end
function HEXAGON_CLASS.get_wall_brush(C, dir)
local dir2 = HEX_RIGHT[dir]
local brush = {}
table.insert(brush, table.copy(C.wall_vert[dir]))
table.insert(brush, table.copy(C.wall_vert[dir2]))
table.insert(brush, table.copy(C.vertex[dir2]))
table.insert(brush, table.copy(C.vertex[dir]))
return brush
end
function HEXAGON_CLASS.get_corner_brush(C, dir)
local dir2 = HEX_LEFT[dir]
local A = C.neighbor[dir2]
local B = C.neighbor[dir]
if not A or not B then
error("get_corner_brush: bad cell")
end
local dir3 = HEX_LEFT [HEX_LEFT [dir]]
local dir4 = HEX_RIGHT[HEX_RIGHT[dir]]
local brush = {}
table.insert(brush, table.copy(C.vertex[dir]))
table.insert(brush, table.copy(B.wall_vert[dir3]))
table.insert(brush, table.copy(A.wall_vert[dir4]))
return brush
end
function HEXAGON_CLASS.build_floor(C, f_h, mat)
-- for lighting system we subdivide the cell into a small hexagon
-- and six trapezoids...
local m_brush = C:get_small_brush(C)
brushlib.add_top(m_brush, f_h)
brushlib.set_mat(m_brush, mat, mat)
Trans.brush(m_brush)
for i = 1, 6 do
local k = HEX_LEFT[i]
local brush =
{
table.copy(C.mid_vert[i])
table.copy(C.vertex [i])
table.copy(C.vertex [k])
table.copy(C.mid_vert[k])
}
brushlib.add_top(brush, f_h)
brushlib.set_mat(brush, mat, mat)
Trans.brush(brush)
end
end
function HEXAGON_CLASS.build_border(C, coords, B)
if B.kind == "nothing" then
return
end
if B.kind == "wall" then
brushlib.set_mat(coords, B.wall_mat, B.wall_mat)
Trans.brush(coords)
end
if B.kind == "fence" or B.kind == "step" then
assert(B.floor_h)
brushlib.add_top(coords, B.floor_h)
brushlib.set_mat(coords, B.floor_mat, B.floor_mat)
Trans.brush(coords)
end
end
function HEXAGON_CLASS.build_wall(C, dir)
local B = C.border[dir]
if not B then return end
local brush = C:get_wall_brush(dir)
C:build_border(brush, B)
end
function HEXAGON_CLASS.build_corner(C, dir)
local B = C.corner[dir]
if not B then return end
local brush = C:get_corner_brush(dir)
C:build_border(brush, B)
end
function HEXAGON_CLASS.debug_path(C, dir)
if not C.path[dir] then return end
local dir2 = HEX_RIGHT[dir]
local x = (C.vertex[dir].x + C.vertex[dir2].x) * 0.35 + C.mid_x * 0.3
local y = (C.vertex[dir].y + C.vertex[dir2].y) * 0.35 + C.mid_y * 0.3
Trans.entity("lamp", x, y, 0)
end
function HEXAGON_CLASS.build_content(C)
local content = C.content
local f_h = C.room.floor_h or 0
if content.kind == "START" then
local ent = "dm_player"
if content.team then
ent = "ctf_" .. content.team .. "_start"
end
Trans.entity(ent, C.mid_x, C.mid_y, f_h, { angle=content.angle })
end
if content.kind == "FLAG" then
assert(content.team)
-- simple pedestal
local brush = C:get_small_brush()
brushlib.add_top(brush, f_h + 12)
brushlib.set_mat(brush, "COMPSPAN", "COMPSPAN")
Trans.brush(brush)
local ent = "ctf_" .. content.team .. "_flag"
Trans.entity(ent, C.mid_x, C.mid_y, f_h + 12, { light=224 })
end
if content.kind == "ENTITY" or
content.kind == "WEAPON"
then
-- FIXME: prefab for weapons
Trans.entity(content.entity, C.mid_x, C.mid_y, f_h, { angle=content.angle, light=160 })
end
end
function HEXAGON_CLASS.build(C)
for dir = 1, 6 do
C:build_corner(dir)
end
if C.kind == "edge" or C.kind == "solid" or C.kind == "dead" then
local w_brush = C:get_brush()
local w_mat = "ASHWALL4"
brushlib.set_mat(w_brush, w_mat, w_mat)
Trans.brush(w_brush)
return
end
local R = assert(C.room)
-- floor --
local f_h = C.room.floor_h
assert(f_h)
C:build_floor(f_h, R.floor_mat)
-- ceiling --
local c_h = f_h + 160
if R.is_outdoor then
c_h = LEVEL.sky_h
end
local c_brush = C:get_brush()
brushlib.add_bottom(c_brush, c_h)
if R.is_outdoor then
brushlib.mark_sky(c_brush)
else
brushlib.set_mat(c_brush, R.wall_mat, R.ceil_mat)
end
Trans.brush(c_brush)
-- walls --
for dir = 1, 6 do
C:build_wall(dir)
end
-- content --
if C.content then
C:build_content(C)
end
end
----------------------------------------------------------------
HEX_ROOM_CLASS = {}
function HEX_ROOM_CLASS.new()
local R =
{
id = Plan_alloc_id("hex_room")
cells = {}
}
table.set_class(R, HEX_ROOM_CLASS)
return R
end
function HEX_ROOM_CLASS.copy(R)
-- does not copy 'id' or the 'cells' list
local R2 = HEX_ROOM_CLASS.new()
R2.floor_h = R.floor_h
R2.flag_room = R.flag_room
return R2
end
function HEX_ROOM_CLASS.tostr(R)
assert(R.id)
if R.id < 0 then
return string.format("MIRROR_%d", 0 - R.id)
else
return string.format("ROOM_%d", R.id)
end
end
function HEX_ROOM_CLASS.add_cell(R, C)
C.room = R
table.insert(R.cells, C)
end
function HEX_ROOM_CLASS.kill(R)
each C in R.cells do
C.kind = "dead"
C.room = nil
end
R.dead = true
R.cells = {}
end
function HEX_ROOM_CLASS.merge(R, old)
assert(not R.dead)
each C in old.cells do
R:add_cell(C)
end
old.dead = true
old.cells = {}
end
function HEX_ROOM_CLASS.calc_bbox(R)
each C in R.cells do
R.min_cx = math.min(R.min_cx or 999, C.cx)
R.min_cy = math.min(R.min_cy or 999, C.cy)
R.max_cx = math.max(R.max_cx or 0, C.cx)
R.max_cy = math.max(R.max_cy or 0, C.cy)
end
end
function HEX_ROOM_CLASS.dump_cells(R)
stderrf("Cells for %s :\n", R:tostr())
stderrf("{\n")
each C in R.cells do
stderrf(" %s\n", C:tostr())
end
stderrf("}\n")
end
function HEX_ROOM_CLASS.dump_bbox(R)
if R.min_cx then
stderrf("bbox for %s : NONE!\n", R:tostr())
else
stderrf("bbox for %s : (%d %d) .. (%d %d)\n",
R:tostr(), R.min_cx, R.min_cy, R.max_cx, R.max_cy)
end
end
function HEX_ROOM_CLASS.find_walk_neighbors(R)
R.walk_neighbors = {}
each C in R.cells do
for dir = 1, 6 do
local N = C.path[dir]
if N and N.room != R then
table.add_unique(R.walk_neighbors, N.room)
end
end
end
assert(not table.empty(R.walk_neighbors))
end
----------------------------------------------------------------
H_WIDTH = 80 + 40
H_HEIGHT = 64 + 32
function Hex_middle_coord(cx, cy)
local x = H_WIDTH * (1 + (cx - 1) * 3 + (1 - (cy % 2)) * 1.5)
local y = H_HEIGHT * cy
return math.round(x), math.round(y)
end
function Hex_neighbor_pos(cx, cy, dir)
if dir == 2 then return cx, cy - 2 end
if dir == 5 then return cx, cy + 2 end
if (cy % 2) == 0 then
if dir == 1 then return cx, cy - 1 end
if dir == 4 then return cx, cy + 1 end
if dir == 3 then return cx + 1, cy - 1 end
if dir == 6 then return cx + 1, cy + 1 end
else
if dir == 1 then return cx - 1, cy - 1 end
if dir == 4 then return cx - 1, cy + 1 end
if dir == 3 then return cx, cy - 1 end
if dir == 6 then return cx, cy + 1 end
end
end
function Hex_vertex_coord(C, dir)
local x, y
if dir == 1 then
x = C.mid_x - H_WIDTH / 2
y = C.mid_y - H_HEIGHT
elseif dir == 2 then
x = C.mid_x + H_WIDTH / 2
y = C.mid_y - H_HEIGHT
elseif dir == 3 then
x = C.mid_x + H_WIDTH
y = C.mid_y
elseif dir == 4 then
x = C.mid_x - H_WIDTH
y = C.mid_y
elseif dir == 5 then
x = C.mid_x - H_WIDTH / 2
y = C.mid_y + H_HEIGHT
elseif dir == 6 then
x = C.mid_x + H_WIDTH / 2
y = C.mid_y + H_HEIGHT
end
return
{
x = math.round(x)
y = math.round(y)
}
end
function Hex_vertex_along(C, dir, along)
local x = C.vertex[dir].x
local y = C.vertex[dir].y
return
{
x = math.round(x * along + C.mid_x * (1 - along))
y = math.round(y * along + C.mid_y * (1 - along))
}
end
function Hex_setup()
HEX_CELLS = table.array_2D(HEX_W, HEX_H)
HEX_MID_X = int((HEX_W + 1) / 2)
HEX_MID_Y = int((HEX_H + 1) / 2)
-- 1. create the hexagon cells
for cx = 1, HEX_W do
for cy = 1, HEX_H do
local C = HEXAGON_CLASS.new(cx, cy)
C.mid_x, C.mid_y = Hex_middle_coord(cx, cy)
HEX_CELLS[cx][cy] = C
end
end
-- 2. setup neighbor links
for cx = 1, HEX_W do
for cy = 1, HEX_H do
local C = HEX_CELLS[cx][cy]
local far_W = HEX_W - sel(LEVEL.CTF, (cy % 2), 0)
for dir = 1,6 do
local nx, ny = Hex_neighbor_pos(cx, cy, dir)
if (nx >= 1) and (nx <= far_W) and
(ny >= 1) and (ny <= HEX_H)
then
C.neighbor[dir] = HEX_CELLS[nx][ny]
else
C.kind = "edge"
end
end
end
end
-- 3. setup vertices
for cx = 1, HEX_W do
for cy = 1, HEX_H do
local C = HEX_CELLS[cx][cy]
for dir = 1,6 do
C.vertex[dir] = Hex_vertex_coord(C, dir)
C.wall_vert[dir] = Hex_vertex_along(C, dir, 0.75)
C. mid_vert[dir] = Hex_vertex_along(C, dir, 0.50)
end
end
end
-- 4. reset other stuff
LEVEL.areas = {}
LEVEL.rooms = {}
LEVEL.scenic_rooms = {}
collectgarbage()
end
function Hex_starting_area()
LEVEL.start_cx = HEX_MID_X
LEVEL.start_cy = HEX_MID_Y
local C = HEX_CELLS[LEVEL.start_cx][LEVEL.start_cy]
C.kind = "used"
if LEVEL.CTF then
local cx1 = HEX_MID_X - int(HEX_W / 4)
local cx2 = HEX_MID_X + int(HEX_W / 4)
if rand.odds(80) then
-- sometimes remove middle
if rand.odds(30) then
C.kind = "free"
end
local C1, C2
C1 = HEX_CELLS[cx1][HEX_MID_Y]
C1.kind = "used"
C2 = HEX_CELLS[cx2][HEX_MID_Y]
C2.kind = "used"
C1.peer = C2
C2.peer = C1
end
end
end
function Hex_make_cycles()
local threads = {}
local MAX_THREAD = 30
local total_thread = 0
local function pick_dir(C)
local dir_list = {}
for dir = 1, 6 do
local N = C.neighbor[dir]
if LEVEL.CTF and dir >= 4 then continue end
if N and N.kind == "free" and N:free_neighbors() == 5 then
table.insert(dir_list, dir)
end
end
if #dir_list == 0 then
return nil
end
return rand.pick(dir_list)
end
local function pick_start()
local list = {}
-- collect all possible starting cells
for cx = 1, HEX_W do
for cy = 1, sel(LEVEL.CTF, HEX_MID_Y, HEX_H) do
local C = HEX_CELLS[cx][cy]
if C.no_start then continue end
if not (C.kind == "used" and not C:is_active()) then
continue
end
if C:free_neighbors() < 3 then continue end
table.insert(list, C)
end
end
while #list > 0 do
local idx = rand.irange(1, #list)
local C = table.remove(list, idx)
local dir = pick_dir(C)
if dir then
return C, dir -- success
end
-- never try this cell again
C.no_start = true
end
return nil -- fail
end
local function do_grow_thread(T, dir, N)
N.kind = "used"
N.thread = T
-- update 'path' links
local B = assert(T.pos)
B.path[dir] = N
N.path[HEX_OPP[dir]] = B
-- update the thread itself
T.pos = N
T.dir = dir
table.insert(T.cells, N)
table.insert(T.history, dir)
end
local function new_thread(start)
return
{
id = Plan_alloc_id("hex_thread")
start = start
cells = { }
history = { }
grow_dirs = rand.sel(50, { 2,3,4 }, { 4,3,2 })
grow_prob = rand.pick({ 40, 60, 80 })
limit = rand.irange(16, 48)
}
end
local function add_thread()
-- reached thread limit ?
if total_thread >= MAX_THREAD then return end