From: Pasi Kallinen Date: Fri, 30 Jul 2021 13:35:33 +0000 (+0300) Subject: Debug flag allowing overwriting stairs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b080ea12c282c8c2ab1cf5797f07090180241aad;p=nethack Debug flag allowing overwriting stairs And using it in the movement tests, so running doesn't stop at stairs. --- diff --git a/include/flag.h b/include/flag.h index fa8ed6f58..cff075431 100644 --- a/include/flag.h +++ b/include/flag.h @@ -204,6 +204,7 @@ struct instance_flags { boolean window_inited; /* true if init_nhwindows() completed */ boolean vision_inited; /* true if vision is ready */ boolean sanity_check; /* run sanity checks */ + boolean debug_overwrite_stairs; /* debug: allow overwriting stairs */ boolean debug_mongen; /* debug: prevent monster generation */ boolean debug_hunger; /* debug: prevent hunger */ boolean mon_polycontrol; /* debug: control monster polymorphs */ diff --git a/include/sp_lev.h b/include/sp_lev.h index ae43d767b..920253543 100644 --- a/include/sp_lev.h +++ b/include/sp_lev.h @@ -196,11 +196,14 @@ struct mapfragment { char *data; }; +#define CAN_OVERWRITE_TERRAIN(ttyp) \ + (iflags.debug_overwrite_stairs || !((ttyp) == LADDER || (ttyp) == STAIRS)) + #define SET_TYPLIT(x, y, ttyp, llit) \ do { \ if ((x) >= 1 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \ - if ((ttyp) < MAX_TYPE && levl[(x)][(y)].typ != STAIRS \ - && levl[(x)][(y)].typ != LADDER) \ + if ((ttyp) < MAX_TYPE \ + && CAN_OVERWRITE_TERRAIN(levl[(x)][(y)].typ)) \ levl[(x)][(y)].typ = (ttyp); \ if ((ttyp) == LAVAPOOL) \ levl[(x)][(y)].lit = 1; \ diff --git a/src/nhlua.c b/src/nhlua.c index ba3834857..92b0808ea 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -974,7 +974,9 @@ nhl_doturn(lua_State *L) } /* set debugging flags. debugging use only, of course. */ -/* nh.debug_flags({ mongen = false, hunger = false }); */ +/* nh.debug_flags({ mongen = false, + hunger = false, + overwrite_stairs = true }); */ static int nhl_debug_flags(lua_State *L) { @@ -1004,6 +1006,12 @@ nhl_debug_flags(lua_State *L) iflags.debug_hunger = !(boolean)val; /* value in lua is negated */ } + /* allow overwriting stairs */ + val = get_table_boolean_opt(L, "overwrite_stairs", -1); + if (val != -1) { + iflags.debug_overwrite_stairs = (boolean)val; + } + return 0; } diff --git a/src/sp_lev.c b/src/sp_lev.c index 7cd2cd108..a73ed4f30 100755 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -2338,7 +2338,7 @@ create_altar(altar* a, struct mkroom* croom) /* check for existing features */ oldtyp = levl[x][y].typ; - if (oldtyp == STAIRS || oldtyp == LADDER) + if (!CAN_OVERWRITE_TERRAIN(oldtyp)) return; amask = sp_amask_to_amask(a->sp_amask); diff --git a/test/testmove.lua b/test/testmove.lua index 3e591e36b..b8d310e8e 100644 --- a/test/testmove.lua +++ b/test/testmove.lua @@ -13,12 +13,15 @@ local POS = { x = 10, y = 05 }; local number_pad = 0; function initlev() - nh.debug_flags({mongen = false, hunger = false }); + nh.debug_flags({mongen = false, hunger = false, overwrite_stairs = true }); des.level_flags("noflip"); des.reset_level(); des.level_init({ style = "solidfill", fg = ".", lit = true }); des.teleport_region({ region = {POS.x,POS.y,POS.x,POS.y}, region_islev = true, dir="both" }); des.finalize_level(); + for k, v in pairs(nh.stairways()) do + des.terrain(v.x - 1, v.y, "."); + end end function ctrl(key)