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

Function l_create_stairway

src/sp_lev.c:4146–4213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4144}
4145
4146staticfn int
4147l_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;

Callers 2

lspo_stairFunction · 0.85
lspo_ladderFunction · 0.85

Calls 11

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_optionFunction · 0.85
nhl_get_xy_paramsFunction · 0.85
set_ok_location_funcFunction · 0.85
get_location_coordFunction · 0.85
t_atFunction · 0.85
deltrapFunction · 0.85
stairway_addFunction · 0.85
mkstairsFunction · 0.85

Tested by

no test coverage detected