[General] Add and use utility function for int value checks in vectors

new-script-api
David Cernat 7 years ago
parent 46d55816b8
commit a796f81444

@ -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;

@ -85,6 +85,11 @@ bool Utils::compareDoubles(double a, double b, double epsilon)
return fabs(a - b) < epsilon;
}
bool Utils::vectorContains(std::vector<int>* vectorChecked, int value)
{
return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end();
}
std::string Utils::toString(int num)
{
std::ostringstream stream;

@ -7,6 +7,7 @@
#include <string>
#include <sstream>
#include <vector>
#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<int>* vectorChecked, int value);
std::string replaceString(const std::string &source, const char *find, const char *replace);
std::string toString(int num);

Loading…
Cancel
Save