diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-10-21 16:55:22 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-10-21 16:55:22 +0200 |
commit | 44514e53fc5ad19e57688bed610f804b6d28be33 (patch) | |
tree | 224fce184f6d59739d77828889025467ecfd1edf /src/Enchantments.cpp | |
parent | Added distance check. (diff) | |
parent | Updated ProtectionAreas (diff) | |
download | cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar.gz cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar.bz2 cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar.lz cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar.xz cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.tar.zst cuberite-44514e53fc5ad19e57688bed610f804b6d28be33.zip |
Diffstat (limited to 'src/Enchantments.cpp')
-rw-r--r-- | src/Enchantments.cpp | 28 |
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(); +} + + + + |