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

Function lspo_map

src/sp_lev.c:6066–6319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6064}
6065
6066DISABLE_WARNING_UNREACHABLE_CODE
6067
6068/* map({ x = 10, y = 10, map = [[...]] }); */
6069/* map({ coord = {10, 10}, map = [[...]] }); */
6070/* map({ halign = "center", valign = "center", map = [[...]] }); */
6071/* map({ map = [[...]], contents = function(map) ... end }); */
6072/* map([[...]]) */
6073/* local selection = map( ... ); */
6074int
6075lspo_map(lua_State *L)
6076{
6077 /*
6078TODO: allow passing an array of strings as map data
6079TODO: handle if map lines aren't same length
6080TODO: gc.coder->croom needs to be updated
6081 */
6082
6083 static const char *const left_or_right[] = {
6084 "left", "half-left", "center", "half-right", "right", "none", NULL
6085 };
6086 static const int l_or_r2i[] = {
6087 SPLEV_LEFT, SPLEV_H_LEFT, SPLEV_CENTER, SPLEV_H_RIGHT,
6088 SPLEV_RIGHT, -1, -1
6089 };
6090 static const char *const top_or_bot[] = {
6091 "top", "center", "bottom", "none", NULL
6092 };
6093 static const int t_or_b2i[] = { TOP, SPLEV_CENTER, BOTTOM, -1, -1 };
6094 int lr, tb;
6095 lua_Integer x = -1, y = -1;
6096 struct mapfragment *mf;
6097 char *tmpstr;
6098 int argc = lua_gettop(L);
6099 boolean has_contents = FALSE;
6100 int tryct = 0;
6101 int ox, oy;
6102 boolean lit = FALSE;
6103 struct selectionvar *sel;
6104
6105 create_des_coder();
6106
6107 if (gi.in_mk_themerooms && gt.themeroom_failed)
6108 return 0;
6109
6110 if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
6111 tmpstr = dupstr(luaL_checkstring(L, 1));
6112 lr = tb = SPLEV_CENTER;
6113 mf = mapfrag_fromstr(tmpstr);
6114 free(tmpstr);
6115 } else {
6116 lcheck_param_table(L);
6117 lr = l_or_r2i[get_table_option(L, "halign", "none", left_or_right)];
6118 tb = t_or_b2i[get_table_option(L, "valign", "none", top_or_bot)];
6119 get_table_xy_or_coord(L, &x, &y);
6120 tmpstr = get_table_str(L, "map");
6121 lit = (boolean) get_table_boolean_opt(L, "lit", FALSE);
6122 lua_getfield(L, 1, "contents");
6123 if (lua_type(L, -1) == LUA_TFUNCTION) {

Callers

nothing calls this directly

Calls 15

create_des_coderFunction · 0.85
dupstrFunction · 0.85
mapfrag_fromstrFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_optionFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_strFunction · 0.85
get_table_boolean_optFunction · 0.85
nhl_errorFunction · 0.85
selection_newFunction · 0.85
somexFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected