Add two new themeroom functions that are called when generating the level: pre_themerooms_generate and post_themerooms_generate, calles before and after themerooms_generate. Allow the buried treasure -themeroom to put down an engraving anywhere on the level, hinting at the location of the treasure. des.object contents function now gets the generated object passed to it as a parameter.
58 lines
1.4 KiB
Lua
58 lines
1.4 KiB
Lua
-- NetHack nhlib.lua $NHDT-Date: 1652196140 2022/05/10 15:22:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.4 $
|
|
-- Copyright (c) 2021 by Pasi Kallinen
|
|
-- NetHack may be freely redistributed. See license for details.
|
|
-- compatibility shim
|
|
math.random = function(...)
|
|
local arg = {...};
|
|
if (#arg == 1) then
|
|
return 1 + nh.rn2(arg[1]);
|
|
elseif (#arg == 2) then
|
|
return nh.random(arg[1], arg[2] + 1 - arg[1]);
|
|
else
|
|
-- we don't support reals
|
|
error("NetHack math.random requires at least one parameter");
|
|
end
|
|
end
|
|
|
|
function shuffle(list)
|
|
for i = #list, 2, -1 do
|
|
local j = math.random(i)
|
|
list[i], list[j] = list[j], list[i]
|
|
end
|
|
end
|
|
|
|
align = { "law", "neutral", "chaos" };
|
|
shuffle(align);
|
|
|
|
-- d(2,6) = 2d6
|
|
-- d(20) = 1d20 (single argument = implicit 1 die)
|
|
function d(dice, faces)
|
|
if (faces == nil) then
|
|
-- 1-arg form: argument "dice" is actually the number of faces
|
|
return math.random(1, dice)
|
|
else
|
|
local sum = 0
|
|
for i=1,dice do
|
|
sum = sum + math.random(1, faces)
|
|
end
|
|
return sum
|
|
end
|
|
end
|
|
|
|
-- percent(20) returns true 20% of the time
|
|
function percent(threshold)
|
|
return math.random(0, 99) < threshold
|
|
end
|
|
|
|
function monkfoodshop()
|
|
if (u.role == "Monk") then
|
|
return "health food shop";
|
|
end
|
|
return "food shop";
|
|
end
|
|
|
|
-- pline with variable number of arguments
|
|
function pline(fmt, ...)
|
|
nh.pline(string.format(fmt, table.unpack({...})));
|
|
end
|