STR, no, this is much more effective CPU-wise.
Only I'm afraid the coords are wrong, each X and Z needs +2, because they are not relative to the area center, but to its XM-ZM corner. That's probably why it doesn't work, right, Daniel? Sorry for misleading you in the code comment, didn't think of that back then.
Okay, i will try it. Thanks.
Can you please explain, how this should work?
Code:
Store the weight together with the enchantments in cEnchantmentsVector (call it cWeightedEnchantments).
How can i then use the weight?
Like this:
struct cWeightedEnchantment
{
int m_Weight;
cEnchantments m_Enchantments;
};
typedef std::vector<cWeightedEnchantment> cWeightedEnchantments;
To use the weight, you sum up the individual m_Weight members, then generate a random number in range 0 - (sum - 1). Then you walk the vector again and subtract each m_Weight from the generated random number; as soon as it becomes negative, you use that item in the vector.
How can i do this without string operations? So how can i get the enchantment (without EnchantmentLevel) from cEnchantments.
Old Code:
int EnchantmentID = atoi(StringSplit((*it).m_Enchantments.ToString(), "=")[0].c_str());
There's this nifty little function in cEnchantments:
/// Returns the level for the specified enchantment; 0 if not stored
int GetLevel(int a_EnchantmentID) const;
This code don't do this what i want.
I need the enchantment ID from a cEnchantments.
Example: cEnchantments("Sharpness=4").
My old code get the id from sharpness.
The method from you get the enchantment level. So this method will return 4.
Yes, but your code only uses the ID to check if the enchantment is there. Which is exactly what you get with this function:
if (it->GetLevel(a_EnchantmentID) > 0)
{
// This weighted enchantment contains the enchantment we don't want, erase it:
a_Enchantments->erase(it);
// Do not break, there may be more incompatible enchantments
}
The code also shouldn't break from the for-loop, since there may be multiple weighted enchantments that need removing. But then you need to care about iterator validity after calling the erase() function.
Thanks, i will push the code now.