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

Function lspo_replace_terrain

src/sp_lev.c:5050–5143  ·  view source on GitHub ↗

* replace_terrain({ x1=NN,y1=NN, x2=NN,y2=NN, fromterrain=MAPCHAR, * toterrain=MAPCHAR, lit=N, chance=NN }); * replace_terrain({ region={x1,y1, x2,y2}, fromterrain=MAPCHAR, * toterrain=MAPCHAR, lit=N, chance=NN }); * replace_terrain({ selection=selection.area(2,5, 40,10), * fromterrain=MAPCHAR, toterrain=MAPCHAR }); * replace_terrain({ se

Source from the content-addressed store, hash-verified

5048 * toterrain=MAPCHAR });
5049 */
5050int
5051lspo_replace_terrain(lua_State *L)
5052{
5053 coordxy totyp, fromtyp;
5054 struct mapfragment *mf = NULL;
5055 struct selectionvar *sel = NULL;
5056 boolean freesel = FALSE;
5057 coordxy x, y;
5058 lua_Integer x1, y1, x2, y2;
5059 int chance;
5060 int tolit;
5061 NhRect rect = cg.zeroNhRect;
5062
5063 create_des_coder();
5064
5065 lcheck_param_table(L);
5066
5067 totyp = get_table_mapchr(L, "toterrain");
5068
5069 if (totyp >= MAX_TYPE)
5070 return 0;
5071
5072 fromtyp = get_table_mapchr_opt(L, "fromterrain", INVALID_TYPE);
5073
5074 if (fromtyp == INVALID_TYPE) {
5075 const char *err;
5076 char *tmpstr = get_table_str(L, "mapfragment");
5077 mf = mapfrag_fromstr(tmpstr);
5078 free(tmpstr);
5079
5080 if ((err = mapfrag_error(mf)) != NULL) {
5081 nhl_error(L, err);
5082 /*NOTREACHED*/
5083 }
5084 }
5085
5086 chance = get_table_int_opt(L, "chance", 100);
5087 tolit = get_table_int_opt(L, "lit", SET_LIT_NOCHANGE);
5088 x1 = get_table_int_opt(L, "x1", -1);
5089 y1 = get_table_int_opt(L, "y1", -1);
5090 x2 = get_table_int_opt(L, "x2", -1);
5091 y2 = get_table_int_opt(L, "y2", -1);
5092
5093 if (x1 == -1 && y1 == -1 && x2 == -1 && y2 == -1) {
5094 get_table_region(L, "region", &x1, &y1, &x2, &y2, TRUE);
5095 }
5096
5097 if (x1 == -1 && y1 == -1 && x2 == -1 && y2 == -1) {
5098 lua_getfield(L, 1, "selection");
5099 if (lua_type(L, -1) != LUA_TNIL)
5100 sel = l_selection_check(L, -1);
5101 lua_pop(L, 1);
5102 }
5103
5104 if (!sel) {
5105 sel = selection_new();
5106 freesel = TRUE;
5107

Callers

nothing calls this directly

Calls 15

create_des_coderFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_mapchrFunction · 0.85
get_table_mapchr_optFunction · 0.85
get_table_strFunction · 0.85
mapfrag_fromstrFunction · 0.85
mapfrag_errorFunction · 0.85
nhl_errorFunction · 0.85
get_table_int_optFunction · 0.85
get_table_regionFunction · 0.85
l_selection_checkFunction · 0.85
selection_newFunction · 0.85

Tested by

no test coverage detected