From 3427c43df26c1588b4e85dcf5fc89e56251c6616 Mon Sep 17 00:00:00 2001 From: copperwater Date: Sun, 23 Feb 2025 16:29:40 -0500 Subject: [PATCH] Guard against no themed rooms or fills being eligible to generate The themed room code previously assumed that on any given level, at least one room or fill would resolve as OK to generate there. However, that's not a great assumption to make, and if it happened to be broken, the first themed room or fill would arbitrarily be executed, even though it wasn't eligible. Fix that by setting the initial pick to nil, and raising an impossible if it's still nil after trying to choose a random room. --- dat/themerms.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dat/themerms.lua b/dat/themerms.lua index b7e0f1f0a..64c1b316e 100644 --- a/dat/themerms.lua +++ b/dat/themerms.lua @@ -936,7 +936,7 @@ function themerooms_generate() themerooms[actualrm].contents(); return end - local pick = 1; + local pick = nil; local total_frequency = 0; for i = 1, #themerooms do if (type(themerooms[i]) ~= "table") then @@ -957,6 +957,10 @@ function themerooms_generate() end end end + if pick == nil then + nh.impossible('no eligible themed rooms?') + return + end themerooms[pick].contents(); end @@ -995,7 +999,7 @@ function themeroom_fill(rm) end return end - local pick = 1; + local pick = nil; local total_frequency = 0; for i = 1, #themeroom_fills do if (type(themeroom_fills[i]) ~= "table") then @@ -1016,6 +1020,10 @@ function themeroom_fill(rm) end end end + if pick == nil then + nh.impossible('no eligible themed room fills?') + return + end themeroom_fills[pick].contents(rm); end