Split themeroom shape from themeroom contents
Previously, the tetris-shaped rooms were always either normal rooms, or turned into shops or other special rooms in NetHack core. Now, the themed room lua code first picks the themed room (which can be a themed or shaped), and some of those will then pick a random filling (eg. ice floor, traps, corpses, 3 altars). Adds a new lua binding to create a selection picking locations in current room. The content-function in special level regions now get passed the room data as a parameter.
This commit is contained in:
24
src/nhlsel.c
24
src/nhlsel.c
@@ -17,6 +17,7 @@ static int l_selection_getpoint(lua_State *);
|
||||
static int l_selection_setpoint(lua_State *);
|
||||
static int l_selection_filter_percent(lua_State *);
|
||||
static int l_selection_rndcoord(lua_State *);
|
||||
static int l_selection_room(lua_State *);
|
||||
static int l_selection_getbounds(lua_State *);
|
||||
static boolean params_sel_2coords(lua_State *, struct selectionvar **,
|
||||
coordxy *, coordxy *, coordxy *, coordxy *);
|
||||
@@ -383,6 +384,28 @@ l_selection_rndcoord(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* local s = selection.room(); */
|
||||
static int
|
||||
l_selection_room(lua_State *L)
|
||||
{
|
||||
struct selectionvar *sel;
|
||||
int argc = lua_gettop(L);
|
||||
struct mkroom *croom = NULL;
|
||||
|
||||
if (argc == 1) {
|
||||
int i = luaL_checkinteger(L, -1);
|
||||
|
||||
croom = (i >= 0 && i < g.nroom) ? &g.rooms[i] : NULL;
|
||||
}
|
||||
|
||||
sel = selection_from_mkroom(croom);
|
||||
|
||||
l_selection_push_copy(L, sel);
|
||||
selection_free(sel, TRUE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* local rect = sel:bounds(); */
|
||||
static int
|
||||
l_selection_getbounds(lua_State *L)
|
||||
@@ -899,6 +922,7 @@ static const struct luaL_Reg l_selection_methods[] = {
|
||||
{ "gradient", l_selection_gradient },
|
||||
{ "iterate", l_selection_iterate },
|
||||
{ "bounds", l_selection_getbounds },
|
||||
{ "room", l_selection_room },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
22
src/sp_lev.c
22
src/sp_lev.c
@@ -6056,7 +6056,8 @@ lspo_region(lua_State *L)
|
||||
lua_getfield(L, 1, "contents");
|
||||
if (lua_type(L, -1) == LUA_TFUNCTION) {
|
||||
lua_remove(L, -2);
|
||||
if (nhl_pcall(L, 0, 0)){
|
||||
l_push_mkroom_table(L, troom);
|
||||
if (nhl_pcall(L, 1, 0)){
|
||||
impossible("Lua error: %s", lua_tostring(L, -1));
|
||||
}
|
||||
} else
|
||||
@@ -6664,6 +6665,25 @@ TODO: g.coder->croom needs to be updated
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct selectionvar *
|
||||
selection_from_mkroom(struct mkroom *croom)
|
||||
{
|
||||
struct selectionvar *sel = selection_new();
|
||||
coordxy x, y;
|
||||
|
||||
if (!croom && g.coder && g.coder->croom)
|
||||
croom = g.coder->croom;
|
||||
if (!croom)
|
||||
return sel;
|
||||
|
||||
for (y = croom->ly; y <= croom->hy; y++)
|
||||
for (x = croom->lx; x <= croom->hx; x++)
|
||||
if (isok(x, y) && !levl[x][y].edge
|
||||
&& levl[x][y].roomno == (croom - g.rooms) + ROOMOFFSET)
|
||||
selection_setpoint(x, y, sel, 1);
|
||||
return sel;
|
||||
}
|
||||
|
||||
void
|
||||
update_croom(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user