Make falling of trap stones more unpredictable
[minetest_pyramids/tsm_pyramids.git] / room.lua
blob7648d8db178e120b64d396fb5e78b9560d761558
1 local S = minetest.get_translator("tsm_pyramids")
3 -- ROOM LAYOUTS
5 local ROOM_WIDTH = 9
7 local room_types = {
8 -- Pillar room
10 style = "yrepeat",
11 layout = {
12 " "," "," "," "," "," "," "," "," ",
13 " ","^"," ","^"," ","^"," ","^"," ",
14 " ","s"," ","s"," ","s"," ","s"," ",
15 " "," "," "," "," "," "," "," "," ",
16 " "," "," "," "," "," "," "," "," ",
17 " "," "," "," "," "," "," "," "," ",
18 " ","s"," ","s"," ","s"," ","s"," ",
19 " ","v"," ","v"," ","v"," ","v"," ",
20 " "," "," "," "," "," "," "," "," "
22 traps = true,
24 -- Hieroglyph walls
26 style = "yrepeat",
27 layout = {
28 "s","s","s","s","s","s","s","s","s",
29 "s"," "," "," "," "," "," "," ","s",
30 "s"," "," "," "," "," "," "," ","s",
31 "s"," "," "," "," "," "," "," ","s",
32 " "," "," "," ","<"," "," "," ","s",
33 "s"," "," "," "," "," "," "," ","s",
34 "s"," "," "," "," "," "," "," ","s",
35 "s"," "," "," "," "," "," "," ","s",
36 "s","s","s","s","s","s","s","s","s"
39 -- 4 large pillars
41 style = "yrepeat",
42 layout = {
43 " "," "," "," ","v"," "," "," "," ",
44 " ","s","s"," "," "," ","s","s"," ",
45 " ","s","s"," "," "," ","s","s"," ",
46 " "," "," "," "," "," "," "," "," ",
47 " "," "," "," "," "," "," "," ","<",
48 " "," "," "," "," "," "," "," "," ",
49 " ","s","s"," "," "," ","s","s"," ",
50 " ","s","s"," "," "," ","s","s"," ",
51 " "," "," "," ","^"," "," "," "," "
54 -- hidden room
56 style = "yrepeat",
57 layout = {
58 " "," "," "," "," "," "," "," "," ",
59 " "," "," "," "," "," "," "," "," ",
60 " "," ","s","S","s","S","s"," "," ",
61 " "," ","S"," "," "," ","S"," "," ",
62 " "," ","s"," ",">"," ","s"," ","<",
63 " "," ","S"," "," "," ","S"," "," ",
64 " "," ","s","S","s","S","s"," "," ",
65 " "," "," "," "," "," "," "," "," ",
66 " "," "," "," "," "," "," "," "," "
69 -- spiral 1
71 style = "yrepeat",
72 layout = {
73 " "," "," "," "," "," "," "," "," ",
74 " ","S","S","S","S","S","S","S"," ",
75 " ","S"," "," "," "," "," ","S"," ",
76 " ","S"," ","s","s","s"," ","S"," ",
77 " ","S"," ","s","v","s"," ","S"," ",
78 "S","S"," ","s"," ","s"," ","S"," ",
79 "S","S"," ","s"," "," "," ","S"," ",
80 "v","S"," ","S","S","S","S","S"," ",
81 " ","S"," "," "," "," "," "," "," "
84 -- spiral 2
86 style = "yrepeat",
87 layout = {
88 " "," "," "," "," "," "," "," "," ",
89 " ","S","S","S","S","S","S","S"," ",
90 " "," "," ","s"," "," "," ","S"," ",
91 "S","S"," ","s"," ","s"," ","S"," ",
92 " ","S"," ","s","^","s"," ","S"," ",
93 " ","S"," ","s","s","s"," ","S"," ",
94 " ","S"," "," "," "," "," ","S"," ",
95 " ","S","S","S","S","S","S","S"," ",
96 " "," "," "," "," "," "," "," "," "
99 -- pillar mania
101 style = "yrepeat",
102 layout = {
103 " "," ","v"," ","v"," ","v"," ","v",
104 " ","s"," ","s"," ","s"," ","s"," ",
105 " "," "," "," "," "," "," "," "," ",
106 " ","s"," ","s"," ","s"," ","s"," ",
107 " "," "," "," "," "," "," "," "," ",
108 " ","s"," ","s"," ","s"," ","s"," ",
109 " "," "," "," "," "," "," "," "," ",
110 " ","s"," ","s"," ","s"," ","s"," ",
111 " "," ","^"," ","^"," ","^"," ","^",
113 --traps = true,
115 -- plusses
117 style = "yrepeat",
118 layout = {
119 "s"," "," "," "," "," "," "," ","s",
120 " "," ","s",">"," ","<","s"," "," ",
121 " ","s","s","s"," ","s","s","s"," ",
122 " "," ","s"," "," "," ","s"," "," ",
123 " "," "," "," ","<"," "," "," "," ",
124 " "," ","s"," "," "," ","s"," "," ",
125 " ","s","s","s"," ","s","s","s"," ",
126 " "," ","s",">"," ","<","s"," "," ",
127 "s"," "," "," "," "," "," "," ","s",
129 --traps = true,
131 -- diamond
133 style = "yrepeat",
134 layout = {
135 ">","s","s","s","s","s","s","s","s",
136 "s","s","s"," "," "," ","s","s","s",
137 "s","s"," "," "," "," "," ","s","s",
138 "s"," "," "," "," "," "," "," ","s",
139 " "," "," "," "," "," "," ","<","s",
140 "s"," "," "," "," "," "," "," ","s",
141 "s","s"," "," "," "," "," ","s","s",
142 "s","s","s"," "," "," ","s","s","s",
143 ">","s","s","s","s","s","s","s","s",
145 --traps = true,
147 -- square
149 style = "yrepeat",
150 layout = {
151 " "," "," "," "," "," "," "," "," ",
152 " ","S","S","S","^","S","S","S"," ",
153 " ","S","S","S","S","S","S","S"," ",
154 " ","S","S","S","S","S","S","S"," ",
155 " ","S","S","S","S","S","S",">"," ",
156 " ","S","S","S","S","S","S","S"," ",
157 " ","S","S","S","S","S","S","S"," ",
158 " ","S","S","S","v","S","S","S"," ",
159 " "," "," "," "," "," "," "," "," ",
162 -- hallway 2
164 style = "yrepeat",
165 layout = {
166 "S","S","S","S",">"," "," "," "," ",
167 "S","S","S","S","S","^","S","S"," ",
168 "S","S","S","S","S","S","S","S"," ",
169 "S","S","S","S","S","S","S","S"," ",
170 " "," "," "," "," "," "," "," "," ",
171 "S","S","S","S","S","S","S","S"," ",
172 "S","S","S","S","S","S","S","S"," ",
173 "S","S","S","S","S","v","S","S"," ",
174 "S","S","S","S",">"," "," "," "," ",
177 -- hallway 3
179 style = "yrepeat",
180 layout = {
181 "S","S","S","S","S"," "," "," "," ",
182 "S","S","S","S","s",">"," "," "," ",
183 "S","s","S","s","S","s","S"," "," ",
184 " "," "," "," "," "," "," "," "," ",
185 " "," "," "," "," "," "," "," "," ",
186 " "," "," "," "," "," "," "," "," ",
187 "S","s","S","s","S","s","S"," "," ",
188 "S","S","S","S","s",">"," "," "," ",
189 "S","S","S","S","S"," "," "," "," ",
192 -- hallway 4
194 style = "yrepeat",
195 layout = {
196 "S","S","S","S","S","v","S","S","S",
197 "S","S","S","S","S","S","S","S","S",
198 "s","S","s","S","s","S","s","S","s",
199 " "," "," "," "," "," "," "," "," ",
200 " "," "," "," "," "," "," "," ","<",
201 " "," "," "," "," "," "," "," "," ",
202 "s","S","s","S","s","S","s","S","s",
203 "S","S","S","S","S","S","S","S","S",
204 "S","S","S","S","S","^","S","S","S",
207 -- tiny
209 style = "yrepeat",
210 layout = {
211 "S","S","S","S","S","S","S","S","v",
212 "S","S","S","S","S","S","S","S"," ",
213 "S","S","S","S","S","S","S","S"," ",
214 "S","S","S"," "," "," ","S","S"," ",
215 " "," "," "," ","<"," ","S","S"," ",
216 "S","S","S"," "," "," ","S","S"," ",
217 "S","S","S","S","S","S","S","S"," ",
218 "S","S","S","S","S","S","S","S"," ",
219 "S","S","S","S","S","S","S","S","^",
222 -- small
224 style = "yrepeat",
225 layout = {
226 "S","S","S","S","S","S","S","S","S",
227 "S","S","S","S","S","S","S","S","S",
228 "S","S"," ","v"," ","v"," ","S","S",
229 "S","S",">"," "," "," ","<","S"," ",
230 " "," "," "," ","s"," "," ","S"," ",
231 "S","S",">"," "," "," ","<","S"," ",
232 "S","S"," ","^"," ","^"," ","S","S",
233 "S","S","S","S","S","S","S","S","S",
234 "S","S","S","S","S","S","S","S","S",
237 -- small 2
239 style = "yrepeat",
240 layout = {
241 " "," "," "," "," "," "," "," "," ",
242 " ","S","S","S","S","S","S","S"," ",
243 " ","S"," "," ","v"," "," ","S"," ",
244 "S","S"," "," "," "," "," ","S"," ",
245 " "," "," "," "," "," ","<","S"," ",
246 "S","S"," "," "," "," "," ","S"," ",
247 " ","S"," "," ","^"," "," ","S"," ",
248 " ","S","S","S","S","S","S","S"," ",
249 " "," "," "," "," "," "," "," "," ",
252 -- big pillar
254 style = "yrepeat",
255 layout = {
256 " "," "," "," "," "," "," "," "," ",
257 " "," "," "," "," "," "," "," "," ",
258 " "," "," "," ","^"," "," "," "," ",
259 " "," "," ","s","s","s"," "," "," ",
260 " "," ","<","s","S","s",">"," "," ",
261 " "," "," ","s","s","s"," "," "," ",
262 " "," "," "," ","v"," "," "," "," ",
263 " "," "," "," "," "," "," "," "," ",
264 " "," "," "," "," "," "," "," "," ",
266 --traps = true,
268 -- pacman
270 style = "yrepeat",
271 layout = {
272 " "," "," "," "," "," "," "," "," ",
273 " "," "," "," "," "," "," "," "," ",
274 " "," "," ","s","s","s"," "," "," ",
275 " "," ","s","s","v","s","s"," "," ",
276 " "," ","s",">"," "," "," "," "," ",
277 " "," ","s","s","^","s","s"," "," ",
278 " "," "," ","s","s","s"," "," "," ",
279 " "," "," "," "," "," "," "," "," ",
280 " "," "," "," "," "," "," "," "," ",
283 -- the wall
285 style = "yrepeat",
286 layout = {
287 "S","S","S","S","S","S","S"," ","<",
288 "s","s","s","s","s","S","S"," ","s",
289 "s"," "," "," "," ","s","S"," ","<",
290 "s"," "," "," "," ","s","S"," ","s",
291 " "," "," "," ","<","s","S"," ","<",
292 "s"," "," "," "," ","s","S"," ","s",
293 "s"," "," "," "," ","s","S"," ","<",
294 "s","s","s","s","s","s","S"," ","s",
295 "S","S","S","S","S","S","S"," ","<",
298 -- split
300 style = "yrepeat",
301 layout = {
302 " "," "," "," "," "," "," "," "," ",
303 " "," "," "," "," "," "," "," "," ",
304 " "," "," "," "," "," "," "," "," ",
305 " "," "," ","^"," ","^"," "," "," ",
306 " "," "," ","s"," ","s"," "," "," ",
307 " "," "," ","v"," ","v"," "," "," ",
308 " "," "," "," "," "," "," "," "," ",
309 " "," "," "," "," "," "," "," "," ",
310 " "," "," "," "," "," "," "," "," ",
313 -- 4 small pillars
315 style = "yrepeat",
316 layout = {
317 " "," "," "," "," "," "," "," "," ",
318 " "," "," "," ","^"," "," "," "," ",
319 " "," "," "," ","s"," "," "," "," ",
320 " "," "," "," "," "," "," "," "," ",
321 " ","<","s"," "," "," ","s",">"," ",
322 " "," "," "," "," "," "," "," "," ",
323 " "," "," "," ","s"," "," "," "," ",
324 " "," "," "," ","v"," "," "," "," ",
325 " "," "," "," "," "," "," "," "," ",
328 -- 6 pillars
330 style = "yrepeat",
331 layout = {
332 " "," "," "," "," "," "," "," "," ",
333 " "," ","^"," ","^"," ","^"," "," ",
334 " "," ","s"," ","s"," ","s"," "," ",
335 " "," "," "," "," "," "," "," "," ",
336 " "," "," "," "," "," "," "," "," ",
337 " "," "," "," "," "," "," "," "," ",
338 " "," ","s"," ","s"," ","s"," "," ",
339 " "," ","v"," ","v"," ","v"," "," ",
340 " "," "," "," "," "," "," "," "," ",
342 traps = true,
344 -- stripes
346 style = "yrepeat",
347 layout = {
348 " ","S","v","S","v","S","v","S","v",
349 " ","S"," ","S"," ","S"," ","S"," ",
350 " ","s"," ","s"," ","s"," ","s"," ",
351 " "," "," "," "," "," "," "," "," ",
352 " "," "," "," "," "," "," "," "," ",
353 " "," "," "," "," "," "," "," "," ",
354 " ","s"," ","s"," ","s"," ","s"," ",
355 " ","S"," ","S"," ","S"," ","S"," ",
356 " ","S","^","S","^","S","^","S","^",
359 -- inside
361 style = "yrepeat",
362 layout = {
363 " "," "," "," "," "," "," "," "," ",
364 " ","s"," "," "," "," "," ","s"," ",
365 " "," "," "," "," "," "," "," "," ",
366 " "," "," ","s","S","s"," "," "," ",
367 " "," "," ","S",">"," "," "," "," ",
368 " "," "," ","s","S","s"," "," "," ",
369 " "," "," "," "," "," "," "," "," ",
370 " ","s"," "," "," "," "," ","s"," ",
371 " "," "," "," "," "," "," "," "," ",
374 -- 1 chest
376 style = "yrepeat",
377 layout = {
378 " "," "," "," "," "," "," "," "," ",
379 " "," "," "," "," "," "," "," "," ",
380 " "," "," "," "," "," "," "," "," ",
381 " "," "," "," "," "," "," "," "," ",
382 " "," "," "," ","<"," "," "," "," ",
383 " "," "," "," "," "," "," "," "," ",
384 " "," "," "," "," "," "," "," "," ",
385 " "," "," "," "," "," "," "," "," ",
386 " "," "," "," "," "," "," "," "," ",
389 -- 2 chests
391 style = "yrepeat",
392 layout = {
393 " "," "," "," "," "," "," "," "," ",
394 " "," "," "," "," "," "," "," ","<",
395 " "," "," "," "," "," "," "," "," ",
396 " "," "," "," "," "," "," "," "," ",
397 " "," "," "," "," "," "," "," "," ",
398 " "," "," "," "," "," "," "," "," ",
399 " "," "," "," "," "," "," "," "," ",
400 " "," "," "," "," "," "," "," ","<",
401 " "," "," "," "," "," "," "," "," ",
403 traps = true,
405 -- X
407 style = "yrepeat",
408 layout = {
409 "s"," "," "," "," "," "," "," ","s",
410 "s","s",">"," "," "," ","<","s","s",
411 " ","s","s"," "," "," ","s","s"," ",
412 " "," ","s","s"," ","s","s"," "," ",
413 " "," "," "," "," "," "," "," "," ",
414 " "," ","s","s"," ","s","s"," "," ",
415 " ","s","s"," "," "," ","s","s"," ",
416 "s","s",">"," "," "," ","<","s","s",
417 "s"," "," "," "," "," "," "," ","s",
420 -- split 2
422 style = "yrepeat",
423 layout = {
424 "S","S","S","S","S","S","S","S","S",
425 "S","S","S"," "," "," "," "," "," ",
426 "S","S","S"," "," "," "," "," "," ",
427 "S","S","S"," "," ","^","^","^","^",
428 " "," "," "," "," ","s","s","s","s",
429 "S","S","S"," "," ","v","v","v","v",
430 "S","S","S"," "," "," "," "," "," ",
431 "S","S","S"," "," "," "," "," "," ",
432 "S","S","S","S","S","S","S","S","S",
435 -- split 3
437 style = "yrepeat",
438 layout = {
439 " "," "," "," "," "," "," "," "," ",
440 " "," "," "," "," "," "," "," "," ",
441 " "," "," "," "," "," "," "," "," ",
442 " ","^"," ","^"," ","^"," ","^"," ",
443 " ","s"," ","s"," ","s"," ","s"," ",
444 " ","v"," ","v"," ","v"," ","v"," ",
445 " "," "," "," "," "," "," "," "," ",
446 " "," "," "," "," "," "," "," "," ",
447 " "," "," "," "," "," "," "," "," ",
450 -- diamond 2
452 style = "yrepeat",
453 layout = {
454 "S","S"," "," "," "," "," ","S","S",
455 "S"," "," "," ","s"," "," "," ","S",
456 " "," ","<","S","S","S",">"," "," ",
457 " "," ","S","S","S","S","S"," "," ",
458 " ","s","S","S","S","S","S","s"," ",
459 " "," ","S","S","S","S","S"," "," ",
460 " "," ","<","S","S","S",">"," "," ",
461 "S"," "," "," ","s"," "," "," ","S",
462 "S","S"," "," "," "," "," ","S","S",
465 -- ultra pillars
467 style = "yrepeat",
468 layout = {
469 " "," "," "," "," "," "," "," "," ",
470 " ","s","^","s"," ","s","^","s"," ",
471 " ","s","s","s"," ","s","s","s"," ",
472 " ","s","s","s"," ","s","s","s"," ",
473 " "," "," "," "," "," "," "," "," ",
474 " ","s","s","s"," ","s","s","s"," ",
475 " ","s","s","s"," ","s","s","s"," ",
476 " ","s","v","s"," ","s","v","s"," ",
477 " "," "," "," "," "," "," "," "," ",
480 -- vstripes
482 style = "yrepeat",
483 layout = {
484 "S"," "," "," "," "," "," "," "," ",
485 "S"," "," ","^"," "," ","^"," "," ",
486 "S"," "," ","s"," "," ","s"," "," ",
487 "S"," "," "," "," "," "," "," "," ",
488 " "," "," ","s"," "," ","s"," "," ",
489 "S"," "," "," "," "," "," "," "," ",
490 "S"," "," ","s"," "," ","s"," "," ",
491 "S"," "," ","v"," "," ","v"," "," ",
492 "S"," "," "," "," "," "," "," "," ",
495 -- sides
497 style = "yrepeat",
498 layout = {
499 "s"," ","s"," ","s"," ","s"," ","s",
500 " "," ","v"," ","v"," ","v"," "," ",
501 "s"," "," "," "," "," "," "," ","s",
502 " "," "," "," "," "," "," "," "," ",
503 " "," "," "," "," "," "," "," ","s",
504 " "," "," "," "," "," "," "," "," ",
505 "s"," "," "," "," "," "," "," ","s",
506 " "," ","^"," ","^"," ","^"," "," ",
507 "s"," ","s"," ","s"," ","s"," ","s",
509 traps = true,
511 -- 9 pillars
513 style = "yrepeat",
514 layout = {
515 " "," "," "," "," "," "," "," "," ",
516 " "," ","^"," ","^"," ","^"," "," ",
517 " "," ","s"," ","s"," ","s"," "," ",
518 " "," "," "," "," "," "," "," "," ",
519 " "," ","s"," ","s"," ","s"," "," ",
520 " "," "," "," "," "," "," "," "," ",
521 " "," ","s"," ","s"," ","s"," "," ",
522 " "," ","v"," ","v"," ","v"," "," ",
523 " "," "," "," "," "," "," "," "," ",
525 --traps = true,
532 local layout_traps
533 local layout_traps_template = {
534 "S","S","S","S","S","S","S","S","S",
535 "?","S","?","S","?","S","?","S","S",
536 "?","S","?","S","?","S","?","S","S",
537 "?","?","?","?","?","?","?","?","S",
538 "?","?","?","?","?","?","?","?","S", -- << entrance on left side
539 "?","?","?","?","?","?","?","?","S",
540 "?","S","?","S","?","S","?","S","S",
541 "?","S","?","S","?","S","?","S","S",
542 "S","S","S","S","S","S","S","S","S"
545 local code_sandstone = {
546 [" "] = "air",
547 ["s"] = "sandstone",
548 ["S"] = "sandstonebrick",
549 ["1"] = "deco_stone1",
550 ["2"] = "deco_stone2",
551 ["3"] = "deco_stone3",
552 ["^"] = "chest",
553 ["<"] = "chest",
554 [">"] = "chest",
555 ["v"] = "chest",
556 ["~"] = "lava_source",
557 ["t"] = "trap",
559 local code_desert = table.copy(code_sandstone)
560 code_desert["s"] = "desert_sandstone"
561 code_desert["1"] = "deco_stone4"
562 code_desert["2"] = "deco_stone5"
563 code_desert["3"] = "deco_stone6"
564 code_desert["S"] = "desert_sandstone_brick"
565 code_desert["t"] = "desert_trap"
567 local function replace(str, iy, code_table, deco, column_style)
568 local out = "default:"
569 if iy < 4 and (str == "<" or str == ">" or str == "^" or str == "v") then str = " " end
570 if column_style == 1 or column_style == 2 then
571 if iy == 0 and str == "s" then out = "tsm_pyramids:" str = deco[1] end
572 if iy == 3 and str == "s" then out = "tsm_pyramids:" str = deco[2] end
573 elseif column_style == 3 then
574 if iy == 0 and str == "s" then out = "tsm_pyramids:" str = deco[1] end
575 if iy == 2 and str == "s" then out = "tsm_pyramids:" str = deco[2] end
576 elseif column_style == 4 then
577 if iy == 2 and str == "s" then out = "tsm_pyramids:" str = deco[1] end
579 if str == " " then out = "" end
580 return out..code_table[str]
583 local function replace2(str, iy, code_table)
584 local out = "default:"
585 if iy == 0 and str == "~" then out = "tsm_pyramids:" str = "t"
586 elseif iy < 3 and str == "~" then str = " " end
588 if str == " " then out = "" end
589 return out..code_table[str]
592 local function get_flat_index(x, y, width)
593 return 1 + x + y * width
596 local function rotate_layout_single(layout, width)
597 local size = width*width
598 local new_layout = {}
599 for x=0, width-1 do
600 for y=0, width-1 do
601 local symbol = layout[get_flat_index((width-1) - y, x, width)]
602 -- Rotate chest
603 if symbol == "^" then
604 symbol = "<"
605 elseif symbol == "<" then
606 symbol = "v"
607 elseif symbol == "v" then
608 symbol = ">"
609 elseif symbol == ">" then
610 symbol = "^"
612 new_layout[get_flat_index(x, y, width)] = symbol
615 return new_layout
618 local function rotate_layout(layout, width, rotations)
619 local new_layout = table.copy(layout)
620 for r=1, rotations do
621 new_layout = rotate_layout_single(new_layout, width)
623 return new_layout
626 -- pos: Position to spawn pyramid
627 -- stype: Sand type ("sandstone" or "desert")
628 -- room_id: Room layout identified (see list of rooms above)
629 -- rotations: Number of times to rotate the room (0-3)
630 function tsm_pyramids.make_room(pos, stype, room_id, rotations)
631 local code_table = code_sandstone
632 if stype == "desert" then
633 code_table = code_desert
635 -- Select random deco block
636 local deco_ids = {"1", "2", "3"}
637 local deco = {}
638 for i=1, 2 do
639 local r = math.random(1, #deco_ids)
640 table.insert(deco, deco_ids[r])
641 table.remove(deco_ids, r)
643 local hole = {x=pos.x+7,y=pos.y+5, z=pos.z+7}
644 if room_id == nil then
645 room_id = math.random(1, #room_types)
647 local room
648 if room_id < 1 or room_id > #room_types then
649 return false, S("Incorrect room type ID: @1", room_id)
651 local room = table.copy(room_types[room_id])
652 local chests = {}
653 local column_style = math.random(0,4)
654 local layout = rotate_layout(room.layout, ROOM_WIDTH, rotations)
655 if room.style == "yrepeat" then
656 for iy=0,4,1 do
657 for ix=0,8,1 do
658 for iz=0,8,1 do
659 local n_str = layout[tonumber(ix*9+iz+1)]
660 local p2 = 0
661 if n_str == "<" then
662 p2 = 0
663 elseif n_str == ">" then
664 p2 = 2
665 elseif n_str == "^" then
666 p2 = 1
667 elseif n_str == "v" then
668 p2 = 3
670 local cpos = {x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}
671 local nn = replace(n_str, iy, code_table, deco, column_style)
672 minetest.set_node(cpos, {name=nn, param2=p2})
673 if nn == "default:chest" then
674 table.insert(chests, cpos)
679 else
680 minetest.log("error", "Invalid pyramid room style! room type ID="..r)
682 local sanded = room.flood_sand ~= false and math.random(1,8) == 1
683 if #chests > 0 then
684 -- Make at least 8 attempts to fill chests
685 local filled = 0
686 while filled < 8 do
687 for c=1, #chests do
688 tsm_pyramids.fill_chest(chests[c], stype, sanded)
689 filled = filled + 1
693 if room.traps then
694 tsm_pyramids.make_traps(pos, stype, rotations)
696 if sanded then
697 tsm_pyramids.flood_sand(pos, stype)
699 return true, nil, sanded
702 local shuffle_traps = function(chance)
703 layout_traps = table.copy(layout_traps_template)
704 for a=1, #layout_traps do
705 if layout_traps[a] == "?" then
706 if math.random(1,100) <= chance then
707 layout_traps[a] = "~"
708 else
709 layout_traps[a] = "S"
715 function tsm_pyramids.make_traps(pos, stype, rotations)
716 local code_table = code_sandstone
717 if stype == "desert" then
718 code_table = code_desert
720 shuffle_traps(math.random(10,100))
721 local hole = {x=pos.x+7,y=pos.y, z=pos.z+7}
722 local layout = rotate_layout(layout_traps, ROOM_WIDTH, rotations)
723 for iy=0,4,1 do
724 for ix=0,8,1 do
725 for iz=0,8,1 do
726 local n_str = layout[tonumber(ix*9+iz+1)]
727 local p2 = 0
728 minetest.set_node({x=hole.x+ix,y=hole.y-iy,z=hole.z+iz}, {name=replace2(n_str, iy, code_table), param2=p2})
734 function tsm_pyramids.flood_sand(pos, stype)
735 local set_to_sand = {}
736 local nn = "default:sand"
737 if stype == "desert" then
738 nn = "default:desert_sand"
740 local hole = {x=pos.x+7,y=pos.y+1, z=pos.z+7}
741 local maxh = math.random(1,4)
742 local chance = math.random(1,7)
743 for ix=0,8,1 do
744 for iz=0,8,1 do
745 if math.random(1,chance) == 1 then
746 local h = math.random(1,maxh)
747 for iy=0,h,1 do
748 local p = {x=hole.x+ix,y=hole.y+iy,z=hole.z+iz}
749 if minetest.get_node(p).name == "air" then
750 table.insert(set_to_sand, p)
756 minetest.bulk_set_node(set_to_sand, {name=nn})