Enchanted books generate in MineShafts chests

master
STRWarrior 2014-10-15 14:08:45 +02:00
parent 7f8118e0cb
commit e3aa6e4857
5 changed files with 30 additions and 6 deletions

View File

@ -994,9 +994,13 @@ void cEnchantments::CheckEnchantmentConflictsFromVector(cWeightedEnchantments &
cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments)
cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed)
{
cFastRandom Random;
if (a_Seed != -1)
{
Random = cFastRandom(a_Seed);
}
int AllWeights = 0;
for (cWeightedEnchantments::iterator it = a_Enchantments.begin(); it != a_Enchantments.end(); ++it)

View File

@ -126,7 +126,7 @@ public:
static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment);
/** Gets random enchantment from Vector and returns it */
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments);
static cEnchantments GetRandomEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed = -1);
/** Returns true if a_Other doesn't contain exactly the same enchantments and levels */
bool operator !=(const cEnchantments & a_Other) const;

View File

@ -90,10 +90,17 @@ int cFastRandom::m_SeedCounter = 0;
cFastRandom::cFastRandom(void) :
m_Seed(m_SeedCounter++),
cFastRandom::cFastRandom(int a_Seed) :
m_Counter(0)
{
if (a_Seed == -1)
{
m_Seed = m_SeedCounter++;
}
else
{
m_Seed = a_Seed;
}
}

View File

@ -30,7 +30,7 @@ salts, the values they get will be different.
class cFastRandom
{
public:
cFastRandom(void);
cFastRandom(int a_Seed = -1);
/// Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M
int NextInt(int a_Range);

View File

@ -637,7 +637,20 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
int Rnd = (Noise.IntNoise1DInt(i) / 7);
int LootRnd = Rnd % TotalProbab;
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 I = 0; I <= NumEnchantments; I++)
{
cEnchantments Enchantment = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Seed);
CurrentLoot.m_Enchantments.AddFromString(Enchantment.ToString());
cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment);
}
for (size_t j = 0; j < a_CountLootProbabs; j++)
{
LootRnd -= a_LootProbabs[i].m_Weight;