From 18dc88505d70ffdbc712ebddc3f23173f0280e09 Mon Sep 17 00:00:00 2001 From: copperwater Date: Thu, 18 Feb 2021 18:55:10 -0500 Subject: [PATCH] Convert room 'joined' and 'needjoining' into booleans des.region() accepted booleans for the joined field, whereas des.room accepted xchars. These were only being used as truth values, so this converts the room ones into booleans for consistency. I don't think accidentally using an int or a boolean wrongly would actually crash the level generator, but consistency is good. This converts an schar field in struct mkroom into a boolean; on most systems these are probably 1-byte types and save files won't be broken, but it might be best to treat this as a save breaker anyway. --- dat/themerms.lua | 6 +++--- doc/lua.adoc | 4 ++-- include/mkroom.h | 2 +- include/sp_lev.h | 3 ++- src/mklev.c | 2 +- src/sp_lev.c | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dat/themerms.lua b/dat/themerms.lua index fa85a44df..0004ff36a 100644 --- a/dat/themerms.lua +++ b/dat/themerms.lua @@ -229,7 +229,7 @@ themerooms = { contents = function(rm) des.room({ type = "themed", x = (rm.width - 1) / 2, y = (rm.height - 1) / 2, - w = 1, h = 1, joined = 0, + w = 1, h = 1, joined = false, contents = function() if (percent(50)) then local mons = { "M", "V", "L", "Z" }; @@ -583,12 +583,12 @@ end }); end end p = placements[d(#placements)] - des.room({ type=ltype, x=p["lx"], y=p["ly"], w=3, h=3, filled=1, joined=0, + des.room({ type=ltype, x=p["lx"], y=p["ly"], w=3, h=3, filled=1, joined=false, contents = function() des.door({ state=shopdoorstate(), wall=p["lwall"] }) end }); - des.room({ type=rtype, x=p["rx"], y=p["ry"], w=3, h=3, filled=1, joined=0, + des.room({ type=rtype, x=p["rx"], y=p["ry"], w=3, h=3, filled=1, joined=false, contents = function() des.door({ state=shopdoorstate(), wall=p["rwall"] }) end diff --git a/doc/lua.adoc b/doc/lua.adoc index 5a8ef3c78..564205d02 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -368,7 +368,7 @@ Initialize the map with a random generator of a certain type. Example: des.level_init({ style = "solidfill", fg = " " }); - des.level_init({ style = "mines", fg = ".", bg = "}", smoothed=1, joined=1, lit=0 }) + des.level_init({ style = "mines", fg = ".", bg = "}", smoothed=true, joined=true, lit=0 }) des.level_init({ style = "maze", corrwid = 3, wallthick = 1, deadends = false }); === levregion @@ -553,7 +553,7 @@ fields: | yalign | Vertical alignment on a rough 3x3 grid. Default is "random". | lit | Is the room lit or unlit? Defaults to -1 (random). | filled | Is the room filled as per the room type. Defaults to 1 (filled). -| joined | Is the room joined to the rest of the level with corridors? Default is 1 (joined). +| joined | Is the room joined to the rest of the level with corridors? Default is true. | contents | A function called with one parameter, a table with "width" and "height", the room width and height, excluding the walls. All coordinates in the function will be relative to the room. |=== diff --git a/include/mkroom.h b/include/mkroom.h index 07d2318aa..8f184ab67 100644 --- a/include/mkroom.h +++ b/include/mkroom.h @@ -14,7 +14,7 @@ struct mkroom { schar orig_rtype; /* same as rtype, but not zeroed later */ schar rlit; /* is the room lit ? */ schar needfill; /* sp_lev: does the room need filling? */ - schar needjoining; /* sp_lev */ + boolean needjoining; /* sp_lev: should the room connect to others? */ schar doorct; /* door count */ schar fdoor; /* index for the first door of the room */ schar nsubrooms; /* number of subrooms */ diff --git a/include/sp_lev.h b/include/sp_lev.h index 3121d543c..b27adb874 100644 --- a/include/sp_lev.h +++ b/include/sp_lev.h @@ -185,7 +185,8 @@ typedef struct _room { Str_or_Len parent; xchar x, y, w, h; xchar xalign, yalign; - xchar rtype, chance, rlit, needfill, joined; + xchar rtype, chance, rlit, needfill; + boolean joined; } room; struct mapfragment { diff --git a/src/mklev.c b/src/mklev.c index bfba3e0ce..dde1b8165 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -65,7 +65,7 @@ mkroom_cmp(const genericptr vx, const genericptr vy) } /* Return TRUE if a door placed at (x, y) which otherwise passes okdoor() - * checks would be connecting into an area that was declared as joined = 0. + * checks would be connecting into an area that was declared as joined = false. * Checking for this in finddpos() enables us to have rooms with sub-areas * (such as shops) that will never randomly generate unwanted doors in order * to connect them up to other areas. diff --git a/src/sp_lev.c b/src/sp_lev.c index 58026e76e..efbc5d339 100755 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3480,7 +3480,7 @@ lspo_level_flags(lua_State* L) } /* level_init({ style = "solidfill", fg = " " }); */ -/* level_init({ style = "mines", fg = ".", bg = "}", smoothed=1, joined=1, lit=0 }) */ +/* level_init({ style = "mines", fg = ".", bg = "}", smoothed=true, joined=true, lit=0 }) */ int lspo_level_init(lua_State* L) { @@ -3694,7 +3694,7 @@ lspo_room(lua_State* L) tmproom.rlit = get_table_int_opt(L, "lit", -1); /* theme rooms default to unfilled */ tmproom.needfill = get_table_int_opt(L, "filled", g.in_mk_themerooms ? 0 : 1); - tmproom.joined = get_table_int_opt(L, "joined", 1); + tmproom.joined = get_table_boolean_opt(L, "joined", TRUE); if (!g.coder->failed_room[g.coder->n_subroom - 1]) { tmpcr = build_room(&tmproom, g.coder->croom); @@ -5430,7 +5430,7 @@ lspo_region(lua_State* L) * "lvflags_only" ==> filled=2, probably in a get_table_needfill_opt */ needfill = get_table_int_opt(L, "filled", 0); irregular = get_table_boolean_opt(L, "irregular", 0); - joined = get_table_boolean_opt(L, "joined", 1); + joined = get_table_boolean_opt(L, "joined", TRUE); do_arrival_room = get_table_boolean_opt(L, "arrival_room", 0); rtype = get_table_roomtype_opt(L, "type", OROOM); rlit = get_table_int_opt(L, "lit", -1); -- 2.50.1