Esempio n. 1
0
void DungeonGen::generate(ManualMapVoxelManipulator *vm, u32 bseed,
						 v3s16 nmin, v3s16 nmax) {
	//TimeTaker t("gen dungeons");
	int approx_groundlevel = 10 + water_level;

	if ((nmin.Y + nmax.Y) / 2 >= approx_groundlevel ||
		NoisePerlin3D(np_rarity, nmin.X, nmin.Y, nmin.Z, mapseed) < 0.2)
		return;
		
	this->vmanip    = vm;
	this->blockseed = bseed;
	random.seed(bseed + 2);

	cid_water_source = ndef->getId("mapgen_water_source");
	cid_cobble       = ndef->getId("mapgen_cobble");
	cid_mossycobble  = ndef->getId("mapgen_mossycobble");
	//cid_torch        = ndef->getId("default:torch");
	cid_cobblestair  = ndef->getId("mapgen_stair_cobble");

	// Dungeon generator doesn't modify places which have this set
	vmanip->clearFlag(VMANIP_FLAG_DUNGEON_INSIDE | VMANIP_FLAG_DUNGEON_PRESERVE);

	// Set all air and water to be untouchable to make dungeons open
	// to caves and open air
	for (s16 z = nmin.Z; z <= nmax.Z; z++) {
		for (s16 y = nmin.Y; y <= nmax.Y; y++) {
			u32 i = vmanip->m_area.index(nmin.X, y, z);
			for (s16 x = nmin.X; x <= nmax.X; x++) {
				content_t c = vmanip->m_data[i].getContent();
				if (c == CONTENT_AIR || c == cid_water_source)
					vmanip->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
				i++;
			}
		}
	}
	
	// Add it
	makeDungeon(v3s16(1,1,1) * MAP_BLOCKSIZE);
	
	// Convert some cobble to mossy cobble
	for (s16 z = nmin.Z; z <= nmax.Z; z++) {
		for (s16 y = nmin.Y; y <= nmax.Y; y++) {
			u32 i = vmanip->m_area.index(nmin.X, y, z);
			for (s16 x = nmin.X; x <= nmax.X; x++) {
				if (vmanip->m_data[i].getContent() == cid_cobble) {
					float wetness = NoisePerlin3D(np_wetness, x, y, z, mapseed);
					float density = NoisePerlin3D(np_density, x, y, z, blockseed);
					if (density < wetness / 3.0)
						vmanip->m_data[i].setContent(cid_mossycobble);
				}
				i++;
			}
		}
	}
	
	//printf("== gen dungeons: %dms\n", t.stop());
}
Esempio n. 2
0
void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax)
{
	assert(vm);

	//TimeTaker t("gen dungeons");
	if (nmin.Y < dp.y_min || nmax.Y > dp.y_max)
		return;

	float nval_density = NoisePerlin3D(&dp.np_density, nmin.X, nmin.Y, nmin.Z, dp.seed);
	if (nval_density < 1.0f)
		return;

	this->vm = vm;
	this->blockseed = bseed;
	random.seed(bseed + 2);

	// Dungeon generator doesn't modify places which have this set
	vm->clearFlag(VMANIP_FLAG_DUNGEON_INSIDE | VMANIP_FLAG_DUNGEON_PRESERVE);

	// Set all air and water to be untouchable
	// to make dungeons open to caves and open air
	for (s16 z = nmin.Z; z <= nmax.Z; z++) {
		for (s16 y = nmin.Y; y <= nmax.Y; y++) {
			u32 i = vm->m_area.index(nmin.X, y, z);
			for (s16 x = nmin.X; x <= nmax.X; x++) {
				content_t c = vm->m_data[i].getContent();
				if (c == CONTENT_AIR || c == dp.c_water || c == dp.c_river_water)
					vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
				i++;
			}
		}
	}

	// Add them
	for (u32 i = 0; i < floor(nval_density); i++)
		makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE);

	// Optionally convert some structure to alternative structure
	if (dp.c_alt_wall == CONTENT_IGNORE)
		return;

	for (s16 z = nmin.Z; z <= nmax.Z; z++)
	for (s16 y = nmin.Y; y <= nmax.Y; y++) {
		u32 i = vm->m_area.index(nmin.X, y, z);
		for (s16 x = nmin.X; x <= nmax.X; x++) {
			if (vm->m_data[i].getContent() == dp.c_wall) {
				if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f)
					vm->m_data[i].setContent(dp.c_alt_wall);
			}
			i++;
		}
	}

	//printf("== gen dungeons: %dms\n", t.stop());
}
Esempio n. 3
0
void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax)
{
	//TimeTaker t("gen dungeons");
	if (NoisePerlin3D(&dp.np_rarity, nmin.X, nmin.Y, nmin.Z, mg->seed) < 0.2)
		return;

	this->blockseed = bseed;
	random.seed(bseed + 2);

	// Dungeon generator doesn't modify places which have this set
	vm->clearFlag(VMANIP_FLAG_DUNGEON_INSIDE | VMANIP_FLAG_DUNGEON_PRESERVE);

	bool no_float = !g_settings->getBool("enable_floating_dungeons");

	// Set all air and water (and optionally ignore) to be untouchable
	// to make dungeons open to caves and open air
	for (s16 z = nmin.Z; z <= nmax.Z; z++) {
		for (s16 y = nmin.Y; y <= nmax.Y; y++) {
			u32 i = vm->m_area.index(nmin.X, y, z);
			for (s16 x = nmin.X; x <= nmax.X; x++) {
				content_t c = vm->m_data[i].getContent();
				if (c == CONTENT_AIR || c == dp.c_water ||
						(no_float && c == CONTENT_IGNORE))
					vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
				i++;
			}
		}
	}

	// Add it
	makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE);

	// Convert some cobble to mossy cobble
	if (dp.mossratio != 0.0) {
		for (s16 z = nmin.Z; z <= nmax.Z; z++)
		for (s16 y = nmin.Y; y <= nmax.Y; y++) {
			u32 i = vm->m_area.index(nmin.X, y, z);
			for (s16 x = nmin.X; x <= nmax.X; x++) {
				if (vm->m_data[i].getContent() == dp.c_cobble) {
					float wetness = NoisePerlin3D(&dp.np_wetness, x, y, z, mg->seed);
					float density = NoisePerlin3D(&dp.np_density, x, y, z, blockseed);
					if (density < wetness / dp.mossratio)
						vm->m_data[i].setContent(dp.c_moss);
				}
				i++;
			}
		}
	}

	//printf("== gen dungeons: %dms\n", t.stop());
}