From 8e6cf385b1e214b68b99e2b484d9d456fc70c19f Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 7 Mar 2023 09:43:39 +0200 Subject: [PATCH] Fix subroom doors Doors weren't getting added to the correct subrooms in certain cases. Also fix one of the themerooms, because doors have to be added after subrooms; there was a possibility of no door to the subroom(s) in that themeroom, because the subrooms overwrote the doors in the parent room. Test case for the subroom doors: Large room, with a medium subroom, with a tiny subroom inside that. The doors go from outermost room <-> tiny innermost room <-> middle room. des.room({ type = "ordinary", x = 1, y = 1, w = 10, h = 10, contents = function() des.room({ type = "ordinary", w = 6, h = 6, x = 2, y = 2, contents = function() des.room({ type = "ordinary", w = 2, h = 2, x = 0, y = 0, contents = function() des.door({ state="random", wall="south", pos = 1 }); end }); des.door({ state="random", wall="north", pos = 1 }); end }); end }); Before this fix: ROOM: ndoors:1, subrooms:1 SUBROOM: ndoors:1, subrooms:1 SUBROOM: ndoors:1, subrooms:0 after this fix: ROOM: ndoors:1, subrooms:1 SUBROOM: ndoors:1, subrooms:1 SUBROOM: ndoors:2, subrooms:0 --- dat/themerms.lua | 8 ++++---- doc/lua.adoc | 1 + src/sp_lev.c | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dat/themerms.lua b/dat/themerms.lua index 60bdd1e02..caeaa8eea 100644 --- a/dat/themerms.lua +++ b/dat/themerms.lua @@ -235,10 +235,6 @@ themerooms = { local hei = math.random(math.floor(rm.height / 2), rm.height - 2); des.room({ type = "ordinary", w = wid,h = hei, filled = 1, contents = function() - des.door({ state="random", wall="all" }); - if (percent(15)) then - des.door({ state="random", wall="all" }); - end if (percent(90)) then des.room({ type = "ordinary", filled = 1, contents = function() @@ -249,6 +245,10 @@ themerooms = { end }); end + des.door({ state="random", wall="all" }); + if (percent(15)) then + des.door({ state="random", wall="all" }); + end end }); end diff --git a/doc/lua.adoc b/doc/lua.adoc index 5f447fe78..fa8be9f35 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -481,6 +481,7 @@ Example: === door Create a door at a coordinate on the map, or in a room's wall. +When adding a door to a <<_room>>, it must be added after the subrooms in the room. * state is one of "random", "open", "closed", "locked", "nodoor", "broken", or "secret", defaulting to "random". diff --git a/src/sp_lev.c b/src/sp_lev.c index e88fc0a9b..bfd86cc3b 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3974,6 +3974,9 @@ lspo_room(lua_State *L) if (tmpcr) { gc.coder->tmproomlist[gc.coder->n_subroom] = tmpcr; gc.coder->failed_room[gc.coder->n_subroom] = FALSE; + /* added a subroom, make parent room irregular */ + if (gc.coder->tmproomlist[gc.coder->n_subroom - 1]) + gc.coder->tmproomlist[gc.coder->n_subroom - 1]->irregular = TRUE; gc.coder->n_subroom++; update_croom(); lua_getfield(L, 1, "contents"); @@ -6007,11 +6010,14 @@ static void add_doors_to_room(struct mkroom *croom) { coordxy x, y; + int i; for (x = croom->lx - 1; x <= croom->hx + 1; x++) for (y = croom->ly - 1; y <= croom->hy + 1; y++) if (IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR) maybe_add_door(x, y, croom); + for (i = 0; i < croom->nsubrooms; i++) + add_doors_to_room(croom->sbrooms[i]); } DISABLE_WARNING_UNREACHABLE_CODE