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

Function lspo_terrain

src/sp_lev.c:4977–5038  ·  view source on GitHub ↗

* [lit_state: 1 On, 0 Off, -1 random, -2 leave as-is] * terrain({ x=NN, y=NN, typ=MAPCHAR, lit=lit_state }); * terrain({ coord={X, Y}, typ=MAPCHAR, lit=lit_state }); * terrain({ selection=SELECTION, typ=MAPCHAR, lit=lit_state }); * terrain( SELECTION, MAPCHAR [, lit_state ] ); * terrain({x,y}, MAPCHAR); * terrain(x,y, MAPCHAR); */

Source from the content-addressed store, hash-verified

4975 * terrain(x,y, MAPCHAR);
4976 */
4977int
4978lspo_terrain(lua_State *L)
4979{
4980 terrain tmpterrain;
4981 coordxy x = 0, y = 0;
4982 struct selectionvar *sel = NULL;
4983 int argc = lua_gettop(L);
4984
4985 create_des_coder();
4986 tmpterrain.tlit = SET_LIT_NOCHANGE;
4987 tmpterrain.ter = INVALID_TYPE;
4988
4989 if (argc == 1) {
4990 lua_Integer tx, ty;
4991 lcheck_param_table(L);
4992
4993 get_table_xy_or_coord(L, &tx, &ty);
4994 x = tx, y = ty;
4995 if (tx == -1 && ty == -1) {
4996 lua_getfield(L, 1, "selection");
4997 sel = l_selection_check(L, -1);
4998 lua_pop(L, 1);
4999 }
5000 tmpterrain.ter = get_table_mapchr(L, "typ");
5001 tmpterrain.tlit = get_table_int_opt(L, "lit", SET_LIT_NOCHANGE);
5002 } else if (argc == 2 && lua_type(L, 1) == LUA_TTABLE
5003 && lua_type(L, 2) == LUA_TSTRING) {
5004 lua_Integer tx, ty;
5005 tmpterrain.ter = check_mapchr(luaL_checkstring(L, 2));
5006 lua_pop(L, 1);
5007 (void) get_coord(L, 1, &tx, &ty);
5008 x = tx;
5009 y = ty;
5010 } else if (argc == 2) {
5011 sel = l_selection_check(L, 1);
5012 tmpterrain.ter = check_mapchr(luaL_checkstring(L, 2));
5013 } else if (argc == 3) {
5014 x = luaL_checkinteger(L, 1);
5015 y = luaL_checkinteger(L, 2);
5016 tmpterrain.ter = check_mapchr(luaL_checkstring(L, 3));
5017 } else {
5018 nhl_error(L, "wrong parameters");
5019 }
5020
5021 if (tmpterrain.ter == INVALID_TYPE)
5022 nhl_error(L, "Erroneous map char");
5023
5024 if (sel) {
5025 selection_iterate(sel, sel_set_ter, (genericptr_t) &tmpterrain);
5026 } else {
5027 get_location_coord(&x, &y, ANY_LOC, gc.coder->croom,
5028 SP_COORD_PACK(x, y));
5029 if (!isok(x, y)) {
5030 nhl_error(L, "terrain coord not ok");
5031 /*NOTREACHED*/
5032 return 0;
5033 }
5034 sel_set_ter(x, y, (genericptr_t) &tmpterrain);

Callers

nothing calls this directly

Calls 13

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
l_selection_checkFunction · 0.85
get_table_mapchrFunction · 0.85
get_table_int_optFunction · 0.85
check_mapchrFunction · 0.85
get_coordFunction · 0.85
nhl_errorFunction · 0.85
selection_iterateFunction · 0.85
get_location_coordFunction · 0.85
isokFunction · 0.85

Tested by

no test coverage detected