diff options
author | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
commit | caecdb681c428c1aab9c0f7eec2570c0460f995c (patch) | |
tree | e5115982ea59bbf2343ba9b35bc4a0cfbb56f407 /src/dungeongen.cpp | |
parent | 81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (diff) | |
parent | 80dc961d24e1964e25d57039ddb2ba639f9f4d22 (diff) | |
download | minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.gz minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.bz2 minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.zip |
Merge 0.4.16 into stable-0.4
Diffstat (limited to 'src/dungeongen.cpp')
-rw-r--r-- | src/dungeongen.cpp | 126 |
1 files changed, 66 insertions, 60 deletions
diff --git a/src/dungeongen.cpp b/src/dungeongen.cpp index 78573da04..6cef3f88d 100644 --- a/src/dungeongen.cpp +++ b/src/dungeongen.cpp @@ -52,6 +52,7 @@ DungeonGen::DungeonGen(INodeDefManager *ndef, if (dparams) { memcpy(&dp, dparams, sizeof(dp)); } else { + // Default dungeon parameters dp.seed = 0; dp.c_water = ndef->getId("mapgen_water_source"); @@ -63,14 +64,20 @@ DungeonGen::DungeonGen(INodeDefManager *ndef, if (dp.c_river_water == CONTENT_IGNORE) dp.c_river_water = ndef->getId("mapgen_water_source"); - dp.diagonal_dirs = false; - dp.holesize = v3s16(1, 2, 1); - dp.roomsize = v3s16(0, 0, 0); - dp.rooms_min = 2; - dp.rooms_max = 16; - dp.y_min = -MAX_MAP_GENERATION_LIMIT; - dp.y_max = MAX_MAP_GENERATION_LIMIT; - dp.notifytype = GENNOTIFY_DUNGEON; + dp.diagonal_dirs = false; + dp.only_in_ground = true; + dp.holesize = v3s16(1, 2, 1); + dp.corridor_len_min = 1; + dp.corridor_len_max = 13; + dp.room_size_min = v3s16(4, 4, 4); + dp.room_size_max = v3s16(8, 6, 8); + dp.room_size_large_min = v3s16(8, 8, 8); + dp.room_size_large_max = v3s16(16, 16, 16); + dp.rooms_min = 2; + dp.rooms_max = 16; + dp.y_min = -MAX_MAP_GENERATION_LIMIT; + dp.y_max = MAX_MAP_GENERATION_LIMIT; + dp.notifytype = GENNOTIFY_DUNGEON; dp.np_density = nparams_dungeon_density; dp.np_alt_wall = nparams_dungeon_alt_wall; @@ -97,16 +104,19 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) // 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++; + if (dp.only_in_ground) { + // 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++; + } } } } @@ -142,21 +152,25 @@ void DungeonGen::makeDungeon(v3s16 start_padding) v3s16 roomplace; /* - Find place for first room + Find place for first room. + There is a 1 in 4 chance of the first room being 'large', + all other rooms are not 'large'. */ bool fits = false; for (u32 i = 0; i < 100 && !fits; i++) { bool is_large_room = ((random.next() & 3) == 1); if (is_large_room) { - roomsize.Z = random.range(8, 16); - roomsize.Y = random.range(8, 16); - roomsize.X = random.range(8, 16); + roomsize.Z = random.range( + dp.room_size_large_min.Z, dp.room_size_large_max.Z); + roomsize.Y = random.range( + dp.room_size_large_min.Y, dp.room_size_large_max.Y); + roomsize.X = random.range( + dp.room_size_large_min.X, dp.room_size_large_max.X); } else { - roomsize.Z = random.range(4, 8); - roomsize.Y = random.range(4, 6); - roomsize.X = random.range(4, 8); + roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z); + roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y); + roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X); } - roomsize += dp.roomsize; // start_padding is used to disallow starting the generation of // a dungeon in a neighboring generation chunk @@ -246,10 +260,9 @@ void DungeonGen::makeDungeon(v3s16 start_padding) makeCorridor(doorplace, doordir, corridor_end, corridor_end_dir); // Find a place for a random sized room - roomsize.Z = random.range(4, 8); - roomsize.Y = random.range(4, 6); - roomsize.X = random.range(4, 8); - roomsize += dp.roomsize; + roomsize.Z = random.range(dp.room_size_min.Z, dp.room_size_max.Z); + roomsize.Y = random.range(dp.room_size_min.Y, dp.room_size_max.Y); + roomsize.X = random.range(dp.room_size_min.X, dp.room_size_max.X); m_pos = corridor_end; m_dir = corridor_end_dir; @@ -397,13 +410,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, 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 length = random.range(dp.corridor_len_min, dp.corridor_len_max); + u32 partlength = random.range(dp.corridor_len_min, dp.corridor_len_max); u32 partcount = 0; s16 make_stairs = 0; @@ -415,8 +423,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, if (partcount != 0) p.Y += make_stairs; - if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0)) && - vm->m_area.contains(v3s16(p.X - dir.X, p.Y - 1, p.Z - dir.Z))) { + // Check segment of minimum size corridor is in voxelmanip + if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) { if (make_stairs) { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 3, 2), @@ -437,14 +445,24 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, // rotate face 180 deg if // making stairs backwards int facedir = dir_to_facedir(dir * make_stairs); - - u32 vi = vm->m_area.index(p.X - dir.X, p.Y - 1, p.Z - dir.Z); - if (vm->m_data[vi].getContent() == dp.c_wall) - vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); - - vi = vm->m_area.index(p.X, p.Y, p.Z); - if (vm->m_data[vi].getContent() == dp.c_wall) - vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); + v3s16 ps = p; + u16 stair_width = (dir.Z != 0) ? dp.holesize.X : dp.holesize.Z; + // Stair width direction vector + v3s16 swv = (dir.Z != 0) ? v3s16(1, 0, 0) : v3s16(0, 0, 1); + + for (u16 st = 0; st < stair_width; st++) { + u32 vi = vm->m_area.index(ps.X - dir.X, ps.Y - 1, ps.Z - dir.Z); + if (vm->m_area.contains(ps + v3s16(-dir.X, -1, -dir.Z)) && + vm->m_data[vi].getContent() == dp.c_wall) + vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); + + vi = vm->m_area.index(ps.X, ps.Y, ps.Z); + if (vm->m_area.contains(ps) && + vm->m_data[vi].getContent() == dp.c_wall) + vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); + + ps += swv; + } } } else { makeFill(p + v3s16(-1, -1, -1), @@ -546,7 +564,6 @@ bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, continue; v3s16 roomplace; // X east, Z north, Y up -#if 1 if (doordir == v3s16(1, 0, 0)) // X+ roomplace = doorplace + v3s16(0, -1, random.range(-roomsize.Z + 2, -2)); @@ -559,17 +576,6 @@ bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, if (doordir == v3s16(0, 0, -1)) // Z- roomplace = doorplace + v3s16(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1); -#endif -#if 0 - if (doordir == v3s16(1, 0, 0)) // X+ - roomplace = doorplace + v3s16(0, -1, -roomsize.Z / 2); - if (doordir == v3s16(-1, 0, 0)) // X- - roomplace = doorplace + v3s16(-roomsize.X+1,-1,-roomsize.Z / 2); - if (doordir == v3s16(0, 0, 1)) // Z+ - roomplace = doorplace + v3s16(-roomsize.X / 2, -1, 0); - if (doordir == v3s16(0, 0, -1)) // Z- - roomplace = doorplace + v3s16(-roomsize.X / 2, -1, -roomsize.Z + 1); -#endif // Check fit bool fits = true; @@ -612,7 +618,7 @@ v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs) dir.Z = random.next() % 3 - 1; dir.Y = 0; dir.X = random.next() % 3 - 1; - } while ((dir.X == 0 && dir.Z == 0) && trycount < 10); + } while ((dir.X == 0 || dir.Z == 0) && trycount < 10); return dir; } else { |