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

Function lspo_trap

src/sp_lev.c:4396–4470  ·  view source on GitHub ↗

trap({ type = "hole", x = 1, y = 1 }); */ trap({ type = "web", spider_on_web = 0 }); */ trap("hole", 3, 4); */ trap("level teleport", {5, 8}); */ trap("rust") */ trap(); */

Source from the content-addressed store, hash-verified

4394/* trap("rust") */
4395/* trap(); */
4396int
4397lspo_trap(lua_State *L)
4398{
4399 spltrap tmptrap;
4400 lua_Integer x, y;
4401 int argc = lua_gettop(L);
4402
4403 create_des_coder();
4404
4405 tmptrap.spider_on_web = TRUE;
4406 tmptrap.seen = FALSE;
4407 tmptrap.novictim = FALSE;
4408
4409 if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
4410 const char *trapstr = luaL_checkstring(L, 1);
4411
4412 tmptrap.type = get_traptype_byname(trapstr);
4413 x = y = -1;
4414 } else if (argc == 2 && lua_type(L, 1) == LUA_TSTRING
4415 && lua_type(L, 2) == LUA_TTABLE) {
4416 const char *trapstr = luaL_checkstring(L, 1);
4417
4418 tmptrap.type = get_traptype_byname(trapstr);
4419 (void) get_coord(L, 2, &x, &y);
4420 } else if (argc == 3) {
4421 const char *trapstr = luaL_checkstring(L, 1);
4422
4423 tmptrap.type = get_traptype_byname(trapstr);
4424 x = luaL_checkinteger(L, 2);
4425 y = luaL_checkinteger(L, 3);
4426 } else {
4427 lcheck_param_table(L);
4428
4429 get_table_xy_or_coord(L, &x, &y);
4430 tmptrap.type = get_table_traptype_opt(L, "type", -1);
4431 tmptrap.spider_on_web = get_table_boolean_opt(L, "spider_on_web", 1);
4432 tmptrap.seen = get_table_boolean_opt(L, "seen", FALSE);
4433 tmptrap.novictim = !get_table_boolean_opt(L, "victim", TRUE);
4434
4435 lua_getfield(L, -1, "launchfrom");
4436 if (lua_type(L, -1) == LUA_TTABLE) {
4437 lua_Integer lx = -1, ly = -1;
4438
4439 (void) get_coord(L, -1, &lx, &ly);
4440 lua_pop(L, 1);
4441 gl.launchplace.x = lx;
4442 gl.launchplace.y = ly;
4443 } else
4444 lua_pop(L, 1);
4445
4446 lua_getfield(L, -1, "teledest");
4447 if (lua_type(L, -1) == LUA_TTABLE) {
4448 lua_Integer lx = -1, ly = -1;
4449
4450 (void) get_coord(L, -1, &lx, &ly);
4451 lua_pop(L, 1);
4452 gl.launchplace.x = lx;
4453 gl.launchplace.y = ly;

Callers

nothing calls this directly

Calls 9

create_des_coderFunction · 0.85
get_traptype_bynameFunction · 0.85
get_coordFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_traptype_optFunction · 0.85
get_table_boolean_optFunction · 0.85
nhl_errorFunction · 0.85
create_trapFunction · 0.85

Tested by

no test coverage detected