pull request #345 - theme room dimensions

"When a room is created and passed down to a contents function in
Lua, the width and height properties of that room are computed by
subtracting lx from hx and ly from hy, which means e.g. a room
which is 8 floor squares wide and 5 tall appears to the contents
function as having a width of 7 and height of 4.  This patch fixes
that off-by-one."

I don't understand the details here:  should a room's dimensions
include its boundary walls or just the inner amount?  This change
didn't seem to cause any problems so I've put it in.

Closes #345
This commit is contained in:
PatR
2020-09-23 17:57:19 -07:00
parent 10d80eb150
commit 9faaa1b25d
3 changed files with 18 additions and 13 deletions

View File

@@ -80,8 +80,8 @@ themerooms = {
function() function()
des.room({ type = "themed", des.room({ type = "themed",
contents = function(rm) contents = function(rm)
for x = 0, rm.width do for x = 0, rm.width - 1 do
for y = 0, rm.height do for y = 0, rm.height - 1 do
if (percent(30)) then if (percent(30)) then
if (percent(50)) then if (percent(50)) then
des.object("boulder"); des.object("boulder");
@@ -99,8 +99,8 @@ themerooms = {
function() function()
des.room({ type = "themed", des.room({ type = "themed",
contents = function(rm) contents = function(rm)
for x = 0, rm.width do for x = 0, rm.width - 1 do
for y = 0, rm.height do for y = 0, rm.height - 1 do
if (percent(30)) then if (percent(30)) then
des.trap("web", x, y); des.trap("web", x, y);
end end
@@ -118,8 +118,8 @@ themerooms = {
"land mine", "sleep gas", "rust", "land mine", "sleep gas", "rust",
"anti magic" }; "anti magic" };
shuffle(traps); shuffle(traps);
for x = 0, rm.width do for x = 0, rm.width - 1 do
for y = 0, rm.height do for y = 0, rm.height - 1 do
if (percent(30)) then if (percent(30)) then
des.trap(traps[1], x, y); des.trap(traps[1], x, y);
end end
@@ -169,8 +169,8 @@ themerooms = {
contents = function(rm) contents = function(rm)
local terr = { "-", "-", "-", "-", "L", "P", "T" }; local terr = { "-", "-", "-", "-", "L", "P", "T" };
shuffle(terr); shuffle(terr);
for x = 0, (rm.width - 3) / 4 do for x = 0, (rm.width / 4) - 1 do
for y = 0, (rm.height - 3) / 4 do for y = 0, (rm.height / 4) - 1 do
des.terrain({ x = x * 4 + 2, y = y * 4 + 2, typ = terr[1], lit = -2 }); des.terrain({ x = x * 4 + 2, y = y * 4 + 2, typ = terr[1], lit = -2 });
des.terrain({ x = x * 4 + 3, y = y * 4 + 2, typ = terr[1], lit = -2 }); des.terrain({ x = x * 4 + 3, y = y * 4 + 2, typ = terr[1], lit = -2 });
des.terrain({ x = x * 4 + 2, y = y * 4 + 3, typ = terr[1], lit = -2 }); des.terrain({ x = x * 4 + 2, y = y * 4 + 3, typ = terr[1], lit = -2 });
@@ -219,7 +219,9 @@ themerooms = {
function() function()
des.room({ type = "themed", w = 5 + nh.rn2(3)*2, h = 5 + nh.rn2(3)*2, des.room({ type = "themed", w = 5 + nh.rn2(3)*2, h = 5 + nh.rn2(3)*2,
contents = function(rm) contents = function(rm)
des.room({ type = "themed", x = (rm.width / 2), y = (rm.height / 2), w = 1, h = 1, joined = 0, des.room({ type = "themed",
x = (rm.width - 1) / 2, y = (rm.height - 1) / 2,
w = 1, h = 1, joined = 0,
contents = function() contents = function()
if (percent(50)) then if (percent(50)) then
local mons = { "M", "V", "L", "Z" }; local mons = { "M", "V", "L", "Z" };
@@ -245,7 +247,8 @@ themerooms = {
contents = function(rm) contents = function(rm)
local feature = { "C", "L", "I", "P", "T" }; local feature = { "C", "L", "I", "P", "T" };
shuffle(feature); shuffle(feature);
des.terrain(rm.width / 2, rm.height / 2, feature[1]); des.terrain((rm.width - 1) / 2, (rm.height - 1) / 2,
feature[1]);
end end
}); });
end, end,

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.307 $ $NHDT-Date: 1600863687 2020/09/23 12:21:27 $ NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.308 $ $NHDT-Date: 1600909016 2020/09/24 00:56:56 $
General Fixes and Modified Features General Fixes and Modified Features
----------------------------------- -----------------------------------
@@ -342,6 +342,7 @@ replace worm tail placement code that reportedly led to a sanity_check warning
[no actual code problem found; might be compiler bug for 'xchar'] [no actual code problem found; might be compiler bug for 'xchar']
learn scroll of teleportation after reading even when random destination is learn scroll of teleportation after reading even when random destination is
right by starting spot right by starting spot
fix off-by-one bug in dimensions of theme rooms
curses: 'msg_window' option wasn't functional for curses unless the binary curses: 'msg_window' option wasn't functional for curses unless the binary
also included tty support also included tty support

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 sp_lev.c $NHDT-Date: 1599434249 2020/09/06 23:17:29 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.202 $ */ /* NetHack 3.7 sp_lev.c $NHDT-Date: 1600909016 2020/09/24 00:56:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.203 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */ /* Copyright (c) 1989 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -3844,7 +3844,8 @@ lua_State *L;
lua_getfield(L, 1, "contents"); lua_getfield(L, 1, "contents");
if (lua_type(L, -1) == LUA_TFUNCTION) { if (lua_type(L, -1) == LUA_TFUNCTION) {
lua_remove(L, -2); lua_remove(L, -2);
l_push_wid_hei_table(L, tmpcr->hx - tmpcr->lx, tmpcr->hy - tmpcr->ly); l_push_wid_hei_table(L, 1 + tmpcr->hx - tmpcr->lx,
1 + tmpcr->hy - tmpcr->ly);
lua_call(L, 1, 0); lua_call(L, 1, 0);
} else } else
lua_pop(L, 1); lua_pop(L, 1);