/*
Minetest
Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2014-2017 paramat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge)
: Mapgen(mapgenid, params, emerge)
{
- this->m_emerge = emerge;
- this->ystride = csize.X; //////fix this
+ m_emerge = emerge;
+ ystride = csize.X; //////fix this
- this->heightmap = new s16[csize.X * csize.Z];
+ heightmap = new s16[csize.X * csize.Z];
- this->spflags = params->spflags;
- this->freq_desert = params->freq_desert;
- this->freq_beach = params->freq_beach;
+ spflags = params->spflags;
+ freq_desert = params->freq_desert;
+ freq_beach = params->freq_beach;
np_cave = ¶ms->np_cave;
np_humidity = ¶ms->np_humidity;
MapgenV6Params::MapgenV6Params()
{
- spflags = MGV6_JUNGLES | MGV6_SNOWBIOMES | MGV6_TREES |
- MGV6_BIOMEBLEND | MGV6_MUDFLOW;
-
- freq_desert = 0.45;
- freq_beach = 0.15;
-
np_terrain_base = NoiseParams(-4, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6, 2.0);
np_terrain_higher = NoiseParams(20, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6, 2.0);
np_steepness = NoiseParams(0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7, 2.0);
// Returns Y one under area minimum if not found
s16 MapgenV6::find_stone_level(v2s16 p2d)
{
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
s16 y_nodes_max = vm->m_area.MaxEdge.Y;
s16 y_nodes_min = vm->m_area.MinEdge.Y;
u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Calculate lighting
if (flags & MG_LIGHT)
BiomeV6Type bt = getBiome(v2s16(x, z));
// Fill ground with stone
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
u32 i = vm->m_area.index(x, node_min.Y, z);
for (s16 y = node_min.Y; y <= node_max.Y; y++) {
if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
// Add mud on ground
s16 mudcount = 0;
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
s16 y_start = surface_y + 1;
u32 i = vm->m_area.index(x, y_start, z);
for (s16 y = y_start; y <= node_max.Y; y++) {
// Node position in 2d
v2s16 p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z);
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
u32 i = vm->m_area.index(p2d.X, node_max.Y, p2d.Y);
s16 y = node_max.Y;
v3s16(-1, 0, 0), // left
};
- // Check that upper is air or doesn't exist.
- // Cancel dropping if upper keeps it in place
+ // Check that upper is walkable. Cancel
+ // dropping if upper keeps it in place.
u32 i3 = i;
vm->m_area.add_y(em, i3, 1);
- if (vm->m_area.contains(i3) == true &&
- ndef->get(vm->m_data[i3]).walkable)
- continue;
+ MapNode *n3 = NULL;
+
+ if (vm->m_area.contains(i3)) {
+ n3 = &vm->m_data[i3];
+ if (ndef->get(*n3).walkable)
+ continue;
+ }
// Drop mud on side
for (u32 di = 0; di < 4; di++) {
} while (ndef->get(*n2).walkable == false);
// Loop one up so that we're in air
vm->m_area.add_y(em, i2, 1);
- n2 = &vm->m_data[i2];
- bool old_is_water = (n->getContent() == c_water_source);
- // Move mud to new place
- if (!dropped_to_unknown) {
- *n2 = *n;
- // Set old place to be air (or water)
- if (old_is_water)
- *n = MapNode(c_water_source);
- else
- *n = MapNode(CONTENT_AIR);
- }
+ // Move mud to new place. Outside mapchunk remove
+ // any decorations above removed or placed mud.
+ if (!dropped_to_unknown)
+ moveMud(i, i2, i3, p2d, em);
// Done
break;
}
+void MapgenV6::moveMud(u32 remove_index, u32 place_index,
+ u32 above_remove_index, v2s16 pos, v3s16 em)
+{
+ MapNode n_air(CONTENT_AIR);
+ // Copy mud from old place to new place
+ vm->m_data[place_index] = vm->m_data[remove_index];
+ // Set old place to be air
+ vm->m_data[remove_index] = n_air;
+ // Outside the mapchunk decorations may need to be removed if above removed
+ // mud or if half-buried in placed mud. Placed mud is to the side of pos so
+ // use 'pos.X >= node_max.X' etc.
+ if (pos.X >= node_max.X || pos.X <= node_min.X ||
+ pos.Y >= node_max.Z || pos.Y <= node_min.Z) {
+ // 'above remove' node is above removed mud. If it is not air, water or
+ // 'ignore' it is a decoration that needs removing. Also search upwards
+ // to remove a possible stacked decoration.
+ // Check for 'ignore' because stacked decorations can penetrate into
+ // 'ignore' nodes above the mapchunk.
+ while (vm->m_area.contains(above_remove_index) &&
+ vm->m_data[above_remove_index].getContent() != CONTENT_AIR &&
+ vm->m_data[above_remove_index].getContent() != c_water_source &&
+ vm->m_data[above_remove_index].getContent() != CONTENT_IGNORE) {
+ vm->m_data[above_remove_index] = n_air;
+ vm->m_area.add_y(em, above_remove_index, 1);
+ }
+ // Mud placed may have partially-buried a stacked decoration, search
+ // above and remove.
+ vm->m_area.add_y(em, place_index, 1);
+ while (vm->m_area.contains(place_index) &&
+ vm->m_data[place_index].getContent() != CONTENT_AIR &&
+ vm->m_data[place_index].getContent() != c_water_source &&
+ vm->m_data[place_index].getContent() != CONTENT_IGNORE) {
+ vm->m_data[place_index] = n_air;
+ vm->m_area.add_y(em, place_index, 1);
+ }
+ }
+}
+
+
void MapgenV6::placeTreesAndJungleGrass()
{
//TimeTaker t("placeTrees");
if (c_junglegrass == CONTENT_IGNORE)
c_junglegrass = CONTENT_AIR;
MapNode n_junglegrass(c_junglegrass);
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
// Divide area into parts
s16 div = 8;
continue;
v3s16 p(x, y, z);
- // Trees grow only on mud and grass and snowblock
+ // Trees grow only on mud and grass
{
u32 i = vm->m_area.index(p);
content_t c = vm->m_data[i].getContent();
if (c != c_dirt &&
c != c_dirt_with_grass &&
- c != c_dirt_with_snow &&
- c != c_snowblock)
+ c != c_dirt_with_snow)
continue;
}
p.Y++;
MapNode n_dirt_with_snow(c_dirt_with_snow);
MapNode n_snowblock(c_snowblock);
MapNode n_snow(c_snow);
- v3s16 em = vm->m_area.getExtent();
+ const v3s16 &em = vm->m_area.getExtent();
u32 index = 0;
for (s16 z = full_node_min.Z; z <= full_node_max.Z; z++)
content_t c = vm->m_data[i].getContent();
if (surface_y >= water_level - 20) {
if (bt == BT_TAIGA && c == c_dirt) {
- vm->m_data[i] = n_snowblock;
- vm->m_area.add_y(em, i, -1);
vm->m_data[i] = n_dirt_with_snow;
} else if (bt == BT_TUNDRA) {
if (c == c_dirt) {
+ vm->m_data[i] = n_snowblock;
+ vm->m_area.add_y(em, i, -1);
vm->m_data[i] = n_dirt_with_snow;
} else if (c == c_stone && surface_y < node_max.Y) {
vm->m_area.add_y(em, i, 1);
- vm->m_data[i] = n_snow;
+ vm->m_data[i] = n_snowblock;
}
} else if (c == c_dirt) {
vm->m_data[i] = n_dirt_with_grass;