| 4662 | } |
| 4663 | |
| 4664 | DISABLE_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); */ |
| 4670 | int |
| 4671 | lspo_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 { |
nothing calls this directly
no test coverage detected