Skip to content

Commit f55816f

Browse files
committedJun 14, 2017
Mgv6 mudflow: Avoid partially removed stacked decorations
Recently we started to remove decorations if the dirt below was flowed away, but this did not check for stacked decorations, causing them to have only their lowest node removed. Also, placed mud could partially bury stacked decorations. Remove 'old_is_water' bool which on testing is never true. Add new function 'moveMud()' to reduce indentation. Remove stacked decoration nodes above a removed decoration. Remove stacked decorations partially buried in placed mud.
1 parent bbe3dd9 commit f55816f

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed
 

Diff for: ‎src/mapgen_v6.cpp

+39-19
Original file line numberDiff line numberDiff line change
@@ -884,26 +884,11 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
884884
} while (ndef->get(*n2).walkable == false);
885885
// Loop one up so that we're in air
886886
vm->m_area.add_y(em, i2, 1);
887-
n2 = &vm->m_data[i2];
888887

889-
bool old_is_water = (n->getContent() == c_water_source);
890-
// Move mud to new place
891-
if (!dropped_to_unknown) {
892-
*n2 = *n;
893-
// Set old place to be air (or water)
894-
if (old_is_water) {
895-
*n = MapNode(c_water_source);
896-
} else {
897-
*n = MapNode(CONTENT_AIR);
898-
// Upper (n3) is not walkable or is NULL. If it is
899-
// not NULL and not air and not water it is a
900-
// decoration that needs removing, to avoid
901-
// unsupported decorations.
902-
if (n3 && n3->getContent() != CONTENT_AIR &&
903-
n3->getContent() != c_water_source)
904-
*n3 = MapNode(CONTENT_AIR);
905-
}
906-
}
888+
// Move mud to new place. Outside mapchunk remove
889+
// any decorations above removed or placed mud.
890+
if (!dropped_to_unknown)
891+
moveMud(i, i2, i3, p2d, em);
907892

908893
// Done
909894
break;
@@ -915,6 +900,41 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos)
915900
}
916901

917902

903+
void MapgenV6::moveMud(u32 remove_index, u32 place_index,
904+
u32 above_remove_index, v2s16 pos, v3s16 em)
905+
{
906+
MapNode n_air(CONTENT_AIR);
907+
// Copy mud from old place to new place
908+
vm->m_data[place_index] = vm->m_data[remove_index];
909+
// Set old place to be air
910+
vm->m_data[remove_index] = n_air;
911+
// Outside the mapchunk decorations may need to be removed if above removed
912+
// mud or if half-buried in placed mud. Placed mud is to the side of pos so
913+
// use 'pos.X >= node_max.X' etc.
914+
if (pos.X >= node_max.X || pos.X <= node_min.X ||
915+
pos.Y >= node_max.Z || pos.Y <= node_min.Z) {
916+
// 'above remove' node is above removed mud. If it is not air and not
917+
// water it is a decoration that needs removing. Also search upwards
918+
// for a possible stacked decoration.
919+
while (vm->m_area.contains(above_remove_index) &&
920+
vm->m_data[above_remove_index].getContent() != CONTENT_AIR &&
921+
vm->m_data[above_remove_index].getContent() != c_water_source) {
922+
vm->m_data[above_remove_index] = n_air;
923+
vm->m_area.add_y(em, above_remove_index, 1);
924+
}
925+
// Mud placed may have half-buried a tall decoration, search above and
926+
// remove.
927+
vm->m_area.add_y(em, place_index, 1);
928+
while (vm->m_area.contains(place_index) &&
929+
vm->m_data[place_index].getContent() != CONTENT_AIR &&
930+
vm->m_data[place_index].getContent() != c_water_source) {
931+
vm->m_data[place_index] = n_air;
932+
vm->m_area.add_y(em, place_index, 1);
933+
}
934+
}
935+
}
936+
937+
918938
void MapgenV6::placeTreesAndJungleGrass()
919939
{
920940
//TimeTaker t("placeTrees");

Diff for: ‎src/mapgen_v6.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class MapgenV6 : public Mapgen {
162162
int generateGround();
163163
void addMud();
164164
void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos);
165+
void moveMud(u32 remove_index, u32 place_index,
166+
u32 above_remove_index, v2s16 pos, v3s16 em);
165167
void growGrass();
166168
void placeTreesAndJungleGrass();
167169
virtual void generateCaves(int max_stone_y);

0 commit comments

Comments
 (0)
Please sign in to comment.