1 local S
= minetest
.get_translator("tsm_pyramids")
12 " "," "," "," "," "," "," "," "," ",
13 " ","^"," ","^"," ","^"," ","^"," ",
14 " ","s"," ","s"," ","s"," ","s"," ",
15 " "," "," "," "," "," "," "," "," ",
16 " "," "," "," "," "," "," "," "," ",
17 " "," "," "," "," "," "," "," "," ",
18 " ","s"," ","s"," ","s"," ","s"," ",
19 " ","v"," ","v"," ","v"," ","v"," ",
20 " "," "," "," "," "," "," "," "," "
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"
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 " "," "," "," ","^"," "," "," "," "
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 " "," "," "," "," "," "," "," "," "
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"," "," "," "," "," "," "," "
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 " "," "," "," "," "," "," "," "," "
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 " "," ","^"," ","^"," ","^"," ","^",
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",
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",
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 " "," "," "," "," "," "," "," "," ",
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",">"," "," "," "," ",
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"," "," "," "," ",
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",
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","^",
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",
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 " "," "," "," "," "," "," "," "," ",
256 " "," "," "," "," "," "," "," "," ",
257 " "," "," "," "," "," "," "," "," ",
258 " "," "," "," ","^"," "," "," "," ",
259 " "," "," ","s","s","s"," "," "," ",
260 " "," ","<","s","S","s",">"," "," ",
261 " "," "," ","s","s","s"," "," "," ",
262 " "," "," "," ","v"," "," "," "," ",
263 " "," "," "," "," "," "," "," "," ",
264 " "," "," "," "," "," "," "," "," ",
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 " "," "," "," "," "," "," "," "," ",
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"," ","<",
302 " "," "," "," "," "," "," "," "," ",
303 " "," "," "," "," "," "," "," "," ",
304 " "," "," "," "," "," "," "," "," ",
305 " "," "," ","^"," ","^"," "," "," ",
306 " "," "," ","s"," ","s"," "," "," ",
307 " "," "," ","v"," ","v"," "," "," ",
308 " "," "," "," "," "," "," "," "," ",
309 " "," "," "," "," "," "," "," "," ",
310 " "," "," "," "," "," "," "," "," ",
317 " "," "," "," "," "," "," "," "," ",
318 " "," "," "," ","^"," "," "," "," ",
319 " "," "," "," ","s"," "," "," "," ",
320 " "," "," "," "," "," "," "," "," ",
321 " ","<","s"," "," "," ","s",">"," ",
322 " "," "," "," "," "," "," "," "," ",
323 " "," "," "," ","s"," "," "," "," ",
324 " "," "," "," ","v"," "," "," "," ",
325 " "," "," "," "," "," "," "," "," ",
332 " "," "," "," "," "," "," "," "," ",
333 " "," ","^"," ","^"," ","^"," "," ",
334 " "," ","s"," ","s"," ","s"," "," ",
335 " "," "," "," "," "," "," "," "," ",
336 " "," "," "," "," "," "," "," "," ",
337 " "," "," "," "," "," "," "," "," ",
338 " "," ","s"," ","s"," ","s"," "," ",
339 " "," ","v"," ","v"," ","v"," "," ",
340 " "," "," "," "," "," "," "," "," ",
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","^",
363 " "," "," "," "," "," "," "," "," ",
364 " ","s"," "," "," "," "," ","s"," ",
365 " "," "," "," "," "," "," "," "," ",
366 " "," "," ","s","S","s"," "," "," ",
367 " "," "," ","S",">"," "," "," "," ",
368 " "," "," ","s","S","s"," "," "," ",
369 " "," "," "," "," "," "," "," "," ",
370 " ","s"," "," "," "," "," ","s"," ",
371 " "," "," "," "," "," "," "," "," ",
378 " "," "," "," "," "," "," "," "," ",
379 " "," "," "," "," "," "," "," "," ",
380 " "," "," "," "," "," "," "," "," ",
381 " "," "," "," "," "," "," "," "," ",
382 " "," "," "," ","<"," "," "," "," ",
383 " "," "," "," "," "," "," "," "," ",
384 " "," "," "," "," "," "," "," "," ",
385 " "," "," "," "," "," "," "," "," ",
386 " "," "," "," "," "," "," "," "," ",
393 " "," "," "," "," "," "," "," "," ",
394 " "," "," "," "," "," "," "," ","<",
395 " "," "," "," "," "," "," "," "," ",
396 " "," "," "," "," "," "," "," "," ",
397 " "," "," "," "," "," "," "," "," ",
398 " "," "," "," "," "," "," "," "," ",
399 " "," "," "," "," "," "," "," "," ",
400 " "," "," "," "," "," "," "," ","<",
401 " "," "," "," "," "," "," "," "," ",
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",
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",
439 " "," "," "," "," "," "," "," "," ",
440 " "," "," "," "," "," "," "," "," ",
441 " "," "," "," "," "," "," "," "," ",
442 " ","^"," ","^"," ","^"," ","^"," ",
443 " ","s"," ","s"," ","s"," ","s"," ",
444 " ","v"," ","v"," ","v"," ","v"," ",
445 " "," "," "," "," "," "," "," "," ",
446 " "," "," "," "," "," "," "," "," ",
447 " "," "," "," "," "," "," "," "," ",
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",
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 " "," "," "," "," "," "," "," "," ",
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"," "," "," "," "," "," "," "," ",
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",
515 " "," "," "," "," "," "," "," "," ",
516 " "," ","^"," ","^"," ","^"," "," ",
517 " "," ","s"," ","s"," ","s"," "," ",
518 " "," "," "," "," "," "," "," "," ",
519 " "," ","s"," ","s"," ","s"," "," ",
520 " "," "," "," "," "," "," "," "," ",
521 " "," ","s"," ","s"," ","s"," "," ",
522 " "," ","v"," ","v"," ","v"," "," ",
523 " "," "," "," "," "," "," "," "," ",
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
= {
548 ["S"] = "sandstonebrick",
549 ["1"] = "deco_stone1",
550 ["2"] = "deco_stone2",
551 ["3"] = "deco_stone3",
556 ["~"] = "lava_source",
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
= {}
601 local symbol
= layout
[get_flat_index((width
-1) - y
, x
, width
)]
603 if symbol
== "^" then
605 elseif symbol
== "<" then
607 elseif symbol
== "v" then
609 elseif symbol
== ">" then
612 new_layout
[get_flat_index(x
, y
, width
)] = symbol
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
)
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"}
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
)
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
])
653 local column_style
= math
.random(0,4)
654 local layout
= rotate_layout(room
.layout
, ROOM_WIDTH
, rotations
)
655 if room
.style
== "yrepeat" then
659 local n_str
= layout
[tonumber(ix
*9+iz
+1)]
663 elseif n_str
== ">" then
665 elseif n_str
== "^" then
667 elseif n_str
== "v" then
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
)
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
684 -- Make at least 8 attempts to fill chests
688 tsm_pyramids
.fill_chest(chests
[c
], stype
, sanded
)
694 tsm_pyramids
.make_traps(pos
, stype
, rotations
)
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
] = "~"
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
)
726 local n_str
= layout
[tonumber(ix
*9+iz
+1)]
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)
745 if math
.random(1,chance
) == 1 then
746 local h
= math
.random(1,maxh
)
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
})