aboutsummaryrefslogtreecommitdiff
path: root/src/mg_decoration.cpp
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/mg_decoration.cpp
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/mg_decoration.cpp')
-rw-r--r--src/mg_decoration.cpp131
1 files changed, 66 insertions, 65 deletions
diff --git a/src/mg_decoration.cpp b/src/mg_decoration.cpp
index 8b6abb5d5..51e4fbbcc 100644
--- a/src/mg_decoration.cpp
+++ b/src/mg_decoration.cpp
@@ -26,12 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/numeric.h"
FlagDesc flagdesc_deco[] = {
- {"place_center_x", DECO_PLACE_CENTER_X},
- {"place_center_y", DECO_PLACE_CENTER_Y},
- {"place_center_z", DECO_PLACE_CENTER_Z},
+ {"place_center_x", DECO_PLACE_CENTER_X},
+ {"place_center_y", DECO_PLACE_CENTER_Y},
+ {"place_center_z", DECO_PLACE_CENTER_Z},
{"force_placement", DECO_FORCE_PLACEMENT},
- {"liquid_surface", DECO_LIQUID_SURFACE},
- {NULL, 0}
+ {"liquid_surface", DECO_LIQUID_SURFACE},
+ {NULL, 0}
};
@@ -82,6 +82,56 @@ Decoration::~Decoration()
void Decoration::resolveNodeNames()
{
getIdsFromNrBacklog(&c_place_on);
+ getIdsFromNrBacklog(&c_spawnby);
+}
+
+
+bool Decoration::canPlaceDecoration(MMVManip *vm, v3s16 p)
+{
+ // Check if the decoration can be placed on this node
+ u32 vi = vm->m_area.index(p);
+ if (!CONTAINS(c_place_on, vm->m_data[vi].getContent()))
+ return false;
+
+ // Don't continue if there are no spawnby constraints
+ if (nspawnby == -1)
+ return true;
+
+ int nneighs = 0;
+ static const v3s16 dirs[16] = {
+ v3s16( 0, 0, 1),
+ v3s16( 0, 0, -1),
+ v3s16( 1, 0, 0),
+ v3s16(-1, 0, 0),
+ v3s16( 1, 0, 1),
+ v3s16(-1, 0, 1),
+ v3s16(-1, 0, -1),
+ v3s16( 1, 0, -1),
+
+ v3s16( 0, 1, 1),
+ v3s16( 0, 1, -1),
+ v3s16( 1, 1, 0),
+ v3s16(-1, 1, 0),
+ v3s16( 1, 1, 1),
+ v3s16(-1, 1, 1),
+ v3s16(-1, 1, -1),
+ v3s16( 1, 1, -1)
+ };
+
+ // Check these 16 neighbouring nodes for enough spawnby nodes
+ for (size_t i = 0; i != ARRLEN(dirs); i++) {
+ u32 index = vm->m_area.index(p + dirs[i]);
+ if (!vm->m_area.contains(index))
+ continue;
+
+ if (CONTAINS(c_spawnby, vm->m_data[index].getContent()))
+ nneighs++;
+ }
+
+ if (nneighs < nspawnby)
+ return false;
+
+ return true;
}
@@ -145,7 +195,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
y < y_min || y > y_max)
continue;
- if (y + getHeight() >= mg->vm->m_area.MaxEdge.Y) {
+ if (y + getHeight() > mg->vm->m_area.MaxEdge.Y) {
continue;
#if 0
printf("Decoration at (%d %d %d) cut off\n", x, y, z);
@@ -156,7 +206,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
}
if (mg->biomemap) {
- std::set<u8>::iterator iter;
+ UNORDERED_SET<u8>::iterator iter;
if (!biomes.empty()) {
iter = biomes.find(mg->biomemap[mapindex]);
@@ -236,66 +286,15 @@ void DecoSimple::resolveNodeNames()
{
Decoration::resolveNodeNames();
getIdsFromNrBacklog(&c_decos);
- getIdsFromNrBacklog(&c_spawnby);
}
-bool DecoSimple::canPlaceDecoration(MMVManip *vm, v3s16 p)
+size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
{
// Don't bother if there aren't any decorations to place
if (c_decos.size() == 0)
- return false;
-
- u32 vi = vm->m_area.index(p);
-
- // Check if the decoration can be placed on this node
- if (!CONTAINS(c_place_on, vm->m_data[vi].getContent()))
- return false;
-
- // Don't continue if there are no spawnby constraints
- if (nspawnby == -1)
- return true;
-
- int nneighs = 0;
- v3s16 dirs[16] = {
- v3s16( 0, 0, 1),
- v3s16( 0, 0, -1),
- v3s16( 1, 0, 0),
- v3s16(-1, 0, 0),
- v3s16( 1, 0, 1),
- v3s16(-1, 0, 1),
- v3s16(-1, 0, -1),
- v3s16( 1, 0, -1),
-
- v3s16( 0, 1, 1),
- v3s16( 0, 1, -1),
- v3s16( 1, 1, 0),
- v3s16(-1, 1, 0),
- v3s16( 1, 1, 1),
- v3s16(-1, 1, 1),
- v3s16(-1, 1, -1),
- v3s16( 1, 1, -1)
- };
-
- // Check a Moore neighborhood if there are enough spawnby nodes
- for (size_t i = 0; i != ARRLEN(dirs); i++) {
- u32 index = vm->m_area.index(p + dirs[i]);
- if (!vm->m_area.contains(index))
- continue;
-
- if (CONTAINS(c_spawnby, vm->m_data[index].getContent()))
- nneighs++;
- }
-
- if (nneighs < nspawnby)
- return false;
-
- return true;
-}
-
+ return 0;
-size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
-{
if (!canPlaceDecoration(vm, p))
return 0;
@@ -316,7 +315,7 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
!force_placement)
break;
- vm->m_data[vi] = MapNode(c_place);
+ vm->m_data[vi] = MapNode(c_place, 0, deco_param2);
}
return 1;
@@ -345,9 +344,7 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
if (schematic == NULL)
return 0;
- u32 vi = vm->m_area.index(p);
- content_t c = vm->m_data[vi].getContent();
- if (!CONTAINS(c_place_on, c))
+ if (!canPlaceDecoration(vm, p))
return 0;
if (flags & DECO_PLACE_CENTER_X)
@@ -370,5 +367,9 @@ size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
int DecoSchematic::getHeight()
{
- return schematic->size.Y;
+ // Account for a schematic being sunk into the ground by flag.
+ // When placed normally account for how a schematic is placed
+ // sunk 1 node into the ground.
+ return (flags & DECO_PLACE_CENTER_Y) ?
+ (schematic->size.Y - 1) / 2 : schematic->size.Y - 1;
}