예제 #1
0
v3s16 random_turn(PseudoRandom &random, v3s16 olddir)
{
	int turn = random.range(0, 2);
	v3s16 dir;
	if (turn == 0)
		// Go straight
		dir = olddir;
	else if (turn == 1)
		// Turn right
		dir = turn_xz(olddir, 0);
	else
		// Turn left
		dir = turn_xz(olddir, 1);
	return dir;
}
예제 #2
0
void DungeonGen::makeCorridor(v3s16 doorplace,
		v3s16 doordir, v3s16 &result_place, v3s16 &result_dir)
{
	makeHole(doorplace);
	v3s16 p0 = doorplace;
	v3s16 dir = doordir;
	u32 length;
	/*if (random.next() % 2)
		length = random.range(1, 13);
	else
		length = random.range(1, 6);*/
	length = random.range(1, 13);
	u32 partlength = random.range(1, 13);
	u32 partcount = 0;
	s16 make_stairs = 0;
	
	if (random.next() % 2 == 0 && partlength >= 3)
		make_stairs = random.next() % 2 ? 1 : -1;
	
	for (u32 i = 0; i < length; i++) {
		v3s16 p = p0 + dir;
		if (partcount != 0)
			p.Y += make_stairs;

		if (vmanip->m_area.contains(p) == true &&
			vmanip->m_area.contains(p + v3s16(0, 1, 0)) == true) {
			if (make_stairs) {
				makeFill(p + v3s16(-1, -1, -1), v3s16(3, 5, 3),
						VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(cid_cobble), 0);
				makeHole(p);
				makeHole(p - dir);
				
				// TODO: fix stairs code so it works 100% (quite difficult)

				// exclude stairs from the bottom step
				if (((make_stairs ==  1) && i != 0) ||
					((make_stairs == -1) && i != length - 1)) {
					// rotate face 180 deg if making stairs backwards
					int facedir = dir_to_facedir(dir * make_stairs);
					
					u32 vi = vmanip->m_area.index(p.X - dir.X, p.Y - 1, p.Z - dir.Z);
					if (vmanip->m_data[vi].getContent() == cid_cobble)
						vmanip->m_data[vi] = MapNode(cid_cobblestair, 0, facedir);
					
					vi = vmanip->m_area.index(p.X, p.Y, p.Z);
					if (vmanip->m_data[vi].getContent() == cid_cobble)
						vmanip->m_data[vi] = MapNode(cid_cobblestair, 0, facedir);
				}
			} else {
				makeFill(p + v3s16(-1, -1, -1), v3s16(3, 4, 3),
						VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(cid_cobble), 0);
				makeHole(p);
			}

			p0 = p;
		} else {
			// Can't go here, turn away
			dir = turn_xz(dir, random.range(0, 1));
			make_stairs = -make_stairs;
			partcount = 0;
			partlength = random.range(1, length);
			continue;
		}

		partcount++;
		if (partcount >= partlength) {
			partcount = 0;

			dir = random_turn(random, dir);

			partlength = random.range(1,length);

			make_stairs = 0;
			if (random.next() % 2 == 0 && partlength >= 3)
				make_stairs = random.next() % 2 ? 1 : -1;
		}
	}
	result_place = p0;
	result_dir = dir;
}