Enable generating specific themed rooms for debugging
A common pain point I encounter when working on themed rooms is making specific rooms generate. The only ways to do this were mass commenting out the rooms not being tested, or hacking in different room frequency values (even more annoying when testing a fill, not a room, or testing pure-function rooms/fills that have no frequency). This change solves that problem by allowing a wizard-mode user to define THEMERM or THEMERMFILL environment variables to make specific rooms or fills generate. The first part of this change is converting all themed rooms and fills that were plain functions into tables, and converting their comment names into actual names in those tables. The names are not intended to be shown during gameplay, but instead serve as values that THEMERM or THEMERMFILL can be matched to to generate those rooms. It's no longer possible to have a function themeroom; this will raise an impossible. As far as I'm concerned, this is a good change because it allows some code simplification of themerooms_generate and makes it easier to add difficulty or eligibility parameters to rooms. The second part of this change is adding a new nh.debug_themerm function to make the environment variable values accessible to themerms.lua. I looked for an existing way to do this but didn't see one (nh.variable is the closest but appears to be for variables that get saved). The final part is inserting behavior into the actual themeroom generation code that changes how they generate when either a room or a fill is set. I don't think it's safe to generate every single room with the requested type or fill - that might lead to cases where the stairs or a magic portal cannot generate. So it creates ordinary rooms half of the time, which still results in plenty of themed rooms on levels. Another thing to note is that any themed room using filler_region will still only pick a fill 30% of the time. If one specifies both a fill and a room that uses filler_region, many of those rooms will appear without a themed fill.
This commit is contained in:
1061
dat/themerms.lua
1061
dat/themerms.lua
File diff suppressed because it is too large
Load Diff
26
src/nhlua.c
26
src/nhlua.c
@@ -65,6 +65,7 @@ staticfn int nhl_rn2(lua_State *);
|
||||
staticfn int nhl_random(lua_State *);
|
||||
staticfn int nhl_level_difficulty(lua_State *);
|
||||
staticfn int nhl_is_genocided(lua_State *);
|
||||
staticfn int nhl_get_debug_themerm_name(lua_State *);
|
||||
staticfn void init_nhc_data(lua_State *);
|
||||
staticfn int nhl_push_anything(lua_State *, int, void *);
|
||||
staticfn int nhl_meta_u_index(lua_State *);
|
||||
@@ -975,6 +976,30 @@ nhl_is_genocided(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* local debug_themerm = nh.debug_themerm(isfill)
|
||||
* if isfill is false, returns value of env variable THEMERM
|
||||
* if isfill is true, returns value of env variable THEMERMFILL
|
||||
* return nil if not in wizard mode or the variable isn't set */
|
||||
staticfn int
|
||||
nhl_get_debug_themerm_name(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1) {
|
||||
char *dbg_themerm = (char *) 0;
|
||||
boolean is_fill = lua_toboolean(L, 1);
|
||||
lua_pop(L, 1);
|
||||
if (wizard)
|
||||
dbg_themerm = getenv(is_fill ? "THEMERMFILL" : "THEMERM");
|
||||
if (!dbg_themerm || strlen(dbg_themerm) == 0) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
lua_pushstring(L, dbg_themerm);
|
||||
}
|
||||
} else {
|
||||
nhl_error(L, "debug_themerm should have 1 boolean arg");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
RESTORE_WARNING_UNREACHABLE_CODE
|
||||
|
||||
@@ -1754,6 +1779,7 @@ static const struct luaL_Reg nhl_functions[] = {
|
||||
{ "random", nhl_random },
|
||||
{ "level_difficulty", nhl_level_difficulty },
|
||||
{ "is_genocided", nhl_is_genocided },
|
||||
{ "debug_themerm", nhl_get_debug_themerm_name },
|
||||
{ "parse_config", nhl_parse_config },
|
||||
{ "get_config", nhl_get_config },
|
||||
{ "get_config_errors", l_get_config_errors },
|
||||
|
||||
Reference in New Issue
Block a user