The system of themed rooms currently makes it so that any themed room can potentially generate anywhere a themed room can be placed. This is problematic in the long run, since it makes it difficult to design new rooms that are an appropriate amount of challenge at all levels of the dungeon. (A few themed rooms already have this problem: a hero starting out on level 1 probably won't live very long when the neighboring room is full of giant spiders, or an arch-lich has generated in a mausoleum nearby). This commit adds optional "mindiff" and "maxdiff" properties for themerooms defined as tables and exposes level_difficulty() to Lua. A themeroom whose mindiff exceeds the current level difficulty, or whose maxdiff is lower than the current level difficulty, is prevented from being selected. Because the set of rooms eligible to generate on a given level is no longer fixed, the total frequency of all the rooms can't be computed once per game when the file is first parsed, as it was before. In place of this, the themerooms_generate() function now uses a reservoir sampling algorithm to choose a room from among the eligible rooms, weighted by frequency.
30 KiB
30 KiB