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.
This commit is contained in:
copperwater
2025-04-11 16:27:34 -07:00
committed by PatR
parent 47e6edc663
commit 3427c43df2
+10 -2
View File
@@ -936,7 +936,7 @@ function themerooms_generate()
themerooms[actualrm].contents(); themerooms[actualrm].contents();
return return
end end
local pick = 1; local pick = nil;
local total_frequency = 0; local total_frequency = 0;
for i = 1, #themerooms do for i = 1, #themerooms do
if (type(themerooms[i]) ~= "table") then if (type(themerooms[i]) ~= "table") then
@@ -957,6 +957,10 @@ function themerooms_generate()
end end
end end
end end
if pick == nil then
nh.impossible('no eligible themed rooms?')
return
end
themerooms[pick].contents(); themerooms[pick].contents();
end end
@@ -995,7 +999,7 @@ function themeroom_fill(rm)
end end
return return
end end
local pick = 1; local pick = nil;
local total_frequency = 0; local total_frequency = 0;
for i = 1, #themeroom_fills do for i = 1, #themeroom_fills do
if (type(themeroom_fills[i]) ~= "table") then if (type(themeroom_fills[i]) ~= "table") then
@@ -1016,6 +1020,10 @@ function themeroom_fill(rm)
end end
end end
end end
if pick == nil then
nh.impossible('no eligible themed room fills?')
return
end
themeroom_fills[pick].contents(rm); themeroom_fills[pick].contents(rm);
end end