diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index c61132122..24b411d4b 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -493,7 +493,7 @@ void Player::setAttribute(unsigned short id, int base, int current) creatureStats.mAttributes[id].mBase = base; creatureStats.mAttributes[id].mCurrent = current; - if (std::find(attributeChanges.attributeIndexes.begin(), attributeChanges.attributeIndexes.end(), id) == attributeChanges.attributeIndexes.end()) + if (!Utils::vectorContains(&attributeChanges.attributeIndexes, id)) attributeChanges.attributeIndexes.push_back(id); attributesChanged = true; @@ -519,7 +519,8 @@ void Player::setSkill(unsigned short id, int base, int current, float progress) skill.mCurrent = current; skill.mProgress = progress; - skillChanges.skillIndexes.push_back(id); + if (!Utils::vectorContains(&skillChanges.skillIndexes, id)) + skillChanges.skillIndexes.push_back(id); skillsChanged = true; } @@ -536,7 +537,7 @@ void Player::setSkillIncrease(unsigned short attributeId, int increase) npcStats.mSkillIncrease[attributeId] = increase; - if (std::find(attributeChanges.attributeIndexes.begin(), attributeChanges.attributeIndexes.end(), attributeId) == attributeChanges.attributeIndexes.end()) + if (!Utils::vectorContains(&attributeChanges.attributeIndexes, attributeId)) attributeChanges.attributeIndexes.push_back(attributeId); attributesChanged = true; diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index bba0c47ac..b3d7246cc 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -85,6 +85,11 @@ bool Utils::compareDoubles(double a, double b, double epsilon) return fabs(a - b) < epsilon; } +bool Utils::vectorContains(std::vector* vectorChecked, int value) +{ + return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end(); +} + std::string Utils::toString(int num) { std::ostringstream stream; diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 47e264358..47353f92a 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -7,6 +7,7 @@ #include #include +#include #if (defined __WIN32__ || defined _WIN32 || defined WIN32) #define __WINDOWS @@ -26,6 +27,8 @@ namespace Utils bool compareDoubles(double a, double b, double epsilon); + bool vectorContains(std::vector* vectorChecked, int value); + std::string replaceString(const std::string &source, const char *find, const char *replace); std::string toString(int num);