Beispiel #1
0
// find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions
// nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
{
	/* Note: A similar but generalized (and therefore slower) version of this
	 * function could be created -- e.g. find_nodes_in_area_under -- which
	 * would accept a node name (or ID?) or list of names that the "above node"
	 * should be.
	 * TODO
	 */

	GET_ENV_PTR;

	INodeDefManager *ndef = getServer(L)->ndef();
	v3s16 minp = read_v3s16(L, 1);
	v3s16 maxp = read_v3s16(L, 2);
	std::set<content_t> filter;

	if (lua_istable(L, 3)) {
		int table = 3;
		lua_pushnil(L);
		while(lua_next(L, table) != 0) {
			// key at index -2 and value at index -1
			luaL_checktype(L, -1, LUA_TSTRING);
			ndef->getIds(lua_tostring(L, -1), filter);
			// removes value, keeps key for next iteration
			lua_pop(L, 1);
		}
	} else if (lua_isstring(L, 3)) {
		ndef->getIds(lua_tostring(L, 3), filter);
	}

	lua_newtable(L);
	u64 i = 0;
	for (s16 x = minp.X; x <= maxp.X; x++)
	for (s16 z = minp.Z; z <= maxp.Z; z++) {
		s16 y = minp.Y;
		v3s16 p(x, y, z);
		content_t c = env->getMap().getNodeNoEx(p).getContent();
		for (; y <= maxp.Y; y++) {
			v3s16 psurf(x, y + 1, z);
			content_t csurf = env->getMap().getNodeNoEx(psurf).getContent();
			if(c != CONTENT_AIR && csurf == CONTENT_AIR &&
					filter.count(c) != 0) {
				push_v3s16(L, v3s16(x, y, z));
				lua_rawseti(L, -2, ++i);
			}
			c = csurf;
		}
	}
	return 1;
}
Beispiel #2
0
int DisplaySurface( WindowObjectType *wo, MetObjectType *mot )
{
	char			title [FILENAMESTRING], 
				sfparmstr[FILENAMESTRING];
	char			sizestr[GEMPAKSTRING], widthstr[GEMPAKSTRING],
				fontstr[GEMPAKSTRING], filterstr[GEMPAKSTRING];
	int			size, width, font_size, filter;
	int			verbose, iret;

	SurfaceObjectType       *sobj;
	MetObjectType		*gmobj;


	sobj = (SurfaceObjectType *) mot->metObjectContent;


	assert( sobj );

	verbose = GetVerboseLevel();
	if( verbose > VERBOSE_0 )
	    printf ( "DisplaySurface\n" );

/*
 *	Save original FDF settings.
 */
	strcpy ( sfparmstr, sobj->sfparm );
	strcpy ( fontstr, sobj->text );
	strcpy ( filterstr, sobj->filter );
	strcpy ( sizestr, sobj->symbol_size );
	strcpy ( widthstr, sobj->symbol_width );

/*
 *	Set plotting parameters according to generalized values.
 */
	GetDepictableValue ( "SYMBOLSIZE", &size );
	GetDepictableValue ( "SYMBOLWIDTH", &width );
	GetDepictableValue ( "FONTSIZE", &font_size );
	GetDepictableValue ( "SYMBOLPACKING", &filter );
	
	SetGemParmVal ( SURFACEOBJECT, sfparmstr, "SYMBOLSIZE", size );
	SetGemParmVal ( SURFACEOBJECT, sfparmstr, "SYMBOLWIDTH", width );
	SetGemText ( SURFACEOBJECT, fontstr, "FONTSIZE", font_size );
	SetGemFloatVar ( SURFACEOBJECT, filterstr, "SYMBOLPACKING", filter );
	SetGemFloatVar ( SURFACEOBJECT, sizestr, "SYMBOLSIZE", size );
	SetGemIntVar ( SURFACEOBJECT, widthstr, "SYMBOLWIDTH", width );
	strcpy ( title, mot->titleString );
	SetGemTitle ( sobj->colors, mot->titleIndex, title );

	psurf(	mot->area,		sfparmstr,
		sobj->dattim,		mot->filename,
		sobj->colors,		title,
		filterstr,		fontstr,
		sizestr,		widthstr,
		&(sobj->marker),	&(sobj->pmarker),	
		&(sobj->skpmis),	&(sobj->nstations),
		&(mot->titleIndex),	&verbose,		
		&iret, 
		strlen(mot->area),	strlen(sfparmstr),
		strlen(sobj->dattim),	strlen(mot->filename),
		strlen(sobj->colors),	strlen(title),
		strlen(filterstr),	strlen(fontstr),
		strlen(sizestr),	strlen(widthstr) );

	SetMetObjectDrawnFlag( mot, True );

	return(0);

}
Beispiel #3
0
// find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions
// nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
{
	/* Note: A similar but generalized (and therefore slower) version of this
	 * function could be created -- e.g. find_nodes_in_area_under -- which
	 * would accept a node name (or ID?) or list of names that the "above node"
	 * should be.
	 * TODO
	 */

	GET_ENV_PTR;

	INodeDefManager *ndef = getServer(L)->ndef();
	v3s16 minp = read_v3s16(L, 1);
	v3s16 maxp = read_v3s16(L, 2);
	sortBoxVerticies(minp, maxp);

	v3s16 cube = maxp - minp + 1;

	/* Limit for too large areas, assume default values
	 * and give tolerances of 1 node on each side
	 * (chunksize * MAP_BLOCKSIZE + 2)^3 = 551368
	*/
	if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 551368) {
		luaL_error(L, "find_nodes_in_area_under_air(): area volume"
				" exceeds allowed value of 551368");
		return 0;
	}

	std::vector<content_t> filter;

	if (lua_istable(L, 3)) {
		lua_pushnil(L);
		while (lua_next(L, 3) != 0) {
			// key at index -2 and value at index -1
			luaL_checktype(L, -1, LUA_TSTRING);
			ndef->getIds(lua_tostring(L, -1), filter);
			// removes value, keeps key for next iteration
			lua_pop(L, 1);
		}
	} else if (lua_isstring(L, 3)) {
		ndef->getIds(lua_tostring(L, 3), filter);
	}

	lua_newtable(L);
	u64 i = 0;
	for (s16 x = minp.X; x <= maxp.X; x++)
	for (s16 z = minp.Z; z <= maxp.Z; z++) {
		s16 y = minp.Y;
		v3s16 p(x, y, z);
		content_t c = env->getMap().getNodeNoEx(p).getContent();
		for (; y <= maxp.Y; y++) {
			v3s16 psurf(x, y + 1, z);
			content_t csurf = env->getMap().getNodeNoEx(psurf).getContent();
			if (c != CONTENT_AIR && csurf == CONTENT_AIR &&
					CONTAINS(filter, c)) {
				push_v3s16(L, v3s16(x, y, z));
				lua_rawseti(L, -2, ++i);
			}
			c = csurf;
		}
	}
	return 1;
}