| 4144 | } |
| 4145 | |
| 4146 | staticfn int |
| 4147 | l_create_stairway(lua_State *L, boolean using_ladder) |
| 4148 | { |
| 4149 | static const char *const stairdirs[] = { "down", "up", NULL }; |
| 4150 | static const int stairdirs2i[] = { 0, 1 }; |
| 4151 | int argc = lua_gettop(L); |
| 4152 | coordxy x = -1, y = -1; |
| 4153 | struct trap *badtrap; |
| 4154 | |
| 4155 | long scoord; |
| 4156 | int up = 0; /* default is down */ |
| 4157 | int ltype = lua_type(L, 1); |
| 4158 | |
| 4159 | create_des_coder(); |
| 4160 | |
| 4161 | if (argc == 1 && ltype == LUA_TTABLE) { |
| 4162 | lua_Integer ax = -1, ay = -1; |
| 4163 | lcheck_param_table(L); |
| 4164 | get_table_xy_or_coord(L, &ax, &ay); |
| 4165 | up = stairdirs2i[get_table_option(L, "dir", "down", stairdirs)]; |
| 4166 | x = (coordxy) ax; |
| 4167 | y = (coordxy) ay; |
| 4168 | } else { |
| 4169 | lua_Integer ix = -1, iy = -1; |
| 4170 | if (argc > 0 && ltype == LUA_TSTRING) { |
| 4171 | up = stairdirs2i[luaL_checkoption(L, 1, "down", stairdirs)]; |
| 4172 | lua_remove(L, 1); |
| 4173 | } |
| 4174 | nhl_get_xy_params(L, &ix, &iy); |
| 4175 | x = (coordxy) ix; |
| 4176 | y = (coordxy) iy; |
| 4177 | } |
| 4178 | |
| 4179 | if (x == -1 && y == -1) { |
| 4180 | set_ok_location_func(good_stair_loc); |
| 4181 | scoord = SP_COORD_PACK_RANDOM(0); |
| 4182 | } else |
| 4183 | scoord = SP_COORD_PACK(x, y); |
| 4184 | |
| 4185 | get_location_coord(&x, &y, DRY, gc.coder->croom, scoord); |
| 4186 | set_ok_location_func(NULL); |
| 4187 | if ((badtrap = t_at(x, y)) != 0) |
| 4188 | deltrap(badtrap); |
| 4189 | SpLev_Map[x][y] = 1; |
| 4190 | |
| 4191 | if (using_ladder) { |
| 4192 | levl[x][y].typ = LADDER; |
| 4193 | if (up) { |
| 4194 | d_level dest; |
| 4195 | |
| 4196 | dest.dnum = u.uz.dnum; |
| 4197 | dest.dlevel = u.uz.dlevel - 1; |
| 4198 | stairway_add(x, y, TRUE, TRUE, &dest); |
| 4199 | levl[x][y].ladder = LA_UP; |
| 4200 | } else { |
| 4201 | d_level dest; |
| 4202 | |
| 4203 | dest.dnum = u.uz.dnum; |
no test coverage detected