summaryrefslogtreecommitdiffstats
path: root/src/Enchantments.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-15 19:23:53 +0200
committerMattes D <github@xoft.cz>2014-10-15 19:23:53 +0200
commit06b466471fa59b2496af702c4d1cf1fd53df8063 (patch)
treeea46d2d2402dc9d116a94753ac5238a3e87f83d0 /src/Enchantments.cpp
parentFunctions in cPluginManager get references instead of pointers. (diff)
parentUsing C++11 loops (diff)
downloadcuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.gz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.bz2
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.lz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.xz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.zst
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.zip
Diffstat (limited to 'src/Enchantments.cpp')
-rw-r--r--src/Enchantments.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index 264878c22..80a9810b6 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"
@@ -1019,3 +1020,30 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment
+
+cEnchantments cEnchantments::GenerateEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed)
+{
+ int AllWeights = 0;
+ for (const auto Enchantment : a_Enchantments)
+ {
+ AllWeights += Enchantment.m_Weight;
+ }
+
+ cNoise Noise(a_Seed);
+ int RandomNumber = Noise.IntNoise1DInt(AllWeights) / 7 % AllWeights;
+
+ for (const auto Enchantment : a_Enchantments)
+ {
+ RandomNumber -= Enchantment.m_Weight;
+ if (RandomNumber < 0)
+ {
+ return Enchantment.m_Enchantments;
+ }
+ }
+
+ return cEnchantments();
+}
+
+
+
+