summaryrefslogtreecommitdiffstats
path: root/src/Enchantments.cpp
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-10-15 14:44:07 +0200
committerSTRWarrior <niels.breuker@hotmail.nl>2014-10-15 14:44:07 +0200
commitff5f57514e172e3344d6d50fce6bd8ea84e7f32b (patch)
treec3988d3d4b12ee37770ed026425bfa7b07f84dba /src/Enchantments.cpp
parentEnchanted books generate in MineShafts chests (diff)
downloadcuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar.gz
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar.bz2
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar.lz
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar.xz
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.tar.zst
cuberite-ff5f57514e172e3344d6d50fce6bd8ea84e7f32b.zip
Diffstat (limited to '')
-rw-r--r--src/Enchantments.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index e106ef398..3cddf37ae 100644
--- a/src/Enchantments.cpp
+++ b/src/Enchantments.cpp
@@ -6,6 +6,7 @@
#include "Enchantments.h"
#include "WorldStorage/FastNBT.h"
#include "FastRandom.h"
+#include "Noise.h"
@@ -994,20 +995,43 @@ void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments &
-cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed)
+cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments)
{
cFastRandom Random;
- if (a_Seed != -1)
+
+ int AllWeights = 0;
+ for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
+ {
+ AllWeights += (*it).m_Weight;
+ }
+ int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1);
+ for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
{
- Random = cFastRandom(a_Seed);
+ RandomNumber -= (*it).m_Weight;
+ if (RandomNumber < 0)
+ {
+ return (*it).m_Enchantments;
+ }
}
+ return cEnchantments();
+}
+
+
+
+
+
+cEnchantments cEnchantments::GenerateEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed)
+{
int AllWeights = 0;
for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
{
AllWeights += (*it).m_Weight;
}
- int RandomNumber = Random.GenerateRandomInteger(0, AllWeights - 1);
+
+ cNoise Noise(a_Seed);
+ int RandomNumber = Noise.IntNoise1DInt(AllWeights) % AllWeights;
+
for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)
{
RandomNumber -= (*it).m_Weight;