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

Function nhl_getmap

src/nhlua.c:529–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

527/* local loc = nh.getmap(x,y); */
528/* local loc = nh.getmap({ x = 10, y = 35 }); */
529staticfn int
530nhl_getmap(lua_State *L)
531{
532 lua_Integer lx, ly;
533 coordxy x, y;
534
535 if (!nhl_get_xy_params(L, &lx, &ly)) {
536 nhl_error(L, "Incorrect arguments");
537 return 0;
538 }
539 x = (coordxy) lx;
540 y = (coordxy) ly;
541 cvt_to_abscoord(&x, &y);
542
543 if (isok(x, y)) {
544 char buf[BUFSZ];
545 lua_newtable(L);
546
547 /* FIXME: some should be boolean values */
548 nhl_add_table_entry_int(L, "glyph", levl[x][y].glyph);
549 nhl_add_table_entry_int(L, "typ", levl[x][y].typ);
550 nhl_add_table_entry_str(L, "typ_name",
551 levltyp_to_name(levl[x][y].typ));
552 Sprintf(buf, "%c", splev_typ2chr(levl[x][y].typ));
553 nhl_add_table_entry_str(L, "mapchr", buf);
554 nhl_add_table_entry_int(L, "seenv", levl[x][y].seenv);
555 nhl_add_table_entry_bool(L, "horizontal", levl[x][y].horizontal);
556 nhl_add_table_entry_bool(L, "lit", levl[x][y].lit);
557 nhl_add_table_entry_bool(L, "waslit", levl[x][y].waslit);
558 nhl_add_table_entry_int(L, "roomno", levl[x][y].roomno);
559 nhl_add_table_entry_bool(L, "edge", levl[x][y].edge);
560 nhl_add_table_entry_bool(L, "candig", levl[x][y].candig);
561
562 nhl_add_table_entry_bool(L, "has_trap", t_at(x, y) ? 1 : 0);
563
564 /* TODO: FIXME: levl[x][y].flags */
565
566 lua_pushliteral(L, "flags");
567 lua_newtable(L);
568
569 if (IS_DOOR(levl[x][y].typ)) {
570 nhl_add_table_entry_bool(L, "nodoor",
571 (levl[x][y].flags == D_NODOOR));
572 nhl_add_table_entry_bool(L, "broken",
573 (levl[x][y].flags & D_BROKEN));
574 nhl_add_table_entry_bool(L, "isopen",
575 (levl[x][y].flags & D_ISOPEN));
576 nhl_add_table_entry_bool(L, "closed",
577 (levl[x][y].flags & D_CLOSED));
578 nhl_add_table_entry_bool(L, "locked",
579 (levl[x][y].flags & D_LOCKED));
580 nhl_add_table_entry_bool(L, "trapped",
581 (levl[x][y].flags & D_TRAPPED));
582 } else if (IS_ALTAR(levl[x][y].typ)) {
583 /* TODO: bits 0, 1, 2 */
584 nhl_add_table_entry_bool(L, "shrine",
585 (levl[x][y].flags & AM_SHRINE));
586 } else if (IS_THRONE(levl[x][y].typ)) {

Callers

nothing calls this directly

Calls 10

nhl_get_xy_paramsFunction · 0.85
nhl_errorFunction · 0.85
cvt_to_abscoordFunction · 0.85
isokFunction · 0.85
nhl_add_table_entry_intFunction · 0.85
nhl_add_table_entry_strFunction · 0.85
levltyp_to_nameFunction · 0.85
splev_typ2chrFunction · 0.85
nhl_add_table_entry_boolFunction · 0.85
t_atFunction · 0.85

Tested by

no test coverage detected