Exemple #1
0
// clear_registered_biomes()
int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
	bmgr->clear();
	return 0;
}
Exemple #2
0
// register_biome({lots of stuff})
int ModApiMapgen::l_register_biome(lua_State *L)
{
	int index = 1;
	luaL_checktype(L, index, LUA_TTABLE);

	INodeDefManager *ndef = getServer(L)->getNodeDefManager();
	BiomeManager *bmgr    = getServer(L)->getEmergeManager()->biomemgr;

	enum BiomeType biometype = (BiomeType)getenumfield(L, index, "type",
		es_BiomeTerrainType, BIOME_TYPE_NORMAL);
	Biome *b = bmgr->create(biometype);

	b->name            = getstringfield_default(L, index, "name", "");
	b->depth_top       = getintfield_default(L, index, "depth_top",          1);
	b->depth_filler    = getintfield_default(L, index, "depth_filler",       3);
	b->height_shore    = getintfield_default(L, index, "height_shore",       3);
	b->depth_water_top = getintfield_default(L, index, "depth_water_top",    0);
	b->y_min           = getintfield_default(L, index, "y_min",         -31000);
	b->y_max           = getintfield_default(L, index, "y_max",          31000);
	b->heat_point      = getfloatfield_default(L, index, "heat_point",     0.f);
	b->humidity_point  = getfloatfield_default(L, index, "humidity_point", 0.f);
	b->flags           = 0; //reserved

	u32 id = bmgr->add(b);
	if (id == (u32)-1) {
		delete b;
		return 0;
	}

	NodeResolveInfo *nri = new NodeResolveInfo(b);
	std::list<std::string> &nnames = nri->nodenames;
	nnames.push_back(getstringfield_default(L, index, "node_top",          ""));
	nnames.push_back(getstringfield_default(L, index, "node_filler",       ""));
	nnames.push_back(getstringfield_default(L, index, "node_shore_top",    ""));
	nnames.push_back(getstringfield_default(L, index, "node_shore_filler", ""));
	nnames.push_back(getstringfield_default(L, index, "node_underwater",   ""));
	nnames.push_back(getstringfield_default(L, index, "node_stone",        ""));
	nnames.push_back(getstringfield_default(L, index, "node_water_top",    ""));
	nnames.push_back(getstringfield_default(L, index, "node_water",        ""));
	nnames.push_back(getstringfield_default(L, index, "node_dust",         ""));
	ndef->pendNodeResolve(nri);

	verbosestream << "register_biome: " << b->name << std::endl;

	lua_pushinteger(L, id);
	return 1;
}
void MapGenerator::CreateBiomes()
{
     BiomeManager* bManager = new BiomeManager();
    bool** check = getArray<bool>(mapSize);
    for(int y =0; y<mapSize; y++)
    {
        for(int x =0; x<mapSize; x++)
        {
            if(!check[x][y])
            {
                //on start un biomes ici, vu que le parser est pas encore passser dessus

                check[x][y]=true;
                BiomesParser((char)map->getBiomesMap()[x][y], (bool**)check, new point(x, y),bManager,bManager->createNewBiome(map->getBiomesMap()[x][y]));
            }
        }
    }
        bManager->generate(map->getBiomesMap(),mapSize);
}
Exemple #4
0
// register_biome({lots of stuff})
int ModApiMapgen::l_register_biome(lua_State *L)
{
	int index = 1;
	luaL_checktype(L, index, LUA_TTABLE);

	INodeDefManager *ndef = getServer(L)->getNodeDefManager();
	BiomeManager *bmgr    = getServer(L)->getEmergeManager()->biomemgr;

	Biome *biome = read_biome_def(L, index, ndef);
	if (!biome)
		return 0;

	ObjDefHandle handle = bmgr->add(biome);
	if (handle == OBJDEF_INVALID_HANDLE) {
		delete biome;
		return 0;
	}

	lua_pushinteger(L, handle);
	return 1;
}
Exemple #5
0
// get_biome_id(biomename)
// returns the biome id used in biomemap
int ModApiMapgen::l_get_biome_id(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	const char *biome_str = lua_tostring(L, 1);
	if (!biome_str)
		return 0;

	BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;

	if (!bmgr)
		return 0;

	Biome *biome = (Biome *)bmgr->getByName(biome_str);

	if (!biome || biome->index == OBJDEF_INVALID_INDEX)
		return 0;

	lua_pushinteger(L, biome->index);

	return 1;
}
Exemple #6
0
// get_humidity(pos)
// returns the humidity at the position
int ModApiMapgen::l_get_humidity(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	v3s16 pos = read_v3s16(L, 1);

	NoiseParams np_humidity;
	NoiseParams np_humidity_blend;

	MapSettingsManager *settingsmgr =
		getServer(L)->getEmergeManager()->map_settings_mgr;

	if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity",
			&np_humidity) ||
			!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend",
			&np_humidity_blend))
		return 0;

	std::string value;
	if (!settingsmgr->getMapSetting("seed", &value))
		return 0;
	std::istringstream ss(value);
	u64 seed;
	ss >> seed;

	BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
	if (!bmgr)
		return 0;

	float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
		np_humidity_blend, seed);
	if (!humidity)
		return 0;

	lua_pushnumber(L, humidity);

	return 1;
}
Exemple #7
0
// register_decoration({lots of stuff})
int ModApiMapgen::l_register_decoration(lua_State *L)
{
	int index = 1;
	luaL_checktype(L, index, LUA_TTABLE);

	INodeDefManager *ndef      = getServer(L)->getNodeDefManager();
	DecorationManager *decomgr = getServer(L)->getEmergeManager()->decomgr;
	BiomeManager *biomemgr     = getServer(L)->getEmergeManager()->biomemgr;

	enum DecorationType decotype = (DecorationType)getenumfield(L, index,
				"deco_type", es_DecorationType, -1);

	Decoration *deco = decomgr->create(decotype);
	if (!deco) {
		errorstream << "register_decoration: decoration placement type "
			<< decotype << " not implemented";
		return 0;
	}

	deco->name       = getstringfield_default(L, index, "name", "");
	deco->fill_ratio = getfloatfield_default(L, index, "fill_ratio", 0.02);
	deco->y_min      = getintfield_default(L, index, "y_min", -31000);
	deco->y_max      = getintfield_default(L, index, "y_max", 31000);
	deco->sidelen    = getintfield_default(L, index, "sidelen", 8);
	if (deco->sidelen <= 0) {
		errorstream << "register_decoration: sidelen must be "
			"greater than 0" << std::endl;
		delete deco;
		return 0;
	}

	NodeResolveInfo *nri = new NodeResolveInfo(deco);

	//// Get node name(s) to place decoration on
	std::vector<const char *> place_on_names;
	getstringlistfield(L, index, "place_on", place_on_names);
	nri->nodelistinfo.push_back(NodeListInfo(place_on_names.size()));
	for (size_t i = 0; i != place_on_names.size(); i++)
		nri->nodenames.push_back(place_on_names[i]);

	getflagsfield(L, index, "flags", flagdesc_deco, &deco->flags, NULL);

	//// Get NoiseParams to define how decoration is placed
	lua_getfield(L, index, "noise_params");
	if (read_noiseparams(L, -1, &deco->np))
		deco->flags |= DECO_USE_NOISE;
	lua_pop(L, 1);

	//// Get biomes associated with this decoration (if any)
	std::vector<const char *> biome_list;
	getstringlistfield(L, index, "biomes", biome_list);
	for (size_t i = 0; i != biome_list.size(); i++) {
		Biome *b = (Biome *)biomemgr->getByName(biome_list[i]);
		if (!b)
			continue;

		deco->biomes.insert(b->id);
	}

	//// Handle decoration type-specific parameters
	bool success = false;
	switch (decotype) {
		case DECO_SIMPLE:
			success = regDecoSimple(L, nri, (DecoSimple *)deco);
			break;
		case DECO_SCHEMATIC:
			success = regDecoSchematic(L, ndef, (DecoSchematic *)deco);
			break;
		case DECO_LSYSTEM:
			break;
	}

	ndef->pendNodeResolve(nri);

	if (!success) {
		delete deco;
		return 0;
	}

	u32 id = decomgr->add(deco);
	if (id == (u32)-1) {
		delete deco;
		return 0;
	}

	verbosestream << "register_decoration: " << deco->name << std::endl;

	lua_pushinteger(L, id);
	return 1;
}
Exemple #8
0
// get_biome_data(pos)
// returns a table containing the biome id, heat and humidity at the position
int ModApiMapgen::l_get_biome_data(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	v3s16 pos = read_v3s16(L, 1);

	NoiseParams np_heat;
	NoiseParams np_heat_blend;
	NoiseParams np_humidity;
	NoiseParams np_humidity_blend;

	MapSettingsManager *settingsmgr =
		getServer(L)->getEmergeManager()->map_settings_mgr;

	if (!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat",
			&np_heat) ||
			!settingsmgr->getMapSettingNoiseParams("mg_biome_np_heat_blend",
			&np_heat_blend) ||
			!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity",
			&np_humidity) ||
			!settingsmgr->getMapSettingNoiseParams("mg_biome_np_humidity_blend",
			&np_humidity_blend))
		return 0;

	std::string value;
	if (!settingsmgr->getMapSetting("seed", &value))
		return 0;
	std::istringstream ss(value);
	u64 seed;
	ss >> seed;

	BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
	if (!bmgr)
		return 0;

	float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed);
	if (!heat)
		return 0;

	float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity,
		np_humidity_blend, seed);
	if (!humidity)
		return 0;

	Biome *biome = (Biome *)bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos.Y);
	if (!biome || biome->index == OBJDEF_INVALID_INDEX)
		return 0;

	lua_newtable(L);

	lua_pushinteger(L, biome->index);
	lua_setfield(L, -2, "biome");

	lua_pushnumber(L, heat);
	lua_setfield(L, -2, "heat");

	lua_pushnumber(L, humidity);
	lua_setfield(L, -2, "humidity");

	return 1;
}