summaryrefslogtreecommitdiffstats
path: root/src/Generating/Trees.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Generating/Trees.cpp')
-rw-r--r--src/Generating/Trees.cpp138
1 files changed, 113 insertions, 25 deletions
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index 72fe5f819..5da8fc44a 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -6,6 +6,7 @@
#include "Globals.h"
#include "Trees.h"
#include "../BlockID.h"
+#include "../World.h"
@@ -130,7 +131,7 @@ inline void PushSomeColumns(int a_BlockX, int a_Height, int a_BlockZ, int a_Colu
{
int x = a_BlockX + a_Coords[i].x;
int z = a_BlockZ + a_Coords[i].z;
- if (a_Noise.IntNoise3DInt(x + 64 * a_Seq, a_Height + (int)i, z + 64 * a_Seq) <= a_Chance)
+ if (a_Noise.IntNoise3DInt(x + 64 * a_Seq, a_Height + static_cast<int>(i), z + 64 * a_Seq) <= a_Chance)
{
for (int j = 0; j < a_ColumnHeight; j++)
{
@@ -200,7 +201,8 @@ void GetTreeImageByBiome(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
}
else
{
- GetJungleTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
+ bool IsLarge = a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY + 32 * a_Seq, a_BlockZ) < 0x60000000;
+ GetJungleTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks, IsLarge);
}
return;
}
@@ -321,12 +323,12 @@ void GetSmallAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a
int Random = a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) >> 3;
- int Heights[] = {1, 2, 2, 3} ;
- int Height = 1 + Heights[Random & 3];
+ HEIGHTTYPE Heights[] = {1, 2, 2, 3} ;
+ HEIGHTTYPE Height = 1 + Heights[Random & 3];
Random >>= 2;
// Pre-alloc so that we don't realloc too often later:
- a_LogBlocks.reserve(Height + 5);
+ a_LogBlocks.reserve(static_cast<size_t>(Height + 5));
a_OtherBlocks.reserve(ARRAYCOUNT(BigO2) * 2 + ARRAYCOUNT(BigO1) + ARRAYCOUNT(Corners) * 3 + 3 + 5);
// Trunk:
@@ -396,8 +398,8 @@ void GetLargeAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a
for (int i = 4; i < Height; i++)
{
// Get a direction for the trunk to go to.
- Vector3d BranchStartDirection = AvailableDirections[a_Noise.IntNoise3DInt(a_BlockX, a_BlockY + i, a_BlockZ) % ARRAYCOUNT(AvailableDirections)];
- Vector3d BranchDirection = AvailableDirections[a_Noise.IntNoise3DInt(a_BlockX, a_BlockY / i, a_BlockZ) % ARRAYCOUNT(AvailableDirections)] / 3;
+ Vector3d BranchStartDirection = AvailableDirections[static_cast<size_t>(a_Noise.IntNoise3DInt(a_BlockX, a_BlockY + i, a_BlockZ)) % ARRAYCOUNT(AvailableDirections)];
+ Vector3d BranchDirection = AvailableDirections[static_cast<size_t>(a_Noise.IntNoise3DInt(a_BlockX, a_BlockY / i, a_BlockZ)) % ARRAYCOUNT(AvailableDirections)] / 3;
int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockX * a_Seq, a_BlockY * a_Seq, a_BlockZ * a_Seq) % 3;
GetLargeAppleTreeBranch(a_BlockX, a_BlockY + i, a_BlockZ, BranchLength, BranchStartDirection, BranchDirection, a_BlockY + Height, a_Noise, a_LogBlocks);
@@ -476,10 +478,10 @@ NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction)
void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
- int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3);
+ HEIGHTTYPE Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3);
// Prealloc, so that we don't realloc too often later:
- a_LogBlocks.reserve(Height);
+ a_LogBlocks.reserve(static_cast<size_t>(Height));
a_OtherBlocks.reserve(80);
// The entire trunk, out of logs:
@@ -650,10 +652,10 @@ void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No
void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
- int Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3);
+ HEIGHTTYPE Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3);
// Prealloc, so that we don't realloc too often later:
- a_LogBlocks.reserve(Height);
+ a_LogBlocks.reserve(static_cast<size_t>(Height));
a_OtherBlocks.reserve(80);
// The entire trunk, out of logs:
@@ -713,12 +715,12 @@ void GetSpruceTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noi
// (each of the mod8 remainders has a very different chance of occurrence) - that's why we divide by 8
int MyRandom = a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY + 32 * a_Seq, a_BlockZ) / 8;
- static const int sHeights[] = {1, 2, 2, 3};
- int Height = sHeights[MyRandom & 3];
+ static const HEIGHTTYPE sHeights[] = {1, 2, 2, 3};
+ HEIGHTTYPE Height = sHeights[MyRandom & 3];
MyRandom >>= 2;
// Prealloc, so that we don't realloc too often later:
- a_LogBlocks.reserve(Height);
+ a_LogBlocks.reserve(static_cast<size_t>(Height));
a_OtherBlocks.reserve(180);
// Clear trunk blocks:
@@ -816,8 +818,8 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise
}
// Pre-allocate the vector:
- a_LogBlocks.reserve(TrunkHeight);
- a_OtherBlocks.reserve(NumLeavesLayers * 25);
+ a_LogBlocks.reserve(static_cast<size_t>(TrunkHeight));
+ a_OtherBlocks.reserve(static_cast<size_t>(NumLeavesLayers * 25));
// The entire trunk, out of logs:
for (int i = TrunkHeight; i >= 0; --i)
@@ -843,7 +845,7 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise
{
break;
}
- ASSERT((size_t)LayerSize < ARRAYCOUNT(BigOs));
+ ASSERT(static_cast<size_t>(LayerSize) < ARRAYCOUNT(BigOs));
PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigOs[LayerSize].Coords, BigOs[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER);
h--;
}
@@ -866,8 +868,8 @@ void GetSwampTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois
int Height = 3 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 8) % 3;
- a_LogBlocks.reserve(Height);
- a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + Height * ARRAYCOUNT(Vines) + 20);
+ a_LogBlocks.reserve(static_cast<size_t>(Height));
+ a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + 20);
for (int i = 0; i < Height; i++)
{
@@ -920,9 +922,9 @@ void GetAppleBushImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois
-void GetJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
+void GetJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large)
{
- if (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY + 32 * a_Seq, a_BlockZ) < 0x60000000)
+ if (!a_Large)
{
GetSmallJungleTreeImage(a_BlockX, a_BlockY, a_BlockZ, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks);
}
@@ -952,8 +954,8 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
int Height = 24 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 24;
- a_LogBlocks.reserve(Height * 4);
- a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO4) + ARRAYCOUNT(BigO3) + Height * ARRAYCOUNT(Vines) + 50);
+ a_LogBlocks.reserve(static_cast<size_t>(Height) * 4);
+ a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO4) + ARRAYCOUNT(BigO3) + static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + 50);
for (int i = 0; i < Height; i++)
{
@@ -999,12 +1001,12 @@ void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
int Height = 7 + (a_Noise.IntNoise3DInt(a_BlockX + 5 * a_Seq, a_BlockY, a_BlockZ + 5 * a_Seq) / 5) % 3;
- a_LogBlocks.reserve(Height);
+ a_LogBlocks.reserve(static_cast<size_t>(Height));
a_OtherBlocks.reserve(
2 * ARRAYCOUNT(BigO3) + // O3 layer, 2x
2 * ARRAYCOUNT(BigO2) + // O2 layer, 2x
ARRAYCOUNT(BigO1) + 1 + // Plus on the top
- Height * ARRAYCOUNT(Vines) + // Vines
+ static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + // Vines
50 // some safety
);
@@ -1041,3 +1043,89 @@ void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise &
+
+bool GetLargeTreeAdjustment(cWorld & a_World, int & a_X, int & a_Y, int & a_Z, NIBBLETYPE a_Meta)
+{
+ bool IsLarge = true;
+ a_Meta = a_Meta & 0x07;
+
+ // Check to see if we are the northwest corner
+ for (int x = 0; x < 2; ++x)
+ {
+ for (int z = 0; z < 2; ++z)
+ {
+ NIBBLETYPE meta;
+ BLOCKTYPE type;
+ a_World.GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta);
+ IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta);
+ }
+ }
+
+ if (IsLarge)
+ {
+ return true;
+ }
+
+ IsLarge = true;
+ // Check to see if we are the southwest corner
+ for (int x = 0; x < 2; ++x)
+ {
+ for (int z = 0; z > -2; --z)
+ {
+ NIBBLETYPE meta;
+ BLOCKTYPE type;
+ a_World.GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta);
+ IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta);
+ }
+ }
+
+ if (IsLarge)
+ {
+ --a_Z;
+ return true;
+ }
+
+ IsLarge = true;
+ // Check to see if we are the southeast corner
+ for (int x = 0; x > -2; --x)
+ {
+ for (int z = 0; z > -2; --z)
+ {
+ NIBBLETYPE meta;
+ BLOCKTYPE type;
+ a_World.GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta);
+ IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta);
+ }
+ }
+
+ if (IsLarge)
+ {
+ --a_Z;
+ --a_X;
+ return true;
+ }
+
+ IsLarge = true;
+ // Check to see if we are the northeast corner
+ for (int x = 0; x > -2; --x)
+ {
+ for (int z = 0; z < 2; ++z)
+ {
+ NIBBLETYPE meta;
+ BLOCKTYPE type;
+ a_World.GetBlockTypeMeta(a_X + x, a_Y, a_Z + z, type, meta);
+ IsLarge = IsLarge && (type == E_BLOCK_SAPLING) && ((a_Meta & meta) == a_Meta);
+ }
+ }
+
+ if (IsLarge)
+ {
+ --a_X;
+ }
+
+ return IsLarge;
+}
+
+
+
+