Revert "whitespace cleanup for themerms.lua"

This reverts commit eee5a1698b.
Easier to commit PR #1384.
This commit is contained in:
PatR
2025-04-11 15:19:06 -07:00
parent 7138af00ba
commit 5a910f3df7
+55 -90
View File
@@ -1,4 +1,4 @@
-- NetHack themerms.lua $NHDT-Date: 1743399789 2025/03/30 21:43:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.36 $ -- NetHack themerms.lua $NHDT-Date: 1652196294 2022/05/10 15:24:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.16 $
-- Copyright (c) 2020 by Pasi Kallinen -- Copyright (c) 2020 by Pasi Kallinen
-- NetHack may be freely redistributed. See license for details. -- NetHack may be freely redistributed. See license for details.
-- --
@@ -81,7 +81,8 @@ themeroom_fills = {
-- Trap room -- Trap room
function(rm) function(rm)
local traps = { "arrow", "dart", "falling rock", "bear", local traps = { "arrow", "dart", "falling rock", "bear",
"land mine", "sleep gas", "rust", "anti magic" }; "land mine", "sleep gas", "rust",
"anti magic" };
shuffle(traps); shuffle(traps);
local locs = selection.room():percentage(30); local locs = selection.room():percentage(30);
local func = function(x,y) local func = function(x,y)
@@ -102,28 +103,22 @@ themeroom_fills = {
des.feature("fountain"); des.feature("fountain");
end end
end end
table.insert(postprocess, { handler = make_garden_walls, table.insert(postprocess, { handler = make_garden_walls, data = { sel = selection.room() } });
data = { sel = selection.room() } });
end end
}, },
-- Buried treasure -- Buried treasure
function(rm) function(rm)
des.object({ des.object({ id = "chest", buried = true, contents = function(otmp)
id = "chest", buried = true,
contents = function(otmp)
local xobj = otmp:totable(); local xobj = otmp:totable();
-- keep track of the last buried treasure -- keep track of the last buried treasure
if (xobj.NO_OBJ == nil) then if (xobj.NO_OBJ == nil) then
table.insert(postprocess, { handler = make_dig_engraving, table.insert(postprocess, { handler = make_dig_engraving, data = { x = xobj.ox, y = xobj.oy }});
data = { x = xobj.ox,
y = xobj.oy } });
end end
for i = 1, d(3, 4) do for i = 1, d(3,4) do
des.object(); des.object();
end end
end end });
});
end, end,
-- Buried zombies -- Buried zombies
@@ -234,9 +229,7 @@ themeroom_fills = {
if (pos.x > 0) then if (pos.x > 0) then
pos.x = pos.x + rm.region.x1 - 1; pos.x = pos.x + rm.region.x1 - 1;
pos.y = pos.y + rm.region.y1; pos.y = pos.y + rm.region.y1;
table.insert(postprocess, { handler = make_a_trap, table.insert(postprocess, { handler = make_a_trap, data = { type = "teleport", seen = true, coord = pos, teledest = 1 } });
data = { type = "teleport", seen = true,
coord = pos, teledest = 1 } });
end end
end end
end, end,
@@ -255,8 +248,7 @@ themerooms = {
function() function()
des.room({ type = "ordinary", w = 11,h = 9, filled = 1, des.room({ type = "ordinary", w = 11,h = 9, filled = 1,
contents = function() contents = function()
des.room({ type = "ordinary", x = 4, y = 3, w = 3, h = 3, des.room({ type = "ordinary", x = 4,y = 3, w = 3,h = 3, filled = 1,
filled = 1,
contents = function() contents = function()
des.door({ state="random", wall="all" }); des.door({ state="random", wall="all" });
end end
@@ -280,8 +272,7 @@ themerooms = {
-- Huge room, with another room inside (90%) -- Huge room, with another room inside (90%)
function() function()
des.room({ type = "ordinary", w = nh.rn2(10) + 11, h = nh.rn2(5) + 8, des.room({ type = "ordinary", w = nh.rn2(10)+11,h = nh.rn2(5)+8, filled = 1,
filled = 1,
contents = function() contents = function()
if (percent(90)) then if (percent(90)) then
des.room({ type = "ordinary", filled = 1, des.room({ type = "ordinary", filled = 1,
@@ -375,11 +366,9 @@ themerooms = {
if (percent(50)) then if (percent(50)) then
local mons = { "M", "V", "L", "Z" }; local mons = { "M", "V", "L", "Z" };
shuffle(mons); shuffle(mons);
des.monster({ class = mons[1], x=0, y=0, des.monster({ class = mons[1], x=0,y=0, waiting = 1 });
waiting = 1 });
else else
des.object({ id = "corpse", montype = "@", des.object({ id = "corpse", montype = "@", coord = {0,0} });
coord = {0,0} });
end end
if (percent(20)) then if (percent(20)) then
des.door({ state="secret", wall="all" }); des.door({ state="secret", wall="all" });
@@ -470,15 +459,13 @@ xxx-----]], contents = function(m) filler_region(1,1); end });
|.........| |.........|
|.........| |.........|
-----------]], contents = function(m) -----------]], contents = function(m)
if (percent(30)) then if (percent(30)) then
local terr = { "-", "P" }; local terr = { "-", "P" };
shuffle(terr); shuffle(terr);
des.replace_terrain({ region = {1,1, 9,9}, des.replace_terrain({ region = {1,1, 9,9}, fromterrain = "L", toterrain = terr[1] });
fromterrain = "L", toterrain = terr[1] }); end
end filler_region(1,1);
filler_region(1,1); end });
end
});
end, end,
-- Circular, small -- Circular, small
@@ -679,27 +666,24 @@ xx|.....|xx
}|..|} }|..|}
}|..|} }|..|}
}----} }----}
}}}}}}]], contents = function(m) des.region({ region = {3, 3, 3, 3}, }}}}}}]], contents = function(m) des.region({ region={3,3,3,3}, type="themed", irregular=true, filled=0, joined=false });
type = "themed", irregular = true, local nasty_undead = { "giant zombie", "ettin zombie", "vampire lord" };
filled = 0, joined = false });
local nasty_undead = { "giant zombie", "ettin zombie",
"vampire lord" };
local chest_spots = { { 2, 2 }, { 3, 2 }, { 2, 3 }, { 3, 3 } }; local chest_spots = { { 2, 2 }, { 3, 2 }, { 2, 3 }, { 3, 3 } };
shuffle(chest_spots) shuffle(chest_spots)
-- Guarantee an escape item inside one of the chests, to prevent the -- Guarantee an escape item inside one of the chests, to prevent the hero
-- hero falling in from above and becoming permanently stuck -- falling in from above and becoming permanently stuck
-- [cf. generate_way_out_method(sp_lev.c)]. -- [cf. generate_way_out_method(sp_lev.c)].
-- If the escape item is made of glass or crystal, make sure that -- If the escape item is made of glass or crystal, make sure that the
-- the chest isn't locked so that kicking it to gain access to its -- chest isn't locked so that kicking it to gain access to its contents
-- contents won't be necessary; otherwise retain lock state from -- won't be necessary; otherwise retain lock state from random creation.
-- random creation. "pick-axe", "dwarvish mattock" could be included -- "pick-axe", "dwarvish mattock" could be included in the list of escape
-- in list of escape items but don't normally generate in containers. -- items but don't normally generate in containers.
local escape_items = { local escape_items = {
"scroll of teleportation", "ring of teleportation", "scroll of teleportation", "ring of teleportation",
"wand of teleportation", "wand of digging" "wand of teleportation", "wand of digging"
}; };
local itm = obj.new( escape_items[math.random(#escape_items)] ); local itm = obj.new(escape_items[math.random(#escape_items)]);
local itmcls = itm:class() local itmcls = itm:class()
local box local box
if itmcls[ "material" ] == "glass" then if itmcls[ "material" ] == "glass" then
@@ -719,13 +703,12 @@ xx|.....|xx
shuffle(nasty_undead); shuffle(nasty_undead);
des.monster(nasty_undead[1], 2, 2); des.monster(nasty_undead[1], 2, 2);
des.exclusion({ type = "teleport", region = { 2,2, 3,3 } }); des.exclusion({ type = "teleport", region = { 2,2, 3,3 } });
end end });
}); -- des.map
end, end,
-- Twin businesses -- Twin businesses
{ {
mindiff = 4; -- arbitrary; needs to be greater than 1 since no shops on 1 mindiff = 4; -- arbitrary
contents = function() contents = function()
-- Due to the way room connections work in mklev.c, we must guarantee -- Due to the way room connections work in mklev.c, we must guarantee
-- that the "aisle" between the shops touches all four walls of the -- that the "aisle" between the shops touches all four walls of the
@@ -738,26 +721,18 @@ xx|.....|xx
northwest = function() return percent(50) and "north" or "west" end northwest = function() return percent(50) and "north" or "west" end
southwest = function() return percent(50) and "south" or "west" end southwest = function() return percent(50) and "south" or "west" end
placements = { placements = {
{ lx = 1, ly = 1, rx = 4, ry = 1, { lx = 1, ly = 1, rx = 4, ry = 1, lwall = "south", rwall = southeast() },
lwall = "south", rwall = southeast() }, { lx = 1, ly = 2, rx = 4, ry = 2, lwall = "north", rwall = northeast() },
{ lx = 1, ly = 2, rx = 4, ry = 2, { lx = 1, ly = 1, rx = 5, ry = 1, lwall = southeast(), rwall = southwest() },
lwall = "north", rwall = northeast() }, { lx = 1, ly = 1, rx = 5, ry = 2, lwall = southeast(), rwall = northwest() },
{ lx = 1, ly = 1, rx = 5, ry = 1, { lx = 1, ly = 2, rx = 5, ry = 1, lwall = northeast(), rwall = southwest() },
lwall = southeast(), rwall = southwest() }, { lx = 1, ly = 2, rx = 5, ry = 2, lwall = northeast(), rwall = northwest() },
{ lx = 1, ly = 1, rx = 5, ry = 2, { lx = 2, ly = 1, rx = 5, ry = 1, lwall = southwest(), rwall = "south" },
lwall = southeast(), rwall = northwest() }, { lx = 2, ly = 2, rx = 5, ry = 2, lwall = northwest(), rwall = "north" }
{ lx = 1, ly = 2, rx = 5, ry = 1,
lwall = northeast(), rwall = southwest() },
{ lx = 1, ly = 2, rx = 5, ry = 2,
lwall = northeast(), rwall = northwest() },
{ lx = 2, ly = 1, rx = 5, ry = 1,
lwall = southwest(), rwall = "south" },
{ lx = 2, ly = 2, rx = 5, ry = 2,
lwall = northwest(), rwall = "north" }
} }
ltype, rtype = "weapon shop", "armor shop" ltype,rtype = "weapon shop","armor shop"
if percent(50) then if percent(50) then
ltype, rtype = rtype, ltype ltype,rtype = rtype,ltype
end end
shopdoorstate = function() shopdoorstate = function()
if percent(1) then if percent(1) then
@@ -768,27 +743,25 @@ xx|.....|xx
return "open" return "open"
end end
end end
p = placements[ d(#placements) ] p = placements[d(#placements)]
des.room({ type = ltype, x = p["lx"], y = p["ly"], w = 3, h = 3, des.room({ type=ltype, x=p["lx"], y=p["ly"], w=3, h=3, filled=1, joined=false,
filled = 1, joined = false,
contents = function() contents = function()
des.door({ state = shopdoorstate(), des.door({ state=shopdoorstate(), wall=p["lwall"] })
wall = p["lwall"] })
end end
}); });
des.room({ type = rtype, x = p["rx"], y = p["ry"], w = 3, h = 3, des.room({ type=rtype, x=p["rx"], y=p["ry"], w=3, h=3, filled=1, joined=false,
filled = 1, joined = false,
contents = function() contents = function()
des.door({ state = shopdoorstate(), des.door({ state=shopdoorstate(), wall=p["rwall"] })
wall = p["rwall"] })
end end
}); });
end end
}); });
end end
}, },
}; };
function filler_region(x, y) function filler_region(x, y)
local rmtyp = "ordinary"; local rmtyp = "ordinary";
local func = nil; local func = nil;
@@ -796,8 +769,7 @@ function filler_region(x, y)
rmtyp = "themed"; rmtyp = "themed";
func = themeroom_fill; func = themeroom_fill;
end end
des.region({ region = {x,y,x,y}, type = rmtyp, irregular = true, filled = 1, des.region({ region={x,y,x,y}, type=rmtyp, irregular=true, filled=1, contents = func });
contents = func });
end end
function is_eligible(room, mkrm) function is_eligible(room, mkrm)
@@ -827,16 +799,14 @@ function themerooms_generate()
-- which may change on different levels because of level difficulty. -- which may change on different levels because of level difficulty.
if is_eligible(themerooms[i], nil) then if is_eligible(themerooms[i], nil) then
local this_frequency; local this_frequency;
if (type(themerooms[i]) == "table" and themerooms[i].frequency ~= nil) if (type(themerooms[i]) == "table" and themerooms[i].frequency ~= nil) then
then
this_frequency = themerooms[i].frequency; this_frequency = themerooms[i].frequency;
else else
this_frequency = 1; this_frequency = 1;
end end
total_frequency = total_frequency + this_frequency; total_frequency = total_frequency + this_frequency;
-- avoid rn2(0) if a room has freq 0 -- avoid rn2(0) if a room has freq 0
if this_frequency > 0 and nh.rn2(total_frequency) < this_frequency if this_frequency > 0 and nh.rn2(total_frequency) < this_frequency then
then
pick = i; pick = i;
end end
end end
@@ -867,16 +837,14 @@ function themeroom_fill(rm)
-- which may change on different levels because of level difficulty. -- which may change on different levels because of level difficulty.
if is_eligible(themeroom_fills[i], rm) then if is_eligible(themeroom_fills[i], rm) then
local this_frequency; local this_frequency;
if (type(themeroom_fills[i]) == "table" if (type(themeroom_fills[i]) == "table" and themeroom_fills[i].frequency ~= nil) then
and themeroom_fills[i].frequency ~= nil) then
this_frequency = themeroom_fills[i].frequency; this_frequency = themeroom_fills[i].frequency;
else else
this_frequency = 1; this_frequency = 1;
end end
total_frequency = total_frequency + this_frequency; total_frequency = total_frequency + this_frequency;
-- avoid rn2(0) if a room has freq 0 -- avoid rn2(0) if a room has freq 0
if this_frequency > 0 and nh.rn2(total_frequency) < this_frequency if this_frequency > 0 and nh.rn2(total_frequency) < this_frequency then
then
pick = i; pick = i;
end end
end end
@@ -901,12 +869,10 @@ function make_dig_engraving(data)
dig = " here"; dig = " here";
else else
if (tx < 0 or tx > 0) then if (tx < 0 or tx > 0) then
dig = string.format(" %i %s", math.abs(tx), dig = string.format(" %i %s", math.abs(tx), (tx > 0) and "east" or "west");
(tx > 0) and "east" or "west");
end end
if (ty < 0 or ty > 0) then if (ty < 0 or ty > 0) then
dig = dig .. string.format(" %i %s", math.abs(ty), dig = dig .. string.format(" %i %s", math.abs(ty), (ty > 0) and "south" or "north");
(ty > 0) and "south" or "north");
end end
end end
des.engraving({ coord = pos, type = "burn", text = "Dig" .. dig }); des.engraving({ coord = pos, type = "burn", text = "Dig" .. dig });
@@ -924,8 +890,7 @@ function make_a_trap(data)
local locs = selection.negate():filter_mapchar("."); local locs = selection.negate():filter_mapchar(".");
repeat repeat
data.teledest = locs:rndcoord(1); data.teledest = locs:rndcoord(1);
until (data.teledest.x ~= data.coord.x until (data.teledest.x ~= data.coord.x and data.teledest.y ~= data.coord.y);
and data.teledest.y ~= data.coord.y);
end end
des.trap(data); des.trap(data);
end end