commit
06b466471f
|
@ -6,6 +6,7 @@
|
||||||
#include "Enchantments.h"
|
#include "Enchantments.h"
|
||||||
#include "WorldStorage/FastNBT.h"
|
#include "WorldStorage/FastNBT.h"
|
||||||
#include "FastRandom.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,9 @@ public:
|
||||||
/** Gets random enchantment from Vector and returns it */
|
/** Gets random enchantment from Vector and returns it */
|
||||||
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments);
|
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments);
|
||||||
|
|
||||||
|
/** Returns an enchantment from a Vector using cNoise. Mostly used for generators.*/
|
||||||
|
static cEnchantments GenerateEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed);
|
||||||
|
|
||||||
/** Returns true if a_Other doesn't contain exactly the same enchantments and levels */
|
/** Returns true if a_Other doesn't contain exactly the same enchantments and levels */
|
||||||
bool operator !=(const cEnchantments & a_Other) const;
|
bool operator !=(const cEnchantments & a_Other) const;
|
||||||
|
|
||||||
|
|
|
@ -637,7 +637,21 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
|
||||||
int Rnd = (Noise.IntNoise1DInt(i) / 7);
|
int Rnd = (Noise.IntNoise1DInt(i) / 7);
|
||||||
int LootRnd = Rnd % TotalProbab;
|
int LootRnd = Rnd % TotalProbab;
|
||||||
Rnd >>= 8;
|
Rnd >>= 8;
|
||||||
cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment
|
cItem CurrentLoot = cItem(E_ITEM_ENCHANTED_BOOK, 1, 0);
|
||||||
|
|
||||||
|
// Choose the enchantments
|
||||||
|
cWeightedEnchantments Enchantments;
|
||||||
|
cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7);
|
||||||
|
int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get.
|
||||||
|
|
||||||
|
for (int j = 0; j <= NumEnchantments; j++)
|
||||||
|
{
|
||||||
|
cEnchantments Enchantment = cEnchantments::GenerateEnchantmentFromVector(Enchantments, Noise.IntNoise2DInt(NumEnchantments, i));
|
||||||
|
CurrentLoot.m_Enchantments.Add(Enchantment);
|
||||||
|
cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment);
|
||||||
|
cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment);
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < a_CountLootProbabs; j++)
|
for (size_t j = 0; j < a_CountLootProbabs; j++)
|
||||||
{
|
{
|
||||||
LootRnd -= a_LootProbabs[i].m_Weight;
|
LootRnd -= a_LootProbabs[i].m_Weight;
|
||||||
|
|
Loading…
Reference in New Issue