From 9bf6d837adddf12021ed5d044a60f7f39e642b11 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 12 Jan 2023 12:36:29 +0200 Subject: [PATCH] More Gehennom filler level variance --- dat/hellfill.lua | 110 +++++++++++++++++++++++++++++++++++++++++------ doc/lua.adoc | 1 + src/sp_lev.c | 4 +- 3 files changed, 102 insertions(+), 13 deletions(-) diff --git a/dat/hellfill.lua b/dat/hellfill.lua index e1325d8e3..0c87550de 100644 --- a/dat/hellfill.lua +++ b/dat/hellfill.lua @@ -82,16 +82,90 @@ end -- +function rnd_halign() + local aligns = { "half-left", "center", "half-right" }; + return aligns[math.random(1, #aligns)]; +end + +function rnd_valign() + local aligns = { "top", "center", "bottom" }; + return aligns[math.random(1, #aligns)]; +end + +-- the prefab maps must have contents-function, or populatemaze() +-- puts the stuff only inside the prefab map. +local hell_prefabs = { + function () + des.map({ halign = rnd_halign(), valign = "center", map = [[ +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +...... +......]], contents = function() end }); + end, + function () + des.map({ halign = rnd_halign(), valign = "center", map = [[ +xxxxxx.....xxxxxx +xxxx.........xxxx +xx.............xx +xx.............xx +x...............x +x...............x +................. +................. +................. +................. +................. +x...............x +x...............x +xx.............xx +xx.............xx +xxxx.........xxxx +xxxxxx.....xxxxxx +]], contents = function() end }); + end, + function () + des.map({ halign = "center", valign = "center", map = [[ +.............................................................. +.............................................................. +.............................................................. +.............................................................. +..............................................................]], contents = function() end }); + end, + function () + des.map({ halign = rnd_halign(), valign = rnd_valign(), lit = true, map = [[ +x.....x +....... +....... +....... +....... +....... +x.....x]], contents = function() end }); + end, +}; + +function rnd_hell_prefab() + local pf = math.random(1, #hell_prefabs); + hell_prefabs[pf](); +end + -- TODO: cold hells? (ice & water instead of lava. sometimes floor = ice) --- TODO: more hell_tweaks: --- - replacing walls with iron bars --- - random prefab areas --- - replace all walls (in a full level width/height) in a small area hells = { -- 1: "mines" style with lava function () - des.level_init({ style = "solidfill", fg = " " }); + des.level_init({ style = "solidfill", fg = " ", lit = 0 }); des.level_flags("mazelevel", "noflip"); des.level_init({ style="mines", fg=".", smoothed=true ,joined=true, lit=0, walled=true }); des.replace_terrain({ fromterrain = " ", toterrain = "L" }); @@ -102,37 +176,50 @@ hells = { -- 2: mazes like original, with some hell_tweaks function () + des.level_init({ style = "solidfill", fg = " ", lit = 0 }); des.level_flags("mazelevel", "noflip"); des.level_init({ style = "mazegrid", bg = "-" }); - des.mazewalk(01,10,"east"); + des.mazewalk({ coord = {01,10}, dir = "east", stocked = false}); local tmpbounds = selection.match("-"); local bnds = tmpbounds:bounds(); local protected_area = selection.fillrect(bnds.lx, bnds.ly + 1, bnds.hx - 2, bnds.hy - 1); hell_tweaks(protected_area:negate()); + if (percent(25)) then + rnd_hell_prefab(); + end end, -- 3: mazes, style 1: wall thick = 1, random wid corr function () - des.level_init({ style = "solidfill", fg = " " }); + des.level_init({ style = "solidfill", fg = " ", lit = 0 }); des.level_flags("mazelevel", "noflip"); des.level_init({ style = "maze", wallthick = 1 }); end, - -- 4: mazes, style 2: replace wall with iron bars of lava + -- 4: mazes, style 2: replace wall with iron bars or lava function () - des.level_init({ style = "solidfill", fg = " " }); + local cwid = math.random(4); + des.level_init({ style = "solidfill", fg = " ", lit = 0 }); des.level_flags("mazelevel", "noflip"); - des.level_init({ style = "maze", wallthick = 1 }); + des.level_init({ style = "maze", wallthick = 1, corrwid = cwid }); local outside_walls = selection.match(" "); local wallterrain = { "F", "L" }; shuffle(wallterrain); des.replace_terrain({ mapfragment = "w", toterrain = wallterrain[1] }); + if (cwid == 1) then + if (wallterrain[1] == "F" and percent(80)) then + -- replace some horizontal iron bars walls with floor + des.replace_terrain({ mapfragment = ".\nF\n.", toterrain = ".", chance = 25 * math.random(4) }); + elseif (percent(25)) then + rnd_hell_prefab(); + end + end des.terrain(outside_walls, " "); -- return the outside back to solid wall end, -- 5: mazes, thick walls, occasionally lava instead of walls function () - des.level_init({ style = "solidfill", fg = " " }); + des.level_init({ style = "solidfill", fg = " ", lit = 0 }); des.level_flags("mazelevel", "noflip"); des.level_init({ style = "maze", wallthick = 1 + math.random(2), corrwid = math.random(2) }); if (percent(50)) then @@ -151,5 +238,4 @@ hells[hellno](); des.stair("up") des.stair("down") -des.region(selection.area(00,00,77,21),"unlit"); populatemaze(); diff --git a/doc/lua.adoc b/doc/lua.adoc index 632ccd949..705991b8e 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -556,6 +556,7 @@ the map are not relative to it. | halign | Horizontal alignment on a rough 3x3 grid. | valign | Vertical alignment on a rough 3x3 grid. | map | Multi-line string describing the map. See <<_map_characters>> +| lit | Boolean. Are the map grids lit? Default is false. | contents | A function called with one parameter, a table with "width" and "height", the map width and height. All coordinates in the function will be relative to the map. |=== diff --git a/src/sp_lev.c b/src/sp_lev.c index 042eb1523..2a79b2ee7 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -6494,6 +6494,7 @@ TODO: gc.coder->croom needs to be updated boolean has_contents = FALSE; int tryct = 0; int ox, oy; + boolean lit = FALSE; struct selectionvar *sel; create_des_coder(); @@ -6512,6 +6513,7 @@ TODO: gc.coder->croom needs to be updated tb = t_or_b2i[get_table_option(L, "valign", "none", top_or_bot)]; get_table_xy_or_coord(L, &x, &y); tmpstr = get_table_str(L, "map"); + lit = (boolean) get_table_boolean_opt(L, "lit", FALSE); lua_getfield(L, 1, "contents"); if (lua_type(L, -1) == LUA_TFUNCTION) { lua_remove(L, -2); @@ -6677,7 +6679,7 @@ TODO: gc.coder->croom needs to be updated continue; selection_setpoint(x, y, sel, 1); levl[x][y].typ = mptyp; - levl[x][y].lit = FALSE; + levl[x][y].lit = lit; /* clear out levl: load_common_data may set them */ levl[x][y].flags = 0; levl[x][y].horizontal = 0;