mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-06-21 11:41:34 +00:00
[General] Add and use utility function for int value checks in vectors
This commit is contained in:
parent
46d55816b8
commit
a796f81444
3 changed files with 12 additions and 3 deletions
|
@ -493,7 +493,7 @@ void Player::setAttribute(unsigned short id, int base, int current)
|
||||||
creatureStats.mAttributes[id].mBase = base;
|
creatureStats.mAttributes[id].mBase = base;
|
||||||
creatureStats.mAttributes[id].mCurrent = current;
|
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);
|
attributeChanges.attributeIndexes.push_back(id);
|
||||||
|
|
||||||
attributesChanged = true;
|
attributesChanged = true;
|
||||||
|
@ -519,7 +519,8 @@ void Player::setSkill(unsigned short id, int base, int current, float progress)
|
||||||
skill.mCurrent = current;
|
skill.mCurrent = current;
|
||||||
skill.mProgress = progress;
|
skill.mProgress = progress;
|
||||||
|
|
||||||
skillChanges.skillIndexes.push_back(id);
|
if (!Utils::vectorContains(&skillChanges.skillIndexes, id))
|
||||||
|
skillChanges.skillIndexes.push_back(id);
|
||||||
|
|
||||||
skillsChanged = true;
|
skillsChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -536,7 +537,7 @@ void Player::setSkillIncrease(unsigned short attributeId, int increase)
|
||||||
|
|
||||||
npcStats.mSkillIncrease[attributeId] = 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);
|
attributeChanges.attributeIndexes.push_back(attributeId);
|
||||||
|
|
||||||
attributesChanged = true;
|
attributesChanged = true;
|
||||||
|
|
|
@ -85,6 +85,11 @@ bool Utils::compareDoubles(double a, double b, double epsilon)
|
||||||
return fabs(a - b) < 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::string Utils::toString(int num)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#if (defined __WIN32__ || defined _WIN32 || defined WIN32)
|
#if (defined __WIN32__ || defined _WIN32 || defined WIN32)
|
||||||
#define __WINDOWS
|
#define __WINDOWS
|
||||||
|
@ -26,6 +27,8 @@ namespace Utils
|
||||||
|
|
||||||
bool compareDoubles(double a, double b, double epsilon);
|
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 replaceString(const std::string &source, const char *find, const char *replace);
|
||||||
|
|
||||||
std::string toString(int num);
|
std::string toString(int num);
|
||||||
|
|
Loading…
Reference in a new issue