forked from obsidian-level-maker/Obsidian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefab.lua
More file actions
3112 lines (2270 loc) · 76.7 KB
/
Copy pathprefab.lua
File metadata and controls
3112 lines (2270 loc) · 76.7 KB
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
------------------------------------------------------------------------
-- WAD PREFAB SYSTEM
------------------------------------------------------------------------
--
-- // Obsidian //
--
-- Copyright (C) 2013-2017 Andrew Apted
-- Copyright (C) 2019-2022 MsrSgtShooterPerson
--
-- 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.
--
------------------------------------------------------------------------
local bit = require("bit")
WADFAB_ENTITIES =
{
-- monster spots
[8102] = { kind="monster", r= 20 },
[8103] = { kind="monster", r= 32 },
[8104] = { kind="monster", r= 48 },
[8106] = { kind="monster", r= 64 },
[8108] = { kind="monster", r=128 },
[8112] = { kind="flyer", r= 20 },
[8113] = { kind="flyer", r= 32 },
[8114] = { kind="flyer", r= 48 },
[8116] = { kind="flyer", r= 64 },
[8118] = { kind="flyer", r=128 },
[8122] = { kind="cage", r= 20 },
[8123] = { kind="cage", r= 32 },
[8124] = { kind="cage", r= 48 },
[8126] = { kind="cage", r= 64 },
[8128] = { kind="cage", r=128 },
[8132] = { kind="trap", r= 20 },
[8133] = { kind="trap", r= 32 },
[8134] = { kind="trap", r= 48 },
[8136] = { kind="trap", r= 64 },
[8138] = { kind="trap", r=128 },
-- special spots
[8151] = { kind="pickup", r=16 },
[8152] = { kind="big_item", r=16 },
[8160] = { kind="important", r=64 },
-- lighting
[8181] = { kind="light" },
-- souuuuund
[8185] = { kind="sound" },
-- miscellaneous
[8199] = { kind="secret" }
}
WADFAB_ENTITIES_HEXEN =
{
-- monster spots
[8105] = { kind="monster", r= 20 },
[8106] = { kind="monster", r= 32 },
[8107] = { kind="monster", r= 48 },
[8108] = { kind="monster", r= 64 },
[8109] = { kind="monster", r=128 },
[8112] = { kind="flyer", r= 20 },
[8113] = { kind="flyer", r= 32 },
[8114] = { kind="flyer", r= 48 },
[8116] = { kind="flyer", r= 64 },
[8118] = { kind="flyer", r=128 },
[8122] = { kind="cage", r= 20 },
[8123] = { kind="cage", r= 32 },
[8124] = { kind="cage", r= 48 },
[8126] = { kind="cage", r= 64 },
[8128] = { kind="cage", r=128 },
[8132] = { kind="trap", r= 20 },
[8133] = { kind="trap", r= 32 },
[8134] = { kind="trap", r= 48 },
[8136] = { kind="trap", r= 64 },
[8138] = { kind="trap", r=128 },
-- special spots
[8151] = { kind="pickup", r=16 },
[8152] = { kind="big_item", r=16 },
[8160] = { kind="important", r=64 },
-- lighting
[8181] = { kind="light" },
-- souuuuund
[8185] = { kind="sound" },
-- miscellaneous
[8199] = { kind="secret" }
}
WADFAB_FX_DELTAS =
{
[1] = 48, -- random off
[2] = 48, -- blink fast
[12] = 48, -- blink fast, sync
[3] = 48, -- blink slow
[13] = 48, -- blink slow, sync
[17] = 48, -- flickers
[8] = 128 -- oscillates
}
WADFAB_REACHABLE = 992
WADFAB_MOVER = 995
WADFAB_DOOR = 996
WADFAB_DELTA_12 = 997
WADFAB_LIGHT_BRUSH = 987
function load_from_subdir(top_level, sub, extension)
-- ignore the attic (it contains a lot of broken stuff)
if sub == "_attic" then return end
local dir = top_level .. "/" .. sub
local list, err = gui.scan_directory(dir, extension)
if list == nil then
gui.printf("Failed to scan prefab directory '%s'\n", sub)
return
end
gui.set_import_dir(dir)
for _,filename in pairs(list) do
gui.debugf("Loading %s/%s\n", sub, filename)
gui.import(filename)
end
gui.set_import_dir("")
end
function visit_dir(top_level, extension)
gui.printf("Loading prefabs from: '%s'\n", top_level)
local subdirs, err = gui.scan_directory(top_level, "DIRS")
if not subdirs then
gui.printf("Failed to scan folder: %s\n", tostring(err))
return
end
for _,sub in pairs(subdirs) do
load_from_subdir(top_level, sub, extension)
end
-- give each loaded definition a 'dir_name' field.
-- [ we assume previous defs also got it, hence this will only set
-- the dir_name in the definitions just loaded ]
for name,def in pairs(PREFABS) do
if not def.dir_name then
def.dir_name = top_level
end
end
gui.printf("OK\n")
end
function Fab_load_all_definitions()
local function kind_from_filename(filename)
assert(filename)
local kind = string.match(filename, "([%w_]+)/")
if not kind then
error("weird prefab filename: " .. tostring(filename))
end
return kind
end
local function random_factor(def)
if not def.prob_skew then return 1 end
local prob_skew = def.prob_skew
local half_skew = (1.0 + prob_skew) / 2.0
return rand.pick({ 1 / prob_skew, 1 / half_skew, 1.0, half_skew, prob_skew })
end
local function calc_prob(def)
if def.skip_prob then
if rand.odds(def.skip_prob) then return 0 end
end
-- check against current game, engine, theme (etc...)
if not ob_match_game(def) then return 0 end
if not ob_match_port(def) then return 0 end
-- normal logic --
local prob = def.prob or 0
prob = prob * random_factor(def)
return prob
end
local function process_resource_pack_fabs()
if PARAM.obsidian_resource_pack_active then
for _,def in pairs(PREFABS) do
if def.replaces then
PREFABS[def.replaces].delete = true
end
end
for _,def in pairs(PREFABS) do
if def.template and PREFABS[def.template].delete then
def.delete = true
end
end
else
for _,def in pairs(PREFABS) do
if def.texture_pack == "armaetus" then
def.delete = true
end
end
end
for _,def in pairs(PREFABS) do
if def.delete then PREFABS[def.name] = nil end
end
end
local function preprocess_all()
table.name_up(PREFABS)
table.expand_templates(PREFABS)
local count = 0
process_resource_pack_fabs()
for _,def in pairs(PREFABS) do
if def.delete then error(table.tostr(def)) end
if not def.kind then
def.kind = kind_from_filename(def.file)
end
def.use_prob = calc_prob(def)
if def.use_prob > 0 then
count = count + 1
end
end
gui.printf(count .. " prefabs loaded and usable!\n\n")
end
---| Fab_load_all_definitions |---
PREFABS = {}
assert(GAME.game_dir)
if GAME.use_generics and GAME.use_generics == true then
if not ob_match_game({game = "doomish"}) or OB_CONFIG.port == "limit_removing" then
visit_dir("games/generic/fabs", "*.lua")
end
end
if not ob_match_game({game = "doomish"}) or OB_CONFIG.port ~= "limit_removing" then
visit_dir("games/" .. GAME.game_dir .. "/fabs", "*.lua")
end
ob_invoke_hook("addon_fabs")
preprocess_all()
end
function Fab_update_skip_prob()
for name,def in pairs(PREFABS) do
if def.skip_prob then
if rand.odds(def.skip_prob) then
def.use_prob = 0
else
def.use_prob = def.prob
end
end
if def.prob_skew and def.use_prob ~= 0 then
local prob_skew = def.prob_skew
local half_skew = (1.0 + prob_skew) / 2.0
local final_skew = rand.pick({ 1 / prob_skew, 1 / half_skew, 1.0, half_skew, prob_skew })
def.use_prob = def.prob * final_skew
end
end
end
function Fab_expansion_groups(list, axis_name, fit_size, pf_size, fabinfo)
local extra = fit_size - pf_size
-- nothing needed if the size is the same
if math.abs(extra) < 1 then return nil end
if extra < 0 then
-- TO-DO: Fix issue with beam fit
if fabinfo.kind == "beam" then goto continue end
local problem_string = "\n\nPREFAB DOES NOT FIT!!!\n"
problem_string = problem_string .. "(on " .. axis_name .. " axis)\n"
problem_string = problem_string .. "Fab info:\n"
problem_string = problem_string .. table.tostr(fabinfo) .. "\n"
problem_string = problem_string .. "Required: " .. fit_size .. " Prefab has: " .. pf_size .. "\n\n"
gui.printf(problem_string)
::continue::
end
--assert(extra > 0)
-- check some special keywords.
-- missing 'x_fit' field (etc) defaults to "stretch",
if not list or list == "stretch" then
local G =
{
low = 0,
high = pf_size,
low2 = 0,
high2 = fit_size
}
G.size = G.high - G.low
G.size2 = G.high2 - G.low2
return { G }
elseif list == "left" or list == "bottom" then
list = { 0, 1 }
elseif list == "right" or list == "top" then
list = { pf_size - 1, pf_size }
elseif list == "frame" then
list = { 0, 1, pf_size - 1, pf_size }
end
if type(list) ~= "table" then
error("Bad " .. axis_name .. "_fit field in prefab: " .. tostring(list))
end
-- validate list
for i = 1, #list-1 do
local A = list[i]
local B = list[i + 1]
if A >= B then
error("Bad ordering in " .. axis_name .. "_fit field in prefab")
end
end
-- compute total weight of expanding sections
local total_weight = 0
for i = 1, #list-1, 2 do
local weight = list[i+1] - list[i]
total_weight = total_weight + weight
end
assert(total_weight > 0)
-- construct the mapping groups
local groups = { }
local pos = list[1]
for i = 1,#list-1 do
local G =
{
low = list[i],
high = list[i+1]
}
G.size = G.high - G.low
G.size2 = G.size
if (i % 2) == 1 then
local weight = list[i+1] - list[i]
G.size2 = G.size2 + extra * weight / total_weight
end
G.low2 = pos
G.high2 = pos + G.size2
pos = pos + G.size2,
table.insert(groups, G)
end
return groups
end
function is_subst(value)
return type(value) == "string" and string.match(value, "^[!?]")
end
function Fab_apply_substitute(value, SKIN)
assert(is_subst(value))
-- a simple substitution is just: "?varname",
-- a more complex one has an operator: "?varname+3", "?foo==1",
local neg, var_name, op, number = string.match(value, "(.)([%w_]*)(%p*)(%-?[%d.]*)");
if var_name == "" then var_name = nil end
if op == "" then op = nil end
if number == "" then number = nil end
if not var_name or (op and not number) or (op and neg == '!') then
error("bad substitution: " .. tostring(value));
end
-- first lookup variable name, abort if not present
value = SKIN[var_name]
if value == nil then
return nil
end
-- recursive substitution is handled by caller
if is_subst(value) then
if op then
error("subst op failed on recursive var: " .. var_name)
end
return value
end
-- apply the boolean negation
if neg == '!' then
return 1 - convert_bool(value)
-- apply the operator
elseif op then
value = 0 + value
number = 0 + number
if op == "+" then return value + number end
if op == "-" then return value - number end
if op == "==" then return sel(value == number, 1, 0) end
if op == "!=" then return sel(value ~= number, 1, 0) end
error("bad subst operator: " .. tostring(op))
end
return value
end
function Fab_determine_bbox(fab)
local x1, y1, z1
local x2, y2, z2
-- Note: no need to handle slopes, they are defined to be "shrinky",
-- (i.e. never higher that t, never lower than b).
for _,B in pairs(fab.brushes) do
if B[1].outlier then goto continue end
if B[1].m == "light" then goto continue end
if B[1].m == "rail" then goto continue end
if B[1].m == "spot" then goto continue end
for _,C in pairs(B) do
if C.x then
if not x1 then
x1, y1 = C.x, C.y
x2, y2 = C.x, C.y
else
x1 = math.min(x1, C.x)
y1 = math.min(y1, C.y)
x2 = math.max(x2, C.x)
y2 = math.max(y2, C.y)
end
elseif C.b or C.t then
local z = C.b or C.t
if not z1 then
z1, z2 = z, z
else
z1 = math.min(z1, z)
z2 = math.max(z2, z)
end
end
end -- C
::continue::
end -- B
assert(x1 and y1 and x2 and y2)
-- Note: it is OK when z1 and z2 are not set (this happens with
-- prefabs consisting entirely of infinitely tall solids).
-- Note: It is possible to get dz == 0,
local dz
if z1 then dz = z2 - z1 end
fab.bbox = { x1=x1, x2=x2, dx=(x2 - x1),
y1=y1, y2=y2, dy=(y2 - y1),
z1=z1, z2=z2, dz=dz,
}
gui.debugf("bbox =\n%s\n", table.tostr(fab.bbox))
end
function Fab_transform_XY(fab, T)
local function brush_xy(brush)
for _,C in pairs(brush) do
if C.x then C.x, C.y = Trans.apply_xy(C.x, C.y) end
if C.slope then C.slope = Trans.apply_slope(C.slope) end
if C.angle then C.angle = Trans.apply_angle(C.angle) end
end
if sel(T.mirror_x, 1, 0) ~= sel(T.mirror_y, 1, 0) then
brushlib.reverse(brush)
end
end
local function entity_xy(E)
if E.x then
E.x, E.y = Trans.apply_xy(E.x, E.y)
end
if E.angle then
E.angle = Trans.apply_angle(E.angle)
end
if E.angles then
E.angles = Trans.apply_angles_xy(E.angles)
end
end
local function model_xy(M)
M.x1, M.y1 = Trans.apply_xy(M.x1, M.y1)
M.x2, M.y2 = Trans.apply_xy(M.x2, M.y2)
-- handle rotation / mirroring
-- NOTE: we only support 0/90/180/270 rotations
if M.x1 > M.x2 then M.x1, M.x2 = M.x2, M.x1 ; M.y_face.u1, M.y_face.u2 = M.y_face.u2, M.y_face.u1 end
if M.y1 > M.y2 then M.y1, M.y2 = M.y2, M.y1 ; M.x_face.u1, M.x_face.u2 = M.x_face.u2, M.x_face.u1 end
-- handle 90 and 270 degree rotations : swap X and Y faces
local rotate = T.rotate or 0
if math.abs(T.rotate - 90) < 15 or math.abs(T.rotate - 270) < 15 then
M.x_face, M.y_face = M.y_face, M.x_face
end
end
---| Fab_transform_XY |---
assert(fab.state == "skinned")
fab.state = "transform_xy"
Trans.set(T)
local bbox = fab.bbox
--- X ---
if fab.x_fit or T.fitted_x then
if not T.fitted_x then
error("Fitted prefab used without fitted X transform Culprit: " .. fab.map .. " from " .. fab.name)
elseif T.scale_x then
error("Fitted transform used with scale_x Culprit: " .. fab.map .. " from " .. fab.name)
elseif math.abs(bbox.x1) > 0.1 then
error("Fitted prefab must have lowest X coord at 0. Culprit: " .. fab.map .. " from " .. fab.name)
end
Trans.TRANSFORM.groups_x = Fab_expansion_groups(fab.x_fit, "x", T.fitted_x, bbox.x2, fab)
else
-- "loose" placement
end
--- Y ---
if fab.y_fit or T.fitted_y then
if not T.fitted_y then
error("Fitted prefab used without fitted Y transform. Culprit: " .. fab.map .. " from " .. fab.name)
elseif T.scale_y then
error("Fitted transform used with scale_y. Culprit: " .. fab.map .. " from " .. fab.name)
elseif math.abs(bbox.y1) > 0.1 then
error("Fitted prefab must have lowest Y coord at 0. Culprit: " .. fab.map .. " from " .. fab.name)
end
Trans.TRANSFORM.groups_y = Fab_expansion_groups(fab.y_fit, "y", T.fitted_y, bbox.y2, fab)
else
-- "loose" placement
end
-- apply the coordinate transform to all parts of the prefab
for _,B in pairs(fab.brushes) do
brush_xy(B)
end
for _,E in pairs(fab.entities) do
entity_xy(E)
end
for _,M in pairs(fab.models) do
model_xy(M)
entity_xy(M.entity)
end
Trans.clear()
end
function Fab_transform_Z(fab, T)
local function brush_z(brush)
local b, t
for _,C in pairs(brush) do
if C.b then C.b = Trans.apply_z(C.b) ; b = C.b end
if C.t then C.t = Trans.apply_z(C.t) ; t = C.t end
end
-- apply capping
if Trans.z1_cap and not b and (not t or t.t > Trans.z1_cap) then
table.insert(brush, { b = Trans.z1_cap })
end
if Trans.z2_cap and not t and (not b or b.b < Trans.z2_cap) then
table.insert(brush, { t = Trans.z2_cap })
end
end
local function entity_z(E)
if E.z then
E.z = Trans.apply_z(E.z)
if E.delta_z then
E.z = E.z + E.delta_z
E.delta_z = nil
end
if PARAM.entity_delta_z then
E.z = E.z + PARAM.entity_delta_z
end
if E.angles then
E.angles = Trans.apply_angles_z(E.angles)
end
end
end
local function model_z(M)
M.z1 = Trans.apply_z(M.z1)
M.z2 = Trans.apply_z(M.z2)
if M.delta_z then
M.z1 = M.z1 + M.delta_z
M.z2 = M.z2 + M.delta_z
end
if Trans.mirror_z then
M.z1, M.z2 = M.z2, M.z1
end
-- handle QUAKE I / II platforms
if M.entity.height and T.scale_z then
M.entity.height = M.entity.height * T.scale_z
end
end
---| Fab_transform_Z |---
assert(fab.state == "transform_xy")
fab.state = "transform_z"
Trans.set(T)
local bbox = fab.bbox
--- Z ---
if fab.z_fit or T.fitted_z then
if not T.fitted_z then
error("Fitted prefab used without fitted Z transform. Culprit: " .. fab.map .. " from " .. fab.name)
elseif T.scale_z then
error("Fitted transform used with scale_z. Culprit: " .. fab.map .. " from " .. fab.name)
elseif not (bbox.dz and bbox.dz >= 1) then
error("Fitted prefab has no vertical range! Culprit: " .. fab.map .. " from " .. fab.name)
elseif math.abs(bbox.z1) > 0.1 then
error("Fitted prefab must have lowest Z coord at 0. Culprit: " .. fab.map .. " from " .. fab.name ..
" Bounding box z1: " .. bbox.z1)
end
Trans.TRANSFORM.groups_z = Fab_expansion_groups(fab.z_fit, "z", T.fitted_z, bbox.z2, fab)
else
-- "loose" mode
end
-- apply the coordinate transform to all parts of the prefab
for _,B in pairs(fab.brushes) do
brush_z(B)
end
for _,E in pairs(fab.entities) do
entity_z(E)
end
for _,M in pairs(fab.models) do
model_z(M)
end
Trans.clear()
end
function Fab_bound_brushes_Z(fab, z1, z2)
if not (z1 or z2) then return end
for _,B in pairs(fab.brushes) do
local b = Brush_get_b(B)
local t = Brush_get_t(B)
if z1 and not b then table.insert(B, { b = z1 }) end
if z2 and not t then table.insert(B, { t = z2 }) end
end
end
function Fab_render(fab)
assert(fab.state == "transform_z")
fab.state = "rendered"
local fab_map
if fab.map then
fab_map = fab.map
else
fab_map = "object"
end
for _,B in pairs(fab.brushes) do
if B[1].m ~= "spot" then
raw_add_brush(B)
end
end
for _,M in pairs(fab.models) do
raw_add_model(M)
end
for _,E in pairs(fab.entities) do
if E.id then
raw_add_entity(E)
end
end
end
function Fab_solid_entities(fab, room)
-- prefab must be rendered (or ready to render)
-- TODO : for doors and joiners, store ent in BOTH rooms
if not room then return end
if fab.solid_ents ~= true then return end
for _,E in pairs(fab.entities) do
if E.id then
room:add_solid_ent(E.id, E.x, E.y, E.z)
end
end
end
function Fab_process_spots(fab, room)
-- prefab must be rendered (or ready to render)
local cur_cage
local cur_trap
local function spot_from_brush(B)
local x1,y1, x2,y2
local z1,z2
if brushlib.is_quad(B) then
x1,y1, x2,y2 = brushlib.bbox(B)
for _,C in pairs(B) do
if C.b then z1 = C.b end
if C.t then z2 = C.t end
end
else
-- TODO : calc middle point and largest square
error("Unimplemented: cage spots on rotated prefabs")
end
if not z1 or not z2 then
error("monster spot brush is missing t/b coord")
end
local SPOT =
{
kind = B[1].spot_kind,
angle = B[1].angle,
rank = B[1].rank,
x1 = x1, y1 = y1, z1 = z1,
x2 = x2, y2 = y2, z2 = z2,
}
return SPOT
end
local function OLD__distribute_spots(R, list)
local seen = {}
for _,spot in pairs(list) do
seen[spot.kind] = 1
end
for _,spot in pairs(list) do
if not seen["big_item"] and spot.kind == "important" then
local new_spot = table.copy(spot)
new_spot.kind = "big_item"
table.insert(R.item_spots, new_spot)
end
if not seen["pickup"] and spot.kind == "monster" then
local new_spot = table.copy(spot)
new_spot.kind = "pickup"
table.insert(R.item_spots, new_spot)
end
end
end
local function process_spot(B)
local spot = spot_from_brush(B)
gui.debugf(" got spot kind '%s'\n", spot.kind)
local R = assert(room)
if spot.kind == "cage" then
if not cur_cage then
cur_cage = { mon_spots={} }
end
table.insert(cur_cage.mon_spots, spot)
return
end
if spot.kind == "trap" then
if not cur_trap then
cur_trap = { mon_spots={} }
end
table.insert(cur_trap.mon_spots, spot)
return
end
if spot.kind == "pickup" or spot.kind == "big_item" then
table.insert(R.item_spots, spot)
elseif spot.kind == "important" then
table.insert(R.important_spots, spot)
else
table.insert(R.mon_spots, spot)
end
end
---| Fab_process_spots |---
gui.debugf("Fab_process_spots @ %s\n", room and room.name or "???")
--TODO : review this
if not room then return end
for _,B in pairs(fab.brushes) do
if B[1].m == "spot" then
process_spot(B)
end
end
if cur_cage then table.insert(room.cages, cur_cage) end
if cur_trap then table.insert(room.traps, cur_trap) end
end
function Fab_size_check__OLD(skin, long, deep)
-- the 'long' and 'deep' parameters can be nil : means anything is OK
if long and skin.long then
if type(skin.long) == "number" then
if long < skin.long then return false end
else
if long < skin.long[1] then return false end
if long > skin.long[2] then return false end
end
end
if deep and skin.deep then
if type(skin.deep) == "number" then
if deep < skin.deep then return false end
else
if deep < skin.deep[1] then return false end
if deep > skin.deep[2] then return false end
end
end
if skin._aspect then
-- we don't know the target size, so cannot guarantee any aspect ratio
if not (long and deep) then return false end
local aspect = long / deep