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

Function lspo_feature

src/sp_lev.c:4843–4923  ·  view source on GitHub ↗

feature("fountain", x, y); */ feature("fountain", {x,y}); */ feature({ type="fountain", x=NN, y=NN }); */ feature({ type="fountain", coord={NN, NN} }); */ feature({ type="tree", coord={NN, NN}, swarm=true, looted=false }); */

Source from the content-addressed store, hash-verified

4841/* feature({ type="fountain", coord={NN, NN} }); */
4842/* feature({ type="tree", coord={NN, NN}, swarm=true, looted=false }); */
4843int
4844lspo_feature(lua_State *L)
4845{
4846 static const char *const features[] = { "fountain", "sink", "pool",
4847 "throne", "tree", NULL };
4848 static const int features2i[] = { FOUNTAIN, SINK, POOL,
4849 THRONE, TREE, STONE };
4850 coordxy x, y;
4851 int typ;
4852 int argc = lua_gettop(L);
4853 boolean can_have_flags = FALSE;
4854 long fcoord;
4855 int humidity;
4856
4857 create_des_coder();
4858
4859 if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
4860 typ = features2i[luaL_checkoption(L, 1, NULL, features)];
4861 x = y = -1;
4862 } else if (argc == 2 && lua_type(L, 1) == LUA_TSTRING
4863 && lua_type(L, 2) == LUA_TTABLE) {
4864 lua_Integer fx, fy;
4865 typ = features2i[luaL_checkoption(L, 1, NULL, features)];
4866 (void) get_coord(L, 2, &fx, &fy);
4867 x = fx;
4868 y = fy;
4869 } else if (argc == 3) {
4870 typ = features2i[luaL_checkoption(L, 1, NULL, features)];
4871 x = luaL_checkinteger(L, 2);
4872 y = luaL_checkinteger(L, 3);
4873 } else {
4874 lua_Integer fx, fy;
4875 lcheck_param_table(L);
4876
4877 get_table_xy_or_coord(L, &fx, &fy);
4878 x = fx, y = fy;
4879 typ = features2i[get_table_option(L, "type", NULL, features)];
4880 can_have_flags = TRUE;
4881 }
4882
4883 if (x == -1 && y == -1) {
4884 fcoord = SP_COORD_PACK_RANDOM(0);
4885 humidity = DRY; /* pick a regular space, no rock or other furniture */
4886 }
4887 else {
4888 fcoord = SP_COORD_PACK(x, y);
4889 humidity = ANY_LOC; /* assume the author knows what they're doing */
4890 }
4891 get_location_coord(&x, &y, humidity, gc.coder->croom, fcoord);
4892
4893 if (typ == STONE)
4894 impossible("feature has unknown type param.");
4895 else
4896 sel_set_feature(x, y, (genericptr_t) &typ);
4897
4898 if (levl[x][y].typ != typ || !can_have_flags)
4899 return 0;
4900

Callers

nothing calls this directly

Calls 9

create_des_coderFunction · 0.85
get_coordFunction · 0.85
lcheck_param_tableFunction · 0.85
get_table_xy_or_coordFunction · 0.85
get_table_optionFunction · 0.85
get_location_coordFunction · 0.85
sel_set_featureFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected