forked from teamnwah/openmw-tes3coop
[General] Add and use utility function for int value checks in vectors
(cherry picked from commit a796f81444
)
This commit is contained in:
parent
b6099024df
commit
7b702bf8c2
3 changed files with 17 additions and 9 deletions
|
@ -409,8 +409,7 @@ void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attribu
|
|||
|
||||
player->creatureStats.mAttributes[attributeId].mBase = value;
|
||||
|
||||
if (std::find(player->attributeChanges.attributeIndexes.begin(), player->attributeChanges.attributeIndexes.end(), attributeId) ==
|
||||
player->attributeChanges.attributeIndexes.end())
|
||||
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
|
||||
player->attributeChanges.attributeIndexes.push_back(attributeId);
|
||||
}
|
||||
|
||||
|
@ -424,8 +423,7 @@ void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short a
|
|||
|
||||
player->creatureStats.mAttributes[attributeId].mMod = 0;
|
||||
|
||||
if (std::find(player->attributeChanges.attributeIndexes.begin(), player->attributeChanges.attributeIndexes.end(), attributeId) ==
|
||||
player->attributeChanges.attributeIndexes.end())
|
||||
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
|
||||
player->attributeChanges.attributeIndexes.push_back(attributeId);
|
||||
}
|
||||
|
||||
|
@ -439,7 +437,8 @@ void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, in
|
|||
|
||||
player->npcStats.mSkills[skillId].mBase = value;
|
||||
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
}
|
||||
|
||||
void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept
|
||||
|
@ -452,7 +451,8 @@ void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill
|
|||
|
||||
player->npcStats.mSkills[skillId].mMod = 0;
|
||||
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept
|
||||
|
@ -465,7 +465,8 @@ void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId
|
|||
|
||||
player->npcStats.mSkills[skillId].mProgress = value;
|
||||
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
|
||||
player->skillChanges.skillIndexes.push_back(skillId);
|
||||
}
|
||||
|
||||
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept
|
||||
|
@ -478,8 +479,7 @@ void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute
|
|||
|
||||
player->npcStats.mSkillIncrease[attributeId] = value;
|
||||
|
||||
if (std::find(player->attributeChanges.attributeIndexes.begin(), player->attributeChanges.attributeIndexes.end(), attributeId) ==
|
||||
player->attributeChanges.attributeIndexes.end())
|
||||
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
|
||||
player->attributeChanges.attributeIndexes.push_back(attributeId);
|
||||
}
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue