MCPcopy Index your code
hub / github.com/NetHack/NetHack / nhl_gettrap

Function nhl_gettrap

src/nhlua.c:415–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

413/* local t = nh.gettrap(x,y); */
414/* local t = nh.gettrap({ x = 10, y = 10 }); */
415staticfn int
416nhl_gettrap(lua_State *L)
417{
418 lua_Integer lx, ly;
419 coordxy x, y;
420
421 if (!nhl_get_xy_params(L, &lx, &ly)) {
422 nhl_error(L, "Incorrect arguments");
423 /*NOTREACHED*/
424 return 0;
425 }
426 x = (coordxy) lx;
427 y = (coordxy) ly;
428 cvt_to_abscoord(&x, &y);
429
430 if (isok(x, y)) {
431 struct trap *ttmp = t_at(x, y);
432
433 if (ttmp) {
434 lua_newtable(L);
435
436 nhl_add_table_entry_int(L, "tx", ttmp->tx);
437 nhl_add_table_entry_int(L, "ty", ttmp->ty);
438 nhl_add_table_entry_int(L, "ttyp", ttmp->ttyp);
439 nhl_add_table_entry_str(L, "ttyp_name",
440 get_trapname_bytype(ttmp->ttyp));
441 nhl_add_table_entry_bool(L, "tseen", ttmp->tseen);
442 nhl_add_table_entry_bool(L, "madeby_u", ttmp->madeby_u);
443 nhl_add_table_entry_bool(L, "once", ttmp->once);
444 switch (ttmp->ttyp) {
445 case SQKY_BOARD:
446 nhl_add_table_entry_int(L, "tnote", ttmp->tnote);
447 break;
448 case ROLLING_BOULDER_TRAP:
449 nhl_add_table_entry_int(L, "launchx", ttmp->launch.x);
450 nhl_add_table_entry_int(L, "launchy", ttmp->launch.y);
451 nhl_add_table_entry_int(L, "launch2x", ttmp->launch2.x);
452 nhl_add_table_entry_int(L, "launch2y", ttmp->launch2.y);
453 break;
454 case PIT:
455 case SPIKED_PIT:
456 nhl_add_table_entry_int(L, "conjoined", ttmp->conjoined);
457 break;
458 }
459 return 1;
460 } else {
461 nhl_error(L, "No trap at location");
462 }
463 } else {
464 nhl_error(L, "Coordinates out of range");
465 }
466 return 0;
467}
468
469/* nh.deltrap(x,y); nh.deltrap({ x = 10, y = 15 }); */
470staticfn int

Callers

nothing calls this directly

Calls 9

nhl_get_xy_paramsFunction · 0.85
nhl_errorFunction · 0.85
cvt_to_abscoordFunction · 0.85
isokFunction · 0.85
t_atFunction · 0.85
nhl_add_table_entry_intFunction · 0.85
nhl_add_table_entry_strFunction · 0.85
get_trapname_bytypeFunction · 0.85
nhl_add_table_entry_boolFunction · 0.85

Tested by

no test coverage detected