Source:NetHack 5.0.0/dat/hellfill.lua

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to hellfill.lua from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/dat/hellfill.lua#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. -- NetHack 5.0	hellfill.des	$NHDT-Date: 1432512783 2015/05/25 00:13:03 $  $NHDT-Branch: master $:$NHDT-Revision: 1.25 $
2. --	Copyright (c) 2022 by Pasi Kallinen
3. -- NetHack may be freely redistributed.  See license for details.
4. --
5. --
6. 
7. --	The "fill" level for gehennom.
8. --
9. --	This level is used to fill out any levels not occupied by
10. --	specific levels.
11. --
12. 
13. function hellobjects()
14.    local objclass = { "(", "/", "=", "+", ")", "[", "?", "*", "%" };
15.    shuffle(objclass);
16. 
17.    des.object(objclass[1]);
18.    des.object(objclass[1]);
19.    des.object(objclass[2]);
20.    des.object(objclass[3]);
21.    des.object(objclass[4]);
22.    des.object(objclass[5]);
23.    des.object()
24.    des.object()
25. end
26. 
27. --
28. 
29. function hellmonsters()
30.    local monclass = { "V", "D", " ", "&", "Z" };
31.    shuffle(monclass);
32. 
33.    des.monster({ class = monclass[1], peaceful = 0 });
34.    des.monster({ class = monclass[1], peaceful = 0 });
35.    des.monster({ class = monclass[2], peaceful = 0 });
36.    des.monster({ class = monclass[2], peaceful = 0 });
37.    des.monster({ class = monclass[3], peaceful = 0 });
38.    des.monster({ class = monclass[4], peaceful = 0 });
39.    des.monster({ peaceful = 0 });
40.    des.monster({ class = "H", peaceful = 0 });
41. end
42. 
43. --
44. 
45. function helltraps()
46.    for i = 1, 12 do
47.       des.trap()
48.    end
49. end
50. 
51. --
52. 
53. function populatemaze()
54.    for i = 1, math.random(8) + 11 do
55.       if (percent(50)) then
56.          des.object("*");
57.       else
58.          des.object();
59.       end
60.    end
61. 
62.    for i = 1, math.random(10) + 2 do
63.       des.object("`");
64.    end
65. 
66.    for i = 1, math.random(3) do
67.       des.monster({ id = "minotaur", peaceful = 0 });
68.    end
69. 
70.    for i = 1, math.random(5) + 7 do
71.       des.monster({ peaceful = 0 });
72.    end
73. 
74.    for i = 1, math.random(6) + 7 do
75.       des.gold();
76.    end
77. 
78.    for i = 1, math.random(6) + 7 do
79.       des.trap();
80.    end
81. end
82. 
83. --
84. 
85. function rnd_halign()
86.    local aligns = { "half-left", "center", "half-right" };
87.    return aligns[math.random(1, #aligns)];
88. end
89. 
90. function rnd_valign()
91.    local aligns = { "top", "center", "bottom" };
92.    return aligns[math.random(1, #aligns)];
93. end
94. 
95. -- the prefab maps must have contents-function, or populatemaze()
96. -- puts the stuff only inside the prefab map.
97. -- contains either a function, or an object with "repeatable" and "contents".
98. -- function alone implies not repeatable.
99. local hell_prefabs = {
100.    {
101.       repeatable = true,
102.       contents = function ()
103.       des.map({ halign = rnd_halign(), valign = "center", map = [[
104. ......
105. ......
106. ......
107. ......
108. ......
109. ......
110. ......
111. ......
112. ......
113. ......
114. ......
115. ......
116. ......
117. ......
118. ......
119. ......]], contents = function() end });
120.       end
121.    },
122.    {
123.       repeatable = true,
124.       contents = function ()
125.       des.map({ halign = rnd_halign(), valign = "center", map = [[
126. xxxxxx.....xxxxxx
127. xxxx.........xxxx
128. xx.............xx
129. xx.............xx
130. x...............x
131. x...............x
132. .................
133. .................
134. .................
135. .................
136. .................
137. x...............x
138. x...............x
139. xx.............xx
140. xx.............xx
141. xxxx.........xxxx
142. xxxxxx.....xxxxxx
143. ]], contents = function() end });
144.       end
145.    },
146.    function (coldhell)
147.       des.map({ halign = rnd_halign(), valign = rnd_valign(), map = [[
148. xxxxxx.xxxxxx
149. xLLLLLLLLLLLx
150. xL---------Lx
151. xL|.......|Lx
152. xL|.......|Lx
153. .L|.......|L.
154. xL|.......|Lx
155. xL|.......|Lx
156. xL---------Lx
157. xLLLLLLLLLLLx
158. xxxxxx.xxxxxx
159. ]], contents = function()
160.    des.non_diggable(selection.area(2,2, 10,8));
161.    des.region(selection.area(4,4, 8,6), "lit");
162.    des.exclusion({ type = "teleport", region = { 2,2, 10,8 } });
163.    if (coldhell) then
164.       des.replace_terrain({ region = {1,1, 11,9}, fromterrain="L", toterrain="P" });
165.    end
166.    local dblocs = {
167.       { x = 1, y = 5, dir="east", state="closed" },
168.       { x = 11, y = 5, dir="west", state="closed" },
169.       { x = 6, y = 1, dir="south", state="closed" },
170.       { x = 6, y = 9, dir="north", state="closed" }
171.    }
172.    shuffle(dblocs);
173.    for i = 1, math.random(1, #dblocs) do
174.       des.drawbridge(dblocs[i]);
175.    end
176.    local mons = { "H", "T", "@" };
177.    shuffle(mons);
178.    for i = 1, 3 + math.random(1, 5) do
179.       des.monster(mons[1], 6, 5);
180.    end
181.       end });
182.    end,
183.    {
184.       repeatable = true,
185.       contents = function ()
186.       des.map({ halign = "center", valign = "center", map = [[
187. ..............................................................
188. ..............................................................
189. ..............................................................
190. ..............................................................
191. ..............................................................]], contents = function() end });
192.       end
193.    },
194.    {
195.       repeatable = true,
196.       contents = function ()
197.       des.map({ halign = rnd_halign(), valign = rnd_valign(), lit = true, map = [[
198. x.....x
199. .......
200. .......
201. .......
202. .......
203. .......
204. x.....x]], contents = function() end  });
205.    end
206.    },
207.    function ()
208.       des.map({ halign = rnd_halign(), valign = rnd_valign(), map = [[
209. BBBBBBB
210. B.....B
211. B.....B
212. B.....B
213. B.....B
214. B.....B
215. BBBBBBB]], contents = function()
216.    des.region({ region={2,2, 2,2}, type="temple", filled=1, irregular=1 });
217.    des.altar({ x=3, y=3, align="noalign", type=percent(75) and "altar" or "shrine" });
218.       end  });
219.    end,
220.    function ()
221.       des.map({ halign = rnd_halign(), valign = rnd_valign(), map = [[
222. ..........
223. ..........
224. ..........
225. ...FFFF...
226. ...F..F...
227. ...F..F...
228. ...FFFF...
229. ..........
230. ..........
231. ..........]], contents = function()
232.    des.exclusion({ type = "teleport", region = { 4,4, 5,5 } });
233.    local mons = { "Angel", "D", "H", "L" };
234.    des.monster(mons[math.random(1, #mons)], 4,4);
235.       end });
236.    end,
237. 
238.    function ()
239.       des.map({ halign = rnd_halign(), valign = rnd_valign(), map = [[
240. .........
241. .}}}}}}}.
242. .}}---}}.
243. .}--.--}.
244. .}|...|}.
245. .}--.--}.
246. .}}---}}.
247. .}}}}}}}.
248. .........
249. ]], contents = function(rm)
250.    des.exclusion({ type = "teleport", region = { 3,3, 5,5 } });
251.    des.monster("L",04,04)
252.       end })
253.    end,
254.    function ()
255.       local mapstr = percent(30) and [[
256. .....
257. .LLL.
258. .LZL.
259. .LLL.
260. .....]] or [[
261. .....
262. .PPP.
263. .PWP.
264. .PPP.
265. .....]];
266.       for dx = 1, 5 do
267.          des.map({ x = dx*14 - 4, y = math.random(3, 15),
268.                    map = mapstr, contents = function() end })
269.       end
270.    end,
271.    {
272.       repeatable = true,
273.       contents = function ()
274.       local mapstr = [[
275. ...
276. ...
277. ...
278. ...
279. ...
280. ...
281. ...
282. ...
283. ...
284. ...
285. ...
286. ...
287. ...
288. ...
289. ...
290. ...
291. ...]];
292.       for dx = 1, 3 do
293.          des.map({ x = math.random(3, 75), y = 3,
294.                    map = mapstr, contents = function() end })
295.       end
296.    end
297.    },
298. };
299. 
300. function rnd_hell_prefab(coldhell)
301.    local dorepeat = true;
302.    local nloops = 0;
303.    repeat
304.       nloops = nloops + 1;
305.       local pf = math.random(1, #hell_prefabs);
306.       local fab = hell_prefabs[pf];
307.       local fabtype = type(fab);
308. 
309.       if (fabtype == "function") then
310.          fab(coldhell);
311.          dorepeat = false;
312.       elseif (fabtype == "table") then
313.          fab.contents(coldhell);
314.          dorepeat = not (fab.repeatable and math.random(0, nloops * 2) == 0);
315.       end
316.    until ((not dorepeat) or (nloops > 5));
317. end
318. 
319. hells = {
320.    -- 1: "mines" style with lava
321.    function ()
322.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
323.       des.level_flags("mazelevel", "noflip");
324.       des.level_init({ style="mines", fg=".", smoothed=true ,joined=true, lit=0, walled=true });
325.       des.replace_terrain({ fromterrain = " ", toterrain = "L" });
326.       des.replace_terrain({ fromterrain = ".", toterrain = "L", chance = 5 });
327.       des.replace_terrain({ mapfragment = w, toterrain = "L", chance = 20 });
328.       des.replace_terrain({ mapfragment = w, toterrain = ".", chance = 15 });
329.    end,
330. 
331.    -- 2: mazes like original, with some hell_tweaks
332.    function ()
333.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
334.       des.level_flags("mazelevel", "noflip");
335.       des.level_init({ style = "mazegrid", bg = "-" });
336.       des.mazewalk({ coord = {01,10}, dir = "east", stocked = false});
337.       local tmpbounds = selection.match("-");
338.       local bnds = tmpbounds:bounds();
339.       local protected_area = selection.fillrect(bnds.lx, bnds.ly + 1, bnds.hx - 2, bnds.hy - 1);
340.       hell_tweaks(protected_area:negate());
341.       if (percent(25)) then
342.          rnd_hell_prefab(false);
343.       end
344.    end,
345. 
346.    -- 3: mazes, style 1: wall thick = 1, random wid corr
347.    function ()
348.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
349.       des.level_flags("mazelevel", "noflip");
350.       des.level_init({ style = "maze", wallthick = 1 });
351.    end,
352. 
353.    -- 4: mazes, style 2: replace wall with iron bars or lava
354.    function ()
355.       local cwid = math.random(4);
356.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
357.       des.level_flags("mazelevel", "noflip");
358.       des.level_init({ style = "maze", wallthick = 1, corrwid = cwid });
359.       local outside_walls = selection.match(" ");
360.       local wallterrain = { "F", "L" };
361.       shuffle(wallterrain);
362.       des.replace_terrain({ mapfragment = "w", toterrain = wallterrain[1] });
363.       if (cwid == 1) then
364.          if (wallterrain[1] == "F" and percent(80)) then
365.             -- replace some horizontal iron bars walls with floor
366.             des.replace_terrain({ mapfragment = ".\nF\n.", toterrain = ".", chance = 25 * math.random(4) });
367.          elseif (percent(25)) then
368.             rnd_hell_prefab(false);
369.          end
370.       end
371.       des.terrain(outside_walls, " ");  -- return the outside back to solid wall
372.    end,
373. 
374.    -- 5: mazes, thick walls, occasionally lava instead of walls
375.    function ()
376.       local wwid = 1 + math.random(2);
377.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
378.       des.level_flags("mazelevel", "noflip");
379.       des.level_init({ style = "maze", wallthick = wwid, corrwid = math.random(2) });
380.       if (percent(50)) then
381.          local outside_walls = selection.match(" ");
382.          des.replace_terrain({ mapfragment = "w", toterrain = "L" });
383.          des.terrain(outside_walls, " ");  -- return the outside back to solid wall
384.          if (wwid == 3 and percent(40)) then
385.             local sel = selection.match("LLL\nLLL\nLLL");
386.             des.terrain(sel:percentage(30 * math.random(4)), "Z");
387.          end
388.       end
389.    end,
390. 
391.    -- 6: cold maze, with ice and water
392.    function ()
393.       local cwid = math.random(4);
394.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
395.       des.level_flags("mazelevel", "noflip", "cold");
396.       des.level_init({ style = "maze", wallthick = 1, corrwid = cwid });
397.       local outside_walls = selection.match(" ");
398.       local icey = selection.negate():percentage(10):grow():filter_mapchar(".");
399.       des.terrain(icey, "I");
400.       if (cwid > 1) then
401.          -- turn some ice into wall of water
402.          des.terrain(icey:percentage(1), "W");
403.       end
404.       des.terrain(icey:percentage(5), "P");
405.       if (percent(25)) then
406.          des.terrain(selection.match("w"), "W"); -- walls of water
407.       end
408.       if (cwid == 1 and percent(25)) then
409.          rnd_hell_prefab(true);
410.       end
411.       des.terrain(outside_walls, " ");  -- return the outside back to solid wall
412.    end,
413. 
414.    -- 7: open cavern, "mines" with more space
415.    function ()
416.       -- walls are either stone or lava
417.       local wter = percent(50) and " " or "L";
418.       des.level_init({ style = "solidfill", fg = " ", lit = 0 });
419.       des.level_flags("mazelevel", "noflip");
420.       des.level_init({ style="mines", fg=".", bg = wter, smoothed=true ,joined=true, lit=0 });
421.       local sel = selection.match("."):grow();
422.       des.terrain({ selection = sel, typ = ".", lit = 0 });
423. 
424.       local border = selection.rect(0,0, 78, 20);
425.       des.terrain({ selection = border, typ = wter, lit = 0 });
426.       des.wallify();
427.    end,
428. 
429. };
430. 
431. local hellno = math.random(1, #hells);
432. hells[hellno]();
433. 
434. --
435. 
436. des.stair("up")
437. if (u.invocation_level) then
438.    des.trap("vibrating square");
439. else
440.    des.stair("down")
441. end
442. 
443. populatemaze();