]> granicus.if.org Git - nethack/commitdiff
Avoid calling rn2(0) when the first room(s) have frequency 0
authorcopperwater <aosdict@gmail.com>
Sat, 23 May 2020 21:11:36 +0000 (17:11 -0400)
committerPasi Kallinen <paxed@alt.org>
Tue, 29 Sep 2020 14:30:11 +0000 (17:30 +0300)
This probably won't happen in practice, but it is a good safeguard
if this ever does happen (it happened for me in debugging when I wished
to have no "regular" rooms and only generate themed rooms).

dat/themerms.lua

index 73d6e8367bafffddcb8956765ec3c49ef885c6ff..4f4f59029ef6331295e7c612c59e9ead814ea4f8 100644 (file)
@@ -576,7 +576,8 @@ function themerooms_generate()
             this_frequency = 1;
          end
          total_frequency = total_frequency + this_frequency;
-         if (nh.rn2(total_frequency) < this_frequency) then
+         -- avoid rn2(0) if a room has freq 0
+         if this_frequency > 0 and nh.rn2(total_frequency) < this_frequency then
             pick = i;
          end
       end