MCPcopy Create free account
hub / github.com/NetHack/NetHack / lspo_door

Function lspo_door

src/sp_lev.c:4664–4734  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4662}
4663
4664DISABLE_WARNING_UNREACHABLE_CODE
4665
4666/* door({ x = 1, y = 1, state = "nodoor" }); */
4667/* door({ coord = {1, 1}, state = "nodoor" }); */
4668/* door({ wall = "north", pos = 3, state="secret" }); */
4669/* door("nodoor", 1, 2); */
4670int
4671lspo_door(lua_State *L)
4672{
4673 static const char *const doorstates[] = {
4674 "random", "open", "closed", "locked", "nodoor", "broken",
4675 "secret", NULL
4676 };
4677 static const int doorstates2i[] = {
4678 -1, D_ISOPEN, D_CLOSED, D_LOCKED, D_NODOOR, D_BROKEN, D_SECRET
4679 };
4680 int msk;
4681 coordxy x, y;
4682 coordxy typ;
4683 int argc = lua_gettop(L);
4684
4685 create_des_coder();
4686
4687 if (argc == 3) {
4688 msk = doorstates2i[luaL_checkoption(L, 1, "random", doorstates)];
4689 x = luaL_checkinteger(L, 2);
4690 y = luaL_checkinteger(L, 3);
4691
4692 } else {
4693 lua_Integer dx, dy;
4694 lcheck_param_table(L);
4695
4696 get_table_xy_or_coord(L, &dx, &dy);
4697 x = dx, y = dy;
4698 msk = doorstates2i[get_table_option(L, "state", "random",
4699 doorstates)];
4700 }
4701
4702 typ = (msk == -1) ? rnddoor() : (coordxy) msk;
4703
4704 if (x == -1 && y == -1) {
4705 static const char *const walldirs[] = {
4706 "all", "random", "north", "west", "east", "south", NULL
4707 };
4708 /* Note that "random" is also W_ANY, because create_door just wants a
4709 * mask of acceptable walls */
4710 static const int walldirs2i[] = {
4711 W_ANY, W_ANY, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0
4712 };
4713 room_door tmpd;
4714
4715 tmpd.secret = (typ == D_SECRET) ? 1 : 0;
4716 tmpd.mask = msk;
4717 tmpd.pos = get_table_int_opt(L, "pos", -1);
4718 tmpd.wall = walldirs2i[get_table_option(L, "wall", "all", walldirs)];
4719
4720 create_door(&tmpd, gc.coder->croom);
4721 } else {

Callers

nothing calls this directly

Calls 11

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_optionFunction · 0.85
rnddoorFunction · 0.85
get_table_int_optFunction · 0.85
create_doorFunction · 0.85
get_location_coordFunction · 0.85
isokFunction · 0.85
nhl_errorFunction · 0.85
sel_set_doorFunction · 0.85

Tested by

no test coverage detected