diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Enchantments.cpp | 20 | ||||
-rw-r--r-- | src/Enchantments.h | 1 | ||||
-rw-r--r-- | src/Item.cpp | 7 |
3 files changed, 23 insertions, 5 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 3caebdff5..ca72065ff 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -893,7 +893,23 @@ void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_ if (EnchantmentID == a_EnchantmentID) { - a_Enchantments->erase(std::remove(a_Enchantments->begin(), a_Enchantments->end(), *it), a_Enchantments->end()); + a_Enchantments->erase(it); + break; + } + } +} + + + + + +void cEnchantments::RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment) +{ + for (cWeightedEnchantments::iterator it = a_Enchantments->begin(); it != a_Enchantments->end(); ++it) + { + if ((*it).m_Enchantments == a_Enchantment) + { + a_Enchantments->erase(it); break; } } @@ -980,6 +996,8 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment return (*it).m_Enchantments; } } + + return cEnchantments(); } diff --git a/src/Enchantments.h b/src/Enchantments.h index 1b3561faf..3cb979042 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -109,6 +109,7 @@ public: static void AddEnchantmentWeightToVector(cWeightedEnchantments * a_Enchantments, int a_Weight, cEnchantments a_Enchantment); /** Remove a enchantment weight from the vector */ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, int a_EnchantmentID); + static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments * a_Enchantments, cEnchantments a_Enchantment); /** Check enchantment conflicts from enchantments from the vector */ static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments & a_Enchantments, cEnchantments a_FirstEnchantment); diff --git a/src/Item.cpp b/src/Item.cpp index 540725492..1941a6693 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -286,7 +286,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment1.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment1), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment1); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1); @@ -302,7 +302,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment2.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment2), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment2); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2); @@ -318,7 +318,7 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment3.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment3), enchantments.end()); + cEnchantments::RemoveEnchantmentWeightFromVector(&enchantments, Enchantment3); // Checking for conflicting enchantments cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3); @@ -334,7 +334,6 @@ bool cItem::EnchantByXPLevels(int a_NumXPLevels) { cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments); m_Enchantments.AddFromString(Enchantment4.ToString()); - enchantments.erase(std::remove(enchantments.begin(), enchantments.end(), Enchantment4), enchantments.end()); } } |