]> granicus.if.org Git - nethack/commitdiff
pull request #345 - theme room dimensions
authorPatR <rankin@nethack.org>
Thu, 24 Sep 2020 00:57:19 +0000 (17:57 -0700)
committerPatR <rankin@nethack.org>
Thu, 24 Sep 2020 00:57:19 +0000 (17:57 -0700)
"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

dat/themerms.lua
doc/fixes37.0
src/sp_lev.c

index acb826cee5f620130b10efc1933729bb3182fb5f..4b3947fe4fa2f893b9cf387a518b5472253491bc 100644 (file)
@@ -80,8 +80,8 @@ themerooms = {
    function()
       des.room({ type = "themed",
                  contents = function(rm)
-                    for x = 0, rm.width do
-                       for y = 0, rm.height do
+                    for x = 0, rm.width - 1 do
+                       for y = 0, rm.height - 1 do
                           if (percent(30)) then
                              if (percent(50)) then
                                 des.object("boulder");
@@ -99,8 +99,8 @@ themerooms = {
    function()
       des.room({ type = "themed",
                  contents = function(rm)
-                    for x = 0, rm.width do
-                       for y = 0, rm.height do
+                    for x = 0, rm.width - 1 do
+                       for y = 0, rm.height - 1 do
                           if (percent(30)) then
                              des.trap("web", x, y);
                           end
@@ -118,8 +118,8 @@ themerooms = {
                                     "land mine", "sleep gas", "rust",
                                     "anti magic" };
                     shuffle(traps);
-                    for x = 0, rm.width do
-                       for y = 0, rm.height do
+                    for x = 0, rm.width - 1 do
+                       for y = 0, rm.height - 1 do
                           if (percent(30)) then
                              des.trap(traps[1], x, y);
                           end
@@ -169,8 +169,8 @@ themerooms = {
                  contents = function(rm)
                     local terr = { "-", "-", "-", "-", "L", "P", "T" };
                     shuffle(terr);
-                    for x = 0, (rm.width - 3) / 4 do
-                       for y = 0, (rm.height - 3) / 4 do
+                    for x = 0, (rm.width / 4) - 1 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 + 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 });
@@ -219,7 +219,9 @@ themerooms = {
    function()
       des.room({ type = "themed", w = 5 + nh.rn2(3)*2, h = 5 + nh.rn2(3)*2,
                  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()
                                   if (percent(50)) then
                                      local mons = { "M", "V", "L", "Z" };
@@ -245,7 +247,8 @@ themerooms = {
                  contents = function(rm)
                     local feature = { "C", "L", "I", "P", "T" };
                     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,
index f343ce0c8a1dbfc3a4216f287182f50d3ad361ce..c0fc2b284d940fd81bcf5d10c8fe433b50d33d9c 100644 (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
 -----------------------------------
@@ -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']
 learn scroll of teleportation after reading even when random destination is
        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
        also included tty support
index d08888028dee46e3beb30d2252e7ee35cecdaebf..5d63476c2f6818e08725a7e322b55ebde76046d0 100755 (executable)
@@ -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 */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -3844,7 +3844,8 @@ lua_State *L;
                 lua_getfield(L, 1, "contents");
                 if (lua_type(L, -1) == LUA_TFUNCTION) {
                     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);
                 } else
                     lua_pop(L, 1);